From 9c7054473ec024f85a18fbce54c784cacd4bf7f1 Mon Sep 17 00:00:00 2001 From: Ramya Balaji Date: Mon, 12 Feb 2018 15:31:38 -0500 Subject: Artifact Handler code changes Refactored code for storing reference data and added unit test cases Issue-ID: APPC-543 Change-Id: I60ed5e327324403409ec0d9725c5880038a3e186 Signed-off-by: Ramya Balaji --- .../artifact/handler/node/ArtifactHandlerNode.java | 168 ++++++++++++--------- .../handler/node/ArtifactHandlerNodeTest.java | 59 +++++++- 2 files changed, 149 insertions(+), 78 deletions(-) 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 705aa4439..a85a31392 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -315,43 +315,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { String actionLevel = content.getString(ACTION_LEVEL); setAttribute(context, content::getString, ACTION_LEVEL); setAttribute(context, document_information::getString, ARTIFACT_TYPE); - if ((null != actionLevel) - && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNFC)) { - vnfcActionList.put(content.getString(ACTION)); - } - if (null != actionLevel - && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VF_MODULE)) { - vfModuleActionList.put(content.getString(ACTION)); - } - if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNF)) { - vnfActionList.put(content.getString(ACTION)); - } - if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VM)) { - if (content.has(VNFC_FUNCTION_CODE_LIST) - && !content.isNull(VNFC_FUNCTION_CODE_LIST) && content.get( - VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) { - log.info("Found vnfc-function-code-list!!"); - JSONArray vnfcList = content.getJSONArray(VNFC_FUNCTION_CODE_LIST); - JSONObject obj = new JSONObject(); - obj.put(content.getString(ACTION), vnfcList); - vmActionVnfcFunctionCodesList.put(obj); - } else { - log.info("Not getting JSONArray for VNFC FUNCTION CODES"); - } - } - if (scope.has(VNFC_TYPE) - && !scope.isNull(VNFC_TYPE)) { - String vnfcTypeScope = scope.getString(VNFC_TYPE); - if (StringUtils.isNotBlank(vnfcTypeScope)) { - setAttribute(context, scope::getString, VNFC_TYPE); - storeCapabilityArtifact = false; - log.info("No capability Artifact for this reference data as it is at VNFC level!!"); - } else { - context.setAttribute(VNFC_TYPE, null); - } - } else { - context.setAttribute(VNFC_TYPE, null); - } + processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList,vnfActionList, vmActionVnfcFunctionCodesList); + storeCapabilityArtifact=isCapabilityArtifactNeeded(scope, context); if (content.has(DEVICE_PROTOCOL)) { setAttribute(context, content::getString, DEVICE_PROTOCOL); } @@ -362,42 +327,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { setAttribute(context, content::getString, PORT_NUMBER); } //context.setAttribute(ARTIFACT_TYPE, ""); - if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) { - JSONArray artifactLists = (JSONArray) content.get("artifact-list"); - for (int i = 0; i < artifactLists.length(); i++) { - JSONObject artifact = (JSONObject) artifactLists.get(i); - log.info("artifact is " + artifact); - setAttribute(context, artifact::getString, ARTIFACT_NAME); - context.setAttribute(FILE_CATEGORY, - artifact.getString(ARTIFACT_TYPE)); - - if (artifact.getString(ARTIFACT_NAME) != null - && artifact.getString(ARTIFACT_NAME).toLowerCase() - .startsWith(PD)) { - suffix = artifact.getString(ARTIFACT_NAME) - .substring(PD.length()); - categorySuffix = artifact.getString(ARTIFACT_TYPE) - .substring(PD.length()); - pdFile = true; - } - log.info("Artifact-type = " + context.getAttribute(ARTIFACT_TYPE)); - dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, - DB_SDC_REFERENCE)); - - cleanArtifactInstanceData(context); - } - - if (pdFile) { - context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix)); - context.setAttribute(FILE_CATEGORY, TOSCA_MODEL); - dbservice.processSdcReferences(context, - dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); - context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix)); - context.setAttribute(FILE_CATEGORY, PARAMETER_YANG); - dbservice.processSdcReferences(context, - dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); - } - } + processArtifactList(content,dbservice,context); processConfigTypeActions(content,dbservice,context); dbservice.processDeviceAuthentication(context, dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION)); @@ -432,6 +362,96 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { return true; } + public boolean isCapabilityArtifactNeeded(JSONObject scope, SvcLogicContext context) { + boolean storeCapabilityArtifact=true; + if (scope.has(VNFC_TYPE) + && !scope.isNull(VNFC_TYPE)) { + String vnfcTypeScope = scope.getString(VNFC_TYPE); + if (StringUtils.isNotBlank(vnfcTypeScope)) { + setAttribute(context, scope::getString, VNFC_TYPE); + storeCapabilityArtifact = false; + log.info("No capability Artifact for this reference data as it is at VNFC level!!"); + } else { + context.setAttribute(VNFC_TYPE, null); + } + } else { + context.setAttribute(VNFC_TYPE, null); + } + return storeCapabilityArtifact; + } + + public void processActionLists(JSONObject content, String actionLevel, JSONArray vnfcActionList, JSONArray vfModuleActionList, + JSONArray vnfActionList, JSONArray vmActionVnfcFunctionCodesList) { + if ((null != actionLevel) + && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNFC)) { + vnfcActionList.put(content.getString(ACTION)); + } + if (null != actionLevel + && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VF_MODULE)) { + vfModuleActionList.put(content.getString(ACTION)); + } + if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VNF)) { + vnfActionList.put(content.getString(ACTION)); + } + if (null != actionLevel && actionLevel.equalsIgnoreCase(ACTION_LEVEL_VM)) { + if (content.has(VNFC_FUNCTION_CODE_LIST) + && !content.isNull(VNFC_FUNCTION_CODE_LIST) && content.get( + VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) { + log.info("Found vnfc-function-code-list!!"); + JSONArray vnfcList = content.getJSONArray(VNFC_FUNCTION_CODE_LIST); + JSONObject obj = new JSONObject(); + obj.put(content.getString(ACTION), vnfcList); + vmActionVnfcFunctionCodesList.put(obj); + } else { + log.info("Not getting JSONArray for VNFC FUNCTION CODES"); + } + } + + } + + public void processArtifactList(JSONObject content, DBService dbservice, SvcLogicContext context) throws Exception { + boolean pdFile = false; + String suffix = null; + String categorySuffix = null; + if (content.has("artifact-list") && content.get("artifact-list") instanceof JSONArray) { + JSONArray artifactLists = (JSONArray) content.get("artifact-list"); + for (int i = 0; i < artifactLists.length(); i++) { + JSONObject artifact = (JSONObject) artifactLists.get(i); + log.info("artifact is " + artifact); + setAttribute(context, artifact::getString, ARTIFACT_NAME); + context.setAttribute(FILE_CATEGORY, + artifact.getString(ARTIFACT_TYPE)); + + if (artifact.getString(ARTIFACT_NAME) != null + && artifact.getString(ARTIFACT_NAME).toLowerCase() + .startsWith(PD)) { + suffix = artifact.getString(ARTIFACT_NAME) + .substring(PD.length()); + categorySuffix = artifact.getString(ARTIFACT_TYPE) + .substring(PD.length()); + pdFile = true; + } + log.info("Artifact-type = " + context.getAttribute(ARTIFACT_TYPE)); + dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, + DB_SDC_REFERENCE)); + + cleanArtifactInstanceData(context); + } + + if (pdFile) { + context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix)); + context.setAttribute(FILE_CATEGORY, TOSCA_MODEL); + dbservice.processSdcReferences(context, + dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); + context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix)); + context.setAttribute(FILE_CATEGORY, PARAMETER_YANG); + dbservice.processSdcReferences(context, + dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); + } + } + + } + 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")) { 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 0f0f0a0a2..65f354ac6 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 @@ -2,22 +2,22 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= * 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. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ @@ -25,6 +25,7 @@ package org.onap.appc.artifact.handler.node; import org.apache.commons.io.IOUtils; +import org.json.JSONArray; import org.json.JSONObject; import org.junit.Before; import org.junit.Ignore; @@ -39,6 +40,7 @@ import java.util.Map; import java.util.HashMap; import java.nio.charset.Charset; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class ArtifactHandlerNodeTest { @@ -206,4 +208,53 @@ public class ArtifactHandlerNodeTest { artifactHandlerNode.processConfigTypeActions(content, dbService, context); } + @Test + public void testProcessArtifactLists() 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.processArtifactList(content,dbService,context); + } + + @Test + public void testProcessActionLists() throws Exception { + String contentStr = "{\r\n\t\"action\": \"HealthCheck\",\r\n\t\"action-level\": \"vm\",\r\n\t\"scope\":" + + " {\r\n\t\t\"vnf-type\": \"vDBE-I\",\r\n\t\t\"vnfc-type\": null\r\n\t},\r\n\t\"template\": " + + "\"N\",\r\n\t\"device-protocol\": \"REST\",\r\n\t\"vnfc-function-code-list\": [\"SSC\", \"MMSC\"]\r\n}"; + JSONObject content = new JSONObject(contentStr); + JSONArray vmActionVnfcFunctionCodesList = new JSONArray(); + JSONArray vnfActionList = new JSONArray(); + JSONArray vfModuleActionList = new JSONArray(); + JSONArray vnfcActionList = new JSONArray(); + String[] actionLevels = { "vnf", "vm", "vf-module", "vnfc" }; + for (String actionLevel : actionLevels) { + artifactHandlerNode.processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList, + vnfActionList, vmActionVnfcFunctionCodesList); + } + } + + @Test + public void testIsCapabilityArtifactNeeded() throws Exception { + String scopeObjStr1= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"somVnfc\"}"; + String scopeObjStr2= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"\"}"; + JSONObject scope1 = new JSONObject(scopeObjStr1); + JSONObject scope2 = new JSONObject(scopeObjStr2); + SvcLogicContext context = new SvcLogicContext(); + assertFalse(artifactHandlerNode.isCapabilityArtifactNeeded(scope1, context)); + assertTrue(artifactHandlerNode.isCapabilityArtifactNeeded(scope2, context)); + } + } -- cgit 1.2.3-korg