From cc9d389bf197c1a365e669b407ea781f2bc87fd4 Mon Sep 17 00:00:00 2001 From: Michael Hwang Date: Wed, 20 Nov 2019 12:32:48 -0500 Subject: Add mod/runtimeapi Change-Id: I6c0a45ddf460a63a1e4b9284e19bf4ab111bd463 Issue-ID: DCAEGEN2-1860 Signed-off-by: Michael Hwang --- .../runtime/web/controllers/GraphController.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java (limited to 'mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java') diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java new file mode 100644 index 0000000..fc222f2 --- /dev/null +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/controllers/GraphController.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 AT&T Intellectual Property. 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.onap.dcae.runtime.web.controllers; + +import org.onap.dcae.runtime.core.Edge; +import org.onap.dcae.runtime.core.FlowGraph; +import org.onap.dcae.runtime.core.Node; +import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel; +import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException; +import org.onap.dcae.runtime.web.models.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.onap.dcae.runtime.web.models.DistributeGraphRequest; +import org.onap.dcae.runtime.web.models.GraphRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.onap.dcae.runtime.web.service.GraphServiceImpl; + +import javax.validation.Valid; +import java.util.Map; +import java.util.HashMap; +import java.util.List; + +@RestController +@RequestMapping(value = "/api/graph") +@Api(tags = "Graph", description = "API to manage Graph") +public class GraphController { + + @Autowired + private GraphServiceImpl graphService; + + Logger logger = LoggerFactory.getLogger(GraphController.class); + + @RequestMapping(method = RequestMethod.GET,value = "/main") + @ApiOperation("Get main graph") + public FlowGraph getMainGraph(){ + return graphService.getMainGraph(); + } + + @PostMapping(value = "/main") + @ApiOperation("Initialize a main graph") + public ResponseEntity initializeGraph(@RequestBody @Valid GraphRequest graphRequest){ + logger.info(graphRequest.toString()); + graphService.initializeMainGraph(graphRequest); + return new ResponseEntity(HttpStatus.CREATED); + } + + @PostMapping(value = "/{id}/distribute") + @ApiOperation("Submit actions on a given graph and distribute blueprints to the inventory") + public ResponseEntity> distributeGraph(@PathVariable(value = "id") String id, + @RequestBody @Valid DistributeGraphRequest distributeGraphRequest){ + logger.info(distributeGraphRequest.getActions().toString()); + List blueprints = graphService.distribute(distributeGraphRequest); + + Map response = new HashMap<>(); + for (BlueprintVessel bpv : blueprints) { + response.put(String.format("%s_%d", bpv.name, bpv.version), bpv.blueprint); + } + return new ResponseEntity>(response, HttpStatus.OK); + } + + @DeleteMapping(value = "/main") + @ApiOperation("Remove the main graph") + public String deleteMainGraph(){ + graphService.deleteMainGraph(); + return "Main Graph has been deleted."; + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.NOT_FOUND) + private void graphNotFoundHandler(MainGraphNotFoundException ex){} +} -- cgit 1.2.3-korg