2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.dmaap.dbcapi.resources;
24 import io.swagger.annotations.Api;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
29 import java.util.List;
31 import javax.ws.rs.Consumes;
32 import javax.ws.rs.DELETE;
33 import javax.ws.rs.GET;
34 import javax.ws.rs.POST;
35 import javax.ws.rs.PUT;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.Produces;
39 import javax.ws.rs.core.GenericEntity;
40 import javax.ws.rs.core.MediaType;
41 import javax.ws.rs.core.Response;
42 import javax.ws.rs.core.Response.Status;
44 import org.apache.log4j.Logger;
45 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
46 import org.onap.dmaap.dbcapi.model.ApiError;
47 import org.onap.dmaap.dbcapi.model.DcaeLocation;
48 import org.onap.dmaap.dbcapi.model.Dmaap;
49 import org.onap.dmaap.dbcapi.service.ApiService;
50 import org.onap.dmaap.dbcapi.service.DcaeLocationService;
53 @Path("/dcaeLocations")
54 @Api( value= "dcaeLocations", description = "an OpenStack tenant purposed for OpenDCAE (i.e. where OpenDCAE components might be deployed)" )
55 @Consumes(MediaType.APPLICATION_JSON)
56 @Produces(MediaType.APPLICATION_JSON)
58 public class DcaeLocationResource extends BaseLoggingClass {
59 static final Logger logger = Logger.getLogger(DcaeLocationResource.class);
60 DcaeLocationService locationService = new DcaeLocationService();
63 @ApiOperation( value = "return dcaeLocation details",
64 notes = "Returns array of `dcaeLocation` objects. All objects managed by DMaaP are deployed in some `dcaeLocation` which is a unique identifier for an *OpenStack* tenant purposed for a *dcaeLayer* (ecomp or edge).",
65 response = DcaeLocation.class)
66 @ApiResponses( value = {
67 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
68 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
70 public Response getDcaeLocations() {
71 ApiService check = new ApiService();
73 List<DcaeLocation> locs = locationService.getAllDcaeLocations();
75 GenericEntity<List<DcaeLocation>> list = new GenericEntity<List<DcaeLocation>>(locs) {
77 return check.success(list);
81 @ApiOperation( value = "return dcaeLocation details",
82 notes = "Create some `dcaeLocation` which is a unique identifier for an *OpenStack* tenant purposed for a *dcaeLayer* (ecomp or edge).",
83 response = DcaeLocation.class)
84 @ApiResponses( value = {
85 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
86 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
88 public Response addDcaeLocation(
91 ApiService check = new ApiService();
93 if ( locationService.getDcaeLocation(location.getDcaeLocationName()) != null ) {
95 check.setCode(Status.CONFLICT.getStatusCode());
96 check.setMessage("dcaeLocation already exists");
97 check.setFields("dcaeLocation");
102 DcaeLocation loc = locationService.addDcaeLocation(location);
103 return check.success(Status.CREATED.getStatusCode(), loc);
107 @ApiOperation( value = "return dcaeLocation details",
108 notes = "update the openStackAvailabilityZone of a dcaeLocation",
109 response = DcaeLocation.class)
110 @ApiResponses( value = {
111 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
112 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
114 @Path("/{locationName}")
115 public Response updateDcaeLocation(
116 @PathParam("locationName") String name,
117 DcaeLocation location
119 ApiService check = new ApiService();
121 location.setDcaeLocationName(name);
122 if ( locationService.getDcaeLocation(location.getDcaeLocationName()) == null ) {
123 ApiError err = new ApiError();
125 err.setCode(Status.NOT_FOUND.getStatusCode());
126 err.setMessage("dcaeLocation does not exist");
127 err.setFields("dcaeLocation");
129 return check.notFound();
133 DcaeLocation loc = locationService.updateDcaeLocation(location);
134 return check.success(Status.CREATED.getStatusCode(), loc );
138 @ApiOperation( value = "return dcaeLocation details", notes = "delete a dcaeLocation", response = Dmaap.class)
139 @ApiResponses( value = {
140 @ApiResponse( code = 204, message = "Success", response = Dmaap.class),
141 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
143 @Path("/{locationName}")
144 public Response deleteDcaeLocation(
145 @PathParam("locationName") String name
147 ApiService check = new ApiService();
149 locationService.removeDcaeLocation(name);
150 return check.success(Status.NO_CONTENT.getStatusCode(), null);
154 @ApiOperation( value = "return dcaeLocation details", notes = "Returns a specific `dcaeLocation` object with specified tag", response = Dmaap.class)
155 @ApiResponses( value = {
156 @ApiResponse( code = 200, message = "Success", response = Dmaap.class),
157 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
159 @Path("/{locationName}")
160 public Response getDcaeLocation(
161 @PathParam("locationName") String name
163 ApiService check = new ApiService();
165 DcaeLocation loc = locationService.getDcaeLocation( name );
167 ApiError err = new ApiError();
169 err.setCode(Status.NOT_FOUND.getStatusCode());
170 err.setMessage("dcaeLocation does not exist");
171 err.setFields("dcaeLocation");
173 return check.error();
178 return check.success(loc);