use of org.onap.sdc.api.notification.IArtifactInfo 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.sdc.api.notification.IArtifactInfo in project so by onap.
the class ASDCController method processNsstNotification.
private void processNsstNotification(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
try {
String category = serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
boolean isNeedInital = (category.contains("NSST") || category.equalsIgnoreCase("TN Network Requirement")) && iNotif.getResources().isEmpty();
if (isNeedInital) {
String artifactContent = null;
List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
Optional<IArtifactInfo> artifactOpt = serviceArtifacts.stream().filter(e -> e.getArtifactType().equalsIgnoreCase("WORKFLOW")).findFirst();
if (artifactOpt.isPresent()) {
IArtifactInfo artifactInfo = artifactOpt.get();
logger.debug("Ready to parse this serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
String filePath = Paths.get(getMsoConfigPath(), "ASDC", artifactInfo.getArtifactVersion(), artifactInfo.getArtifactName()).normalize().toString();
ZipParser zipParserInstance = ZipParser.getInstance();
artifactContent = zipParserInstance.parseJsonForZip(filePath);
logger.debug("serviceArtifact parsing success! serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
resourceStructure.setResourceType(ResourceType.OTHER);
toscaInstaller.installNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure, artifactContent);
} else {
logger.debug("serviceArtifact is null");
toscaInstaller.installNsstService(toscaResourceStructure, null, null);
}
}
} catch (IOException e) {
logger.error("serviceArtifact parse failure for service uuid: " + serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
} catch (Exception e) {
logger.error("error NSST process resource failure ", e);
}
}
use of org.onap.sdc.api.notification.IArtifactInfo in project so by onap.
the class ASDCController method sendCsarDeployNotification.
protected void sendCsarDeployNotification(ResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, DistributionStatusEnum statusEnum, String errorReason) {
IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact();
this.sendASDCNotification(NotificationType.DEPLOY, csarArtifact.getArtifactURL(), asdcConfig.getConsumerID(), resourceStructure.getNotification().getDistributionID(), statusEnum, errorReason, System.currentTimeMillis());
}
use of org.onap.sdc.api.notification.IArtifactInfo 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);
}
}
use of org.onap.sdc.api.notification.IArtifactInfo in project so by onap.
the class ToscaResourceInstaller method createServiceArtifact.
private void createServiceArtifact(Service service, VfResourceStructure vfResourceStruct, String artifactContent) {
if (null == vfResourceStruct) {
return;
}
List<ServiceArtifact> serviceArtifactList = new ArrayList<>();
ServiceArtifact serviceArtifact;
List<IArtifactInfo> artifactInfoList = vfResourceStruct.getNotification().getServiceArtifacts().stream().filter(artifact -> artifact.getArtifactType().equalsIgnoreCase("WORKFLOW")).collect(Collectors.toList());
for (IArtifactInfo artifactInfo : artifactInfoList) {
serviceArtifact = new ServiceArtifact();
serviceArtifact.setArtifactUUID(artifactInfo.getArtifactUUID());
serviceArtifact.setName(artifactInfo.getArtifactName());
serviceArtifact.setType("OTHER");
serviceArtifact.setVersion(artifactInfo.getArtifactVersion());
serviceArtifact.setDescription(artifactInfo.getArtifactDescription());
serviceArtifact.setChecksum(artifactInfo.getArtifactChecksum());
serviceArtifact.setContent(artifactContent);
serviceArtifact.setService(service);
serviceArtifactList.add(serviceArtifact);
}
service.setServiceArtifactList(serviceArtifactList);
}
Aggregations