Search in sources :

Example 1 with Pathed

use of org.onap.aaiclient.client.graphinventory.entities.Pathed in project so by onap.

the class HeatBridgeImpl method updateSriovPfToSriovVF.

/**
 * Needs to be corrected according to the specification that is in draft If pserver/p-interface does not have a
 * SRIOV-PF object matching the PCI-ID of the Openstack port object, then create it in AAI. Openstack SRIOV Port
 * object has pci-id (to match sriov-pf on pserver/p-interface), physical-network ID (that matches the p-interface
 * name).
 *
 * @param port Openstack port object
 * @param lIf AAI l-interface object
 * @throws HeatBridgeException
 */
protected void updateSriovPfToSriovVF(final Port port, final LInterface lIf) throws HeatBridgeException {
    if (port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) {
        AAIResourceUri sriovVfUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).sriovVf(port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString()));
        boolean relationshipExist = sriovVfHasSriovPfRelationship(sriovVfUri);
        Server server = getOpenstackServerById(port.getDeviceId());
        String pserverHostName = server.getHypervisorHostname();
        lIf.setInterfaceDescription("Attached to SR-IOV port: " + pserverHostName);
        if (!relationshipExist) {
            AAIResourceUri pserverUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverHostName));
            if (resourcesClient.exists(pserverUri)) {
                String pfPciId = port.getProfile().get(HeatBridgeConstants.OS_PF_PCI_SLOT_KEY).toString();
                DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(new DSLStartNode(Types.PSERVER, __.key("hostname", pserverHostName))).to(__.node(Types.P_INTERFACE).to(__.node(Types.SRIOV_PF, __.key("pf-pci-id", pfPciId)).output()));
                List<Pathed> results = getAAIDSLClient().queryPathed(new DSLQuery(builder.build()));
                if (results.size() == 1) {
                    AAIResourceUri sriovPfUri = AAIUriFactory.createResourceFromExistingURI(Types.SRIOV_PF, UriBuilder.fromUri(results.get(0).getResourceLink()).build());
                    transaction.connect(sriovPfUri, sriovVfUri);
                } else {
                    throw new HeatBridgeException("Unable to find sriov-pf related link " + pfPciId + ". Unexpected results size" + results.size());
                }
            } else {
                logger.error("Pserver {} does not exist in AAI. Unable to build sriov-vf to sriov-pf relationship.", pserverHostName);
                throw new HeatBridgeException("Pserver " + pserverHostName + " does not exist in AAI");
            }
        }
    }
}
Also used : Server(org.openstack4j.model.compute.Server) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) Start(org.onap.aaiclient.client.graphinventory.entities.Start) Node(org.onap.aaiclient.client.graphinventory.entities.Node) DSLStartNode(org.onap.aaiclient.client.graphinventory.entities.DSLStartNode) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) IPAddressString(inet.ipaddr.IPAddressString) DSLStartNode(org.onap.aaiclient.client.graphinventory.entities.DSLStartNode)

Example 2 with Pathed

use of org.onap.aaiclient.client.graphinventory.entities.Pathed in project so by onap.

the class HttpLookupUri method extractRelatedLink.

protected Optional<String> extractRelatedLink(String jsonString) throws IOException {
    Optional<String> result;
    ObjectMapper mapper = new ObjectMapper();
    Results<Pathed> results = mapper.readValue(jsonString, new TypeReference<Results<Pathed>>() {
    });
    if (results.getResult().size() == 1) {
        String uriString = results.getResult().get(0).getResourceLink();
        URI uri = UriBuilder.fromUri(uriString).build();
        String rawPath = uri.getRawPath();
        result = Optional.of(rawPath.replaceAll("/aai/v\\d+", ""));
    } else if (results.getResult().isEmpty()) {
        result = Optional.empty();
    } else {
        throw new IllegalStateException("more than one result returned");
    }
    return result;
}
Also used : Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) Results(org.onap.aaiclient.client.aai.entities.Results) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Pathed

use of org.onap.aaiclient.client.graphinventory.entities.Pathed in project so by onap.

the class HeatBridgeImplTest method testUpdateVserverLInterfacesToAai.

