use of org.onap.so.serviceinstancebeans.Service in project so by onap.
the class RequestHandlerUtils method configureUserParams.
protected List<Map<String, Object>> configureUserParams(RequestParameters reqParams) throws IOException {
logger.debug("Configuring UserParams for Macro Request");
Map<String, Object> userParams = new HashMap<>();
for (Map<String, Object> params : reqParams.getUserParams()) {
if (params.containsKey("service")) {
Service service = serviceMapper(params);
addUserParams(userParams, service.getInstanceParams());
for (Networks network : service.getResources().getNetworks()) {
addUserParams(userParams, network.getInstanceParams());
}
for (Vnfs vnf : service.getResources().getVnfs()) {
addUserParams(userParams, vnf.getInstanceParams());
for (VfModules vfModule : vnf.getVfModules()) {
addUserParams(userParams, vfModule.getInstanceParams());
}
}
}
}
return mapFlatMapToNameValue(userParams);
}
use of org.onap.so.serviceinstancebeans.Service in project so by onap.
the class RequestHandlerUtils method getServiceURI.
protected RecipeLookupResult getServiceURI(ServiceInstancesRequest servInstReq, Actions action, boolean alaCarteFlag) throws IOException {
// SERVICE REQUEST
// Construct the default service name
// TODO need to make this a configurable property
String defaultServiceModelName = getDefaultModel(servInstReq);
RequestDetails requestDetails = servInstReq.getRequestDetails();
ModelInfo modelInfo = requestDetails.getModelInfo();
org.onap.so.db.catalog.beans.Service serviceRecord;
List<org.onap.so.db.catalog.beans.Service> serviceRecordList;
ServiceRecipe recipe = null;
if (alaCarteFlag) {
serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
if (serviceRecord != null) {
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
}
} else {
serviceRecord = catalogDbClient.getServiceByID(modelInfo.getModelVersionId());
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(modelInfo.getModelVersionId(), action.toString());
if (recipe == null) {
serviceRecordList = catalogDbClient.getServiceByModelInvariantUUIDOrderByModelVersionDesc(modelInfo.getModelInvariantId());
if (!serviceRecordList.isEmpty()) {
for (org.onap.so.db.catalog.beans.Service record : serviceRecordList) {
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(record.getModelUUID(), action.toString());
if (recipe != null) {
break;
}
}
}
}
}
// if an aLaCarte flag was sent in the request, throw an error if the recipe was not found
RequestParameters reqParam = requestDetails.getRequestParameters();
if (reqParam != null && alaCarteFlag && recipe == null) {
return null;
} else if (!alaCarteFlag && recipe != null && Action.createInstance.equals(action)) {
mapToLegacyRequest(requestDetails);
} else if (recipe == null) {
// aLaCarte wasn't sent, so we'll try the default
serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
}
if (modelInfo.getModelVersionId() == null) {
modelInfo.setModelVersionId(serviceRecord.getModelUUID());
}
if (recipe == null) {
return null;
}
return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout());
}
use of org.onap.so.serviceinstancebeans.Service 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.serviceinstancebeans.Service in project so by onap.
the class ConfigureInstanceParamsForVfModuleTest 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();
configureInstanceParamsForVfModule.populateInstanceParams(jsonObject, new ArrayList<>(), VNF_CUSTOMIZATION_ID, VFMODULE_2_CUSTOMIZATION_ID, VFMODULE_2_INSTANCE_NAME);
assertEquals("abc", jsonObject.get("param-1").getAsString());
assertEquals("999", jsonObject.get("param-2").getAsString());
assertEquals("AAA", jsonObject.get("param-3").getAsString());
}
use of org.onap.so.serviceinstancebeans.Service 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);
}
}
Aggregations