Search in sources :

Example 1 with ASDCElementInfo

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

the class ASDCElementInfoTest method createASDCElementInfoWithNullParameterTest.

@Test
public void createASDCElementInfoWithNullParameterTest() {
    ASDCElementInfo elementInfoFromNullVfArtifact = ASDCElementInfo.createElementFromVfArtifactInfo(null);
    ASDCElementInfo elementInfoFromNullVfModuleStructure = ASDCElementInfo.createElementFromVfModuleStructure(null);
    ASDCElementInfo elementInfoFromNullVfResourceStructure = ASDCElementInfo.createElementFromVfResourceStructure(null);
    elementInfoFromNullVfArtifact.addElementInfo(null, null);
    elementInfoFromNullVfModuleStructure.addElementInfo(null, "someValue");
    elementInfoFromNullVfResourceStructure.addElementInfo("someKey", null);
    assertEquals(elementInfoFromNullVfArtifact.toString(), "");
    assertEquals(elementInfoFromNullVfModuleStructure.toString(), "");
    assertEquals(elementInfoFromNullVfResourceStructure.toString(), "");
    assertNotNull(elementInfoFromNullVfArtifact);
    assertNotNull(elementInfoFromNullVfModuleStructure);
    assertNotNull(elementInfoFromNullVfResourceStructure);
    assertNotNull(ASDCElementInfo.EMPTY_INSTANCE);
    assertEquals(elementInfoFromNullVfArtifact, ASDCElementInfo.EMPTY_INSTANCE);
    assertEquals(elementInfoFromNullVfModuleStructure, ASDCElementInfo.EMPTY_INSTANCE);
    assertEquals(elementInfoFromNullVfResourceStructure, ASDCElementInfo.EMPTY_INSTANCE);
    assertEquals(ASDCElementInfo.EMPTY_INSTANCE.getType(), "");
    assertEquals(ASDCElementInfo.EMPTY_INSTANCE.toString(), "");
    assertEquals(elementInfoFromNullVfArtifact.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
    assertEquals(elementInfoFromNullVfModuleStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
    assertEquals(elementInfoFromNullVfResourceStructure.getType(), ASDCElementInfo.EMPTY_INSTANCE.getType());
}
Also used : ASDCElementInfo(org.onap.so.asdc.installer.ASDCElementInfo) Test(org.junit.Test)

Example 2 with ASDCElementInfo

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

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

the class ToscaResourceInstaller method installTheVfResource.

@Transactional(rollbackFor = { ArtifactInstallerException.class })
public void installTheVfResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
    VfResourceStructure vfResourceStructure = vfResourceStruct;
    extractHeatInformation(toscaResourceStruct, vfResourceStructure);
    // PCLO: in case of deployment failure, use a string that will represent
    // the type of artifact that failed...
    List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
    try {
        createToscaCsar(toscaResourceStruct);
        createService(toscaResourceStruct, vfResourceStruct);
        Service service = toscaResourceStruct.getCatalogService();
        createServiceInfo(toscaResourceStruct, service);
        List<IEntityDetails> vfEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.VF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
        List<IEntityDetails> arEntityDetails = new ArrayList<IEntityDetails>();
        for (IEntityDetails vfEntityDetails : vfEntityList) {
            Metadata metadata = vfEntityDetails.getMetadata();
            String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
            if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) {
                arEntityDetails.add(vfEntityDetails);
            }
            processVfModules(vfEntityDetails, toscaResourceStruct, vfResourceStructure, service, metadata);
        }
        processResourceSequence(toscaResourceStruct, service);
        processAllottedResources(arEntityDetails, toscaResourceStruct, service);
        processNetworks(toscaResourceStruct, service);
        // process Network Collections
        processNetworkCollections(toscaResourceStruct, service);
        // Process Service Proxy & Configuration
        processServiceProxyAndConfiguration(toscaResourceStruct, service);
        logger.info("Saving Service: {} ", service.getModelName());
        service = serviceRepo.save(service);
        correlateConfigCustomResources(service);
        workflowResource.processWorkflows(vfResourceStructure);
        WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
        status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
        watchdogCDStatusRepository.save(status);
        toscaResourceStruct.setSuccessfulDeployment();
    } catch (Exception e) {
        logger.debug("Exception :", e);
        WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
        status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
        watchdogCDStatusRepository.save(status);
        Throwable dbExceptionToCapture = e;
        while (!(dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) && (dbExceptionToCapture.getCause() != null)) {
            dbExceptionToCapture = dbExceptionToCapture.getCause();
        }
        if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) {
            logger.warn(LoggingAnchor.FIVE, MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), vfResourceStructure.getResourceInstance().getResourceName(), vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), "Exception - ASCDC Artifact already deployed", e);
        } else {
            String elementToLog = (!artifactListForLogging.isEmpty() ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() : "No element listed");
            logger.error(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, ErrorCode.DataError.getValue(), "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback", e);
            throw new ArtifactInstallerException("Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
        }
    }
}
Also used : ASDCElementInfo(org.onap.so.asdc.installer.ASDCElementInfo) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ArrayList(java.util.ArrayList) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Service(org.onap.so.db.catalog.beans.Service) 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) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ASDCElementInfo

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

