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.GET;
32 import javax.ws.rs.HeaderParam;
33 import javax.ws.rs.Path;
34 import javax.ws.rs.Produces;
35 import javax.ws.rs.QueryParam;
36 import javax.ws.rs.core.Context;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.core.Response;
39 import javax.ws.rs.core.UriInfo;
40 import javax.ws.rs.core.Response.Status;
42 import org.onap.dmaap.dbcapi.aaf.authentication.AuthenticationErrorException;
43 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
44 import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum;
45 import org.onap.dmaap.dbcapi.model.ApiError;
46 import org.onap.dmaap.dbcapi.model.BrTopic;
47 import org.onap.dmaap.dbcapi.model.DcaeLocation;
48 import org.onap.dmaap.dbcapi.model.Dmaap;
49 import org.onap.dmaap.dbcapi.model.MirrorMaker;
50 import org.onap.dmaap.dbcapi.service.ApiService;
51 import org.onap.dmaap.dbcapi.service.MirrorMakerService;
54 @Api( value= "bridge", description = "Endpoint for retreiving MR Bridge metrics" )
55 @Consumes(MediaType.APPLICATION_JSON)
56 @Produces(MediaType.APPLICATION_JSON)
58 public class BridgeResource extends BaseLoggingClass {
60 private MirrorMakerService mmService = new MirrorMakerService();
63 @ApiOperation( value = "return BrTopic details",
64 notes = "Returns array of `BrTopic` objects.",
65 response = BrTopic.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 getBridgedTopics(@QueryParam("source") String source,
71 @QueryParam("target") String target){
72 ApiService check = new ApiService();
74 BrTopic brTopic = new BrTopic();
76 logger.info( "getBridgeTopics():" + " source=" + source + ", target=" + target);
77 // System.out.println("getBridgedTopics() " + "source=" + source + ", target=" + target );
78 if (source != null && target != null) { // get topics between 2 bridged locations
79 brTopic.setBrSource(source);
80 brTopic.setBrTarget(target);
81 MirrorMaker mm = mmService.getMirrorMaker(source, target);
83 brTopic.setTopicCount( mm.getTopicCount() );
86 logger.info( "topicCount [2 locations]: " + brTopic.getTopicCount() );
88 else if (source == null && target == null ) {
89 List<String> mmList = mmService.getAllMirrorMakers();
90 brTopic.setBrSource("all");
91 brTopic.setBrTarget("all");
93 for( String key: mmList ) {
95 MirrorMaker mm = mmService.getMirrorMaker(key);
97 mCnt = mm.getTopicCount();
99 logger.info( "Count for "+ key + ": " + mCnt);
103 logger.info( "topicCount [all locations]: " + totCnt );
104 brTopic.setTopicCount(totCnt);
109 logger.error( "source or target is missing");
110 check.setCode(Status.BAD_REQUEST.getStatusCode());
111 check.setMessage("Either 2 locations or no location must be provided");
112 return check.error();
114 return check.success(brTopic);