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

* ServerManagerTest
 * Modify tests accordingly
  • Loading branch information
Paul Richardson committed Dec 18, 2012
1 parent 0f9104a commit 7d72490
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 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,19 @@ 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)
continue;

if (teiidAdminInfo.getPortNumber() != jb7.getManagementPort())
if (parentServerId != null && ! server.getId().equals(parentServerId)) {
// Double checks against the parent server id only if a parent server id was
// save. In the case of the old registry format, this was not possible so host
// comparison is sufficient
continue;
}

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

Expand Down Expand Up @@ -978,6 +986,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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerLifecycleListener;
import org.jboss.ide.eclipse.as.core.server.internal.v7.JBoss7Server;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -52,7 +51,7 @@ private class TestServersProvider implements IServersProvider {

private final String[] HOSTS = new String[] { "localhost", "myserver.com" };

private final int[] PORTS = new int[] { 8080, 8180, 8280, 31443, 31444 };
private final String[] PARENT_IDS = new String[] { "server1", "server2" };

private List<IServer> servers = new ArrayList<IServer>();

Expand All @@ -61,14 +60,11 @@ private class TestServersProvider implements IServersProvider {
*/
public TestServersProvider() {

for (int port : PORTS) {
JBoss7Server mockJBossServer = mock(JBoss7Server.class);
when(mockJBossServer.getManagementPort()).thenReturn(port);

for (String parentId : PARENT_IDS) {
for (String host : HOSTS) {
IServer mockServer = mock(IServer.class);
when(mockServer.getHost()).thenReturn(host);
when(mockServer.loadAdapter(JBoss7Server.class, null)).thenReturn(mockJBossServer);
when(mockServer.getId()).thenReturn(parentId);

servers.add(mockServer);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/org.teiid.designer.dqp.test/testdata/serverRegistry.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<servers>
<server customLabel="My Custom Label" default="true" version="8.1.2">
<server customLabel="My Custom Label" default="true" version="8.1.2" parentServerId="server1">
<admin host="localhost" password="YWRtaW4=" port="31443" secure="true" user="admin"/>
<jdbc jdbchost="localhost" jdbcport="31000" jdbcsecure="false" jdbcuser="teiid"/>
</server>
<server>
<admin host="myserver.com" port="31444" secure="false" user="admin2" version="8.2.1-beta1"/>
<admin host="myserver.com" port="31444" secure="false" user="admin2" version="8.2.1-beta1" parentServerId="server2"/>
<jdbc jdbchost="myserver.com" jdbcpassword="dGVpaWQ=" jdbcport="31001" jdbcsecure="true" jdbcuser="teiid2"/>
</server>
</servers>

0 comments on commit 7d72490

Please sign in to comment.