aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/CatalogDbAdapterRest.java58
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java72
2 files changed, 129 insertions, 1 deletions
diff --git 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
index cd6522b487..d0d3999cf4 100644
--- 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
@@ -69,6 +69,7 @@ import org.openecomp.mso.adapters.catalogdb.catalogrest.CatalogQuery;
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;
@@ -77,6 +78,7 @@ import org.openecomp.mso.adapters.catalogdb.catalogrest.QueryVfModule;
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;
@@ -481,7 +483,7 @@ 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;
String entity = "";
try (CatalogDatabase db = CatalogDatabase.getInstance()) {
@@ -515,4 +517,58 @@ public class CatalogDbAdapterRest {
.build();
}
}
+
+ /**
+ * 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();
+ }
+ }
}
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java
new file mode 100644
index 0000000000..5be6970554
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/java/org/openecomp/mso/adapters/catalogdb/catalogrest/QueryResourceRecipe.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.adapters.catalogdb.catalogrest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.openecomp.mso.db.catalog.beans.Recipe;
+
+/**
+ * serivce csar query support
+ * <br>
+ * <p>
+ * </p>
+ *
+ * @author
+ * @version ONAP Beijing Release 2018-02-28
+ */
+public class QueryResourceRecipe extends CatalogQuery{
+
+ private Recipe resourceRecipe;
+
+ public QueryResourceRecipe(Recipe resourceRecipe){
+ this.resourceRecipe =resourceRecipe;
+ }
+
+ private final String template =
+ "\t{\n"+
+ "\t\t\"id\" : <ID>,\n"+
+ "\t\t\"action\" : <ACTION>,\n"+
+ "\t\t\"orchestrationUri\" : <ORCHESTRATION_URI>,\n"+
+ "\t\t\"recipeTimeout\" : <RECIPE_TIMEOUT>,\n"+
+ "\t\t\"paramXSD\" : <PARAM_XSD>,\n"+
+ "\t\t\"description\" : <DESCRIPTION>\n"+
+ "\t}";
+
+ @Override
+ public String toString() {
+
+ return resourceRecipe.toString();
+ }
+
+ @Override
+ public String JSON2(boolean isArray, boolean isEmbed) {
+ Map<String, String> valueMap = new HashMap<>();
+ put(valueMap, "ID", null == resourceRecipe ? null : resourceRecipe.getId());
+ put(valueMap, "ACTION", null == resourceRecipe ? null : resourceRecipe.getAction());
+ put(valueMap, "ORCHESTRATION_URI", null == resourceRecipe ? null : resourceRecipe.getOrchestrationUri());
+ put(valueMap, "RECIPE_TIMEOUT", null == resourceRecipe ? null : resourceRecipe.getRecipeTimeout());
+ put(valueMap, "PARAM_XSD", null == resourceRecipe ? null : resourceRecipe.getParamXSD());
+ put(valueMap, "DESCRIPTION", null == resourceRecipe ? null : resourceRecipe.getDescription());
+ return this.setTemplate(template, valueMap);
+ }
+
+}