49cc0190db26f60435a6ebb69c7d0e23bd809195
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2018 IBM.
8  * Modifications Copyright (c) 2019 Samsung
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.so.adapters.cloudregion;
25
26
27 import javax.ws.rs.Consumes;
28 import javax.ws.rs.DELETE;
29 import javax.ws.rs.POST;
30 import javax.ws.rs.PUT;
31 import javax.ws.rs.Path;
32 import javax.ws.rs.PathParam;
33 import javax.ws.rs.Produces;
34 import javax.ws.rs.core.MediaType;
35 import javax.ws.rs.core.Response;
36 import org.apache.http.HttpStatus;
37 import org.onap.so.db.catalog.beans.CloudSite;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Component;
42 import io.swagger.v3.oas.annotations.OpenAPIDefinition;
43 import io.swagger.v3.oas.annotations.Operation;
44 import io.swagger.v3.oas.annotations.Parameter;
45 import io.swagger.v3.oas.annotations.info.Info;
46 import io.swagger.v3.oas.annotations.media.Content;
47 import io.swagger.v3.oas.annotations.media.Schema;
48 import io.swagger.v3.oas.annotations.responses.ApiResponse;
49 import io.swagger.v3.oas.annotations.responses.ApiResponses;
50
51
52 @Path("/v1/cloud-region")
53 @OpenAPIDefinition(info = @Info(title = "/v1/cloud-region", description = "root of cloud region adapter"))
54 @Component
55 public class CloudRegionRestV1 {
56     private static Logger logger = LoggerFactory.getLogger(CloudRegionRestV1.class);
57
58     @Autowired
59     private CloudRestImpl cloudRestImpl;
60
61     @POST
62     @Consumes({MediaType.APPLICATION_JSON})
63     @Produces({MediaType.APPLICATION_JSON})
64     @Operation(description = "CreateCloudRegion", summary = "Create a cloud site in MSO and Region In AAI")
65     @ApiResponses({@ApiResponse(responseCode = "201", description = "Cloud Region has been created"),
66             @ApiResponse(responseCode = "500", description = "Create Cloud Region has failed")})
67     public Response createCloudRegion(
68             @Parameter(name = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId,
69             @Parameter(name = "CloudSite", required = true) final CloudSite cloudSite) {
70         cloudRestImpl.createCloudRegion(cloudSite);
71         return Response.status(HttpStatus.SC_CREATED).build();
72     }
73
74     @DELETE
75     @Path("{cloud-region-id}/{cloud-owner}")
76     @Consumes({MediaType.APPLICATION_JSON})
77     @Produces({MediaType.APPLICATION_JSON})
78     @Operation(description = "CreateCloudRegion", summary = "Delete an cloud Region in SO")
79     @ApiResponses({@ApiResponse(responseCode = "204", description = "cloud Region has been deleted"),
80             @ApiResponse(responseCode = "500", description = "Cloud Region delete has failed")})
81     public Response deleteCloudRegion(
82             @Parameter(name = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId,
83             @Parameter(name = "cloud-owner", required = true) @PathParam("cloud-owner") String cloudOwner) {
84         cloudRestImpl.deleteCloudRegion(cloudRegionId);
85         return Response.status(HttpStatus.SC_NO_CONTENT).build();
86     }
87
88     @PUT
89     @Path("{cloud-region-id}/{cloud-owner}")
90     @Consumes({MediaType.APPLICATION_JSON})
91     @Produces({MediaType.APPLICATION_JSON})
92     @Operation(description = "CreateCloudRegion", summary = "Update an existing Cloud Region")
93     @ApiResponses({@ApiResponse(responseCode = "200", description = "Cloud Region has been updated"), @ApiResponse(
94             responseCode = "500", description = "Update Cloud Region has failed examine entity object for details")})
95     public Response updateCloudRegion(
96             @Parameter(name = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId,
97             @Parameter(name = "cloud-owner", required = true) @PathParam("cloud-owner") String cloudOwner,
98             @Parameter(name = "CloudSite", required = true) final CloudSite cloudSite) {
99         cloudRestImpl.updateCloudRegion(cloudSite);
100         return Response.status(HttpStatus.SC_OK).build();
101     }
102 }