Search in sources :

Example 1 with PayloadGenerationException

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

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

the class ConfigureInstanceParamsForVfModule method getInstanceParams.

private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException {
    Vnfs foundedVnf = service.getResources().getVnfs().stream().filter(vnfs -> vnfs.getModelInfo().getModelCustomizationId().equals(vnfCustomizationUuid)).findFirst().orElseThrow(() -> new PayloadGenerationException(String.format("Can not find vnf for genericVnfModelCustomizationUuid: %s", vnfCustomizationUuid)));
    VfModules vfModule = foundedVnf.getVfModules().stream().filter(vfModules -> vfModules.getModelInfo().getModelCustomizationId().equals(vfModuleCustomizationUuid)).findFirst().orElseThrow(() -> new PayloadGenerationException(String.format("Can not find vnf for vfModuleCustomizationUuid: %s", vfModuleCustomizationUuid)));
    return vfModule.getInstanceParams();
}
Also used : VfModules(org.onap.so.serviceinstancebeans.VfModules) Vnfs(org.onap.so.serviceinstancebeans.Vnfs) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Example 3 with PayloadGenerationException

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

Example 4 with PayloadGenerationException

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

the class ServiceCDSRequestProvider method buildRequestPayload.

@Override
public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
    JsonObject cdsPropertyObject = new JsonObject();
    JsonObject serviceObject = new JsonObject();
    try {
        ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getServiceInstance();
        bluePrintName = serviceInstance.getModelInfoServiceInstance().getBlueprintName();
        bluePrintVersion = serviceInstance.getModelInfoServiceInstance().getBlueprintVersion();
        resolutionKey = serviceInstance.getServiceInstanceName();
        serviceObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
        serviceObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
        final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
        List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams();
        if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
            configureInstanceParamsForService.populateInstanceParams(serviceObject, userParamsFromRequest);
        }
    } catch (Exception e) {
        throw new PayloadGenerationException("Failed to buildPropertyObjectForService", e);
    }
    cdsPropertyObject.addProperty("resolution-key", resolutionKey);
    cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, serviceObject);
    return Optional.of(buildRequestJsonObject(cdsPropertyObject, action));
}
Also used : GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) JsonObject(com.google.gson.JsonObject) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) Map(java.util.Map) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException) PayloadGenerationException(org.onap.so.client.exception.PayloadGenerationException)

Example 5 with PayloadGenerationException

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

the class VnfCDSRequestProvider method buildRequestPayload.

@Override
public Optional<String> buildRequestPayload(String action) throws PayloadGenerationException {
    JsonObject cdsPropertyObject = new JsonObject();
    JsonObject vnfObject = new JsonObject();
    String resolutionKey;
    try {
        ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
        GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
        final String modelCustomizationUuid = genericVnf.getModelInfoGenericVnf().getModelCustomizationUuid();
        resolutionKey = genericVnf.getVnfName();
        blueprintName = genericVnf.getModelInfoGenericVnf().getBlueprintName();
        blueprintVersion = genericVnf.getModelInfoGenericVnf().getBlueprintVersion();
        vnfObject.addProperty("service-instance-id", serviceInstance.getServiceInstanceId());
        vnfObject.addProperty("service-model-uuid", serviceInstance.getModelInfoServiceInstance().getModelUuid());
        vnfObject.addProperty("vnf-id", genericVnf.getVnfId());
        vnfObject.addProperty("vnf-name", genericVnf.getVnfName());
        vnfObject.addProperty("vnf-customization-uuid", modelCustomizationUuid);
        final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock();
        List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams();
        String vnfInstanceName = execution.getLookupMap().getOrDefault(ResourceKey.VNF_INSTANCE_NAME, "");
        if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) {
            configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, modelCustomizationUuid, vnfInstanceName);
        }
    } catch (Exception e) {
        throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e);
    }
    cdsPropertyObject.addProperty("resolution-key", resolutionKey);
    cdsPropertyObject.add(action + SEPARATOR + PROPERTIES, vnfObject);
    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) 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