diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java index 7fea81417..3615f73e4 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/CreateApplicationTask.java @@ -58,7 +58,14 @@ public WorkReport execute(WorkContext workContext) { Identity identity = null; if (identityName != null) { - identity = mtaClient.getIdentity(identityName); + Result identityResult = mtaClient.getIdentity(identityName); + if (identityResult instanceof Result.Failure failure) { + taskLogger.logErrorWithSlf4j("MTA client returned failed result to get identity: {}", identityName); + return new DefaultWorkReport(WorkStatus.FAILED, workContext, failure.t()); + } + else { + identity = ((Result.Success) identityResult).value(); + } } Result result = mtaClient diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java index 4858833f8..e9c8c8848 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClient.java @@ -54,7 +54,7 @@ interface MTAApplicationClient { Result create(App app); - Identity getIdentity(String name); + Result getIdentity(String name); } diff --git a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClientImpl.java b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClientImpl.java index 644cdd17c..252d174c1 100644 --- a/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClientImpl.java +++ b/prebuilt-tasks/src/main/java/com/redhat/parodos/tasks/migrationtoolkit/MTAApplicationClientImpl.java @@ -84,7 +84,7 @@ public Result get(String name) { } @Override - public Identity getIdentity(String name) { + public Result getIdentity(String name) { // identities in MTA have unique constraints on name. try { HttpResponse getAll = client.send( @@ -98,14 +98,14 @@ public Identity getIdentity(String name) { Optional identity = identities.stream().filter(v -> v.name().equals(name)).findFirst(); if (identity.isPresent()) { - return identity.get(); + return new Result.Success<>(identity.get()); } else { - throw new NotFoundException("failed to find identity by name " + name); + return new Result.Failure<>(new NotFoundException("failed to find identity by name " + name)); } } catch (IOException | InterruptedException e) { - return null; + return new Result.Failure<>(e); } } diff --git a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java index 801aa577d..a3f746cb2 100644 --- a/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java +++ b/workflow-examples/src/main/java/com/redhat/parodos/examples/prebuilt/migrationtoolkit/MigrationAssessmentWorkflow.java @@ -86,7 +86,7 @@ WorkFlowOption defaultOption() { @Bean(name = "AnalyzeApplicationAssessment") @Assessment(parameters = { @Parameter(key = "repositoryURL", description = "The repository with the code to analyze", - type = WorkParameterType.TEXT, optional = false), + type = WorkParameterType.URL, optional = false), @Parameter(key = "applicationName", description = "The name of the application to analyze", type = WorkParameterType.TEXT, optional = false), @Parameter(key = "branch", description = "The repository branch to analyze", type = WorkParameterType.TEXT, diff --git a/workflow-examples/src/test/java/com/redhat/parodos/examples/move2kube/task/utils/Move2KubeUtilsTest.java b/workflow-examples/src/test/java/com/redhat/parodos/examples/move2kube/task/utils/Move2KubeUtilsTest.java new file mode 100644 index 000000000..1d6886c44 --- /dev/null +++ b/workflow-examples/src/test/java/com/redhat/parodos/examples/move2kube/task/utils/Move2KubeUtilsTest.java @@ -0,0 +1,24 @@ +package com.redhat.parodos.examples.move2kube.task.utils; + +import java.net.URISyntaxException; + +import com.redhat.parodos.examples.move2kube.utils.Move2KubeUtils; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class Move2KubeUtilsTest { + + private static final String WORKSPACE_ID = "workspace-id"; + + private static final String PROJECT_ID = "project-id"; + + private static final String OUTPUT_ID = "output-id"; + + @Test + void testGetPath() throws URISyntaxException { + String expectedResponse = "http://test.com/workspaces/workspace-id/projects/project-id/outputs/output-id"; + assertEquals(expectedResponse, Move2KubeUtils.getPath("http://test.com", WORKSPACE_ID, PROJECT_ID, OUTPUT_ID)); + } + +}