diff options
Diffstat (limited to 'asdc-controller/src/main/java/org/openecomp/mso/asdc/client')
12 files changed, 1432 insertions, 42 deletions
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java index e069989aeb..98c7173581 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCConfiguration.java @@ -53,6 +53,9 @@ public class ASDCConfiguration implements IConfiguration { public static final String MSO_PROP_ASDC = "MSO_PROP_ASDC"; public static final String PARAMETER_PATTERN = "asdc-connections"; + public static final String MSG_BUS_ADDRESS_ATTRIBUTE_NAME = "messageBusAddress"; + public static final String COMPONENT_NAMES_ADDRESS_ATTRIBUTE_NAME = "componentNames"; + public static final String WATCHDOG_TIMEOUT_NAME = "watchDogTimeout"; public static final String CONSUMER_GROUP_ATTRIBUTE_NAME = "consumerGroup"; public static final String CONSUMER_ID_ATTRIBUTE_NAME = "consumerId"; @@ -113,14 +116,46 @@ public class ASDCConfiguration implements IConfiguration { } + @Override public java.lang.Boolean isUseHttpsWithDmaap() { return false; } + + @Override + public boolean isConsumeProduceStatusTopic(){ + return true; + } + + @Override + public List<String> getMsgBusAddress(){ + + JsonNode masterConfigNode = getASDCControllerConfigJsonNode (); + if (masterConfigNode != null && masterConfigNode.get (MSG_BUS_ADDRESS_ATTRIBUTE_NAME) != null) { + List<String> msgAddressList = new ArrayList<>(); + + Iterator<JsonNode> config = masterConfigNode.get(MSG_BUS_ADDRESS_ATTRIBUTE_NAME).elements(); + + while( config.hasNext() ) { + String key = (String)config.next().asText(); + msgAddressList.add(key); + } + if ("NULL".equals (msgAddressList) || msgAddressList.isEmpty ()) { + return null; + } else { + return msgAddressList; + } + } else { + return null; + } + + + } + public String getAsdcControllerName () { return asdcControllerName; } - + private JsonNode getASDCControllerConfigJsonNode () { if (this.msoProperties.getJsonRootNode ().get (PARAMETER_PATTERN) != null) { return this.msoProperties.getJsonRootNode ().get (PARAMETER_PATTERN).get (this.asdcControllerName); @@ -184,6 +219,16 @@ public class ASDCConfiguration implements IConfiguration { return null; } } + + public int getWatchDogTimeout () { + JsonNode masterConfigNode = getASDCControllerConfigJsonNode (); + if (masterConfigNode != null && masterConfigNode.get (WATCHDOG_TIMEOUT_NAME) != null) { + + return masterConfigNode.get (WATCHDOG_TIMEOUT_NAME).asInt (); + } else { + return 0; + } + } @Override public String getConsumerID () { @@ -376,6 +421,11 @@ public class ASDCConfiguration implements IConfiguration { throw new ASDCParametersException (POLLING_TIMEOUT_ATTRIBUTE_NAME + " parameter cannot be found in config mso.properties"); } + + if (this.getWatchDogTimeout() == 0) { + throw new ASDCParametersException (WATCHDOG_TIMEOUT_NAME + + " parameter cannot be found in config mso.properties"); + } if (this.getRelevantArtifactTypes () == null || this.getRelevantArtifactTypes ().isEmpty ()) { throw new ASDCParametersException (RELEVANT_ARTIFACT_TYPES_ATTRIBUTE_NAME @@ -386,6 +436,12 @@ public class ASDCConfiguration implements IConfiguration { throw new ASDCParametersException (USER_ATTRIBUTE_NAME + " parameter cannot be found in config mso.properties"); } + + if (this.getMsgBusAddress() == null || this.getMsgBusAddress().isEmpty ()) { + throw new ASDCParametersException (MSG_BUS_ADDRESS_ATTRIBUTE_NAME + + " parameter cannot be found in config mso.properties"); + } + } /** diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCController.java index 22c4b04ff4..6a752297ca 100644 --- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/ASDCController.java @@ -1,5 +1,5 @@ /*-
- * ============LICENSE_START=======================================================
+d * ============LICENSE_START=======================================================
* ONAP - SO
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
@@ -26,14 +26,18 @@ import java.io.File; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.List;
import org.openecomp.sdc.api.IDistributionClient;
import org.openecomp.sdc.api.consumer.IDistributionStatusMessage;
+import org.openecomp.sdc.api.consumer.IFinalDistrStatusMessage;
import org.openecomp.sdc.api.consumer.INotificationCallback;
+import org.openecomp.sdc.api.consumer.IStatusCallback;
import org.openecomp.sdc.api.notification.IArtifactInfo;
import org.openecomp.sdc.api.notification.INotificationData;
import org.openecomp.sdc.api.notification.IResourceInstance;
+import org.openecomp.sdc.api.notification.IStatusData;
import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
import org.openecomp.sdc.api.results.IDistributionClientResult;
import org.openecomp.sdc.impl.DistributionClientFactory;
@@ -48,10 +52,14 @@ import org.openecomp.mso.asdc.installer.ToscaResourceStructure; import org.openecomp.mso.asdc.installer.VfResourceStructure;
import org.openecomp.mso.asdc.installer.heat.ToscaResourceInstaller;
import org.openecomp.mso.asdc.installer.heat.VfResourceInstaller;
+import org.openecomp.mso.asdc.tenantIsolation.DistributionStatus;
+import org.openecomp.mso.asdc.tenantIsolation.WatchdogDistribution;
import org.openecomp.mso.asdc.util.ASDCNotificationLogging;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoAlarmLogger;
import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import org.openecomp.mso.requestsdb.WatchdogDistributionStatusDb;
import org.openecomp.mso.utils.UUIDChecker;
public class ASDCController {
@@ -66,6 +74,96 @@ public class ASDCController { protected ToscaResourceInstaller toscaInstaller;
+ private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+
+ private final class ResourceInstance implements IResourceInstance {
+
+ @Override
+ public String getResourceInstanceName(){
+ return new String();
+ }
+
+ @Override
+ public String getResourceName(){
+ return new String();
+ }
+
+ @Override
+ public String getResourceVersion(){
+ return new String();
+ }
+
+ @Override
+ public String getResourceType(){
+ return new String();
+ }
+
+ @Override
+ public String getResourceUUID(){
+ return new String();
+ }
+
+ // Method descriptor #10 ()Ljava/util/List;
+ @Override
+ public java.util.List getArtifacts(){
+ return new ArrayList();
+ }
+
+ @Override
+ public String getResourceInvariantUUID(){
+ return new String();
+ }
+
+ @Override
+ public String getResourceCustomizationUUID(){
+ return new String();
+ }
+
+ @Override
+ public String getCategory(){
+ return new String();
+ }
+
+ @Override
+ public String getSubcategory(){
+ return new String();
+ }
+
+ }
+
+ private final class ASDCStatusCallBack implements IStatusCallback {
+
+ @Override
+ public void activateCallback (IStatusData iStatus) {
+
+ long startTime = System.currentTimeMillis ();
+ UUIDChecker.generateUUID (LOGGER);
+ MsoLogger.setServiceName ("ASDCStatusCallBack");
+ MsoLogger.setLogContext (iStatus.getDistributionID (), iStatus.getComponentName());
+ String event = "Receive a callback componentStatus in ASDC, for componentName: " + iStatus.getComponentName() + " and status of " + iStatus.getStatus() + " distributionID of " + iStatus.getDistributionID() +
+ " consumerID of " + iStatus.getConsumerID() + " errorReason of " + iStatus.getErrorReason();
+
+ try{
+
+ if (iStatus.getStatus() == DistributionStatusEnum.COMPONENT_DONE_OK ||
+ iStatus.getStatus() == DistributionStatusEnum.COMPONENT_DONE_ERROR) {
+
+ LOGGER.debug(event);
+
+ toscaInstaller.installTheComponentStatus(iStatus);
+
+ }
+
+ }catch(ArtifactInstallerException e){
+ System.out.println("Error in ASDCStatusCallback " + e.getMessage());
+ LOGGER.debug("Error in ASDCStatusCallback " + e.getMessage());
+ }
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Completed the Status Call Back");
+ }
+
+ }
+
/**
* Inner class for Notification callback
@@ -96,6 +194,7 @@ public class ASDCController { LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Completed the treatment of the notification");
}
}
+
// ***** Controller STATUS code
@@ -136,7 +235,6 @@ public class ASDCController { }
// ***** END of Controller STATUS code
-
protected ASDCConfiguration asdcConfig;
private IDistributionClient distributionClient;
private IVfResourceInstaller resourceInstaller;
@@ -224,7 +322,7 @@ public class ASDCController { }
long initStartTime = System.currentTimeMillis ();
IDistributionClientResult result = this.distributionClient.init (asdcConfig,
- new ASDCNotificationCallBack (this));
+ new ASDCNotificationCallBack (this), new ASDCStatusCallBack());
if (!result.getDistributionActionResult ().equals (DistributionActionResultEnum.SUCCESS)) {
String endEvent = "ASDC distribution client init failed with reason:"
+ result.getDistributionMessageResult ();
@@ -284,20 +382,20 @@ public class ASDCController { private boolean checkResourceAlreadyDeployed (VfResourceStructure resource) throws ArtifactInstallerException {
- if (toscaInstaller.isResourceAlreadyDeployed (resource)) {
- LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
+
+ if (toscaInstaller.isResourceAlreadyDeployed (resource)) {
+ LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
resource.getResourceInstance().getResourceInstanceName(),
resource.getResourceInstance().getResourceUUID(),
resource.getResourceInstance().getResourceName(), "", "");
- this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
- this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DEPLOYED,null);
-
- return true;
- } else {
- return false;
- }
+ this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
+ this.sendDeployNotificationsForResource(resource,DistributionStatusEnum.ALREADY_DEPLOYED,null);
+ return true;
+ } else {
+ return false;
+ }
}
private final static String UUID_PARAM = "(UUID:";
@@ -413,7 +511,7 @@ public class ASDCController { for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) {
- if (DistributionStatusEnum.DEPLOY_OK.equals(distribStatus)
+ if ((DistributionStatusEnum.DEPLOY_OK.equals(distribStatus) && !artifactInfo.getArtifactType().equalsIgnoreCase("OTHER"))
// This could be NULL if the artifact is a VF module artifact, this won't be present in the MAP
&& vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()) != null
&& vfResourceStructure.getArtifactsMapByUUID().get(artifactInfo.getArtifactUUID()).getDeployedInDb() == 0) {
@@ -435,7 +533,34 @@ public class ASDCController { }
}
}
-
+
+ private void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) {
+
+ IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
+
+ if(deploySuccessful){
+
+ this.sendASDCNotification (NotificationType.DEPLOY,
+ csarArtifact.getArtifactURL (),
+ asdcConfig.getConsumerID (),
+ resourceStructure.getNotification().getDistributionID(),
+ DistributionStatusEnum.DEPLOY_OK,
+ errorReason,
+ System.currentTimeMillis ());
+
+ } else {
+
+ this.sendASDCNotification (NotificationType.DEPLOY,
+ csarArtifact.getArtifactURL (),
+ asdcConfig.getConsumerID (),
+ resourceStructure.getNotification().getDistributionID(),
+ DistributionStatusEnum.DEPLOY_ERROR,
+ errorReason,
+ System.currentTimeMillis ());
+
+ }
+ }
+
private void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
LOGGER.info (MessageEnum.ASDC_START_DEPLOY_ARTIFACT, resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC", "deployResourceStructure");
@@ -445,21 +570,10 @@ public class ASDCController { if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){
resourceStructure.createVfModuleStructures();
}
- //resourceInstaller.installTheResource (resourceStructure);
-
- //ToscaResourceInstaller tri = new ToscaResourceInstaller();
- toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure);
-
- /* if(toscaResourceStructure.isVnfAlreadyInstalled()){
- LOGGER.info (MessageEnum.ASDC_ARTIFACT_ALREADY_EXIST,
- toscaResourceStructure.getCatalogVnfResource().getModelName(),
- toscaResourceStructure.getCatalogVnfResource().getModelUuid(),
- toscaResourceStructure.getCatalogVnfResource().getModelUuid(),"","");
+
-
- this.sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.ALREADY_DOWNLOADED,null);
- this.sendDeployNotificationsForResource(resourceStructure,DistributionStatusEnum.ALREADY_DEPLOYED,null);
- } */
+ toscaInstaller.installTheResource(toscaResourceStructure, resourceStructure);
+
} catch (ArtifactInstallerException e) {
LOGGER.info (MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL,
@@ -470,7 +584,7 @@ public class ASDCController { throw e;
}
- if (resourceStructure.isDeployedSuccessfully()) {
+ if (resourceStructure.isDeployedSuccessfully() || toscaResourceStructure.isDeployedSuccessfully()) {
LOGGER.info (MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC,
resourceStructure.getResourceInstance().getResourceName(),
resourceStructure.getResourceInstance().getResourceUUID(),
@@ -479,6 +593,7 @@ public class ASDCController { }
}
+
private enum NotificationType {
DOWNLOAD, DEPLOY
@@ -541,10 +656,42 @@ public class ASDCController { }
LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent notification to ASDC", "ASDC", action, null);
}
+
+ private void sendFinalDistributionStatus (
+ String distributionID,
+ DistributionStatusEnum status,
+ String errorReason) {
+
+
+ LOGGER.debug ("Enter sendFinalDistributionStatus with DistributionID " + distributionID + " and Status of " + status.name() + " and ErrorReason " + errorReason);
+
+ long subStarttime = System.currentTimeMillis ();
+ try {
+
+
+ IFinalDistrStatusMessage finalDistribution = new FinalDistributionStatusMessage(distributionID,status,subStarttime, asdcConfig.getConsumerID());
+
+ if(errorReason == null){
+ this.distributionClient.sendFinalDistrStatus(finalDistribution);
+ }else{
+ this.distributionClient.sendFinalDistrStatus(finalDistribution, errorReason);
+ }
+
+
+ } catch (RuntimeException e) {
+ // TODO: May be a list containing the unsent notification should be
+ // kept
+ LOGGER.debug ("Exception caught in sendFinalDistributionStatus " + e.getMessage());
+ LOGGER.warn (MessageEnum.ASDC_SEND_NOTIF_ASDC_EXEC, "ASDC", "sendASDCNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException - sendASDCNotification", e);
+ }
+ LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent Final notification to ASDC", "ASDC", null, null);
+ }
public void treatNotification (INotificationData iNotif) {
int noOfArtifacts = 0;
+ WatchdogDistribution wd = new WatchdogDistribution();
+
for (IResourceInstance resource : iNotif.getResources ()) {
noOfArtifacts += resource.getArtifacts ().size ();
}
@@ -561,21 +708,102 @@ public class ASDCController { // Process only the Resource artifacts in MSO
for (IResourceInstance resource : iNotif.getResources()) {
-
- // We process only VNF(VF) and Network(VL) resources on MSO Side
- // We process only VNF resource on MSO Side
- if ("VF".equals(resource.getResourceType()) || "VL".equals(resource.getResourceType())) {
- this.processResourceNotification(iNotif,resource);
- }
+
+ // We process only VNF(VF), Network(VL) and PNF resources on MSO Side
+ //if ("VF".equals(resource.getResourceType()) || "VL".equals(resource.getResourceType()) || "PNF".equals(resource.getResourceType())){
+ this.processResourceNotification(iNotif,resource);
+ //}
}
+
+ //Handle services without any resources
+ if (iNotif.getResources() == null || iNotif.getResources().size() < 1){
+
+ this.processResourceNotification(iNotif, new ResourceInstance());
+ }
+
+ //********************************************************************************************************
+ //Start Watchdog loop and wait for all components to complete before reporting final status back.
+ // **If timer expires first then we will report a Distribution Error back to ASDC
+ //********************************************************************************************************
+ long initialStartTime = System.currentTimeMillis();
+ boolean componentsComplete = false;
+ String distributionStatus = null;
+ String watchdogError = null;
+ String overallStatus = null;
+ int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000;
+ boolean isDeploySuccess = false;
+ WatchdogDistributionStatusDb wdDistributionStatus = WatchdogDistributionStatusDb.getInstance();
+
+
+ while(componentsComplete == false && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout)
+ {
+
+ try{
+
+ distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
+ Thread.sleep(watchDogTimeout / 10);
+
+ }catch(Exception e){
+ LOGGER.debug ("Exception in Watchdog Loop " + e.getMessage());
+ Thread.sleep(watchDogTimeout / 10);
+ }
+
+ if(distributionStatus != null && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())){
+
+ if(distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())){
+ isDeploySuccess = true;
+ overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name();
+ }else{
+ overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
+ }
+
+ componentsComplete = true;
+ }
+ }
+
+ if(componentsComplete == false){
+ LOGGER.debug("Timeout of " + watchDogTimeout + " seconds was reached before all components reported status");
+ watchdogError = "Timeout occurred while waiting for all components to report status";
+ overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
+ }
+
+ if(distributionStatus == null){
+ overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
+ LOGGER.debug("DistributionStatus is null for DistributionId: " + iNotif.getDistributionID());
+
+ }
+
+ try {
+ wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus);
+ LOGGER.debug ("A&AI Updated succefully with Distribution Status!");
+ }
+ catch(Exception e) {
+ LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e.getMessage());
+ watchdogError = "Error calling A&AI " + e.getMessage();
+ if(e.getCause() != null) {
+ LOGGER.debug ("Exception caused by: " + e.getCause().getMessage());
+ }
+ }
+
+
+ if(isDeploySuccess && watchdogError == null){
+ sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, null);
+ wdDistributionStatus.updateWatchdogDistributionIdStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name());
+ } else {
+ sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError);
+ wdDistributionStatus.updateWatchdogDistributionIdStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
+ }
+
+
-
-
- } catch (RuntimeException e) {
+ } catch (Exception e) {
LOGGER.error (MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
"Unexpected exception caught during the notification processing", "ASDC", "treatNotification", MsoLogger.ErrorCode.SchemaError, "RuntimeException in treatNotification",
e);
+
+ sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, e.getMessage());
+
} finally {
this.changeControllerStatus (ASDCControllerStatus.IDLE);
}
@@ -586,6 +814,8 @@ public class ASDCController { // For each artifact, create a structure describing the VFModule in a ordered flat level
VfResourceStructure resourceStructure = new VfResourceStructure(iNotif,resource);
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
+ boolean deploySuccessful = true;
+ String errorMessage = null;
try {
@@ -605,12 +835,22 @@ public class ASDCController { }
}
-
this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
- this.deployResourceStructure(resourceStructure, toscaResourceStructure);
+ try{
+
+ this.deployResourceStructure(resourceStructure, toscaResourceStructure);
+
+ } catch(ArtifactInstallerException e){
+ deploySuccessful = false;
+ errorMessage = e.getMessage();
+ }
+
+ this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, errorMessage);
+
- }
+
+ }
} catch (ArtifactInstallerException | ASDCDownloadException | UnsupportedEncodingException e) {
LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
"Exception caught during Installation of artifact", "ASDC", "processResourceNotification", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processResourceNotification", e);
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/FinalDistributionStatusMessage.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/FinalDistributionStatusMessage.java new file mode 100644 index 0000000000..6205bd5140 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/FinalDistributionStatusMessage.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client; + +import org.openecomp.sdc.api.consumer.IFinalDistrStatusMessage; +import org.openecomp.sdc.utils.DistributionStatusEnum; + +public class FinalDistributionStatusMessage implements IFinalDistrStatusMessage{ + + private String componentName; + + private String consumerID; + + private String distributionID; + + private DistributionStatusEnum status; + + private long timestamp; + + public FinalDistributionStatusMessage (String distributionId, final DistributionStatusEnum distributionStatusEnum, final long timestampL, String consumerId) { + //componentName = componentname; + consumerID = consumerId; + distributionID = distributionId; + status = distributionStatusEnum; + timestamp = timestampL; + } + + public DistributionStatusEnum getStatus() { + return status; + } + + public void setStatus(DistributionStatusEnum status) { + this.status = status; + } + + public String getDistributionID() { + return distributionID; + } + + public void setDistributionID(String distributionID) { + this.distributionID = distributionID; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + + public String getComponentName() { + return componentName; + } + + public void setComponentName(String componentName) { + this.componentName = componentName; + } + + public String getConsumerID() { + return consumerID; + } + + public void setConsumerID(String consumerID) { + this.consumerID = consumerID; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/DistributionClientEmulator.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/DistributionClientEmulator.java new file mode 100644 index 0000000000..d6d6f7986d --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/DistributionClientEmulator.java @@ -0,0 +1,204 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.openecomp.mso.asdc.installer.IVfModuleData; +import org.openecomp.sdc.api.IDistributionClient; +import org.openecomp.sdc.api.consumer.IComponentDoneStatusMessage; +import org.openecomp.sdc.api.consumer.IConfiguration; +import org.openecomp.sdc.api.consumer.IDistributionStatusMessage; +import org.openecomp.sdc.api.consumer.IFinalDistrStatusMessage; +import org.openecomp.sdc.api.consumer.INotificationCallback; +import org.openecomp.sdc.api.consumer.IStatusCallback; +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.IVfModuleMetadata; +import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; +import org.openecomp.sdc.api.results.IDistributionClientResult; +import org.openecomp.sdc.impl.DistributionClientDownloadResultImpl; +import org.openecomp.sdc.impl.DistributionClientResultImpl; +import org.openecomp.sdc.utils.DistributionActionResultEnum; + +public class DistributionClientEmulator implements IDistributionClient { + + private String resourcePath; + + private List<IVfModuleData> listVFModuleMetaData; + + private List<IDistributionStatusMessage> distributionMessageReceived = new LinkedList<>(); + + public DistributionClientEmulator(String notifFolderInResource) { + + resourcePath = notifFolderInResource; + } + + public List<IDistributionStatusMessage> getDistributionMessageReceived() { + return distributionMessageReceived; + } + + @Override + public List<IVfModuleMetadata> decodeVfModuleArtifact(byte[] arg0) { + return null; + } + + /* @Override + public List<IVfModuleData> decodeVfModuleArtifact(byte[] arg0) { + try { + listVFModuleMetaData = new ObjectMapper().readValue(arg0, new TypeReference<List<JsonVfModuleMetaData>>(){}); + return listVFModuleMetaData; + + } catch (JsonParseException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } */ + + public List<IVfModuleData> getListVFModuleMetaData() { + return listVFModuleMetaData; + } + + @Override + public IDistributionClientDownloadResult download (IArtifactInfo arg0) { + + + //String filename = resourcePath+"/artifacts/"+arg0.getArtifactURL(); + String filename = arg0.getArtifactURL(); + System.out.println("Emulating the download from resources files:"+filename); + + InputStream inputStream = null; + + if(arg0.getArtifactName().equals("service_PortMirroringContainer_csar.csar")){ + try{ + inputStream = new FileInputStream("C://Users//JM5423//git//mso//asdc-tosca-1712-test3//openecomp-mso//asdc-controller//src//main//resources//resource-examples//service_PortMirroringContainer_csar.csar"); + }catch(Exception e){ + System.out.println("Error " + e.getMessage()); + } + }else{ + + inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath + filename); + } + + if (inputStream == null) { + System.out.println("InputStream is NULL for:"+filename); + } + try { + return new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, DistributionActionResultEnum.SUCCESS.name(),arg0.getArtifactName(),IOUtils.toByteArray(inputStream)); + } catch (IOException e) { + + e.printStackTrace(); + } + return null; + } + + @Override + public IConfiguration getConfiguration() { + return null; + } + + @Override + public IDistributionClientResult init(IConfiguration arg0, INotificationCallback arg1) { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult init(IConfiguration arg0, INotificationCallback arg1, IStatusCallback arg2) { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage arg0) { + this.distributionMessageReceived.add(arg0); + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult sendDeploymentStatus(IDistributionStatusMessage arg0, String arg1) { + this.distributionMessageReceived.add(arg0); + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage arg0) { + this.distributionMessageReceived.add(arg0); + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult sendDownloadStatus(IDistributionStatusMessage arg0, String arg1) { + this.distributionMessageReceived.add(arg0); + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult start() { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult stop() { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + + } + + @Override + public IDistributionClientResult updateConfiguration(IConfiguration arg0) { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS,DistributionActionResultEnum.SUCCESS.name()); + } + + @Override + public IDistributionClientResult sendComponentDoneStatus( + IComponentDoneStatusMessage arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus( + IFinalDistrStatusMessage arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendComponentDoneStatus( + IComponentDoneStatusMessage arg0, String arg1) { + // TODO Auto-generated method stub + return null; + } + + @Override + public IDistributionClientResult sendFinalDistrStatus( + IFinalDistrStatusMessage arg0, String arg1) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfo.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfo.java new file mode 100644 index 0000000000..2da59969a7 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfo.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdc.api.notification.IArtifactInfo; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class JsonArtifactInfo implements IArtifactInfo { + + @JsonIgnore + private Map<String,IArtifactInfo> artifactsMapByUUID = new HashMap<>(); + + @JsonIgnore + private Map<String,Object> attributesMap = new HashMap<>(); + + public JsonArtifactInfo() { + + } + + public synchronized void addArtifactToUUIDMap (List<JsonArtifactInfo> artifactList) { + for (JsonArtifactInfo artifact:artifactList) { + artifactsMapByUUID.put(artifact.getArtifactUUID(), artifact); + } + + } + + @SuppressWarnings("unused") + @JsonAnySetter + public final void setAttribute(String attrName, Object attrValue) { + if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) { + this.attributesMap.put(attrName,attrValue); + } + } + + + + public Map<String, IArtifactInfo> getArtifactsMapByUUID() { + return artifactsMapByUUID; + } + + @Override + public String getArtifactChecksum() { + return (String)attributesMap.get("artifactCheckSum"); + } + + @Override + public String getArtifactDescription() { + return (String)attributesMap.get("artifactDescription"); + } + + @Override + public String getArtifactName() { + return (String)attributesMap.get("artifactName"); + } + + @Override + public Integer getArtifactTimeout() { + return (Integer)attributesMap.get("artifactTimeout"); + } + + @Override + public String getArtifactType() { + return (String)attributesMap.get("artifactType"); + } + + @Override + public String getArtifactURL() { + return (String)attributesMap.get("artifactURL"); + } + + @Override + public String getArtifactUUID() { + return (String)attributesMap.get("artifactUUID"); + } + + @Override + public String getArtifactVersion() { + return (String)attributesMap.get("artifactVersion"); + } + + @Override + public IArtifactInfo getGeneratedArtifact () { + return artifactsMapByUUID.get(attributesMap.get("generatedArtifact")); + } + + @Override + public List<IArtifactInfo> getRelatedArtifacts() { + List<IArtifactInfo> listArtifacts = new LinkedList<>(); + List<String> uuidList = (List<String>)attributesMap.get("relatedArtifact"); + if (uuidList != null) { + for(String uuid:uuidList) { + listArtifacts.add(artifactsMapByUUID.get(uuid)); + } + } + return listArtifacts; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfoDeserializer.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfoDeserializer.java new file mode 100644 index 0000000000..66863b562e --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonArtifactInfoDeserializer.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonArtifactInfoDeserializer extends JsonDeserializer<List<JsonArtifactInfo>>{ + + @Override + public List<JsonArtifactInfo> deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + List<JsonArtifactInfo> jsonArtifactInfoList = new ObjectMapper().readValue(jp, new TypeReference<List<JsonArtifactInfo>>(){}); + + // For each artifact add the list of artifact retrieved + // This could be used later to index by UUID + for (JsonArtifactInfo artifactInfo:jsonArtifactInfoList) { + artifactInfo.addArtifactToUUIDMap(jsonArtifactInfoList); + } + return jsonArtifactInfoList; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationData.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationData.java new file mode 100644 index 0000000000..257dae99cf --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonNotificationData.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.INotificationData; +import org.openecomp.sdc.api.notification.IResourceInstance; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + + +public class JsonNotificationData implements INotificationData { + + @JsonIgnore + private static ObjectMapper mapper = new ObjectMapper(); + + @JsonIgnore + private Map<String,Object> attributesMap = new HashMap<>(); + + @JsonProperty("serviceArtifacts") + @JsonDeserialize(using=JsonArtifactInfoDeserializer.class) + private List<IArtifactInfo> serviceArtifacts; + + @JsonProperty("resources") + @JsonDeserialize(using=JsonResourceInfoDeserializer.class) + private List<IResourceInstance> resourcesList; + + public JsonNotificationData() { + + } + + /** + * Method instantiate a INotificationData implementation from a JSON file. + * + * @param notifFilePath The file path in String + * @return A JsonNotificationData instance + * @throws IOException in case of the file is not readable or not accessible + */ + public static JsonNotificationData instantiateNotifFromJsonFile(String notifFilePath) throws IOException { + + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(notifFilePath + "notif-structure.json"); + + //String fileLocation = System.getProperty("mso.config.path") + "notif-structure.json"; + + //String source = fileLocation; + //InputStream is = IOUtils.toInputStream(source, "UTF-8"); + + //String myString = IOUtils.toString(is, "UTF-8"); + + + //System.out.println(myString); + + if (is == null) { + //throw new FileExistsException("Resource Path does not exist: "+notifFilePath); + } + return mapper.readValue(is, JsonNotificationData.class); + } + + @SuppressWarnings("unused") + @JsonAnySetter + public final void setAttribute(String attrName, Object attrValue) { + if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) { + this.attributesMap.put(attrName,attrValue); + } + } + + @Override + public String getWorkloadContext(){ + return (String)this.attributesMap.get("workloadContext"); + } + + @Override + public void setWorkloadContext(java.lang.String arg0){ + + } + + @Override + public IArtifactInfo getArtifactMetadataByUUID(String arg0) { + return null; + } + + @Override + public String getDistributionID() { + return (String)this.attributesMap.get("distributionID"); + } + + @Override + public List<IResourceInstance> getResources() { + return resourcesList; + } + + @Override + public List<IArtifactInfo> getServiceArtifacts() { + return this.serviceArtifacts; + } + + @Override + public String getServiceDescription() { + return (String)this.attributesMap.get("serviceDescription"); + } + + @Override + public String getServiceInvariantUUID() { + return (String)this.attributesMap.get("serviceInvariantUUID"); + } + + @Override + public String getServiceName() { + return (String)this.attributesMap.get("serviceName"); + } + + @Override + public String getServiceUUID() { + return (String)this.attributesMap.get("serviceUUID"); + } + + @Override + public String getServiceVersion() { + return (String)this.attributesMap.get("serviceVersion"); + } +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfo.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfo.java new file mode 100644 index 0000000000..c2e1cbbcce --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfo.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.openecomp.sdc.api.notification.IResourceInstance; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +public class JsonResourceInfo implements IResourceInstance { + + @JsonIgnore + private Map<String,Object> attributesMap = new HashMap<>(); + + @JsonProperty("artifacts") + @JsonDeserialize(using=JsonArtifactInfoDeserializer.class) + private List<IArtifactInfo> artifacts; + + public JsonResourceInfo() { + + } + + @Override + public List<IArtifactInfo> getArtifacts() { + return artifacts; + } + + @Override + public String getResourceInstanceName() { + return (String)attributesMap.get("resourceInstanceName"); + } + + @Override + public String getResourceInvariantUUID() { + return (String)attributesMap.get("resourceInvariantUUID"); + } + + @Override + public String getResourceCustomizationUUID() { + return (String)attributesMap.get("resourceCustomizationUUID"); + } + + @Override + public String getResourceName() { + return (String)attributesMap.get("resourceName"); + } + + @Override + public String getResourceType() { + return (String)attributesMap.get("resourceType"); + } + + @Override + public String getResourceUUID() { + return (String)attributesMap.get("resourceUUID"); + } + + @Override + public String getResourceVersion() { + return (String)attributesMap.get("resourceVersion"); + } + + @Override + public String getSubcategory() { + return (String)attributesMap.get("subCategory"); + } + + @Override + public String getCategory() { + return (String)attributesMap.get("category"); + } + + @SuppressWarnings("unused") + @JsonAnySetter + public final void setAttribute(String attrName, Object attrValue) { + if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) { + this.attributesMap.put(attrName,attrValue); + } + } +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoDeserializer.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoDeserializer.java new file mode 100644 index 0000000000..49908e71a0 --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonResourceInfoDeserializer.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonResourceInfoDeserializer extends JsonDeserializer<List<JsonResourceInfo>>{ + + @Override + public List<JsonResourceInfo> deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + List<JsonResourceInfo> jsonResourceInfoList = new ObjectMapper().readValue(jp, new TypeReference<List<JsonResourceInfo>>(){}); + + return jsonResourceInfoList; + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusData.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusData.java new file mode 100644 index 0000000000..627f8f409e --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonStatusData.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.sdc.api.notification.IStatusData; +import org.openecomp.sdc.utils.DistributionStatusEnum; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class JsonStatusData implements IStatusData { + + @JsonIgnore + private static ObjectMapper mapper = new ObjectMapper(); + + @JsonIgnore + private Map<String,Object> attributesMap = new HashMap<>(); + + public JsonStatusData() { + + } + + @Override + public String getErrorReason(){ + return "MSO FAILURE"; + } + + @Override + public String getDistributionID(){ + //return (String)this.attributesMap.get("distributionID"); + return "35120a87-1f82-4276-9735-f6de5a244d65"; + } + + @Override + public String getConsumerID(){ + //return (String)this.attributesMap.get("consumerID"); + return "mso.123456"; + } + + @Override + public String getComponentName(){ + //return (String)this.attributesMap.get("componentName"); + return "SDN-C"; + } + + @Override + public Long getTimestamp(){ + //return (String)this.attributesMap.get("timestamp"); + return null; + } + + @Override + public String getArtifactURL(){ + //return (String)this.attributesMap.get("artifactURL"); + return "/sdc/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"; + } + + @Override + public DistributionStatusEnum getStatus(){ + //return (DistributionStatusEnum)this.attributesMap.get(DistributionStatusEnum.DEPLOY_OK); + return DistributionStatusEnum.COMPONENT_DONE_OK; + } + + /** + * Method instantiate a INotificationData implementation from a JSON file. + * + * @param notifFilePath The file path in String + * @return A JsonNotificationData instance + * @throws IOException in case of the file is not readable or not accessible + */ + public static JsonStatusData instantiateNotifFromJsonFile(String notifFilePath) throws IOException { + + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(notifFilePath + "status-structure.json"); + + //String fileLocation = System.getProperty("mso.config.path") + "notif-structure.json"; + + //String source = fileLocation; + //InputStream is = IOUtils.toInputStream(source, "UTF-8"); + + //String myString = IOUtils.toString(is, "UTF-8"); + + + //System.out.println(myString); + + if (is == null) { + //throw new FileExistsException("Resource Path does not exist: "+notifFilePath); + } + return mapper.readValue(is, JsonStatusData.class); + } + + @SuppressWarnings("unused") + @JsonAnySetter + public final void setAttribute(String attrName, Object attrValue) { + if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) { + this.attributesMap.put(attrName,attrValue); + } + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonVfModuleMetaData.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonVfModuleMetaData.java new file mode 100644 index 0000000000..765f14f78e --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/emulators/JsonVfModuleMetaData.java @@ -0,0 +1,96 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.emulators; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openecomp.mso.asdc.installer.IVfModuleData; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; + +public class JsonVfModuleMetaData implements IVfModuleData { + + @JsonProperty("artifacts") + private List<String> artifacts; + @JsonProperty("properties") + //private List<Map<String, Object>> properties = new ArrayList<>(); + private Map<String,String> properties = new HashMap<>(); + + public Map<String, String> getProperties() { + return properties; + } + + @JsonIgnore + private Map<String,Object> attributesMap = new HashMap<>(); + + @Override + public List<String> getArtifacts() { + return artifacts; + } + + @Override + public String getVfModuleModelDescription() { + return (String)attributesMap.get("vfModuleModelDescription"); + } + + @Override + public String getVfModuleModelInvariantUUID() { + return (String)attributesMap.get("vfModuleModelInvariantUUID"); + } + + @Override + public String getVfModuleModelCustomizationUUID() { + return (String)attributesMap.get("vfModuleModelCustomizationUUID"); + } + + @Override + public String getVfModuleModelName() { + return (String)attributesMap.get("vfModuleModelName"); + } + + @Override + public String getVfModuleModelUUID() { + return (String)attributesMap.get("vfModuleModelUUID"); + } + + @Override + public String getVfModuleModelVersion() { + return (String)attributesMap.get("vfModuleModelVersion"); + } + + @Override + public boolean isBase() { + return (boolean)attributesMap.get("isBase"); + } + + @SuppressWarnings("unused") + @JsonAnySetter + public final void setAttribute(String attrName, Object attrValue) { + if ((null != attrName) && (!attrName.isEmpty()) && (null != attrValue) && (null != attrValue.toString())) { + this.attributesMap.put(attrName,attrValue); + } + } + +} diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/rest/ASDCRestInterface.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/rest/ASDCRestInterface.java new file mode 100644 index 0000000000..ae434b1d3c --- /dev/null +++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/client/test/rest/ASDCRestInterface.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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.openecomp.mso.asdc.client.test.rest;
+
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.mso.asdc.client.ASDCController;
+import org.openecomp.mso.asdc.client.test.emulators.DistributionClientEmulator;
+import org.openecomp.mso.asdc.client.test.emulators.JsonNotificationData;
+import org.openecomp.mso.asdc.client.test.emulators.JsonStatusData;
+import org.openecomp.mso.asdc.installer.heat.ToscaResourceInstaller;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+
+/**
+ * This is a TEST only rest interface. It is not used in production, it is used to aid in testing the ASDC service on jboss without the need to be connected
+ * to the ASDC service broker. It starts the test at the treatNotification step and simulates both the notification step as well as the artifact download step.
+ *
+ * i.e. http://localhost:8080/asdc/treatNotification/v1
+ *
+ * i.e. http://localhost:8080/asdc/statusData/v1
+ *
+ * @author jm5423
+ *
+ */
+
+@Path("/")
+public class ASDCRestInterface {
+
+ private static DistributionClientEmulator distributionClientEmulator;
+
+ private static JsonNotificationData notifDataWithoutModuleInfo;
+
+ private static JsonStatusData statusData;
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC);
+
+ @GET
+ @Path("/treatNotification/v1")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response invokeASDCService(String request) {
+
+ try{
+ distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
+ notifDataWithoutModuleInfo = JsonNotificationData.instantiateNotifFromJsonFile("resource-examples/");
+
+ ASDCController asdcController = new ASDCController("asdc-controller1", distributionClientEmulator);
+ LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "initASDC()");
+ asdcController.initASDC();
+ LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "treatNotification()");
+ asdcController.treatNotification(notifDataWithoutModuleInfo);
+ LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "closeASDC()");
+ asdcController.closeASDC();
+ }catch(Exception e){
+ System.out.println("Error caught " + e.getMessage());
+ LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION,
+ "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in invokeASDCService", e);
+ }
+ System.out.println("ASDC Updates are complete");
+ LOGGER.info(MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "ASDC Updates Are Complete");
+
+ return null;
+ }
+
+ @GET
+ @Path("/statusData/v1")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response invokeASDCStatusData(String request) {
+
+ ToscaResourceInstaller toscaInstaller = new ToscaResourceInstaller();
+
+ try{
+ distributionClientEmulator = new DistributionClientEmulator("resource-examples/");
+ statusData = JsonStatusData.instantiateNotifFromJsonFile("resource-examples/");
+
+ ASDCController asdcController = new ASDCController("asdc-controller1", distributionClientEmulator);
+ //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "initASDC()");
+ asdcController.initASDC();
+ //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "treatNotification()");
+ toscaInstaller.installTheComponentStatus(statusData);
+ //asdcController.treatNotification(notifDataWithoutModuleInfo);
+ //LOGGER.info(MessageEnum.ASDC_INIT_ASDC_CLIENT_EXC, notifDataWithoutModuleInfo.getServiceUUID(), "ASDC", "closeASDC()");
+ asdcController.closeASDC();
+ }catch(Exception e){
+ System.out.println("Error caught " + e.getMessage());
+ LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION,
+ "Exception caught during ASDCRestInterface", "ASDC", "invokeASDCService", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in invokeASDCService", e);
+ }
+ System.out.println("ASDC Updates are complete");
+ LOGGER.info(MessageEnum.ASDC_ARTIFACT_DEPLOY_SUC, statusData.getDistributionID(), "ASDC", "ASDC Updates Are Complete");
+
+ return null;
+ }
+}
|