Search in sources :

Example 21 with AAIResourcesClient

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

the class E2EServiceInstances method Activate5GSliceServiceInstances.

private Response Activate5GSliceServiceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
    // TODO should be a new one or the same service instance Id
    E2ESliceServiceActivateRequest e2eActReq;
    ObjectMapper mapper = new ObjectMapper();
    try {
        e2eActReq = mapper.readValue(requestJSON, E2ESliceServiceActivateRequest.class);
    } catch (Exception e) {
        logger.debug("Mapping of request to JSON object failed : ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    String requestId = UUID.randomUUID().toString();
    RecipeLookupResult recipeLookupResult;
    try {
        // TODO Get the service template model version uuid from AAI.
        String modelVersionId = null;
        AAIResourcesClient client = new AAIResourcesClient();
        AAIResourceUri url = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(e2eActReq.getGlobalSubscriberId()).serviceSubscription(e2eActReq.getServiceType()).serviceInstance(instanceIdMap.get(SERVICE_ID)));
        Optional<ServiceInstance> serviceInstanceOpt = client.get(ServiceInstance.class, url);
        if (serviceInstanceOpt.isPresent()) {
            modelVersionId = serviceInstanceOpt.get().getModelVersionId();
        }
        recipeLookupResult = getServiceInstanceOrchestrationURI(modelVersionId, action);
    } catch (Exception e) {
        logger.error(MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON, null, null);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    if (recipeLookupResult == null) {
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action, ModelType.service.name(), requestJSON, null, null);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    String bpmnRequest = null;
    RequestClientParameter postParam = null;
    try {
        JSONObject jjo = new JSONObject(requestJSON);
        jjo.put("operationId", requestId);
        bpmnRequest = jjo.toString();
        String serviceId = instanceIdMap.get(SERVICE_ID);
        String operationType = instanceIdMap.get("operationType");
        String serviceInstanceType = e2eActReq.getServiceType();
        postParam = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setOperationType(operationType).setServiceType(serviceInstanceType).setRequestDetails(bpmnRequest).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
    } catch (Exception e) {
        Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine");
        logger.debug("End of the transaction, the final response is: " + resp.getEntity());
        return resp;
    }
    return postRequest(recipeLookupResult.getOrchestrationURI(), postParam, version);
}
Also used : E2ESliceServiceActivateRequest(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2ESliceServiceActivateRequest) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ServiceInstance(org.onap.aai.domain.yang.v16.ServiceInstance) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) JSONObject(org.json.JSONObject) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 22 with AAIResourcesClient

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

the class E2EServiceInstances method deleteE2EserviceInstances.

private Response deleteE2EserviceInstances(String requestJSON, Action action, HashMap<String, String> instanceIdMap, String version) throws ApiException {
    // TODO should be a new one or the same service instance Id
    E2EServiceInstanceDeleteRequest e2eDelReq;
    ObjectMapper mapper = new ObjectMapper();
    try {
        e2eDelReq = mapper.readValue(requestJSON, E2EServiceInstanceDeleteRequest.class);
    } catch (Exception e) {
        logger.debug("Mapping of request to JSON object failed : ", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_REQUEST, MsoException.ServiceException, "Mapping of request to JSON object failed.  " + e.getMessage(), ErrorNumbers.SVC_BAD_PARAMETER, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_REQUEST_VALIDATION_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.SchemaError.getValue(), requestJSON, e);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    String requestId = UUID.randomUUID().toString();
    RecipeLookupResult recipeLookupResult;
    try {
        // TODO Get the service template model version uuid from AAI.
        String modelVersionId = null;
        AAIResourcesClient client = new AAIResourcesClient();
        AAIResourceUri url = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(e2eDelReq.getGlobalSubscriberId()).serviceSubscription(e2eDelReq.getServiceType()).serviceInstance(instanceIdMap.get(SERVICE_ID)));
        Optional<ServiceInstance> serviceInstanceOpt = client.get(ServiceInstance.class, url);
        if (serviceInstanceOpt.isPresent()) {
            modelVersionId = serviceInstanceOpt.get().getModelVersionId();
        }
        recipeLookupResult = getServiceInstanceOrchestrationURI(modelVersionId, action);
    } catch (Exception e) {
        logger.error(MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e);
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON, null, null);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    if (recipeLookupResult == null) {
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB");
        Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version);
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action, ModelType.service.name(), requestJSON, null, null);
        logger.debug(END_OF_THE_TRANSACTION + response.getEntity());
        return response;
    }
    String bpmnRequest = null;
    RequestClientParameter clientParam = null;
    try {
        JSONObject jjo = new JSONObject(requestJSON);
        jjo.put("operationId", requestId);
        bpmnRequest = jjo.toString();
        String serviceId = instanceIdMap.get(SERVICE_ID);
        String serviceInstanceType = e2eDelReq.getServiceType();
        clientParam = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()).setServiceInstanceId(serviceId).setServiceType(serviceInstanceType).setRequestDetails(bpmnRequest).setApiVersion(version).setALaCarte(false).setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).build();
    } catch (Exception e) {
        Response resp = msoRequest.buildServiceErrorResponse(HttpStatus.SC_BAD_GATEWAY, MsoException.ServiceException, "Failed calling bpmn " + e.getMessage(), ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version);
        logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_BPEL_COMMUNICATE_ERROR.toString(), MSO_PROP_APIHANDLER_INFRA, ErrorCode.AvailabilityError.getValue(), "Exception while communicate with BPMN engine");
        logger.debug("End of the transaction, the final response is: " + resp.getEntity());
        return resp;
    }
    return postRequest(recipeLookupResult.getOrchestrationURI(), clientParam, version);
}
Also used : ResponseBuilder(org.onap.so.apihandler.common.ResponseBuilder) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ServiceInstance(org.onap.aai.domain.yang.v16.ServiceInstance) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) BPMNFailureException(org.onap.so.apihandlerinfra.exceptions.BPMNFailureException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) IOException(java.io.IOException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) CamundaResponse(org.onap.so.apihandler.camundabeans.CamundaResponse) GetE2EServiceInstanceResponse(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) JSONObject(org.json.JSONObject) E2EServiceInstanceDeleteRequest(org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with AAIResourcesClient

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

the class AAIClientHelper method updateAaiOperationalEnvironment.

/**
 * Update managing ECOMP Environment Info from A&AI
 *
 * @param id = operationalEnvironmentId
 * @param aaiRequest object
 */
public void updateAaiOperationalEnvironment(String id, OperationalEnvironment aaiRequest) {
    AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(id));
    AAIResourcesClient client = this.getClient();
    client.update(uri, aaiRequest);
}
Also used : AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient)

