diff options
Diffstat (limited to 'appc-inbound/appc-artifact-handler')
6 files changed, 112 insertions, 56 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java index 5afe4e501..9b2d80d3f 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/dbservices/DBService.java @@ -388,13 +388,19 @@ public class DBService { log.info(fn + "Starting DB operation for Vnfc Reference " + isUpdate); String key = ""; int vm_instance = -1; + String templateId=""; + if (context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE) != null) { vm_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VM_INSTANCE)); } int vnfc_instance = -1; if (context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE) != null) { vnfc_instance = Integer.parseInt(context.getAttribute(SdcArtifactHandlerConstants.VNFC_INSTANCE)); + } + if (context.getAttribute(SdcArtifactHandlerConstants.TEMPLATE_ID) != null) { + templateId = context.getAttribute(SdcArtifactHandlerConstants.TEMPLATE_ID); } + QueryStatus status = null; if (isUpdate) { key = "update " + SdcArtifactHandlerConstants.DB_VNFC_REFERENCE + " set VM_INSTANCE = " + vm_instance @@ -413,7 +419,8 @@ public class DBService { + " , VM_INSTANCE = $" + SdcArtifactHandlerConstants.VM_INSTANCE + " , VNFC_INSTANCE = $" + SdcArtifactHandlerConstants.VNFC_INSTANCE + " , VNFC_TYPE = $" + SdcArtifactHandlerConstants.VNFC_TYPE + " , VNFC_FUNCTION_CODE = $" - + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , GROUP_NOTATION_TYPE = $" + + SdcArtifactHandlerConstants.VNFC_FUNCTION_CODE + " , TEMPLATE_ID = $" + + SdcArtifactHandlerConstants.TEMPLATE_ID + " , GROUP_NOTATION_TYPE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_TYPE + " , IPADDRESS_V4_OAM_VIP = $" + SdcArtifactHandlerConstants.IPADDRESS_V4_OAM_VIP + " , GROUP_NOTATION_VALUE = $" + SdcArtifactHandlerConstants.GROUP_NOTATION_VALUE; diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java index 6a365e4f5..705aa4439 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java @@ -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); diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java index 4f4525dd1..5051bb136 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java @@ -62,6 +62,7 @@ public class SdcArtifactHandlerConstants { public static final String IPADDRESS_V4_OAM_VIP = "ipaddress-v4-oam-vip"; public static final String GROUP_NOTATION_TYPE = "group-notation-type"; public static final String GROUP_NOTATION_VALUE = "group-notation-value"; + public static final String TEMPLATE_ID = "template-id"; public static final String REFERENCE = "reference"; public static final String VNFC_INSTANCE = "vnfc-instance"; public static final String DEVICE_PROTOCOL = "device-protocol"; diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java index f123fcc55..0ea4a4428 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java @@ -182,7 +182,7 @@ public class DBServiceTest { MockDBService dbService = MockDBService.initialise(); SvcLogicContext ctx = new SvcLogicContext(); ctx.setAttribute("test", "test"); - boolean isUpdate = true; + boolean isUpdate = false; dbService.processVnfcReference(ctx, isUpdate); } diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java index caec09172..90b02b6c3 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockDBService.java @@ -48,4 +48,3 @@ public class MockDBService extends DBService { } } - diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java index c7f18d777..0f0f0a0a2 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -174,5 +174,36 @@ public class ArtifactHandlerNodeTest { String yangContents = "SomeContent"; Whitebox.invokeMethod(artifactHandlerNode, "updateYangContents", artifactId, yangContents); } - + + @Test + public void testProcessVmList() throws Exception{ + String contentStr = "{\r\n\t\"action\": \"ConfigScaleOut\",\r\n\t\"action-level\": \"VNF\",\r\n\t\"scope\": " + + "{\r\n\t\t\"vnf-type\": \"ScaleOutVNF\",\r\n\t\t\"vnfc-type\": \"\"\r\n\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\": " + + "[\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id1\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t1\",\r\n\t\t\t\"vnfc-function-code\": " + + "\"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": " + + "\"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{ \r\n\t\t\"vm-instance\": 1,\r\n\t\t\"template-id\":\"id2\",\r\n\t\t\r\n\t\t\"vnfc\": [{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": " + + "\"t1\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": \"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"N\",\r\n\t\t\t\"group-notation-value\": " + + "\"GNValue\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"vnfc-instance\": 2,\r\n\t\t\t\"vnfc-type\": \"t2\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": " + + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t},\r\n\t{\r\n\t\t\"vm-instance\": 2,\r\n\t\t\"template-id\":\"id3\",\r\n\t\t\"vnfc\": " + + "[{\r\n\t\t\t\"vnfc-instance\": 1,\r\n\t\t\t\"vnfc-type\": \"t3\",\r\n\t\t\t\"vnfc-function-code\": \"Testdbg\",\r\n\t\t\t\"group-notation-type\": " + + "\"GNType\",\r\n\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\"group-notation-value\": \"GNValue\"\r\n\t\t}]\r\n\t}],\r\n\t\"device-protocol\": " + + "\"TEST-PROTOCOL\",\r\n\t\"user-name\": \"Testnetconf\",\r\n\t\"port-number\": \"22\",\r\n\t\"artifact-list\": [{\r\n\t\t\"artifact-name\": \"Testv_template.json\",\r\n\t\t\"artifact-type\": " + + "\"Testconfig_template\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": \"TESTv_parameter_definitions.json\",\r\n\t\t\"artifact-type\": \"Testparameter_definitions\"\r\n\t},\r\n\t{\r\n\t\t\"artifact-name\": " + + "\"PD_JunitTESTv_parameter_yang.json\",\r\n\t\t\"artifact-type\": \"PD_definations\"\r\n\t}]\r\n}"; + JSONObject content=new JSONObject(contentStr); + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext context = new SvcLogicContext(); + artifactHandlerNode.processVmList(content, context, dbService); + } + + @Test + public void testProcessConfigTypeActions() throws Exception{ + String contentStr = "{\"action\": \"ConfigScaleOut\"}"; + JSONObject content=new JSONObject(contentStr); + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL,"Test"); + artifactHandlerNode.processConfigTypeActions(content, dbService, context); + } + } |