Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBIDE-16133: Provide better feedback for incorrect admin password #267

Merged
merged 1 commit into from
Dec 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,20 @@ public void run() {

getServerManager().addListener(excutionConfigListener);

TeiidServerAdapterFactory adapterFactory = new TeiidServerAdapterFactory();
if (parentServer.getServerState() == IServer.STATE_STARTED)
// If server is started we can be more adventurous in what to display since we can ask
// the server whether teiid has been installed.
teiidServer = adapterFactory.adaptServer(parentServer, ServerOptions.ADD_TO_REGISTRY);
else {
// Cannot ask a lot except whether the server is a JBoss Server
teiidServer = adapterFactory.adaptServer(parentServer,
try {
TeiidServerAdapterFactory adapterFactory = new TeiidServerAdapterFactory();
if (parentServer.getServerState() == IServer.STATE_STARTED)
// If server is started we can be more adventurous in what to display since we can ask
// the server whether teiid has been installed.
teiidServer = adapterFactory.adaptServer(parentServer, ServerOptions.ADD_TO_REGISTRY);
else {
// Cannot ask a lot except whether the server is a JBoss Server
teiidServer = adapterFactory.adaptServer(parentServer,
ServerOptions.NO_CHECK_CONNECTION,
ServerOptions.ADD_TO_REGISTRY);
}
} catch (Exception ex) {
DqpPlugin.handleException(ex);
}

if (teiidServer != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public String getText() {
public ITeiidServer getTeiidServer() {
return teiidServer;
}

@Override
public String toString() {
return text;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
import java.util.ResourceBundle;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.server.core.IServer;
import org.osgi.framework.BundleContext;
import org.teiid.core.designer.PluginUtil;
Expand All @@ -26,7 +31,6 @@
import org.teiid.designer.core.workspace.ModelWorkspaceNotificationAdapter;
import org.teiid.designer.extension.ExtensionPlugin;
import org.teiid.designer.extension.registry.ModelExtensionRegistry;
import org.teiid.designer.runtime.connection.spi.IPasswordProvider;
import org.teiid.designer.runtime.extension.rest.RestModelExtensionAssistant;
import org.teiid.designer.runtime.extension.rest.RestModelExtensionConstants;
import org.teiid.designer.runtime.preview.PreviewManager;
Expand Down Expand Up @@ -89,11 +93,6 @@ public static DqpPlugin getInstance() {
* Provider of the {@link IServer}s collection
*/
private IServersProvider serversProvider;

/**
* The password provider to be used in the server manager's preview manager
*/
private IPasswordProvider passwordProvider;

/**
* Obtains the current plugin preferences values.
Expand Down Expand Up @@ -279,4 +278,62 @@ void handleNewModelEvent(final ModelWorkspaceNotification notification) {
}
}

private static Display getDisplay() {
return (Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent());
}

/**
* @param operation The operation to be executed in the SWT thread.
* @param asynchronous True if the operation should be run asynchronously, meaning the calling thread will not be blocked.
*/
private static void runInSwtThread( final Runnable operation, final boolean asynchronous ) {
Display display = getDisplay();
if (Thread.currentThread() != display.getThread()) {
if (asynchronous) {
display.asyncExec(operation);
} else {
display.syncExec(operation);
}
} else {
operation.run();
}
}

/**
* Convey the given exception to the user.
*
* @param ex
*/
public static void handleException(final Exception ex) {
/**
* TODO
* Not ideal as we are calling a UI dialog in a technically non-UI plugin.
* However, it already depends on org.eclipse.ui so free to use this stuff
* and displaying an error dialog is crucial to the user.
*/

Util.log(ex);

Runnable runnable = new Runnable() {

@Override
public void run() {
String title = Util.getString("TeiidParentServerListener.initTeiidServerException.title"); //$NON-NLS-1$
String message = Util.getString("TeiidParentServerListener.initTeiidServerException.message"); //$NON-NLS-1$
String reason = Util.getString("TeiidParentServerListener.initTeiidServerException.reason"); //$NON-NLS-1$

MultiStatus multiStatus = new MultiStatus(PLUGIN_ID, 0, reason, null);
Throwable throwable = ex;
do {
Status status = new Status(IStatus.ERROR, PLUGIN_ID, " * " + throwable.getLocalizedMessage()); //$NON-NLS-1$
multiStatus.add(status);
throwable = throwable.getCause();
} while (throwable != null);

ErrorDialog.openError(getDisplay().getActiveShell(), title, message, multiStatus);
}
};

runInSwtThread(runnable, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/
package org.teiid.designer.runtime;

import static org.teiid.designer.runtime.DqpPlugin.Util;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerLifecycleListener;
import org.eclipse.wst.server.core.IServerListener;
Expand Down Expand Up @@ -42,7 +41,7 @@ public static TeiidParentServerListener getInstance() {
private boolean sleep;

private TeiidParentServerListener() {}

@Override
public void serverAdded(IServer server) {
if (sleep) return;
Expand All @@ -53,35 +52,43 @@ public void serverAdded(IServer server) {
server.addServerListener(this);

// New server added so add a teiid instance, even though it is not currently connected
factory.adaptServer(server, ServerOptions.NO_CHECK_CONNECTION, ServerOptions.ADD_TO_REGISTRY);
try {
factory.adaptServer(server, ServerOptions.NO_CHECK_CONNECTION, ServerOptions.ADD_TO_REGISTRY);
} catch (final Exception ex) {
DqpPlugin.handleException(ex);
}
}

@Override
public void serverChanged(IServer server) {
if (sleep) return;

ITeiidServerManager serverManager = DqpPlugin.getInstance().getServerManager();

for (ITeiidServer teiidServer : serverManager.getServers()) {
if (! server.equals(teiidServer.getParent()))
continue;

ITeiidServer newTeiidServer = factory.adaptServer(server, ServerOptions.NO_CHECK_SERVER_REGISTRY, ServerOptions.NO_CHECK_CONNECTION);

// Cannot use updateServer as it replaces rather than modified the existing server
// and references in editor will thus hang on to the old defunct version
teiidServer.update(newTeiidServer);
teiidServer.notifyRefresh();

try {
for (ITeiidServer teiidServer : serverManager.getServers()) {
if (! server.equals(teiidServer.getParent()))
continue;

ITeiidServer newTeiidServer = factory.adaptServer(server, ServerOptions.NO_CHECK_SERVER_REGISTRY, ServerOptions.NO_CHECK_CONNECTION);

return;
}
// Cannot use updateServer as it replaces rather than modified the existing server
// and references in editor will thus hang on to the old defunct version
teiidServer.update(newTeiidServer);
teiidServer.notifyRefresh();

return;
}

/*
* We have a parent server with no Teiid Instance attached
* This may be intentional if the parent server is not teiid
* enabled but should check just in case.
*/
factory.adaptServer(server, ServerOptions.ADD_TO_REGISTRY);
/*
* We have a parent server with no Teiid Instance attached
* This may be intentional if the parent server is not teiid
* enabled but should check just in case.
*/
factory.adaptServer(server, ServerOptions.ADD_TO_REGISTRY);
} catch (Exception ex) {
DqpPlugin.handleException(ex);
}
}

@Override
Expand Down Expand Up @@ -116,39 +123,39 @@ public void serverChanged(ServerEvent event) {
int state = event.getState();
IServer parentServer = event.getServer();

if (state == IServer.STATE_STOPPING || state == IServer.STATE_STOPPED) {
ITeiidServer teiidServer = factory.adaptServer(parentServer);
if (teiidServer != null)
teiidServer.disconnect();
try {
if (state == IServer.STATE_STOPPING || state == IServer.STATE_STOPPED) {
ITeiidServer teiidServer = factory.adaptServer(parentServer);
if (teiidServer != null)
teiidServer.disconnect();

} else if (state == IServer.STATE_STARTED) {

ITeiidServer teiidServer = factory.adaptServer(parentServer, ServerOptions.ADD_TO_REGISTRY);
if (teiidServer != null && teiidServer.isParentConnected()) {
/*
* Update all the settings since the server has been started and a
* proper set of queries can take place.
*/
ITeiidServer queryServer = factory.adaptServer(parentServer,
} else if (state == IServer.STATE_STARTED) {

ITeiidServer teiidServer = factory.adaptServer(parentServer, ServerOptions.ADD_TO_REGISTRY);
if (teiidServer != null && teiidServer.isParentConnected()) {
/*
* Update all the settings since the server has been started and a
* proper set of queries can take place.
*/
ITeiidServer queryServer = factory.adaptServer(parentServer,
ServerOptions.NO_CHECK_SERVER_REGISTRY);

if (queryServer != null)
teiidServer.update(queryServer);
else {
// If the query server is null then this is not a Teiid-enabled JBoss Server but
// a TeiidServer was cached in the registry, presumably due to an adaption
// being made while the server was not started. Since we now know better, we
// can correct the registry.
DqpPlugin.getInstance().getServerManager().removeServer(teiidServer);
}

try {
if (queryServer != null)
teiidServer.update(queryServer);
else {
// If the query server is null then this is not a Teiid-enabled JBoss Server but
// a TeiidServer was cached in the registry, presumably due to an adaption
// being made while the server was not started. Since we now know better, we
// can correct the registry.
DqpPlugin.getInstance().getServerManager().removeServer(teiidServer);
}

teiidServer.reconnect();
} catch (Exception ex) {
Util.log(ex);
}

}
}
} catch (Exception ex) {
DqpPlugin.handleException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,26 @@ public void connect() throws Exception {
}

if (this.admin == null) {
this.admin = TeiidRuntimeRegistry.getInstance().getExecutionAdmin(this);
try {
this.admin = TeiidRuntimeRegistry.getInstance().getExecutionAdmin(this);

if (admin != null) {
/*
* Avoid the refresh listener being fired prematurely by the admin client.
* Want to fire the refresh ourselves using {#notifyRefresh} at the end
* of this function.
*/
getEventManager().permitListeners(false);
try {
if (admin != null) {
/*
* Avoid the refresh listener being fired prematurely by the admin client.
* Want to fire the refresh ourselves using {#notifyRefresh} at the end
* of this function.
*/
getEventManager().permitListeners(false);

this.admin.connect();
} catch (Exception ex) {
throw ex;
} finally {
getEventManager().permitListeners(true);
}
} catch (Exception ex) {
throw ex;
} finally {
getEventManager().permitListeners(true);
}

getEventManager().notifyListeners(ExecutionConfigurationEvent.createServerConnectedEvent(this));

notifyRefresh();
}
}
Expand All @@ -207,8 +207,13 @@ public void reconnect() {
try {
// Call disconnect() first to clear out Server & admin caches
getEventManager().permitListeners(false);
disconnect();
getEventManager().permitListeners(true);
try {
disconnect();
} catch (Exception ex) {
throw ex;
} finally {
getEventManager().permitListeners(true);
}

if (isParentConnected()) {
// Refresh is implied in the getting of the admin object since it will
Expand All @@ -219,6 +224,11 @@ public void reconnect() {
}

setConnectionError(null);
} catch (IllegalArgumentException e) {
DqpPlugin.Util.log(e);
String msg = DqpPlugin.Util.getString("serverReconnectErrorMsg", this) + "\n" + //$NON-NLS-1$ //$NON-NLS-2$
DqpPlugin.Util.getString("serverAdminInitError"); //$NON-NLS-1$
setConnectionError(msg);
} catch (Exception e) {
DqpPlugin.Util.log(e);
String msg = DqpPlugin.Util.getString("serverReconnectErrorMsg", this) + "\n" + e.getLocalizedMessage(); //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -317,8 +327,13 @@ public boolean isParentConnected() {
if(this.parentServer == null || this.parentServer.getServerState() != IServer.STATE_STARTED)
return false;

TeiidServerAdapterFactory factory = new TeiidServerAdapterFactory();
return factory.isParentServerConnected(parentServer);
try {
TeiidServerAdapterFactory factory = new TeiidServerAdapterFactory();
return factory.isParentServerConnected(parentServer);
} catch (Exception ex) {
DqpPlugin.Util.log(ex);
return false;
}
}

/**
Expand Down