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);
}
}
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);
}
}
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);
}
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);
}
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));
}
Aggregations