Search in sources :

Example 1 with IDistributionClientDownloadResult

use of org.onap.sdc.api.results.IDistributionClientDownloadResult 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;
}
Also used : IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException)

Example 2 with IDistributionClientDownloadResult

use of org.onap.sdc.api.results.IDistributionClientDownloadResult 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);
            }
        }
    }
}
Also used : IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) ASDCParametersException(org.onap.so.asdc.client.exceptions.ASDCParametersException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException)

Example 3 with IDistributionClientDownloadResult

use of org.onap.sdc.api.results.IDistributionClientDownloadResult 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 4 with IDistributionClientDownloadResult

use of org.onap.sdc.api.results.IDistributionClientDownloadResult in project so by onap.

the class DistributionClientEmulatorTest method downloadSuccess.

@Test
public void downloadSuccess() throws IOException {
    ArtifactInfoImpl info = new ArtifactInfoImpl();
    info.setArtifactURL("mso.json");
    info.setArtifactName("testArtifactName");
    distClientEmulator.setResourcePath("src/test/resources/");
    IDistributionClientDownloadResult result = distClientEmulator.download(info);
    byte[] expectedInputStream = Files.readAllBytes(Paths.get(distClientEmulator.getResourcePath() + info.getArtifactURL()));
    IDistributionClientDownloadResult expectedResult = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, DistributionActionResultEnum.SUCCESS.name(), info.getArtifactName(), expectedInputStream);
    assertEquals(expectedResult.getDistributionActionResult(), result.getDistributionActionResult());
    assertEquals(expectedResult.getDistributionMessageResult(), result.getDistributionMessageResult());
}
Also used : IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) DistributionClientDownloadResultImpl(org.onap.sdc.impl.DistributionClientDownloadResultImpl) Test(org.junit.Test)

Aggregations

IDistributionClientDownloadResult (org.onap.sdc.api.results.IDistributionClientDownloadResult)4 ASDCDownloadException (org.onap.so.asdc.client.exceptions.ASDCDownloadException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)2 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 Test (org.junit.Test)1 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)1 DistributionClientDownloadResultImpl (org.onap.sdc.impl.DistributionClientDownloadResultImpl)1 DistributionStatusEnum (org.onap.sdc.utils.DistributionStatusEnum)1 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)1 ASDCParametersException (org.onap.so.asdc.client.exceptions.ASDCParametersException)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 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)1 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)1