Skip to content

Commit

Permalink
TEIIDDES-1518: Fixes teiid server manager restore state failure
Browse files Browse the repository at this point in the history
* TeiidServerManager restore state is failing to find a parent server for
  2 reasons:
 * Being called too soon by NewServerAction
 * Cannot find 7.7.2 servers due to adapting to jboss 7 server rather than
   jboss 5 server

* NewServerAction
 * Lazily assign teiid server manager when action is executed

* DqpPlugin
 * Log an exception if further attempts are made to initialise server manager
   before the workbench has initialised
  • Loading branch information
Paul Richardson committed Dec 18, 2012
1 parent 0f9104a commit 0ceb18a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
*/
public class NewServerAction extends Action implements IHandler {

/**
* The server manager used to create and edit servers.
*/
private final TeiidServerManager teiidServerManager;

/**
* The shell used to display the dialog that edits and creates servers.
*/
Expand All @@ -47,8 +42,6 @@ public NewServerAction() {
setToolTipText(UTIL.getString("newServerActionToolTip")); //$NON-NLS-1$
setImageDescriptor(DqpUiPlugin.getDefault().getImageDescriptor(DqpUiConstants.Images.NEW_SERVER_ICON));
}

this.teiidServerManager = DqpPlugin.getInstance().getServerManager();
}

/**
Expand All @@ -69,8 +62,9 @@ public void run() {
if (shell == null) {
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
}

ServerWizard wizard = new ServerWizard(this.teiidServerManager);

TeiidServerManager teiidServerManager = DqpPlugin.getInstance().getServerManager();
ServerWizard wizard = new ServerWizard(teiidServerManager);
WizardDialog dialog = new WizardDialog(this.shell, wizard) {
/**
* {@inheritDoc}
Expand Down
1 change: 1 addition & 0 deletions plugins/org.teiid.designer.dqp/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Export-Package: org.teiid.designer.runtime,
org.teiid.designer.runtime.preview,
org.teiid.designer.runtime.preview.jobs
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.8.0,4.0.0)",
org.eclipse.ui;bundle-version="3.103.0",
org.jdom;bundle-version="[1.1.1,2.0.0)",
org.eclipse.core.resources;bundle-version="[3.8.0,4.0.0)",
org.teiid.designer.jdbc;bundle-version="[8.0.0,9.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.server.core.IServer;
import org.osgi.framework.BundleContext;
import org.teiid.core.designer.PluginUtil;
Expand Down Expand Up @@ -114,8 +115,21 @@ public IPath getRuntimePath() {
* @return the server manager
*/
public TeiidServerManager getServerManager() {

if (serverMgr == null) {

/*
* Server manager init requires restoring its state dependent on
* the server provider which may not have been inited. To ensure
* that latter is inited avoid initing prior to the workbench initialization
*/
if (PlatformUI.getWorkbench().isStarting()) {
try {
throw new Exception("Programming Error: Server Manager should not be instantiated prior to the workbench"); //$NON-NLS-1$
} catch (Exception ex) {
Util.log(ex);
}
}

try {
initializeServerRegistry();
} catch (final Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.wst.server.core.IServerListener;
import org.eclipse.wst.server.core.ServerEvent;
import org.eclipse.wst.server.core.util.ServerLifecycleAdapter;
import org.jboss.ide.eclipse.as.core.server.internal.v7.JBoss7Server;
import org.teiid.core.designer.util.Base64;
import org.teiid.core.designer.util.CoreArgCheck;
import org.teiid.datatools.connectivity.spi.ISecureStorageProvider;
Expand Down Expand Up @@ -130,6 +129,8 @@ private enum RuntimeState {
* The attribute used to persist a server's host value.
*/
private static final String HOST_ATTR = "host"; //$NON-NLS-1$

private static final String PARENT_SERVER_ID = "parentServerId"; //$NON-NLS-1$

/**
* The attribute used to persist a server's version value.
Expand Down Expand Up @@ -170,6 +171,7 @@ private enum RuntimeState {
* The attribute used to persist a server's secure value.
*/
private static final String JDBC_SECURE_ATTR = "jdbcsecure"; //$NON-NLS-1$


// ===========================================================================================================================
// Fields
Expand Down Expand Up @@ -701,6 +703,7 @@ public IStatus restoreState() {
}

String host = null;
String parentServerId = null;
String customLabel = null;
boolean previewServer = false;

Expand All @@ -717,6 +720,12 @@ public IStatus restoreState() {
host = hostNode.getNodeValue();
}

Node parentServerNode = serverAttributeMap.getNamedItem(PARENT_SERVER_ID);

if (parentServerNode != null) {
parentServerId = parentServerNode.getNodeValue();
}

// custom label attribute
Node customLabelNode = serverAttributeMap.getNamedItem(CUSTOM_LABEL_ATTR);

Expand Down Expand Up @@ -842,7 +851,7 @@ public IStatus restoreState() {
// add server to registry
IServer parentServer = null;
try {
parentServer = findParentServer(host, teiidAdminInfo);
parentServer = findParentServer(host, parentServerId, teiidAdminInfo);
} catch (OrphanedTeiidServerException ex) {
// Cannot add the teiid server since it has no parent
continue;
Expand Down Expand Up @@ -873,20 +882,15 @@ public IStatus restoreState() {
return Status.OK_STATUS;
}

private IServer findParentServer(String host, ITeiidAdminInfo teiidAdminInfo) throws OrphanedTeiidServerException {
private IServer findParentServer(String host, String parentServerId, ITeiidAdminInfo teiidAdminInfo) throws OrphanedTeiidServerException {
IServer[] servers = parentServersProvider.getServers();
for (IServer server : servers) {
if (! host.equals(server.getHost()))
continue;

JBoss7Server jb7 = (JBoss7Server) server.loadAdapter(JBoss7Server.class, null);
if (jb7 == null)
if (! server.getId().equals(parentServerId))
continue;

if (teiidAdminInfo.getPortNumber() != jb7.getManagementPort())
continue;

// The host and admin port match so must be the same server
return server;
}

Expand Down Expand Up @@ -978,6 +982,10 @@ private void saveState() throws TransformerFactoryConfigurationError {
serverElement.setAttribute(HOST_ATTR, teiidServer.getHost());
}

{ // Parent Server Id
serverElement.setAttribute(PARENT_SERVER_ID, teiidServer.getParent().getId());
}

{ // CUSTOM LABEL
if (!StringUtilities.isEmpty(teiidServer.getCustomLabel())) {
serverElement.setAttribute(CUSTOM_LABEL_ATTR, teiidServer.getCustomLabel());
Expand Down

0 comments on commit 0ceb18a

Please sign in to comment.