Search in sources :

Example 16 with Relationship

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());
}
Also used : RelationshipList(org.onap.aai.domain.yang.RelationshipList) Server(org.openstack4j.model.compute.Server) AaiHelper(org.onap.so.heatbridge.helpers.AaiHelper) VfModule(org.onap.aai.domain.yang.VfModule) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) RelationshipList(org.onap.aai.domain.yang.RelationshipList) Relationship(org.onap.aai.domain.yang.Relationship) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 17 with Relationship

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;
}
Also used : RelationshipList(org.onap.aai.domain.yang.RelationshipList) Relationship(org.onap.aai.domain.yang.Relationship)

Example 18 with Relationship

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;
}
Also used : Relationship(org.onap.aai.domain.yang.Relationship)

Example 19 with 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");
    }
}
Also used : AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) Network(org.openstack4j.model.network.Network) Relationship(org.onap.aai.domain.yang.Relationship) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) Server(org.openstack4j.model.compute.Server) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) HeatBridgeConstants(org.onap.so.heatbridge.constants.HeatBridgeConstants) Pserver(org.onap.aai.domain.yang.Pserver) L3Network(org.onap.aai.domain.yang.L3Network) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Port(org.openstack4j.model.network.Port) RelationshipData(org.onap.aai.domain.yang.RelationshipData) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Logger(org.slf4j.Logger) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) Collection(java.util.Collection) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) HeatBridgeException(org.onap.so.heatbridge.HeatBridgeException) Subnet(org.openstack4j.model.network.Subnet) Collectors(java.util.stream.Collectors) List(java.util.List) Vserver(org.onap.aai.domain.yang.Vserver) Optional(java.util.Optional) Flavor(org.onap.aai.domain.yang.Flavor) PInterface(org.onap.aai.domain.yang.PInterface) Preconditions(com.google.common.base.Preconditions) SriovVf(org.onap.aai.domain.yang.SriovVf) Image(org.onap.aai.domain.yang.Image) HeatBridgeException(org.onap.so.heatbridge.HeatBridgeException) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 20 with Relationship

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());
    }
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) Configuration(org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) ServiceInstance(org.onap.aai.domain.yang.ServiceInstance) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) VfModule(org.onap.aai.domain.yang.VfModule) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) GenericVnf(org.onap.aai.domain.yang.GenericVnf) RelationshipList(org.onap.aai.domain.yang.RelationshipList) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) Relationship(org.onap.aai.domain.yang.Relationship) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Aggregations

Relationship (org.onap.aai.domain.yang.Relationship)28 Test (org.junit.Test)11 RelationshipList (org.onap.aai.domain.yang.RelationshipList)11 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)6 VfModule (org.onap.aai.domain.yang.VfModule)5 ArrayList (java.util.ArrayList)4 GenericVnf (org.onap.aai.domain.yang.GenericVnf)4 RelationshipData (org.onap.aai.domain.yang.RelationshipData)4 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)4 Server (org.openstack4j.model.compute.Server)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ServiceInstance (org.onap.aai.domain.yang.ServiceInstance)3 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)3 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)3 Resource (org.onap.so.bpmn.infrastructure.workflow.tasks.Resource)3 Configuration (org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 IOException (java.io.IOException)2 List (java.util.List)2