Add feature to support reboot lcm command 01/55701/2
authorMei Su <ms6523@att.com>
Tue, 3 Jul 2018 12:56:08 +0000 (08:56 -0400)
committerMei Su <ms6523@att.com>
Tue, 3 Jul 2018 21:52:58 +0000 (17:52 -0400)
Add method getIdentityUrl to fetch identity-url

Issue-ID: APPC-1044
Change-Id: I8fe6f774754e04b0329fe3e735f4b927d6db10bc
Signed-off-by: Mei Su <ms6523@att.com>
appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/aai/AaiService.java
appc-outbound/appc-aai-client/provider/src/main/java/org/onap/appc/aai/client/node/AAIResourceNode.java
appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/MockAaiService.java
appc-outbound/appc-aai-client/provider/src/test/java/org/onap/appc/aai/client/aai/TestAaiService.java

index 0f0f5a4..b10abc4 100644 (file)
@@ -149,6 +149,7 @@ public class AaiService {
             SvcLogicContext vmCtx = readResource(resourceKey, PARAM_VM_INFO, PARAM_VSERVER);
             ctx.setAttribute(prefix + "vm.prov-status", vmCtx.getAttribute("vmInfo.prov-status"));
             ctx.setAttribute(prefix + "vm.vserver-name", vmCtx.getAttribute("vmInfo.vserver-name"));
+            ctx.setAttribute(prefix + "vm.vserver-selflink", vmCtx.getAttribute("vmInfo.vserver-selflink"));
 
             String relLen = vmCtx.getAttribute("vmInfo.relationship-list.relationship_length");
             int relationshipLength = 0;
@@ -399,7 +400,7 @@ public class AaiService {
         if (SvcLogicResource.QueryStatus.SUCCESS.equals(response)) {
             log.info("Added VNFC SUCCESSFULLY " + vnfcName);
         } else if (SvcLogicResource.QueryStatus.FAILURE.equals(response)) {
-            throw new AaiServiceInternalException("VNFC Add failed for for vnfc_name " + vnfcName);
+            throw new AaiServiceInternalException("VNFC Add failed for vnfc_name " + vnfcName);
         }
     }
 
@@ -760,4 +761,26 @@ public class AaiService {
         log.info("End - getModelVersionInfo");
 
     }
+
+    public void getIdentityUrl(Map<String, String> params, SvcLogicContext ctx) throws Exception{
+        log.info("Recieved getIdentityUrl call with params : "+params);
+        String prefix = params.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX);
+        prefix = StringUtils.isNotBlank(prefix) ? (prefix + ".") : "";
+
+        String cloudOwner = params.get("cloudOwner");
+        String cloudRegionId = params.get("cloudRegionId");
+        // per comment from git review, we need to sanitize the two parameters 
+        // to avoid security issues
+        cloudOwner = cloudOwner.replaceAll("'", "");
+        cloudRegionId = cloudRegionId.replaceAll("'", "");
+        log.debug("cloudOwner" +cloudOwner +"," +"cloudRegionId"+ cloudRegionId);
+        String resourceKey = "cloud-region.cloud-owner = '" + cloudOwner +
+                "' AND cloud-region.cloud-region-id = '" + cloudRegionId + "'";
+        String queryPrefix ="urlInfo";
+        String resourceType = "cloud-region";
+        SvcLogicContext urlCtx = readResource(resourceKey, queryPrefix, resourceType);
+        log.info("IdentityUrl: "+urlCtx.getAttribute("urlInfo.identity-url"));
+        ctx.setAttribute(prefix+"cloud-region.identity-url", urlCtx.getAttribute("urlInfo.identity-url"));
+    }
 }
index 99949e9..cc084d4 100644 (file)
@@ -47,6 +47,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
     private static final String STR_TENANT_ID = "].tenant-id";
     private static final String STR_CLOUD_OWNER = "].cloud-owner";
     private static final String STR_CLOUD_REGION_ID = "].cloud-region-id";
+    private static final String STR_VSERVER_SELFLINK ="].vserver-selflink";
     private static final String STR_TMP_VNF_INFO = "tmp.vnfInfo.vm[";
 
     private static final String PARAM_VSERVER_ID = "vserverId";
