/*- * ============LICENSE_START======================================================= * Copyright (C) 2021 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 io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.onap.dcae.runtime.core.Edge; import org.onap.dcae.runtime.core.FlowGraph; import org.onap.dcae.runtime.core.FlowGraphParser.BlueprintVessel; import org.onap.dcae.runtime.core.Node; import org.onap.dcae.runtime.web.exception.MainGraphNotFoundException; import org.onap.dcae.runtime.web.models.DistributeGraphRequest; import org.onap.dcae.runtime.web.models.GraphRequest; import org.onap.dcae.runtime.web.service.GraphService; 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.DeleteMapping; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping(value = "/api/graph") @Api(tags = "Graph", description = "API to manage Graph") public class GraphController { @Autowired private GraphService 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){} }