Search in sources :

Example 26 with AAIResourcesClient

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

the class AAIServiceInstanceResources method getOwningEntityByName.

public org.onap.aai.domain.yang.OwningEntity getOwningEntityByName(String owningEntityName) throws AAIEntityNotFoundException {
    AAIPluralResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().owningEntities()).queryParam("owning-entity-name", owningEntityName);
    AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
    Optional<OwningEntities> owningEntities = aaiRC.get(OwningEntities.class, owningEntityUri);
    if (owningEntities.isPresent()) {
        List<org.onap.aai.domain.yang.OwningEntity> owningEntityList = owningEntities.get().getOwningEntity();
        if (owningEntityList.size() > 1) {
            throw new AAIEntityNotFoundException("Non unique result returned for owning entity name: " + owningEntityName);
        } else {
            return owningEntityList.get(0);
        }
    } else {
        throw new AAIEntityNotFoundException("No result returned for owning entity name: " + owningEntityName);
    }
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) OwningEntity(org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) OwningEntities(org.onap.aai.domain.yang.OwningEntities)

Example 27 with AAIResourcesClient

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

the class ServiceInstanceUriTest method notfound.

@Test
public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
    final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
    ServiceInstanceUri instance = new ServiceInstanceUri(Types.SERVICE_INSTANCE.getFragment("key3"));
    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);
    exception.expect(GraphInventoryUriComputationException.class);
    spy.locateAndBuild();
}
Also used : GraphInventoryUriNotFoundException(org.onap.aaiclient.client.graphinventory.exceptions.GraphInventoryUriNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 28 with AAIResourcesClient

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

the class SDNOValidatorImpl method healthDiagnostic.

@Override
public boolean healthDiagnostic(String vnfId, UUID uuid, String requestingUserId) throws IOException, Exception {
    AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId));
    AAIResourcesClient client = new AAIResourcesClient();
    GenericVnf vnf = client.get(GenericVnf.class, uri).orElseThrow(() -> new NotFoundException(vnfId + " not found in A&AI"));
    SDNO requestDiagnostic = buildRequestDiagnostic(vnf, uuid, requestingUserId);
    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString(requestDiagnostic);
    this.submitRequest(json);
    boolean status = this.pollForResponse(uuid.toString());
    return status;
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) SDNO(org.onap.so.client.sdno.beans.SDNO) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(javax.ws.rs.NotFoundException) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 29 with AAIResourcesClient

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

the class DeleteVServers method doExecute.

@Override
public void doExecute(TestContext context) {
    try {
        logger.info("Deleting Vservers in A&AI");
        AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
        String vserverId = context.getVariable("vServerId");
        String cloudRegion = context.getVariable("cloudRegion");
        String cloudOwner = context.getVariable("cloudOwner");
        String tenantId = context.getVariable("tenantId");
        AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId).vserver(vserverId));
        aaiResourceClient.delete(vserverURI);
        logger.error("Delete Vservers in AAI: {}", vserverURI);
    } catch (Exception e) {
        logger.error("Error Deleting VServer in A&AI", e);
    }
}
Also used : AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient)

Example 30 with AAIResourcesClient

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

the class WatchdogDistributionTest method getSetAaiClientTest.

@Test
public void getSetAaiClientTest() {
    aaiResourceClient = watchdogDistribution.getAaiClient();
    watchdogDistribution.setAaiClient(aaiResourceClient);
    AAIResourcesClient aaiResourceClient2 = watchdogDistribution.getAaiClient();
    assertEquals(aaiResourceClient, aaiResourceClient2);
}
Also used : AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

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