diff options
Diffstat (limited to 'bpmn/mso-infrastructure-bpmn/src')
-rw-r--r-- | bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowOnboardingSupport.java | 412 |
1 files changed, 0 insertions, 412 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowOnboardingSupport.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowOnboardingSupport.java index 8506b9542f..939164492b 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowOnboardingSupport.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowOnboardingSupport.java @@ -28,7 +28,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -47,24 +46,15 @@ import javax.ws.rs.ext.Provider; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; -import org.onap.so.db.catalog.beans.NetworkRecipe; -import org.onap.so.db.catalog.beans.NetworkResource; -import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.rest.catalog.beans.Service; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.CrossOrigin; - -import com.fasterxml.jackson.databind.ObjectMapper; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import net.minidev.json.JSONObject; -import org.onap.so.db.catalog.beans.VnfRecipe; -import org.onap.so.db.catalog.beans.VnfResource; /** * @@ -77,318 +67,11 @@ import org.onap.so.db.catalog.beans.VnfResource; public class WorkflowOnboardingSupport extends ProcessEngineAwareService { protected static final Logger logger = LoggerFactory.getLogger(WorkflowOnboardingSupport.class); - protected static final long DEFAULT_WAIT_TIME = 60000; // default wait time - private static final String SERVICE = "SERVICE"; - private static final String NETWORK = "NETWORK"; - private static final String VNF = "VNF"; @Autowired private CatalogDbClient catalogDbClient; /** - * Get all service recipes. - * - * @return - */ - @GET - @ApiOperation(value = "Get all service recipes", notes = "Get all service recipes") - @Path("/serviceRecipes") - public Response getServiceRecipes() { - List<ServiceRecipe> serviceRecipes = catalogDbClient.getServiceRecipes(); - List<Service> services = catalogDbClient.getServices(); - Map<String, String> idToName = new HashMap<String, String>(); - for (Service service : services) { - idToName.put(service.getModelVersionId(), service.getModelName()); - } - Map<String, String> flowToName = new HashMap<String, String>(); - Map<String, List<String>> packages = getPackages(); - for (Entry<String, List<String>> entry : packages.entrySet()) { - for (String flow : entry.getValue()) { - flowToName.put(flow, entry.getKey()); - } - } - Map<String, List<Map<String, String>>> mapServiceRecipes = new HashMap<String, List<Map<String, String>>>(); - List<Map<String, String>> recipeList = new ArrayList<Map<String, String>>(); - for (ServiceRecipe serviceRecipe : serviceRecipes) { - Map<String, String> recipeObj = new HashMap<String, String>(); - recipeObj.put("id", String.valueOf(serviceRecipe.getId())); - recipeObj.put("modelVersionId", serviceRecipe.getServiceModelUUID()); - recipeObj.put("modelName", idToName.get(serviceRecipe.getServiceModelUUID())); - recipeObj.put("operation", serviceRecipe.getAction()); - recipeObj.put("orchestrationPackageName", flowToName.get(serviceRecipe.getOrchestrationUri())); - recipeObj.put("orchestrationFlow", serviceRecipe.getOrchestrationUri()); - recipeList.add(recipeObj); - } - mapServiceRecipes.put("serviceRecipes", recipeList); - String resp = JSONObject.toJSONString(mapServiceRecipes); - - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } - - /** - * Add new recipe for service - * - * @param request - * @return - */ - @SuppressWarnings("unchecked") - @POST - @Path("/serviceRecipes") - @ApiOperation(value = "Add a new service recipe", notes = "Add a new service recipe") - @Produces("application/json") - @Consumes("application/json") - public Response addServiceRecipDese(String request) { - Map<String, String> mapRecipeInfo; - ObjectMapper mapper = new ObjectMapper(); - - try { - - try { - mapRecipeInfo = mapper.readValue(request, Map.class); - - } catch (Exception e) { - logger.debug("Mapping of request to JSON object failed : ", e); - return Response.status(200).header("Access-Control-Allow-Origin", "*").build(); - } - String nfRole = mapRecipeInfo.get("nfRole"); - String type = mapRecipeInfo.get("modelType"); - String modelVersionId = mapRecipeInfo.get("modelVersionId"); - String action = mapRecipeInfo.get("operation"); - String orchestrationFlow = "/mso/async/services/" + mapRecipeInfo.get("orchestrationFlow"); - String modelName = mapRecipeInfo.get("modelName"); - String description = action + " orchestration flow for template " + mapRecipeInfo.get("modelName"); - - String[] validTypes = { SERVICE, NETWORK, VNF }; - - if (org.springframework.util.StringUtils.isEmpty(type) - || !Arrays.asList(validTypes).contains(type.toUpperCase())) { - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"type is invalid.\"}").build(); - - } - int assignedId = 0; - boolean isModelVersionExists = false; - Object[] conflictAndIdCheck; - - if (type.equalsIgnoreCase(SERVICE)) { - isModelVersionExists = isServiceModelVersionIdExists(modelVersionId); - if (!isModelVersionExists) { - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"The service template does not exist.\"}").build(); - } - - conflictAndIdCheck = isServiceActionConflict(modelVersionId, action); - if ((boolean) conflictAndIdCheck[0]) { - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity( - "{\"errMsg\":\"The recipe for this action of the service template already exists.\"}") - .build(); - } - assignedId = (int) conflictAndIdCheck[1] + 1; - ServiceRecipe serviceRecipe = new ServiceRecipe(); - serviceRecipe.setId(assignedId); - serviceRecipe.setServiceModelUUID(modelVersionId); - serviceRecipe.setAction(action); - serviceRecipe.setOrchestrationUri(orchestrationFlow); - serviceRecipe.setRecipeTimeout(180); - serviceRecipe.setDescription(description); - catalogDbClient.postServiceRecipe(serviceRecipe); - } else if (type.equalsIgnoreCase(NETWORK)) { - - isModelVersionExists = isNetworkVersionIdValid(modelVersionId); - if (!isModelVersionExists) { - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"The network template does not exist.\"}").build(); - } - - conflictAndIdCheck = isNetworkActionConflict(modelVersionId, action); - if ((boolean) conflictAndIdCheck[0]) { - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity( - "{\"errMsg\":\"The recipe for this action of the network template already exists.\"}") - .build(); - } - - assignedId = (int) conflictAndIdCheck[1] + 1; - NetworkRecipe nwrecipe = new NetworkRecipe(); - nwrecipe.setId(assignedId); - nwrecipe.setModelName(modelName); - nwrecipe.setAction(action); - nwrecipe.setOrchestrationUri(orchestrationFlow); - nwrecipe.setDescription(description); - nwrecipe.setRecipeTimeout(180); - nwrecipe.setVersionStr(modelVersionId); - catalogDbClient.postNetworkRecipe(nwrecipe); - - } else if (type.equalsIgnoreCase(VNF)) { - - isModelVersionExists = isVnfVersionIdValid(modelVersionId); - if (!isModelVersionExists) { - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"The Vnf template does not exist.\"}").build(); - - } - - conflictAndIdCheck = isVfActionConflict(modelVersionId, action); - if ((boolean) conflictAndIdCheck[0]) { - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"The recipe for this action of the vnf template already exists.\"}") - .build(); - } - - assignedId = (int) conflictAndIdCheck[1] + 1; - VnfRecipe vnfRecipe = new VnfRecipe(); - vnfRecipe.setNfRole(nfRole); - vnfRecipe.setId(assignedId); - vnfRecipe.setAction(action); - vnfRecipe.setDescription(description); - vnfRecipe.setVersionStr(modelVersionId); - vnfRecipe.setOrchestrationUri(orchestrationFlow); - vnfRecipe.setRecipeTimeout(180); - catalogDbClient.postVnfRecipe(vnfRecipe); - - } - - mapRecipeInfo.put("id", String.valueOf(assignedId)); - } catch (Exception e) { - logger.debug("WorkflowOnboardingSupport addServiceRecipDese error {} : ", e); - return Response.status(200).header("Access-Control-Allow-Origin", "*") - .entity("{\"errMsg\":\"Unable to process.\"}").build(); - } - String resp = JSONObject.toJSONString(mapRecipeInfo); - return Response.status(201).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } - - private boolean isServiceModelVersionIdExists(String modelVersionId) { - List<Service> services = catalogDbClient.getServices(); - boolean isExists = false; - for(Service service: services) { - if(service.getModelVersionId().equals(modelVersionId)){ - isExists = true; - break; - } - } - return isExists; - } - - private Object[] isServiceActionConflict(String modelVersionId,String action) { - List<ServiceRecipe> serviceRecipes = catalogDbClient.getServiceRecipes(); - boolean isConflict = false; - Object[] data= new Object[2]; - int maxId = serviceRecipes.get(0)!=null? serviceRecipes.get(0).getId(): 1; - for (ServiceRecipe recipe : serviceRecipes) { - maxId = recipe.getId() > maxId ? recipe.getId() : maxId; - if (recipe.getServiceModelUUID().equals(modelVersionId) - && recipe.getAction().equals(action)) { - isConflict = true; - } - } - data[0]=isConflict; - data[1]=maxId; - return data; - } - - private Object[] isNetworkActionConflict(String modelVersionId,String action) { - List<NetworkRecipe> recipes = catalogDbClient.getNetworkRecipes(); - boolean isConflict = false; - Object[] data= new Object[2]; - int maxId = recipes.get(0)!=null ? recipes.get(0).getId() : 1; - for (NetworkRecipe recipe : recipes) { - maxId = recipe.getId() > maxId ? recipe.getId() : maxId; - if (recipe.getVersionStr().equals(modelVersionId) - && recipe.getAction().equals(action)) { - isConflict = true; - - } - - } - data[0]=isConflict; - data[1]=maxId; - return data; - } - - private Object[] isVfActionConflict(String modelVersionId,String action) { - List<VnfRecipe> vnfRecipes = catalogDbClient.getVnfRecipes(); - boolean isConflict = false; - Object[] data= new Object[2]; - int maxId = vnfRecipes.get(0) !=null ? vnfRecipes.get(0).getId() : 1; - for (VnfRecipe recipe : vnfRecipes) { - maxId = recipe.getId() > maxId ? recipe.getId() : maxId; - if (recipe.getVersionStr().equals(modelVersionId) - && recipe.getAction().equals(action)) { - isConflict = true; - } - } - data[0]=isConflict; - data[1]=maxId; - return data; - } - - - - private boolean isNetworkVersionIdValid(String modelVersionId) { - List<NetworkResource> networkResources = catalogDbClient.getNetworkResources(); - boolean isExists = false; - for(NetworkResource networkResource: networkResources) { - if(networkResource.getModelVersion().equals(modelVersionId)){ - isExists = true; - break; - } - } - return isExists; - } - - private boolean isVnfVersionIdValid(String modelVersionId) { - List<VnfResource> vnfResources = catalogDbClient.getVnfResources(); - boolean isExists = false; - for(VnfResource vnfResource: vnfResources) { - if(vnfResource.getModelVersion().equals(modelVersionId)){ - isExists = true; - break; - } - } - return isExists; - } - - /** - * delete service recipe - * - * @param request the body of the request - * @return - */ - @DELETE - @Path("/serviceRecipes/{id}") - @ApiOperation(value = "delete a service recipe", notes = "delete a service recipe") - @Produces("application/json") - @Consumes("application/json") - public Response delServiceRecipe(String request, @PathParam("id") String id) { - catalogDbClient.deleteServiceRecipe(id); - return Response.status(200).header("Access-Control-Allow-Origin", "*").build(); - } - - /** - * Get service templates - * - * @return - */ - @GET - @ApiOperation(value = "query all service templates", notes = "query all service templates") - @Path("/serviceTemplates") - public Response getServices() { - List<Service> services = catalogDbClient.getServices(); - Map<String, List<Map<String, String>>> mapServices = new HashMap<String, List<Map<String, String>>>(); - List<Map<String, String>> serviceList = new ArrayList<Map<String, String>>(); - for (Service service : services) { - Map<String, String> serviceObj = new HashMap<String, String>(); - serviceObj.put("modelInvariantId", service.getModelInvariantId()); - serviceObj.put("modelVersionId", service.getModelVersionId()); - serviceObj.put("modelName", service.getModelName()); - serviceList.add(serviceObj); - } - mapServices.put("services", serviceList); - String resp = JSONObject.toJSONString(mapServices); - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } - - /** * Get all workflow packages including all bpmn infos. * * @return @@ -524,99 +207,4 @@ public class WorkflowOnboardingSupport extends ProcessEngineAwareService { } return true; } - /** - * Get all network recipes. - * - * @return - */ - @GET - @ApiOperation(value = "Get all network recipes", notes = "Get all network recipes") - @Path("/networkRecipes") - public Response getNetworkRecipes() { - List<NetworkRecipe> networkRecipes = catalogDbClient.getNetworkRecipes(); - Map<String, List<Map<String, String>>> mapNetworkRecipes = new HashMap<String, List<Map<String, String>>>(); - List<Map<String, String>> recipeList = new ArrayList<Map<String, String>>(); - for (NetworkRecipe networkRecipe : networkRecipes) { - Map<String, String> recipeObj = new HashMap<String, String>(); - recipeObj.put("id", String.valueOf(networkRecipe.getId())); - recipeObj.put("paramXsd", String.valueOf(networkRecipe.getParamXsd())); - recipeObj.put("modelName", String.valueOf(networkRecipe.getModelName())); - recipeObj.put("description", String.valueOf(networkRecipe.getDescription())); - recipeObj.put("action", String.valueOf(networkRecipe.getAction())); - recipeObj.put("orchestrationUri", String.valueOf(networkRecipe.getOrchestrationUri())); - recipeObj.put("recipeTimeout", String.valueOf(networkRecipe.getRecipeTimeout())); - recipeObj.put("versionStr", String.valueOf(networkRecipe.getVersionStr())); - recipeObj.put("serviceType", String.valueOf(networkRecipe.getServiceType())); - recipeObj.put("created", String.valueOf(networkRecipe.getCreated())); - recipeList.add(recipeObj); - } - mapNetworkRecipes.put("networkRecipes", recipeList); - String resp = JSONObject.toJSONString(mapNetworkRecipes); - - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } - - /** - * Get all network recipes. - * - * @return - */ - @GET - @ApiOperation(value = "Get all network recipes", notes = "Get all network recipes") - @Path("/getServiceRecipes") - public Response getServiceRecipesList() { - List<ServiceRecipe> serviceRecipes = catalogDbClient.getServiceRecipes(); - Map<String, List<Map<String, String>>> mapNetworkRecipes = new HashMap<String, List<Map<String, String>>>(); - List<Map<String, String>> recipeList = new ArrayList<Map<String, String>>(); - for (ServiceRecipe serviceRecipe : serviceRecipes) { - Map<String, String> recipeObj = new HashMap<String, String>(); - recipeObj.put("id", String.valueOf(serviceRecipe.getId())); - recipeObj.put("paramXsd", String.valueOf(serviceRecipe.getParamXsd())); - recipeObj.put("serviceModelUUID", String.valueOf(serviceRecipe.getServiceModelUUID())); - recipeObj.put("description", String.valueOf(serviceRecipe.getDescription())); - recipeObj.put("action", String.valueOf(serviceRecipe.getAction())); - recipeObj.put("orchestrationUri", String.valueOf(serviceRecipe.getOrchestrationUri())); - recipeObj.put("recipeTimeout", String.valueOf(serviceRecipe.getRecipeTimeout())); - recipeObj.put("serviceTimeoutInterim", String.valueOf(serviceRecipe.getServiceTimeoutInterim())); - recipeObj.put("created", String.valueOf(serviceRecipe.getCreated())); - recipeList.add(recipeObj); - } - mapNetworkRecipes.put("serviceRecipes", recipeList); - String resp = JSONObject.toJSONString(mapNetworkRecipes); - - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } - - /** - * Get all vnf recipes. - * - * @return - */ - @GET - @ApiOperation(value = "Get all vnf recipes", notes = "Get all vnf recipes") - @Path("/vnfRecipes") - public Response getVNFRecipes() { - List<VnfRecipe> vnfRecipes = catalogDbClient.getVnfRecipes(); - Map<String, List<Map<String, String>>> mapVnfRecipes = new HashMap<String, List<Map<String, String>>>(); - List<Map<String, String>> recipeList = new ArrayList<Map<String, String>>(); - for (VnfRecipe vnfRecipe : vnfRecipes) { - Map<String, String> recipeObj = new HashMap<String, String>(); - recipeObj.put("id", String.valueOf(vnfRecipe.getId())); - recipeObj.put("nfRole", String.valueOf(vnfRecipe.getNfRole())); - recipeObj.put("paramXsd", String.valueOf(vnfRecipe.getParamXsd())); - recipeObj.put("vfModuleId", String.valueOf(vnfRecipe.getVfModuleId())); - recipeObj.put("description", String.valueOf(vnfRecipe.getDescription())); - recipeObj.put("action", String.valueOf(vnfRecipe.getAction())); - recipeObj.put("orchestrationUri", String.valueOf(vnfRecipe.getOrchestrationUri())); - recipeObj.put("recipeTimeout", String.valueOf(vnfRecipe.getRecipeTimeout())); - recipeObj.put("versionStr", String.valueOf(vnfRecipe.getVersionStr())); - recipeObj.put("serviceType", String.valueOf(vnfRecipe.getServiceType())); - recipeObj.put("created", String.valueOf(vnfRecipe.getCreated())); - recipeList.add(recipeObj); - } - mapVnfRecipes.put("vnfRecipes", recipeList); - String resp = JSONObject.toJSONString(mapVnfRecipes); - - return Response.status(200).header("Access-Control-Allow-Origin", "*").entity(resp).build(); - } } |