Search in sources :

Example 21 with CloudConfiguration

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

the class ServiceInstances method getCloudConfigurationOnReplace.

protected CloudConfiguration getCloudConfigurationOnReplace(String requestScope, HashMap<String, String> instanceIdMap, InfraActiveRequests currentActiveReq) throws ApiException {
    logger.debug("Replace request is missing cloudConfiguration, autofilling from create.");
    CloudConfiguration cloudConfiguration = null;
    if (requestScope.equals(ModelType.vfModule.toString())) {
        cloudConfiguration = bpmnRequestBuilder.getCloudConfigurationVfModuleReplace(instanceIdMap.get("vnfInstanceId"), instanceIdMap.get("vfModuleInstanceId"));
    } else {
        cloudConfiguration = bpmnRequestBuilder.mapCloudConfigurationVnf(instanceIdMap.get("vnfInstanceId"));
    }
    if (cloudConfiguration == null) {
        String errorMessage = "CloudConfiguration not found during autofill for replace request.";
        logger.error(errorMessage);
        updateStatus(currentActiveReq, Status.FAILED, errorMessage);
        throw new CloudConfigurationNotFoundException("CloudConfiguration not found during autofill for replace request.");
    }
    return cloudConfiguration;
}
Also used : CloudConfigurationNotFoundException(org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration)

Example 22 with CloudConfiguration

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

the class RequestHandlerUtils method addCloudConfig.

private Optional<CloudConfiguration> addCloudConfig(CloudConfiguration sourceCloudConfiguration) {
    CloudConfiguration targetConfiguration = new CloudConfiguration();
    if (sourceCloudConfiguration != null) {
        targetConfiguration.setAicNodeClli(sourceCloudConfiguration.getAicNodeClli());
        targetConfiguration.setTenantId(sourceCloudConfiguration.getTenantId());
        targetConfiguration.setLcpCloudRegionId(sourceCloudConfiguration.getLcpCloudRegionId());
        targetConfiguration.setCloudOwner(sourceCloudConfiguration.getCloudOwner());
        return Optional.of(targetConfiguration);
    }
    return Optional.empty();
}
Also used : CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration)

Example 23 with CloudConfiguration

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

the class RequestHandlerUtils method configureCloudConfig.

