summaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-artifact-handler
diff options
context:
space:
mode:
authorSonali Das <sd394g@att.com>2019-02-13 16:28:02 -0500
committerTakamune Cho <takamune.cho@att.com>2019-02-15 18:16:32 +0000
commitfa84c610d97ea983203fa0e79635b7167578d745 (patch)
tree3a18988b69a418e27018e3b4d16f4e41a883f528 /appc-inbound/appc-artifact-handler
parentffdeff1694e362befeebef4d462a45c1805a639d (diff)
Support multiple Ansible servers
Issue-ID: APPC-1364 Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa Signed-off-by: Sonali Das <sd394g@att.com> Review Comment update Issue-ID: APPC-1364 Change-Id: I03fa97d60c6497218c14b53531c2dea69c7fba34 Signed-off-by: Sonali Das <sd394g@att.com> Review Comment update Issue-ID: APPC-1364 Change-Id: I03fa97d60c6497218c14b53531c2dea69c7fba34 Signed-off-by: Sonali Das <sd394g@att.com> Support multiple Ansible servers Issue-ID: APPC-1364 Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa Signed-off-by: Sonali Das <sd394g@att.com> Support multiple Ansible servers Issue-ID: APPC-1364 Change-Id: I63cf89f5964bcfaba7d1f0b0eac2477f827b69fa Signed-off-by: Sonali Das <sd394g@att.com>
Diffstat (limited to 'appc-inbound/appc-artifact-handler')
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNode.java278
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/main/java/org/onap/appc/artifact/handler/utils/SdcArtifactHandlerConstants.java4
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/node/ArtifactHandlerNodeTest.java145
3 files changed, 320 insertions, 107 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 0b8aa5f81..b2cc984fb 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
@@ -81,6 +81,7 @@ import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.V
import static org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants.VNF_TYPE;
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;
@@ -104,6 +105,11 @@ 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;
+
public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
private static final EELFLogger log = EELFManager.getInstance().getLogger(ArtifactHandlerNode.class);
@@ -120,7 +126,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
return;
}
String postData = inParams.get("postData");
- if (postData == null || postData.isEmpty()) {
+ if ( StringUtils.isBlank(postData)) {
return;
}
try {
@@ -129,7 +135,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
storeUpdateSdcArtifacts(input);
} catch (Exception e) {
log.error("Error when processing artifact", e);
- throw new ArtifactProcessorException("Error occurred while processing artifact", e);
+ throw new ArtifactProcessorException("Error occurred while processing artifact, " + e.getMessage(), e);
}
}
@@ -139,35 +145,113 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
JSONObject requestInfo = (JSONObject) postDataJson.get(REQUEST_INFORMATION);
JSONObject documentInfo = (JSONObject) postDataJson.get(DOCUMENT_PARAMETERS);
String artifactName = documentInfo.getString(ARTIFACT_NAME);
- if (artifactName != null) {
- updateStoreArtifacts(requestInfo, documentInfo);
- if (artifactName.toLowerCase().startsWith(REFERENCE)) {
- return storeReferenceData(requestInfo, documentInfo);
- } else if (artifactName.toLowerCase().startsWith(PD)) {
- return createDataForPD(requestInfo, documentInfo);
- }
- } else {
- throw new ArtifactHandlerInternalException("Missing Artifact Name for Request: "
- + requestInfo.getString(REQUEST_ID));
+ if (StringUtils.isBlank(artifactName))
+ throw new ArtifactHandlerInternalException("Missing Artifact Name ");
+
+ if (artifactName.toLowerCase().startsWith(ANSIBLE)) {
+ validateAnsibleAdminArtifact(documentInfo);
+ log.info("validateAnsibleAdminArtifact sucessfully done");
}
+
+ updateStoreArtifacts(requestInfo, documentInfo);
+ if (artifactName.toLowerCase().startsWith(REFERENCE)) {
+ return storeReferenceData(requestInfo, documentInfo);
+ } else if (artifactName.toLowerCase().startsWith(PD)) {
+ return createDataForPD(requestInfo, documentInfo);
+ }
+
} catch (Exception e) {
log.error("Error while processing request with id: "
- + ((JSONObject) postDataJson.get(REQUEST_INFORMATION)).getString(REQUEST_ID), e);
-
+ + ((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), e);
+ + ((JSONObject) postDataJson.get(REQUEST_INFORMATION)).getString(REQUEST_ID)
+ + ", Exception Message : " + e.getMessage(), e);
}
return false;
}
+ public void validateAnsibleAdminArtifact(JSONObject documentInfo) throws ArtifactHandlerInternalException {
+ String fn = "ArtifactHandlerNode.validateAnsibleAdminArtifact";
+ String artifactName = documentInfo.getString(ARTIFACT_NAME);
+ log.info(fn + ": Received Admin File Name: " + artifactName + " ArtifactCotent : "
+ + 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);
+ artifactMap.put(fqdn.getString("vnf-management-server-fqdn"), valuesforFQDN);
+ }
+
+ validateKeyValue(artifactMap);
+
+ } catch (JSONException je) {
+ 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);
+ } catch (ArtifactHandlerInternalException 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);
+ }
+
+ }
+ 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());
+ }
+
+
+ }
+ }
+ }
+}
+
+ private List<String> populateValueForFQDN(JSONObject 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 valueforFQDN = cloudOwner + "-" + region + "-" + tenant;
+ log.info("valueforFQDN for i " + i + " & j " + j + " :" + valueforFQDN);
+ valuesforFQDN.add(valueforFQDN);
+ }
+ }
+ }
+ return valuesforFQDN;
+ }
+
private boolean createDataForPD(JSONObject requestInfo, JSONObject documentInfo)
- throws ArtifactHandlerInternalException {
+ throws ArtifactHandlerInternalException {
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());
@@ -180,11 +264,11 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void createArtifactRecords(JSONObject requestInfo, JSONObject documentInfo, String suffix)
- throws ArtifactHandlerInternalException {
+ throws ArtifactHandlerInternalException {
try {
log.info("Creating Tosca Records and storing into SDC Artifacs");
- String[] docs = {TOSCA_PARAM, YANG_PARAM};
+ String[] docs = { TOSCA_PARAM, YANG_PARAM };
ArtifactHandlerProviderUtil ahpUtil = new ArtifactHandlerProviderUtil();
String pdFileContents = documentInfo.getString(ARTIFACT_CONTENTS);
@@ -240,17 +324,15 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
return dbservice.getArtifactID(context, yangName);
}
- protected boolean updateStoreArtifacts(JSONObject requestInfo, JSONObject documentInfo)
- throws SvcLogicException {
+ protected boolean updateStoreArtifacts(JSONObject requestInfo, JSONObject documentInfo) throws SvcLogicException {
log.info("UpdateStoreArtifactsStarted storing of SDC Artifacs ");
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);
+ 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);
if (internalVersion != null) {
intversion = Integer.parseInt(internalVersion);
@@ -276,18 +358,15 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
public boolean storeReferenceData(JSONObject requestInfo, JSONObject documentInfo)
- throws ArtifactHandlerInternalException {
+ throws ArtifactHandlerInternalException {
log.info("Started storing of SDC Artifacs 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,
+ 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);
JSONObject capabilities = new JSONObject();
JSONArray vnfActionList = new JSONArray();
@@ -311,7 +390,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
setAttribute(context, content::getString, ACTION_LEVEL);
setAttribute(context, documentInfo::getString, ARTIFACT_TYPE);
processActionLists(content, actionLevel, vnfcActionList, vfModuleActionList, vnfActionList,
- vmActionVnfcFunctionCodesList);
+ vmActionVnfcFunctionCodesList);
JSONArray vnfcTypeList = setVnfcTypeInformation(scope, context);
storeCapabilityArtifact = isCapabilityArtifactNeeded(context);
if (content.has(DEVICE_PROTOCOL)) {
@@ -329,17 +408,16 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
processArtifactList(content, dbservice, context, vnfcTypeList);
processConfigTypeActions(content, dbservice, context);
dbservice.processDeviceAuthentication(context,
- dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION));
+ dbservice.isArtifactUpdateRequired(context, DB_DEVICE_AUTHENTICATION));
String actionProtocol = tryGetProtocol(content);
if (!StringUtils.equalsIgnoreCase(actionProtocol, OPENSTACK)) {
- populateProtocolReference(dbservice, content);
+ populateProtocolReference(dbservice, content);
}
context.setAttribute(VNFC_TYPE, null);
- if (content.has(VM)
- && content.get(VM) instanceof JSONArray) {
+ if (content.has(VM) && content.get(VM) instanceof JSONArray) {
processVmList(content, context, dbservice);
}
}
@@ -348,9 +426,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
capabilities.put("vf-module", vfModuleActionList);
capabilities.put("vnfc", vnfcActionList);
capabilities.put("vm", vmActionVnfcFunctionCodesList);
- processAndStoreCapabilitiesArtifact(dbservice, documentInfo, capabilities,
- capabilityArtifactName,
- vnfType);
+ processAndStoreCapabilitiesArtifact(dbservice, documentInfo, capabilities, capabilityArtifactName,
+ vnfType);
}
} catch (Exception e) {
@@ -365,22 +442,20 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
public boolean isCapabilityArtifactNeeded(SvcLogicContext context) {
String vnfcType = context.getAttribute(VNFC_TYPE);
if (StringUtils.isNotBlank(vnfcType)) {
- log.info("No capability Artifact for this reference data as it is at VNFC level!!" );
+ log.info("No capability Artifact for this reference data as it is at VNFC level!!");
return false;
- }
- else {
+ } else {
return true;
}
}
public JSONArray setVnfcTypeInformation(JSONObject scope, SvcLogicContext context) {
JSONArray vnfcTypeList = null;
- if (scope.has(VNFC_TYPE)
- && !scope.isNull(VNFC_TYPE)) {
+ if (scope.has(VNFC_TYPE) && !scope.isNull(VNFC_TYPE)) {
String vnfcTypeScope = scope.getString(VNFC_TYPE);
if (StringUtils.isNotBlank(vnfcTypeScope)) {
setAttribute(context, scope::getString, VNFC_TYPE);
- 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);
}
@@ -388,16 +463,15 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
context.setAttribute(VNFC_TYPE, null);
}
if (scope.has(VNFC_TYPE_LIST) && !scope.isNull(VNFC_TYPE_LIST)
- && scope.get(VNFC_TYPE_LIST) instanceof JSONArray) {
+ && scope.get(VNFC_TYPE_LIST) instanceof JSONArray) {
vnfcTypeList = scope.getJSONArray(VNFC_TYPE_LIST);
- log.info("VNFC TYPE LIST found for this artifact!! "+ vnfcTypeList.toString());
+ log.info("VNFC TYPE LIST found for this artifact!! " + vnfcTypeList.toString());
}
return vnfcTypeList;
}
public void processActionLists(JSONObject content, String actionLevel, JSONArray vnfcActionList,
- JSONArray vfModuleActionList,
- JSONArray vnfActionList, JSONArray vmActionVnfcFunctionCodesList) {
+ JSONArray vfModuleActionList, JSONArray vnfActionList, JSONArray vmActionVnfcFunctionCodesList) {
if (validateActionLevel(actionLevel, ACTION_LEVEL_VNFC)) {
vnfcActionList.put(content.getString(ACTION));
}
@@ -408,9 +482,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) && content.get(
- VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) {
+ if (content.has(VNFC_FUNCTION_CODE_LIST) && !content.isNull(VNFC_FUNCTION_CODE_LIST)
+ && content.get(VNFC_FUNCTION_CODE_LIST) instanceof JSONArray) {
log.info("Found vnfc-function-code-list!!");
JSONArray vnfcList = content.getJSONArray(VNFC_FUNCTION_CODE_LIST);
JSONObject obj = new JSONObject();
@@ -427,9 +500,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
return null != actionLevel && actionLevel.equalsIgnoreCase(actionLevelVnfc);
}
- public void processArtifactList(JSONObject content, DBService dbservice, SvcLogicContext context, JSONArray vnfcTypeList)
- throws ArtifactHandlerInternalException {
-
+ public void processArtifactList(JSONObject content, DBService dbservice, SvcLogicContext context,
+ JSONArray vnfcTypeList) throws ArtifactHandlerInternalException {
try {
if (content.has(ARTIFACT_LIST_PARAM) && content.get(ARTIFACT_LIST_PARAM) instanceof JSONArray) {
@@ -437,7 +509,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
JSONArray templateIdList = null;
if (content.has("template-id-list") && null != content.get("template-id-list")
&& content.get("template-id-list") instanceof JSONArray) {
- templateIdList = content.getJSONArray("template-id-list");
+ templateIdList = content.getJSONArray("template-id-list");
}
doProcessArtifactList(dbservice, context, artifactLists, templateIdList, vnfcTypeList);
@@ -449,30 +521,30 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void doProcessArtifactList(DBService dbservice, SvcLogicContext context, JSONArray artifactLists,
- JSONArray templateIdList, JSONArray vnfcTypeList)
- throws SvcLogicException, SQLException, ConfigurationException, DBException {
+ JSONArray templateIdList, JSONArray vnfcTypeList)
+ throws SvcLogicException, SQLException, ConfigurationException, DBException {
boolean pdFile = false;
- int modelInd = 0, vnfcRefInd = 0;
+ int modelInd = 0, vnfcRefInd = 0;
for (int i = 0; i < artifactLists.length(); i++) {
String suffix = null;
String model = null;
JSONObject artifact = (JSONObject) artifactLists.get(i);
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
+ // 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 != vnfcTypeList && i>0 && i%3 == 0) {
- //TDP 517180 - CD tool has made changes to send 3 artifacts instead of 2
+ if (null != vnfcTypeList && i > 0 && i % 3 == 0) {
+ // TDP 517180 - CD tool has made changes to send 3 artifacts instead of 2
vnfcRefInd++;
}
setAttribute(context, artifact::getString, ARTIFACT_NAME);
- context.setAttribute(FILE_CATEGORY,
- artifact.getString(ARTIFACT_TYPE));
+ context.setAttribute(FILE_CATEGORY, artifact.getString(ARTIFACT_TYPE));
if (artifact.getString(ARTIFACT_NAME) != null
- && artifact.getString(ARTIFACT_NAME).toLowerCase().startsWith(PD)) {
+ && artifact.getString(ARTIFACT_NAME).toLowerCase().startsWith(PD)) {
suffix = artifact.getString(ARTIFACT_NAME).substring(PD.length());
pdFile = true;
@@ -480,11 +552,11 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
log.info("Artifact-type = " + context.getAttribute(FILE_CATEGORY));
log.info("Artifact-name = " + context.getAttribute(ARTIFACT_NAME));
- if (null != templateIdList && modelInd < templateIdList.length()) {
+ 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() ) {
+ if (null != vnfcTypeList && vnfcRefInd < vnfcTypeList.length()) {
String vnfcType = vnfcTypeList.getString(vnfcRefInd);
if (StringUtils.isNotBlank(vnfcType)) {
context.setAttribute(VNFC_TYPE, vnfcType);
@@ -492,60 +564,55 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
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);
- }
- else {
- dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context,
- DB_SDC_REFERENCE));
+ dbservice.processSdcReferences(context,
+ dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
+ } else {
+ dbservice.processSdcReferences(context, dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE));
}
cleanArtifactInstanceData(context);
- //Moving this into the for loop to account for mulitple artifact sets with pds
+ // Moving this into the for loop to account for mulitple artifact sets with pds
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 afterprocessing yang and Tosca
}
}
}
- private void tryUpdateContext(DBService dbservice, SvcLogicContext context, boolean pdFile,
- String suffix, String model)
- throws SvcLogicException, SQLException, ConfigurationException, DBException {
+ private void tryUpdateContext(DBService dbservice, SvcLogicContext context, boolean pdFile, String suffix,
+ String model) throws SvcLogicException, SQLException, ConfigurationException, DBException {
if (pdFile) {
context.setAttribute(ARTIFACT_NAME, "Tosca".concat(suffix));
context.setAttribute(FILE_CATEGORY, TOSCA_MODEL);
dbservice.processSdcReferences(context,
- dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
+ dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
context.setAttribute(ARTIFACT_NAME, "Yang".concat(suffix));
context.setAttribute(FILE_CATEGORY, PARAMETER_YANG);
dbservice.processSdcReferences(context,
- dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
+ dbservice.isArtifactUpdateRequired(context, DB_SDC_REFERENCE, model), model);
}
}
public void processConfigTypeActions(JSONObject content, DBService dbservice, SvcLogicContext context)
- throws ArtifactHandlerInternalException {
+ throws ArtifactHandlerInternalException {
try {
- if (contentsActionEquals(content, CONFIGURE_PARAM)
- || contentsActionEquals(content, CONFIG_MODIFY_PARAM)
- || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM)) {
+ if (contentsActionEquals(content, CONFIGURE_PARAM) || contentsActionEquals(content, CONFIG_MODIFY_PARAM)
+ || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM)) {
if (content.has(DOWNLOAD_DG_REFERENCE) && content.getString(DOWNLOAD_DG_REFERENCE).length() > 0) {
setAttribute(context, content::getString, DOWNLOAD_DG_REFERENCE);
dbservice.processDownloadDgReference(context,
- dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
+ dbservice.isArtifactUpdateRequired(context, DB_DOWNLOAD_DG_REFERENCE));
}
if (StringUtils.isBlank(context.getAttribute(DOWNLOAD_DG_REFERENCE))) {
- context.setAttribute(DOWNLOAD_DG_REFERENCE,
- dbservice.getDownLoadDGReference(context));
+ context.setAttribute(DOWNLOAD_DG_REFERENCE, dbservice.getDownLoadDGReference(context));
}
- dbservice
- .processConfigActionDg(context, dbservice.isArtifactUpdateRequired(context, DB_CONFIG_ACTION_DG));
+ dbservice.processConfigActionDg(context,
+ dbservice.isArtifactUpdateRequired(context, DB_CONFIG_ACTION_DG));
tryProcessInterfaceProtocol(content, dbservice, context);
}
@@ -556,13 +623,12 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void tryProcessInterfaceProtocol(JSONObject content, DBService dbservice, SvcLogicContext context)
- throws SvcLogicException, SQLException, ConfigurationException, DBException {
+ throws SvcLogicException, SQLException, ConfigurationException, DBException {
if (contentsActionEquals(content, CONFIGURE_PARAM) || contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM)) {
boolean isUpdateRequired = dbservice.isArtifactUpdateRequired(context, DB_DEVICE_INTERFACE_PROTOCOL);
if (contentsActionEquals(content, CONFIGURE_PARAM)
- || (contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM)
- && !isUpdateRequired)) {
+ || (contentsActionEquals(content, CONFIG_SCALE_OUT_PARAM) && !isUpdateRequired)) {
dbservice.processDeviceInterfaceProtocol(context, isUpdateRequired);
}
@@ -574,7 +640,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
public void processVmList(JSONObject content, SvcLogicContext context, DBService dbservice)
- throws SvcLogicException {
+ throws SvcLogicException {
JSONArray vmList = (JSONArray) content.get(VM);
dbservice.cleanUpVnfcReferencesForVnf(context);
for (int i = 0; i < vmList.length(); i++) {
@@ -608,9 +674,9 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void tryProcessVnfcReference(JSONObject content, SvcLogicContext context, DBService dbservice)
- throws SvcLogicException {
+ throws SvcLogicException {
if (content.getString(ACTION).equals(CONFIGURE_PARAM)
- || content.getString(ACTION).equals(CONFIG_SCALE_OUT_PARAM)) {
+ || content.getString(ACTION).equals(CONFIG_SCALE_OUT_PARAM)) {
dbservice.processVnfcReference(context, false);
}
@@ -645,8 +711,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void processAndStoreCapabilitiesArtifact(DBService dbService, JSONObject documentInfo,
- JSONObject capabilities, String capabilityArtifactName, String vnfType)
- throws ArtifactHandlerInternalException {
+ JSONObject capabilities, String capabilityArtifactName, String vnfType)
+ throws ArtifactHandlerInternalException {
log.info("Begin-->processAndStoreCapabilitiesArtifact ");
@@ -663,8 +729,8 @@ 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);
+ 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;
@@ -694,7 +760,7 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
}
private void populateProtocolReference(DBService dbservice, JSONObject content)
- throws ArtifactHandlerInternalException {
+ throws ArtifactHandlerInternalException {
log.info("Begin-->populateProtocolReference ");
try {
SvcLogicContext context = new SvcLogicContext();
@@ -705,8 +771,8 @@ public class ArtifactHandlerNode implements SvcLogicJavaPlugin {
String actionLevel = tryGetActionLevel(content);
String template = tryGetTemplate(content);
- boolean isUpdateNeeded = dbservice
- .isProtocolReferenceUpdateRequired(context, vnfType, protocol, action, actionLevel, template);
+ boolean isUpdateNeeded = dbservice.isProtocolReferenceUpdateRequired(context, vnfType, protocol, action,
+ actionLevel, template);
if (isUpdateNeeded) {
dbservice.updateProtocolReference(context, vnfType, protocol, action, actionLevel, template);
} else {
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 13941b369..f4f623cce 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
@@ -92,6 +92,8 @@ public class SdcArtifactHandlerConstants {
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 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 0d25fbcb4..7adee0da9 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
@@ -58,6 +58,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
@RunWith(PowerMockRunner.class)
@PrepareForTest({DBService.class, YANGGeneratorFactory.class})
@@ -298,4 +300,147 @@ 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();
+ 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) {
+ 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();
+ 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"));
+
+ }
+
+ }
+
+ @Test
+ public void testProcessArtifactWithException() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("test", "test");
+ Map<String, String> inParams = new HashMap<>();
+ JSONObject postData = new JSONObject();
+ JSONObject input = new JSONObject();
+ 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());
+ documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent);
+ documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "");
+ requestInfo.put("RequestInfo", "testValue");
+ 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("Missing Artifact Name"));
+ }
+
+ }
+ @Test
+ public void testProcessArtifactWithExceptionforAnsible() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("test", "test");
+ Map<String, String> inParams = new HashMap<>();
+ JSONObject postData = new JSONObject();
+ JSONObject input = new JSONObject();
+ 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());
+ 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");
+ 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"));
+ }
+ }
+
+ @Test
+ public void testProcessAndStoreCapablitiesArtifact() throws Exception {
+ ArtifactHandlerNode ah = new ArtifactHandlerNode();
+ JSONObject capabilities = new JSONObject();
+ JSONObject documentInfo = new JSONObject();
+ MockDBService dbService = MockDBService.initialise();
+ documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid");
+ documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist");
+ documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName");
+ documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc");
+ documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes");
+ documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns");
+ documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSION, "testVers");
+ documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType");
+ documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid");
+ documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSION, "testArtifactVers");
+ documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc");
+ Whitebox.invokeMethod(ah, "processAndStoreCapabilitiesArtifact", dbService, documentInfo, capabilities,
+ "artifactName", "someVnf");
+ }
+
+
}