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