@@ -54,6 +55,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
     private static final String PARAM_CLOUD_OWNER = "cloudOwner";
     private static final String PARAM_CLOUD_REGION_ID = "cloudRegionId";
     private static final String PARAM_VSERVER_NAME = "vserver-name";
+    private static final String PARAM_VSERVER_SELFLINK = "vserver-selflink";
     private static final String PARAM_VNFC_NAME = "vnfcName";
 
     private static final String ATTR_VNF_VM_COUNT = "vnf.vm-count";
@@ -122,6 +124,7 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
                 paramsVm.put(PARAM_TENANT_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_TENANT_ID));
                 paramsVm.put(PARAM_CLOUD_OWNER, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_OWNER));
                 paramsVm.put(PARAM_CLOUD_REGION_ID, ctx.getAttribute(responsePrefix + "vm[" + i + STR_CLOUD_REGION_ID));
+                paramsVm.put(PARAM_VSERVER_SELFLINK, ctx.getAttribute(responsePrefix + "vm[" + i + STR_VSERVER_SELFLINK));
                 paramsVm.put(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX,
                     inParams.get(AppcAaiClientConstant.INPUT_PARAM_RESPONSE_PREFIX));
 
@@ -136,6 +139,9 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
                 // Parameters returned by getVMInfo
                 vserverMap.put(PARAM_VSERVER_NAME, vmServerCtx.getAttribute(responsePrefix + "vm.vserver-name"));
                 vserverMap.put("vf-module-id", vmServerCtx.getAttribute(responsePrefix + "vm.vf-module-id"));
+                vserverMap.put("vserver-selflink", vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
+                
+                log.info("VSERVER-LINK VALUE:" + vmServerCtx.getAttribute(responsePrefix + "vm.vserver-selflink"));
 
                 // as Per 17.07 requirements we are supporting only one VNFC per VM.
 
@@ -473,12 +479,14 @@ public class AAIResourceNode implements SvcLogicJavaPlugin {
         String tenantId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_TENANT_ID);
         String cloudOwner = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_OWNER);
         String cloudRegionId = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_CLOUD_REGION_ID);
+        String vserverSelflink = ctx.getAttribute(STR_TMP_VNF_INFO + arrayIndex + STR_VSERVER_SELFLINK);
         log.info("setVmParams()::tenantId=" + tenantId + " cloudOwner=" + cloudOwner + " cloudRegiodId= "
             + cloudRegionId);
         params.put(PARAM_VSERVER_ID, vServerId);
         params.put(PARAM_TENANT_ID, tenantId);
         params.put(PARAM_CLOUD_OWNER, cloudOwner);
         params.put(PARAM_CLOUD_REGION_ID, cloudRegionId);
+        params.put(PARAM_VSERVER_SELFLINK, vserverSelflink);
         log.info("setVmParams()::setVmParamsVM level action:" + params.toString());
         return params;
     }
index 55fd392..8dec463 100644 (file)
@@ -57,6 +57,8 @@ public class MockAaiService extends AaiService {
             populateVmContext(resourceContext, prefix);
         } else if ("vnfc".equals(resourceType)) {
             populateVnfcContext(resourceContext, prefix);
+        } else if ("cloud-region".equals(resourceType)) {
+            resourceContext.setAttribute(prefix + ".identity-url", "TestUrl");
         }
 
         return resourceContext;
index fbfe40b..0f3d84c 100644 (file)
@@ -381,4 +381,21 @@ public class TestAaiService {
         assertEquals (groupNotationValue4,"gn1");
 
     }
+
+    @Test
+    public void testgetIdentityUrl() throws Exception {
+
+        MockAaiService mockAai = new MockAaiService(aaiClient);
+
+        Map<String, String> inParams = new HashMap<String, String>();
+        inParams.put("responsePrefix", "tmp.vnfInfo");
+        inParams.put("cloudOwner", "testCloudOwner");
+        inParams.put("cloudRegionId", "testCloudRegionId");
+
+        SvcLogicContext ctx = new SvcLogicContext();
+        mockAai.getIdentityUrl(inParams, ctx);
+        assertEquals(ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url"), "TestUrl");
+
+    }
+
 }