Search in sources :

Example 6 with AAIResourcesClient

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

the class CreateVFModule method getNodeType.

protected NodeType getNodeType(CloudRegion cloudRegion) {
    AAIResourceUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()));
    AAIResourcesClient client = getAAIClient();
    Optional<Relationships> relationships = client.get(cloudRegionUri).getRelationships();
    if (relationships.isPresent()) {
        AAIPluralResourceUri networkTechsGreenfieldUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId())).relatedTo(Types.NETWORK_TECHNOLOGIES.getFragment()).queryParam("network-technology-name", NodeType.GREENFIELD.getNetworkTechnologyName());
        AAIResultWrapper networkTechsGreenfield = client.get(networkTechsGreenfieldUri);
        if (networkTechsGreenfield != null && !networkTechsGreenfield.isEmpty()) {
            return NodeType.GREENFIELD;
        }
    }
    return NodeType.BROWNFIELD;
}
Also used : Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Example 7 with AAIResourcesClient

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

the class ServiceInstanceUriTest method serializeTest.

@Test
public void serializeTest() throws IOException, ClassNotFoundException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
    ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3"));
    final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
    ServiceInstanceUri spy = spy(instance);
    AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
    AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
    when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class), ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
    when(wrapper.getJson()).thenReturn(content);
    when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
    spy.locateAndBuild();
    instance = spy.clone();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(bos);
    objectOutputStream.writeObject(instance);
    objectOutputStream.flush();
    objectOutputStream.close();
    ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    ObjectInputStream objectInputStream = new ObjectInputStream(bis);
    ServiceInstanceUri e2 = (ServiceInstanceUri) objectInputStream.readObject();
    objectInputStream.close();
    ServiceInstanceUri spy2 = spy(e2);
    assertEquals(spy2.build().toString(), instance.build().toString());
    // use the cached value do not call out to external system
    verify(spy2, times(0)).getResourcesClient();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) ObjectOutputStream(java.io.ObjectOutputStream) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 8 with AAIResourcesClient

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

the class ServiceInstanceUriTest method noVertexFound.

@Test
public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
    ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3"));
    ServiceInstanceUri spy = spy(instance);
    AAIResourcesClient client = aaiClient;
    doReturn(client).when(spy).getResourcesClient();
    wireMockRule.stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3")).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBodyFile("")));
    exception.expect(NotFoundException.class);
    spy.locateAndBuild();
}
Also used : AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Test(org.junit.Test)

Example 9 with AAIResourcesClient

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

the class CreateAAInventory method doExecute.

@Override
public void doExecute(TestContext context) {
    final Logger logger = LoggerFactory.getLogger(CreateAAInventory.class);
    try {
        String stackName = context.getVariable("stackName");
        if (stackName != null && stackName.equals("replace_module")) {
            String vServerId = "92272b67-d23f-42ca-87fa-7b06a9ec81f3";
            AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
            AAICommonObjectMapperProvider aaiMapper = new AAICommonObjectMapperProvider();
            InputStream vserverFile = new ClassPathResource("openstack/gr_api/CreateAAIInventory.json").getInputStream();
            Vserver vserver = aaiMapper.getMapper().readValue(vserverFile, Vserver.class);
            AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("cloudOwner", "regionOne").tenant("0422ffb57ba042c0800a29dc85ca70f8").vserver(vServerId));
            aaiResourceClient.create(vserverURI, vserver);
        }
    } catch (Exception e) {
        logger.debug("Exception in CreateAAInventory.doExecute", e);
    }
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) InputStream(java.io.InputStream) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Logger(org.slf4j.Logger) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAICommonObjectMapperProvider(org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 10 with AAIResourcesClient

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

the class ServicePluginFactory method getTPsfromAAI.

// This method returns Local and remote TPs information from AAI
public Map getTPsfromAAI(String serviceName) {
    Map<String, Object> tpInfo = new HashMap<>();
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().logicalLinks());
    AAIResourcesClient client = new AAIResourcesClient();
    Optional<LogicalLinks> result = client.get(LogicalLinks.class, uri);
    if (result.isPresent()) {
        LogicalLinks links = result.get();
        LogicalLink link = selectLogicalLink(links.getLogicalLink(), serviceName);
        if (link != null) {
            boolean isRemoteLink = false;
            logger.info("processing link :{}", link.getLinkName());
            AAIResultWrapper wrapper = new AAIResultWrapper(link);
            Optional<Relationships> optRelationships = wrapper.getRelationships();
            List<AAIResourceUri> pInterfaces = new ArrayList<>();
            if (optRelationships.isPresent()) {
                Relationships relationships = optRelationships.get();
                if (!relationships.getRelatedUris(Types.EXT_AAI_NETWORK).isEmpty()) {
                    isRemoteLink = true;
                }
                pInterfaces.addAll(relationships.getRelatedUris(Types.P_INTERFACE));
                if (isRemoteLink) {
                    // find remote p interface
                    AAIResourceUri localTP = null;
                    AAIResourceUri remoteTP = null;
                    AAIResourceUri pInterface0 = pInterfaces.get(0);
                    if (isRemotePInterface(client, pInterface0)) {
                        remoteTP = pInterfaces.get(0);
                        localTP = pInterfaces.get(1);
                    } else {
                        localTP = pInterfaces.get(0);
                        remoteTP = pInterfaces.get(1);
                    }
                    tpInfo = getTPInfo(client, localTP, remoteTP);
                }
            }
        }
    }
    return tpInfo;
}
Also used : HashMap(java.util.HashMap) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) LogicalLink(org.onap.aai.domain.yang.LogicalLink) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) LogicalLinks(org.onap.aai.domain.yang.LogicalLinks) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)30 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)23 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)5 NotFoundException (javax.ws.rs.NotFoundException)4 Test (org.junit.Test)4 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Logger (org.slf4j.Logger)3 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Response (javax.ws.rs.core.Response)2 JSONObject (org.json.JSONObject)2 ServiceInstance (org.onap.aai.domain.yang.v16.ServiceInstance)2 Relationships (org.onap.aaiclient.client.aai.entities.Relationships)2 GraphInventoryUriNotFoundException (org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException)2 CamundaResponse (org.onap.so.apihandler.camundabeans.CamundaResponse)2 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)2 GetE2EServiceInstanceResponse (org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse)2 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)2