@Test
public void testUpdateVserverLInterfacesToAai() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException {
    // Arrange
    List<Resource> stackResources = (List<Resource>) extractTestStackResources();
    Port port = mock(Port.class);
    when(port.getId()).thenReturn("test-port-id");
    when(port.getHostId()).thenReturn("pserverId");
    when(port.getName()).thenReturn("test-port-name");
    when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE);
    when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78");
    when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a");
    when(port.getDeviceId()).thenReturn("test-device-id");
    when(osClient.getServerById("test-device-id")).thenReturn(server);
    when(server.getHypervisorHostname()).thenReturn("test.server.name");
    String pfPciId = "0000:08:00.0";
    when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, HeatBridgeConstants.OS_PF_PCI_SLOT_KEY, "testPfPciId"));
    IP ip = mock(IP.class);
    Set<IP> ipSet = new HashSet<>();
    ipSet.add(ip);
    when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226");
    when(ip.getSubnetId()).thenReturn("testSubnetId");
    when(port.getFixedIps()).thenAnswer(x -> ipSet);
    Subnet subnet = mock(Subnet.class);
    when(subnet.getCidr()).thenReturn("169.254.100.0/24");
    when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet);
    Network network = mock(Network.class);
    when(network.getId()).thenReturn("test-network-id");
    when(network.getNetworkType()).thenReturn(NetworkType.VLAN);
    when(network.getProviderSegID()).thenReturn("2345");
    when(network.getProviderPhyNet()).thenReturn("ovsnet");
    when(osClient.getPortById("212a203a-9764-4f42-84ea-731536a8f13a")).thenReturn(port);
    when(osClient.getPortById("387e3904-8948-43d1-8635-b6c2042b54da")).thenReturn(port);
    when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port);
    when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port);
    when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port);
    when(osClient.getNetworkById(anyString())).thenReturn(network);
    SriovPf sriovPf = new SriovPf();
    sriovPf.setPfPciId(pfPciId);
    when(resourcesClient.exists(any(AAIResourceUri.class))).thenReturn(true);
    when(env.getProperty("mso.cloudOwner.included", "")).thenReturn("CloudOwner");
    doReturn(dSLQueryClient).when(heatbridge).getAAIDSLClient();
    List<Pathed> pathed = ((Results<Pathed>) MAPPER.readValue(getJson("pathed-sriov-pf.json"), new TypeReference<Results<Pathed>>() {
    })).getResult();
    when(dSLQueryClient.queryPathed(any(DSLQuery.class))).thenReturn(pathed);
    doReturn(false).when(heatbridge).sriovVfHasSriovPfRelationship(any());
    // Act
    heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner");
    // Assert
    verify(transaction, times(20)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class));
    verify(osClient, times(5)).getPortById(anyString());
    verify(osClient, times(5)).getSubnetById("testSubnetId");
    verify(osClient, times(10)).getNetworkById(anyString());
    verify(transaction, times(5)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class));
}
Also used : Optional(java.util.Optional) Port(org.openstack4j.model.network.Port) IP(org.openstack4j.model.network.IP) Resource(org.openstack4j.model.heat.Resource) HeatResource(org.openstack4j.openstack.heat.domain.HeatResource) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SriovPf(org.onap.aai.domain.yang.SriovPf) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) Results(org.onap.aaiclient.client.aai.entities.Results) Network(org.openstack4j.model.network.Network) List(java.util.List) L3InterfaceIpv6AddressList(org.onap.aai.domain.yang.L3InterfaceIpv6AddressList) ArrayList(java.util.ArrayList) RelationshipList(org.onap.aai.domain.yang.RelationshipList) DSLQuery(org.onap.aaiclient.client.graphinventory.entities.DSLQuery) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Subnet(org.openstack4j.model.network.Subnet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Pathed

use of org.onap.aaiclient.client.graphinventory.entities.Pathed in project so by onap.

the class AAIQueryClientTest method querySingleTypeTest.

@Test
public void querySingleTypeTest() throws IOException {
    when(client.createClient(isA(AAIResourceUri.class))).thenReturn(restClient);
    when(restClient.put(any(Object.class), any(GenericType.class))).thenReturn(mapper.readValue(getJson("pathed-result.json"), new TypeReference<Results<Map<String, Object>>>() {
    }));
    List<Pathed> results = aaiQueryClient.queryPathed(new CustomQuery(Arrays.asList(AAIUriFactory.createNodesUri(Types.COMPLEX.getFragment("test")))));
    assertEquals(2, results.size());
    assertEquals("service-instance", results.get(1).getResourceType());
}
Also used : GenericType(javax.ws.rs.core.GenericType) Pathed(org.onap.aaiclient.client.graphinventory.entities.Pathed) CustomQuery(org.onap.aaiclient.client.aai.entities.CustomQuery) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Pathed (org.onap.aaiclient.client.graphinventory.entities.Pathed)4 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 Test (org.junit.Test)2 Results (org.onap.aaiclient.client.aai.entities.Results)2 DSLQuery (org.onap.aaiclient.client.graphinventory.entities.DSLQuery)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IPAddressString (inet.ipaddr.IPAddressString)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 GenericType (javax.ws.rs.core.GenericType)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 L3InterfaceIpv6AddressList (org.onap.aai.domain.yang.L3InterfaceIpv6AddressList)1 RelationshipList (org.onap.aai.domain.yang.RelationshipList)1 SriovPf (org.onap.aai.domain.yang.SriovPf)1 CustomQuery (org.onap.aaiclient.client.aai.entities.CustomQuery)1