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.DR_Pub;
46 import org.onap.dmaap.dbcapi.model.MR_Cluster;
47 import org.onap.dmaap.dbcapi.service.ApiService;
48 import org.onap.dmaap.dbcapi.service.MR_ClientService;
49 import org.onap.dmaap.dbcapi.service.MR_ClusterService;
53 @Api( value= "MR_Clusters", description = "Endpoint for a Message Router servers in a Cluster configuration" )
54 @Consumes(MediaType.APPLICATION_JSON)
55 @Produces(MediaType.APPLICATION_JSON)
57 public class MR_ClusterResource extends BaseLoggingClass {
59 MR_ClusterService mr_clusterService = new MR_ClusterService();
60 MR_ClientService mr_clients = new MR_ClientService();
63 @ApiOperation( value = "return MR_Cluster details",
64 notes = "Returns array of `MR_Cluster` objects.",
65 response = MR_Cluster.class)
66 @ApiResponses( value = {
67 @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
68 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
70 public Response getMr_Clusters() {
71 ApiService resp = new ApiService();
73 List<MR_Cluster> clusters = mr_clusterService.getAllMr_Clusters();
75 GenericEntity<List<MR_Cluster>> list = new GenericEntity<List<MR_Cluster>>(clusters) {
77 return resp.success(list);
81 @ApiOperation( value = "return MR_Cluster details",
82 notes = "Create an `MR_Cluster` object.",
83 response = MR_Cluster.class)
84 @ApiResponses( value = {
85 @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
86 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
88 public Response addMr_Cluster(
91 ApiService resp = new ApiService();
94 resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
95 resp.required( "fqdn", cluster.getFqdn(), "" );
96 } catch( RequiredFieldException rfe ) {
99 MR_Cluster mrc = mr_clusterService.addMr_Cluster(cluster, resp.getErr() );
100 if ( mrc != null && mrc.isStatusValid() ) {
101 return resp.success(Status.CREATED.getStatusCode(), mrc);
108 @ApiOperation( value = "return MR_Cluster details",
109 notes = "Update an `MR_Cluster` object, specified by clusterId.",
110 response = MR_Cluster.class)
111 @ApiResponses( value = {
112 @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
113 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
115 @Path("/{clusterId}")
116 public Response updateMr_Cluster(
117 @PathParam("clusterId") String clusterId,
120 ApiService resp = new ApiService();
123 resp.required( "fqdn", clusterId, "" );
124 resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
125 } catch( RequiredFieldException rfe ) {
128 cluster.setDcaeLocationName(clusterId);
129 MR_Cluster mrc = mr_clusterService.updateMr_Cluster(cluster, resp.getErr() );
130 if ( mrc != null && mrc.isStatusValid() ) {
131 return resp.success(Status.CREATED.getStatusCode(), mrc);
137 @ApiOperation( value = "return MR_Cluster details",
138 notes = "Delete an `MR_Cluster` object, specified by clusterId.",
139 response = MR_Cluster.class)
140 @ApiResponses( value = {
141 @ApiResponse( code = 204, message = "Success", response = DR_Pub.class),
142 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
144 @Path("/{clusterId}")
145 public Response deleteMr_Cluster(
146 @PathParam("clusterId") String id
148 ApiService resp = new ApiService();
151 resp.required( "fqdn", id, "" );
152 } catch( RequiredFieldException rfe ) {
155 mr_clusterService.removeMr_Cluster(id, resp.getErr() );
156 if ( resp.getErr().is2xx()) {
157 return resp.success(Status.NO_CONTENT.getStatusCode(), null);
163 @ApiOperation( value = "return MR_Cluster details",
164 notes = "Retrieve an `MR_Cluster` object, specified by clusterId.",
165 response = MR_Cluster.class)
166 @ApiResponses( value = {
167 @ApiResponse( code = 200, message = "Success", response = DR_Pub.class),
168 @ApiResponse( code = 400, message = "Error", response = ApiError.class )
170 @Path("/{clusterId}")
171 public Response getMR_Cluster(
172 @PathParam("clusterId") String id
174 ApiService resp = new ApiService();
177 resp.required( "dcaeLocationName", id, "" );
178 } catch( RequiredFieldException rfe ) {
181 MR_Cluster mrc = mr_clusterService.getMr_Cluster( id, resp.getErr() );
182 if ( mrc != null && mrc.isStatusValid() ) {
183 return resp.success(Status.CREATED.getStatusCode(), mrc);