Search in sources :

Example 1 with QueryResourceRecipe

use of org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe in project so by onap.

the class CatalogDbAdapterRest method resourceRecipe.

/**
 * Get the resource recipe info from catalog <br>
 *
 * @param rmUuid resource model uuid
 * @return the recipe information of the resource.
 * @since ONAP Beijing Release
 */
@GET
@Path("resourceRecipe")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
    int respStatus = HttpStatus.SC_OK;
    String entity = "";
    try {
        if (rmUuid != null && !"".equals(rmUuid)) {
            logger.debug("Query recipe by resource model uuid: {}", rmUuid);
            // check vnf and network and ar, the resource could be any resource.
            Recipe recipe = null;
            VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
            if (vnf != null) {
                recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion());
                // for network service fetch the default recipe
                if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
                }
            }
            if (null == recipe) {
                NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
                if (nResource != null) {
                    recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, nResource.getModelVersion());
                    // for network fetch the default recipe
                    if (recipe == null) {
                        recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
                    }
                }
            }
            if (null == recipe) {
                AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
                if (arResource != null) {
                    recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion());
                }
            }
            if (null == recipe) {
                InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
                if (grpResource != null) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(grpResource.getModelName(), action, grpResource.getModelVersion());
                }
            }
            if (recipe != null) {
                QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
                entity = resourceRecipe.JSON2(false, false);
            } else {
                respStatus = HttpStatus.SC_NOT_FOUND;
            }
        } else {
            throw new Exception("Incoming parameter is null or blank");
        }
        return Response.status(respStatus).entity(entity).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception during query recipe by resource model uuid: ", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
}
Also used : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfResource(org.onap.so.db.catalog.beans.VnfResource) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) Recipe(org.onap.so.db.catalog.beans.Recipe) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)1 QueryResourceRecipe (org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe)1 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)1 InstanceGroup (org.onap.so.db.catalog.beans.InstanceGroup)1 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)1 Recipe (org.onap.so.db.catalog.beans.Recipe)1 VnfRecipe (org.onap.so.db.catalog.beans.VnfRecipe)1 VnfResource (org.onap.so.db.catalog.beans.VnfResource)1