diff options
author | Dunietz, Irwin <id1681@att.com> | 2020-01-16 15:13:14 -0500 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2020-01-29 19:44:48 +0000 |
commit | b5fe8a69e90b950c07dc11af481eab7e9bab52c6 (patch) | |
tree | 3da81ce60554e65b93776b9aea647f3c6d8679ab /appc-inbound/appc-artifact-handler/provider | |
parent | 9b32cb60360a2a2973c621053510718de0072111 (diff) |
Change code in appc dispatcher for new LCMs in R6
Also introduce some minor improvements to robustness, efficiency, & formatting.
Issue-ID: APPC-1789
Signed-off-by: Dunietz, Irwin <id1681@att.com>
Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider')
5 files changed, 345 insertions, 269 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 b6fd2f599..48dd67f02 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-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -60,6 +60,7 @@ import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.R import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_ID; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.REQUEST_INFORMATION; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME; +import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_NAME; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_TYPE; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_UUID; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.RESOURCE_VERSION; @@ -82,7 +83,6 @@ import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.V import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.URL; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.OPENSTACK; import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.ANSIBLE; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; import java.io.ByteArrayOutputStream; @@ -93,6 +93,7 @@ import java.util.function.Function; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.StringUtils; import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; import org.onap.appc.artifact.handler.dbservices.DBException; import org.onap.appc.artifact.handler.dbservices.DBService; @@ -104,8 +105,6 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; import org.onap.sdnc.config.params.transformer.tosca.ArtifactProcessorImpl; import org.onap.sdnc.config.params.transformer.tosca.exceptions.ArtifactProcessorException; - -import org.json.JSONException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -120,20 +119,21 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { private static final String CONFIG_SCALE_OUT_PARAM = "ConfigScaleOut"; private static final String CONFIG_MODIFY_PARAM = "ConfigModify"; private static final String GET_CONFIG = "GetConfig"; - private static final String POST_EVACUATE= "PostEvacuate"; + private static final String POST_EVACUATE = "PostEvacuate"; private static final String PRE_EVACUATE = "PreEvacuate"; private static final String POST_MIGRATE = "PostMigrate"; private static final String PRE_MIGRATE = "PreMigrate"; private static final String PRE_REBUILD = "PreRebuild"; private static final String POST_REBUILD = "PostRebuild"; private static final String STOP_TRAFFIC = "StopTraffic"; + public void processArtifact(Map<String, String> inParams, SvcLogicContext ctx) throws ArtifactProcessorException { if (inParams == null || inParams.isEmpty()) { return; } String postData = inParams.get("postData"); - if ( StringUtils.isBlank(postData)) { + if (StringUtils.isBlank(postData)) { return; } try { @@ -147,14 +147,15 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { } private boolean storeUpdateSdcArtifacts(JSONObject postDataJson) throws ArtifactHandlerInternalException { - log.info("Starting processing of SDC Artifacs into Handler with Data : " + postDataJson.toString()); + log.info("Starting processing of SDC Artifacts into Handler with Data: " + postDataJson.toString()); try { JSONObject requestInfo = (JSONObject) postDataJson.get(REQUEST_INFORMATION); JSONObject documentInfo = (JSONObject) postDataJson.get(DOCUMENT_PARAMETERS); String artifactName = documentInfo.getString(ARTIFACT_NAME); - if (StringUtils.isBlank(artifactName)) - throw new ArtifactHandlerInternalException("Missing Artifact Name "); + if (StringUtils.isBlank(artifactName)) { + throw new ArtifactHandlerInternalException("Missing Artifact Name"); + } if (artifactName.toLowerCase().startsWith(ANSIBLE)) { validateAnsibleAdminArtifact(documentInfo); @@ -174,7 +175,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { + ((JSONObject) postDataJson.get(REQUEST_INFORMATION)).getString(REQUEST_ID), e); throw new ArtifactHandlerInternalException("Error while processing request with id: " + ((JSONObject) postDataJson.get(REQUEST_INFORMATION)).getString(REQUEST_ID) - + ", Exception Message : " + e.getMessage(), e); + + ", Exception Message: " + e.getMessage(), e); } return false; } @@ -183,16 +184,15 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { String fn = "ArtifactHandlerNode.validateAnsibleAdminArtifact"; String artifactName = documentInfo.getString(ARTIFACT_NAME); - log.info(fn + ": Received Admin File Name: " + artifactName + " ArtifactCotent : " - + documentInfo.getString(ARTIFACT_CONTENTS)); + log.info(fn + ": Received Admin File Name: " + artifactName + + ", ArtifactContent: " + documentInfo.getString(ARTIFACT_CONTENTS)); try { ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); String contentString = ahpUtil.escapeSql(documentInfo.getString(ARTIFACT_CONTENTS)); JSONObject artifact = new JSONObject(contentString); JSONArray fqdnList = artifact.getJSONArray("fqdn-list"); Map<String, List<String>> artifactMap = new HashMap<>(); - - + for (int i = 0; i < fqdnList.length(); i++) { JSONObject fqdn = fqdnList.getJSONObject(i); List<String> valuesforFQDN = populateValueForFQDN(fqdn); @@ -202,56 +202,66 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { validateKeyValue(artifactMap); } catch (JSONException je) { - log.error( - fn + " ansible_admin artifact content may not be a valid JSON, error message : " + je.getMessage()); + log.error(fn + " ansible admin artifact content may not be a valid JSON, error message: " + + je.getMessage()); throw new ArtifactHandlerInternalException( - "JSON Exception:ansible admin artifact content may not be a valid JSON, error message : " + je.getMessage(), je); + "JSON Exception:ansible admin artifact content may not be a valid JSON, error message: " + + je.getMessage(), + je); } catch (ArtifactHandlerInternalException ae) { - throw ae; + throw ae; } catch (Exception e) { - log.error(fn + "Error while creating Admin data records", e); - throw new ArtifactHandlerInternalException("Error while processing ansible admin artifact" + e.getMessage(), e); + throw new ArtifactHandlerInternalException( + "Error while processing ansible admin artifact: " + e.getMessage(), e); } } + private void validateKeyValue(Map<String, List<String>> artifactMap) throws ArtifactHandlerInternalException { - for (Map.Entry<String,List<String>> entry1:artifactMap.entrySet()) { - for (String value : entry1.getValue()) { - for(Map.Entry<String,List<String>> entry2:artifactMap.entrySet() ) { - if (!entry1.getKey().equals(entry2.getKey()) && entry2.getValue().contains(value)) { - log.info("Validation Failure, error message : Ansible Admin artifact has CloudOwner-RegionId-Tenant : " + value - + " mapped to multiple FQDN :" + entry1.getKey() + " & " + entry2.getKey()); - throw new ArtifactHandlerInternalException( - "Validation Failure, error message : Ansible Admin artifact has CloudOwner-RegionId-Tenant : " + value - + " mapped to multiple FQDN :" + entry1.getKey() + " & " + entry2.getKey()); - } + for (String fqdn1 : artifactMap.keySet()) { + + for (String value : artifactMap.get(fqdn1)) { + for (String fqdn2 : artifactMap.keySet()) { + + if (!fqdn1.equals(fqdn2) && artifactMap.get(fqdn2).contains(value)) { + String msg = "Validation Failure: Ansible Admin artifact has CloudOwner-RegionId-Tenant: " + + value + " mapped to multiple FQDN: " + fqdn1 + " & " + fqdn2; + log.info(msg); + throw new ArtifactHandlerInternalException(msg); + } } } + + } + } -} private List<String> populateValueForFQDN(JSONObject fqdn) { - log.info("Inside populateValueForFQDN :" + fqdn.getString("vnf-management-server-fqdn")); + log.info("Inside populateValueForFQDN: " + fqdn.getString("vnf-management-server-fqdn")); List<String> valuesforFQDN = new ArrayList<>(); JSONArray cloudJsonList = fqdn.getJSONArray("cloud-owner-list"); for (int j = 0; j < cloudJsonList.length(); j++) { String cloudOwner = cloudJsonList.getJSONObject(j).getString("cloud-owner"); JSONArray regionList = cloudJsonList.getJSONObject(j).getJSONArray("region-id-list"); + for (int i = 0; i < regionList.length(); i++) { + String region = regionList.getJSONObject(i).getString("region-id"); + JSONArray tenantList = regionList.getJSONObject(i).getJSONArray("tenant-id-list"); for (int k = 0; k < tenantList.length(); k++) { - String tenant = tenantList.getString(k); + String tenant = tenantList.getString(k); String valueforFQDN = cloudOwner + "-" + region + "-" + tenant; - log.info("valueforFQDN for i " + i + " & j " + j + " :" + valueforFQDN); + log.info("valueforFQDN for i " + i + " & j " + j + ": " + valueforFQDN); valuesforFQDN.add(valueforFQDN); } } } + return valuesforFQDN; } @@ -260,7 +270,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { String fn = "ArtifactHandlerNode.createReferenceDataForPD"; String artifactName = documentInfo.getString(ARTIFACT_NAME); - log.info(fn + "Received PD File Name: " + artifactName + " and suffix length " + PD.length()); + log.info(fn + " Received PD File Name: " + artifactName + " and suffix length " + PD.length()); try { String suffix = artifactName.substring(PD.length()); @@ -276,7 +286,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { throws ArtifactHandlerInternalException { try { - log.info("Creating Tosca Records and storing into SDC Artifacs"); + log.info("Creating Tosca Records and storing into SDC Artifacts"); String[] docs = { TOSCA_PARAM, YANG_PARAM }; ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); String pdFileContents = documentInfo.getString(ARTIFACT_CONTENTS); @@ -287,7 +297,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { ArtifactProcessorImpl toscaGenerator = getArtifactProcessorImpl(); toscaGenerator.generateArtifact(pdFileContents, toscaStream); toscaContents = toscaStream.toString(); - log.info("Generated Tosca File : " + toscaContents); + log.info("Generated Tosca File: " + toscaContents); String yangContents = "YANG generation is in Progress"; String yangName = null; @@ -333,16 +343,18 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { return dbservice.getArtifactID(context, yangName); } - protected boolean updateStoreArtifacts(JSONObject requestInfo, JSONObject documentInfo) throws SvcLogicException { - log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs "); + protected boolean updateStoreArtifacts(JSONObject requestInfo, JSONObject documentInfo) + throws SvcLogicException, SQLException { + log.info("updateStoreArtifacts started storing of SDC Artifacts"); + SvcLogicContext context = new SvcLogicContext(); DBService dbservice = DBService.initialise(); ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); int intversion = 0; context.setAttribute("artifact_name", documentInfo.getString(ARTIFACT_NAME)); - String internalVersion = dbservice.getInternalVersionNumber(context, documentInfo.getString(ARTIFACT_NAME), - null); - log.info("Internal Version number received from Database : " + internalVersion); + String internalVersion = + dbservice.getInternalVersionNumber(context, documentInfo.getString(ARTIFACT_NAME), null); + log.info("Internal Version number received from Database: " + internalVersion); if (internalVersion != null) { intversion = Integer.parseInt(internalVersion); intversion++; @@ -354,6 +366,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { setAttribute(context, documentInfo::getString, RESOURCE_UUID); setAttribute(context, documentInfo::getString, RESOURCE_INSTANCE_NAME); setAttribute(context, documentInfo::getString, RESOURCE_VERSION); + setAttribute(context, documentInfo::getString, RESOURCE_NAME); setAttribute(context, documentInfo::getString, RESOURCE_TYPE); setAttribute(context, documentInfo::getString, ARTIFACT_UUID); setAttribute(context, documentInfo::getString, ARTIFACT_TYPE); @@ -368,15 +381,14 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { public boolean storeReferenceData(JSONObject requestInfo, JSONObject documentInfo) throws ArtifactHandlerInternalException { - - log.info("Started storing of SDC Artifacs into Handler"); + log.info("Started storing of SDC Artifacts into Handler"); try { DBService dbservice = DBService.initialise(); ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil(); String contentString = ahpUtil.escapeSql(documentInfo.getString(ARTIFACT_CONTENTS)); String artifactName = ahpUtil.escapeSql(documentInfo.getString(ARTIFACT_NAME)); - String capabilityArtifactName = StringUtils.replace(artifactName, ARTIFACT_NAME_REFERENCE, - ARTIFACT_NAME_CAPABILITY); + String capabilityArtifactName = + StringUtils.replace(artifactName, ARTIFACT_NAME_REFERENCE, ARTIFACT_NAME_CAPABILITY); JSONObject capabilities = new JSONObject(); JSONArray vnfActionList = new JSONArray(); JSONArray vfModuleActionList = new JSONArray(); @@ -386,11 +398,12 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { JSONObject contentObject = new JSONObject(contentString); JSONArray contentArray = contentObject.getJSONArray("reference_data"); boolean storeCapabilityArtifact = true; + for (int a = 0; a < contentArray.length(); a++) { - JSONObject content = (JSONObject) contentArray.get(a); - log.info("contentString =" + content.toString()); + JSONObject content = contentArray.getJSONObject(a); + log.info("contentString = " + content.toString()); JSONObject scope = content.getJSONObject("scope"); - log.info("scope :" + scope); + log.info("scope: " + scope); SvcLogicContext context = new SvcLogicContext(); vnfType = scope.getString(VNF_TYPE); setAttribute(context, scope::getString, VNF_TYPE); @@ -402,6 +415,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { vmActionVnfcFunctionCodesList); JSONArray vnfcTypeList = setVnfcTypeInformation(scope, context); storeCapabilityArtifact = isCapabilityArtifactNeeded(context); + if (content.has(DEVICE_PROTOCOL)) { setAttribute(context, content::getString, DEVICE_PROTOCOL); } @@ -423,9 +437,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { if (!StringUtils.equalsIgnoreCase(actionProtocol, OPENSTACK)) { populateProtocolReference(dbservice, content); } - context.setAttribute(VNFC_TYPE, null); - if (content.has(VM) && content.get(VM) instanceof JSONArray) { processVmList(content, context, dbservice); } @@ -464,7 +476,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { String vnfcTypeScope = scope.getString(VNFC_TYPE); if (StringUtils.isNotBlank(vnfcTypeScope)) { setAttribute(context, scope::getString, VNFC_TYPE); - log.info("VNFC Type has been set for this reference artifact!!" + vnfcTypeScope); + log.info("VNFC type has been set for this reference artifact!! " + vnfcTypeScope); } else { context.setAttribute(VNFC_TYPE, null); } @@ -491,7 +503,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { vnfActionList.put(content.getString(ACTION)); } if (validateActionLevel(actionLevel, ACTION_LEVEL_VM)) { - if (content.has(VNFC_FUNCTION_CODE_LIST) && !content.isNull(VNFC_FUNCTION_CODE_LIST) + 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); @@ -510,7 +523,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { } public void processArtifactList(JSONObject content, DBService dbservice, SvcLogicContext context, - JSONArray vnfcTypeList) throws ArtifactHandlerInternalException { + JSONArray vnfcTypeList) + throws ArtifactHandlerInternalException { try { if (content.has(ARTIFACT_LIST_PARAM) && content.get(ARTIFACT_LIST_PARAM) instanceof JSONArray) { @@ -521,7 +535,6 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { templateIdList = content.getJSONArray("template-id-list"); } doProcessArtifactList(dbservice, context, artifactLists, templateIdList, vnfcTypeList); - } } catch (Exception e) { log.error("An error occurred when processing artifact list", e); @@ -533,7 +546,9 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { JSONArray templateIdList, JSONArray vnfcTypeList) throws SvcLogicException, SQLException, ConfigurationException, DBException { boolean pdFile = false; - int modelInd = 0, vnfcRefInd = 0; + int modelInd = 0; + int vnfcRefInd = 0; + for (int i = 0; i < artifactLists.length(); i++) { String suffix = null; String model = null; @@ -541,9 +556,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { log.info("artifact is " + artifact); // Get Model details - if (null != templateIdList && i > 0 && i % 2 == 0) {// Should this be changed to 3 to account for 3 - // artifacts - modelInd++; + if (null != templateIdList && i > 0 && i % 2 == 0) { // Should this be changed to 3 + modelInd++; // to account for 3 artifacts } if (null != vnfcTypeList && i > 0 && i % 3 == 0) { // TDP 517180 - CD tool has made changes to send 3 artifacts instead of 2 @@ -563,18 +577,19 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { if (null != templateIdList && modelInd < templateIdList.length()) { model = templateIdList.getString(modelInd); - log.info("Model is ::: " + model + " ,modelInd = " + modelInd); + log.info("Model is ::: " + model + ", modelInd = " + modelInd); } if (null != vnfcTypeList && vnfcRefInd < vnfcTypeList.length()) { String vnfcType = vnfcTypeList.getString(vnfcRefInd); if (StringUtils.isNotBlank(vnfcType)) { context.setAttribute(VNFC_TYPE, vnfcType); } - log.info("Setting vnfc type from vnfc-type-list ::" + vnfcType); + log.info("Setting vnfc type from vnfc-type-list :: " + vnfcType); } if (StringUtils.isNotBlank(model)) { dbservice.processSdcReferences(context, - dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model); + dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), + model); } else { dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); } @@ -584,14 +599,14 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { if (pdFile) { log.info("Sending information related to pdfile Artifact"); tryUpdateContext(dbservice, context, pdFile, suffix, model); - pdFile = false;// set to false afterprocessing yang and Tosca + pdFile = false; // set to false after processing yang and Tosca } } - } private void tryUpdateContext(DBService dbservice, SvcLogicContext context, boolean pdFile, String suffix, - String model) throws SvcLogicException, SQLException, ConfigurationException, DBException { + String model) + throws SvcLogicException, SQLException, ConfigurationException, DBException { if (pdFile) { context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix)); context.setAttribute(FILE_CATEGORY, TOSCA_MODEL); @@ -606,8 +621,11 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { public void processConfigTypeActions(JSONObject content, DBService dbservice, SvcLogicContext context) throws ArtifactHandlerInternalException { + try { - if (isContentActionConfig(content) + if (contentsActionEquals(content, CONFIGURE_PARAM) + || contentsActionEquals(content, CONFIG_MODIFY_PARAM) + || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM) || contentsActionEquals(content, GET_CONFIG) || contentsActionEquals(content, POST_EVACUATE) || contentsActionEquals(content, PRE_EVACUATE) @@ -616,7 +634,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { || contentsActionEquals(content, POST_REBUILD) || contentsActionEquals(content, PRE_REBUILD) || contentsActionEquals(content, STOP_TRAFFIC) - ) { + ) { if (content.has(DOWNLOAD_DG_REFERENCE) && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) { @@ -640,20 +658,17 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { private void tryProcessInterfaceProtocol(JSONObject content, DBService dbservice, SvcLogicContext context) throws SvcLogicException, SQLException, ConfigurationException, DBException { - if (isContentActionConfig(content)) { + + if (contentsActionEquals(content, CONFIGURE_PARAM) || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM)) { boolean isUpdateRequired = dbservice.isArtifactUpdateRequired(context, DB_DEVICE_INTERFACE_PROTOCOL); - if (isContentActionConfig(content) && !isUpdateRequired) { + if (contentsActionEquals(content, CONFIGURE_PARAM) + || (contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM) + && !isUpdateRequired)) { + dbservice.processDeviceInterfaceProtocol(context, isUpdateRequired); } } } - - //Consolidates the if statements required to check if the action is one of the config actions - private boolean isContentActionConfig(JSONObject content) { - return contentsActionEquals(content, CONFIGURE_PARAM) - || contentsActionEquals(content, CONFIG_MODIFY_PARAM) - || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM); - } private boolean contentsActionEquals(JSONObject content, String action) { return content.getString(ACTION).equals(action); @@ -734,7 +749,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { JSONObject capabilities, String capabilityArtifactName, String vnfType) throws ArtifactHandlerInternalException { - log.info("Begin-->processAndStoreCapabilitiesArtifact "); + log.info("Begin-->processAndStoreCapabilitiesArtifact"); try { JSONObject newCapabilitiesObject = new JSONObject(); @@ -749,9 +764,9 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { context.setAttribute(ARTIFACT_CONTENTS, newCapabilitiesObject.toString()); dbService.processSdcReferences(context, dbService.isArtifactUpdateRequired(context, DB_SDC_REFERENCE)); int intVersion = 0; - String internalVersion = dbService.getInternalVersionNumber(context, context.getAttribute(ARTIFACT_NAME), - null); - log.info("Internal Version number received from Database : " + internalVersion); + String internalVersion = + dbService.getInternalVersionNumber(context, context.getAttribute(ARTIFACT_NAME), null); + log.info("Internal Version number received from Database: " + internalVersion); if (internalVersion != null) { intVersion = Integer.parseInt(internalVersion) + 1; } @@ -771,7 +786,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin { log.error("Error saving capabilities artifact to DB", e); throw new ArtifactHandlerInternalException("Error saving capabilities artifact to DB", e); } finally { - log.info("End-->processAndStoreCapabilitiesArtifact "); + log.info("End-->processAndStoreCapabilitiesArtifact"); } } diff --git a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java index 214e6db68..359e6fea8 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java +++ b/appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtil.java @@ -2,22 +2,21 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. - * * ============LICENSE_END========================================================= */ @@ -84,28 +83,28 @@ public class ArtifactHandlerProviderUtil { JSONObject docParams = new JSONObject(); docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, - "TLSUUID" + templateData.getRequestInformation().getRequestId()); + "TLSUUID" + templateData.getRequestInformation().getRequestId()); docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "TLDID" + random); docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, "TLServiceName"); docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "Template Loader Test"); docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, "[]"); docParams.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "TLRUID" + random); docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "TLRIName"); - docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, "TLResourceName"); + docParams.put(SdcArtifactHandlerConstants.RESOURCE_NAME, "TLResourceName"); docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "TLResourceVersion"); docParams.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "TLResourceType"); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "TLAUUID" + random); docParams - .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, "APPC-CONFIG"); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, - templateData.getDocumentParameters().getArtifactVersion()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "SdcTestDescription"); + templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESCRIPTION, "SdcTestDescription"); docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - log.info("Final data =" + this.templateData); + log.info("Final data = " + this.templateData); return String.format("{\"input\": %s}", json.toString()); } @@ -136,41 +135,42 @@ public class ArtifactHandlerProviderUtil { requestInfo.put(SdcArtifactHandlerConstants.SOURCE, templateData.getRequestInformation().getSource()); String serviceDescription = serviceDescriptionData( - templateData.getDocumentParameters().getServiceDescription()); + templateData.getDocumentParameters().getServiceDescription()); JSONObject docParams = new JSONObject(); docParams.put(SdcArtifactHandlerConstants.SERVICE_UUID, templateData.getDocumentParameters().getResourceUuid()); - docParams - .put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, templateData.getDocumentParameters().getDistributionId()); + docParams.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, + templateData.getDocumentParameters().getDistributionId()); docParams.put(SdcArtifactHandlerConstants.SERVICE_NAME, templateData.getDocumentParameters().getServiceName()); docParams.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, serviceDescription); docParams.put(SdcArtifactHandlerConstants.SERVICE_ARTIFACTS, - templateData.getDocumentParameters().getServiceArtifacts()); + templateData.getDocumentParameters().getServiceArtifacts()); docParams - .put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); + .put(SdcArtifactHandlerConstants.RESOURCE_UUID, templateData.getDocumentParameters().getResourceUuid()); docParams.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, - templateData.getDocumentParameters().getResourceInstanceName()); - docParams.put(SdcArtifactHandlerConstants.REOURCE_NAME, templateData.getDocumentParameters().getResourceName()); + templateData.getDocumentParameters().getResourceInstanceName()); + docParams + .put(SdcArtifactHandlerConstants.RESOURCE_NAME, templateData.getDocumentParameters().getResourceName()); docParams.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, - templateData.getDocumentParameters().getResourceVersion()); + templateData.getDocumentParameters().getResourceVersion()); docParams - .put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); + .put(SdcArtifactHandlerConstants.RESOURCE_TYPE, templateData.getDocumentParameters().getResourceType()); docParams - .put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); + .put(SdcArtifactHandlerConstants.ARTIFACT_UUID, templateData.getDocumentParameters().getArtifactUuid()); docParams - .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); + .put(SdcArtifactHandlerConstants.ARTIFACT_NAME, templateData.getDocumentParameters().getArtifactName()); docParams - .put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); + .put(SdcArtifactHandlerConstants.ARTIFACT_TYPE, templateData.getDocumentParameters().getArtifactType()); docParams.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, - templateData.getDocumentParameters().getArtifactVersion()); - docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, - templateData.getDocumentParameters().getArtifactDescription()); + templateData.getDocumentParameters().getArtifactVersion()); + docParams.put(SdcArtifactHandlerConstants.ARTIFACT_DESCRIPTION, + templateData.getDocumentParameters().getArtifactDescription()); docParams.put("artifact-contents", templateData.getDocumentParameters().getArtifactContents()); json.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); json.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, docParams); - log.info("Final data =" + this.templateData); + log.info("Final data = " + this.templateData); return String.format("{\"input\": %s}", json.toString()); } 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 f4f623cce..63ac5767b 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 @@ -2,22 +2,22 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. - * + * * ============LICENSE_END========================================================= */ @@ -26,24 +26,26 @@ package org.onap.appc.artifact.handler.utils; public class SdcArtifactHandlerConstants { public static final String DOCUMENT_PARAMETERS = "document-parameters"; - public static final String SERVICE_UUID = "service-uuid"; - public static final String DISTRIBUTION_ID = "distribution-id"; + public static final String SERVICE_UUID = "service-uuid"; + public static final String DISTRIBUTION_ID = "distribution-id"; public static final String REQUEST_ID = "request-id"; - public static final String REQUEST_ACTION = "request-action"; + public static final String REQUEST_ACTION = "request-action"; public static final String SOURCE = "source"; - public static final String SERVICE_NAME = "service-name"; - public static final String SERVICE_DESCRIPTION ="service-description"; - public static final String SERVICE_ARTIFACTS = "service-artifacts"; - public static final String RESOURCE_UUID ="resource-uuid"; + public static final String SERVICE_NAME = "service-name"; + public static final String SERVICE_DESCRIPTION = "service-description"; + public static final String SERVICE_ARTIFACTS = "service-artifacts"; + public static final String RESOURCE_UUID = "resource-uuid"; public static final String RESOURCE_INSTANCE_NAME = "resource-instance-name"; - public static final String REOURCE_NAME = "resource-name"; - public static final String RESOURCE_VERSION ="resource-version"; - public static final String RESOURCE_TYPE= "resource-type"; - public static final String ARTIFACT_UUID ="artifact-uuid"; - public static final String ARTIFACT_NAME = "artifact-name"; - public static final String ARTIFACT_TYPE = "artifact-type"; + public static final String RESOURCE_NAME = "resource-name"; + public static final String REOURCE_NAME = "resource-name"; // misspelling that was once supported + public static final String RESOURCE_VERSION = "resource-version"; + public static final String RESOURCE_TYPE = "resource-type"; + public static final String ARTIFACT_UUID = "artifact-uuid"; + public static final String ARTIFACT_NAME = "artifact-name"; + public static final String ARTIFACT_TYPE = "artifact-type"; public static final String ARTIFACT_VERSION = "artifact-version"; - public static final String ARTIFACT_DESRIPTION = "artifact-description"; + public static final String ARTIFACT_DESCRIPTION = "artifact-description"; + public static final String ARTIFACT_DESRIPTION = "artifact-description"; // misspelling that was once supported public static final String ARTIFACT_CONTENTS = "artifact-contents"; public static final String REQUEST_INFORMATION = "request-information"; public static final String INTERNAL_VERSION = "internal-versoin"; @@ -58,8 +60,8 @@ public class SdcArtifactHandlerConstants { public static final String VNFC_FUNCTION_CODE = "vnfc-function-code"; public static final String VNFC_FUNCTION_CODE_LIST = "vnfc-function-code-list"; public static final String GROUP_NOTATION = "group-notation"; - 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 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"; @@ -71,7 +73,8 @@ public class SdcArtifactHandlerConstants { public static final String PORT_NUMBER = "port-number"; public static final String DOWNLOAD_DG_REFERENCE = "download-dg-reference"; public static final String VNFC_TYPE_LIST = "vnfc-type-list"; - + + public static final String DB_DOWNLOAD_DG_REFERENCE = "DOWNLOAD_DG_REFERENCE"; public static final String DB_SDC_REFERENCE = "ASDC_REFERENCE"; public static final String DB_DEVICE_INTERFACE_PROTOCOL = "DEVICE_INTERFACE_PROTOCOL"; @@ -83,17 +86,16 @@ public class SdcArtifactHandlerConstants { public static final String TOSCA_MODEL = "tosca_model"; public static final String DESIGN_TOOL = "Design-tool"; public static final String ACTION_LEVEL_VNFC = "VNFC"; - public static final String ACTION_LEVEL_VF_MODULE ="VF-MODULE"; + public static final String ACTION_LEVEL_VF_MODULE = "VF-MODULE"; public static final String ACTION_LEVEL_VNF = "VNF"; public static final String ACTION_LEVEL_VM = "VM"; public static final String CAPABILITY = "capability"; public static final String TEMPLATE = "template"; public static final String ARTIFACT_NAME_REFERENCE = "reference"; public static final String ARTIFACT_NAME_CAPABILITY = "capability"; - public static final String APPC_CONFIG_DIR="/opt/appcauth"; - public static final String URL="url"; - public static final String OPENSTACK = "OS"; - public static final String ANSIBLE = "ansible"; - + public static final String APPC_CONFIG_DIR = "/opt/appcauth"; + public static final String URL = "url"; + public static final String OPENSTACK = "OS"; + public static final String ANSIBLE = "ansible"; } 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 cb3a4625d..98df4d299 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,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -76,7 +76,8 @@ public class ArtifactHandlerNodeTest { artifactHandlerNode = Mockito.spy(new ArtifactHandlerNode()); PowerMockito.mockStatic(DBService.class); dbServiceMock = Mockito.mock(DBService.class); - Mockito.doReturn("12345").when(dbServiceMock).getInternalVersionNumber(Mockito.any(), Mockito.anyString(), Mockito.anyString()); + Mockito.doReturn("12345") + .when(dbServiceMock).getInternalVersionNumber(Mockito.any(), Mockito.anyString(), Mockito.anyString()); PowerMockito.when(DBService.initialise()).thenReturn(dbServiceMock); PowerMockito.mockStatic(YANGGeneratorFactory.class); YANGGenerator yangGeneratorMock = Mockito.mock(YANGGenerator.class); @@ -97,7 +98,7 @@ public class ArtifactHandlerNodeTest { JSONObject documentInfo = getDocumentInfo("templates/reference_template"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); requestInfo.put("RequestInfo", "testValue"); - requestInfo.put("request-id","testREQUEST_ID"); + requestInfo.put("request-id", "testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); @@ -139,25 +140,39 @@ public class ArtifactHandlerNodeTest { String artifactId = "1"; String yangContents = "SomeContent"; Whitebox.invokeMethod(artifactHandlerNode, "updateYangContents", artifactId, yangContents); - Mockito.verify(dbServiceMock).updateYangContents(Mockito.any(SvcLogicContext.class), - Mockito.anyString(), Mockito.anyString()); + Mockito.verify(dbServiceMock) + .updateYangContents(Mockito.any(SvcLogicContext.class), Mockito.anyString(), Mockito.anyString()); } @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}"; + + "{\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(); @@ -165,20 +180,20 @@ public class ArtifactHandlerNodeTest { } @Test - public void testProcessConfigTypeActions() throws Exception{ + public void testProcessConfigTypeActions() throws Exception { String contentStr = "{\"action\": \"ConfigScaleOut\"}"; - JSONObject content=new JSONObject(contentStr); + JSONObject content = new JSONObject(contentStr); MockDBService dbService = MockDBService.initialise(); SvcLogicContext context = new SvcLogicContext(); - context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL,"Test"); + context.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "Test"); artifactHandlerNode.processConfigTypeActions(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}"; + + " {\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(); @@ -193,8 +208,8 @@ public class ArtifactHandlerNodeTest { @Test public void testIsCapabilityArtifactNeeded() throws Exception { - String scopeObjStr1= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"somVnfc\"}"; - String scopeObjStr2= "{\"vnf-type\":\"someVnf\",\"vnfc-type\":\"\"}"; + 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(); @@ -206,20 +221,30 @@ public class ArtifactHandlerNodeTest { @Test public void testProcessArtifactListsWithMultipleTemplates() throws Exception { - String contentStr = "{\r\n\t\t\"action\": \"ConfigScaleOut\",\r\n\t\t\"action-level\": \"vnf\",\r\n\t\t\"scope\": {\r\n\t\t\t\"vnf-type\": " - + "\"vCfgSO-0405\",\r\n\t\t\t\"vnfc-type\": \"\"\r\n\t\t},\r\n\t\t\"template\": \"Y\",\r\n\t\t\"vm\": [{\r\n\t\t\t\"template-id\": " - + "\"TID-0405-EZ\",\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n\t\t\t\t\"vnfc-function-code\": " - + "\"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\":" - + " \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n\t\t\t}]\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"template-id\": " - + "\"TID-0405-EZ\",\r\n\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n\t\t\t\t\"vnfc-function-code\": " - + "\"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\":" - + " \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n\t\t\t}]\r\n\t\t}],\r\n\t\t\"device-protocol\": \"ANSIBLE\",\r\n\t\t\"user-name\": \"root\"," - + "\r\n\t\t\"port-number\": \"22\",\r\n\t\t\"artifact-list\": [{\r\n\t\t\t\"artifact-name\": \"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.json\"," - + "\r\n\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.yaml\"," - + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": " - + "\"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.json\",\r\n\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": " - + "\"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.yaml\",\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}],\r\n\t\t\"template-id-list\":" - + " [\"TID-0405-EZ\",\r\n\t\t\"TID-0405-EZ-2\"],\r\n\t\t\"scopeType\": \"vnf-type\"\r\n\t}"; + String contentStr = "{\r\n\t\t\"action\": \"ConfigScaleOut\",\r\n\t\t\"action-level\": \"vnf\",\r\n" + + "\t\t\"scope\": {\r\n\t\t\t\"vnf-type\": \"vCfgSO-0405\",\r\n\t\t\t\"vnfc-type\": \"\"\r\n\t\t},\r\n" + + "\t\t\"template\": \"Y\",\r\n\t\t\"vm\": [{\r\n\t\t\t\"template-id\": \"TID-0405-EZ\",\r\n" + + "\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n" + + "\t\t\t\t\"vnfc-function-code\": \"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n" + + "\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n" + + "\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n" + + "\t\t\t}]\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"template-id\": \"TID-0405-EZ\",\r\n" + + "\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n" + + "\t\t\t\t\"vnfc-function-code\": \"Cfg-ez\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n" + + "\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n" + + "\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vCfg-0405-ez\"\r\n" + + "\t\t\t}]\r\n\t\t}],\r\n\t\t\"device-protocol\": \"ANSIBLE\",\r\n\t\t\"user-name\": \"root\",\r\n" + + "\t\t\"port-number\": \"22\",\r\n\t\t\"artifact-list\": [{\r\n" + + "\t\t\t\"artifact-name\": \"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.json\",\r\n" + + "\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n" + + "\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ.yaml\",\r\n" + + "\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n\t\t{\r\n" + + "\t\t\t\"artifact-name\": \"template_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.json\",\r\n" + + "\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n" + + "\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_vCfgSO-0405_0.0.1V_TID-0405-EZ-2.yaml\",\r\n" + + "\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}],\r\n" + + "\t\t\"template-id-list\": [\"TID-0405-EZ\",\r\n\t\t\"TID-0405-EZ-2\"],\r\n" + + "\t\t\"scopeType\": \"vnf-type\"\r\n\t}"; JSONObject content = new JSONObject(contentStr); MockDBService dbService = MockDBService.initialise(); SvcLogicContext context = new SvcLogicContext(); @@ -230,24 +255,35 @@ public class ArtifactHandlerNodeTest { @Test public void testProcessArtifactListsWithVnfcTypeList() throws Exception { - String contentStr = "{\r\n\t\"action\": \"Configure\",\r\n\t\"action-level\": \"vnf\",\r\n\t\"scope\": {\r\n\t\t\"vnf-type\": " - + "\"newtypeofvnf\",\r\n\t\t\"vnfc-type-list\": [\"vnfctype1\",\"vnfctype2\"]\r\n\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\":" - + " [{\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"template-id\": \"vnfctype1\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": " - + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": " - + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t}," - + "\r\n\t\t{\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": " - + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": " - + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t}," - + "\r\n\t\t{\r\n\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": " - + "\"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n\t\t\t\t\"group-notation-type\": " - + "\"first-vnfc-name\",\r\n\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n\t\t}\r\n\t]," - + "\r\n\t\"device-protocol\": \"NETCONF-XML\",\r\n\t\"user-name\": \"netconf\",\r\n\t\"port-number\": \"20\",\r\n\t\"artifact-list\": " - + "[{\r\n\t\t\t\"artifact-name\": \"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.xml\",\r\n\t\t\t\"artifact-type\": " - + "\"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.yaml\"," - + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": " - + "\"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.xml\",\r\n\t\t\t\"artifact-type\": " - + "\"config_template\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.yaml\"," - + "\r\n\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}\r\n\t],\r\n\t\"scopeType\": \"vnf-type\"\r\n}"; + String contentStr = "{\r\n\t\"action\": \"Configure\",\r\n\t\"action-level\": \"vnf\",\r\n\t\"scope\": {\r\n" + + "\t\t\"vnf-type\": \"newtypeofvnf\",\r\n\t\t\"vnfc-type-list\": [\"vnfctype1\",\"vnfctype2\"]\r\n" + + "\t},\r\n\t\"template\": \"Y\",\r\n\t\"vm\": [{\r\n\t\t\t\"vm-instance\": 1,\r\n" + + "\t\t\t\"template-id\": \"vnfctype1\",\r\n\t\t\t\"vnfc\": [{\r\n" + + "\t\t\t\t\"vnfc-instance\": \"1\",\r\n\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n" + + "\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n" + + "\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n" + + "\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n" + + "\t\t},\r\n\t\t{\r\n\t\t\t\"vm-instance\": 1,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n" + + "\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n" + + "\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n" + + "\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n" + + "\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n" + + "\t\t},\r\n\t\t{\r\n\t\t\t\"vm-instance\": 2,\r\n\t\t\t\"template-id\": \"vnfctype2\",\r\n" + + "\t\t\t\"vnfc\": [{\r\n\t\t\t\t\"vnfc-instance\": \"1\",\r\n" + + "\t\t\t\t\"vnfc-function-code\": \"fcx\",\r\n\t\t\t\t\"ipaddress-v4-oam-vip\": \"Y\",\r\n" + + "\t\t\t\t\"group-notation-type\": \"first-vnfc-name\",\r\n" + + "\t\t\t\t\"group-notation-value\": \"pair\",\r\n\t\t\t\t\"vnfc-type\": \"vDBE\"\r\n\t\t\t}]\r\n" + + "\t\t}\r\n\t],\r\n\t\"device-protocol\": \"NETCONF-XML\",\r\n\t\"user-name\": \"netconf\",\r\n" + + "\t\"port-number\": \"20\",\r\n\t\"artifact-list\": [{\r\n" + + "\t\t\t\"artifact-name\": \"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.xml\",\r\n" + + "\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n\t\t{\r\n" + + "\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype1.yaml\",\r\n" + + "\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t},\r\n" + + "\t\t{\r\n\t\t\t\"artifact-name\": \"template_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.xml\",\r\n" + + "\t\t\t\"artifact-type\": \"config_template\"\r\n\t\t},\r\n" + + "\t\t{\r\n\t\t\t\"artifact-name\": \"pd_ConfigScaleOut_newtypeofvnf_0.0.1V_vnfctype2.yaml\",\r\n" + + "\t\t\t\"artifact-type\": \"parameter_definitions\"\r\n\t\t}\r\n\t],\r\n" + + "\t\"scopeType\": \"vnf-type\"\r\n}"; JSONObject content = new JSONObject(contentStr); MockDBService dbService = MockDBService.initialise(); SvcLogicContext context = new SvcLogicContext(); @@ -256,9 +292,9 @@ public class ArtifactHandlerNodeTest { JSONObject scope = (JSONObject)content.get("scope"); JSONArray vnfcTypeList = artifactHandlerNode.setVnfcTypeInformation(scope, context); artifactHandlerNode.processArtifactList(content, dbService, context, vnfcTypeList); - JSONArray vnfcLists = scope.getJSONArray("vnfc-type-list"); + JSONArray vnfcLists = scope.getJSONArray("vnfc-type-list"); assertEquals(vnfcLists.toString(), "[\"vnfctype1\",\"vnfctype2\"]"); - assertEquals(context.getAttribute("vnfc-type"),"vnfctype2"); + assertEquals(context.getAttribute("vnfc-type"), "vnfctype2"); assertNotNull (vnfcTypeList); } @@ -274,7 +310,7 @@ public class ArtifactHandlerNodeTest { JSONObject documentInfo = getDocumentInfo("templates/pd_template"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "pd_Junit.json"); requestInfo.put("RequestInfo", "testValue"); - requestInfo.put("request-id","testREQUEST_ID"); + requestInfo.put("request-id", "testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); @@ -285,15 +321,17 @@ public class ArtifactHandlerNodeTest { private JSONObject getDocumentInfo(String filename) throws IOException { JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream(filename), Charset.defaultCharset()); + String artifactContent = IOUtils.toString( + ArtifactHandlerProviderUtilTest.class.getClassLoader().getResourceAsStream(filename), + Charset.defaultCharset()); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "12345"); documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "12345"); documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "12345"); documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "12345"); - documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "12345"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "12345"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "12345"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_NAME, "12345"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "12345"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "12345"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "12345"); @@ -302,70 +340,81 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "12345"); return documentInfo; } - - + + @Test public void testValidateAnsibleAdminArtifact() throws Exception { - String contentStr = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"," - + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," - + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," - + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\"," - + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," - + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid5\"," - + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," - + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," - + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," - + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; - - JSONObject documentInfo = new JSONObject(); + String contentStr = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid3\"," + + "\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\"," + + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"}," + + "{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," + + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," + + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; + + JSONObject documentInfo = new JSONObject(); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStr); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); artifactHandlerNode.validateAnsibleAdminArtifact(documentInfo); } - + @Test public void testValidateAnsibleAdminArtifactWithException() throws Exception { - String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"," - + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," - + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," - + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}],\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\"," - + "\"create-date\":\"\",\"modify-username\":\"\",\"modify-date\":\"\"},{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," - + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid1\"," - + "\"tenantuuid6\"]},{\"region-id\":\"san4b\",\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," - + "\"region-id-list\":[{\"region-id\":\"san4a\",\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," - + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," - + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; - JSONObject documentInfoOne = new JSONObject(); - documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne); - documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); - - try { - artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne); - fail("Missing exception"); - }catch(ArtifactHandlerInternalException e) { + String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid2\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid3\",\"tenantuuid4\"]}]}]," + + "\"description\":\"fqdn for east zone Production\",\"username\":\"attuid\",\"create-date\":\"\"," + + "\"modify-username\":\"\",\"modify-date\":\"\"}," + + "{\"vnf-management-server-fqdn\":\"fqdn-value2 url:port\"," + + "\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\",\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid1\",\"tenantuuid6\"]},{\"region-id\":\"san4b\"," + + "\"tenant-id-list\":[\"tenantuuid5\",\"tenantuuid6\"]}]},{\"cloud-owner\":\"nc1.0\"," + + "\"region-id-list\":[{\"region-id\":\"san4a\"," + + "\"tenant-id-list\":[\"tenantuuid7\",\"tenantuuid8\"]}]}]," + + "\"description\":\"fqdn for east zone Test\",\"username\":\"attuid\",\"create-date\":\"\"," + + "\"modify-username\":\"\",\"modify-date\":\"\"}]}"; + JSONObject documentInfoOne = new JSONObject(); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne); + documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); + + try { + artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne); + fail("Missing exception"); + } catch (ArtifactHandlerInternalException e) { assertTrue(e.getMessage().contains("Validation Failure")); - } - + } + } - + @Test public void testValidateAnsibleAdminArtifactWithJSONException() throws Exception { - String contentStrOne = "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"}"; - - JSONObject documentInfoOne = new JSONObject(); + String contentStrOne = + "{\"fqdn-list\":[{\"vnf-management-server-fqdn\":\"fqdn-value1 url:port\",\"cloud-owner-list\":[{\"cloud-owner\":\"aic3.0\"}"; + + JSONObject documentInfoOne = new JSONObject(); documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, contentStrOne); documentInfoOne.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.1V.json"); - + try { artifactHandlerNode.validateAnsibleAdminArtifact(documentInfoOne); fail("Missing exception"); - }catch(ArtifactHandlerInternalException je) { - assertTrue(je.getMessage().contains("JSON Exception")); - - } - - } - + } catch (ArtifactHandlerInternalException je) { + assertTrue(je.getMessage().contains("JSON Exception")); + } + + } + @Test public void testProcessArtifactWithException() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); @@ -376,12 +425,13 @@ public class ArtifactHandlerNodeTest { inParams.put("response_prefix", "prefix"); JSONObject requestInfo = new JSONObject(); JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + String artifactContent = IOUtils.toString( + ArtifactHandlerProviderUtilTest.class.getClassLoader().getResourceAsStream("templates/reference_template"), + Charset.defaultCharset()); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, ""); requestInfo.put("RequestInfo", "testValue"); - requestInfo.put("request-id","testREQUEST_ID"); + requestInfo.put("request-id", "testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); @@ -389,11 +439,12 @@ public class ArtifactHandlerNodeTest { try { artifactHandlerNode.processArtifact(inParams, ctx); fail("Missing exception"); - }catch(Exception e) { - assertTrue(e.getMessage().contains("Missing Artifact Name")); + } catch (Exception e) { + assertTrue(e.getMessage().contains("Missing Artifact Name")); } - + } + @Test public void testProcessArtifactWithExceptionforAnsible() throws Exception { SvcLogicContext ctx = new SvcLogicContext(); @@ -404,25 +455,26 @@ public class ArtifactHandlerNodeTest { inParams.put("response_prefix", "prefix"); JSONObject requestInfo = new JSONObject(); JSONObject documentInfo = new JSONObject(); - String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() - .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + String artifactContent = IOUtils.toString( + ArtifactHandlerProviderUtilTest.class.getClassLoader().getResourceAsStream("templates/reference_template"), + Charset.defaultCharset()); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "ansible_admin_FQDN_Artifact_0.0.2V.json"); requestInfo.put("RequestInfo", "testValue"); - requestInfo.put("request-id","testREQUEST_ID"); + requestInfo.put("request-id", "testREQUEST_ID"); input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); postData.put("input", input); inParams.put("postData", postData.toString()); - + try { - artifactHandlerNode.processArtifact(inParams, ctx); - fail("Missing exception"); - }catch(Exception e) { - assertTrue(e.getMessage().contains("JSON Exception:ansible admin")); + artifactHandlerNode.processArtifact(inParams, ctx); + fail("Missing exception"); + } catch (Exception e) { + assertTrue(e.getMessage().contains("JSON Exception:ansible admin")); } - } - + } + @Test public void testProcessAndStoreCapablitiesArtifact() throws Exception { ArtifactHandlerNode ah = new ArtifactHandlerNode(); @@ -435,6 +487,7 @@ public class ArtifactHandlerNodeTest { documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_NAME, "testResName"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers"); documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType"); documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); @@ -443,6 +496,6 @@ public class ArtifactHandlerNodeTest { Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities, "artifactName", "someVnf"); } - + } diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java index cf27dce63..529fa368b 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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. - * * ============LICENSE_END========================================================= */ @@ -32,8 +31,8 @@ import java.io.IOException; import java.nio.charset.Charset; import org.apache.commons.io.IOUtils; import org.json.JSONObject; -import org.junit.Test; import org.junit.Ignore; +import org.junit.Test; import org.mockito.Mockito; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInput; import org.opendaylight.yang.gen.v1.org.onap.appc.artifacthandler.rev170321.UploadartifactInputBuilder; @@ -57,7 +56,7 @@ public class ArtifactHandlerProviderUtilTest { ahprovider.processTemplate(obj.toString()); } - @Ignore + // @Ignore @Test(expected = Exception.class) public void testcreateDummyRequestData() throws Exception { String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() @@ -67,7 +66,7 @@ public class ArtifactHandlerProviderUtilTest { obj.put("artifact-version", "0.01"); obj.put("artifact-contents", artifact_conetent); ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); - ahprovider.createDummyRequestData(); + String requestInfo = ahprovider.createDummyRequestData(); } @Test @@ -78,6 +77,13 @@ public class ArtifactHandlerProviderUtilTest { } @Test + public void testGetRandom() throws Exception { + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + Whitebox.invokeMethod(ahprovider, "getRandom"); + assertTrue(true); + } + + @Test public void testEscapeUtils() throws Exception { String str = "The Test string is 'test'"; assertEquals("The Test string is ''test''", EscapeUtils.escapeSql(str)); @@ -105,7 +111,8 @@ public class ArtifactHandlerProviderUtilTest { builder.setRequestInformation(mockRequestInformation); UploadartifactInput uploadArtifactInput = builder.build(); Whitebox.setInternalState(ahprovider, "templateData", uploadArtifactInput); - assertTrue(ahprovider.createDummyRequestData().startsWith("{\"input\": {\"document-parameters\":{\"service-uuid\":\"TLSUUIDREQUEST ID\"")); + assertTrue(ahprovider.createDummyRequestData() + .startsWith("{\"input\": {\"document-parameters\":{\"service-uuid\":\"TLSUUIDREQUEST ID\"")); } @Test @@ -125,4 +132,3 @@ public class ArtifactHandlerProviderUtilTest { ahProvider.createRequestData()); } } - |