Skip to content

Commit

Permalink
TEIIDDES-2064: Update the teiid version upon successful connection
Browse files Browse the repository at this point in the history
* TeiidServer
 * Once the instance has successfully connected update its version with
   the runtime version from the server. If the instance is the default then
   this value will be displayed and used accordingly.

* TeiidServerEditor
 * Make the runtime version editable if the instance is stopped. This will
   allow the user to control the version of the instance, including which
   runtime client is used to connect to it.
 * Once the instance is successfully started, the runtime version is
   discovered and the editor's version is populated correctly and no longer
   editable.
  • Loading branch information
Paul Richardson committed Mar 3, 2014
1 parent efe7589 commit 68609e7
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ TeiidServerOverviewSection.description=The configuration of the Teiid Instance i
TeiidServerOverviewSection.customLabel=Display Name
TeiidServerOverviewSection.hostLabel=Host
TeiidServerOverviewSection.versionLabel=Teiid Runtime Version
TeiidServerOverviewSection.versionValueTooltip=The runtime version is acquired from the running Teiid instance. If the Teiid instance is stopped then the version can be modified manually but care should be taken since this will influence the runtime client used to connect to the instance when started.
TeiidServerOverviewSection.jbLabel=JBoss Server
TeiidServerOverviewSection.newHyperlinkLabel=New
TeiidServerOverviewSection.editHyperlinkLabel=Edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
package org.teiid.designer.runtime.ui.server.editor;

import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
Expand All @@ -17,8 +21,10 @@
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
Expand Down Expand Up @@ -47,14 +53,18 @@
import org.teiid.designer.core.loading.IManagedLoading;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.IServersProvider;
import org.teiid.designer.runtime.TeiidServerFactory;
import org.teiid.designer.runtime.TeiidServerFactory.ServerOptions;
import org.teiid.designer.runtime.adapter.TeiidServerAdapterFactory;
import org.teiid.designer.runtime.registry.TeiidRuntimeRegistry;
import org.teiid.designer.runtime.spi.ExecutionConfigurationEvent;
import org.teiid.designer.runtime.spi.IExecutionConfigurationListener;
import org.teiid.designer.runtime.spi.ITeiidAdminInfo;
import org.teiid.designer.runtime.spi.ITeiidJdbcInfo;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.spi.ITeiidServerManager;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
import org.teiid.designer.ui.common.util.UiUtil;

