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;
}
}
Aggregations