Search in sources :

Example 6 with ServiceRecipe

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());
}
Also used : ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Service(org.onap.so.serviceinstancebeans.Service) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) RequestParameters(org.onap.so.serviceinstancebeans.RequestParameters)

Example 7 with ServiceRecipe

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());
}
Also used : Service(org.onap.so.db.catalog.beans.Service) DeAllocate3gppService(org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.DeAllocate3gppService) Modify3gppService(org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Modify3gppService) ActivateOrDeactivate3gppService(org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.ActivateOrDeactivate3gppService) Allocate3gppService(org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Allocate3gppService) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe)

Example 8 with ServiceRecipe

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());
}
Also used : Service(org.onap.so.db.catalog.beans.Service) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe)

Example 9 with ServiceRecipe

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());
}
Also used : Service(org.onap.so.db.catalog.beans.Service) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe)

Example 10 with ServiceRecipe

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());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServiceRecipe(org.onap.so.db.catalog.beans.ServiceRecipe) Test(org.junit.Test) CatalogDbAdapterBaseTest(org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)

Aggregations

ServiceRecipe (org.onap.so.db.catalog.beans.ServiceRecipe)36 Test (org.junit.Test)27 Service (org.onap.so.db.catalog.beans.Service)24 RequestReferences (org.onap.so.serviceinstancebeans.RequestReferences)10 ServiceInstancesResponse (org.onap.so.serviceinstancebeans.ServiceInstancesResponse)10 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)5 RequestError (org.onap.so.serviceinstancebeans.RequestError)5 Before (org.junit.Before)3 Recipe (org.onap.so.db.catalog.beans.Recipe)3 HttpEntity (org.springframework.http.HttpEntity)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 ActivateOrDeactivate3gppService (org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.ActivateOrDeactivate3gppService)1 Allocate3gppService (org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Allocate3gppService)1 DeAllocate3gppService (org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.DeAllocate3gppService)1 Modify3gppService (org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Modify3gppService)1 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)1 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)1 RequestParameters (org.onap.so.serviceinstancebeans.RequestParameters)1 Service (org.onap.so.serviceinstancebeans.Service)1 HttpHeaders (org.springframework.http.HttpHeaders)1