Search in sources :

Example 1 with TenantIsolationException

use of org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException in project so by onap.

the class CreateVnfOperationalEnvironment method execute.

public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
    try {
        setRequest(request);
        ObjectMapper objectMapper = new ObjectMapper();
        AAIResultWrapper aaiResultWrapper = aaiHelper.getAaiOperationalEnvironment(getEcompManagingEnvironmentId());
        if (aaiResultWrapper.isEmpty()) {
            throw new NotFoundException(getEcompManagingEnvironmentId() + " not found in A&AI");
        }
        OperationalEnvironment aaiEnv = aaiResultWrapper.asBean(OperationalEnvironment.class).get();
        // Find ECOMP environments in GRM
        logger.debug(" Start of GRM findRunningServicesAsString");
        String searchKey = getSearchKey(aaiEnv);
        String tenantContext = getTenantContext().toUpperCase();
        String jsonResponse = getGrmClient().findRunningServicesAsString(searchKey, 1, tenantContext);
        ServiceEndPointList sel = objectMapper.readValue(jsonResponse, ServiceEndPointList.class);
        if (sel.getServiceEndPointList().size() == 0) {
            throw new TenantIsolationException("GRM did not find any matches for " + searchKey + " in " + tenantContext);
        }
        // Replicate end-point for VNF Operating environment in GRM
        List<ServiceEndPointRequest> serviceEndpointRequestList = buildEndPointRequestList(sel);
        int ctr = 0;
        int total = serviceEndpointRequestList.size();
        for (ServiceEndPointRequest requestList : serviceEndpointRequestList) {
            logger.debug("Creating endpoint " + ++ctr + " of " + total + ": " + requestList.getServiceEndPoint().getName());
            getGrmClient().addServiceEndPoint(requestList);
        }
        // Create VNF operating in A&AI
        aaiHelper.createOperationalEnvironment(aaiClientObjectBuilder.buildAAIOperationalEnvironment("INACTIVE", request));
        aaiHelper.createRelationship(request.getOperationalEnvironmentId(), getEcompManagingEnvironmentId());
        // Update request database
        requestDb.updateInfraSuccessCompletion("SUCCESSFULLY created VNF operational environment", requestId, request.getOperationalEnvironmentId());
    } catch (Exception e) {
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.DataError).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
        throw validateException;
    }
}
Also used : ServiceEndPointList(org.onap.so.client.grm.beans.ServiceEndPointList) ServiceEndPointRequest(org.onap.so.client.grm.beans.ServiceEndPointRequest) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) AAIClientObjectBuilder(org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder) NotFoundException(javax.ws.rs.NotFoundException) ServiceEndPoint(org.onap.so.client.grm.beans.ServiceEndPoint) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) NotFoundException(javax.ws.rs.NotFoundException) OperationalEnvironment(org.onap.aai.domain.yang.OperationalEnvironment) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TenantIsolationException(org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 NotFoundException (javax.ws.rs.NotFoundException)1 OperationalEnvironment (org.onap.aai.domain.yang.OperationalEnvironment)1 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)1 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)1 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)1 ErrorLoggerInfo (org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo)1 TenantIsolationException (org.onap.so.apihandlerinfra.tenantisolation.exceptions.TenantIsolationException)1 AAIClientObjectBuilder (org.onap.so.apihandlerinfra.tenantisolation.helpers.AAIClientObjectBuilder)1 ServiceEndPoint (org.onap.so.client.grm.beans.ServiceEndPoint)1 ServiceEndPointList (org.onap.so.client.grm.beans.ServiceEndPointList)1 ServiceEndPointRequest (org.onap.so.client.grm.beans.ServiceEndPointRequest)1