Search in sources :

Example 1 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class GraphInventoryResourcesClient method deleteIfExists.

/**
 * Deletes object from GraphInventory only if exists. Automatically handles resource-version.
 *
 * @param uri
 * @return
 */
public void deleteIfExists(SingleUri uri) {
    GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone();
    RestClient giRC = client.createClient(clone);
    Optional<Map<String, Object>> result = giRC.get(new GenericType<Map<String, Object>>() {
    });
    if (result.isPresent()) {
        String resourceVersion = (String) result.get().get("resource-version");
        giRC = client.createClient(clone.resourceVersion(resourceVersion));
        giRC.delete();
    } else {
        logger.warn(clone.build() + " already does not exist in " + client.getGraphDBName() + " therefore delete call not executed");
    }
}
Also used : RestClient(org.onap.so.client.RestClient) Map(java.util.Map)

Example 2 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAISingleTransactionClient method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.onap.aaiclient.client.aai.GraphInventoryTransactionClient#execute()
     */
@Override
public void execute() throws BulkProcessFailed {
    try {
        if (!this.request.getOperations().isEmpty()) {
            RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.SINGLE_TRANSACTION));
            SingleTransactionResponse response = client.post(this.request, SingleTransactionResponse.class);
            if (response != null) {
                final Optional<String> errorMessage = this.locateErrorMessages(response);
                if (errorMessage.isPresent()) {
                    throw new BulkProcessFailed("One or more transactions failed in A&AI. Check logs for payloads.\nMessages:\n" + errorMessage.get());
                }
            } else {
                throw new BulkProcessFailed("Transactions acccepted by A&AI, but there was no response. Unsure of result.");
            }
        }
    } finally {
        this.request.getOperations().clear();
        this.actionCount = 0;
    }
}
Also used : SingleTransactionResponse(org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse) RestClient(org.onap.so.client.RestClient) BulkProcessFailed(org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)

Example 3 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class GraphInventoryResourcesClient method delete.

/**
 * Deletes object from GraphInventory. Automatically handles resource-version.
 *
 * @param uri
 * @return
 */
public void delete(SingleUri uri) {
    GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> clone = (SingleUri) uri.clone();
    RestClient giRC = client.createClient(clone);
    Map<String, Object> result = giRC.get(new GenericType<Map<String, Object>>() {
    }).orElseThrow(() -> new NotFoundException(clone.build() + " does not exist in " + client.getGraphDBName()));
    String resourceVersion = (String) result.get("resource-version");
    giRC = client.createClient(clone.resourceVersion(resourceVersion));
    giRC.delete();
}
Also used : GenericType(javax.ws.rs.core.GenericType) RestClient(org.onap.so.client.RestClient) NotFoundException(javax.ws.rs.NotFoundException)

Example 4 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class GraphInventoryResourcesClient method disconnect.

/**
 * Removes relationship from two objects in GraphInventory
 *
 * @param uriA
 * @param uriB
 * @return
 */
public void disconnect(SingleUri uriA, SingleUri uriB) {
    GraphInventorySingleResourceUri<?, ?, ?, ?, ?, ?> uriAClone = (SingleUri) uriA.clone();
    RestClient giRC = client.createClient(uriAClone.relationshipAPI());
    giRC.delete(this.buildRelationship(uriB));
}
Also used : RestClient(org.onap.so.client.RestClient)

Example 5 with RestClient

use of org.onap.so.client.RestClient in project so by onap.

the class AAIResourcesClientTest method testGetFirstWrongPluralClass.

@Test
public void testGetFirstWrongPluralClass() {
    GenericVnf vnf = new GenericVnf();
    AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnfs());
    RestClient restClientMock = mock(RestClient.class);
    doReturn(restClientMock).when(client).createClient(uri);
    when(restClientMock.get(GenericVnf.class)).thenReturn(Optional.of(vnf));
    Optional<GenericVnf> result = aaiClient.getFirst(GenericVnf.class, GenericVnf.class, uri);
    assertFalse(result.isPresent());
}
Also used : GenericVnf(org.onap.aai.domain.yang.GenericVnf) AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) RestClient(org.onap.so.client.RestClient) Test(org.junit.Test)

Aggregations

RestClient (org.onap.so.client.RestClient)23 Test (org.junit.Test)8 Response (javax.ws.rs.core.Response)7 GenericVnf (org.onap.aai.domain.yang.GenericVnf)6 AAIPluralResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri)6 GenericVnfs (org.onap.aai.domain.yang.GenericVnfs)5 StackInfo (org.onap.so.openstack.beans.StackInfo)4 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)2 URI (java.net.URI)2 URL (java.net.URL)2 NotFoundException (javax.ws.rs.NotFoundException)2 BulkProcessFailed (org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)2 CreateStackParam (com.woorea.openstack.heat.model.CreateStackParam)1 Stack (com.woorea.openstack.heat.model.Stack)1 Map (java.util.Map)1 GenericType (javax.ws.rs.core.GenericType)1 SingleTransactionResponse (org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse)1 GraphInventoryPluralResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryPluralResourceUri)1 GraphInventoryResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventoryResourceUri)1 GraphInventorySingleResourceUri (org.onap.aaiclient.client.graphinventory.entities.uri.GraphInventorySingleResourceUri)1