Issue #2202 Add edex specific connectivity checking.

Change-Id: I003957001ed608d1054ab2a87019b018f8996d36

Former-commit-id: b8e5323b70db03817c6c750746f29cc550cbc815
This commit is contained in:
Ben Steffensmeier 2013-08-02 14:20:10 -05:00
parent 2c33f301df
commit cfd9cb0b7d
9 changed files with 106 additions and 48 deletions

View file

@ -20,6 +20,9 @@
package com.raytheon.uf.viz.core.comm; package com.raytheon.uf.viz.core.comm;
import java.net.URI; import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.jms.JMSException; import javax.jms.JMSException;
@ -27,6 +30,10 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import com.raytheon.uf.common.comm.HttpClient; import com.raytheon.uf.common.comm.HttpClient;
import com.raytheon.uf.common.localization.msgs.GetServersRequest;
import com.raytheon.uf.common.localization.msgs.GetServersResponse;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
/** /**
* Class for checking connectivity of http servers, currently only used for * Class for checking connectivity of http servers, currently only used for
@ -42,8 +49,10 @@ import com.raytheon.uf.common.comm.HttpClient;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Aug 12, 2009 mschenke Initial creation * Aug 12, 2009 mschenke Initial creation
* Mar 22, 2013 1786 mpduff Changed to use HttpClient for connectivity. * Mar 22, 2013 1786 mpduff Changed to use HttpClient for
* connectivity.
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -53,6 +62,13 @@ import com.raytheon.uf.common.comm.HttpClient;
public class ConnectivityManager { public class ConnectivityManager {
/*
* Since a get servers request is used for checking localization server
* connectivity, this map will cache the result in case it is needed later.
*/
private static final Map<String, GetServersResponse> getServersResponseCache = Collections
.synchronizedMap(new HashMap<String, GetServersResponse>(2));
public static class ConnectivityResult { public static class ConnectivityResult {
public boolean hasConnectivity; public boolean hasConnectivity;
@ -86,6 +102,43 @@ public class ConnectivityManager {
callback.connectionChecked(new ConnectivityResult(good, server)); callback.connectionChecked(new ConnectivityResult(good, server));
} }
/**
* Checks the connectivity of the given localization server
*
* @param server
* server to check
*/
public static void checkLocalizationServer(String server, IConnectivityCallback callback) {
boolean good = false;
try {
good = checkLocalizationServer(server, true) != null;
} catch (Exception e) {
// ignore
}
callback.connectionChecked(new ConnectivityResult(good, server));
}
/**
* Returns a GetServersResponse for the provided server. If force is false
* and this localization server has already been contacted then a cached
* result is returned, otherwise the localization server is contacted to get
* the response.
*/
public static GetServersResponse checkLocalizationServer(String server, boolean force)
throws VizException {
if (!force) {
GetServersResponse resp = getServersResponseCache.get(server);
if (resp != null) {
return resp;
}
}
GetServersRequest req = new GetServersRequest();
GetServersResponse resp = (GetServersResponse) ThriftClient.sendRequest(req, server);
getServersResponseCache.put(server, resp);
return resp;
}
/** /**
* Checks the connectivity of the given server * Checks the connectivity of the given server
* *

View file

@ -56,9 +56,10 @@ import com.raytheon.uf.common.util.FileUtil;
* *
* <pre> * <pre>
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* May 8, 2008 #878 chammack Initial creation * May 08, 2008 878 chammack Initial creation
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -68,9 +69,6 @@ import com.raytheon.uf.common.util.FileUtil;
public class CAVELocalizationAdapter implements ILocalizationAdapter { public class CAVELocalizationAdapter implements ILocalizationAdapter {
private static final LocalizationManager manager = LocalizationManager
.getInstance();
private final Map<LocalizationType, LocalizationContext[]> contexts; private final Map<LocalizationType, LocalizationContext[]> contexts;
public CAVELocalizationAdapter() { public CAVELocalizationAdapter() {
@ -170,8 +168,9 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
context.length); context.length);
if (serverContexts.size() > 0) { if (serverContexts.size() > 0) {
List<ListResponseEntry[]> entriesList = manager List<ListResponseEntry[]> entriesList = LocalizationManager
.getListResponseEntry(context, fileName, true, false); .getInstance().getListResponseEntry(context, fileName,
true, false);
for (int i = 0; i < context.length; i++) { for (int i = 0; i < context.length; i++) {
ListResponseEntry[] entries = entriesList.get(i); ListResponseEntry[] entries = entriesList.get(i);
@ -223,7 +222,7 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
return; return;
} }
manager.retrieve(file); LocalizationManager.getInstance().retrieve(file);
} }
/* /*
@ -241,8 +240,9 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
InputStream in = null; InputStream in = null;
try { try {
in = new LockingFileInputStream(localFile); in = new LockingFileInputStream(localFile);
long serverModTime = manager.upload(file.getContext(), long serverModTime = LocalizationManager.getInstance().upload(
file.getFileName(), in, localFile.length()); file.getContext(), file.getFileName(), in,
localFile.length());
// Success! set potentially changed fields // Success! set potentially changed fields
file.setTimeStamp(new Date(serverModTime)); file.setTimeStamp(new Date(serverModTime));
file.setIsAvailableOnServer(true); file.setIsAvailableOnServer(true);
@ -374,6 +374,7 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
List<ListResponse> responses = new ArrayList<ListResponse>( List<ListResponse> responses = new ArrayList<ListResponse>(
contexts.length); contexts.length);
LocalizationManager manager = LocalizationManager.getInstance();
if (serverContexts.size() > 0) { if (serverContexts.size() > 0) {
List<ListResponseEntry[]> entryList = manager.getListResponseEntry( List<ListResponseEntry[]> entryList = manager.getListResponseEntry(
serverContexts serverContexts
@ -469,7 +470,8 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
@Override @Override
public boolean delete(ModifiableLocalizationFile file) public boolean delete(ModifiableLocalizationFile file)
throws LocalizationOpFailedException { throws LocalizationOpFailedException {
long deleteTime = manager.delete(file.getContext(), file.getFileName()); long deleteTime = LocalizationManager.getInstance().delete(
file.getContext(), file.getFileName());
// Made it here! file on server succesfully deleted! Delete local file // Made it here! file on server succesfully deleted! Delete local file
// reference. If that fails, doesn't matter since file does not exist! // reference. If that fails, doesn't matter since file does not exist!
@ -595,7 +597,8 @@ public class CAVELocalizationAdapter implements ILocalizationAdapter {
@Override @Override
public String[] getContextList(LocalizationLevel level) public String[] getContextList(LocalizationLevel level)
throws LocalizationOpFailedException { throws LocalizationOpFailedException {
List<ListResponseEntry[]> entriesList = manager.getContextList(level); List<ListResponseEntry[]> entriesList = LocalizationManager
.getInstance().getContextList(level);
Set<String> fileList = new HashSet<String>(); Set<String> fileList = new HashSet<String>();
for (ListResponseEntry[] entryArr : entriesList) { for (ListResponseEntry[] entryArr : entriesList) {
for (ListResponseEntry entry : entryArr) { for (ListResponseEntry entry : entryArr) {

View file

@ -56,7 +56,8 @@ import com.raytheon.uf.viz.core.comm.IConnectivityCallback;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Aug 5, 2009 mschenke Initial creation * Aug 05, 2009 mschenke Initial creation
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -363,7 +364,7 @@ public class ConnectivityPreferenceDialog extends Dialog {
} }
private void validateLocalization() { private void validateLocalization() {
ConnectivityManager.checkHttpServer(localization, localizationCallback); ConnectivityManager.checkLocalizationServer(localization, localizationCallback);
} }
private void validateAlertviz() { private void validateAlertviz() {

View file

@ -28,13 +28,12 @@ import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.msgs.GetServersRequest;
import com.raytheon.uf.common.localization.msgs.GetServersResponse; import com.raytheon.uf.common.localization.msgs.GetServersResponse;
import com.raytheon.uf.common.util.FileUtil; import com.raytheon.uf.common.util.FileUtil;
import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.VizServers; import com.raytheon.uf.viz.core.VizServers;
import com.raytheon.uf.viz.core.comm.ConnectivityManager;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.ThriftClient;
/** /**
* Class that does work of checking localization server, popping up dialog if * Class that does work of checking localization server, popping up dialog if
@ -47,9 +46,10 @@ import com.raytheon.uf.viz.core.requests.ThriftClient;
* SOFTWARE HISTORY * SOFTWARE HISTORY
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 5, 2009 mschenke Initial creation * Nov 05, 2009 mschenke Initial creation
* Sep 12, 2012 1167 djohnson Add datadelivery servers. * Sep 12, 2012 1167 djohnson Add datadelivery servers.
* Jan 14, 2013 1469 bkowal Removed the hdf5 data directory. * Jan 14, 2013 1469 bkowal Removed the hdf5 data directory.
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -121,9 +121,9 @@ public class LocalizationInitializer {
* @throws VizException * @throws VizException
*/ */
protected final void processGetServers() throws VizException { protected final void processGetServers() throws VizException {
GetServersRequest req = new GetServersRequest(); GetServersResponse resp = ConnectivityManager.checkLocalizationServer(
GetServersResponse resp = (GetServersResponse) ThriftClient LocalizationManager.getInstance().getLocalizationServer(),
.sendLocalizationRequest(req); false);
VizApp.setHttpServer(resp.getHttpServer()); VizApp.setHttpServer(resp.getHttpServer());
VizApp.setJmsServer(resp.getJmsServer()); VizApp.setJmsServer(resp.getJmsServer());
VizApp.setPypiesServer(resp.getPypiesServer()); VizApp.setPypiesServer(resp.getPypiesServer());

View file

@ -55,7 +55,6 @@ import com.raytheon.uf.common.localization.msgs.AbstractPrivilegedUtilityCommand
import com.raytheon.uf.common.localization.msgs.AbstractUtilityResponse; import com.raytheon.uf.common.localization.msgs.AbstractUtilityResponse;
import com.raytheon.uf.common.localization.msgs.DeleteUtilityCommand; import com.raytheon.uf.common.localization.msgs.DeleteUtilityCommand;
import com.raytheon.uf.common.localization.msgs.DeleteUtilityResponse; import com.raytheon.uf.common.localization.msgs.DeleteUtilityResponse;
import com.raytheon.uf.common.localization.msgs.GetServersRequest;
import com.raytheon.uf.common.localization.msgs.GetServersResponse; import com.raytheon.uf.common.localization.msgs.GetServersResponse;
import com.raytheon.uf.common.localization.msgs.GetUtilityCommand; import com.raytheon.uf.common.localization.msgs.GetUtilityCommand;
import com.raytheon.uf.common.localization.msgs.ListContextCommand; import com.raytheon.uf.common.localization.msgs.ListContextCommand;
@ -73,6 +72,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.application.ProgramArguments; import com.raytheon.uf.viz.application.ProgramArguments;
import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.VizServers; import com.raytheon.uf.viz.core.VizServers;
import com.raytheon.uf.viz.core.comm.ConnectivityManager;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.requests.PrivilegedRequestFactory; import com.raytheon.uf.viz.core.requests.PrivilegedRequestFactory;
import com.raytheon.uf.viz.core.requests.ThriftClient; import com.raytheon.uf.viz.core.requests.ThriftClient;
@ -85,13 +85,14 @@ import com.raytheon.uf.viz.core.requests.ThriftClient;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 17, 2007 chammack Initial Creation. * Apr 17, 2007 chammack Initial Creation.
* Jul 24, 2007 njensen Added upload(). * Jul 24, 2007 njensen Added upload().
* Jul 30, 2007 njensen Refactored. * Jul 30, 2007 njensen Refactored.
* Feb 12, 2008 chammack Removed base configuration * Feb 12, 2008 chammack Removed base configuration
* Mar 26, 2008 njensen Added rename() and getFileContents(). * Mar 26, 2008 njensen Added rename() and getFileContents().
* May 19, 2007 #1127 randerso Implemented error handling * May 19, 2007 1127 randerso Implemented error handling
* Sep 12, 2012 1167 djohnson Add datadelivery servers. * Sep 12, 2012 1167 djohnson Add datadelivery servers.
* Jan 14, 2013 1469 bkowal Removed the hdf5 data directory. * Jan 14, 2013 1469 bkowal Removed the hdf5 data directory.
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -217,10 +218,9 @@ public class LocalizationManager implements IPropertyChangeListener {
applyChanges(); applyChanges();
} }
GetServersRequest req = new GetServersRequest();
try { try {
GetServersResponse resp = (GetServersResponse) ThriftClient GetServersResponse resp = ConnectivityManager.checkLocalizationServer(
.sendLocalizationRequest(req); currentServer, false);
VizApp.setHttpServer(resp.getHttpServer()); VizApp.setHttpServer(resp.getHttpServer());
VizApp.setJmsServer(resp.getJmsServer()); VizApp.setJmsServer(resp.getJmsServer());
VizApp.setPypiesServer(resp.getPypiesServer()); VizApp.setPypiesServer(resp.getPypiesServer());

View file

@ -60,6 +60,7 @@ import com.raytheon.uf.viz.core.comm.IConnectivityCallback;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 18, 2007 chammack Initial Creation. * Apr 18, 2007 chammack Initial Creation.
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -217,7 +218,7 @@ public class LocalizationPreferences extends FieldEditorPreferencePage
private void checkConnectivity() { private void checkConnectivity() {
final ConnectivityResult result = new ConnectivityResult(false, ""); final ConnectivityResult result = new ConnectivityResult(false, "");
Text text = localizationEditor.getTextControl(getFieldEditorParent()); Text text = localizationEditor.getTextControl(getFieldEditorParent());
ConnectivityManager.checkHttpServer(text.getText().trim(), ConnectivityManager.checkLocalizationServer(text.getText().trim(),
new IConnectivityCallback() { new IConnectivityCallback() {
@Override @Override
public void connectionChecked(ConnectivityResult results) { public void connectionChecked(ConnectivityResult results) {

View file

@ -47,8 +47,10 @@ import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 8, 2011 mschenke Initial creation * Nov 08, 2011 mschenke Initial creation
* Jan 14, 2013 1469 bkowal The hdf5 data directory is no longer a preference. * Jan 14, 2013 1469 bkowal The hdf5 data directory is no longer a
* preference.
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -135,7 +137,7 @@ public class ThinClientServerPreferences extends FieldEditorPreferencePage {
// check HTTP Server // check HTTP Server
Text text = servicesServer.getTextControl(getFieldEditorParent()); Text text = servicesServer.getTextControl(getFieldEditorParent());
ConnectivityManager.checkHttpServer(text.getText().trim(), ConnectivityManager.checkLocalizationServer(text.getText().trim(),
new IConnectivityCallback() { new IConnectivityCallback() {
@Override @Override
public void connectionChecked(ConnectivityResult results) { public void connectionChecked(ConnectivityResult results) {

View file

@ -25,14 +25,13 @@ import org.apache.commons.collections.map.DefaultedMap;
import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.IPreferenceStore;
import com.raytheon.uf.common.comm.HttpClient; import com.raytheon.uf.common.comm.HttpClient;
import com.raytheon.uf.common.localization.msgs.GetServersRequest;
import com.raytheon.uf.common.localization.msgs.GetServersResponse; import com.raytheon.uf.common.localization.msgs.GetServersResponse;
import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.VizApp;
import com.raytheon.uf.viz.core.VizServers; import com.raytheon.uf.viz.core.VizServers;
import com.raytheon.uf.viz.core.comm.ConnectivityManager;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.localization.LocalizationInitializer; import com.raytheon.uf.viz.core.localization.LocalizationInitializer;
import com.raytheon.uf.viz.core.localization.LocalizationManager; import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.uf.viz.core.requests.ThriftClient;
import com.raytheon.uf.viz.thinclient.Activator; import com.raytheon.uf.viz.thinclient.Activator;
import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants; import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
import com.raytheon.uf.viz.thinclient.ui.ThinClientConnectivityDialog; import com.raytheon.uf.viz.thinclient.ui.ThinClientConnectivityDialog;
@ -47,9 +46,10 @@ import com.raytheon.uf.viz.thinclient.ui.ThinClientConnectivityDialog;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 23, 2011 bsteffen Initial creation * Nov 23, 2011 bsteffen Initial creation
* Dec 06, 2012 1396 njensen Added setting VizServers * Dec 06, 2012 1396 njensen Added setting VizServers
* Jan 14, 2013 1469 bkowal Removed setting the hdf5 data directory * Jan 14, 2013 1469 bkowal Removed setting the hdf5 data directory
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -88,12 +88,9 @@ public class ThinClientLocalizationInitializer extends LocalizationInitializer {
.getString(ThinClientPreferenceConstants.P_SERVICES_PROXY); .getString(ThinClientPreferenceConstants.P_SERVICES_PROXY);
LocalizationManager.getInstance().setCurrentServer(servicesProxy); LocalizationManager.getInstance().setCurrentServer(servicesProxy);
if (!disableJMS) { if (!disableJMS) {
GetServersRequest req = new GetServersRequest(); GetServersResponse resp = ConnectivityManager.checkLocalizationServer(
GetServersResponse resp = (GetServersResponse) ThriftClient servicesProxy, false);
.sendLocalizationRequest(req); VizApp.setJmsServer(resp.getJmsServer());
if (!disableJMS) {
VizApp.setJmsServer(resp.getJmsServer());
}
} }
VizApp.setHttpServer(servicesProxy); VizApp.setHttpServer(servicesProxy);
VizApp.setPypiesServer(store VizApp.setPypiesServer(store

View file

@ -53,7 +53,8 @@ import com.raytheon.uf.viz.thinclient.preferences.ThinClientPreferenceConstants;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Nov 23, 2011 bsteffen Initial creation * Nov 23, 2011 bsteffen Initial creation
* Aug 02, 2013 2202 bsteffen Add edex specific connectivity checking.
* *
* </pre> * </pre>
* *
@ -237,7 +238,7 @@ public class ThinClientConnectivityDialog extends ConnectivityPreferenceDialog {
} }
private void validateServices() { private void validateServices() {
ConnectivityManager.checkHttpServer(services, servicesCallback); ConnectivityManager.checkLocalizationServer(services, servicesCallback);
} }
private void validatePypies() { private void validatePypies() {