use of org.onap.aai.domain.yang.Relationship in project so by onap.
the class HeatBridgeImplTest method testCreateRelationships.
@Test
public void testCreateRelationships() throws HeatBridgeException, JsonProcessingException {
AaiHelper aaiHelper = new AaiHelper();
VfModule module = new VfModule();
RelationshipList relationships = new RelationshipList();
List<Relationship> listRelationships = relationships.getRelationship();
Relationship vnfcRelationship = new Relationship();
vnfcRelationship.setRelationshipLabel("org.onap.relationships.inventory.Uses");
vnfcRelationship.setRelatedTo("vnfc");
vnfcRelationship.setRelatedLink("/aai/v22/network/vnfcs/vnfc/test-server1-name");
listRelationships.add(vnfcRelationship);
module.setRelationshipList(relationships);
AAIResultWrapper wrapper = new AAIResultWrapper(new AAICommonObjectMapperProvider().getMapper().writeValueAsString(module));
when(aaiResourcesClient.get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("test-genericVnf-id").vfModule("test-vfModule-id")))).thenReturn(wrapper);
aaiHelper.setAAIResourcesClient(aaiResourcesClient);
// Arrange
Server server1 = mock(Server.class);
when(server1.getId()).thenReturn("test-server1-id");
when(server1.getHypervisorHostname()).thenReturn("test-hypervisor");
when(server1.getName()).thenReturn("test-server1-name");
when(server1.getStatus()).thenReturn(Status.ACTIVE);
when(server1.getLinks()).thenReturn(new ArrayList<>());
// HypervisorHostname is not set
Server server2 = mock(Server.class);
when(server2.getId()).thenReturn("test-server1-id");
when(server2.getName()).thenReturn("test-server1-name");
when(server2.getStatus()).thenReturn(Status.ACTIVE);
when(server2.getLinks()).thenReturn(new ArrayList<>());
// HypervisorHostname is empty string
Server server3 = mock(Server.class);
when(server3.getId()).thenReturn("test-server1-id");
when(server3.getHypervisorHostname()).thenReturn("");
when(server3.getName()).thenReturn("test-server1-name");
when(server3.getStatus()).thenReturn(Status.ACTIVE);
when(server3.getLinks()).thenReturn(new ArrayList<>());
org.onap.aai.domain.yang.RelationshipList relList = aaiHelper.getVserverRelationshipList(CLOUD_OWNER, REGION_ID, "test-genericVnf-id", "test-vfModule-id", server1);
assertEquals(3, relList.getRelationship().size());
org.onap.aai.domain.yang.RelationshipList relList2 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER, REGION_ID, "test-genericVnf-id", "test-vfModule-id", server2);
assertEquals(2, relList2.getRelationship().size());
org.onap.aai.domain.yang.RelationshipList relList3 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER, REGION_ID, "test-genericVnf-id", "test-vfModule-id", server3);
assertEquals(2, relList3.getRelationship().size());
}
use of org.onap.aai.domain.yang.Relationship in project so by onap.
the class AaiHelper method getVserverRelationshipList.
/**
* Build vserver relationship object to entities: pserver, vf-module, image, flavor
*
* @param cloudOwner AAI cloudOwner value
* @param cloudRegionId AAI cloud-region identifier
* @param genericVnfId AAI generic-vnf identifier
* @param vfModuleId AAI vf-module identifier
* @param server Openstack Server object
* @throws HeatBridgeException
*/
public RelationshipList getVserverRelationshipList(final String cloudOwner, final String cloudRegionId, final String genericVnfId, final String vfModuleId, final Server server) throws HeatBridgeException {
RelationshipList relationshipList = new RelationshipList();
List<Relationship> relationships = relationshipList.getRelationship();
// vserver to pserver relationship
if (!StringUtils.isEmpty(server.getHypervisorHostname())) {
Relationship pserverRelationship = buildRelationship(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(server.getHypervisorHostname())));
relationships.add(pserverRelationship);
}
// vserver to vnfc relationship
/*
* if (!StringUtils.isEmpty(server.getName())) {
* relationships.add(createVnfRelationshiptoVserver(server.getName(), genericVnfId, vfModuleId)); }
*/
// vserver to generic-vnf relationship
Relationship genericVnfRelationship = buildRelationship(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId)));
relationships.add(genericVnfRelationship);
// vserver to vf-module relationship
Relationship vfModuleRelationship = buildRelationship(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId)));
relationships.add(vfModuleRelationship);
// vserver to image relationship
if (server.getImage() != null) {
Relationship imageRel = buildRelationship(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).image(server.getImage().getId())));
relationships.add(imageRel);
}
// vserver to flavor relationship
if (server.getFlavor() != null) {
Relationship flavorRel = buildRelationship(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).flavor(server.getFlavor().getId())));
relationships.add(flavorRel);
}
return relationshipList;
}
use of org.onap.aai.domain.yang.Relationship in project so by onap.
the class AaiHelper method buildRelationship.
/**
* Build the relationship object
*
* @param relatedTo Related to entity value
* @param relationshipKeyValues Key value pairs of relationship data
* @return AAI Relationship object
*/
private Relationship buildRelationship(final AAIResourceUri relatedLink) {
Relationship relationship = new Relationship();
relationship.setRelatedLink(relatedLink.build().toString());
return relationship;
}
use of org.onap.aai.domain.yang.Relationship in project so by onap.
the class AaiHelper method createVnfRelationshiptoVserver.
public Relationship createVnfRelationshiptoVserver(String vserverName, String genericVnfId, String vfModuleId) throws HeatBridgeException {
AAIResourceUri vfModuleUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(genericVnfId).vfModule(vfModuleId));
AAIResultWrapper vfModule = resourcesClient.get(vfModuleUri);
if (vfModule.hasRelationshipsTo(Types.VNFC)) {
List<AAIResourceUri> vnfcUris = vfModule.getRelationships().get().getRelatedUris(Types.VNFC);
Optional<AAIResourceUri> foundVnfcURI = vnfcUris.stream().filter(resourceUri -> resourceUri.getURIKeys().get("vnfc-name").startsWith(vserverName)).findFirst();
if (!foundVnfcURI.isPresent()) {
throw new HeatBridgeException("Cannot Find VNFC to create edge to VServer");
} else {
return buildRelationship(foundVnfcURI.get());
}
} else {
throw new HeatBridgeException("VF Module contains no relationships to VNFCS, cannot build edge to VServer");
}
}
use of org.onap.aai.domain.yang.Relationship in project so by onap.
the class WorkflowActionTest method selectExecutionListVnfMacroReplaceTest.
@Test
public void selectExecutionListVnfMacroReplaceTest() throws Exception {
String gAction = "replaceInstance";
String resource = "Vnf";
String bpmnRequest = readBpmnRequestFromFile(MACRO_VNF_MACRO_REPLACE_JSON);
initExecution(gAction, bpmnRequest, false);
execution.setVariable("requestUri", "v7/serviceInstances/123/vnfs/1234/replace");
execution.setVariable("serviceInstanceId", "123");
execution.setVariable("vnfId", "1234");
NorthBoundRequest northBoundRequest = new NorthBoundRequest();
List<OrchestrationFlow> orchFlows = createFlowList("AAICheckVnfInMaintBB", "AAISetVnfInMaintBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVnfBB", "ChangeModelVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "AssignFabricConfigurationBB", "ActivateFabricConfigurationBB", "ChangeModelVnfBB", "ActivateVnfBB", "ChangeModelServiceInstanceBB", "SDNOVnfHealthCheckBB", "AAIUnsetVnfInMaintBB");
northBoundRequest.setOrchestrationFlowList(orchFlows);
ServiceInstance serviceInstanceAAI = new ServiceInstance();
serviceInstanceAAI.setServiceInstanceId("123");
org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstanceMSO = new org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance();
org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf vnf = new org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf();
vnf.setVnfId("1234");
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
vfModule.setVfModuleId("vfModule1");
vnf.getVfModules().add(vfModule);
org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule2 = new org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule();
vfModule2.setVfModuleId("vfModule2");
vnf.getVfModules().add(vfModule2);
serviceInstanceMSO.getVnfs().add(vnf);
VfModule vfModuleAAI1 = new VfModule();
vfModuleAAI1.setIsBaseVfModule(false);
VfModule vfModuleAAI2 = new VfModule();
vfModuleAAI2.setIsBaseVfModule(false);
vfModuleAAI2.setVfModuleId("vfModule2");
RelationshipList relationshipList = new RelationshipList();
Relationship relationship = new Relationship();
relationshipList.getRelationship().add(relationship);
vfModuleAAI2.setRelationshipList(relationshipList);
Relationships relationships = new Relationships("abc");
Configuration config = new Configuration();
config.setConfigurationId("configId");
Optional<Configuration> configOp = Optional.of(config);
Optional<Relationships> relationshipsOp = Optional.of(relationships);
doReturn(new org.onap.aai.domain.yang.GenericVnf()).when(bbSetupUtils).getAAIGenericVnf(vnf.getVnfId());
doReturn(relationshipsOp).when(workflowActionUtils).extractRelationshipsVnfc(isA(Relationships.class));
doReturn(configOp).when(workflowActionUtils).extractRelationshipsConfiguration(isA(Relationships.class));
doReturn(vfModuleAAI1).when(bbSetupUtils).getAAIVfModule("1234", "vfModule1");
doReturn(vfModuleAAI2).when(bbSetupUtils).getAAIVfModule("1234", "vfModule2");
doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById("123");
doReturn(serviceInstanceMSO).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI);
when(catalogDbClient.getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(gAction, resource, false, "cloud-owner")).thenReturn(northBoundRequest);
workflowAction.selectExecutionList(execution);
List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute");
assertEqualsBulkFlowName(ebbs, "AAICheckVnfInMaintBB", "AAISetVnfInMaintBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB", "DeactivateVfModuleBB", "DeleteVfModuleBB", "DeactivateVnfBB", "ChangeModelVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "ChangeModelVfModuleBB", "CreateVfModuleBB", "ActivateVfModuleBB", "AssignFabricConfigurationBB", "ActivateFabricConfigurationBB", "ChangeModelVnfBB", "ActivateVnfBB", "ChangeModelServiceInstanceBB", "SDNOVnfHealthCheckBB", "AAIUnsetVnfInMaintBB");
for (ExecuteBuildingBlock executeBuildingBlock : ebbs) {
assertEquals("123", executeBuildingBlock.getWorkflowResourceIds().getServiceInstanceId());
}
}
Aggregations