use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.
the class ActivateVnfOperationalEnvironment method execute.
/**
* The Point-Of-Entry from APIH with VID request to send activate request
*
* @param requestId - String
* @param request - CloudOrchestrationRequest object
* @return void - nothing
*/
public void execute(String requestId, CloudOrchestrationRequest request) throws ApiException {
String vnfOperationalEnvironmentId = request.getOperationalEnvironmentId();
String vidWorkloadContext = request.getRequestDetails().getRequestParameters().getWorkloadContext();
List<ServiceModelList> serviceModelVersionIdList = request.getRequestDetails().getRequestParameters().getManifest().getServiceModelList();
String ecompOperationalEnvironmentId = null;
AAIResultWrapper wrapper = getAAIOperationalEnvironment(vnfOperationalEnvironmentId);
Optional<Relationships> optRelationships = wrapper.getRelationships();
if (optRelationships.isPresent()) {
Relationships relationships = optRelationships.get();
List<AAIResourceUri> operationalEnvironments = relationships.getRelatedUris(Types.OPERATIONAL_ENVIRONMENT);
if (!operationalEnvironments.isEmpty()) {
ecompOperationalEnvironmentId = operationalEnvironments.get(0).getURIKeys().get(AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId);
}
}
logger.debug(" vnfOperationalEnvironmentId : {}", vnfOperationalEnvironmentId);
logger.debug(" ecompOperationalEnvironmentId : {}", ecompOperationalEnvironmentId);
OperationalEnvironment operationalEnv = wrapper.asBean(OperationalEnvironment.class).get();
String workloadContext = operationalEnv.getWorkloadContext();
logger.debug(" aai workloadContext: {}", workloadContext);
if (!vidWorkloadContext.equals(workloadContext)) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
throw new ValidateException.Builder(" The vid workloadContext did not match from aai record. " + " vid workloadContext:" + vidWorkloadContext + " aai workloadContext:" + workloadContext, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
if (ecompOperationalEnvironmentId == null) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
throw new ValidateException.Builder(" The ECOMP OE was not in aai record; the value of relationship.relationship-data key: " + AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
processActivateSDCRequest(requestId, ecompOperationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.
the class ActivateVnfOperationalEnvironmentTest method processActivateSDCRequestTest_202.
@Test
public void processActivateSDCRequestTest_202() throws Exception {
String distributionId = "TEST_distributionId";
JSONObject jsonObject = new JSONObject();
jsonObject.put("statusCode", "202");
jsonObject.put("message", "Success");
jsonObject.put("distributionId", distributionId);
// prepare request detail
List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
serviceModelVersionIdList.add(serviceModelList1);
wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.
the class ActivateVnfOperationalEnvironmentTest method processActivateSDCRequestTest_409.
@Test
public void processActivateSDCRequestTest_409() throws ApiException, JsonProcessingException {
// ERROR in asdc
JSONObject jsonMessages = new JSONObject();
jsonMessages.put("message", "Failure");
jsonMessages.put("messageId", "SVC4675");
jsonMessages.put("text", "Error: Service state is invalid for this action.");
JSONObject jsonServException = new JSONObject();
jsonServException.put("policyException", jsonMessages);
// jsonServException.put("serviceException", jsonMessages);
JSONObject jsonErrorResponse = new JSONObject();
jsonErrorResponse.put("requestError", jsonServException);
// prepare request detail
List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
serviceModelVersionIdList.add(serviceModelList1);
InfraActiveRequests iar = new InfraActiveRequests();
iar.setRequestId(requestId);
iar.setRequestStatus("PENDING");
wireMockServer.stubFor(get(urlPathEqualTo("/infraActiveRequests/" + requestId)).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withBody(mapper.writeValueAsString(iar)).withStatus(HttpStatus.SC_OK)));
wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonErrorResponse.toString()).withStatus(HttpStatus.SC_CONFLICT)));
wireMockServer.stubFor(post(urlPathEqualTo("/infraActiveRequests/")).withRequestBody(containing("operationalEnvId\":\"1dfe7154-eae0-44f2-8e7a-8e5e7882e55d\"")).willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
thrown.expect(ValidateException.class);
activateVnf.processActivateSDCRequest(requestId, operationalEnvironmentId, serviceModelVersionIdList, workloadContext, vnfOperationalEnvironmentId);
}
use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.
the class ActivateVnfOperationalEnvironmentTest method executionTest.
@Test
public void executionTest() throws Exception {
List<ServiceModelList> serviceModelVersionIdList = new ArrayList<>();
ServiceModelList serviceModelList1 = new ServiceModelList();
serviceModelList1.setRecoveryAction(RecoveryAction.retry);
serviceModelList1.setServiceModelVersionId(serviceModelVersionId);
serviceModelVersionIdList.add(serviceModelList1);
RequestDetails requestDetails = new RequestDetails();
RequestParameters requestParameters = new RequestParameters();
Manifest manifest = new Manifest();
manifest.setServiceModelList(serviceModelVersionIdList);
requestParameters.setManifest(manifest);
requestParameters.setWorkloadContext(workloadContext);
requestDetails.setRequestParameters(requestParameters);
request.setOperationalEnvironmentId(vnfOperationalEnvironmentId);
request.setRequestDetails(requestDetails);
JSONObject jsonObject = new JSONObject();
jsonObject.put("statusCode", "202");
jsonObject.put("message", "Success");
jsonObject.put("distributionId", sdcDistributionId);
wireMockServer.stubFor(get(urlPathMatching("/aai/" + AAIVersion.LATEST + "/cloud-infrastructure/operational-environments/.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("vnfoperenv/activateOperationalEnvironmentWithRelationship.json").withStatus(HttpStatus.SC_ACCEPTED)));
wireMockServer.stubFor(post(urlPathMatching("/sdc/v1/catalog/services/TEST_serviceModelVersionId/distr.*")).willReturn(aResponse().withHeader("Content-Type", "application/json").withBody(jsonObject.toString()).withStatus(HttpStatus.SC_ACCEPTED)));
activateVnf.execute(requestId, request);
}
use of org.onap.so.apihandlerinfra.tenantisolationbeans.ServiceModelList in project so by onap.
the class ActivateVnfOperationalEnvironment method processActivateSDCRequest.
/**
* The Method to send the Activation Requests to SDC
*
* @param requestId - String
* @param operationalEnvironmentId - String
* @param serviceModelVersionIdList - List<ServiceModelList> list
* @param workloadContext - String
* @return jsonResponse - JSONObject object
*/
public void processActivateSDCRequest(String requestId, String operationalEnvironmentId, List<ServiceModelList> serviceModelVersionIdList, String workloadContext, String vnfOperationalEnvironmentId) throws ApiException {
JSONObject jsonResponse = null;
int retryCount = 0;
try {
retryCount = Integer.parseInt(sdcRetryCount);
} catch (NumberFormatException e) {
retryCount = DEFAULT_ACTIVATE_RETRY_COUNT;
}
// loop through the serviceModelVersionId, and send request SDC
for (ServiceModelList serviceModelList : serviceModelVersionIdList) {
String serviceModelVersionId = serviceModelList.getServiceModelVersionId();
String recoveryAction = serviceModelList.getRecoveryAction().toString().toUpperCase();
// should insert 1 row
OperationalEnvServiceModelStatus serviceModelStatus = dbHelper.insertRecordToOperationalEnvServiceModelStatus(requestId, operationalEnvironmentId, serviceModelVersionId, DISTRIBUTION_STATUS_SENT, recoveryAction, retryCount, workloadContext, vnfOperationalEnvironmentId);
client.save(serviceModelStatus);
String distributionId = "";
jsonResponse = sdcClientHelper.postActivateOperationalEnvironment(serviceModelVersionId, operationalEnvironmentId, workloadContext);
String statusCode = jsonResponse.get("statusCode").toString();
if (statusCode.equals(String.valueOf(Response.Status.ACCEPTED.getStatusCode()))) {
distributionId = jsonResponse.get("distributionId").toString();
// should insert 1 row
OperationalEnvDistributionStatus distStatus = dbHelper.insertRecordToOperationalEnvDistributionStatus(distributionId, operationalEnvironmentId, serviceModelVersionId, requestId, DISTRIBUTION_STATUS_SENT, "");
client.save(distStatus);
} else {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, ErrorCode.BusinessProcessError).build();
String dbErrorMessage = " Failure calling SDC: statusCode: " + statusCode + "; messageId: " + jsonResponse.get("messageId") + "; message: " + jsonResponse.get("message");
requestDb.updateInfraFailureCompletion(dbErrorMessage, requestId, operationalEnvironmentId);
throw new ValidateException.Builder(dbErrorMessage, HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).errorInfo(errorLoggerInfo).build();
}
}
}
Aggregations