Artifact Handler updates for ConfigScaleOut
[appc.git] / appc-inbound / appc-artifact-handler / provider / src / main / java / org / onap / appc / artifact / handler / node / ArtifactHandlerNode.java
index 6a365e4..705aa44 100644 (file)
@@ -70,6 +70,7 @@ import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.D
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.FILE_CATEGORY;
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE;
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE;
+import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.TEMPLATE_ID;
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP;
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PARAMETER_YANG;
 import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.PD;
@@ -397,26 +398,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
                             dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
                     }
                 }
-                if (content.getString(ACTION).equals("Configure")
-                    || content.getString(ACTION).equals("ConfigModify")) {
-                    if (content.has(DOWNLOAD_DG_REFERENCE)
-                        && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) {
-                        setAttribute(context, content::getString, DOWNLOAD_DG_REFERENCE);
-                        dbservice.processDownloadDgReference(context,
-                            dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
-                    }
-                    if (StringUtils.isBlank(context.getAttribute(DOWNLOAD_DG_REFERENCE))) {
-                        context.setAttribute(DOWNLOAD_DG_REFERENCE,
-                            dbservice.getDownLoadDGReference(context));
-                    }
-                    dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context,
-                        DB_CONFIG_ACTION_DG));
-                    if (content.getString(ACTION).equals("Configure")) {
-                        dbservice.processDeviceInterfaceProtocol(context, dbservice.isArtifactUpdateRequired(context,
-                            DB_DEVICE_INTERFACE_PROTOCOL));
-                    }
-
-                }
+                processConfigTypeActions(content,dbservice,context);
                 dbservice.processDeviceAuthentication(context,
                     dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION));
 
@@ -426,38 +408,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
 
                 if (content.has(VM)
                     && content.get(VM) instanceof JSONArray) {
-                    JSONArray vmList = (JSONArray) content.get(VM);
-                    dbservice.cleanUpVnfcReferencesForVnf(context);
-                    for (int i = 0; i < vmList.length(); i++) {
-                        JSONObject vmInstance = (JSONObject) vmList.get(i);
-                        setAttribute(context, s -> String.valueOf(vmInstance.getInt(s)), VM_INSTANCE);
-                        log.info("VALUE = " + context.getAttribute(VM_INSTANCE));
-                        if (vmInstance.get(VNFC) instanceof JSONArray) {
-                            JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(VNFC);
-                            for (int k = 0; k < vnfcInstanceList.length(); k++) {
-                                JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k);
-
-                                setAttribute(context, s -> String.valueOf(vnfcInstance.getInt(s)), VNFC_INSTANCE);
-                                setAttribute(context, vnfcInstance::getString, VNFC_TYPE);
-                                setAttribute(context, vnfcInstance::getString, VNFC_FUNCTION_CODE);
-
-                                if (vnfcInstance.has(IPADDRESS_V4_OAM_VIP)) {
-                                    setAttribute(context, vnfcInstance::getString, IPADDRESS_V4_OAM_VIP);
-                                }
-                                if (vnfcInstance.has(GROUP_NOTATION_TYPE)) {
-                                    setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_TYPE);
-                                }
-                                if (vnfcInstance.has(GROUP_NOTATION_VALUE)) {
-                                    setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_VALUE);
-                                }
-                                if (content.getString(ACTION).equals("Configure")) {
-                                    dbservice.processVnfcReference(context, false);
-                                }
-                                cleanVnfcInstance(context);
-                            }
-                            context.setAttribute(VM_INSTANCE, null);
-                        }
-                    }
+                    processVmList(content, context, dbservice);
                 }
 
 
@@ -481,6 +432,73 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
         return true;
     }
 
+    public void processConfigTypeActions(JSONObject content, DBService dbservice, SvcLogicContext context)throws Exception {
+        if (content.getString(ACTION).equals("Configure")
+                || content.getString(ACTION).equals("ConfigModify") || content.getString(ACTION).equals("ConfigScaleOut")) {
+                if (content.has(DOWNLOAD_DG_REFERENCE)
+                    && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) {
+                    setAttribute(context, content::getString, DOWNLOAD_DG_REFERENCE);
+                    dbservice.processDownloadDgReference(context,
+                        dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
+                }
+                if (StringUtils.isBlank(context.getAttribute(DOWNLOAD_DG_REFERENCE))) {
+                    context.setAttribute(DOWNLOAD_DG_REFERENCE,
+                        dbservice.getDownLoadDGReference(context));
+                }
+                dbservice.processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context,
+                    DB_CONFIG_ACTION_DG));
+                if (content.getString(ACTION).equals("Configure") || content.getString(ACTION).equals("ConfigScaleOut")) {
+                    boolean isPresent=dbservice.isArtifactUpdateRequired(context,DB_DEVICE_INTERFACE_PROTOCOL);
+                    if (content.getString(ACTION).equals("Configure") || (content.getString(ACTION).equals("ConfigScaleOut") && !isPresent))
+                        dbservice.processDeviceInterfaceProtocol(context, isPresent);
+                }
+
+            }
+
+    }
+
+    public void processVmList(JSONObject content, SvcLogicContext context, DBService dbservice) throws Exception{
+        JSONArray vmList = (JSONArray) content.get(VM);
+        dbservice.cleanUpVnfcReferencesForVnf(context);
+        for (int i = 0; i < vmList.length(); i++) {
+            JSONObject vmInstance = (JSONObject) vmList.get(i);
+            setAttribute(context, s -> String.valueOf(vmInstance.getInt(s)), VM_INSTANCE);
+            log.info("VALUE = " + context.getAttribute(VM_INSTANCE));
+            String templateId = vmInstance.optString(TEMPLATE_ID);
+            if (StringUtils.isNotBlank(templateId)) {
+                setAttribute(context, vmInstance::optString, TEMPLATE_ID);
+            }
+            if (vmInstance.get(VNFC) instanceof JSONArray) {
+                JSONArray vnfcInstanceList = (JSONArray) vmInstance.get(VNFC);
+                for (int k = 0; k < vnfcInstanceList.length(); k++) {
+                    JSONObject vnfcInstance = (JSONObject) vnfcInstanceList.get(k);
+
+                    setAttribute(context, s -> String.valueOf(vnfcInstance.getInt(s)), VNFC_INSTANCE);
+                    setAttribute(context, vnfcInstance::getString, VNFC_TYPE);
+                    setAttribute(context, vnfcInstance::getString, VNFC_FUNCTION_CODE);
+
+                    if (vnfcInstance.has(IPADDRESS_V4_OAM_VIP)) {
+                        setAttribute(context, vnfcInstance::getString, IPADDRESS_V4_OAM_VIP);
+                    }
+                    if (vnfcInstance.has(GROUP_NOTATION_TYPE)) {
+                        setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_TYPE);
+                    }
+                    if (vnfcInstance.has(GROUP_NOTATION_VALUE)) {
+                        setAttribute(context, vnfcInstance::getString, GROUP_NOTATION_VALUE);
+                    }
+                    if (content.getString(ACTION).equals("Configure")
+                            || content.getString(ACTION).equals("ConfigScaleOut")) {
+                        dbservice.processVnfcReference(context, false);
+                    }
+                    cleanVnfcInstance(context);
+                }
+                context.setAttribute(VM_INSTANCE, null);
+                context.setAttribute(TEMPLATE_ID, null);
+            }
+        }
+
+    }
+
     private void cleanArtifactInstanceData(SvcLogicContext context) {
         context.setAttribute(ARTIFACT_NAME, null);
         context.setAttribute(FILE_CATEGORY, null);