Search in sources :

Example 1 with Results

use of org.onap.aaiclient.client.aai.entities.Results in project so by onap.

the class GraphInventoryQueryClient method getResourceAndUrl.

public List<ResourceAndUrl<Wrapper>> getResourceAndUrl(I query) throws IOException {
    List<ResourceAndUrl<Wrapper>> result = new ArrayList<>();
    ObjectMapper mapper = mapperProvider.getMapper();
    Results<Map<String, Object>> resultsFromJson = mapper.readValue(query(Format.RESOURCE_AND_URL, query), new TypeReference<Results<Map<String, Object>>>() {
    });
    for (Map<String, Object> m : resultsFromJson.getResult()) {
        for (Entry<String, Object> entrySet : m.entrySet()) {
            if (!entrySet.getKey().equals("url")) {
                String url = (String) m.get("url");
                String stringJson = mapper.writeValueAsString(entrySet.getValue());
                result.add(new ResourceAndUrl<Wrapper>(url, createType(entrySet.getKey(), url), createWrapper(stringJson)));
            }
        }
    }
    return result;
}
Also used : GraphInventoryResultWrapper(org.onap.aaiclient.client.graphinventory.entities.GraphInventoryResultWrapper) ResourceAndUrl(org.onap.aaiclient.client.graphinventory.entities.ResourceAndUrl) ArrayList(java.util.ArrayList) Results(org.onap.aaiclient.client.aai.entities.Results) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Results

use of org.onap.aaiclient.client.aai.entities.Results in project so by onap.

the class AAIRestClientImpl method getListOfPservers.

protected List<Pserver> getListOfPservers(String jsonInput) throws IOException {
    ObjectMapper mapper = new AAICommonObjectMapperProvider().getMapper();
    Results<Map<String, Pserver>> resultsFromJson = mapper.readValue(jsonInput, new TypeReference<Results<Map<String, Pserver>>>() {
    });
    List<Pserver> results = new ArrayList<>();
    for (Map<String, Pserver> m : resultsFromJson.getResult()) {
        results.add(m.get("pserver"));
    }
    return results;
}
Also used : Results(org.onap.aaiclient.client.aai.entities.Results) Pserver(org.onap.aai.domain.yang.Pserver) ArrayList(java.util.ArrayList) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with Results

use of org.onap.aaiclient.client.aai.entities.Results 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 4 with Results

use of org.onap.aaiclient.client.aai.entities.Results 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)

Aggregations

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