Search in sources :

Example 6 with PayloadGenerationException

use of org.onap.so.client.exception.PayloadGenerationException 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 7 with PayloadGenerationException

use of org.onap.so.client.exception.PayloadGenerationException 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 8 with PayloadGenerationException

use of org.onap.so.client.exception.PayloadGenerationException in project so by onap.

the class GeneratePayloadForCds method buildCdsPropertiesBean.

/**
 * Build properties like (blueprint name, version, action etc..) along with the request payload for pnf.
 *
 * @param execution - A building block execution object.
 * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
 * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
 */
public AbstractCDSPropertiesBean buildCdsPropertiesBean(DelegateExecution execution) throws PayloadGenerationException {
    final String scope = String.valueOf(execution.getVariable(PayloadConstants.SCOPE));
    final String action = String.valueOf(execution.getVariable(PayloadConstants.ACTION));
    final String requestId = String.valueOf(execution.getVariable(MSO_REQUEST_ID));
    final String mode = extractAndSetMode(execution);
    CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
    requestProvider.setExecutionObject(execution);
    final String requestPayload = requestProvider.buildRequestPayload(action).orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
    return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, mode);
}
Also used : PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Example 9 with PayloadGenerationException

use of org.onap.so.client.exception.PayloadGenerationException in project so by onap.

the class GeneratePayloadForCds method buildCdsPropertiesBean.

/**
 * Build properties like (blueprint name, version, action etc..) along with the request payload for vnf, vf-module
 * and service.
 *
 * @param execution - A building block execution object.
 * @return AbstractCDSPropertiesBean - A POJO which contains CDS related information.
 * @throws PayloadGenerationException - Throw an exception if it fails to build payload for CDS.
 */
public AbstractCDSPropertiesBean buildCdsPropertiesBean(BuildingBlockExecution execution) throws PayloadGenerationException {
    ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
    BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
    final String requestId = execution.getGeneralBuildingBlock().getRequestContext().getMsoRequestId();
    final String scope = buildingBlock.getBpmnScope();
    final String action = buildingBlock.getBpmnAction();
    CDSRequestProvider requestProvider = getRequestProviderByScope(scope);
    requestProvider.setExecutionObject(execution);
    final String requestPayload = requestProvider.buildRequestPayload(action).orElseThrow(() -> new PayloadGenerationException("Failed to build payload for CDS"));
    return prepareAndSetCdsPropertyBean(requestProvider, requestPayload, requestId, action, DEFAULT_SYNC_MODE);
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Example 10 with PayloadGenerationException

use of org.onap.so.client.exception.PayloadGenerationException in project so by onap.

the class VfModuleCDSRequestProvider method buildRequestPayload.

@Override
public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
    JsonObject cdsPropertyObject = new JsonObject();
    JsonObject vfModuleObject = new JsonObject();
    String vfModuleName;
    try {
        ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
        GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        final String modelCustomizationUuidForVnf = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
        blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName();
        blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion();
        VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
        vfModuleName = vfModule.getVfModuleName();
        final String modelCustomizationUuidForVfModule = vfModule.getModelInfoVfModule().getModelCustomizationUUID();
        vfModuleObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
        vfModuleObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
        vfModuleObject.addProperty("vnf-id", genericVnf.getVnfId());
        vfModuleObject.addProperty("vnf-name", genericVnf.getVnfName());
        vfModuleObject.addProperty("vf-module-id", vfModule.getVfModuleId());
        vfModuleObject.addProperty("vf-module-name", vfModule.getVfModuleName());
        vfModuleObject.addProperty("vf-module-customization-uuid", vfModule.getModelInfoVfModule().getModelCustomizationUUID());
        final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
        List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams();
        String vfModuleInstanceName = execution.getLookupMap().getOrDefault(ResourceKey.VF_MODULE_INSTANCE_NAME, "");
        if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
            configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule, vfModuleInstanceName);
        }
    } catch (Exception e) {
        throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e);
    }
    // Not sure for resolutionKey should be same as vfModule name.
    cdsPropertyObject.addProperty("resolution-key", vfModuleName);
    cdsPropertyObject.addProperty("template-prefix", vfModuleName + action);
    cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vfModuleObject);
    return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
}
Also used : GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) JsonObject(com.google.gson.JsonObject) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) Map(java.util.Map) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Aggregations

PayloadGenerationException (org.onap.so.client.exception.PayloadGenerationException)12 Map (java.util.Map)7 JsonObject (com.google.gson.JsonObject)4 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)4 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)4 Service (org.onap.so.serviceinstancebeans.Service)4 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Pnf (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf)1 VfModule (org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule)1 BuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock)1 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)1 ConfigureInstanceParamsForPnf (org.onap.so.client.cds.ConfigureInstanceParamsForPnf)1 BBObjectNotFoundException (org.onap.so.client.exception.BBObjectNotFoundException)1 VfModules (org.onap.so.serviceinstancebeans.VfModules)1 Vnfs (org.onap.so.serviceinstancebeans.Vnfs)1