diff options
Diffstat (limited to 'appc-inbound')
16 files changed, 1221 insertions, 726 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()); } } - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java index 3cbbd88b1..6381aee0d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignInfo.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========================================================= */ @@ -26,29 +25,34 @@ package org.onap.appc.design.data; import com.fasterxml.jackson.annotation.JsonProperty; public class DesignInfo{ - + @JsonProperty("vnf-type") String vnf_type; - + @JsonProperty("vnfc-type") String vnfc_type; - + @JsonProperty("protocol") String protocol; - + @JsonProperty("incart") String inCart; - + @JsonProperty("action") String action; - + @JsonProperty("artifact-name") String artifact_name; - @JsonProperty("artifact-type") String artifact_type; + @JsonProperty("permission") + String permission; + + @JsonProperty("creatorUserId") + String creatorUserId; + public String getArtifact_type() { return artifact_type; } @@ -105,10 +109,26 @@ public class DesignInfo{ this.inCart = inCart; } + public String getPermission() { + return permission; + } + + public void setPermission(String permission) { + this.permission = permission; + } + + public String getCreatorUserId() { + return creatorUserId; + } + + public void setCreatorUserId(String creatorUserId) { + this.creatorUserId = creatorUserId; + } + @Override public String toString() { return "DesignInfo [vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + protocol + ", inCart=" + inCart + "]"; } - + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java index 84fb55cfb..72f60bc80 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/DesignResponse.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========================================================= */ @@ -28,19 +27,23 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class DesignResponse{ - @JsonProperty("userID") - String userId ; - + String userId; + @JsonProperty("designInfo") List<DesignInfo> designInfoList; - + @JsonProperty("statusInfo") List<StatusInfo> statusInfoList; - + @JsonProperty("artifactInfo") List<ArtifactInfo> artifactInfo; - + + @JsonProperty("vnf-type") + String vnfType; + + @JsonProperty("users") + List<UserPermissionInfo> users; public List<ArtifactInfo> getArtifactInfo() { return artifactInfo; @@ -65,7 +68,7 @@ public class DesignResponse{ public void setDesignInfoList(List<DesignInfo> designInfoList) { this.designInfoList = designInfoList; } - + public List<StatusInfo> getStatusInfoList() { return statusInfoList; } @@ -73,4 +76,21 @@ public class DesignResponse{ public void setStatusInfoList(List<StatusInfo> statusInfoList) { this.statusInfoList = statusInfoList; } + + public String getVnfType() { + return vnfType; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public List<UserPermissionInfo> getUsers() { + return users; + } + + public void setUsers(List<UserPermissionInfo> userPermInfoList) { + this.users = userPermInfoList; + } + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java new file mode 100644 index 000000000..bbe87dee1 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/data/UserPermissionInfo.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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========================================================= + */ + +package org.onap.appc.design.data; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class UserPermissionInfo { + + @JsonProperty("userID") + String userID; + @JsonProperty("permission") + String permission; + + public String getUserID() { + return userID; + } + + public String getPermission() { + return permission; + } + + public void setUserID(String user_id) { + this.userID = user_id; + } + + public void setPermission(String perm) { + this.permission = perm; + } +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java index 5e5f78a53..9ed45be8c 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DbResponseProcessor.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========================================================= */ @@ -31,93 +30,104 @@ import com.att.eelf.configuration.EELFManager; public class DbResponseProcessor { private static final EELFLogger log = EELFManager.getInstance().getLogger(DbResponseProcessor.class); - public String parseResponse(String dbresposne, String action) throws Exception { - - log.info("Starting Parsing the response for action :[" + action + "]\n data:[" + dbresposne +"]" ); - String response ; + public String parseResponse(String dbresponse, String action) throws Exception { + + log.info("Starting Parsing the response for action :[" + action + "]\ndata:[" + dbresponse + "]"); + String response; switch (action) { case DesignServiceConstants.GETDESIGNS: - response = getDesignsResponse(dbresposne); + response = getDesignsResponse(dbresponse); break; case DesignServiceConstants.GETAPPCTIMESTAMPUTC: - response = getAppcTimestampResponse(dbresposne); + response = getAppcTimestampResponse(dbresponse); break; case DesignServiceConstants.ADDINCART: - response = getAddInCartResponse(dbresposne); - break ; + response = getAddInCartResponse(dbresponse); + break; case DesignServiceConstants.GETARTIFACTREFERENCE: - response= getArtifactReferenceResponse(dbresposne); + response = getArtifactReferenceResponse(dbresponse); break; case DesignServiceConstants.GETARTIFACT: - response= getArtifactResponse(dbresposne); + response = getArtifactResponse(dbresponse); break; case DesignServiceConstants.GETGUIREFERENCE: - response= getGuiReferenceResponse(dbresposne); + response = getGuiReferenceResponse(dbresponse); break; case DesignServiceConstants.GETSTATUS: - response= getStatusResponse(dbresposne); + response = getStatusResponse(dbresponse); break; case DesignServiceConstants.UPLOADARTIFACT: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.SETPROTOCOLREFERENCE: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.SETINCART: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.UPLOADADMINARTIFACT: - response= getsetStatusResponse(dbresposne); - break; + response = getSetStatusResponse(dbresponse); + break; case DesignServiceConstants.CHECKVNF: - response= getStatusResponse(dbresposne); - break; + response = getStatusResponse(dbresponse); + break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + response = getStatusResponse(dbresponse); + break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + response = getRetrieveVnfPermissionsResponse(dbresponse); + break; default: - log.error("Action " + action + " Not Supported by response Parser"); - throw new Exception(" Action " + action + " not found while processing request "); + log.error("Action " + action + " Not Supported by Response Parser"); + throw new Exception("Action " + action + " not found while processing request"); - } - return response; + } + return response; } - private String getArtifactResponse(String dbresposne) { + private String getArtifactResponse(String dbresponse) { // TODO Auto-generated method stub - return dbresposne; + return dbresponse; } - private String getsetStatusResponse(String dbresposne) { + private String getSetStatusResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getStatusResponse(String dbresposne) { - log.info("Returning reposne from Response Parser " + dbresposne); - return dbresposne; + private String getStatusResponse(String dbresponse) { + log.info("Returning response from Response Parser " + dbresponse); + return dbresponse; } - private String getGuiReferenceResponse(String dbresposne) { + private String getGuiReferenceResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getArtifactReferenceResponse(String dbresposne) { + private String getArtifactReferenceResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getAddInCartResponse(String dbresposne) { + private String getAddInCartResponse(String dbresponse) { // TODO Auto-generated method stub return null; } - private String getDesignsResponse(String dbresposne) { - return dbresposne; - + private String getDesignsResponse(String dbresponse) { + return dbresponse; } - private String getAppcTimestampResponse(String dbresposne) { - log.info("getAppcTimestampResponse:[" + dbresposne +"]" ); - return dbresposne; + private String getAppcTimestampResponse(String dbresponse) { + log.info("getAppcTimestampResponse:[" + dbresponse +"]" ); + return dbresponse; } + + private String getRetrieveVnfPermissionsResponse(String dbresponse) { + log.info("Returning response from Response Parser " + dbresponse); + return dbresponse; + } + } diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java index 2353e6b0c..723818f92 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/DesignDBService.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 * ================================================================================ @@ -30,39 +30,45 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Strings; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import java.util.Date; +import java.text.DateFormat; +import java.text.SimpleDateFormat; import org.json.JSONObject; import org.onap.appc.design.data.ArtifactInfo; import org.onap.appc.design.data.DesignInfo; import org.onap.appc.design.data.DesignResponse; import org.onap.appc.design.data.StatusInfo; +import org.onap.appc.design.data.UserPermissionInfo; import org.onap.appc.design.services.util.ArtifactHandlerClient; import org.onap.appc.design.services.util.DesignServiceConstants; import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.apache.commons.lang.StringUtils; public class DesignDBService { private static final EELFLogger log = EELFManager.getInstance().getLogger(DesignDBService.class); private static DesignDBService dgGeneralDBService; - + private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory(); private static final String SUCCESS_JSON = "{\"update\" : \"success\" } "; private static final String STATUS = "STATUS"; - private static final String INFO_STR = "Info : "; - private static final String DB_OPERATION_ERROR = "Error while DB operation : "; + private static final String INFO_STR = "Info: "; + private static final String DB_OPERATION_ERROR = "Error during DB operation: "; private static final String VNFC_TYPE = "vnfc-type"; - private static final String QUERY_STR = "Query String :"; + private static final String VNF_TYPE = "vnf-type"; + private static final String QUERY_STR = "Query String: "; private static final String USER_ID = "userID"; + private static final String COLUMN_USER_ID = "user_id"; + private static final String COLUMN_PERMISSION = "permission"; private SvcLogicResource serviceLogic; private DbService dbservice; - private static ArtifactHandlerFactory artifactHandlerFactory = new ArtifactHandlerFactory(); - public static DesignDBService initialise() { if (dgGeneralDBService == null) { dgGeneralDBService = new DesignDBService(); @@ -76,144 +82,277 @@ public class DesignDBService { } } - public String execute(String action, String payload, String requestID) throws Exception { + public String execute(String action, String payload, String requestId) throws Exception { - log.info("Received execute request for action : " + action + " with Payload : " + payload); + log.info("Received execute request for action: " + action + " with Payload: " + payload); RequestValidator.validate(action, payload); String response; dbservice = new DbService(); switch (action) { case DesignServiceConstants.GETDESIGNS: - response = getDesigns(payload, requestID); + response = getDesigns(payload, requestId); break; case DesignServiceConstants.GETAPPCTIMESTAMPUTC: - response = getAppcTimestampUTC( requestID ); + response = getAppcTimestampUTC(requestId); break; case DesignServiceConstants.ADDINCART: - response = setInCart(payload, requestID); + response = setInCart(payload, requestId); break; case DesignServiceConstants.GETARTIFACTREFERENCE: - response = getArtifactReference(payload, requestID); + response = getArtifactReference(payload, requestId); break; case DesignServiceConstants.GETARTIFACT: - response = getArtifact(payload, requestID); + response = getArtifact(payload, requestId); break; case DesignServiceConstants.GETGUIREFERENCE: - response = getGuiReference(payload, requestID); + response = getGuiReference(payload, requestId); break; case DesignServiceConstants.GETSTATUS: - response = getStatus(payload, requestID); + response = getStatus(payload, requestId); break; case DesignServiceConstants.SETSTATUS: - response = setStatus(payload, requestID); + response = setStatus(payload, requestId); break; case DesignServiceConstants.UPLOADARTIFACT: - response = uploadArtifact(payload, requestID); + response = uploadArtifact(payload, requestId); break; case DesignServiceConstants.SETPROTOCOLREFERENCE: - response = setProtocolReference(payload, requestID); + response = setProtocolReference(payload, requestId); break; case DesignServiceConstants.UPLOADADMINARTIFACT: - response = uploadAdminArtifact(payload, requestID); + response = uploadAdminArtifact(payload, requestId); break; case DesignServiceConstants.CHECKVNF: - response = checkVNF(payload, requestID); + response = checkVNF(payload, requestId); + break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + response = retrieveVnfPermissions(payload, requestId); + break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + response = saveUserPermissionInfo(payload, requestId); break; default: - throw new DBException(" Action " + action + " not found while processing request "); + throw new DBException("Action " + action + " not found while processing request"); } return response; } + private String saveUserPermissionInfo(String payload, String requestId) throws Exception { + try { + if (requestId == null || requestId.isEmpty()) { + throw new DBException("requestId in saveUserPermissionInfo request is null or Blank"); + } + log.info("Received Save User Permission from " + requestId + " with payload " + payload); + Date startTime = new Date(); + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + String dbDate = dateFormat.format(startTime); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String vnf_type = payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue(); + String modifier = payloadObject.get(DesignServiceConstants.CREATORUSERID).textValue(); + JsonNode users = payloadObject.get("users"); + if (users == null || !users.isArray()) { + throw new DBException("Users list is not provided in the input payload"); + } + for (JsonNode node : users) { + String userId = node.get(DesignServiceConstants.USER_ID).textValue(); + String permission = node.get(DesignServiceConstants.PERMISSION).textValue(); + ArrayList<String> argList = new ArrayList<>(); + argList.add(vnf_type); + argList.add(userId); + log.info("Checking User - " + userId + " current permissions in db for this vnf type"); + String queryString = "SELECT PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + queryString); + String user_permission = null; + int rowCount = 0; + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + rowCount++; + user_permission = data.getString("PERMISSION"); + if (Strings.isNullOrEmpty(permission)) { + log.info("Received request to delete db record for User - " + userId); + ArrayList<String> delArgList = new ArrayList<>(); + delArgList.add(vnf_type); + delArgList.add(userId); + String deleteQuery = "DELETE FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + deleteQuery); + log.info("Arguments List: " + delArgList); + boolean status = dbservice.updateDBData(deleteQuery, delArgList); + if (!status) { + throw new DBException("Error while deleting record from DT_USER_PERMISSIONS"); + } else { + log.info("Record deleted"); + } + } else if (user_permission.matches(permission)) { + log.info("User " + userId + " permission record found in db for same vnf_type " + vnf_type + + ". No update needed."); + } else { + log.info("User's permission record will be updated. New permission: " + permission + + " for user " + userId + " as requested by " + requestId + + " will be saved to database."); + ArrayList<String> updateArgList = new ArrayList<>(); + updateArgList.add(permission); + updateArgList.add(modifier); + updateArgList.add(dbDate); + updateArgList.add(vnf_type); + updateArgList.add(userId); + + String updateQuery = + "UPDATE DT_USER_PERMISSIONS SET PERMISSION = ?, MODIFIER = ?, DATE_MODIFIED = ?" + + " WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + updateQuery); + log.info("Arguments List: " + updateArgList); + boolean updateStatus = dbservice.updateDBData(updateQuery, updateArgList); + if (!updateStatus) { + throw new DBException("Error while updating User Permissions"); + } + } + } + } + if (rowCount == 0 && !(Strings.isNullOrEmpty(permission))) { + log.info("User not found in database for this vnf_type. The new permission " + permission + + " for user " + userId + " and vnf_type " + vnf_type + " as requested by " + requestId + + " will be saved to database."); + ArrayList<String> insertArgList = new ArrayList<>(); + insertArgList.add(vnf_type); + insertArgList.add(userId); + insertArgList.add(permission); + insertArgList.add(modifier); + String insertQuery = + "INSERT INTO DT_USER_PERMISSIONS (VNF_TYPE, USER_ID, PERMISSION, DATE_MODIFIED, MODIFIER)" + + " VALUES (?, ?, ?, sysdate(), ?)"; + log.info(QUERY_STR + insertQuery); + log.info("Arguments List: " + insertArgList); + boolean updateStatus = dbservice.updateDBData(insertQuery, insertArgList); + if (!updateStatus) { + throw new DBException("Error while inserting record for User Permissions"); + } + } + } + } catch (Exception e) { + log.error("An error occurred in saveUserPermissionInfo " + e.getMessage(), e); + throw e; + } + return SUCCESS_JSON; + } + private String checkVNF(String payload, String requestId) throws Exception { + try { + log.info("Got into Check VNF Request with payload: " + payload); + if (payload == null || payload.isEmpty()) { + throw new DBException("Payload in CheckVNF request is null or Blank"); + } + if (requestId == null || requestId.isEmpty()) { + throw new DBException("requestId in CheckVNF request is null or Blank"); + } + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + String vnfType = payloadObject.get("vnf-type").textValue(); - log.info("Got into Check VNF Request with payload: " + payload); - if (StringUtils.isBlank(payload)) - throw new DBException("Payload in CheckVNF request is null or Blank"); - if (StringUtils.isBlank(requestId)) - throw new DBException("requestId in CheckVNF request is null or Blank"); - ObjectMapper objectMapper = new ObjectMapper(); - JsonNode payloadObject = objectMapper.readTree(payload); - String vnfType = payloadObject.get("vnf-type").textValue(); - log.info("Check VNF Request with VNF TYPE: " + vnfType); - ArrayList<String> argList = new ArrayList<>(); - argList.add(vnfType); - String queryString = "SELECT DT_ACTION_STATUS_ID,USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ? ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1 ; "; - log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - int rowCount = 0; - String user = null; - String dtActionStatusId = null; - while (data.next()) { - rowCount++; - user = data.getString("USER"); - dtActionStatusId = data.getString("DT_ACTION_STATUS_ID"); - } - log.debug("DT_ACTION_STATUS_ID-> " + dtActionStatusId + " user-> " + user); - JSONObject jObject = new JSONObject(); - if (rowCount == 0) { - log.debug("vnf-type does not present in APPC DB, row Count:" + rowCount); - jObject.put("result", "No"); - } else { - log.debug("vnf-type present in APPC DB, row Count:" + rowCount); - jObject.put("result", "Yes"); - jObject.put("user", user); - } - log.info("Check VNF result: " + jObject.toString()); + log.info("Check VNF Request with VNF TYPE: " + vnfType); + + ArrayList<String> argList = new ArrayList<>(); + argList.add(vnfType); + + String queryString = + "SELECT DT_ACTION_STATUS_ID, USER FROM sdnctl.DT_ACTION_STATUS WHERE VNF_TYPE = ?" + + " ORDER BY DT_ACTION_STATUS_ID DESC LIMIT 1;"; + + log.info(QUERY_STR + queryString); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + String user = null; + String dtActionStatusId = null; + + while (data.next()) { + rowCount++; + user = data.getString("USER"); + dtActionStatusId = data.getString("DT_ACTION_STATUS_ID"); + } + + log.debug("DT_ACTION_STATUS_ID " + dtActionStatusId + " user " + user); + + JSONObject jObject = new JSONObject(); + + + if (rowCount == 0) { + log.debug("vnf-type not present in APPC DB, row Count: " + rowCount); + jObject.put("result", "No"); + } else { + log.debug("vnf-type present in APPC DB, row Count: " + rowCount); + jObject.put("result", "Yes"); + jObject.put("user", user); + } + + log.info("Check VNF result: " + jObject.toString()); + return jObject.toString(); - return jObject.toString(); + } + } catch (Exception e) { + log.error("An error occurred in checkVNF " + e.getMessage(), e); + throw e; + } } private String uploadAdminArtifact(String payload, String requestId) throws Exception { + try { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); + JsonNode payloadObject = objectMapper.readTree(payload); + log.info("Got upload Admin Artifact with requestId: " + requestId + " & Payload: " + + payloadObject.asText()); + + if (Strings.isNullOrEmpty(requestId)) { + throw new DBException("Request-id is missing in the uploadAdminArtifact payload."); + } + + ArtifactHandlerClient ac = new ArtifactHandlerClient(); + String requestString = ac.createArtifactData(payload, requestId); + ac.execute(requestString, "POST"); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); - JsonNode payloadObject = objectMapper.readTree(payload); - log.info("Got upload Admin Aritfact with requestId : " + requestId + " & Payload" + payloadObject.asText()); - if (StringUtils.isBlank(requestId)) { - throw new DBException("Request-id is missing in the uploadAdminArtifact payload . "); - } - ArtifactHandlerClient ac = new ArtifactHandlerClient(); - String requestString = ac.createArtifactData(payload, requestId); - ac.execute(requestString, "POST"); + int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); + if (sdcArtifactId == 0) { + throw new DBException("Error occurred while validating/Saving the artifact to SDC_ARTIFACTS" + + " or getting SDC_ARTIFACTS_ID."); + } - int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); - if (sdcArtifactId == 0) - throw new DBException( - "Error occured while validating/Saving the artifact to SDC_ARTIFACTS or getting SDC_ARTIFACTS_ID ."); - JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID); - if (json == null) { - throw new DBException("User Id is null"); - } else if (json.asText().trim().isEmpty()) { - log.info("UserId in Admin Aritfact is blank, User Id : " + json.asText()); - throw new DBException("User Id is blank"); - } + JsonNode json = payloadObject.get(DesignServiceConstants.USER_ID); + if (json == null) { + throw new DBException("User Id is null"); + } else if (json.asText().trim().isEmpty()) { + log.info("UserId in Admin Artifact is blank, User Id: " + json.asText()); + throw new DBException("User Id is blank"); + } - int sdcReferenceId = 0; - createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); + int sdcReferenceId = 0; + createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); + } catch (Exception e) { + log.error("An error occurred in uploadAdminArtifact: " + e.getMessage(), e); + throw e; + } return SUCCESS_JSON; } - private String getAppcTimestampUTC( String requestID) throws Exception - { - log.info("Starting getAppcTimestampUTC: requestID:" + requestID ); - java.util.TimeZone gmtTZ= java.util.TimeZone.getTimeZone("GMT"); - java.text.SimpleDateFormat formatter = - new java.text.SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ); - formatter.setTimeZone( gmtTZ ); - java.util.Date dateVal= new java.util.Date(); - log.info("getAppcTimestampUTC: current local Date:[" + dateVal+ "]"); - String timeStr= formatter.format( dateVal ); - log.info("getAppcTimestampUTC: returning:[" + timeStr + "]"); - return timeStr; + private String getAppcTimestampUTC(String requestId) throws Exception { + log.info("Starting getAppcTimestampUTC: requestId: " + requestId); + java.util.TimeZone gmtTZ = java.util.TimeZone.getTimeZone("GMT"); + java.text.SimpleDateFormat formatter = + new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + formatter.setTimeZone(gmtTZ); + java.util.Date dateVal = new java.util.Date(); + log.info("getAppcTimestampUTC: current local Date: [" + dateVal + "]"); + String timeStr = formatter.format(dateVal); + log.info("getAppcTimestampUTC: returning: [" + timeStr + "]"); + return timeStr; } - private String setInCart(String payload, String requestID) throws Exception { + private String setInCart(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -221,16 +360,16 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.INCART).textValue()); argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); - String queryString = "UPDATE DT_ARTIFACT_TRACKING SET INCART= ? WHERE ASDC_REFERENCE_ID IN " - + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ? "; + String queryString = + "UPDATE DT_ARTIFACT_TRACKING SET INCART = ? WHERE ASDC_REFERENCE_ID IN" + + " (SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE_ID WHERE VNF_TYPE = ?"; - if (payloadObject.get(DesignServiceConstants.VNF_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNF_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? ) AND USER = ? "; + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + queryString += " AND VNFC_TYPE = ?"; argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - } else { - queryString = queryString + " ) AND USER = ? "; } + queryString += ") AND USER = ?"; argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); @@ -241,7 +380,7 @@ public class DesignDBService { return SUCCESS_JSON; } - private String setProtocolReference(String payload, String requestID) throws Exception { + private String setProtocolReference(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -252,9 +391,9 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); - String queryString = " DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE= ? AND PROTOCOL = ? "; + String queryString = "DELETE FROM PROTOCOL_REFERENCE WHERE ACTION = ? AND ACTION_LEVEL AND VNF_TYPE = ? AND PROTOCOL = ?"; - log.info("Delete Query String :" + queryString); + log.info("Delete Query String: " + queryString); boolean data; log.info("Record Deleted"); @@ -270,10 +409,9 @@ public class DesignDBService { if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? )"; - } else { - queryString = queryString + " ) "; + queryString += " AND VNFC_TYPE = ?"; } + queryString += ")"; log.info(QUERY_STR + queryString); data = dbservice.updateDBData(queryString, argList); @@ -283,33 +421,72 @@ public class DesignDBService { return SUCCESS_JSON; } - private String uploadArtifact(String payload, String requestID) throws Exception { + private String uploadArtifact(String payload, String requestId) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true); JsonNode payloadObject = objectMapper.readTree(payload); - log.info("Got upload Aritfact with Payload : " + payloadObject.asText()); + log.info("Got upload Artifact with Payload: " + payloadObject.asText()); try { ArtifactHandlerClient ac = artifactHandlerFactory.ahi(); - String requestString = ac.createArtifactData(payload, requestID); + String requestString = ac.createArtifactData(payload, requestId); ac.execute(requestString, "POST"); - int sdcArtifactId = getSDCArtifactIDbyRequestID(requestID); + int sdcArtifactId = getSDCArtifactIDbyRequestID(requestId); int sdcReferenceId = getSDCReferenceID(payload); - createArtifactTrackingRecord(payload, requestID, sdcArtifactId, sdcReferenceId); + createArtifactTrackingRecord(payload, requestId, sdcArtifactId, sdcReferenceId); String status = getDataFromActionStatus(payload, STATUS); if (status == null || status.isEmpty()) { - log.info("Action Status is: "+ status); - setActionStatus(payload, "Not Tested"); + log.info("Action Status is: " + status); + setActionStatus(payload, "Not Tested"); } linkstatusRelationShip(sdcArtifactId, sdcReferenceId, payload); - + savePermissionInfo(payload, requestId); } catch (Exception e) { - log.error("An error occured in uploadArtifact", e); + log.error("An error occurred in uploadArtifact", e); throw e; } return SUCCESS_JSON; } + private void savePermissionInfo(String payload, String requestId) throws Exception { + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList<String> argList = new ArrayList<>(); + argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + log.info("Entered savePermissionInfo from uploadArtifact with payload " + payload); + String queryString = "SELECT PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ? AND USER_ID = ?"; + log.info(QUERY_STR + queryString); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + String user_permission = null; + int rowCount = 0; + while (data.next()) { + rowCount++; + user_permission = data.getString("PERMISSION"); + log.info("User exists in database with permission = " + user_permission); + } + if (rowCount == 0) { + log.info("No record found in database"); + log.info("Inserting one record in database"); + String permission = "owner"; + ArrayList<String> insertArgList = new ArrayList<>(); + insertArgList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); + insertArgList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + insertArgList.add(permission); + insertArgList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); + String insertQuery = + "INSERT INTO DT_USER_PERMISSIONS (VNF_TYPE, USER_ID, PERMISSION, DATE_MODIFIED, MODIFIER)" + + " VALUES (?, ?, ?, sysdate(), ?)"; + log.info(QUERY_STR + insertQuery); + log.info("Arguments List: " + insertArgList); + boolean updateStatus = dbservice.updateDBData(insertQuery, insertArgList); + if (!updateStatus) { + throw new DBException("Error while inserting record to DT_USER_PERMISSIONS"); + } + } + } + } private void linkstatusRelationShip(int sdcArtifactId, int sdcReferenceId, String payload) throws Exception { @@ -323,21 +500,22 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); String queryString = - "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID,DT_ACTION_STATUS_ID) VALUES " + - "(( SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ? ) , " - + "( SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; - - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { - queryString = queryString + " AND VNFC_TYPE = ? GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) )"; - } else { - queryString = queryString + " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ) ) "; + "INSERT INTO DT_STATUS_RELATIONSHIP (DT_ARTIFACT_TRACKING_ID, DT_ACTION_STATUS_ID) VALUES" + + " ((SELECT DT_ARTIFACT_TRACKING_ID FROM DT_ARTIFACT_TRACKING" + + " WHERE ASDC_ARTIFACTS_ID = ? AND ASDC_REFERENCE_ID = ?)," + + " (SELECT DT_ACTION_STATUS_ID FROM DT_ACTION_STATUS" + + " WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ?"; + + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + queryString += " AND VNFC_TYPE = ?"; } + queryString += " GROUP BY VNF_TYPE HAVING COUNT(VNF_TYPE)>=1 ))"; log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); if (!data) { - throw new DBException("Error while updating RelationShip table"); + throw new DBException("Error while updating Relationship table"); } } @@ -352,29 +530,30 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_TYPE).textValue()); argList.add(payloadObject.get(DesignServiceConstants.ARTIFACT_NAME).textValue()); - String queryString = " SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ? " - + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ? "; + String queryString = + "SELECT ASDC_REFERENCE_ID FROM ASDC_REFERENCE WHERE VNF_TYPE = ?" + + " AND ARTIFACT_TYPE = ? AND ARTIFACT_NAME = ?"; - if (payloadObject.get(DesignServiceConstants.ACTION) != null && !payloadObject - .get(DesignServiceConstants.ACTION).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.ACTION) != null + && !payloadObject.get(DesignServiceConstants.ACTION).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); - queryString = queryString + " AND ACTION = ? "; + queryString += " AND ACTION = ?"; } - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; - + queryString += " AND VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - int sdcReferenceId = 0; - while (data.next()) { - sdcReferenceId = data.getInt("ASDC_REFERENCE_ID"); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + int sdcReferenceId = 0; + while (data.next()) { + sdcReferenceId = data.getInt("ASDC_REFERENCE_ID"); + } + log.info("Got sdcReferenceId = " + sdcReferenceId); + return sdcReferenceId; } - log.info("Got sdcReferenceId= " + sdcReferenceId); - return sdcReferenceId; } private String getDataFromActionStatus(String payload, String dataValue) throws Exception { @@ -386,19 +565,20 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.ACTION).textValue()); argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); String queryString = - " SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ? "; - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + "SELECT " + dataValue + " FROM DT_ACTION_STATUS WHERE VNF_TYPE = ? AND ACTION = ? AND USER = ?"; + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); - queryString = queryString + " AND VNFC_TYPE = ? "; + queryString += " AND VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - status = data.getString(STATUS); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + status = data.getString(STATUS); + } + log.info("DT_ACTION_STATUS Status = " + status); + return status; } - log.info("DT_ACTION_STATUS Status = " + status); - return status; } private void setActionStatus(String payload, String status) throws Exception { @@ -409,16 +589,16 @@ public class DesignDBService { argList.add(payloadObject.get(DesignServiceConstants.VNF_TYPE).textValue()); String insertQuery = " INSERT INTO DT_ACTION_STATUS (ACTION, VNF_TYPE, VNFC_TYPE, USER, TECHNOLOGY, UPDATED_DATE, STATUS) VALUES (?,?,?,?,?,sysdate() , ?); "; - if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null && !payloadObject - .get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.VNFC_TYPE) != null + && !payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); log.info("Vnfc-Type: " + payloadObject.get(DesignServiceConstants.VNFC_TYPE).textValue()); } else { argList.add(null); } argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject - .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null + && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); } else { argList.add(null); @@ -428,12 +608,13 @@ public class DesignDBService { log.info("QueryString: " + insertQuery); log.info("Arguments List: " + argList); boolean updateStatus = dbservice.updateDBData(insertQuery, argList); - if (!updateStatus) + if (!updateStatus) { throw new DBException("Error while updating Action Status"); + } } - private void createArtifactTrackingRecord(String payload, String requestID, int sdcArtifactId, int sdcReferenceId) - throws Exception { + private void createArtifactTrackingRecord(String payload, String requestId, int sdcArtifactId, int sdcReferenceId) + throws Exception { ObjectMapper objectMapper = new ObjectMapper(); JsonNode payloadObject = objectMapper.readTree(payload); @@ -442,51 +623,55 @@ public class DesignDBService { argList.add(String.valueOf(sdcArtifactId)); argList.add(String.valueOf(sdcReferenceId)); argList.add(payloadObject.get(DesignServiceConstants.USER_ID).textValue()); - if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null && !payloadObject - .get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.TECHNOLOGY) != null + && !payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.TECHNOLOGY).textValue()); } else { argList.add(""); } - if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null && !payloadObject - .get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) { + if (payloadObject.get(DesignServiceConstants.PROTOCOL) != null + && !payloadObject.get(DesignServiceConstants.PROTOCOL).textValue().isEmpty()) { argList.add(payloadObject.get(DesignServiceConstants.PROTOCOL).textValue()); } else { argList.add(""); } - String queryString = "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY, CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART) VALUES (? , ? , ?, ?, sysdate() , sysdate(), 'Created', ? ,'N' )"; + String queryString = + "INSERT INTO DT_ARTIFACT_TRACKING (ASDC_ARTIFACTS_ID, ASDC_REFERENCE_ID, USER, TECHNOLOGY," + + " CREATION_DATE, UPDATED_DATE, ARTIFACT_STATUS, PROTOCOL, IN_CART)" + + " VALUES (?, ?, ?, ?, sysdate(), sysdate(), 'Created', ?, 'N')"; log.info(QUERY_STR + queryString); boolean data = dbservice.updateDBData(queryString, argList); if (!data) { - throw new DBException("Error Updating DT_ARTIFACT_TRACKING "); + throw new DBException("Error Updating DT_ARTIFACT_TRACKING"); } } - private int getSDCArtifactIDbyRequestID(String requestID) throws Exception { + private int getSDCArtifactIDbyRequestID(String requestId) throws Exception { log.info("Starting getArtifactIDbyRequestID DB Operation"); int artifactId = 0; try { ArrayList<String> argList = new ArrayList<>(); - argList.add("TLSUUID" + requestID); - String queryString = " SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ? "; - log.info(QUERY_STR + queryString+ " & UUID or" + "TLSUUID :" + requestID); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - artifactId = data.getInt("ASDC_ARTIFACTS_ID"); + argList.add("TLSUUID" + requestId); + String queryString = "SELECT ASDC_ARTIFACTS_ID FROM ASDC_ARTIFACTS where SERVICE_UUID = ?"; + log.info(QUERY_STR + queryString + " & UUID: " + "TLSUUID" + requestId); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + artifactId = data.getInt("ASDC_ARTIFACTS_ID"); + } } } catch (Exception e) { log.error("An error occurred in getSDCArtifactIDbyRequestID", e); throw e; } - log.info("Got SDC_ARTIFACTS_ID As :" + artifactId); + log.info("Got SDC_ARTIFACTS_ID As: " + artifactId); return artifactId; } - private String getArtifact(String payload, String requestID) throws Exception { + private String getArtifact(String payload, String requestId) throws Exception { log.info("Starting getArtifact DB Operation"); try { ObjectMapper objectMapper = new ObjectMapper(); @@ -496,29 +681,40 @@ public class DesignDBService { argList.add(artifactName); argList.add(payloadObject.get("artifact-type").textValue()); - String queryString = "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS where " - + " ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ? "; + String queryString = + "SELECT INTERNAL_VERSION, ARTIFACT_CONTENT FROM ASDC_ARTIFACTS" + + " where ARTIFACT_NAME = ? AND ARTIFACT_TYPE = ?"; + log.info(QUERY_STR + queryString); - ResultSet data = dbservice.getDBData(queryString, argList); String artifactContent = null; - int rowCount = 0; - int hightestVerion = -1; - while (data.next()) { - rowCount++; - int version = data.getInt("INTERNAL_VERSION"); - if (hightestVerion < version) { - artifactContent = data.getString("ARTIFACT_CONTENT"); - hightestVerion = version; + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + int highestVersion = -1; + + while (data.next()) { + rowCount++; + + int version = data.getInt("INTERNAL_VERSION"); + if (highestVersion < version) { + artifactContent = data.getString("ARTIFACT_CONTENT"); + highestVersion = version; + } + } + + log.debug("No of rows: " + rowCount + " highest Internal Version " + highestVersion); + + if (rowCount == 0) { + throw new DBException( + "Sorry!!! APPC DB doesn't have any artifact Named: " + artifactName); + } + + if (artifactContent == null || artifactContent.isEmpty()) { + throw new DBException("Sorry!!! Artifact Content is stored blank in APPC DB for " + artifactName + + " and Internal version " + highestVersion); } } - log.debug("No of rows: " + rowCount + " highest Inetrnal Version" + hightestVerion); - if (rowCount == 0) { - throw new DBException("Sorry !!!APPC DB doesn't have any artifact Named : " + artifactName); - } - if (artifactContent == null || artifactContent.isEmpty()) { - throw new DBException("Sorry !!! Artifact Content is stored blank in APPC DB for " + artifactName - + " and Internal version " + hightestVerion); - } + DesignResponse designResponse = new DesignResponse(); List<ArtifactInfo> artifactInfoList = new ArrayList<>(); ArtifactInfo artifactInfo = new ArtifactInfo(); @@ -527,7 +723,7 @@ public class DesignDBService { designResponse.setArtifactInfo(artifactInfoList); ObjectMapper mapper = new ObjectMapper(); String jsonString = mapper.writeValueAsString(designResponse); - log.debug("End of getArtifact:" + INFO_STR + jsonString); + log.debug("End of getArtifact: " + INFO_STR + jsonString); return jsonString; } catch (Exception e) { log.error(DB_OPERATION_ERROR, e); @@ -535,7 +731,7 @@ public class DesignDBService { } } - private String setStatus(String payload, String requestID) throws Exception { + private String setStatus(String payload, String requestId) throws Exception { log.info("Starting getStatus DB Operation"); try { @@ -557,7 +753,7 @@ public class DesignDBService { if (payloadObject.get(VNFC_TYPE) != null && !payloadObject.get(VNFC_TYPE).textValue().isEmpty()) { argList.add(payloadObject.get(VNFC_TYPE).textValue()); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; + queryString += " and DAS.VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); @@ -579,7 +775,7 @@ public class DesignDBService { } } - private String getStatus(String payload, String requestID) throws Exception { + private String getStatus(String payload, String requestId) throws Exception { log.info("Starting getStatus DB Operation"); try { String vnfcType = null; @@ -595,15 +791,16 @@ public class DesignDBService { argList.add(userID); argList.add(vnfType); - String queryString = "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS " - + "from DT_ACTION_STATUS DAS , DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR " + - " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID " - + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ? " - + " and DAS.VNF_TYPE = ? "; + String queryString = + "SELECT DAS.VNF_TYPE, DAS.VNFC_TYPE, DAS.STATUS, DAS.ACTION, DAT.ARTIFACT_STATUS" + + " from DT_ACTION_STATUS DAS, DT_ARTIFACT_TRACKING DAT, DT_STATUS_RELATIONSHIP DSR" + + " where DAT.USER = DAS.USER and DSR.DT_ARTIFACT_TRACKING_ID = DAT.DT_ARTIFACT_TRACKING_ID" + + " and DSR.DT_ACTION_STATUS_ID = DAS.DT_ACTION_STATUS_ID and DAT.USER = ?" + + " and DAS.VNF_TYPE = ?"; if (vnfcType != null && !vnfcType.isEmpty()) { argList.add(vnfcType); - queryString = queryString + " and DAS.VNFC_TYPE = ? "; + queryString = queryString + " and DAS.VNFC_TYPE = ?"; } log.info(QUERY_STR + queryString); @@ -611,20 +808,21 @@ public class DesignDBService { DesignResponse designResponse = new DesignResponse(); designResponse.setUserId(userID); List<StatusInfo> statusInfoList = new ArrayList<>(); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - StatusInfo statusInfo = new StatusInfo(); - statusInfo.setAction(data.getString("ACTION")); - statusInfo.setAction_status(data.getString(STATUS)); - statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); - statusInfo.setVnf_type(data.getString("VNF_TYPE")); - statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); - statusInfoList.add(statusInfo); - } + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + StatusInfo statusInfo = new StatusInfo(); + statusInfo.setAction(data.getString("ACTION")); + statusInfo.setAction_status(data.getString(STATUS)); + statusInfo.setArtifact_status(data.getString("ARTIFACT_STATUS")); + statusInfo.setVnf_type(data.getString("VNF_TYPE")); + statusInfo.setVnfc_type(data.getString("VNFC_TYPE")); + statusInfoList.add(statusInfo); + } - if (statusInfoList.isEmpty()) { - throw new DBException( - "OOPS !!!! No VNF information available for VNF-TYPE : " + vnfType + " for User : " + userID); + if (statusInfoList.isEmpty()) { + throw new DBException( + "OOPS!!!! No VNF information available for VNF-TYPE: " + vnfType + " for User: " + userID); + } } designResponse.setStatusInfoList(statusInfoList); ObjectMapper mapper = new ObjectMapper(); @@ -636,22 +834,22 @@ public class DesignDBService { throw e; } catch (Exception e) { log.error(DB_OPERATION_ERROR + e.getMessage()); - log.error("Exception : ", e); + log.error("Exception:", e); throw e; } } - private String getGuiReference(String payload, String requestID) { + private String getGuiReference(String payload, String requestId) { // TODO Auto-generated method stub return null; } - private String getArtifactReference(String payload, String requestID) { + private String getArtifactReference(String payload, String requestId) { // TODO Auto-generated method stub return null; } - private String getDesigns(String payload, String requestID) throws Exception { + private String getDesigns(String payload, String requestId) throws Exception { String queryString; log.info("Starting getDesigns DB Operation"); @@ -666,41 +864,45 @@ public class DesignDBService { } ArrayList<String> argList = new ArrayList<>(); argList.add(userID); + argList.add(userID); + queryString = + "SELECT DISTINCT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME," + + " AR.ARTIFACT_TYPE, DUP.PERMISSION, DAS.USER FROM " + + DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT, " + + DesignServiceConstants.DB_SDC_REFERENCE + " AR, " + DesignServiceConstants.DB_DT_USER_PERMISSIONS + + " DUP, " + DesignServiceConstants.DB_DT_ACTION_STATUS + " DAS " + + " WHERE AR.VNF_TYPE = DUP.VNF_TYPE AND DAS.VNF_TYPE = DUP.VNF_TYPE" + + " AND DAT.ASDC_REFERENCE_ID = AR.ASDC_REFERENCE_ID AND DUP.USER_ID = ? AND AR.VNF_TYPE IN" + + " (SELECT DUP.VNF_TYPE FROM DT_USER_PERMISSIONS DUP" + + " WHERE DUP.PERMISSION IN('owner','contributor') AND DUP.USER_ID = ? GROUP BY VNF_TYPE)"; if (filterKey != null) { - queryString = - "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " - + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " - + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? and AR.ARTIFACT_NAME like '%" - + filterKey + "%' GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; - } else { - queryString = - "SELECT AR.VNF_TYPE, AR.VNFC_TYPE, DAT.PROTOCOL, DAT.IN_CART, AR.ACTION, AR.ARTIFACT_NAME, AR.ARTIFACT_TYPE from " - + - DesignServiceConstants.DB_DT_ARTIFACT_TRACKING + " DAT , " - + DesignServiceConstants.DB_SDC_REFERENCE + - " AR where DAT.ASDC_REFERENCE_ID= AR.ASDC_REFERENCE_ID and DAT.USER = ? GROUP BY AR.VNF_TYPE,AR.ARTIFACT_NAME"; + queryString += " AND AR.ARTIFACT_NAME like '%" + filterKey + "%'"; } + queryString += " GROUP BY AR.VNF_TYPE, AR.ARTIFACT_NAME"; + + log.info("QUERY FOR getDesigns: " + queryString); DesignResponse designResponse = new DesignResponse(); designResponse.setUserId(userID); List<DesignInfo> designInfoList = new ArrayList<>(); - ResultSet data = dbservice.getDBData(queryString, argList); - while (data.next()) { - DesignInfo designInfo = new DesignInfo(); - designInfo.setInCart(data.getString("IN_CART")); - designInfo.setProtocol(data.getString("PROTOCOL")); - designInfo.setVnf_type(data.getString("VNF_TYPE")); - designInfo.setVnfc_type(data.getString("VNFC_TYPE")); - designInfo.setAction(data.getString("ACTION")); - designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); - designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); - designInfoList.add(designInfo); - } - if (designInfoList.isEmpty()) { - throw new DBException( - " Welcome to CDT, Looks like you dont have Design Yet... Lets create some...."); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + while (data.next()) { + DesignInfo designInfo = new DesignInfo(); + designInfo.setInCart(data.getString("IN_CART")); + designInfo.setProtocol(data.getString("PROTOCOL")); + designInfo.setVnf_type(data.getString("VNF_TYPE")); + designInfo.setVnfc_type(data.getString("VNFC_TYPE")); + designInfo.setAction(data.getString("ACTION")); + designInfo.setArtifact_type(data.getString("ARTIFACT_TYPE")); + designInfo.setArtifact_name(data.getString("ARTIFACT_NAME")); + designInfo.setPermission(data.getString("PERMISSION")); + designInfo.setCreatorUserId(data.getString("USER")); + designInfoList.add(designInfo); + } + if (designInfoList.isEmpty()) { + throw new DBException( + "Welcome to CDT, Looks like you don't have Design Yet... Let's create some...."); + } } designResponse.setDesignInfoList(designInfoList); ObjectMapper mapper = new ObjectMapper(); @@ -708,15 +910,60 @@ public class DesignDBService { log.info(INFO_STR + jsonString); return jsonString; } catch (Exception e) { - log.error("Error while Starting getDesgins DB operation : ", e); + log.error("Error while Starting getDesigns DB operation:", e); throw e; } } - public static class ArtifactHandlerFactory { + private String retrieveVnfPermissions(String payload, String requestId) throws Exception { + log.info("Starting retrieveVnfPermissions DB Operation"); + + try { + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode payloadObject = objectMapper.readTree(payload); + ArrayList<String> argList = new ArrayList<>(); + String vnfType = payloadObject.get(VNF_TYPE).textValue(); + argList.add(vnfType); - public ArtifactHandlerClient ahi() throws Exception{ + String queryString = "SELECT USER_ID, PERMISSION FROM DT_USER_PERMISSIONS WHERE VNF_TYPE = ?"; + log.info(QUERY_STR + queryString); + List<UserPermissionInfo> userPermList = new ArrayList<>(); + try (ResultSet data = dbservice.getDBData(queryString, argList)) { + + int rowCount = 0; + + while (data.next()) { + rowCount++; + UserPermissionInfo userPermInfo = new UserPermissionInfo(); + userPermInfo.setUserID(data.getString(COLUMN_USER_ID)); + userPermInfo.setPermission(data.getString(COLUMN_PERMISSION)); + userPermList.add(userPermInfo); + } + log.info("Number of rows=" + rowCount + ", for vnf-type=" + vnfType); + + if (userPermList.isEmpty()) { + throw new DBException("No user permissions information available for VNF-TYPE: " + vnfType); + } + } + DesignResponse designResponse = new DesignResponse(); + designResponse.setUsers(userPermList); + designResponse.setVnfType(vnfType); + ObjectMapper mapper = new ObjectMapper(); + String jsonString = mapper.writeValueAsString(designResponse); + log.info("End of retrieveVnfPermissions: " + INFO_STR + jsonString); + return jsonString; + + } catch (Exception e) { + log.error("Error while Starting retrieveVnfPermissions DB operation:", e); + throw e; + } + } + + public static class ArtifactHandlerFactory { + public ArtifactHandlerClient ahi() throws Exception { return new ArtifactHandlerClient(); } } + } + diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java index f98aae46f..778313644 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/dbervices/RequestValidator.java @@ -9,15 +9,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========================================================= */ @@ -87,6 +86,9 @@ public class RequestValidator { case DesignServiceConstants.UPLOADADMINARTIFACT: errorString = resolveUploadArtifactErrorString(payloadObject); break; + case DesignServiceConstants.RETRIEVEVNFPERMISSIONS: + errorString = resolveRetrieveVnfPermissionsErrorString(payloadObject); + break; case SETPROTOCOLREFERENCE: case SETINCART: errorString = resolveErrorString(payloadObject); @@ -94,14 +96,23 @@ public class RequestValidator { case DesignServiceConstants.CHECKVNF: errorString = resolveCheckVNFErrorString(payloadObject); break; + case DesignServiceConstants.SAVEVNFPERMISSIONS: + errorString = resolveSaveUserPermissionErrorString(payloadObject); + break; default: throw new RequestValidationException(" Action " + action + " not found while processing request "); } checkForErrorString(errorString); } + private static String resolveSaveUserPermissionErrorString(JsonNode payloadObject) { + if (nullOrEmpty(payloadObject, VNF_TYPE)) + return VNF_TYPE; + return null; + } + private static String resolveCheckVNFErrorString(JsonNode payloadObject) { - if (nullOrEmpty(payloadObject, VNF_TYPE)) + if (nullOrEmpty(payloadObject, VNF_TYPE)) return VNF_TYPE; return null; } @@ -192,6 +203,10 @@ public class RequestValidator { return payload == null || payload.textValue().trim().isEmpty(); } + private static String resolveRetrieveVnfPermissionsErrorString(JsonNode payloadObject) { + if (nullOrEmpty(payloadObject, VNF_TYPE)) { + return VNF_TYPE; + } + return null; + } } - - diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java index 12f0a368d..e9515dc32 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.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========================================================= */ @@ -30,15 +29,6 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; - -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Feature; -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; - import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -49,13 +39,19 @@ import java.util.Properties; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.ws.rs.HttpMethod; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Feature; import javax.ws.rs.core.MediaType; - +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; public class ArtifactHandlerClient { private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerClient.class); - static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; + public static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR"; private Properties props = new Properties(); public ArtifactHandlerClient() throws IOException { @@ -122,7 +118,6 @@ public class ArtifactHandlerClient { sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, new javax.net.ssl.TrustManager[]{secureRestClientTrustManager}, null); - client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(getHostnameVerifier()).build(); String password = et.decrypt(props.getProperty("appc.upload.pass")); @@ -133,9 +128,9 @@ public class ArtifactHandlerClient { if (HttpMethod.GET.equalsIgnoreCase(rpc)) { clientResponse = webResource.request(responseDataType).get(Response.class); } else if (HttpMethod.POST.equalsIgnoreCase(rpc)) { - clientResponse = webResource.request(requestDataType).post(Entity.json(payload),Response.class); + clientResponse = webResource.request(requestDataType).post(Entity.json(payload), Response.class); } else if (HttpMethod.PUT.equalsIgnoreCase(rpc)) { - clientResponse = webResource.request(requestDataType).put(Entity.json(payload),Response.class); + clientResponse = webResource.request(requestDataType).put(Entity.json(payload), Response.class); } else if (HttpMethod.DELETE.equalsIgnoreCase(rpc)) { clientResponse = webResource.request().delete(Response.class); } @@ -144,7 +139,7 @@ public class ArtifactHandlerClient { } catch (Exception e) { log.debug("failed in RESTCONT Action", e); - throw new IOException("Error While Sending Rest Request" + e.getMessage(), e); + throw new IOException("Error While Sending Rest Request: " + e.getMessage(), e); } finally { // clean up. if (client != null) { diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java index 42f3d3f3e..e5ceb358d 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/DesignServiceConstants.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========================================================= */ @@ -39,18 +38,18 @@ public class DesignServiceConstants { public static final String GETDESIGNS = "getDesigns"; public static final String GETAPPCTIMESTAMPUTC = "getAppcTimestampUTC"; - public static final String UPLOADARTIFACTS = "uploadArtifacts"; - public static final String VALIDATETEMPLATE = "validateTemplate"; - public static final String GETSTATUS = "getStatus"; - public static final String SETSTATUS = "setStatus"; + public static final String UPLOADARTIFACTS = "uploadArtifacts"; + public static final String VALIDATETEMPLATE = "validateTemplate"; + public static final String GETSTATUS = "getStatus"; + public static final String SETSTATUS = "setStatus"; public static final String GETGUIREFERENCE = "getGUIReference"; - public static final String GETARTIFACTREFERENCE = "getArtifactReference"; - public static final String GETAAIDATA = "getAAIData"; - public static final String GETINSTARDATA = "getInstarData"; - public static final String PUBLISHARTIFACTS = "publishdArtifacts"; - public static final String ADDINCART = "addInCart"; - - public static final String SUCCESS = "success"; + public static final String GETARTIFACTREFERENCE = "getArtifactReference"; + public static final String GETAAIDATA = "getAAIData"; + public static final String GETINSTARDATA = "getInstarData"; + public static final String PUBLISHARTIFACTS = "publishdArtifacts"; + public static final String ADDINCART = "addInCart"; + + public static final String SUCCESS = "success"; public static final String DESINGTIME = "DesignTime"; public static final String RUNTIME = "RunTime"; public static final String APPC_FLOW_CONTROLLER = "/appc-flow-controller.properties"; @@ -62,21 +61,22 @@ public class DesignServiceConstants { public static final String VNFC = "vnfc"; 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 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_VERSOIN ="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_VERSOIN = "artifact-version"; + public static final String RESOURCE_VERSOIN = "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 DB_DT_ACTION_STATUS = "DT_ACTION_STATUS"; + public static final String DB_DT_USER_PERMISSIONS = "DT_USER_PERMISSIONS"; + public static final String ARTIFACT_VERSOIN = "artifact-version"; public static final String ARTIFACT_DESRIPTION = "artifact-description"; public static final String ARTIFACT_CONTENTS = "artifact-contents"; public static final String REQUEST_INFORMATION = "request-information"; @@ -109,10 +109,16 @@ public class DesignServiceConstants { public static final String INSTAR_V4_MASK = "v4Subnet"; public static final String INSTAR_V6_MASK = "v6Subnet"; public static final String CHECKVNF = "checkVNF"; + public static final String RETRIEVEVNFPERMISSIONS = "retrieveVnfPermissions"; + public static final String SAVEVNFPERMISSIONS = "saveVnfPermissions"; + public static final String CREATORUSERID = "creator-userID"; + public static final String PERMISSION = "permission"; + private DesignServiceConstants() { } public static String getEnvironmentVariable(String env) { return System.getenv(env); } -}
\ No newline at end of file + +} diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java index 7f64863b9..21347ced2 100644 --- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.java +++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XResponseProcessor.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 * ================================================================================ @@ -13,15 +13,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========================================================= */ @@ -38,7 +37,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class XResponseProcessor { private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class); - private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occured while receiving data"; + private static final String EXCEPTION_WHILE_RECEIVING_DATA = "Exception occurred while receiving data"; Dme2Client dme2Client; public static XResponseProcessor getInstance() { @@ -61,37 +60,39 @@ public class XResponseProcessor { // check the payload whether its having ipaddr along with subnet ipAddress = payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS) != null ? payloadObject.get(DesignServiceConstants.INSTAR_V4_ADDRESS).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null) - ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue() - .toUpperCase() - : null; - - mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null - ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() - : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) - ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() - : null; - - // TODO -short format - - /* - * if (mask != null) { queryParam = ipAddress + "," +mask ; - * log.info("Calling Instar with IpAddress "+ ipAddress + " Mask value: "+ mask ); } else { - * queryParam = "ipAddress "+ipAddress ; log.info("Calling Instar with IpAddress "+ - * ipAddress); } - */ - - payload = new HashMap<String, String>(); - payload.put("ipAddress", ipAddress); - payload.put("mask", mask); - log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); - dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); - - instarResponse = dme2Client.send(); - - log.debug("Resposne from Instar = " + instarResponse); - if (instarResponse == null || instarResponse.length() < 0) - throw new Exception("No Data received from Instar for this action " + action); + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_ADDRESS).textValue().toUpperCase() + : null; + + mask = payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK) != null + ? payloadObject.get(DesignServiceConstants.INSTAR_V4_MASK).textValue() + + : (payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK) != null) + ? payloadObject.get(DesignServiceConstants.INSTAR_V6_MASK).textValue().toUpperCase() + : null; + + // TODO -short format + + /* if (mask != null) { + * queryParam = ipAddress + "," + mask; + * log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); + * } else { + * queryParam = "ipAddress " + ipAddress; + * log.info("Calling Instar with IpAddress " + ipAddress); + * } + */ + + payload = new HashMap<String, String>(); + payload.put("ipAddress", ipAddress); + payload.put("mask", mask); + log.info("Calling Instar with IpAddress " + ipAddress + " Mask value: " + mask); + dme2Client = new Dme2Client("getVnfbyIpadress", "payload", payload); + + instarResponse = dme2Client.send(); + + log.debug("Response from Instar = " + instarResponse); + if (instarResponse == null || instarResponse.length() < 0) + throw new Exception("No Data received from Instar for this action " + action); } catch (Exception e) { log.error(EXCEPTION_WHILE_RECEIVING_DATA, e); throw e; diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java index 43105a79a..fe59637a6 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDbResponse.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========================================================= */ @@ -31,19 +30,20 @@ import org.onap.appc.design.dbervices.DbResponseProcessor; public class TestDbResponse { @Test - public void testDbResponse() throws Exception{ + public void testDbResponse() throws Exception { DbResponseProcessor dbResponse = new DbResponseProcessor(); - dbResponse.parseResponse("Test", "getDesigns"); - dbResponse.parseResponse("Test", "addInCart"); - dbResponse.parseResponse("Test", "getArtifactReference"); - dbResponse.parseResponse("Test", "getArtifact"); - dbResponse.parseResponse("Test", "getGUIReference"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "uploadArtifact"); - dbResponse.parseResponse("Test", "setProtocolReference"); - dbResponse.parseResponse("Test", "setInCart"); - dbResponse.parseResponse("Test", "getStatus"); - dbResponse.parseResponse("Test", "getAppcTimestampUTC"); - + dbResponse.parseResponse("Test", "getDesigns"); + dbResponse.parseResponse("Test", "addInCart"); + dbResponse.parseResponse("Test", "getArtifactReference"); + dbResponse.parseResponse("Test", "getArtifact"); + dbResponse.parseResponse("Test", "getGUIReference"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "uploadArtifact"); + dbResponse.parseResponse("Test", "setProtocolReference"); + dbResponse.parseResponse("Test", "setInCart"); + dbResponse.parseResponse("Test", "getStatus"); + dbResponse.parseResponse("Test", "getAppcTimestampUTC"); + dbResponse.parseResponse("Test", "retrieveVnfPermissions"); + dbResponse.parseResponse("Test", "saveVnfPermissions"); } } diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java index 50f7ac65d..cbfca0aec 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/validator/TestDesigndata.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========================================================= */ @@ -25,12 +24,14 @@ package org.onap.appc.design.validator; import java.util.ArrayList; import java.util.List; +import org.junit.Assert; import org.junit.Test; import org.onap.appc.design.data.ArtifactInfo; import org.onap.appc.design.data.DesignInfo; import org.onap.appc.design.data.DesignRequest; import org.onap.appc.design.data.DesignResponse; import org.onap.appc.design.data.StatusInfo; +import org.onap.appc.design.data.UserPermissionInfo; public class TestDesigndata { @@ -38,64 +39,121 @@ public class TestDesigndata { @Test public void testSetUserID() { - dr.setUserId("00000"); - dr.getUserId(); + String userId = "0000"; + dr.setUserId(userId); + Assert.assertEquals("Unexpected getUserId value", userId, dr.getUserId()); } @Test public void testSetDesignInfoList() { DesignInfo di = new DesignInfo(); List<DesignInfo> li = new ArrayList<DesignInfo>(); - di.setAction("TestAction"); - di.setArtifact_name("TestName"); - di.setArtifact_type("TestType"); - di.setInCart("TestCart"); - di.setProtocol("TestProtocol"); - di.setVnf_type("TestVNF"); - di.setVnfc_type("TestVNFC"); + String action = "TestAction"; + di.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, di.getAction()); + String artifact_name = "TestName"; + di.setArtifact_name(artifact_name); + Assert.assertEquals("Unexpected getArtifact_name value", artifact_name, di.getArtifact_name()); + String artifact_type = "TestType"; + di.setArtifact_type(artifact_type); + Assert.assertEquals("Unexpected getArtifact_type value", artifact_type, di.getArtifact_type()); + String inCart = "TestCart"; + di.setInCart(inCart); + Assert.assertEquals("Unexpected getInCart value", inCart, di.getInCart()); + String protocol = "TestProtocol"; + di.setProtocol(protocol); + Assert.assertEquals("Unexpected getProtocol value", protocol, di.getProtocol()); + String vnf_type = "TestVNF"; + di.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, di.getVnf_type()); + String vnfc_type = "TestVNFC"; + di.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, di.getVnfc_type()); li.add(di); dr.setDesignInfoList(li); + Assert.assertEquals("Unexpected getDesignInfoList value", li, dr.getDesignInfoList()); } @Test public void testSetArtifactInfo() { ArtifactInfo ai = new ArtifactInfo(); List<ArtifactInfo> li = new ArrayList<ArtifactInfo>(); - ai.setArtifact_content("TestContent"); + String artifact_content = "TestContent"; + ai.setArtifact_content(artifact_content); + Assert.assertEquals("Unexpected getArtifact_content value", artifact_content, ai.getArtifact_content()); li.add(ai); dr.setArtifactInfo(li); + Assert.assertEquals("Unexpected getArtifactInfo value", li, dr.getArtifactInfo()); } @Test public void testStatusInfo() { StatusInfo si = new StatusInfo(); List<StatusInfo> li = new ArrayList<StatusInfo>(); - si.setAction("TestAction"); - si.setAction_status("TestActionStatus"); - si.setArtifact_status("TestArtifactStatus"); - si.setVnf_type("TestVNF"); - si.setVnfc_type("TestVNFC"); + String action = "TestAction"; + si.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, si.getAction()); + String action_status = "TestActionStatus"; + si.setAction_status(action_status); + Assert.assertEquals("Unexpected getAction_status value", action_status, si.getAction_status()); + String artifact_status = "TestArtifactStatus"; + si.setArtifact_status(artifact_status); + Assert.assertEquals("Unexpected getArtifact_status value", artifact_status, si.getArtifact_status()); + String vnf_type = "TestVNF"; + si.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, si.getVnf_type()); + String vnfc_type = "TestVNFC"; + si.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, si.getVnfc_type()); li.add(si); dr.setStatusInfoList(li); + Assert.assertEquals("Unexpected getStatusInfoList value", li, dr.getStatusInfoList()); } @Test public void testDesignRequest() { DesignRequest dreq = new DesignRequest(); - dreq.setAction("TestAction"); - dreq.setArtifact_contents("TestContent"); - dreq.setArtifact_name("TestName"); - dreq.setProtocol("TestProtocol"); - dreq.setUserId("0000"); - dreq.setVnf_type("testvnf"); - dreq.setVnfc_type("testvnfc"); - dreq.getAction(); - dreq.getArtifact_contents(); - dreq.getArtifact_name(); - dreq.getProtocol(); - dreq.getUserId(); - dreq.getVnf_type(); - dreq.getVnfc_type(); - dreq.toString(); + String action = "TestAction"; + dreq.setAction(action); + Assert.assertEquals("Unexpected getAction value", action, dreq.getAction()); + String artifact_contents = "TestContent"; + dreq.setArtifact_contents(artifact_contents); + Assert.assertEquals("Unexpected getArtifact_contents value", artifact_contents, dreq.getArtifact_contents()); + String artifact_name = "TestName"; + dreq.setArtifact_name(artifact_name); + Assert.assertEquals("Unexpected getArtifact_name value", artifact_name, dreq.getArtifact_name()); + String protocol = "TestProtocol"; + dreq.setProtocol(protocol); + Assert.assertEquals("Unexpected getProtocol value", protocol, dreq.getProtocol()); + String userId = "0000"; + dreq.setUserId(userId); + Assert.assertEquals("Unexpected getUserId value", userId, dreq.getUserId()); + String vnf_type = "testvnf"; + dreq.setVnf_type(vnf_type); + Assert.assertEquals("Unexpected getVnf_type value", vnf_type, dreq.getVnf_type()); + String vnfc_type = "testvnfc"; + dreq.setVnfc_type(vnfc_type); + Assert.assertEquals("Unexpected getVnfc_type value", vnfc_type, dreq.getVnfc_type()); + String expecting = + "DesignRequest [userId=" + userId + ", vnf_type=" + vnf_type + ", vnfc_type=" + vnfc_type + ", protocol=" + + protocol + ", action=" + action + ", artifact_name=" + artifact_name + ", artifact_contents=" + + artifact_contents + "]"; + Assert.assertEquals("Unexpected toString value", expecting, dreq.toString()); } + + @Test + public void testUserPermissionInfo() { + UserPermissionInfo upi = new UserPermissionInfo(); + List<UserPermissionInfo> li = new ArrayList<UserPermissionInfo>(); + String userId = "uu1234"; + upi.setUserID(userId); + Assert.assertEquals("Unexpected getUserId value", userId, upi.getUserID()); + String permission = "owner"; + upi.setPermission(permission); + Assert.assertEquals("Unexpected getPermission value", permission, upi.getPermission()); + li.add(upi); + dr.setUsers(li); + Assert.assertEquals("Unexpected getUsers value", li, dr.getUsers()); + } + } |