Search in sources :

Example 1 with DistributionStatusEnum

use of org.onap.sdc.utils.DistributionStatusEnum 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);
    }
}
Also used : IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) DistributionStatusEnum(org.onap.sdc.utils.DistributionStatusEnum) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException)

Example 2 with DistributionStatusEnum

use of org.onap.sdc.utils.DistributionStatusEnum in project so by onap.

the class ASDCController method isCsarAlreadyDeployed.

protected boolean isCsarAlreadyDeployed(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
    VfResourceStructure resourceStructure = null;
    String errorMessage = "";
    boolean csarAlreadyDeployed = false;
    DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
    WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(iNotif.getDistributionID(), MSO);
    try {
        csarAlreadyDeployed = toscaInstaller.isCsarAlreadyDeployed(toscaResourceStructure);
        if (csarAlreadyDeployed) {
            deployStatus = DistributionStatusEnum.ALREADY_DEPLOYED;
            resourceStructure = new VfResourceStructure(iNotif, null);
            errorMessage = String.format("Csar with UUID: %s already exists", toscaResourceStructure.getToscaArtifact().getArtifactUUID());
            wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
            watchdogCDStatusRepository.saveAndFlush(wdStatus);
            logger.error(errorMessage);
        }
    } catch (ArtifactInstallerException e) {
        deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
        resourceStructure = new VfResourceStructure(iNotif, null);
        errorMessage = e.getMessage();
        wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
        watchdogCDStatusRepository.saveAndFlush(wdStatus);
        logger.warn("Tosca Checksums don't match, Tosca validation check failed", e);
    }
    if (deployStatus != DistributionStatusEnum.DEPLOY_OK) {
        notifyErrorToAsdc(iNotif, toscaResourceStructure, deployStatus, resourceStructure, errorMessage);
    }
    return csarAlreadyDeployed;
}
Also used : VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) DistributionStatusEnum(org.onap.sdc.utils.DistributionStatusEnum) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException)

Aggregations

DistributionStatusEnum (org.onap.sdc.utils.DistributionStatusEnum)2 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)2 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)1 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)1 IDistributionClientDownloadResult (org.onap.sdc.api.results.IDistributionClientDownloadResult)1 ASDCDownloadException (org.onap.so.asdc.client.exceptions.ASDCDownloadException)1 PnfResourceStructure (org.onap.so.asdc.installer.PnfResourceStructure)1 ResourceStructure (org.onap.so.asdc.installer.ResourceStructure)1 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)1 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)1