Skip to content

Commit

Permalink
Add the possibility to have a merge config within the job config and …
Browse files Browse the repository at this point in the history
…fix a bug in JLineupHandler when urlKey differs from url
  • Loading branch information
MediaMarco committed Apr 17, 2024
1 parent 2f5d42c commit a9ebe4b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
6 changes: 6 additions & 0 deletions cli/src/main/java/de/otto/jlineup/cli/JLineup.java
Expand Up @@ -321,6 +321,12 @@ public Integer call() throws Exception {
jobConfig = ConfigMerger.mergeJobConfigWithMergeConfig(jobConfig, mergeConfig);
}

if (jobConfig.mergeConfig != null) {
JobConfig mainGlobalConfig = JobConfig.copyOfBuilder(jobConfig).withMergeConfig(null).build();
JobConfig mergeGlobalConfig = jobConfig.mergeConfig;
jobConfig = ConfigMerger.mergeJobConfigWithMergeConfig(mainGlobalConfig, mergeGlobalConfig);
}

jobConfig = jobConfig.insertDefaults();

if (browserOverride != null) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/de/otto/jlineup/JLineupRunner.java
Expand Up @@ -38,7 +38,7 @@ public JLineupRunner(JobConfig jobConfig, RunStepConfig runStepConfig) throws Va
validateConfig();
}

