Search in sources :

Example 1 with ArtifactInstallerException

use of org.onap.so.asdc.client.exceptions.ArtifactInstallerException in project so by onap.

the class ToscaResourceInstaller method isResourceAlreadyDeployed.

public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) throws ArtifactInstallerException {
    boolean status = false;
    ResourceStructure vfResourceStructure = vfResourceStruct;
    try {
        status = vfResourceStructure.isDeployedSuccessfully();
    } catch (RuntimeException e) {
        status = false;
        logger.debug("Exception :", e);
    }
    try {
        Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
        if (existingService != null && !serviceDeployed)
            status = true;
        if (status) {
            logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
            WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
            wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
            watchdogCDStatusRepository.saveAndFlush(wdStatus);
        } else {
            logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
        }
        return status;
    } catch (Exception e) {
        logger.error(LoggingAnchor.THREE, MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed");
        throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
    }
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) Service(org.onap.so.db.catalog.beans.Service) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with ArtifactInstallerException

use of org.onap.so.asdc.client.exceptions.ArtifactInstallerException in project so by onap.

the class ToscaResourceInstaller method installTheComponentStatus.

public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
    logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}", iStatus.getDistributionID(), iStatus.getComponentName());
    try {
        WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(), iStatus.getComponentName());
        cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
        watchdogCDStatusRepository.save(cdStatus);
    } catch (Exception e) {
        logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
        throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
    }
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with ArtifactInstallerException

use of org.onap.so.asdc.client.exceptions.ArtifactInstallerException in project so by onap.

the class ToscaResourceInstaller method isCsarAlreadyDeployed.

public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
    boolean deployed = false;
    if (toscaResourceStructure == null) {
        return deployed;
    }
    IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
    String checkSum = inputToscaCsar.getArtifactChecksum();
    String artifactUuid = inputToscaCsar.getArtifactUUID();
    Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
    if (toscaCsarObj.isPresent()) {
        ToscaCsar toscaCsar = toscaCsarObj.get();
        if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
            String errorMessage = String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
            throw new ArtifactInstallerException(errorMessage);
        } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
            deployed = true;
        }
    }
    return deployed;
}
Also used : IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar)

Example 4 with ArtifactInstallerException

use of org.onap.so.asdc.client.exceptions.ArtifactInstallerException in project so by onap.

the class ASDCStatusCallBack method activateCallback.

@Override
public void activateCallback(IStatusData iStatus) {
    String event = "Receive a callback componentStatus in ASDC, for componentName: " + iStatus.getComponentName() + " and status of " + iStatus.getStatus() + " distributionID of " + iStatus.getDistributionID();
    try {
        if (iStatus.getStatus() == null) {
            logger.info("Missing status on Status Object. ");
            return;
        }
        if (!iStatus.getStatus().equals(DistributionStatusEnum.COMPONENT_DONE_OK) && !iStatus.getStatus().equals(DistributionStatusEnum.COMPONENT_DONE_ERROR)) {
            logger.info("Status is not 'Component Done OK' or 'Component Done Error'");
            return;
        }
        WatchdogDistributionStatus watchdogDistributionStatus = watchdogDistributionStatusRepository.findById(iStatus.getDistributionID()).orElseGet(() -> null);
        if (watchdogDistributionStatus == null) {
            watchdogDistributionStatus = new WatchdogDistributionStatus();
            watchdogDistributionStatus.setDistributionId(iStatus.getDistributionID());
            watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
        }
        logger.debug(event);
        toscaInstaller.installTheComponentStatus(iStatus);
    } catch (ArtifactInstallerException e) {
        logger.error("Error in ASDCStatusCallback {}", e.getMessage(), e);
        logger.debug("Error in ASDCStatusCallback {}", e.getMessage());
    }
}
Also used : WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException)

Example 5 with ArtifactInstallerException

use of org.onap.so.asdc.client.exceptions.ArtifactInstallerException 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)

Aggregations

ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)10 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)5 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)5 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)5 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)5 Service (org.onap.so.db.catalog.beans.Service)4 ArrayList (java.util.ArrayList)3 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)3 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)3 DistributionStatusEnum (org.onap.sdc.utils.DistributionStatusEnum)3 ASDCElementInfo (org.onap.so.asdc.installer.ASDCElementInfo)3 PnfResourceStructure (org.onap.so.asdc.installer.PnfResourceStructure)3 ResourceStructure (org.onap.so.asdc.installer.ResourceStructure)3 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)3 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)2 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)2 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)2 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)2