Search in sources :

Example 56 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class ServiceInstances method deleteInstanceGroups.

/**
 * This method deletes the Instance Groups.
 *
 * This method will check whether the request is not duplicate in requestdb. if its not then will save as a new
 * request. And will send a POST request to BEPL client to delete the Insatnce Groups.
 *
 * @param action
 * @param instanceIdMap
 * @param version
 * @param requestId
 * @param requestUri
 * @param requestContext
 * @return
 * @throws ApiException
 */
public Response deleteInstanceGroups(Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, ContainerRequestContext requestContext) throws ApiException {
    String instanceGroupId = instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID);
    Boolean aLaCarte = true;
    String apiVersion = version.substring(1);
    ServiceInstancesRequest sir = new ServiceInstancesRequest();
    sir.setInstanceGroupId(instanceGroupId);
    String requestScope = ModelType.instanceGroup.toString();
    InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, null, requestScope);
    requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
    try {
        requestHandlerUtils.validateHeaders(requestContext);
    } catch (ValidationException e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_VALIDATION_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        ValidateException validateException = new ValidateException.Builder(e.getMessage(), HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
        requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, validateException.getMessage());
        throw validateException;
    }
    requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null);
    ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
    RequestReferences referencesResponse = new RequestReferences();
    referencesResponse.setRequestId(requestId);
    serviceResponse.setRequestReferences(referencesResponse);
    Boolean isBaseVfModule = false;
    RecipeLookupResult recipeLookupResult = new RecipeLookupResult("/mso/async/services/WorkflowActionBB", 180);
    try {
        infraActiveRequestsClient.save(currentActiveReq);
    } catch (Exception e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e).errorInfo(errorLoggerInfo).build();
    }
    RequestClientParameter requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
    return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ValidationException(org.onap.so.exceptions.ValidationException) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) InfraActiveRequests(org.onap.so.db.request.beans.InfraActiveRequests) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException) ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) RequestDbFailureException(org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException) IOException(java.io.IOException) CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) ValidationException(org.onap.so.exceptions.ValidationException) RequestClientParameter(org.onap.so.apihandler.common.RequestClientParameter) ErrorLoggerInfo(org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences)

Example 57 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class ServiceInstanceDeleteValidatorTest method before.

@Before
public void before() {
    serviceInstancesRequest = new ServiceInstancesRequest();
    RequestDetails requestDetails = new RequestDetails();
    RequestParameters requestParameters = new RequestParameters();
    requestParameters.setaLaCarte(true);
    requestDetails.setRequestParameters(requestParameters);
    serviceInstancesRequest.setRequestDetails(requestDetails);
}
Also used : ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters) Before(org.junit.Before)

Example 58 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class VolumeGroupDeleteValidatorTest method validateFailureVnfTest.

@Test
public void validateFailureVnfTest() {
    instanceIdMap.put("volumeGroupInstanceId", "1");
    ServiceInstancesRequest request = new ServiceInstancesRequest();
    RequestDetails details = new RequestDetails();
    details.setCloudConfiguration(new CloudConfiguration());
    request.setRequestDetails(details);
    when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule(any(CloudConfiguration.class), eq("1"))).thenReturn(true);
    Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, request, null, null);
    assertEquals(true, result.isPresent());
}
Also used : CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) Test(org.junit.Test)

Example 59 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class RelatedInstancesValidationTest method testCreateVnfNetworkInstanceGroup.

@Test
public void testCreateVnfNetworkInstanceGroup() throws IOException, ValidationException {
    String requestJson = new String(Files.readAllBytes(Paths.get("src/test/resources/MsoRequestTest/RelatedInstances/v7CreateVnfNetworkInstanceGroup.json")));
    ObjectMapper mapper = new ObjectMapper();
    ServiceInstancesRequest sir = mapper.readValue(requestJson, ServiceInstancesRequest.class);
    ValidationInformation info = new ValidationInformation(sir, new HashMap<String, String>(), Action.createInstance, 6, false, sir.getRequestDetails().getRequestParameters());
    info.setRequestScope("vnf");
    sir.setServiceInstanceId("0fd90c0c-0e3a-46e2-abb5-4c4820d5985b");
    sir.getRequestDetails().getModelInfo().setModelCustomizationName("name");
    RelatedInstancesValidation validation = new RelatedInstancesValidation();
    validation.validate(info);
    assertEquals(info.getVnfType(), "Test/name");
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) BaseTest(org.onap.so.apihandlerinfra.BaseTest) Test(org.junit.Test)

Example 60 with ServiceInstancesRequest

use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.

the class RelatedInstancesValidationTest method setupValidationInformation.

public ValidationInformation setupValidationInformation(String path) throws IOException {
    String jsonInput = new String(Files.readAllBytes(Paths.get(path)));
    ObjectMapper mapper = new ObjectMapper();
    ServiceInstancesRequest sir = mapper.readValue(jsonInput, ServiceInstancesRequest.class);
    ValidationInformation info = new ValidationInformation(sir, null, Action.createInstance, 7, false, sir.getRequestDetails().getRequestParameters());
    info.setRequestScope("service");
    sir.setServiceInstanceId("0fd90c0c-0e3a-46e2-abb5-4c4820d5985b");
    sir.getRequestDetails().getModelInfo().setModelCustomizationName("name");
    info.setRequestInfo(sir.getRequestDetails().getRequestInfo());
    return info;
}
Also used : ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest)

Aggregations

ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)100 Test (org.junit.Test)58 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)36 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)33 InfraActiveRequests (org.onap.so.db.request.beans.InfraActiveRequests)17 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)15 RequestInfo (org.onap.so.serviceinstancebeans.RequestInfo)15 IOException (java.io.IOException)11 BaseTest (org.onap.so.apihandlerinfra.BaseTest)11 CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)11 ValidationException (org.onap.so.exceptions.ValidationException)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ValidateException (org.onap.so.apihandlerinfra.exceptions.ValidateException)8 CloudConfigurationNotFoundException (org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException)8 Service (org.onap.so.db.catalog.beans.Service)8 ArrayList (java.util.ArrayList)7 RequestClientParameter (org.onap.so.apihandler.common.RequestClientParameter)7 ApiException (org.onap.so.apihandlerinfra.exceptions.ApiException)7 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)7 GenericVnf (org.onap.aai.domain.yang.GenericVnf)6