use of org.onap.so.db.catalog.beans.ServiceRecipe 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.db.catalog.beans.ServiceRecipe in project so by onap.
the class Onap3gppServiceInstances method getServiceURI.
/**
* Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe.
*
* @param serviceModelUUID the service version uuid
* @param action the action of the service.
* @param defaultServiceModelName default service name
* @return the service recipe result.
*/
private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action, String defaultServiceModelName) {
Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
// set recipe as default generic recipe
ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
// check the service special recipe
if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) {
ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name());
if (null != serviceSpecialRecipe) {
// set service special recipe.
recipe = serviceSpecialRecipe;
}
}
if (recipe == null) {
return null;
}
return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd());
}
use of org.onap.so.db.catalog.beans.ServiceRecipe in project so by onap.
the class ServiceIntentApiHandler method getServiceURI.
/**
* Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe.
*
* @param serviceModelUUID the service version uuid
* @param action the action of the service.
* @param defaultServiceModelName default service name
* @return the service recipe result.
*/
private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action, String defaultServiceModelName) {
Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
// set recipe as default generic recipe
ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
// check the service special recipe
if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) {
ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name());
if (null != serviceSpecialRecipe) {
// set service special recipe.
recipe = serviceSpecialRecipe;
}
}
if (recipe == null) {
return null;
}
return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd());
}
use of org.onap.so.db.catalog.beans.ServiceRecipe in project so by onap.
the class E2EServiceInstances method getServiceURI.
/**
* Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe.
*
* @param serviceModelUUID the service version uuid
* @param action the action of the service.
* @return the service recipe result.
*/
private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action) {
String defaultServiceModelName = "UUI_DEFAULT";
Service defaultServiceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
// set recipe as default generic recipe
ServiceRecipe recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name());
// check the service special recipe
if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) {
ServiceRecipe serviceSpecialRecipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name());
if (null != serviceSpecialRecipe) {
// set service special recipe.
recipe = serviceSpecialRecipe;
}
}
if (recipe == null) {
return null;
}
return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd());
}
use of org.onap.so.db.catalog.beans.ServiceRecipe in project so by onap.
the class CatalogDBRestTest method testCreateServiceRecipe.
@Test
public void testCreateServiceRecipe() throws JSONException {
ServiceRecipe recipe = new ServiceRecipe();
recipe.setAction("action");
recipe.setDescription("description");
recipe.setOrchestrationUri("http://test");
recipe.setRecipeTimeout(120);
recipe.setServiceModelUUID(serviceUUID);
HttpEntity<ServiceRecipe> entity = new HttpEntity<ServiceRecipe>(recipe, headers);
headers.set("Accept", MediaType.APPLICATION_JSON);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(SERVICE_RECIPE));
ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), HttpMethod.POST, entity, String.class);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusCode().value());
}
Aggregations