use of org.onap.so.asdc.client.exceptions.ASDCDownloadException in project so by onap.
the class ASDCController method downloadTheArtifact.
protected IDistributionClientDownloadResult downloadTheArtifact(IArtifactInfo artifact, String distributionId) throws ASDCDownloadException {
logger.info("Trying to download the artifact UUID: {} from URL: {}", artifact.getArtifactUUID(), artifact.getArtifactURL());
IDistributionClientDownloadResult downloadResult;
try {
downloadResult = distributionClient.download(artifact);
if (null == downloadResult) {
logger.info(LoggingAnchor.TWO, MessageEnum.ASDC_ARTIFACT_NULL.toString(), artifact.getArtifactUUID());
return downloadResult;
}
} catch (RuntimeException e) {
logger.debug("Not able to download the artifact due to an exception: " + artifact.getArtifactURL());
this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(), distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, e.getMessage(), System.currentTimeMillis());
throw new ASDCDownloadException("Exception caught when downloading the artifact", e);
}
if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) {
logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_DOWNLOAD_SUC.toString(), artifact.getArtifactURL(), artifact.getArtifactUUID(), downloadResult.getArtifactPayload().length);
} else {
logger.error(LoggingAnchor.SEVEN, MessageEnum.ASDC_ARTIFACT_DOWNLOAD_FAIL.toString(), artifact.getArtifactName(), artifact.getArtifactURL(), artifact.getArtifactUUID(), downloadResult.getDistributionMessageResult(), ErrorCode.DataError.getValue(), "ASDC artifact download fail");
this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(), distributionId, DistributionStatusEnum.DOWNLOAD_ERROR, downloadResult.getDistributionMessageResult(), System.currentTimeMillis());
throw new ASDCDownloadException("Artifact " + artifact.getArtifactName() + " could not be downloaded from ASDC URL " + artifact.getArtifactURL() + UUID_PARAM + artifact.getArtifactUUID() + ")" + System.lineSeparator() + "Error message is " + downloadResult.getDistributionMessageResult() + System.lineSeparator());
}
this.sendASDCNotification(NotificationType.DOWNLOAD, artifact.getArtifactURL(), asdcConfig.getConsumerID(), distributionId, DistributionStatusEnum.DOWNLOAD_OK, null, System.currentTimeMillis());
return downloadResult;
}
use of org.onap.so.asdc.client.exceptions.ASDCDownloadException in project so by onap.
the class ASDCController method processCsarServiceArtifacts.
protected void processCsarServiceArtifacts(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
for (IArtifactInfo artifact : serviceArtifacts) {
if (artifact.getArtifactType().equals(ASDCConfiguration.TOSCA_CSAR)) {
try {
toscaResourceStructure.setToscaArtifact(artifact);
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
writeArtifactToFile(artifact, resultArtifact);
toscaResourceStructure.updateResourceStructure(artifact);
toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
logger.debug(ASDCNotificationLogging.dumpCSARNotification(iNotif, toscaResourceStructure));
} catch (Exception e) {
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", ErrorCode.BusinessProcessError.getValue(), "Exception in processCsarServiceArtifacts", e);
}
} else if (artifact.getArtifactType().equals(ASDCConfiguration.WORKFLOW)) {
try {
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
writeArtifactToFile(artifact, resultArtifact);
toscaResourceStructure.setToscaArtifact(artifact);
logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
} catch (Exception e) {
logger.info("Whats the error {}", e.getMessage());
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", ErrorCode.BusinessProcessError.getValue(), "Exception in processCsarServiceArtifacts", e);
}
} else if (artifact.getArtifactType().equals(ASDCConfiguration.OTHER)) {
try {
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
writeArtifactToFile(artifact, resultArtifact);
toscaResourceStructure.setToscaArtifact(artifact);
toscaResourceStructure.setServiceVersion(iNotif.getServiceVersion());
} catch (ASDCDownloadException e) {
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during processCsarServiceArtifacts", "ASDC", "processCsarServiceArtifacts", ErrorCode.BusinessProcessError.getValue(), "Exception in processCsarServiceArtifacts", e);
}
}
}
}
use of org.onap.so.asdc.client.exceptions.ASDCDownloadException in project so by onap.
the class ToscaResourceStructure method updateResourceStructure.
public void updateResourceStructure(IArtifactInfo artifact) throws ASDCDownloadException {
try {
// Autoclosable
SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
String filePath = Paths.get(msoConfigPath, "ASDC", artifact.getArtifactVersion(), artifact.getArtifactName()).normalize().toString();
File spoolFile = new File(filePath);
logger.debug("ASDC File path is: {}", spoolFile.getAbsolutePath());
logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), "***PATH", "ASDC", spoolFile.getAbsolutePath());
sdcCsarHelper = factory.getSdcCsarHelper(spoolFile.getAbsolutePath(), false);
} catch (Exception e) {
logger.debug(e.getMessage(), e);
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during parser *****LOOK********* " + artifact.getArtifactName(), "ASDC", "processResourceNotification", ErrorCode.BusinessProcessError.getValue(), "Exception in " + "processResourceNotification", e);
throw new ASDCDownloadException("Exception caught when passing the csar file to the parser ", e);
}
serviceMetadata = sdcCsarHelper.getServiceMetadata();
}
use of org.onap.so.asdc.client.exceptions.ASDCDownloadException in project so by onap.
the class ASDCController method processResourceNotification.
protected void processResourceNotification(INotificationData iNotif) {
// For each artifact, create a structure describing the VFModule in a ordered flat level
ResourceStructure resourceStructure = null;
String msoConfigPath = getMsoConfigPath();
ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
String errorMessage = null;
boolean serviceDeployed = false;
try {
this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) {
return;
}
// process NsstResource
this.processNsstNotification(iNotif, toscaResourceStructure);
if (iNotif.getResources().isEmpty()) {
logger.error("Service Model contains no resources.");
return;
}
for (IResourceInstance resource : iNotif.getResources()) {
String resourceType = resource.getResourceType();
boolean hasVFResource = false;
logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID());
resourceStructure = getResourceStructure(iNotif, resource, resourceType);
try {
if (!this.checkResourceAlreadyDeployed(resourceStructure, serviceDeployed)) {
logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID());
if ("VF".equals(resourceType)) {
hasVFResource = true;
for (IArtifactInfo artifact : resource.getArtifacts()) {
IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
if (resultArtifact == null) {
continue;
}
if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
logger.debug("VF_MODULE_ARTIFACT: " + new String(resultArtifact.getArtifactPayload(), StandardCharsets.UTF_8));
logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure).decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
}
if (!ASDCConfiguration.WORKFLOW.equals(artifact.getArtifactType())) {
resourceStructure.addArtifactToStructure(distributionClient, artifact, resultArtifact);
} else {
writeArtifactToFile(artifact, resultArtifact);
logger.debug("Adding workflow artifact to structure: " + artifact.getArtifactName());
resourceStructure.addWorkflowArtifactToStructure(artifact, resultArtifact);
}
}
// Deploy VF resource and artifacts
logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
serviceDeployed = true;
}
}
} catch (ArtifactInstallerException e) {
deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
if (!hasVFResource) {
logger.debug("No resources found for Service: " + iNotif.getServiceUUID());
logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
try {
this.deployResourceStructure(resourceStructure, toscaResourceStructure);
serviceDeployed = true;
} catch (ArtifactInstallerException e) {
deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
errorMessage = e.getMessage();
logger.error("Exception occurred", e);
}
}
}
this.sendCsarDeployNotification(resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
} catch (ASDCDownloadException | UnsupportedEncodingException e) {
logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", ErrorCode.BusinessProcessError.getValue(), "Exception in processResourceNotification", e);
}
}
Aggregations