Changes to config bundle for vnf level enhancement
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / InventoryInfoExtractor.java
index 4e27065..b45d636 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP : APPC
  * ================================================================================
  * Copyright (C) 2018 Nokia. All rights reserved.
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,66 +34,65 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
  */
 class InventoryInfoExtractor {
 
-  private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class);
+    private static final EELFLogger log = EELFManager.getInstance().getLogger(InventoryInfoExtractor.class);
 
-  InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId)  {
-    String fn = "InventoryInfoExtractor.getInventoryInfo";
+    InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) {
+        String fn = "InventoryInfoExtractor.getInventoryInfo";
 
-    VnfInfo vnfInfo = new VnfInfo();
-    vnfInfo.setVnfId(vnfId);
-    vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name"));
-    vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"));
-    vnfInfo.setIdentityUrl(getIdentityUrl(ctx,vnfInfo,vnfId));
+        VnfInfo vnfInfo = new VnfInfo();
+        vnfInfo.setVnfId(vnfId);
+        vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name"));
+        vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"));
+        vnfInfo.setIdentityUrl(getIdentityUrl(ctx, vnfInfo, vnfId));
 
-    String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count");
-    log.info(fn + "vmcount:" + vmcount);
+        String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count");
+        log.info(fn + "vmcount:" + vmcount);
 
-    int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0;
+        int vmCount = (StringUtils.isNotBlank(vmcount)) ? Integer.parseInt(vmcount) : 0;
 
-    for (int i = 0; i < vmCount; i++) {
-      processVm(ctx, vnfInfo, i);
-    }
-
-    InventoryInfo inventoryInfo = new InventoryInfo();
-    inventoryInfo.setVnfInfo(vnfInfo);
-    log.info(fn + "Inventory Output:" + inventoryInfo.toString());
+        for (int i = 0; i < vmCount; i++) {
+            processVm(ctx, vnfInfo, i);
+        }
 
-    return inventoryInfo;
-  }
+        InventoryInfo inventoryInfo = new InventoryInfo();
+        inventoryInfo.setVnfInfo(vnfInfo);
+        log.info(fn + "Inventory Output:" + inventoryInfo.toString());
 
-  private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) {
-    Vm vm = new Vm();
-    vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id"));
-    vm.setVmId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-selflink"));
-    int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count"));
-    if (vnfcCount > 0) {
-      Vnfcslist vnfc = new Vnfcslist();
-      vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name"));
-      vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type"));
-      vm.setVnfc(vnfc);
+        return inventoryInfo;
     }
-    vnfInfo.getVm().add(vm);
-  }
 
+    private void processVm(SvcLogicContext ctx, VnfInfo vnfInfo, int index) {
+        Vm vm = new Vm();
+        vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-id"));
+        vm.setVmId(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vserver-selflink"));
+        int vnfcCount = Integer.parseInt(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-count"));
+        if (vnfcCount > 0) {
+            Vnfcslist vnfc = new Vnfcslist();
+            vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-name"));
+            vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-type"));
+            vnfc.setVnfcFunctionCode(ctx.getAttribute("tmp.vnfInfo.vm[" + index + "].vnfc-function-code"));
+            vm.setVnfc(vnfc);
+        }
+        vnfInfo.getVm().add(vm);
+    }
 
-  public String getIdentityUrl(SvcLogicContext ctx, VnfInfo vnfInfo, String vnfId) {
-      String identityUrl = "";
-      for (String key : ctx.getAttributeKeySet()) {
+    public String getIdentityUrl(SvcLogicContext ctx, VnfInfo vnfInfo, String vnfId) {
+        String identityUrl = "";
+        for (String key : ctx.getAttributeKeySet()) {
             log.debug("InventoryData " + key + "=" + ctx.getAttribute(key));
-      }
-      String urlFromPayload= ctx.getAttribute("identity-url");
-      log.info("Url from payload:" + urlFromPayload);
-      String urlFromAAI=ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url");
-      log.info("Url from AAI:" + urlFromAAI);
+        }
+        String urlFromPayload = ctx.getAttribute("identity-url");
+        log.info("Url from payload:" + urlFromPayload);
+        String urlFromAAI = ctx.getAttribute("tmp.vnfInfo.cloud-region.identity-url");
+        log.info("Url from AAI:" + urlFromAAI);
+
+        if (StringUtils.isNotBlank(urlFromPayload)) {
+            identityUrl = urlFromPayload;
+        } else if (StringUtils.isNotBlank(urlFromAAI)) {
+            identityUrl = urlFromAAI;
+        }
+        return identityUrl;
 
-      if(StringUtils.isNotBlank(urlFromPayload)){
-          identityUrl=urlFromPayload;
-      }else if(StringUtils.isNotBlank(urlFromAAI)){
-          identityUrl=urlFromAAI;
-      }
-    return identityUrl;
-
-
-  }
+    }
 
 }