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());
}
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"));
}
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);
}
}
}
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);
}
}
}
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"));
}
Aggregations