Search in sources :

Example 6 with Service

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

the class RequestHandlerUtils method configureUserParams.

protected List<Map<String, Object>> configureUserParams(RequestParameters reqParams) throws IOException {
    logger.debug("Configuring UserParams for Macro Request");
    Map<String, Object> userParams = new HashMap<>();
    for (Map<String, Object> params : reqParams.getUserParams()) {
        if (params.containsKey("service")) {
            Service service = serviceMapper(params);
            addUserParams(userParams, service.getInstanceParams());
            for (Networks network : service.getResources().getNetworks()) {
                addUserParams(userParams, network.getInstanceParams());
            }
            for (Vnfs vnf : service.getResources().getVnfs()) {
                addUserParams(userParams, vnf.getInstanceParams());
                for (VfModules vfModule : vnf.getVfModules()) {
                    addUserParams(userParams, vfModule.getInstanceParams());
                }
            }
        }
    }
    return mapFlatMapToNameValue(userParams);
}
Also used : Networks(org.onap.so.serviceinstancebeans.Networks) VfModules(org.onap.so.serviceinstancebeans.VfModules) HashMap(java.util.HashMap) Service(org.onap.so.serviceinstancebeans.Service) Vnfs(org.onap.so.serviceinstancebeans.Vnfs)

Example 7 with Service

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

the class RequestHandlerUtils method getServiceURI.

protected RecipeLookupResult getServiceURI(ServiceInstancesRequest servInstReq, Actions action, boolean alaCarteFlag) throws IOException {
    // SERVICE REQUEST
    // Construct the default service name
    // TODO need to make this a configurable property
    String defaultServiceModelName = getDefaultModel(servInstReq);
    RequestDetails requestDetails = servInstReq.getRequestDetails();
    ModelInfo modelInfo = requestDetails.getModelInfo();
    org.onap.so.db.catalog.beans.Service serviceRecord;
    List<org.onap.so.db.catalog.beans.Service> serviceRecordList;
    ServiceRecipe recipe = null;
    if (alaCarteFlag) {
        serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
        if (serviceRecord != null) {
            recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
        }
    } else {
        serviceRecord = catalogDbClient.getServiceByID(modelInfo.getModelVersionId());
        recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(modelInfo.getModelVersionId(), action.toString());
        if (recipe == null) {
            serviceRecordList = catalogDbClient.getServiceByModelInvariantUUIDOrderByModelVersionDesc(modelInfo.getModelInvariantId());
            if (!serviceRecordList.isEmpty()) {
                for (org.onap.so.db.catalog.beans.Service record : serviceRecordList) {
                    recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(record.getModelUUID(), action.toString());
                    if (recipe != null) {
                        break;
                    }
                }
            }
        }
    }
    // if an aLaCarte flag was sent in the request, throw an error if the recipe was not found
    RequestParameters reqParam = requestDetails.getRequestParameters();
    if (reqParam != null && alaCarteFlag && recipe == null) {
        return null;
    } else if (!alaCarteFlag && recipe != null && Action.createInstance.equals(action)) {
        mapToLegacyRequest(requestDetails);
    } else if (recipe == null) {
        // aLaCarte wasn't sent, so we'll try the default
        serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
        recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
    }
    if (modelInfo.getModelVersionId() == null) {
        modelInfo.setModelVersionId(serviceRecord.getModelUUID());
    }
    if (recipe == null) {
        return null;
    }
    return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout());
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Service(org.onap.so.serviceinstancebeans.Service) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters)

Example 8 with Service

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

the class ConfigureInstanceParamsForService method populateInstanceParams.

/**
 * Read instance parameters for Service and put into JsonObject.
 *
 * @param jsonObject - JsonObject which will hold the payload to send to CDS.
 * @param userParamsFromRequest - User parameters.
 * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload.
 */
public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest) throws PayloadGenerationException {
    try {
        Optional<Service> service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
        service.map(Service::getInstanceParams).ifPresent(p -> applyParamsToObject(p, jsonObject));
    } catch (Exception e) {
        throw new PayloadGenerationException("Failed to resolve instance parameters", e);
    }
}
Also used : Service(org.onap.so.serviceinstancebeans.Service) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Example 9 with Service

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

the class ConfigureInstanceParamsForVfModuleTest method testPopulateInstanceParamsByInstanceName.

@Test
public void testPopulateInstanceParamsByInstanceName() throws Exception {
    Service service = new Service();
    Resources resources = new Resources();
    resources.setVnfs(createVnfs());
    service.setResources(resources);
    when(extractServiceFromUserParameters.getServiceFromRequestUserParams(any())).thenReturn(Optional.of(service));
    JsonObject jsonObject = new JsonObject();
    configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, VFMODULE_2_CUSTOMIZATION_ID, VFMODULE_2_INSTANCE_NAME);
    assertEquals("abc", jsonObject.get("param-1").getAsString());
    assertEquals("999", jsonObject.get("param-2").getAsString());
    assertEquals("AAA", jsonObject.get("param-3").getAsString());
}
Also used : Service(org.onap.so.serviceinstancebeans.Service) JsonObject(com.google.gson.JsonObject) Resources(org.onap.so.serviceinstancebeans.Resources) Test(org.junit.Test)

Example 10 with Service

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

the class ConfigureInstanceParamsForVnf method populateInstanceParams.

/**
 * Read instance parameters for VNF and put into JsonObject.
 *
 * @param jsonObject - JsonObject which will hold the payload to send to CDS.
 * @param userParamsFromRequest - User parameters.
 * @param modelCustomizationUuid - Unique ID for Vnf.
 * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload.
 */
public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, String modelCustomizationUuid, String vnfInstanceName) throws PayloadGenerationException {
    try {
        Optional<Service> service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
        if (service.isPresent()) {
            List<Map<String, String>> instanceParamsList;
            if (StringUtils.isNotBlank(vnfInstanceName)) {
                instanceParamsList = getInstanceParamByVnfInstanceName(service.get(), vnfInstanceName);
            } else {
                instanceParamsList = getInstanceParamForVnf(service.get(), modelCustomizationUuid);
            }
            applyParamsToObject(instanceParamsList, jsonObject);
        }
    } catch (Exception e) {
        throw new PayloadGenerationException("Failed to resolve instance parameters", e);
    }
}
Also used : Service(org.onap.so.serviceinstancebeans.Service) Map(java.util.Map) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Aggregations

Service (org.onap.so.serviceinstancebeans.Service)19 Resources (org.onap.so.serviceinstancebeans.Resources)7 JsonObject (com.google.gson.JsonObject)4 Map (java.util.Map)4 Test (org.junit.Test)4 PayloadGenerationException (org.onap.so.client.exception.PayloadGenerationException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Networks (org.onap.so.serviceinstancebeans.Networks)3 VfModules (org.onap.so.serviceinstancebeans.VfModules)3 Vnfs (org.onap.so.serviceinstancebeans.Vnfs)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 RequestParameters (org.onap.so.serviceinstancebeans.RequestParameters)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Actions (org.onap.so.apihandlerinfra.Actions)1 ApplyUpdatedConfigValidation (org.onap.so.apihandlerinfra.validation.ApplyUpdatedConfigValidation)1 CloudConfigurationValidation (org.onap.so.apihandlerinfra.validation.CloudConfigurationValidation)1 ConfigurationParametersValidation (org.onap.so.apihandlerinfra.validation.ConfigurationParametersValidation)1 CustomWorkflowValidation (org.onap.so.apihandlerinfra.validation.CustomWorkflowValidation)1