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;
23 import io.swagger.annotations.Api;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
28 import java.util.List;
30 import javax.ws.rs.Consumes;
31 import javax.ws.rs.DELETE;
32 import javax.ws.rs.GET;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.PUT;
35 import javax.ws.rs.Path;
36 import javax.ws.rs.PathParam;
37 import javax.ws.rs.Produces;
38 import javax.ws.rs.core.GenericEntity;
39 import javax.ws.rs.core.MediaType;
40 import javax.ws.rs.core.Response;
41 import javax.ws.rs.core.Response.Status;
43 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
44 import org.onap.dmaap.dbcapi.model.ApiError;
45 import org.onap.dmaap.dbcapi.model.MR_Cluster;
46 import org.onap.dmaap.dbcapi.service.ApiService;
47 import org.onap.dmaap.dbcapi.service.MR_ClientService;
48 import org.onap.dmaap.dbcapi.service.MR_ClusterService;
52 @Api( value= "MR_Clusters", description = "Endpoint for a Message Router servers in a Cluster configuration" )
53 @Consumes(MediaType.APPLICATION_JSON)
54 @Produces(MediaType.APPLICATION_JSON)
56 public class MR_ClusterResource extends BaseLoggingClass {
58 MR_ClusterService mr_clusterService = new MR_ClusterService();
59 MR_ClientService mr_clients = new MR_ClientService();
62 @ApiOperation( value = "return MR_Cluster details",
63 notes = "Returns array of `MR_Cluster` objects.",
64 response = MR_Cluster.class)
65 @ApiResponses( value = {
66 @ApiResponse( code = 200, message = "Success", response = MR_Cluster.class),
67 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
69 public Response getMr_Clusters() {
70 ApiService resp = new ApiService();
72 List<MR_Cluster> clusters = mr_clusterService.getAllMr_Clusters();
74 GenericEntity<List<MR_Cluster>> list = new GenericEntity<List<MR_Cluster>>(clusters) {
76 return resp.success(list);
80 @ApiOperation( value = "return MR_Cluster details",
81 notes = "Create an `MR_Cluster` object.",
82 response = MR_Cluster.class)
83 @ApiResponses( value = {
84 @ApiResponse( code = 200, message = "Success", response = MR_Cluster.class),
85 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
87 public Response addMr_Cluster(
90 ApiService resp = new ApiService();
93 resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
94 resp.required( "fqdn", cluster.getFqdn(), "" );
95 } catch( RequiredFieldException rfe ) {
98 MR_Cluster mrc = mr_clusterService.addMr_Cluster(cluster, resp.getErr() );
99 if ( mrc != null && mrc.isStatusValid() ) {
100 return resp.success(Status.CREATED.getStatusCode(), mrc);
107 @ApiOperation( value = "return MR_Cluster details",
108 notes = "Update an `MR_Cluster` object, specified by clusterId.",
109 response = MR_Cluster.class)
110 @ApiResponses( value = {
111 @ApiResponse( code = 200, message = "Success", response = MR_Cluster.class),
112 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
114 @Path("/{clusterId}")
115 public Response updateMr_Cluster(
116 @PathParam("clusterId") String clusterId,
119 ApiService resp = new ApiService();
122 resp.required( "fqdn", clusterId, "" );
123 resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
124 } catch( RequiredFieldException rfe ) {
127 cluster.setDcaeLocationName(clusterId);
128 MR_Cluster mrc = mr_clusterService.updateMr_Cluster(cluster, resp.getErr() );
129 if ( mrc != null && mrc.isStatusValid() ) {
130 return resp.success(Status.CREATED.getStatusCode(), mrc);
136 @ApiOperation( value = "return MR_Cluster details",
137 notes = "Delete an `MR_Cluster` object, specified by clusterId.",
138 response = MR_Cluster.class)
139 @ApiResponses( value = {
140 @ApiResponse( code = 204, message = "Success", response = MR_Cluster.class),
141 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
143 @Path("/{clusterId}")
144 public Response deleteMr_Cluster(
145 @PathParam("clusterId") String id
147 ApiService resp = new ApiService();
150 resp.required( "fqdn", id, "" );
151 } catch( RequiredFieldException rfe ) {
154 mr_clusterService.removeMr_Cluster(id, resp.getErr() );
155 if ( resp.getErr().is2xx()) {
156 return resp.success(Status.NO_CONTENT.getStatusCode(), null);
162 @ApiOperation( value = "return MR_Cluster details",
163 notes = "Retrieve an `MR_Cluster` object, specified by clusterId.",
164 response = MR_Cluster.class)
165 @ApiResponses( value = {
166 @ApiResponse( code = 200, message = "Success", response = MR_Cluster.class),
167 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
169 @Path("/{clusterId}")
170 public Response getMR_Cluster(
171 @PathParam("clusterId") String id
173 ApiService resp = new ApiService();
176 resp.required( "dcaeLocationName", id, "" );
177 } catch( RequiredFieldException rfe ) {
180 MR_Cluster mrc = mr_clusterService.getMr_Cluster( id, resp.getErr() );
181 if ( mrc != null && mrc.isStatusValid() ) {
182 return resp.success(Status.CREATED.getStatusCode(), mrc);