Example 24 with AAIResourcesClient

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

the class ProcessVnfc method doExecute.

@Override
public void doExecute(TestContext context) {
    final Logger logger = LoggerFactory.getLogger(ProcessVnfc.class);
    try {
        logger.debug("running ProcessVnfc scenario");
        logger.debug("requestAction: {}", context.getVariable("requestAction"));
        logger.debug("serviceAction: {}", context.getVariable("serviceAction"));
        logger.debug("cloudOwner: {}", context.getVariable("cloudOwner"));
        logger.debug("cloundRegion: {}", context.getVariable("cloudRegion"));
        logger.debug("tenant: {}", context.getVariable("tenant"));
        logger.debug("vfModuleId: {}", context.getVariable("vfModuleId"));
        logger.debug("vnfId: {}", context.getVariable("vnfId"));
        AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
        if (context.getVariable("requestAction").equals("CreateVfModuleInstance") && context.getVariable("serviceAction").equals("assign")) {
            AAIResourceUri vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(VNF_SERVER_1_NAME));
            Vnfc vnfc = new Vnfc();
            vnfc.setVnfcName(VNF_SERVER_1_NAME);
            vnfc.setNfcNamingCode("oamfw");
            vnfc.setNfcFunction("EPC-OAM-FIREWALL");
            vnfc.setProvStatus("PREPROV");
            vnfc.setOrchestrationStatus("Active");
            vnfc.setInMaint(false);
            vnfc.setIsClosedLoopDisabled(false);
            vnfc.setModelInvariantId("b214d2e9-73d9-49d7-b7c4-a9ae7f06e244");
            vnfc.setModelVersionId("9e314c37-2258-4572-a399-c0dd7d5f1aec");
            vnfc.setModelCustomizationId("2bd95cd4-d7ff-4af0-985d-2adea0339921");
            AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(context.getVariable("vnfId")).vfModule(context.getVariable("vfModuleId")));
            if (aaiResourceClient.exists(vnfcURI)) {
                Optional<VfModule> vfModule = aaiResourceClient.get(vfModuleURI).asBean(VfModule.class);
                if (vfModule.isPresent() && vfModule.get().getVfModuleName().contains("macro")) {
                    String vnfcName = VNF_SERVER_1_NAME + vfModule.get().getVfModuleName().substring(vfModule.get().getVfModuleName().length() - 1);
                    vnfc.setVnfcName(vnfcName);
                    vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfcName));
                } else {
                    logger.debug("cleaning up VNFC");
                    aaiResourceClient.delete(vnfcURI);
                }
            }
            logger.debug("creating new VNFC");
            aaiResourceClient.create(vnfcURI, vnfc);
            logger.debug("creating VNFC edge to vf module");
            aaiResourceClient.connect(vfModuleURI, vnfcURI);
        }
    } catch (Exception e) {
        logger.debug("Exception in ProcessVnfc.doExecute", e);
    }
}
Also used : AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Logger(org.slf4j.Logger) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Vnfc(org.onap.aai.domain.yang.Vnfc) VfModule(org.onap.aai.domain.yang.VfModule)

Example 25 with AAIResourcesClient

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

the class AAIServiceInstanceResources method existsOwningEntityName.

public boolean existsOwningEntityName(String owningEntityName) {
    AAIPluralResourceUri owningEntityUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().owningEntities()).queryParam("owning-entity-name", owningEntityName);
    AAIResourcesClient aaiRC = injectionHelper.getAaiClient();
    return aaiRC.exists(owningEntityUri);
}
Also used : AAIPluralResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient)

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