package org.onap.so.asdc.client;
+import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
+import java.nio.file.Paths;
import java.util.List;
import org.onap.sdc.api.IDistributionClient;
import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
import org.onap.so.asdc.installer.IVfResourceInstaller;
import org.onap.so.asdc.installer.ToscaResourceStructure;
-import org.onap.so.asdc.installer.VfModuleStructure;
import org.onap.so.asdc.installer.VfResourceStructure;
+import org.onap.so.asdc.installer.bpmn.BpmnInstaller;
import org.onap.so.asdc.installer.heat.ToscaResourceInstaller;
import org.onap.so.asdc.tenantIsolation.DistributionStatus;
import org.onap.so.asdc.tenantIsolation.WatchdogDistribution;
import org.onap.so.db.request.beans.WatchdogDistributionStatus;
import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
import org.onap.so.logger.MessageEnum;
-import org.onap.so.logger.MsoAlarmLogger;
+
import org.onap.so.logger.MsoLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
protected static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ASDCController.class);
- protected static MsoAlarmLogger alarmLogger = new MsoAlarmLogger ();
+
protected boolean isAsdcClientAutoManaged = false;
@Autowired
private ToscaResourceInstaller toscaInstaller;
+ @Autowired
+ private BpmnInstaller bpmnInstaller;
+
@Autowired
private WatchdogDistributionStatusRepository wdsRepo;
+ artifact.getArtifactUUID ()
+ ")");
+ String filePath = Paths.get(System.getProperty("mso.config.path"), "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize().toString();
+ // make parent directory
+ File file = new File(filePath);
+ File fileParent = file.getParentFile();
+ if (!fileParent.exists()) {
+ fileParent.mkdirs();
+ }
+
byte[] payloadBytes = resultArtifact.getArtifactPayload();
- try (FileOutputStream outFile = new FileOutputStream(System.getProperty("mso.config.path") + "/ASDC" + "/" + artifact.getArtifactName())) {
+ try (FileOutputStream outFile = new FileOutputStream(filePath)) {
LOGGER.info(MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF, "***WRITE FILE ARTIFACT NAME", "ASDC", artifact.getArtifactName());
outFile.write(payloadBytes, 0, payloadBytes.length);
outFile.close();
distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
Thread.sleep(watchDogTimeout / 10);
}catch(Exception e){
- LOGGER.debug ("Exception in Watchdog Loop " + e.getMessage());
+ LOGGER.debug ("Exception in Watchdog Loop " + e);
Thread.sleep(watchDogTimeout / 10);
}
LOGGER.debug ("A&AI Updated succefully with Distribution Status!");
}
catch(Exception e) {
- LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e.getMessage());
+ LOGGER.debug ("Exception in Watchdog executePatchAAI(): " + e);
watchdogError = "Error calling A&AI " + e.getMessage();
if(e.getCause() != null) {
LOGGER.debug ("Exception caused by: " + e.getCause().getMessage());
LOGGER.debug ("A&AI Updated succefully with Distribution Status of " + DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
}
catch(Exception aaiException) {
- LOGGER.debug ("Exception in executePatchAAI(): " + aaiException.getMessage());
+ LOGGER.debug ("Exception in executePatchAAI(): " + aaiException);
if(aaiException.getCause() != null) {
LOGGER.debug ("Exception caused by: " + aaiException.getCause().getMessage());
}
VfResourceStructure resourceStructure = null;
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
boolean deploySuccessful = true;
+ boolean hasVFResource = false;
String errorMessage = null;
try {
this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
-
- // Install a service with no resources, only the service itself
- if (iNotif.getResources() == null || iNotif.getResources().size() < 1) {
-
- LOGGER.debug("No resources found for Service: " + iNotif.getServiceUUID());
-
- try{
- resourceStructure = new VfResourceStructure(iNotif,new ResourceInstance());
-
- this.deployResourceStructure(resourceStructure, toscaResourceStructure);
-
- } catch(ArtifactInstallerException e){
- deploySuccessful = false;
- errorMessage = e.getMessage();
- }
- } else { // Services with resources
-
+ IArtifactInfo iArtifact = toscaResourceStructure.getToscaArtifact();
+ String filePath = System.getProperty("mso.config.path") + "/ASDC/" + iArtifact.getArtifactVersion() + "/" + iArtifact.getArtifactName();
+ File csarFile = new File(filePath);
+ String csarFilePath = csarFile.getAbsolutePath();
+ if (bpmnInstaller.containsWorkflows(csarFilePath)) {
+ bpmnInstaller.installBpmn(csarFilePath);
+ }
+
for (IResourceInstance resource : iNotif.getResources()){
resourceStructure = new VfResourceStructure(iNotif,resource);
LOGGER.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID());
if("VF".equals(resourceType) && !"Allotted Resource".equalsIgnoreCase(category)){
+
+ hasVFResource = true;
for (IArtifactInfo artifact : resource.getArtifacts()) {
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,
iNotif.getDistributionID());
if (resultArtifact != null) {
+
if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
LOGGER.debug("VF_MODULE_ARTIFACT: "+new String(resultArtifact.getArtifactPayload(),"UTF-8"));
LOGGER.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(resourceStructure.decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
resourceStructure.addArtifactToStructure(distributionClient,artifact, resultArtifact);
}
}
+
+ //Deploy VF resource and artifacts
+ LOGGER.debug("Preparing to deploy Service: " + iNotif.getServiceUUID());
+ try{
+
+ this.deployResourceStructure(resourceStructure, toscaResourceStructure);
+
+ } catch(ArtifactInstallerException e){
+ deploySuccessful = false;
+ errorMessage = e.getMessage();
+ LOGGER.error(e);
+ }
}
+
+ }
+
+ // There are cases where the Service has no VF resources, those are handled here
+ if (!hasVFResource) {
+
+ LOGGER.debug("No resources found for Service: " + iNotif.getServiceUUID());
- //Deploy All resources and artifacts
- LOGGER.debug("Preparing to deploy Service: " + iNotif.getServiceUUID());
- try{
-
+ try{
+ resourceStructure = new VfResourceStructure(iNotif,new ResourceInstance());
+
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
} catch(ArtifactInstallerException e){
deploySuccessful = false;
errorMessage = e.getMessage();
- }
-
- }
+ LOGGER.error(e);
+ }
}
this.sendCsarDeployNotification(iNotif, resourceStructure, toscaResourceStructure, deploySuccessful, errorMessage);
"Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processCsarServiceArtifacts", e);
}
}
+ else if(artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOWS)){
+
+ try{
+
+ IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact,iNotif.getDistributionID());
+
+ writeArtifactToFile(artifact, resultArtifact);
+
+ toscaResourceStructure.setToscaArtifact(artifact);
+
+ LOGGER.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
+
+
+ } catch(Exception e){
+ System.out.println("Whats the error " + e.getMessage());
+ LOGGER.error(MessageEnum.ASDC_GENERAL_EXCEPTION_ARG,
+ "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processCsarServiceArtifacts", e);
+ }
+ }
+
}
}