From: Chuanyu Chen Date: Wed, 7 Mar 2018 07:21:01 +0000 (+0000) Subject: Merge "Support resource recipe query rest" X-Git-Tag: v1.2.1~498 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=0faf120de696415e565b8f9de3b3d26d3ad406ea;p=so.git Merge "Support resource recipe query rest" --- 0faf120de696415e565b8f9de3b3d26d3ad406ea diff --cc adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java index cd6522b487,bcf2ab3b30..d0d3999cf4 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java @@@ -481,38 -482,93 +483,92 @@@ public class CatalogDbAdapterRest @GET @Path("serviceToscaCsar") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - public Response ServiceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) { + public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) { int respStatus = HttpStatus.SC_OK; - CatalogDatabase db = CatalogDatabase.getInstance(); String entity = ""; - try{ - if(smUuid != null && !"".equals(smUuid)){ - LOGGER.debug ("Query Csar by service model uuid: " + smUuid); + try (CatalogDatabase db = CatalogDatabase.getInstance()) { + if (smUuid != null && !"".equals(smUuid)) { + LOGGER.debug("Query Csar by service model uuid: " + smUuid); ToscaCsar toscaCsar = db.getToscaCsarByServiceModelUUID(smUuid); - if(toscaCsar != null){ + if (toscaCsar != null) { QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar); entity = serviceCsar.JSON2(false, false); - } - else{ + } else { respStatus = HttpStatus.SC_NOT_FOUND; } - }else{ - throw(new Exception("Incoming parameter is null or blank")); - } - LOGGER.debug ("Query Csar exit"); + } else { + throw (new Exception("Incoming parameter is null or blank")); + } + LOGGER.debug("Query Csar exit"); return Response - .status(respStatus) - .entity(entity) - .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .build(); - }catch(Exception e){ - LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar", MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service model uuid: ", e); - CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null); + .status(respStatus) + .entity(entity) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .build(); + } catch (Exception e) { + LOGGER.error(MessageEnum.RA_QUERY_VNF_ERR, smUuid, "", "ServiceToscaCsar", + MsoLogger.ErrorCode.BusinessProcesssError, "Exception during query csar by service 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(excResp) {}) - .build(); - }finally { - db.close(); + .status(HttpStatus.SC_INTERNAL_SERVER_ERROR) + .entity(new GenericEntity(excResp) { + }) + .build(); } } + + /** + * Get the resource recipe info from catalog + *
+ * + * @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; + CatalogDatabase db = CatalogDatabase.getInstance(); + 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 = db.getVnfRecipeByModuleUuid(rmUuid, action); + if(null == recipe){ + recipe = db.getNetworkRecipeByModuleUuid(rmUuid, action); + } + if(null == recipe){ + recipe = db.getArRecipeByModuleUuid(rmUuid, action); + } + 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")); + } + LOGGER.debug ("Query recipe exit"); + return Response + .status(respStatus) + .entity(entity) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .build(); + }catch(Exception e){ + LOGGER.error (MessageEnum.RA_QUERY_VNF_ERR, rmUuid, "", "resourceRecipe", MsoLogger.ErrorCode.BusinessProcesssError, "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(excResp) {}) + .build(); + }finally { + db.close(); + } + } }