Search in sources :

Example 11 with Service

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

the class ConfigureInstanceParamsForPnf method populateInstanceParams.

/**
 * Read instance parameters for PNF 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 Pnf.
 * @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) throws PayloadGenerationException {
    try {
        Optional<Service> service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
        if (service.isPresent()) {
            List<Map<String, String>> instanceParamsList = getInstanceParamForPnf(service.get(), modelCustomizationUuid);
            applyParamsToObject(instanceParamsList, jsonObject);
        }
    } catch (Exception exception) {
        throw new PayloadGenerationException("Failed to resolve instance parameters", exception);
    }
}
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)

Example 12 with Service

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

the class ConfigureInstanceParamsForVfModule method populateInstanceParams.

/**
 * Read instance parameters for VF-Module and put into JsonObject.
 *
 * @param jsonObject- JsonObject which will hold the payload to send to CDS.
 * @param userParamsFromRequest - User parameters for a vf-module
 * @param vnfCustomizationUuid - Unique ID for vnf.
 * @param vfModuleCustomizationUuid - Unique ID for vf-module.
 * @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 vnfCustomizationUuid, String vfModuleCustomizationUuid, String vfModuleInstanceName) throws PayloadGenerationException {
    try {
        Optional<Service> service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
        if (service.isPresent()) {
            List<Map<String, String>> instanceParamsList;
            if (StringUtils.isNotBlank(vfModuleInstanceName)) {
                instanceParamsList = getInstanceParamsByInstanceNames(service.get(), vfModuleInstanceName);
            } else {
                instanceParamsList = getInstanceParams(service.get(), vnfCustomizationUuid, vfModuleCustomizationUuid);
            }
            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)

Example 13 with Service

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

the class ConfigureInstanceParamsForVfModuleTest method testPopulateInstanceParamsByCustomizationId.

@Test
public void testPopulateInstanceParamsByCustomizationId() 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();
    // No instance name is passed
    configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, VFMODULE_1_CUSTOMIZATION_ID, null);
    assertEquals("xyz", jsonObject.get("param-1").getAsString());
    assertEquals("123", jsonObject.get("param-2").getAsString());
    assertEquals("CCC", 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 14 with Service

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

the class ConfigureInstanceParamsForVnfTest method testPopulateInstanceParamsByCustomizationId.

@Test
public void testPopulateInstanceParamsByCustomizationId() 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();
    // No instance name is passed
    configureInstanceParamsForVnf.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_1_CUSTOMIZATION_ID, null);
    assertEquals("xyz", jsonObject.get("param-1").getAsString());
    assertEquals("123", jsonObject.get("param-2").getAsString());
    assertEquals("CCC", 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 15 with Service

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

the class ConfigureInstanceParamsForVnfTest 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();
    configureInstanceParamsForVnf.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_2_CUSTOMIZATION_ID, VNF_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)

Aggregations

Service (org.onap.so.serviceinstancebeans.Service)19 Resources (org.onap.so.serviceinstancebeans.Resources)7 Map (java.util.Map)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JsonObject (com.google.gson.JsonObject)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 PayloadGenerationException (org.onap.so.client.exception.PayloadGenerationException)3 Networks (org.onap.so.serviceinstancebeans.Networks)3 RequestParameters (org.onap.so.serviceinstancebeans.RequestParameters)3 VfModules (org.onap.so.serviceinstancebeans.VfModules)3 Vnfs (org.onap.so.serviceinstancebeans.Vnfs)3 HashMap (java.util.HashMap)2 Set (java.util.Set)2 ServiceRecipe (org.onap.so.db.catalog.beans.ServiceRecipe)2 ValidationException (org.onap.so.exceptions.ValidationException)2 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)2 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)2 Include (com.fasterxml.jackson.annotation.JsonInclude.Include)1 IOException (java.io.IOException)1