/**
Expand Down Expand Up @@ -91,7 +101,7 @@ public class TeiidServerEditor extends EditorPart implements IManagedLoading {

private Label hostNameLabel;

private Label versionValueLabel;
private Combo versionValueCombo;

private Label adminDescriptionLabel;

Expand Down Expand Up @@ -351,10 +361,38 @@ private void createOverviewSection(Composite parent) {

Label versionLabel = toolkit.createLabel(composite, UTIL.getString("TeiidServerOverviewSection.versionLabel")); //$NON-NLS-1$
blueForeground(versionLabel);

versionValueLabel = toolkit.createLabel(composite, teiidServer.getServerVersion().toString());
GridDataFactory.fillDefaults().grab(true, false).applyTo(versionValueLabel);
blueForeground(versionValueLabel);

versionValueCombo = new Combo(composite, SWT.DROP_DOWN);
versionValueCombo.setToolTipText(UTIL.getString("TeiidServerOverviewSection.versionValueTooltip")); //$NON-NLS-1$
GridDataFactory.fillDefaults().grab(false, false).applyTo(versionValueCombo);
versionValueCombo.addKeyListener(dirtyKeyListener);
versionValueCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TeiidServerEditor.this.setDirty();
execute(new TeiidServerCommand(parentServerWorkingCopy));
}
});

// Populate the version value combo with existing server versions
// and the current teiid server version
List<String> serverVersions = new ArrayList<String>();
serverVersions.add(teiidServer.getServerVersion().toString());
try {
Collection<ITeiidServerVersion> registeredServerVersions = TeiidRuntimeRegistry.getInstance().getRegisteredServerVersions();
for (ITeiidServerVersion version : registeredServerVersions) {
serverVersions.add(version.toString());
}
} catch (Exception ex) {
serverVersions.addAll(TeiidServerVersion.DEFAULT_TEIID_SERVER_IDS);
}

Collections.sort(serverVersions, Collections.reverseOrder());
versionValueCombo.setItems(serverVersions.toArray(new String[0]));
versionValueCombo.setText(teiidServer.getServerVersion().toString());

// Can only edit if teiid server has been stopped
versionValueCombo.setEnabled(! teiidServer.isConnected());

Label jbLabel = toolkit.createLabel(composite, UTIL.getString("TeiidServerOverviewSection.jbLabel")); //$NON-NLS-1$
blueForeground(jbLabel);
Expand Down Expand Up @@ -526,7 +564,9 @@ private void refreshDisplayValues() {

customNameText.setText(teiidServer.getCustomLabel() != null ? teiidServer.getCustomLabel() : ""); //$NON-NLS-1$
hostNameLabel.setText(teiidServer.getHost());
versionValueLabel.setText(teiidServer.getServerVersion().toString());
versionValueCombo.setText(teiidServer.getServerVersion().toString());
// Can only edit if teiid server has been stopped
versionValueCombo.setEnabled(! teiidServer.isConnected());
jbServerNameLabel.setText(parentServer != null ? parentServer.getName() : ""); //$NON-NLS-1$

ITeiidAdminInfo teiidAdminInfo = teiidServer.getTeiidAdminInfo();
Expand Down Expand Up @@ -588,31 +628,38 @@ public void doSave(IProgressMonitor monitor) {
if (teiidServer == null)
return;

ITeiidServerVersion newTeiidServerVersion = teiidServer.getServerVersion();
if (versionValueCombo.getText() != null)
newTeiidServerVersion = new TeiidServerVersion(versionValueCombo.getText());

// Overwrite the properties of the Teiid Instance
teiidServer.setCustomLabel(customNameText.getText());

ITeiidAdminInfo adminInfo = teiidServer.getTeiidAdminInfo();

if (adminUserNameText != null) {
adminInfo.setUsername(adminUserNameText.getText());
}

if (adminPasswdText != null) {
adminInfo.setPassword(adminPasswdText.getText());
}

if (adminSSLCheckbox != null) {
adminInfo.setSecure(adminSSLCheckbox.getSelection());
}

ITeiidJdbcInfo jdbcInfo = teiidServer.getTeiidJdbcInfo();
jdbcInfo.setUsername(jdbcUserNameText.getText());
jdbcInfo.setPassword(jdbcPasswdText.getText());
jdbcInfo.setSecure(jdbcSSLCheckbox.getSelection());


TeiidServerFactory teiidServerFactory = new TeiidServerFactory();

List<ServerOptions> serverOptions = new ArrayList<ServerOptions>();
if (adminSSLCheckbox != null && adminSSLCheckbox.getSelection())
serverOptions.add(ServerOptions.ADMIN_SECURE_CONNECTION);
if (jdbcSSLCheckbox.getSelection())
serverOptions.add(ServerOptions.JDBC_SECURE_CONNECTION);

ITeiidServer newTeiidServer = teiidServerFactory.createTeiidServer(
newTeiidServerVersion,
getServerManager(),
teiidServer.getParent(),
teiidServer.getTeiidAdminInfo().getPort(),
adminUserNameText != null ? adminUserNameText.getText() : teiidServer.getTeiidAdminInfo().getUsername(),
adminPasswdText != null ? adminPasswdText.getText() : teiidServer.getTeiidAdminInfo().getPassword(),
jdbcPort instanceof Text ? ((Text) jdbcPort).getText() : teiidServer.getTeiidJdbcInfo().getPort(),
jdbcUserNameText.getText(),
jdbcPasswdText.getText(),
serverOptions.toArray(new ServerOptions[0]));

teiidServer.update(newTeiidServer);

dirty = false;
firePropertyChange(IEditorPart.PROP_DIRTY);

getServerManager().notifyListeners(ExecutionConfigurationEvent.createServerRefreshEvent(teiidServer));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public class TeiidServer implements ITeiidServer {
*/
private final IServer parentServer;

/**
* Adapter factory providing adaption and teiid utilities
*/
private TeiidServerAdapterFactory serverAdapterFactory;

