Issue #2694 Converted GetBrokerConnections to Java.
Change-Id: Ic9445906ed88036d6598ffec0319de9c89f8c163 Former-commit-id:6222cb6eb9
[formerly7c9f4091c2
] [formerlyd16380e50e
] [formerlyd16380e50e
[formerlya6794beaa5
]] [formerlydf9c5c81d6
[formerlyd16380e50e
[formerlya6794beaa5
] [formerlydf9c5c81d6
[formerly 102c81e1aafdcfa171440df1cba97d27b2ba3c2a]]]] Former-commit-id:df9c5c81d6
Former-commit-id: b4c4e64b16df7d08436aef4a610aea258919fda9 [formerly 7524b26cc572e199e0f694889a08af77618fbbde] [formerlyd1cb494222
[formerlyd778e9dac6
]] Former-commit-id:d1cb494222
Former-commit-id:454323fd74
This commit is contained in:
parent
e72d27de65
commit
a7123fd58e
8 changed files with 169 additions and 130 deletions
|
@ -41,8 +41,9 @@ export EBXML_REGISTRY_FEDERATION_ENABLED=true
|
|||
# these values are returned to clients that contact the localization service
|
||||
export HTTP_PORT=9581
|
||||
export HTTP_SERVER=http://localhost:${HTTP_PORT}/services
|
||||
export JMS_SERVER=tcp://localhost:5672
|
||||
export JMS_SERVER=tcp://${BROKER_ADDR}:5672
|
||||
export JMS_VIRTUALHOST=edex
|
||||
export JMS_CONNECTIONS_URL=http://${BROKER_ADDR}:8180/rest/connection/${JMS_VIRTUALHOST}
|
||||
export RADAR_SERVER=tcp://localhost:8813
|
||||
export DATADELIVERY_SERVER=http://${DATADELIVERY_HOST}:${EBXML_THRIFT_SERVICE_PORT}/services
|
||||
export EBXML_REGISTRY_SERVICE=http://${EBXML_REGISTRY_HOST}:${EBXML_THRIFT_SERVICE_PORT}/services
|
||||
|
|
|
@ -28,7 +28,8 @@ Require-Bundle: com.raytheon.uf.common.dataplugin.gfe;bundle-version="1.12.1174"
|
|||
com.google.guava;bundle-version="1.0.0",
|
||||
org.apache.commons.lang;bundle-version="2.3.0",
|
||||
com.raytheon.uf.common.python.concurrent;bundle-version="1.0.0",
|
||||
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174"
|
||||
com.raytheon.uf.common.dataplugin.level;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.edex.esb.camel;bundle-version="1.12.1174"
|
||||
Export-Package: com.raytheon.edex.plugin.gfe,
|
||||
com.raytheon.edex.plugin.gfe.config,
|
||||
com.raytheon.edex.plugin.gfe.db.dao,
|
||||
|
|
|
@ -32,7 +32,10 @@
|
|||
<constructor-arg value="com.raytheon.uf.common.dataplugin.gfe.request.ClearPracticeVTECTableRequest"/>
|
||||
<constructor-arg ref="clearTableHandler"/>
|
||||
</bean>
|
||||
<bean id="clientsHandler" class="com.raytheon.edex.plugin.gfe.server.handler.GetClientsHandler"/>
|
||||
<bean id="brokerConnectionsProvider" class="com.raytheon.uf.edex.esb.camel.jms.QpidBrokerConnectionsImpl"/>
|
||||
<bean id="clientsHandler" class="com.raytheon.edex.plugin.gfe.server.handler.GetClientsHandler">
|
||||
<constructor-arg ref="brokerConnectionsProvider"/>
|
||||
</bean>
|
||||
<bean factory-bean="handlerRegistry" factory-method="register">
|
||||
<constructor-arg value="com.raytheon.uf.common.dataplugin.gfe.request.GetClientsRequest"/>
|
||||
<constructor-arg ref="clientsHandler"/>
|
||||
|
|
|
@ -19,36 +19,27 @@
|
|||
**/
|
||||
package com.raytheon.edex.plugin.gfe.server.handler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import jep.JepException;
|
||||
|
||||
import com.raytheon.uf.common.dataplugin.gfe.request.GetClientsRequest;
|
||||
import com.raytheon.uf.common.dataplugin.gfe.server.message.ServerResponse;
|
||||
import com.raytheon.uf.common.localization.IPathManager;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
|
||||
import com.raytheon.uf.common.localization.PathManagerFactory;
|
||||
import com.raytheon.uf.common.python.PythonScript;
|
||||
import com.raytheon.uf.common.serialization.comm.IRequestHandler;
|
||||
import com.raytheon.uf.common.status.IUFStatusHandler;
|
||||
import com.raytheon.uf.common.status.UFStatus;
|
||||
import com.raytheon.uf.common.status.UFStatus.Priority;
|
||||
import com.raytheon.uf.edex.esb.camel.jms.IBrokerConnectionsProvider;
|
||||
|
||||
/**
|
||||
* TODO Add Description
|
||||
* Handler for get clients request. Returns list of Client IDs for all clients
|
||||
* connected to the JMS broker
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 21, 2009 randerso Initial creation
|
||||
* 09/22/09 3058 rjpeter Converted to IRequestHandler
|
||||
* May 21, 2009 randerso Initial creation
|
||||
* Sep 22, 2009 3058 rjpeter Converted to IRequestHandler
|
||||
* Apr 04, 2014 #2694 randerso Changed to use Java implementation
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
|
@ -58,64 +49,31 @@ public class GetClientsHandler implements IRequestHandler<GetClientsRequest> {
|
|||
private static final transient IUFStatusHandler statusHandler = UFStatus
|
||||
.getHandler(GetClientsHandler.class);
|
||||
|
||||
// TODO: Use better caching mechanism
|
||||
private static ThreadLocal<PythonScript> scriptCache = new ThreadLocal<PythonScript>() {
|
||||
private IBrokerConnectionsProvider provider;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.ThreadLocal#initialValue()
|
||||
*/
|
||||
@Override
|
||||
public PythonScript initialValue() {
|
||||
IPathManager pathMgr = PathManagerFactory.getPathManager();
|
||||
LocalizationContext lc = pathMgr.getContext(
|
||||
LocalizationType.COMMON_STATIC, LocalizationLevel.BASE);
|
||||
|
||||
File file = pathMgr.getFile(lc, "GetBrokerConnections.py");
|
||||
if (file == null) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Unable to find GetBrokerConnections.py");
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
ArrayList<String> preevals = new ArrayList<String>(1);
|
||||
preevals.add("sys.argv = ['GetBrokerConnections']");
|
||||
return new PythonScript(file.getAbsolutePath(), "", this
|
||||
.getClass().getClassLoader(), preevals);
|
||||
} catch (JepException e) {
|
||||
statusHandler.handle(Priority.PROBLEM,
|
||||
"Unable to set up GetBrokerConnections.py", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param provider
|
||||
* broker connections provider implementation
|
||||
*/
|
||||
public GetClientsHandler(IBrokerConnectionsProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse<List<String>> handleRequest(GetClientsRequest request)
|
||||
throws Exception {
|
||||
|
||||
ServerResponse<List<String>> sr = new ServerResponse<List<String>>();
|
||||
List<String> clients = new ArrayList<String>();
|
||||
sr.setPayload(clients);
|
||||
|
||||
PythonScript ps = scriptCache.get();
|
||||
|
||||
HashMap<String, Object> argsHash = new HashMap<String, Object>();
|
||||
argsHash.put("brokerHost", System.getenv("BROKER_ADDR"));
|
||||
try {
|
||||
Object obj = ps.execute("getConnections", argsHash);
|
||||
if (obj instanceof String[]) {
|
||||
for (String s : (String[]) obj) {
|
||||
clients.add(s);
|
||||
}
|
||||
}
|
||||
} catch (JepException e) {
|
||||
sr.addMessage("Error getting client list - " + e.getMessage());
|
||||
List<String> clients = provider.getConnections();
|
||||
sr.setPayload(clients);
|
||||
} catch (Exception e) {
|
||||
statusHandler.error("Unable to retrieve active client list: ", e);
|
||||
sr.addMessage("Server error trying to retrieve clientlist: "
|
||||
+ e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
return sr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
##
|
||||
# This software was developed and / or modified by Raytheon Company,
|
||||
# pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
#
|
||||
# U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
# This software product contains export-restricted data whose
|
||||
# export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
# to non-U.S. persons whether in the United States or abroad requires
|
||||
# an export license or other authorization.
|
||||
#
|
||||
# Contractor Name: Raytheon Company
|
||||
# Contractor Address: 6825 Pine Street, Suite 340
|
||||
# Mail Stop B8
|
||||
# Omaha, NE 68106
|
||||
# 402.291.0100
|
||||
#
|
||||
# See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
# further licensing information.
|
||||
##
|
||||
##
|
||||
# Returns the client ids of all connections established to qpid.
|
||||
#
|
||||
#
|
||||
# SOFTWARE HISTORY
|
||||
#
|
||||
# Date Ticket# Engineer Description
|
||||
# ------------ ---------- ----------- --------------------------
|
||||
# 03/21/13 1814 rjpeter Updated to use rest API for java broker
|
||||
# 01/15/14 2660 randerso Log status and reason if request fails
|
||||
##
|
||||
import httplib
|
||||
import json
|
||||
|
||||
def getConnections(brokerHost, port=8180):
|
||||
# Use rest services to pull connection clientId
|
||||
# http://cp1f:9090/rest/connection
|
||||
# port needs to be passed as a parameter
|
||||
# parse json response for clientId, recommend using a hash of some kind
|
||||
if (port is None):
|
||||
httpConn = httplib.HTTPConnection(brokerHost)
|
||||
else:
|
||||
httpConn = httplib.HTTPConnection(brokerHost, port)
|
||||
|
||||
httpConn.connect()
|
||||
httpConn.request("GET", "/rest/connection/edex")
|
||||
response = httpConn.getresponse()
|
||||
|
||||
if (response.status != 200):
|
||||
msg = "Broker %s returned %d %s" % (brokerHost, response.status, response.reason)
|
||||
raise Exception(msg)
|
||||
|
||||
jsonStr = response.read()
|
||||
jsonObjArray = json.loads(jsonStr)
|
||||
resultSet = set()
|
||||
|
||||
for statDict in jsonObjArray:
|
||||
clientId = statDict.get("clientId")
|
||||
if clientId:
|
||||
resultSet.add(clientId)
|
||||
|
||||
return list(resultSet)
|
|
@ -15,9 +15,12 @@ Require-Bundle: org.apache.camel;bundle-version="1.0.0",
|
|||
com.raytheon.uf.edex.core,
|
||||
com.raytheon.uf.common.stats;bundle-version="1.0.0",
|
||||
org.quartz;bundle-version="1.8.6",
|
||||
org.slf4j;bundle-version="1.7.5"
|
||||
org.slf4j;bundle-version="1.7.5",
|
||||
com.raytheon.uf.common.comm;bundle-version="1.12.1174",
|
||||
com.raytheon.uf.common.json;bundle-version="1.0.0"
|
||||
Export-Package: com.raytheon.uf.edex.esb.camel,
|
||||
com.raytheon.uf.edex.esb.camel.directvm
|
||||
com.raytheon.uf.edex.esb.camel.directvm,
|
||||
com.raytheon.uf.edex.esb.camel.jms
|
||||
Import-Package: com.raytheon.uf.common.event,
|
||||
com.raytheon.uf.common.message,
|
||||
com.raytheon.uf.edex.database.cluster,
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.jms;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface for retrieving list of client IDs of active broker connections
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 4, 2014 randerso Initial creation
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
* @version 1.0
|
||||
*/
|
||||
public interface IBrokerConnectionsProvider {
|
||||
|
||||
/**
|
||||
* @return list of Client IDs for active broker connections
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public List<String> getConnections() throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.edex.esb.camel.jms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
import com.raytheon.uf.common.comm.HttpClient;
|
||||
import com.raytheon.uf.common.comm.HttpClient.HttpClientResponse;
|
||||
import com.raytheon.uf.common.json.geo.BasicJsonService;
|
||||
|
||||
/**
|
||||
* Qpid implementation of IBrokerConnectionsProvider
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Apr 04, 2014 #2694 randerso Converted python implementation to Java
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author randerso
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class QpidBrokerConnectionsImpl implements IBrokerConnectionsProvider {
|
||||
@Override
|
||||
public List<String> getConnections() throws Exception {
|
||||
// Use rest services to pull connection clientId
|
||||
// http://brokerHost:port/rest/connection/edex
|
||||
// port needs to be passed as a parameter
|
||||
// parse json response for clientId, recommend using a hash of some kind
|
||||
|
||||
String url = System.getenv("JMS_CONNECTIONS_URL");
|
||||
|
||||
HttpGet request = new HttpGet(url);
|
||||
HttpClientResponse response = HttpClient.getInstance().executeRequest(
|
||||
request);
|
||||
if (!response.isSuccess()) {
|
||||
String msg = String.format("Broker returned %d %s", response.code,
|
||||
new String(response.data));
|
||||
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
String jsonStr = new String(response.data);
|
||||
|
||||
BasicJsonService json = new BasicJsonService();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> jsonObjList = (List<Map<String, Object>>) json
|
||||
.deserialize(jsonStr, Object.class);
|
||||
|
||||
List<String> resultSet = new ArrayList<String>();
|
||||
for (Map<String, Object> statDict : jsonObjList) {
|
||||
String clientId = (String) statDict.get("clientId");
|
||||
if (clientId != null) {
|
||||
resultSet.add(clientId);
|
||||
}
|
||||
}
|
||||
return resultSet;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue