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