Search in sources :

Example 1 with VfResourceStructure

use of org.onap.so.asdc.installer.VfResourceStructure 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 VfResourceStructure

use of org.onap.so.asdc.installer.VfResourceStructure in project so by onap.

the class ASDCElementInfoTest method createASDCElementInfoFromVfModuleTest.

@Test
public void createASDCElementInfoFromVfModuleTest() throws ArtifactInstallerException {
    String resourceInstanceName = "Resource 1";
    UUID generatedUUID = UUID.randomUUID();
    INotificationData notificationData = Mockito.mock(INotificationData.class);
    IResourceInstance resourceInstance = Mockito.mock(IResourceInstance.class);
    Mockito.when(resourceInstance.getResourceInstanceName()).thenReturn(resourceInstanceName);
    Mockito.when(resourceInstance.getResourceInvariantUUID()).thenReturn(generatedUUID.toString());
    VfResourceStructure vfResourceStructure = new VfResourceStructure(notificationData, resourceInstance);
    // Create module structure now
    String vfModuleModelName = "Module Model XYZ";
    UUID generatedUUIDForModule = UUID.randomUUID();
    IVfModuleData moduleMetadata = Mockito.mock(IVfModuleData.class);
    Mockito.when(moduleMetadata.getVfModuleModelName()).thenReturn(vfModuleModelName);
    Mockito.when(moduleMetadata.getVfModuleModelInvariantUUID()).thenReturn(generatedUUIDForModule.toString());
    Mockito.when(moduleMetadata.getArtifacts()).thenReturn(Collections.<String>emptyList());
    VfModuleStructure vfModuleStructure = new VfModuleStructure(vfResourceStructure, moduleMetadata);
    ASDCElementInfo elementInfoFromVfModule = ASDCElementInfo.createElementFromVfModuleStructure(vfModuleStructure);
    assertTrue(elementInfoFromVfModule.toString().contains(vfModuleModelName));
    assertTrue(elementInfoFromVfModule.toString().contains(generatedUUIDForModule.toString()));
    assertFalse(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name().equals(elementInfoFromVfModule.getType()));
    assertEquals(ASDCConfiguration.VF_MODULES_METADATA, elementInfoFromVfModule.getType());
    assertFalse(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
    elementInfoFromVfModule.addElementInfo("MyInfo2", "someValue");
    assertTrue(elementInfoFromVfModule.toString().contains("MyInfo2: someValue"));
}
Also used : VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ASDCElementInfo(org.onap.so.asdc.installer.ASDCElementInfo) INotificationData(org.onap.sdc.api.notification.INotificationData) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) IVfModuleData(org.onap.so.asdc.installer.IVfModuleData) UUID(java.util.UUID) VfModuleStructure(org.onap.so.asdc.installer.VfModuleStructure) Test(org.junit.Test)

Example 3 with VfResourceStructure

use of org.onap.so.asdc.installer.VfResourceStructure 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);
    }
}
Also used : ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) ONAPLogConstants(org.onap.logging.ref.slf4j.ONAPLogConstants) IFinalDistrStatusMessage(org.onap.sdc.api.consumer.IFinalDistrStatusMessage) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) INotificationData(org.onap.sdc.api.notification.INotificationData) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) WatchdogComponentDistributionStatusRepository(org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ResourceType(org.onap.so.asdc.installer.ResourceType) ASDCNotificationLogging(org.onap.so.asdc.util.ASDCNotificationLogging) MessageEnum(org.onap.so.logger.MessageEnum) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) WatchdogDistribution(org.onap.so.asdc.tenantIsolation.WatchdogDistribution) IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) ASDCParametersException(org.onap.so.asdc.client.exceptions.ASDCParametersException) DistributionStatus(org.onap.so.asdc.tenantIsolation.DistributionStatus) StandardCharsets(java.nio.charset.StandardCharsets) IDistributionClient(org.onap.sdc.api.IDistributionClient) List(java.util.List) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) DistributionActionResultEnum(org.onap.sdc.utils.DistributionActionResultEnum) Optional(java.util.Optional) LoggingAnchor(org.onap.so.logger.LoggingAnchor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WatchdogDistributionStatusRepository(org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository) ZipParser(org.onap.so.asdc.util.ZipParser) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) ErrorCode(org.onap.logging.filter.base.ErrorCode) IDistributionStatusMessage(org.onap.sdc.api.consumer.IDistributionStatusMessage) IDistributionClientResult(org.onap.sdc.api.results.IDistributionClientResult) DistributionStatusEnum(org.onap.sdc.utils.DistributionStatusEnum) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileOutputStream(java.io.FileOutputStream) IVfResourceInstaller(org.onap.so.asdc.installer.IVfResourceInstaller) Include(com.fasterxml.jackson.annotation.JsonInclude.Include) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) File(java.io.File) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) ToscaResourceInstaller(org.onap.so.asdc.installer.heat.ToscaResourceInstaller) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) Component(org.springframework.stereotype.Component) Paths(java.nio.file.Paths) MDC(org.slf4j.MDC) SdcPropertyNames(org.onap.sdc.tosca.parser.impl.SdcPropertyNames) DeployActivitySpecs(org.onap.so.asdc.activity.DeployActivitySpecs) DistributionClientFactory(org.onap.sdc.impl.DistributionClientFactory) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) IOException(java.io.IOException) 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) 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) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ZipParser(org.onap.so.asdc.util.ZipParser) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance)

Example 4 with VfResourceStructure

use of org.onap.so.asdc.installer.VfResourceStructure in project so by onap.

the class ASDCController method getResourceStructure.

private ResourceStructure getResourceStructure(INotificationData iNotif, IResourceInstance resource, String resourceType) {
    if ("VF".equals(resourceType)) {
        return new VfResourceStructure(iNotif, resource);
    }
    if ("PNF".equals(resourceType)) {
        return new PnfResourceStructure(iNotif, resource);
    }
    logger.info("No resources found for Service: {}", iNotif.getServiceUUID());
    ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
    resourceStructure.setResourceType(ResourceType.OTHER);
    return resourceStructure;
}
Also used : VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) 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)

Example 5 with VfResourceStructure

use of org.onap.so.asdc.installer.VfResourceStructure in project so by onap.

the class ASDCController method notifyErrorToAsdc.

protected void notifyErrorToAsdc(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure, DistributionStatusEnum deployStatus, VfResourceStructure resourceStructure, String errorMessage) {
    // do csar lever first
    this.sendCsarDeployNotification(resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
    // at resource level
    for (IResourceInstance resource : iNotif.getResources()) {
        resourceStructure = new VfResourceStructure(iNotif, resource);
        errorMessage = String.format("Resource with UUID: %s already exists", resource.getResourceUUID());
        this.sendCsarDeployNotification(resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
    }
}
Also used : VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance)

Aggregations

VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)12 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)9 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)8 PnfResourceStructure (org.onap.so.asdc.installer.PnfResourceStructure)7 ResourceStructure (org.onap.so.asdc.installer.ResourceStructure)7 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)7 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 DistributionStatusEnum (org.onap.sdc.utils.DistributionStatusEnum)6 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)6 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)5 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)5 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)5 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)5 ASDCElementInfo (org.onap.so.asdc.installer.ASDCElementInfo)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 ErrorCode (org.onap.logging.filter.base.ErrorCode)4