2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dcaegen2.platform.mod.web.controller;
23 import org.onap.dcaegen2.platform.mod.model.exceptions.msinstance.MsInstanceAlreadyExistsException;
24 import org.onap.dcaegen2.platform.mod.model.microserviceinstance.MsInstance;
25 import org.onap.dcaegen2.platform.mod.model.restapi.ErrorResponse;
26 import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceRequest;
27 import org.onap.dcaegen2.platform.mod.model.restapi.MsInstanceUpdateRequest;
28 import org.onap.dcaegen2.platform.mod.web.service.microserviceinstance.MsInstanceService;
29 import io.swagger.annotations.Api;
30 import io.swagger.annotations.ApiOperation;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.ResponseEntity;
34 import org.springframework.web.bind.annotation.*;
36 import java.util.List;
39 * Controller class to manage MicroserviceInstance's REST endpoints
43 @Api(tags = "Microservice Instance", description = "APIs to manage Microservice Instance")
44 @RequestMapping("/api/microservice-instance")
45 public class MicroserviceInstanceController {
48 MsInstanceService msInstanceService;
51 @ApiOperation("Get all Microservices Instances")
52 public List<MsInstance> getAll() {
53 return msInstanceService.getAll();
57 @PostMapping("/{msName}")
58 @ApiOperation("Create a Microservice Instance")
59 @ResponseStatus(HttpStatus.CREATED)
60 public MsInstance createMsInstance(@PathVariable String msName, @RequestBody MsInstanceRequest request) {
61 return msInstanceService.createMicroserviceInstance(msName, request);
64 @PatchMapping("/{msId}")
65 @ApiOperation("Patch a Microservice Instance")
66 @ResponseStatus(HttpStatus.OK)
67 public MsInstance patchMsInstance(@RequestBody MsInstanceUpdateRequest request, @PathVariable String msId){
68 return msInstanceService.updateMsInstance(request, msId);
72 public ResponseEntity<ErrorResponse> resolveMsInstanceConflict(MsInstanceAlreadyExistsException ex) {
73 return new ResponseEntity<>(new ErrorResponse("Microservice Instance for the given name and release already exists"), HttpStatus.CONFLICT);