diff options
author | Elena Kuleshov <evn@att.com> | 2019-04-08 01:17:53 -0400 |
---|---|---|
committer | Elena Kuleshov <evn@att.com> | 2019-04-08 10:04:51 -0400 |
commit | eeaa95784e2bed48c82f8a5d2c8ed34cc57a37fd (patch) | |
tree | 634cc459e6fb8946b7c30170f3e9458b6bd71627 /mso-api-handlers | |
parent | 2c8c818a1815758e14e88fe74b782c3e8be8ac4b (diff) |
Workflow Recipe Lookup
Workflow Recipe Lookup and related Catalog Beans
Change-Id: Ib1c3493106658d139861d2620dfb9cb382115744
Issue-ID: SO-1728
Signed-off-by: Kuleshov, Elena <evn@att.com>
Diffstat (limited to 'mso-api-handlers')
4 files changed, 77 insertions, 16 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java index 1580c9fb34..51962f2b9e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/InstanceManagement.java @@ -29,9 +29,12 @@ import org.apache.http.HttpStatus; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.RequestClientParameter; import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException; import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.db.catalog.beans.Workflow; +import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.exceptions.ValidationException; @@ -72,6 +75,9 @@ public class InstanceManagement { private RequestsDbClient infraActiveRequestsClient; @Autowired + private CatalogDbClient catalogDbClient; + + @Autowired private MsoRequest msoRequest; @Autowired @@ -156,7 +162,8 @@ public class InstanceManagement { workflowUuid = instanceIdMap.get("workflowUuid"); } - RecipeLookupResult recipeLookupResult = getCustomWorkflowUri(workflowUuid); + RecipeLookupResult recipeLookupResult = getInstanceManagementWorkflowRecipe(currentActiveReq, workflowUuid); + String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, true); serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir); @@ -196,11 +203,43 @@ public class InstanceManagement { .errorInfo(errorLoggerInfo).build(); } return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope); - } + } + + private RecipeLookupResult getInstanceManagementWorkflowRecipe(InfraActiveRequests currentActiveReq, String workflowUuid) throws ApiException { + RecipeLookupResult recipeLookupResult = null; + + try { + recipeLookupResult = getCustomWorkflowUri(workflowUuid); + } catch (IOException e) { + ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e) + .errorInfo(errorLoggerInfo).build(); + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage()); + throw validateException; + } + + if (recipeLookupResult == null) { + ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + RecipeNotFoundException recipeNotFoundExceptionException = new RecipeNotFoundException.Builder("Recipe could not be retrieved from catalog DB.", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_GENERAL_SERVICE_ERROR) + .errorInfo(errorLoggerInfo).build(); + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, recipeNotFoundExceptionException.getMessage()); + throw recipeNotFoundExceptionException; + } + + return recipeLookupResult; + } - private RecipeLookupResult getCustomWorkflowUri(String workflowUuid) { + private RecipeLookupResult getCustomWorkflowUri(String workflowUuid) throws IOException { - RecipeLookupResult recipeLookupResult = new RecipeLookupResult("/mso/async/services/VnfInPlaceUpdate", 180); - return recipeLookupResult; + String recipeUri = null; + Workflow workflow = catalogDbClient.findWorkflowByArtifactUUID(workflowUuid); + if (workflow == null) { + return null; + } + else { + String workflowName = workflow.getArtifactName(); + recipeUri = "/mso/async/services/" + workflowName; + } + return new RecipeLookupResult(recipeUri, 180); } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java index b70322cecf..e694120405 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/InstanceManagementTest.java @@ -50,7 +50,6 @@ import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.logger.HttpHeadersConstants; import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -67,9 +66,6 @@ public class InstanceManagementTest extends BaseTest{ private final ObjectMapper mapper = new ObjectMapper(); private ObjectMapper errorMapper = new ObjectMapper(); - @Autowired - private InstanceManagement instanceManagement; - @Value("${wiremock.server.port}") private String wiremockPort; @@ -154,15 +150,14 @@ public class InstanceManagementTest extends BaseTest{ @Test public void executeCustomWorkflow() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate")) + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/testingWorkflow")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]" + - "nfRole=GR-API-DEFAULT&action=inPlaceSoftwareUpdate")) - .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .withBody(getWiremockResponseForCatalogdb("vnfRecipeInPlaceUpdate_Response.json")) - .withStatus(org.apache.http.HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/workflow/search/findByArtifactUUID[?]artifactUUID=71526781-e55c-4cb7-adb3-97e09d9c76be")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("workflow_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_Response.json new file mode 100644 index 0000000000..6e358f7e17 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/workflow_Response.json @@ -0,0 +1,4 @@ +{ + "artifactUUID": "71526781-e55c-4cb7-adb3-97e09d9c76be", + "artifactName": "testingWorkflow" +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql index 5e8713681b..2c03173b16 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql @@ -1466,4 +1466,27 @@ create table if not exists model ( PRIMARY KEY (`ID`), CONSTRAINT uk1_model UNIQUE (`MODEL_TYPE`, `MODEL_VERSION_ID`), FOREIGN KEY (`RECIPE`) REFERENCES `model_recipe` (`MODEL_ID`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=latin1;
\ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +CREATE TABLE IF NOT EXISTS `workflow` ( + `ID` int(11) NOT NULL AUTO_INCREMENT, + `ARTIFACT_UUID` varchar(200) NOT NULL, + `ARTIFACT_NAME` varchar(200) NOT NULL, + `NAME` varchar(200) NOT NULL, + `OPERATION_NAME` varchar(200) DEFAULT NULL, + `VERSION` double NOT NULL, + `DESCRIPTION` varchar(1200) DEFAULT NULL, + `BODY` longtext DEFAULT NULL, + `RESOURCE_TARGET` varchar(200) NOT NULL, + `SOURCE` varchar(200) NOT NULL, + `TIMEOUT_MINUTES` int(11) DEFAULT NULL, + `ARTIFACT_CHECKSUM` varchar(200) DEFAULT 'MANUAL RECORD', + `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`ID`), + UNIQUE KEY `UK_workflow` (`ARTIFACT_UUID`,`NAME`,`VERSION`,`SOURCE`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + + + + + |