Skip to content

Commit

Permalink
fix: support native executor.json and executor bu API #83
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetkov-ma committed Jul 2, 2024
1 parent cd6d9d6 commit abd2ebb
Show file tree
Hide file tree
Showing 47 changed files with 3,157 additions and 3,104 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ id_rsa
!**/resources/**/*.zip
!**/resources/**/*.jar
allure-server-store/
allure-server-store-db/
tmp/

pg-secret.yaml
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ services:
- postgres

postgres:
image: postgres:latest
image: postgres:16.3-alpine
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: allure
ports:
- 5432:5432
volumes:
- ./allure-server-store-db:/var/lib/postgresql/data:rw
4 changes: 2 additions & 2 deletions src/main/java/ru/iopump/qa/allure/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
@EnableTransactionManagement
@EnableConfigurationProperties({AllureProperties.class, CleanUpProperties.class, BasicProperties.class, TmsProperties.class})
@EnableVaadin
public class Application { //NOPMD
public class Application {

public static void main(String[] args) { //NOPMD
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.iopump.qa.allure.controller; //NOPMD
package ru.iopump.qa.allure.controller;

import com.google.common.base.Preconditions;
import io.qameta.allure.entity.ExecutorInfo;
Expand Down Expand Up @@ -65,20 +65,20 @@ public String baseUrl() {
@GetMapping
public Collection<ReportResponse> getAllReports(@RequestParam(required = false) String path) {
return StreamUtil.stream(getAllCached())
.filter(i -> path == null || i.getPath().startsWith(path))
.collect(Collectors.toUnmodifiableSet());
.filter(i -> path == null || i.getPath().startsWith(path))
.collect(Collectors.toUnmodifiableSet());
}

@Cacheable(CACHE) // caching results
public Collection<ReportResponse> getAllCached() {
return StreamUtil.stream(reportService.getAll())
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
}

@Operation(summary = "Generate report")
Expand All @@ -88,18 +88,18 @@ public Collection<ReportResponse> getAllCached() {
public ReportResponse generateReport(@RequestBody @Valid ReportGenerateRequest reportGenerateRequest) throws IOException {

final ReportEntity reportEntity = reportService.generate(
reportGenerateRequest.getReportSpec().getPathsAsPath(),
reportGenerateRequest.getResultsAsPath(resultService.getStoragePath()),
reportGenerateRequest.isDeleteResults(),
reportGenerateRequest.getReportSpec().getExecutorInfo(),
baseUrl()
reportGenerateRequest.getReportSpec().getPathsAsPath(),
reportGenerateRequest.getResultsAsPath(resultService.getStoragePath()),
reportGenerateRequest.isDeleteResults(),
reportGenerateRequest.getReportSpec().getExecutorInfo(),
baseUrl()
);

return new ReportResponse(
reportEntity.getUuid(),
reportEntity.getPath(),
reportEntity.generateUrl(baseUrl(), allureProperties.reports().dir()),
reportEntity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
reportEntity.getUuid(),
reportEntity.getPath(),
reportEntity.generateUrl(baseUrl(), allureProperties.reports().dir()),
reportEntity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
);
}

Expand All @@ -110,39 +110,39 @@ public ReportResponse generateReport(@RequestBody @Valid ReportGenerateRequest r
@ResponseStatus(HttpStatus.CREATED)
@CacheEvict(value = CACHE, allEntries = true) // update results cache
public ReportResponse uploadReport(
@PathVariable("reportPath") @NonNull String reportPath,
@Parameter(description = "File as multipart body. File must be an zip archive and not be empty. Nested type is 'application/zip'",
name = "allureResults",
example = "allure-result.zip",
required = true,
content = @Content(mediaType = "application/zip")
)
@RequestParam MultipartFile allureReportArchive) {
@PathVariable("reportPath") @NonNull String reportPath,
@Parameter(description = "File as multipart body. File must be an zip archive and not be empty. Nested type is 'application/zip'",
name = "allureResults",
example = "allure-result.zip",
required = true,
content = @Content(mediaType = "application/zip")
)
@RequestParam MultipartFile allureReportArchive) {

final String contentType = allureReportArchive.getContentType();

// Check Content-Type
if (StringUtils.isNotBlank(contentType)) {
Preconditions.checkArgument(StringUtils.equalsAny(contentType, "application/zip", "application/x-zip-compressed"),
"Content-Type must be '%s' but '%s'", "application/zip", contentType);
"Content-Type must be '%s' but '%s'", "application/zip", contentType);
}

// Check Extension
if (allureReportArchive.getOriginalFilename() != null) {
Preconditions.checkArgument(allureReportArchive.getOriginalFilename().endsWith(".zip"),
"File must have '.zip' extension but '%s'", allureReportArchive.getOriginalFilename());
"File must have '.zip' extension but '%s'", allureReportArchive.getOriginalFilename());
}

// Unzip and save
ReportEntity reportEntity = reportService
.uploadReport(reportPath, allureReportArchive.getInputStream(), new ExecutorInfo(), baseUrl());
.uploadReport(reportPath, allureReportArchive.getInputStream(), new ExecutorInfo(), baseUrl());
log.info("File saved to file system '{}'", allureReportArchive);

return new ReportResponse(
reportEntity.getUuid(),
reportEntity.getPath(),
reportEntity.generateUrl(baseUrl(), allureProperties.reports().dir()),
reportEntity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
reportEntity.getUuid(),
reportEntity.getPath(),
reportEntity.generateUrl(baseUrl(), allureProperties.reports().dir()),
reportEntity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
);
}

Expand All @@ -151,13 +151,13 @@ public ReportResponse uploadReport(
@CacheEvict(value = CACHE, allEntries = true)
public Collection<ReportResponse> deleteAllHistory() {
return reportService.clearAllHistory().stream()
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
}

@Operation(summary = "Delete all reports or older than date in epoch seconds")
Expand All @@ -172,17 +172,17 @@ public Collection<ReportResponse> deleteAll(@RequestParam(required = false) Long
deleted = reportService.deleteAllOlderThanDate(boundaryDate);
}
return deleted.stream()
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
.map(entity -> new ReportResponse(
entity.getUuid(),
entity.getPath(),
entity.generateUrl(baseUrl(), allureProperties.reports().dir()),
entity.generateLatestUrl(baseUrl(), allureProperties.reports().path())
))
.collect(Collectors.toUnmodifiableList());
}

@ExceptionHandler(ConstraintViolationException.class)
private void constraintViolationException(HttpServletResponse response) throws IOException { //NOPMD
private void constraintViolationException(HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.BAD_REQUEST.value());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.iopump.qa.allure.controller; //NOPMD
package ru.iopump.qa.allure.controller;

import com.google.common.base.Preconditions;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -65,7 +65,7 @@ public Collection<ResultResponse> deleteAllResults() throws IOException {
@DeleteMapping(path = "/{uuid}")
@CacheEvict(value = CACHE, allEntries = true)
public ResultResponse deleteResult(
@PathVariable @NotBlank @Pattern(regexp = PathUtil.UUID_PATTERN) String uuid
@PathVariable @NotBlank @Pattern(regexp = PathUtil.UUID_PATTERN) String uuid
) throws IOException {
return resultService.internalDeleteByUUID(uuid);
}
Expand All @@ -74,9 +74,9 @@ public ResultResponse deleteResult(
@GetMapping(path = "/{uuid}")
public ResultResponse getResult(@PathVariable @NotBlank @Pattern(regexp = PathUtil.UUID_PATTERN) String uuid) throws IOException {
return StreamUtil.stream(getAllResult())
.filter(i -> uuid.equalsIgnoreCase(i.getUuid()))
.findFirst()
.orElse(ResultResponse.builder().build());
.filter(i -> uuid.equalsIgnoreCase(i.getUuid()))
.findFirst()
.orElse(ResultResponse.builder().build());
}

@Operation(summary = "Get all uploaded allure results archives")
Expand All @@ -102,33 +102,33 @@ public Collection<ResultResponse> getAllResult() throws IOException {

@SneakyThrows
@Operation(summary = "Upload allure-results.zip with allure results files before generating report. " +
"Don't forgot memorize uuid from response for further report generation"
"Don't forgot memorize uuid from response for further report generation"
)
@PostMapping(consumes = {"multipart/form-data"})
@ResponseStatus(HttpStatus.CREATED)
@CacheEvict(value = CACHE, allEntries = true) // update results cache
public UploadResponse uploadResults(
@Parameter(description = "File as multipart body. File must be an zip archive and not be empty. Nested type is 'application/zip'",
name = "allureResults",
example = "allure-result.zip",
required = true,
content = @Content(mediaType = "application/zip")
)
@RequestParam MultipartFile allureResults
@Parameter(description = "File as multipart body. File must be an zip archive and not be empty. Nested type is 'application/zip'",
name = "allureResults",
example = "allure-result.zip",
required = true,
content = @Content(mediaType = "application/zip")
)
@RequestParam MultipartFile allureResults
) {

final String contentType = allureResults.getContentType();

// Check Content-Type
if (StringUtils.isNotBlank(contentType)) {
Preconditions.checkArgument(StringUtils.equalsAny(contentType, "application/zip", "application/x-zip-compressed"),
"Content-Type must be '%s' but '%s'", "application/zip", contentType);
"Content-Type must be '%s' but '%s'", "application/zip", contentType);
}

// Check Extension
if (allureResults.getOriginalFilename() != null) {
Preconditions.checkArgument(allureResults.getOriginalFilename().endsWith(".zip"),
"File must have '.zip' extension but '%s'", allureResults.getOriginalFilename());
"File must have '.zip' extension but '%s'", allureResults.getOriginalFilename());
}

// Unzip and save
Expand All @@ -141,4 +141,4 @@ public UploadResponse uploadResults(
public void constraintViolationException(HttpServletResponse response) throws IOException {
response.sendError(HttpStatus.BAD_REQUEST.value());
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/ru/iopump/qa/allure/entity/ReportEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public class ReportEntity {
private boolean active;
@Builder.Default
@PositiveOrZero
private long level = 0L; //NOPMD
private long level = 0L;
@Builder.Default
@PositiveOrZero
@Access(AccessType.PROPERTY)
@Column(columnDefinition = "bigint not null default '0'")
private long size = 0L; //NOPMD
private long size = 0L;
@Builder.Default
@PositiveOrZero
@Column(columnDefinition = "int not null default '0'")
private int version = 1; //NOPMD
private int version = 1;
@Builder.Default
@NotNull
@Column(nullable = false, columnDefinition = "varchar(255) not null default ''")
private String buildUrl = ""; //NOPMD
private String buildUrl = "";

public static long sizeKB(@Nullable Path path) {
if (path == null || Files.notExists(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void onClickGenerate() {
info.setVisible(true);
info.setText("Success: " + res);
}
} catch (Exception e) { //NOPMD
} catch (Exception e) {
error.setVisible(true);
error.setText("Error: " + e.getLocalizedMessage());
log.error("Generation error", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static ru.iopump.qa.util.Str.format;

@Slf4j
public class ResultUploadDialog extends Dialog { //NOPMD
public class ResultUploadDialog extends Dialog {

private static final long serialVersionUID = -4958469225519042248L;
private final MemoryBuffer buffer;
Expand Down Expand Up @@ -54,7 +54,7 @@ public ResultUploadDialog(
event.getFileName(), event.getContentLength(), uploadResponse
)), false
);
} catch (Exception ex) { //NOPMD
} catch (Exception ex) {
show(error("Internal error: " + ex.getLocalizedMessage()), true);
log.error("Uploading error", ex);
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/ru/iopump/qa/allure/gui/view/AboutView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ru.iopump.qa.allure.gui.view;

import static ru.iopump.qa.allure.gui.MainLayout.ALLURE_SERVER;

import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
Expand All @@ -10,15 +8,18 @@
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import ru.iopump.qa.allure.gui.MainLayout;
import ru.iopump.qa.util.ResourceUtil;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import static ru.iopump.qa.allure.gui.MainLayout.ALLURE_SERVER;

@Tag("about-view")
@PageTitle("About | " + ALLURE_SERVER)
@Route(value = "about", layout = MainLayout.class)
Expand Down Expand Up @@ -63,9 +64,9 @@ public AboutView() {
public static String getVersionOrDefault(@NonNull String defaultVersion) {
try (final InputStream inputStream = ResourceUtil.getResourceAsStream("version.info")) {
var version = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
log.info("App version from version.info = " + version); //NOPMD
log.info("App version from version.info = " + version);
return StringUtils.isBlank(version) ? defaultVersion : version;
} catch (Exception e) { //NOPMD
} catch (Exception e) {
log.error("Version error", e);
return defaultVersion;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ru/iopump/qa/allure/gui/view/ReportsView.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ru.iopump.qa.allure.gui.view; //NOPMD
package ru.iopump.qa.allure.gui.view;

import com.google.common.collect.ImmutableList;
import com.vaadin.flow.component.Tag;
Expand Down Expand Up @@ -79,7 +79,7 @@ public ReportsView(final JpaReportService jpaReportService,
try {
jpaReportService.internalDeleteByUUID(uuid);
Notification.show("Delete success: " + uuid, 2000, Notification.Position.TOP_START);
} catch (Exception e) { //NOPMD
} catch (Exception e) {
Notification.show("Deleting error: " + e.getLocalizedMessage(),
5000,
Notification.Position.TOP_START);
Expand Down
Loading

0 comments on commit abd2ebb

Please sign in to comment.