// ===========================================================================================================================
// Constructors
// ===========================================================================================================================
Expand Down Expand Up @@ -176,11 +181,11 @@ public void connect() throws Exception {
if (! isParentConnected()) {
throw new Exception(DqpPlugin.Util.getString("jbossServerNotStartedMessage")); //$NON-NLS-1$
}

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

if (admin != null) {
/*
* Avoid the refresh listener being fired prematurely by the admin client.
Expand All @@ -189,6 +194,24 @@ public void connect() throws Exception {
*/
getEventManager().permitListeners(false);

/*
* Since we have connected successfully, query the runtime version
* of the server to ensure it is correct rather than the guess made
* when the server was stopped.
*/
try {
ITeiidServerVersion teiidVersion = getAdapterFactory().getTeiidRuntimeVersion(parentServer);
if (teiidVersion != null)
serverVersion = teiidVersion;
} catch (Exception ex) {
DqpPlugin.Util.log(ex);
}

/*
* The version should be determined prior to this 'connect'
* which is in fact nothing but a refresh, which may well
* depend on the version being correct.
*/
this.admin.connect();
}
} catch (Exception ex) {
Expand All @@ -201,7 +224,17 @@ public void connect() throws Exception {
notifyRefresh();
}
}


/**
* @return server adapter factory
*/
private TeiidServerAdapterFactory getAdapterFactory() {
if (serverAdapterFactory == null)
serverAdapterFactory = new TeiidServerAdapterFactory();

return serverAdapterFactory;
}

@Override
public void reconnect() {
try {
Expand Down Expand Up @@ -328,8 +361,7 @@ public boolean isParentConnected() {
return false;

try {
TeiidServerAdapterFactory factory = new TeiidServerAdapterFactory();
return factory.isParentServerConnected(parentServer);
return getAdapterFactory().isParentServerConnected(parentServer);
} catch (Exception ex) {
DqpPlugin.Util.log(ex);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
import org.teiid.designer.runtime.DebugConstants;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;

/**
*
Expand Down Expand Up @@ -117,4 +119,15 @@ protected static boolean serverStarted(IServer server) {

return true;
}

/**
* @param parentServer
* @param jbossServer
*
* @return since the jboss server is the older version 5, it cannot be queried
* and can only be a maximum of version 7
*/
public static ITeiidServerVersion getTeiidRuntimeVersion(IServer parentServer, JBossServer jbossServer) {
return TeiidServerVersion.DEFAULT_TEIID_7_SERVER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.teiid.designer.runtime.spi.ITeiidJdbcInfo;
import org.teiid.designer.runtime.spi.ITeiidServer;
import org.teiid.designer.runtime.spi.ITeiidServerManager;
import org.teiid.designer.runtime.version.spi.TeiidServerVersion;
import org.teiid.designer.runtime.version.spi.ITeiidServerVersion;

/**
* Adapter factory that can adapt an {@link IServer} to a {@link ITeiidServer}
Expand Down Expand Up @@ -247,7 +247,7 @@ private ITeiidServer createJbossTeiidServer(final IServer parentServer, final JB
optionList.add(ServerOptions.ADMIN_SECURE_CONNECTION);

TeiidServerFactory factory = new TeiidServerFactory();
ITeiidServer teiidServer = factory.createTeiidServer(TeiidServerVersion.DEFAULT_TEIID_7_SERVER,
ITeiidServer teiidServer = factory.createTeiidServer(JBossServerUtil.getTeiidRuntimeVersion(parentServer, jbossServer),
getTeiidServerManager(),
parentServer,
ITeiidAdminInfo.DEFAULT_LEGACY_PORT,
Expand Down Expand Up @@ -282,4 +282,25 @@ public boolean isParentServerConnected(IServer server) throws Exception {

return false;
}

/**
* @param server
*
* @return the teiid runtime version of the given server
* @throws Exception
*/
public ITeiidServerVersion getTeiidRuntimeVersion(IServer server) throws Exception {
if (! getTeiidServerManager().isStarted())
return null;

JBoss7Server jb7 = (JBoss7Server) server.loadAdapter(JBoss7Server.class, null);
if (jb7 != null) {
return JBoss7ServerUtil.getTeiidRuntimeVersion(server, jb7);
} else {
JBossServer jb = (JBossServer) server.loadAdapter(JBossServer.class, null);
if (jb != null)
return JBossServerUtil.getTeiidRuntimeVersion(server, jb);
}
return null;
}
}

0 comments on commit 68609e7

Please sign in to comment.