the class ToscaResourceInstaller method installPnfResource.

private void installPnfResource(ToscaResourceStructure toscaResourceStruct, PnfResourceStructure resourceStruct) throws ArtifactInstallerException {
    // PCLO: in case of deployment failure, use a string that will represent
    // the type of artifact that failed...
    List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
    try {
        createToscaCsar(toscaResourceStruct);
        Service service = createService(toscaResourceStruct, resourceStruct);
        processResourceSequence(toscaResourceStruct, service);
        processPnfResources(toscaResourceStruct, service, resourceStruct);
        serviceRepo.save(service);
        WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
        status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
        watchdogCDStatusRepository.save(status);
        toscaResourceStruct.setSuccessfulDeployment();
    } catch (Exception e) {
        logger.debug("Exception :", e);
        WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(resourceStruct.getNotification().getDistributionID(), MSO);
        status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
        watchdogCDStatusRepository.save(status);
        Throwable dbExceptionToCapture = e;
        while (!(dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) && (dbExceptionToCapture.getCause() != null)) {
            dbExceptionToCapture = dbExceptionToCapture.getCause();
        }
        if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) {
            logger.warn(LoggingAnchor.FIVE, MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), resourceStruct.getResourceInstance().getResourceName(), resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), "Exception - ASCDC Artifact already deployed", e);
        } else {
            String elementToLog = (!artifactListForLogging.isEmpty() ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() : "No element listed");
            logger.error(LoggingAnchor.FOUR, MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, ErrorCode.DataError.getValue(), "Exception caught during installation of " + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback", e);
            throw new ArtifactInstallerException("Exception caught during installation of " + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
        }
    }
}
Also used : ASDCElementInfo(org.onap.so.asdc.installer.ASDCElementInfo) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) 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) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException)

Example 5 with ASDCElementInfo

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

the class ASDCElementInfoTest method createASDCElementInfoFromVfResourceTest.

@Test
public void createASDCElementInfoFromVfResourceTest() {
    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);
    ASDCElementInfo elementInfoFromVfResource = ASDCElementInfo.createElementFromVfResourceStructure(vfResourceStructure);
    assertTrue(elementInfoFromVfResource.toString().contains(resourceInstanceName));
    assertTrue(elementInfoFromVfResource.toString().contains(generatedUUID.toString()));
    assertFalse(ASDCConfiguration.VF_MODULES_METADATA.equals(elementInfoFromVfResource.getType()));
    assertEquals(ASDCElementInfo.ASDCElementTypeEnum.VNF_RESOURCE.name(), elementInfoFromVfResource.getType());
    assertFalse(elementInfoFromVfResource.toString().contains("MyInfo1: someValue"));
    elementInfoFromVfResource.addElementInfo("MyInfo1", "someValue");
    assertTrue(elementInfoFromVfResource.toString().contains("MyInfo1: 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) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

ASDCElementInfo (org.onap.so.asdc.installer.ASDCElementInfo)6 Test (org.junit.Test)4 UUID (java.util.UUID)3 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ArrayList (java.util.ArrayList)2 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)2 INotificationData (org.onap.sdc.api.notification.INotificationData)2 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)2 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)2 Service (org.onap.so.db.catalog.beans.Service)2 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)2 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)2 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)1 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)1 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)1 IVfModuleData (org.onap.so.asdc.installer.IVfModuleData)1 VfModuleStructure (org.onap.so.asdc.installer.VfModuleStructure)1 Transactional (org.springframework.transaction.annotation.Transactional)1