use of org.onap.sdc.api.notification.IResourceInstance 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.sdc.api.notification.IResourceInstance in project so by onap.
the class ToscaResourceInstallerTest method prepareToscaResourceStructure.
private ToscaResourceStructure prepareToscaResourceStructure(boolean prepareVFModuleStructures, ToscaResourceInstaller toscaInstaller) throws ArtifactInstallerException {
Metadata metadata = mock(Metadata.class);
IResourceInstance resourceInstance = mock(ResourceInstance.class);
NodeTemplate nodeTemplate = mock(NodeTemplate.class);
ISdcCsarHelper csarHelper = mock(SdcCsarHelperImpl.class);
IArtifactInfo inputCsar = mock(IArtifactInfo.class);
String artifactUuid = "0122c05e-e13a-4c63-b5d2-475ccf23aa74";
String checkSum = "MGUzNjJjMzk3OTBkYzExYzQ0MDg2ZDc2M2E3ZjZiZmY=";
doReturn(checkSum).when(inputCsar).getArtifactChecksum();
doReturn(artifactUuid).when(inputCsar).getArtifactUUID();
doReturn("1.0").when(inputCsar).getArtifactVersion();
doReturn("TestCsarWithGroupAndVFModule").when(inputCsar).getArtifactName();
doReturn("Test Csar data with Group and VF module inputs").when(inputCsar).getArtifactDescription();
doReturn("http://localhost/dummy/url/test.csar").when(inputCsar).getArtifactURL();
ToscaResourceStructure toscaResourceStructObj = new ToscaResourceStructure();
toscaResourceStructObj.setToscaArtifact(inputCsar);
ToscaCsarRepository toscaCsarRepo = spy(ToscaCsarRepository.class);
ToscaCsar toscaCsar = mock(ToscaCsar.class);
Optional<ToscaCsar> returnValue = Optional.of(toscaCsar);
doReturn(artifactUuid).when(toscaCsar).getArtifactUUID();
doReturn(checkSum).when(toscaCsar).getArtifactChecksum();
doReturn(returnValue).when(toscaCsarRepo).findById(artifactUuid);
ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo);
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setDistributionID("testStatusSuccessfulTosca");
notificationData.setServiceVersion("1234567");
notificationData.setServiceUUID("serviceUUID1");
notificationData.setWorkloadContext("workloadContext1");
String serviceType = "test-type1";
String serviceRole = "test-role1";
String category = "Network L3+";
String description = "Customer Orderable service description";
String name = "Customer_Orderable_Service";
String uuid = "72db5868-4575-4804-b546-0b0d3c3b5ac6";
String invariantUUID = "6f30bbe3-4590-4185-a7e0-4f9610926c6f";
String namingPolicy = "naming Policy1";
String ecompGeneratedNaming = "true";
String environmentContext = "General_Revenue-Bearing1";
String resourceCustomizationUUID = "0177ba22-5547-4e4e-bcf8-178f7f71de3a";
doReturn(serviceType).when(metadata).getValue("serviceType");
doReturn(serviceRole).when(metadata).getValue("serviceRole");
doReturn(category).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
doReturn(description).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION);
doReturn("1.0").when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VERSION);
doReturn(name).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
doReturn(environmentContext).when(metadata).getValue(metadata.getValue("environmentContext"));
doReturn(invariantUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
doReturn(namingPolicy).when(metadata).getValue("namingPolicy");
doReturn(ecompGeneratedNaming).when(metadata).getValue("ecompGeneratedNaming");
doReturn(resourceCustomizationUUID).when(metadata).getValue("vfModuleModelCustomizationUUID");
ServiceRepository serviceRepo = spy(ServiceRepository.class);
VnfResourceRepository vnfRepo = spy(VnfResourceRepository.class);
doReturn(null).when(vnfRepo).findResourceByModelUUID(uuid);
VFModuleRepository vfModuleRepo = spy(VFModuleRepository.class);
InstanceGroupRepository instanceGroupRepo = spy(InstanceGroupRepository.class);
WorkflowResource workflowResource = spy(WorkflowResource.class);
ReflectionTestUtils.setField(toscaInstaller, "serviceRepo", serviceRepo);
ReflectionTestUtils.setField(toscaInstaller, "vnfRepo", vnfRepo);
ReflectionTestUtils.setField(toscaInstaller, "vfModuleRepo", vfModuleRepo);
ReflectionTestUtils.setField(toscaInstaller, "instanceGroupRepo", instanceGroupRepo);
ReflectionTestUtils.setField(toscaInstaller, "workflowResource", workflowResource);
// doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper();
toscaResourceStructObj.setSdcCsarHelper(csarHelper);
doReturn(resourceCustomizationUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID);
// vnfc instance group list
List<Group> vnfcInstanceGroupList = new ArrayList<>();
Group vnfcG1 = mock(Group.class);
Map<String, Object> metaProperties = new HashMap<>();
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_UUID, "vnfc_group1_uuid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_NAME, "vnfc_group1_uuid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID, "vnfc_group1_invariantid");
metaProperties.put(SdcPropertyNames.PROPERTY_NAME_VERSION, "1.0");
Metadata vnfcmetadata = new Metadata(metaProperties);
doReturn(vnfcmetadata).when(vnfcG1).getMetadata();
ArrayList<NodeTemplate> memberList = new ArrayList();
doReturn(memberList).when(vnfcG1).getMemberNodes();
vnfcInstanceGroupList.add(vnfcG1);
SubstitutionMappings submappings = mock(SubstitutionMappings.class);
doReturn(new ArrayList<Input>()).when(submappings).getInputs();
doReturn(submappings).when(nodeTemplate).getSubMappingToscaTemplate();
doReturn(notificationData).when(vfResourceStruct).getNotification();
doReturn(resourceInstance).when(vfResourceStruct).getResourceInstance();
if (prepareVFModuleStructures) {
// VfModule list
List<Group> vfModuleGroups = new ArrayList<>();
Group g1 = mock(Group.class);
doReturn(metadata).when(g1).getMetadata();
vfModuleGroups.add(g1);
doReturn(metadata).when(nodeTemplate).getMetaData();
List<NodeTemplate> nodeList = new ArrayList<>();
nodeList.add(nodeTemplate);
IVfModuleData moduleMetadata = mock(IVfModuleData.class);
doReturn(name).when(moduleMetadata).getVfModuleModelName();
doReturn(invariantUUID).when(moduleMetadata).getVfModuleModelInvariantUUID();
doReturn(Collections.<String>emptyList()).when(moduleMetadata).getArtifacts();
doReturn(resourceCustomizationUUID).when(moduleMetadata).getVfModuleModelCustomizationUUID();
doReturn(uuid).when(moduleMetadata).getVfModuleModelUUID();
doReturn("1.0").when(moduleMetadata).getVfModuleModelVersion();
VfModuleStructure moduleStructure = new VfModuleStructure(vfResourceStruct, moduleMetadata);
List<VfModuleStructure> moduleStructures = new ArrayList<>();
moduleStructures.add(moduleStructure);
doReturn(moduleStructures).when(vfResourceStruct).getVfModuleStructure();
}
toscaResourceStructObj.setServiceMetadata(metadata);
doReturn("resourceInstanceName1").when(resourceInstance).getResourceInstanceName();
doReturn(resourceCustomizationUUID).when(resourceInstance).getResourceCustomizationUUID();
doReturn("resourceName1").when(resourceInstance).getResourceName();
Service service = toscaInstaller.createService(toscaResourceStructObj, vfResourceStruct);
assertNotNull(service);
service.setModelVersion("1.0");
doReturn(service).when(serviceRepo).save(service);
WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository = spy(WatchdogComponentDistributionStatusRepository.class);
ReflectionTestUtils.setField(toscaInstaller, "watchdogCDStatusRepository", watchdogCDStatusRepository);
doReturn(null).when(watchdogCDStatusRepository).save(any(WatchdogComponentDistributionStatus.class));
VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo = spy(VnfcInstanceGroupCustomizationRepository.class);
ReflectionTestUtils.setField(toscaInstaller, "vnfcInstanceGroupCustomizationRepo", vnfcInstanceGroupCustomizationRepo);
doReturn(null).when(vnfcInstanceGroupCustomizationRepo).save(any(VnfcInstanceGroupCustomization.class));
return toscaResourceStructObj;
}
use of org.onap.sdc.api.notification.IResourceInstance 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;
}
use of org.onap.sdc.api.notification.IResourceInstance in project so by onap.
the class ASDCController method treatNotification.
public void treatNotification(INotificationData iNotif) {
int noOfArtifacts = 0;
for (IResourceInstance resource : iNotif.getResources()) {
noOfArtifacts += resource.getArtifacts().size();
}
logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_CALLBACK_NOTIF.toString(), noOfArtifacts, iNotif.getServiceUUID(), "ASDC");
try {
if (iNotif.getDistributionID() != null && !iNotif.getDistributionID().isEmpty()) {
MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, iNotif.getDistributionID());
}
logger.debug(ASDCNotificationLogging.dumpASDCNotification(iNotif));
logger.info(LoggingAnchor.FOUR, MessageEnum.ASDC_RECEIVE_SERVICE_NOTIF.toString(), iNotif.getServiceUUID(), "ASDC", "treatNotification");
this.changeControllerStatus(ASDCControllerStatus.BUSY);
Optional<String> notificationMessage = getNotificationJson(iNotif);
toscaInstaller.processWatchdog(iNotif.getDistributionID(), iNotif.getServiceUUID(), notificationMessage, asdcConfig.getConsumerID());
// Process only the Resource artifacts in MSO
this.processResourceNotification(iNotif);
// ********************************************************************************************************
// Start Watchdog loop and wait for all components to complete before reporting final status back.
// **If timer expires first then we will report a Distribution Error back to ASDC
// ********************************************************************************************************
long initialStartTime = System.currentTimeMillis();
boolean componentsComplete = false;
String distributionStatus = null;
String watchdogError = null;
String overallStatus = null;
int watchDogTimeout = asdcConfig.getWatchDogTimeout() * 1000;
boolean isDeploySuccess = false;
while (!componentsComplete && (System.currentTimeMillis() - initialStartTime) < watchDogTimeout) {
try {
distributionStatus = wd.getOverallDistributionStatus(iNotif.getDistributionID());
Thread.sleep(watchDogTimeout / 10);
} catch (Exception e) {
logger.debug("Exception in Watchdog Loop {}", e.getMessage());
Thread.sleep(watchDogTimeout / 10);
}
if (distributionStatus != null && !distributionStatus.equalsIgnoreCase(DistributionStatus.INCOMPLETE.name())) {
if (distributionStatus.equalsIgnoreCase(DistributionStatus.SUCCESS.name())) {
isDeploySuccess = true;
overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.name();
} else {
overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
}
componentsComplete = true;
}
}
if (!componentsComplete) {
logger.debug("Timeout of {} seconds was reached before all components reported status", watchDogTimeout);
watchdogError = "Timeout occurred while waiting for all components to report status";
overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
}
if (distributionStatus == null) {
overallStatus = DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name();
logger.debug("DistributionStatus is null for DistributionId: {}", iNotif.getDistributionID());
}
try {
wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), overallStatus);
logger.debug("A&AI Updated succefully with Distribution Status!");
} catch (Exception e) {
logger.debug("Exception in Watchdog executePatchAAI(): {}", e.getMessage());
watchdogError = "Error calling A&AI " + e.getMessage();
if (e.getCause() != null) {
logger.debug("Exception caused by: {}", e.getCause().getMessage());
}
}
wd.updateCatalogDBStatus(iNotif.getServiceInvariantUUID(), overallStatus);
if (isDeploySuccess && watchdogError == null) {
sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK, null);
WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_OK.toString());
wdsRepo.save(wds);
} else {
sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, watchdogError);
WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
wdsRepo.save(wds);
}
} catch (ObjectOptimisticLockingFailureException e) {
logger.debug("OptimisticLockingFailure for DistributionId: {} Another process " + "has already altered this distribution, so not going to process it on this site.", iNotif.getDistributionID());
logger.error(LoggingAnchor.FIVE, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Database concurrency exception: ", "ASDC", "treatNotification", ErrorCode.BusinessProcessError.getValue(), "RuntimeException in treatNotification", e);
} catch (Exception e) {
logger.error("", MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Unexpected exception caught during the notification processing", "ASDC", "treatNotification", ErrorCode.SchemaError.getValue(), "RuntimeException in treatNotification", e);
try {
wd.executePatchAAI(iNotif.getDistributionID(), iNotif.getServiceInvariantUUID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
logger.debug("A&AI Updated succefully with Distribution Status of {}", DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.name());
} catch (Exception aaiException) {
logger.debug("Exception in executePatchAAI(): {}", aaiException);
if (aaiException.getCause() != null) {
logger.debug("Exception caused by: {}", aaiException.getCause().getMessage());
}
}
sendFinalDistributionStatus(iNotif.getDistributionID(), DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR, e.getMessage());
WatchdogDistributionStatus wds = new WatchdogDistributionStatus(iNotif.getDistributionID());
wds.setDistributionIdStatus(DistributionStatusEnum.DISTRIBUTION_COMPLETE_ERROR.toString());
wdsRepo.save(wds);
} finally {
this.changeControllerStatus(ASDCControllerStatus.IDLE);
}
}
use of org.onap.sdc.api.notification.IResourceInstance 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);
}
}
Aggregations