import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryException;
import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQueryExceptionCategory;
import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryAllottedResourceCustomization;
+import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryResourceRecipe;
import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceCsar;
import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceMacroHolder;
import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryServiceNetworks;
import org.openecomp.mso.db.catalog.CatalogDatabase;
import org.openecomp.mso.db.catalog.beans.AllottedResourceCustomization;
import org.openecomp.mso.db.catalog.beans.NetworkResourceCustomization;
+import org.openecomp.mso.db.catalog.beans.Recipe;
import org.openecomp.mso.db.catalog.beans.ServiceMacroHolder;
import org.openecomp.mso.db.catalog.beans.ToscaCsar;
import org.openecomp.mso.db.catalog.beans.VfModuleCustomization;
@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 = "";
db.close();
}
}
+
+ /**
+ * 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;
+ 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<CatalogQueryException>(excResp) {})
+ .build();
+ }finally {
+ db.close();
+ }
+ }
}
--- /dev/null
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+package org.openecomp.mso.adapters.catalogdb.catalogrest;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.openecomp.mso.db.catalog.beans.Recipe;\r
+\r
+/**\r
+ * serivce csar query support \r
+ * <br>\r
+ * <p>\r
+ * </p>\r
+ * \r
+ * @author\r
+ * @version ONAP Beijing Release 2018-02-28\r
+ */\r
+public class QueryResourceRecipe extends CatalogQuery{\r
+ \r
+ private Recipe resourceRecipe;\r
+ \r
+ public QueryResourceRecipe(Recipe resourceRecipe){\r
+ this.resourceRecipe =resourceRecipe;\r
+ }\r
+\r
+ private final String template =\r
+ "\t{\n"+\r
+ "\t\t\"id\" : <ID>,\n"+\r
+ "\t\t\"action\" : <ACTION>,\n"+\r
+ "\t\t\"orchestrationUri\" : <ORCHESTRATION_URI>,\n"+\r
+ "\t\t\"recipeTimeout\" : <RECIPE_TIMEOUT>,\n"+\r
+ "\t\t\"paramXSD\" : <PARAM_XSD>,\n"+\r
+ "\t\t\"description\" : <DESCRIPTION>\n"+\r
+ "\t}";\r
+ \r
+ @Override\r
+ public String toString() {\r
+\r
+ return resourceRecipe.toString();\r
+ }\r
+\r
+ @Override\r
+ public String JSON2(boolean isArray, boolean isEmbed) {\r
+ Map<String, String> valueMap = new HashMap<>();\r
+ put(valueMap, "ID", null == resourceRecipe ? null : resourceRecipe.getId());\r
+ put(valueMap, "ACTION", null == resourceRecipe ? null : resourceRecipe.getAction());\r
+ put(valueMap, "ORCHESTRATION_URI", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());\r
+ put(valueMap, "RECIPE_TIMEOUT", null == resourceRecipe ? null : resourceRecipe.getRecipeTimeout());\r
+ put(valueMap, "PARAM_XSD", null == resourceRecipe ? null : resourceRecipe.getParamXSD());\r
+ put(valueMap, "DESCRIPTION", null == resourceRecipe ? null : resourceRecipe.getDescription());\r
+ return this.setTemplate(template, valueMap);\r
+ }\r
+\r
+}\r