Search in sources :

Example 1 with BulkProcessFailed

use of org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed 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 2 with BulkProcessFailed

use of org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed in project so by onap.

the class AAITransactionalClient method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.onap.aaiclient.client.aai.GraphInventoryTransactionalClient#execute()
     */
@Override
public void execute() throws BulkProcessFailed {
    try {
        if (!this.transactions.getTransactions().isEmpty()) {
            RestClient client = aaiClient.createClient(AAIUriFactory.createResourceUri(AAIObjectType.BULK_PROCESS));
            Response response = client.put(this.transactions);
            if (response.hasEntity()) {
                final Optional<String> errorMessage = this.locateErrorMessages(response.readEntity(String.class));
                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.transactions.getTransactions().clear();
        this.currentTransaction = null;
        this.actionCount = 0;
    }
}
Also used : Response(javax.ws.rs.core.Response) RestClient(org.onap.so.client.RestClient) BulkProcessFailed(org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)

Aggregations

BulkProcessFailed (org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed)2 RestClient (org.onap.so.client.RestClient)2 Response (javax.ws.rs.core.Response)1 SingleTransactionResponse (org.onap.aaiclient.client.aai.entities.singletransaction.SingleTransactionResponse)1