Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
add task log & fix report url for mta
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardW98 authored and openshift-merge-robot committed Jun 14, 2023
1 parent 66e9622 commit 6122832
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ public WorkReport execute(WorkContext workContext) {
Result<App> result = mtaClient.create(new App(0, appName, new Repository("git", repo, branch)));

if (result == null) {
taskLogger.logErrorWithSlf4j("MTA client returned empty result with no error");
// unexpected
return new DefaultWorkReport(WorkStatus.FAILED, new WorkContext(),
return new DefaultWorkReport(WorkStatus.REJECTED, new WorkContext(),
new IllegalStateException("MTA client returned empty result with no error"));
}
else if (result instanceof Result.Failure<App> failure) {
return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t());
taskLogger.logErrorWithSlf4j("MTA client returned failed result");
return new DefaultWorkReport(WorkStatus.REJECTED, workContext, failure.t());
}
else if (result instanceof Result.Success<App> success) {
workContext.put("application", success.value());
taskLogger.logInfoWithSlf4j("MTA client returned success result for application creation: {}",
success.value().name());
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
throw new IllegalArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,29 @@ public WorkReport execute(WorkContext workContext) {
Result<TaskGroup> result = mtaClient.get(taskGroupID);

if (result == null) {
taskLogger.logErrorWithSlf4j("MTA client returned empty result with no error.");
// unexpected
return new DefaultWorkReport(WorkStatus.FAILED, new WorkContext(),
return new DefaultWorkReport(WorkStatus.REJECTED, new WorkContext(),
new IllegalStateException("MTA client returned empty result with no error."));
}
else if (result instanceof Result.Failure<TaskGroup> failure) {
return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t());
taskLogger.logErrorWithSlf4j("MTA client returned failed result");
return new DefaultWorkReport(WorkStatus.REJECTED, workContext, failure.t());
}
else if (result instanceof Result.Success<TaskGroup> success) {
if ("Ready".equals(success.value().state()) && success.value().tasks() != null
&& "Succeeded".equals(success.value().tasks()[0].state())) {
String reportURL = "%s/hub/applications/%d/bucket/%s".formatted(serverUrl,
String reportURL = "%s/hub/applications/%d/bucket%s".formatted(serverUrl,
success.value().tasks()[0].application().id(), success.value().data().output());
taskLogger.logInfoWithSlf4j("MTA client returned success result with report url: {}", reportURL);
addParameter("reportURL", reportURL);
notificationSender.send("Migration Analysis Report Completed",
"[Migration analysis report](%s) completed.".formatted(reportURL));
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
else if ("Failed".equals(success.value().state())) {
return new DefaultWorkReport(WorkStatus.FAILED, workContext,
taskLogger.logErrorWithSlf4j("The underlying task failed, the report will not be ready");
return new DefaultWorkReport(WorkStatus.REJECTED, workContext,
new Throwable("The underlying task failed, the report will not be ready"));
}
return new DefaultWorkReport(WorkStatus.FAILED, workContext, new Throwable("The report is not ready yet."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ public WorkReport execute(WorkContext workContext) {
Result<App> result = mtaClient.get(applicationName);

if (result == null) {
taskLogger.logErrorWithSlf4j("MTA client returned empty result with no error");
// unexpected
return new DefaultWorkReport(WorkStatus.FAILED, new WorkContext(),
return new DefaultWorkReport(WorkStatus.REJECTED, new WorkContext(),
new IllegalStateException("MTA client returned empty result with no error"));
}
else if (result instanceof Result.Failure<App> failure) {
return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t());
taskLogger.logErrorWithSlf4j("MTA client returned failed result");
return new DefaultWorkReport(WorkStatus.REJECTED, workContext, failure.t());
}
else if (result instanceof Result.Success<App> success) {
addParameter("applicationID", String.valueOf(success.value().id()));
taskLogger.logInfoWithSlf4j("MTA client returned success result for getting application with id: {}",
String.valueOf(success.value().id()));
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
throw new IllegalArgumentException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ public WorkReport execute(WorkContext workContext) {
Result<TaskGroup> result = mtaClient.create(applicationID);

if (result == null) {
taskLogger.logErrorWithSlf4j("MTA client returned empty result with no error");
// unexpected
return new DefaultWorkReport(WorkStatus.FAILED, new WorkContext(),
return new DefaultWorkReport(WorkStatus.REJECTED, new WorkContext(),
new IllegalStateException("MTA client returned result with no error"));
}
else if (result instanceof Result.Failure<TaskGroup> failure) {
return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t());
taskLogger.logErrorWithSlf4j("MTA client returned failed result");
return new DefaultWorkReport(WorkStatus.REJECTED, workContext, failure.t());
}
else if (result instanceof Result.Success<TaskGroup> success) {
addParameter("taskGroupID", String.valueOf(success.value().id()));
taskLogger.logInfoWithSlf4j("MTA client returned success result for analysis task with id: {}",
String.valueOf(success.value().id()));
return new DefaultWorkReport(WorkStatus.COMPLETED, workContext);
}
throw new IllegalArgumentException();
Expand Down

0 comments on commit 6122832

Please sign in to comment.