Skip to content

Commit

Permalink
TEIIDDES-2904
Browse files Browse the repository at this point in the history
 * Added checks in PreviewManager to look for JNDI name in model,
determine if DS exists with that name and query the user to create it if
it doesn't
 * If deployment/creation of missing DS fails, the preview dialog will
cancel on it's own.
  • Loading branch information
blafond committed Aug 30, 2016
1 parent eff05ea commit 87c61a6
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 21 deletions.
Expand Up @@ -186,6 +186,7 @@ public Properties getConnectionProperties(ModelResource modelResource)
String home = modelProps.getProperty(IFlatFileProfileConstants.HOME_URL);
if( home != null ) {
connProps.put(IFlatFileProfileConstants.TEIID_PARENT_DIRECTORY_KEY, home);
connProps.put(FILE_CLASSNAME, FILE_CONNECTION_FACTORY);
}

return connProps;
Expand Down
Expand Up @@ -15,7 +15,6 @@
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.datatools.DatatoolsPlugin;
import org.teiid.designer.datatools.connection.ConnectionInfoHelper;
import org.teiid.designer.datatools.connection.IConnectionInfoProvider;
import org.teiid.designer.type.IDataTypeManagerService.DataSourceTypes;
Expand Down Expand Up @@ -48,7 +47,7 @@ public String getPasswordPropertyKey() {
public Properties getTeiidRelatedProperties(IConnectionProfile connectionProfile) {
Properties connectionProps = new Properties();

Properties props = connectionProfile.getBaseProperties();
Properties props = connectionProfile.getBaseProperties();

String fileUrl = props.getProperty(IFlatFileProfileConstants.URL_PROP_ID);
if( fileUrl != null ) {
Expand Down Expand Up @@ -89,6 +88,23 @@ public Properties getCommonProfileProperties(IConnectionProfile profile) {
return super.getCommonProfileProperties(profile);
}

@Override
public Properties getConnectionProperties(ModelResource modelResource)
throws ModelWorkspaceException {
Properties modelProps = super.getConnectionProperties(modelResource);

Properties connProps = new Properties();
// Search for "URL" value

String url = (String)modelProps.get(IFlatFileProfileConstants.URL_PROP_ID);
if( url != null ) {
connProps.put(IFlatFileProfileConstants.WS_ENDPOINT_KEY, url);
connProps.put(WS_CLASSNAME, WS_CONNECTION_FACTORY);
}

return connProps;
}

@Override
public String getTranslatorName(ModelResource modelResource) {
return "ws"; //$NON-NLS-1$
Expand Down
Expand Up @@ -95,7 +95,7 @@ public IConnectionProfile getConnectionProfile(ModelResource modelResource) {

Properties baseProps = profile.getBaseProperties();
Properties flatFileProps = new Properties();

try {
flatFileProps = getConnectionProperties(modelResource);
} catch (ModelWorkspaceException e) {
Expand All @@ -116,7 +116,16 @@ public Properties getConnectionProperties(ModelResource modelResource)
throws ModelWorkspaceException {
Properties modelProps = super.getConnectionProperties(modelResource);

return modelProps;
Properties connProps = new Properties();
// Search for "URL" value

String url = (String)modelProps.get(IXmlProfileConstants.LOCAL_FILE_PATH_PROP_ID);
if( url != null ) {
connProps.put(IXmlProfileConstants.TEIID_PARENT_DIRECTORY_KEY, url);
connProps.put(FILE_CLASSNAME, FILE_CONNECTION_FACTORY);
}

return connProps;
}

@Override
Expand Down
Expand Up @@ -115,21 +115,16 @@ public Properties getConnectionProperties(ModelResource modelResource)
throws ModelWorkspaceException {
Properties modelProps = super.getConnectionProperties(modelResource);

return modelProps;
Properties connProps = new Properties();
// Search for "URL" value

// Properties connProps = new Properties();
// Search for "HOME" value
String url = (String)modelProps.get(IXmlProfileConstants.URL_PROP_ID);
if( url != null ) {
connProps.put(IXmlProfileConstants.WS_ENDPOINT_KEY, url);
connProps.put(WS_CLASSNAME, WS_CONNECTION_FACTORY);
}

// String fileUrl = modelProps.getProperty(IXmlProfileConstants.LOCAL_FILE_PATH_PROP_ID);
// if( fileUrl != null ) {
// IPath fullPath = new Path(fileUrl);
// String fileName = fullPath.lastSegment().toString();
// String directoryUrl = fullPath.removeLastSegments(1).toString();
// connProps.put(IXmlProfileConstants.TEIID_PARENT_DIRECTORY_KEY, directoryUrl);
// connProps.put(IXmlProfileConstants.XML_FILE_NAME, fileName);
// }
//
// return connProps;
return connProps;
}

@Override
Expand Down
Expand Up @@ -105,6 +105,10 @@ public class Messages extends NLS {
public static String PreviewDataInputDialog_initialMessage;
public static String PreviewDataInputDialog_previewXMLLabel;

public static String PreviewDataWorker_dataSourceMissingTitle;
public static String PreviewDataWorker_dataSourceCreationErrorTitle;
public static String PreviewDataWorker_vdbDeploymentErrorTitle;

static {
NLS.initializeMessages("org.teiid.designer.runtime.ui.messages", Messages.class); //$NON-NLS-1$
}
Expand Down
Expand Up @@ -93,4 +93,8 @@ PreviewDataInputDialog_sqlQueryLabel=SQL Query
PreviewDataInputDialog_previewSqlLabel=Preview SQL
PreviewDataInputDialog_title=Preview Data
PreviewDataInputDialog_initialMessage=Customize your SQL query and view your preview VDB XML content
PreviewDataInputDialog_previewXMLLabel=Preview VDB XML Content
PreviewDataInputDialog_previewXMLLabel=Preview VDB XML Content

PreviewDataWorker_dataSourceMissingTitle=Data Sources Missing
PreviewDataWorker_dataSourceCreationErrorTitle=Data Source Creation Error
PreviewDataWorker_vdbDeploymentErrorTitle=VDB Deployment Error
Expand Up @@ -75,6 +75,7 @@
import org.teiid.designer.runtime.spi.ITeiidServerManager;
import org.teiid.designer.runtime.spi.ITeiidTranslator;
import org.teiid.designer.runtime.ui.DqpUiConstants;
import org.teiid.designer.runtime.ui.Messages;
import org.teiid.designer.runtime.ui.dialogs.AccessPatternColumnsDialog;
import org.teiid.designer.runtime.ui.dialogs.ParameterInputDialog;
import org.teiid.designer.runtime.ui.server.RuntimeAssistant;
Expand Down Expand Up @@ -319,15 +320,31 @@ private void internalRun( final EObject eObject,
return;
}

PreviewDataInputDialog dialog = new PreviewDataInputDialog(getShell(), sql, manager.getDynamicVdbString());
// Check data source deployments
String dynVdbXml = manager.getDynamicVdbString();
IStatus dsStatus = manager.getDataSourcesStatus();
if( dsStatus.getSeverity() == IStatus.ERROR ) {
boolean result = MessageDialog.openQuestion(getShell(), Messages.PreviewDataWorker_dataSourceMissingTitle, dsStatus.getMessage());
if( result ) {
IStatus dsCreateStatus = manager.doCreateMissingDataSources();
if( dsCreateStatus.getSeverity() == IStatus.ERROR ) {
MessageDialog.openError(getShell(), Messages.PreviewDataWorker_dataSourceCreationErrorTitle, dsCreateStatus.getMessage());
return;
}
} else {
return;
}
}

PreviewDataInputDialog dialog = new PreviewDataInputDialog(getShell(), sql, dynVdbXml);

if( dialog.open() != Window.OK ) return;

IStatus status = manager.deployDynamicVdb();
if( status.isOK() ) {
sql = dialog.getSQL();
} else {
MessageDialog.openError(getShell(), "VDB Deployment Error", status.getMessage());
MessageDialog.openError(getShell(), Messages.PreviewDataWorker_vdbDeploymentErrorTitle, status.getMessage());
}


Expand Down
@@ -0,0 +1,151 @@
package org.teiid.designer.runtime.preview;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.osgi.util.NLS;
import org.teiid.designer.core.ModelerCore;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.datatools.connection.ConnectionInfoProviderFactory;
import org.teiid.designer.datatools.connection.DataSourceConnectionHelper;
import org.teiid.designer.datatools.connection.IConnectionInfoProvider;
import org.teiid.designer.runtime.DqpPlugin;
import org.teiid.designer.runtime.spi.ITeiidDataSource;
import org.teiid.designer.runtime.spi.ITeiidServer;

public class DataSourceHelper {
Map<String, ModelResource> jndiNameModelMap;
Set<String> missingJndiNames;
IStatus status;

public DataSourceHelper() {
jndiNameModelMap = new HashMap<String, ModelResource>();
missingJndiNames = new HashSet<String>();
}

public void addJndiName(String jndiName, ModelResource mr) {
if( jndiNameModelMap != null ) {
jndiNameModelMap.put(jndiName, mr);
}
}

public IStatus getStatus() {
return status;
}

public boolean checkDeployments() {
status = Status.OK_STATUS;

// Assume the server is defined and active
ITeiidServer teiidServer = DqpPlugin.getInstance().getServerManager().getDefaultServer();
if( teiidServer == null ) {
// SHOULD NEVER GET HERE
status = new Status(IStatus.ERROR, DqpPlugin.PLUGIN_ID, Messages.DataSourceHelper_noServerDefined); //$NON-NLS-1$);
return false;
}
try {
// If any JNDI name doesn't exist on the server...
// Show Error Dialog
// return false
for( String jndiName : jndiNameModelMap.keySet() ) {
ITeiidDataSource ds = teiidServer.getDataSource(jndiName);
if( ds == null && jndiName != null) {
missingJndiNames.add(jndiName);
}
}
} catch (Exception e) {
status = new Status(IStatus.ERROR, DqpPlugin.PLUGIN_ID, Messages.DataSourceHelper_errorCheckingDataSourceDeployments);
return false;
}

if( !missingJndiNames.isEmpty() ) {
status = new Status(IStatus.ERROR, DqpPlugin.PLUGIN_ID, Messages.DataSourceHelper_requiredDataSourcesMissing);
return false;
}

return true;
}

public IStatus createMissingDataSources() {

for( String jndiName : missingJndiNames ) {
try {
handleCreateDataSource(jndiNameModelMap.get(jndiName), jndiName);
} catch (Exception e) {
return new Status(IStatus.ERROR, DqpPlugin.PLUGIN_ID, NLS.bind(Messages.DataSourceHelper_dataSourceFailedToDeploy, jndiName));
}
}

return Status.OK_STATUS;
}

public boolean handleCreateDataSource(ModelResource modelResource, String jndiName) throws Exception {
boolean didDeployDS = false;

DataSourceConnectionHelper helper = new DataSourceConnectionHelper(modelResource, null);

Properties connProps = getModelConnectionProperties(modelResource);

String dsType = helper.getDataSourceType();

getServer().getOrCreateDataSource(jndiName, jndiName, dsType, connProps);
didDeployDS = true;

return didDeployDS;
}

public Properties getModelConnectionProperties(ModelResource mr) throws ModelWorkspaceException {

IConnectionInfoProvider provider = null;

try {
provider = getProvider(mr);
} catch (Exception e) {
// If provider throws exception its OK because some models may not have connection info.
}

if (provider != null) {
Properties properties = provider.getConnectionProperties(mr);

if (properties != null && !properties.isEmpty()) {
return properties;
}
}

return null;
}

private IConnectionInfoProvider getProvider(ModelResource mr) throws Exception {
ConnectionInfoProviderFactory providerFactory = new ConnectionInfoProviderFactory();

return providerFactory.getProvider(mr);

}

public static ITeiidServer getServer() {
return ModelerCore.getTeiidServerManager().getDefaultServer();
}


public String getDataSourceType(ModelResource mr) {
IConnectionInfoProvider provider = null;

try {
provider = getProvider(mr);
} catch (Exception e) {
// If provider throws exception its OK because some models may not have connection info.
}

if (provider != null) {
return provider.getDataSourceType();
}

return null;
}
}
Expand Up @@ -65,6 +65,11 @@ public final class Messages extends NLS {
public static String JarDeploymentJarNotFound;
public static String JarDeploymentFailed;
public static String JarDeploymentJarNotReadable;

public static String DataSourceHelper_noServerDefined;
public static String DataSourceHelper_errorCheckingDataSourceDeployments;
public static String DataSourceHelper_requiredDataSourcesMissing;
public static String DataSourceHelper_dataSourceFailedToDeploy;

static {
NLS.initializeMessages("org.teiid.designer.runtime.preview.messages", Messages.class); //$NON-NLS-1$
Expand Down

0 comments on commit 87c61a6

Please sign in to comment.