Fix the retrival of resource recipe 18/72518/1
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Mon, 12 Nov 2018 12:05:37 +0000 (17:35 +0530)
committerSeshu Kumar M <seshu.kumar.m@huawei.com>
Tue, 13 Nov 2018 09:52:09 +0000 (09:52 +0000)
Fix the retrival of resource recipe.

Change-Id: Iaec1046f487ce61b995d61414dbe4229e8a51115
Issue-ID: SO-1197
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
(cherry picked from commit 1c831520f085527c9525d8a757e9c0ccddae0219)

adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/NetworkRecipe.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/VnfRecipe.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ArRecipeRepository.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/NetworkRecipeRepository.java
mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/VnfRecipeRepository.java

index eaf3e12..36e00ad 100644 (file)
@@ -73,6 +73,7 @@ import org.onap.so.db.catalog.beans.Service;
 import org.onap.so.db.catalog.beans.ToscaCsar;
 import org.onap.so.db.catalog.beans.VfModule;
 import org.onap.so.db.catalog.beans.VfModuleCustomization;
+import org.onap.so.db.catalog.beans.VnfRecipe;
 import org.onap.so.db.catalog.beans.VnfResource;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
@@ -116,6 +117,7 @@ import java.util.List;
 public class CatalogDbAdapterRest {
     protected static Logger logger = LoggerFactory.getLogger(CatalogDbAdapterRest.class);
     private static final boolean IS_ARRAY = true;
+    private static final String NETWORK_SERVICE = "network service";
 
     @Autowired
     private VnfCustomizationRepository vnfCustomizationRepo;
@@ -563,15 +565,32 @@ public class CatalogDbAdapterRest {
             if (rmUuid != null && !"".equals(rmUuid)) {
                 logger.debug("Query recipe by resource model uuid: {}", rmUuid);
                 //check vnf and network and ar, the resource could be any resource.
+                Recipe recipe = null;
+
                 VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
-                Recipe recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction(vnf.getModelName(), action);
+                if (vnf != null) {
+                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion());
+
+                    // for network service fetch the default recipe
+                    if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
+                        recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
+                    }
+                }
+
+
                 if (null == recipe) {
                     NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
-                    recipe = networkRecipeRepo.findFirstByModelNameAndAction(nResource.getModelName(), action);
+                    recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, vnf.getModelVersion());
+
+                    // for network fetch the default recipe
+                    if (recipe == null) {
+                        recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
+                    }
                 }
+
                 if (null == recipe) {
                     AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
-                    recipe = arRecipeRepo.findByModelNameAndAction(arResource.getModelName(), action);
+                    recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion());
                 }
                 if (recipe != null) {
                     QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
index 73056e2..51bcd54 100644 (file)
@@ -59,6 +59,9 @@ public class NetworkRecipe implements Serializable, Recipe {
        @Column(name = "RECIPE_TIMEOUT")
        private Integer recipeTimeout;
 
+       @Column(name = "VERSION_STR")
+       private String versionStr;
+
        @BusinessKey
        @Column(name = "SERVICE_TYPE")
        private String serviceType;
@@ -171,4 +174,12 @@ public class NetworkRecipe implements Serializable, Recipe {
                sb.append(",networkParamXSD=" + paramXsd);
                return sb.toString();
        }
+
+       public String getVersionStr() {
+               return versionStr;
+       }
+
+       public void setVersionStr(String versionStr) {
+               this.versionStr = versionStr;
+       }
 }
index aef2ac5..ab2eb62 100644 (file)
@@ -71,6 +71,9 @@ public class VnfRecipe implements Serializable, Recipe {
        @Column(name = "RECIPE_TIMEOUT")
        private Integer recipeTimeout;
 
+       @Column(name = "VERSION_STR")
+       private String versionStr;
+
        @BusinessKey
        @Column(name = "SERVICE_TYPE")
        private String serviceType;
@@ -184,4 +187,12 @@ public class VnfRecipe implements Serializable, Recipe {
        public Date getCreated() {
                return created;
        }
+
+       public String getVersionStr() {
+               return versionStr;
+       }
+
+       public void setVersionStr(String versionStr) {
+               this.versionStr = versionStr;
+       }
 }
index 1241dac..22f3ccb 100644 (file)
@@ -28,4 +28,5 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 public interface ArRecipeRepository extends JpaRepository<ArRecipe, String> {
 
        ArRecipe findByModelNameAndAction(String modelName, String action);
+       ArRecipe findByModelNameAndActionAndVersion(String modelName, String action, String version);
 }
index 10290b5..c74fade 100644 (file)
@@ -27,4 +27,5 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource;
 @RepositoryRestResource(collectionResourceRel = "networkRecipe", path = "networkRecipe")
 public interface NetworkRecipeRepository extends JpaRepository<NetworkRecipe, String> {
        NetworkRecipe findFirstByModelNameAndAction(String modelName, String action);
+       NetworkRecipe findFirstByModelNameAndActionAndVersionStr(String modelName, String action, String versionStr);
 }
\ No newline at end of file
index dbc86cb..b99e2bd 100644 (file)
@@ -7,9 +7,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -29,4 +29,6 @@ public interface VnfRecipeRepository extends JpaRepository<VnfRecipe, String> {
        VnfRecipe findVnfRecipeByServiceTypeAndAction(String serviceType, String action);
        
        VnfRecipe findFirstVnfRecipeByNfRoleAndAction(String nfRole, String action);
+
+       VnfRecipe findFirstVnfRecipeByNfRoleAndActionAndVersionStr(String nfRole, String action, String versionStr);
 }
\ No newline at end of file