From eeaa95784e2bed48c82f8a5d2c8ed34cc57a37fd Mon Sep 17 00:00:00 2001 From: Elena Kuleshov Date: Mon, 8 Apr 2019 01:17:53 -0400 Subject: Workflow Recipe Lookup Workflow Recipe Lookup and related Catalog Beans Change-Id: Ib1c3493106658d139861d2620dfb9cb382115744 Issue-ID: SO-1728 Signed-off-by: Kuleshov, Elena --- .../so/apihandlerinfra/InstanceManagement.java | 49 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org') 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; @@ -71,6 +74,9 @@ public class InstanceManagement { @Autowired private RequestsDbClient infraActiveRequestsClient; + @Autowired + private CatalogDbClient catalogDbClient; + @Autowired private MsoRequest msoRequest; @@ -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); } } -- cgit 1.2.3-korg