Workflow Recipe Lookup
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / InstanceManagement.java
index 1580c9f..51962f2 100644 (file)
@@ -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);          
        }       
 }