public boolean run() {
public boolean run() {

final FileService fileService = new FileService(runStepConfig, jobConfig);
final ImageService imageService = new ImageService();
Expand Down
32 changes: 17 additions & 15 deletions core/src/main/java/de/otto/jlineup/config/JobConfig.java
Expand Up @@ -92,6 +92,9 @@ public final class JobConfig {
@JsonInclude(value = Include.CUSTOM, valueFilter = HttpCheckFilter.class)
public final HttpCheckConfig httpCheck;

@JsonInclude(Include.NON_DEFAULT)
public final JobConfig mergeConfig;

public JobConfig() {
this(jobConfigBuilder());
}
Expand All @@ -111,6 +114,7 @@ private JobConfig(Builder builder) {
checkForErrorsInLog = builder.checkForErrorsInLog;
httpCheck = builder.httpCheck;
name = builder.name;
mergeConfig = builder.mergeConfig;
}

public static String prettyPrint(JobConfig jobConfig) {
Expand Down Expand Up @@ -203,6 +207,10 @@ public HttpCheckConfig getHttpCheck() {
return httpCheck;
}

public JobConfig getMergeConfig() {
return mergeConfig;
}

/*
*
*
Expand Down Expand Up @@ -230,6 +238,7 @@ public static Builder copyOfBuilder(JobConfig jobConfig) {
.withGlobalTimeout(jobConfig.globalTimeout)
.withDebug(jobConfig.debug)
.withLogToFile(jobConfig.logToFile)
.withMergeConfig(jobConfig.mergeConfig)
.withCheckForErrorsInLog(jobConfig.checkForErrorsInLog);
}

Expand All @@ -238,25 +247,12 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
JobConfig jobConfig = (JobConfig) o;
return pageLoadTimeout == jobConfig.pageLoadTimeout &&
screenshotRetries == jobConfig.screenshotRetries &&
threads == jobConfig.threads &&
globalTimeout == jobConfig.globalTimeout &&
debug == jobConfig.debug &&
logToFile == jobConfig.logToFile &&
checkForErrorsInLog == jobConfig.checkForErrorsInLog &&
Objects.equals(urls, jobConfig.urls) &&
browser == jobConfig.browser &&
Objects.equals(name, jobConfig.name) &&
Objects.equals(globalWaitAfterPageLoad, jobConfig.globalWaitAfterPageLoad) &&
Objects.equals(windowHeight, jobConfig.windowHeight) &&
Objects.equals(reportFormat, jobConfig.reportFormat) &&
Objects.equals(httpCheck, jobConfig.httpCheck);
return pageLoadTimeout == jobConfig.pageLoadTimeout && screenshotRetries == jobConfig.screenshotRetries && threads == jobConfig.threads && globalTimeout == jobConfig.globalTimeout && debug == jobConfig.debug && logToFile == jobConfig.logToFile && checkForErrorsInLog == jobConfig.checkForErrorsInLog && Objects.equals(urls, jobConfig.urls) && browser == jobConfig.browser && Objects.equals(name, jobConfig.name) && Objects.equals(globalWaitAfterPageLoad, jobConfig.globalWaitAfterPageLoad) && Objects.equals(windowHeight, jobConfig.windowHeight) && Objects.equals(reportFormat, jobConfig.reportFormat) && Objects.equals(httpCheck, jobConfig.httpCheck) && Objects.equals(mergeConfig, jobConfig.mergeConfig);
}

@Override
public int hashCode() {
return Objects.hash(urls, browser, name, globalWaitAfterPageLoad, pageLoadTimeout, windowHeight, reportFormat, screenshotRetries, threads, globalTimeout, debug, logToFile, checkForErrorsInLog, httpCheck);
return Objects.hash(urls, browser, name, globalWaitAfterPageLoad, pageLoadTimeout, windowHeight, reportFormat, screenshotRetries, threads, globalTimeout, debug, logToFile, checkForErrorsInLog, httpCheck, mergeConfig);
}

@Override
Expand Down Expand Up @@ -403,6 +399,7 @@ public static final class Builder {
private boolean logToFile = false;
private boolean checkForErrorsInLog = false;
private HttpCheckConfig httpCheck = DEFAULT_HTTP_CHECK_CONFIG;
public JobConfig mergeConfig;

private Builder() {
}
Expand Down Expand Up @@ -482,6 +479,11 @@ public Builder withHttpCheck(HttpCheckConfig val) {
return this;
}

public Builder withMergeConfig(JobConfig val) {
mergeConfig = val;
return this;
}

public JobConfig build() {
return new JobConfig(this);
}
Expand Down
Expand Up @@ -55,7 +55,7 @@ public class JLineupHandler implements RequestStreamHandler {
public void handleRequest(InputStream input, OutputStream output, Context context) {
try {
LambdaRequestPayload event = objectMapper.readValue(input, LambdaRequestPayload.class);
ScreenshotContext screenshotContext = ScreenshotContext.copyOfBuilder(event.screenshotContext).withStep(event.step.toBrowserStep()).withUrlKey(event.urlKey).withUrlConfig(event.jobConfig.urls.get(event.screenshotContext.url)).build();
ScreenshotContext screenshotContext = ScreenshotContext.copyOfBuilder(event.screenshotContext).withStep(event.step.toBrowserStep()).withUrlKey(event.urlKey).withUrlConfig(event.jobConfig.urls.get(event.screenshotContext.urlKey)).build();
LambdaRunner runner = createRun(event.runId, event.step == RunStep.after ? RunStep.after_only : event.step, event.jobConfig, screenshotContext);
runner.run();

Expand Down
Expand Up @@ -110,6 +110,7 @@ public void takeScreenshots(List<ScreenshotContext> screenshotContexts) throws E
}

} catch (ServiceException e) {
LOG.error("Lambda call failed");
throw new RuntimeException(e);
}

Expand Down
Expand Up @@ -78,6 +78,7 @@ public synchronized JLineupRunStatus startBeforeRun(JobConfig jobConfig) throws
return State.BEFORE_DONE;
}, executorService)
.exceptionally(ex -> {
LOG.error("Error in before runStep.", ex);
return State.ERROR;
})
.thenApply(st -> {
Expand Down
8 changes: 8 additions & 0 deletions web/src/main/java/de/otto/jlineup/web/JLineupController.java
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
import com.google.common.collect.ImmutableMap;
import de.otto.jlineup.browser.Browser;
import de.otto.jlineup.config.ConfigMerger;
import de.otto.jlineup.config.JobConfig;
import de.otto.jlineup.exceptions.ValidationError;
import de.otto.jlineup.service.BrowserNotInstalledException;
Expand Down Expand Up @@ -46,6 +47,13 @@ public String getHello(HttpServletRequest request) {

@PostMapping(value = "/runs")
public ResponseEntity<RunBeforeResponse> runBefore(@RequestBody JobConfig jobConfig, HttpServletRequest request) throws Exception {

if (jobConfig.mergeConfig != null) {
JobConfig mainGlobalConfig = JobConfig.copyOfBuilder(jobConfig).withMergeConfig(null).build();
JobConfig mergeGlobalConfig = jobConfig.mergeConfig;
jobConfig = ConfigMerger.mergeJobConfigWithMergeConfig(mainGlobalConfig, mergeGlobalConfig);
}

String id = jLineupService.startBeforeRun(jobConfig.insertDefaults()).getId();

HttpHeaders headers = new HttpHeaders();
Expand Down

0 comments on commit a9ebe4b

Please sign in to comment.