protected CloudConfiguration configureCloudConfig(RequestParameters reqParams) throws IOException {
    for (Map<String, Object> params : reqParams.getUserParams()) {
        if (params.containsKey("service")) {
            Service service = serviceMapper(params);
            Optional<CloudConfiguration> targetConfiguration = addCloudConfig(service.getCloudConfiguration());
            if (targetConfiguration.isPresent()) {
                return targetConfiguration.get();
            } else {
                for (Networks network : service.getResources().getNetworks()) {
                    targetConfiguration = addCloudConfig(network.getCloudConfiguration());
                    if (targetConfiguration.isPresent()) {
                        return targetConfiguration.get();
                    }
                }
                for (Vnfs vnf : service.getResources().getVnfs()) {
                    targetConfiguration = addCloudConfig(vnf.getCloudConfiguration());
                    if (targetConfiguration.isPresent()) {
                        return targetConfiguration.get();
                    }
                    for (VfModules vfModule : vnf.getVfModules()) {
                        targetConfiguration = addCloudConfig(vfModule.getCloudConfiguration());
                        if (targetConfiguration.isPresent()) {
                            return targetConfiguration.get();
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : Networks(org.onap.so.serviceinstancebeans.Networks) VfModules(org.onap.so.serviceinstancebeans.VfModules) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) Service(org.onap.so.serviceinstancebeans.Service) Vnfs(org.onap.so.serviceinstancebeans.Vnfs)

Example 24 with CloudConfiguration

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

the class ServiceInstances method serviceInstances.

public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri, HashMap<String, String> queryParams) throws ApiException {
    String serviceInstanceId;
    Boolean aLaCarte = null;
    ServiceInstancesRequest sir;
    String apiVersion = version.substring(1);
    sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
    action = handleReplaceInstance(action, sir);
    String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
    try {
        requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
    } catch (ApiException e) {
        msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, requestJSON, requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null), sir);
        throw e;
    }
    InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope);
    if (sir.getRequestDetails().getRequestParameters() != null) {
        aLaCarte = sir.getRequestDetails().getRequestParameters().getALaCarte();
    }
    requestHandlerUtils.parseRequest(sir, instanceIdMap, action, version, requestJSON, aLaCarte, requestId, currentActiveReq);
    if ((action == Action.replaceInstance || action == Action.replaceInstanceRetainAssignments) && (requestScope.equals(ModelType.vnf.toString()) || requestScope.equals(ModelType.vfModule.toString())) && sir.getRequestDetails().getCloudConfiguration() == null) {
        CloudConfiguration cloudConfiguration = getCloudConfigurationOnReplace(requestScope, instanceIdMap, currentActiveReq);
        sir.getRequestDetails().setCloudConfiguration(cloudConfiguration);
        setCloudConfigurationCurrentActiveRequest(cloudConfiguration, currentActiveReq);
    }
    requestHandlerUtils.setInstanceId(currentActiveReq, requestScope, null, instanceIdMap);
    String instanceName = null;
    if (sir.getRequestDetails().getRequestInfo() != null) {
        instanceName = sir.getRequestDetails().getRequestInfo().getInstanceName();
    }
    boolean alaCarteFlag = msoRequest.getAlacarteFlag(sir);
    String vnfType = msoRequest.getVnfType(sir, requestScope);
    String networkType = msoRequest.getNetworkType(sir, requestScope);
    String sdcServiceModelVersion = msoRequest.getSDCServiceModelVersion(sir);
    String vfModuleType = msoRequest.getVfModuleType(sir, requestScope);
    if (requestScope.equalsIgnoreCase(ModelType.vnf.name()) && vnfType != null) {
        currentActiveReq.setVnfType(vnfType);
    } else if (requestScope.equalsIgnoreCase(ModelType.network.name()) && networkType != null) {
        currentActiveReq.setNetworkType(networkType);
    }
    requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, instanceName);
    ServiceInstancesResponse serviceResponse = new ServiceInstancesResponse();
    RequestReferences referencesResponse = new RequestReferences();
    referencesResponse.setRequestId(requestId);
    serviceResponse.setRequestReferences(referencesResponse);
    RecipeLookupResult recipeLookupResult = requestHandlerUtils.getServiceInstanceOrchestrationURI(sir, action, alaCarteFlag, currentActiveReq);
    String serviceInstanceType = requestHandlerUtils.getServiceType(requestScope, sir, alaCarteFlag);
    ModelInfo modelInfo = sir.getRequestDetails().getModelInfo();
    ModelType modelType = requestHandlerUtils.getModelType(action, modelInfo);
    Boolean isBaseVfModule = false;
    if (modelType.equals(ModelType.vfModule)) {
        isBaseVfModule = requestHandlerUtils.getIsBaseVfModule(modelInfo, action, vnfType, sdcServiceModelVersion, currentActiveReq);
    }
    serviceInstanceId = requestHandlerUtils.setServiceInstanceId(requestScope, sir);
    String vnfId = "";
    String vfModuleId = "";
    String volumeGroupId = "";
    String networkId = "";
    String pnfCorrelationId = "";
    String instanceGroupId = null;
    if (sir.getVnfInstanceId() != null) {
        vnfId = sir.getVnfInstanceId();
    }
    if (sir.getVfModuleInstanceId() != null) {
        vfModuleId = sir.getVfModuleInstanceId();
    }
    if (sir.getVolumeGroupInstanceId() != null) {
        volumeGroupId = sir.getVolumeGroupInstanceId();
    }
    if (sir.getNetworkInstanceId() != null) {
        networkId = sir.getNetworkInstanceId();
    }
    if (sir.getInstanceGroupId() != null) {
        instanceGroupId = sir.getInstanceGroupId();
    }
    pnfCorrelationId = getPnfCorrelationId(sir);
    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();
    }
    if (!requestScope.equalsIgnoreCase(ModelType.service.name()) && action != Action.recreateInstance && !requestScope.equalsIgnoreCase(ModelType.vnf.name())) {
        aLaCarte = true;
    } else if (aLaCarte == null) {
        aLaCarte = false;
    }
    RequestClientParameter requestClientParameter;
    try {
        requestClientParameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(isBaseVfModule).setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.toString()).setServiceInstanceId(serviceInstanceId).setPnfCorrelationId(pnfCorrelationId).setVnfId(vnfId).setVfModuleId(vfModuleId).setVolumeGroupId(volumeGroupId).setNetworkId(networkId).setServiceType(serviceInstanceType).setVnfType(vnfType).setVfModuleType(vfModuleType).setNetworkType(networkType).setRequestDetails(requestHandlerUtils.mapJSONtoMSOStyle(requestJSON, sir, aLaCarte, action)).setApiVersion(apiVersion).setALaCarte(aLaCarte).setRequestUri(requestUri).setInstanceGroupId(instanceGroupId).build();
    } catch (IOException e) {
        logger.error("Exception occurred", e);
        ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
        throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo).build();
    }
    return requestHandlerUtils.postBPELRequest(currentActiveReq, requestClientParameter, recipeLookupResult.getOrchestrationURI(), requestScope);
}
Also used : ValidateException(org.onap.so.apihandlerinfra.exceptions.ValidateException) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) BpmnRequestBuilder(org.onap.so.apihandlerinfra.infra.rest.BpmnRequestBuilder) IOException(java.io.IOException) 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) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) ModelType(org.onap.so.serviceinstancebeans.ModelType) ServiceInstancesResponse(org.onap.so.serviceinstancebeans.ServiceInstancesResponse) RequestReferences(org.onap.so.serviceinstancebeans.RequestReferences) ApiException(org.onap.so.apihandlerinfra.exceptions.ApiException)

Example 25 with CloudConfiguration

use of org.onap.so.serviceinstancebeans.CloudConfiguration 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)

Aggregations

CloudConfiguration (org.onap.so.serviceinstancebeans.CloudConfiguration)42 Test (org.junit.Test)28 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)15 ResourceKey (org.onap.so.bpmn.servicedecomposition.entities.ResourceKey)15 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)15 HashMap (java.util.HashMap)13 Service (org.onap.so.db.catalog.beans.Service)13 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)13 File (java.io.File)12 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)12 ModelInfoServiceInstance (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance)12 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)11 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)11 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)10 ModelInfoGenericVnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf)9 L3Network (org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network)8 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)8 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)7 ConfigurationResourceKeys (org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys)7 CloudConfigurationNotFoundException (org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException)6