From 49f38ff32c2323f5460e18ee300eff015bbd8772 Mon Sep 17 00:00:00 2001 From: eyalholz Date: Thu, 27 Jul 2017 20:37:54 +0300 Subject: fixed for defect SO-70 - recipe lookup mechanism doesn't allow to define default recipe mapping for any 'source' at level of 'service' and 'network' resources. Change-Id: I42dafa343e2e65c6e892c21de5f3f1131890b24e Signed-off-by: eyalholz --- .../mso/apihandlerinfra/ServiceInstances.java | 65 +++++++++++++--------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java index 317859da0e..988d72cc6f 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/ServiceInstances.java @@ -654,33 +654,35 @@ public class ServiceInstances { // SERVICE REQUEST // Construct the default service name // TODO need to make this a configurable property - String defaultServiceName = msoRequest.getRequestInfo().getSource() + "_DEFAULT"; + String sourceDefaultServiceName = msoRequest.getRequestInfo().getSource() + "_DEFAULT"; + String defaultService = "*"; Service serviceRecord = null; - if(msoRequest.getALaCarteFlag()){ - serviceRecord = db.getServiceByName(defaultServiceName); - }else{ - serviceRecord = db.getServiceByVersionAndInvariantId(msoRequest.getModelInfo().getModelInvariantId(), msoRequest.getModelInfo().getModelVersion()); - } int serviceId; ServiceRecipe recipe = null; - if(serviceRecord !=null){ - serviceId = serviceRecord.getId(); - recipe = db.getServiceRecipe(serviceId, action.name()); + + //if an aLaCarte flag was Not sent in the request, look first if there is a custom recipe for the specific model version + if(!msoRequest.getALaCarteFlag()){ + serviceRecord = db.getServiceByVersionAndInvariantId(msoRequest.getModelInfo().getModelInvariantId(), msoRequest.getModelInfo().getModelVersion()); + if(serviceRecord !=null){ + serviceId = serviceRecord.getId(); + recipe = db.getServiceRecipe(serviceId, action.name()); + } } - //if an aLaCarte flag was sent in the request, throw an error if the recipe was not found - RequestParameters reqParam = msoRequest.getServiceInstancesRequest().getRequestDetails().getRequestParameters(); - if(reqParam!=null && reqParam.isALaCarteSet() && recipe==null){ - return null; - }else if (recipe == null) { //aLaCarte wasn't sent, so we'll try the default - serviceRecord = db.getServiceByName(defaultServiceName); - serviceId = serviceRecord.getId(); - recipe = db.getServiceRecipe(serviceId, action.name()); + + if (recipe == null) { + //find source(initiator) default recipe + recipe = db.getServiceRecipeByServiceNameAndAction(sourceDefaultServiceName, action.name()); + } + if (recipe == null) { + //find default recipe + recipe = db.getServiceRecipeByServiceNameAndAction(defaultService, action.name()); } if(recipe==null){ return null; } return new RecipeLookupResult (recipe.getOrchestrationUri (), recipe.getRecipeTimeout ()); + } @@ -787,27 +789,38 @@ public class ServiceInstances { private RecipeLookupResult getNetworkUri (CatalogDatabase db, MsoRequest msoRequest, Action action) throws Exception { - String defaultNetworkType = msoRequest.getRequestInfo().getSource() + "_DEFAULT"; + String sourceDefaultNetworkType = msoRequest.getRequestInfo().getSource() + "_DEFAULT"; + String defaultNetworkType = "*"; String modelName = msoRequest.getModelInfo().getModelName(); Recipe recipe = null; - if(msoRequest.getALaCarteFlag()){ - recipe = db.getNetworkRecipe(defaultNetworkType, action.name()); - }else{ + //if an aLaCarte flag was Not sent in the request, look first if there is a custom recipe for the specific ModelCustomizationId + if(!msoRequest.getALaCarteFlag()){ + String networkType = null; + if(msoRequest.getModelInfo().getModelCustomizationId()!=null){ NetworkResource networkResource = db.getNetworkResourceByModelCustUuid(msoRequest.getModelInfo().getModelCustomizationId()); if(networkResource!=null){ - recipe = db.getNetworkRecipe(networkResource.getNetworkType(), action.name()); + networkType = networkResource.getNetworkType(); }else{ throw new ValidationException("no catalog entry found"); } }else{ //ok for version < 3 - recipe = db.getNetworkRecipe(modelName, action.name()); - } - if(recipe == null){ - recipe = db.getNetworkRecipe(defaultNetworkType, action.name()); + networkType = modelName; } + + //find latest version Recipe for the given networkType and action + recipe = db.getNetworkRecipe(networkType, action.name()); + } + + if(recipe == null){ + //find source(initiator) default recipe + recipe = db.getNetworkRecipe(sourceDefaultNetworkType, action.name()); + } + if(recipe == null){ + //find default recipe + recipe = db.getNetworkRecipe(defaultNetworkType, action.name()); } if (recipe == null) { return null; -- cgit 1.2.3-korg