Skip to content

Commit

Permalink
TEIIDDES-2433 applying Teiid file name version feature from
Browse files Browse the repository at this point in the history
TEIIDDES-2165
  • Loading branch information
blafond committed Mar 26, 2015
1 parent 38d73b0 commit fcaabcf
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,8 @@ VdbDeployer.checkModelTranslatorTask = Checking translator for model "{0}"
VdbDeployer.checkModelDataSourceTask = Checking data source for model "{0}"
VdbDeployer.createModelDataSourceTask = Creating data source for model "{0}" on Teiid Instance
VdbDeployer.deployVdbTask = Deploying VDB "{0}" to Teiid Instance
VdbDeployer.vdbNameContainsTooManyDotsErrorMessage = "VDB "{0}" name contains too many '.' characters.\n\
Name can be of the form {deployment-name}.{version#}.vdb, where version# is optional

#########################################
# DeployVdbAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.eclipse.datatools.connectivity.ProfileManager;
Expand Down Expand Up @@ -99,6 +100,9 @@ void internalRun(final IFile selectedVdb) {
deployed = DeployVdbAction.deployVdb(teiidServer, selectedVdb);

String vdbName = selectedVdb.getFullPath().removeFileExtension().lastSegment();
if( vdbName.indexOf('.') > -1 ) {
vdbName = new Path(vdbName).removeFileExtension().toString();
}
if (teiidServer.isVdbActive(vdbName)) {
if( deployed ) {
executeVdb(DqpPlugin.getInstance().getServerManager().getDefaultServer(), vdbName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
package org.teiid.designer.runtime.ui.vdb;

import static org.teiid.designer.runtime.ui.DqpUiConstants.UTIL;

import java.util.Collection;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.teiid.core.designer.util.CoreArgCheck;
Expand Down Expand Up @@ -301,9 +304,22 @@ public void run() {

if (this.status == null) {
monitor.subTask(UTIL.getString(PREFIX + "deployVdbTask", getVdbName())); //$NON-NLS-1$
teiidServer.deployVdb(vdb.getFile());
this.status = (teiidServer.hasVdb(getVdbName()) ? DeployStatus.DEPLOYED_VDB : DeployStatus.DEPLOY_VDB_FAILED);
}

// VDB name can contain an integer value
// VDB can also have a version in it's manifest (vdb.xml)
//
// EXAMPLE: Customers.2.vdb
//
int version = vdb.getVersion(); // Manifest version
int versionInName = getVdbVersion(getVdbName()); // version in name
if( versionInName > 0 ) { // If version in name, then use it (i.e. ignore manifest version)
version = versionInName;
}
teiidServer.deployVdb(vdb.getFile(), version);
//teiidServer.deployVdb(vdb.getFile());
// VDB name may have a version in it, so need to strip off any extension
String actualName = new Path(getVdbName()).removeFileExtension().toString();
this.status = (teiidServer.hasVdb(actualName) ? DeployStatus.DEPLOYED_VDB : DeployStatus.DEPLOY_VDB_FAILED); }
} catch (Exception e) {
this.status = DeployStatus.EXCEPTION;
this.error = e;
Expand All @@ -318,6 +334,22 @@ public void run() {
return null;
}

private int getVdbVersion(String originalVdbName) throws Exception {
String vdbName = originalVdbName;
String vdbVersionStr = null;
int firstIndex = vdbName.indexOf('.');
int lastIndex = vdbName.lastIndexOf('.');
if (firstIndex != -1) {
if (firstIndex != lastIndex) {
// TODO:
throw new Exception(UTIL.getString(PREFIX + "vdbNameContainsTooManyDotsErrorMessage", originalVdbName)); //$NON-NLS-1$"VBD Version contains more than one '.'"); //Messages.getString(Messages.ExecutionAdmin.invalidVdbName, originalVdbName));
}
vdbVersionStr = vdbName.substring(firstIndex+1);
return Integer.parseInt(vdbVersionStr);
}
return -1;
}

/*
* Check the server sources to see if a datasource with the provided JNDI name exists.
* @param jndiName the jndi name to check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public String toString() {
}
}

int version = ((ITeiidVdb)value).getVersion();
builder.append("\nVersion:").append(version); //$NON-NLS-1$
builder.append("\nModels:"); //$NON-NLS-1$
for (String modelName : vdb.getModelNames()) {
builder.append("\n\t ").append(modelName); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ public void deployVdb(IFile vdbFile) throws Exception {
connect();
admin.deployVdb(vdbFile);
}

@Override
public void deployVdb(IFile vdbFile, int version) throws Exception {
connect();
admin.deployVdb(vdbFile, version);
}

@Override
public ITeiidDataSource getDataSource(String name) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ enum PingType {
*/
void deployVdb(IFile vdbFile) throws Exception;

/**
* Deploys the VDB (IFile) to the related Teiid Instance
*
* @param vdbFile the vdb file
*
* @throws Exception if deployment fails
*/
void deployVdb(IFile vdbFile, int version) throws Exception;

/**
* Returns a teiid data source object if it exists in this server
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ NewVdbWizard.notModelProjectMessage = Cannot create a VDB. Parent project is not
NewVdbWizard.selectFolderMessage = Select a workspace location.
NewVdbWizard.vdbNameError = VDB name is invalid.
NewVdbWizard.selectedModelsGroupTitle = Selected Models
NewVdbWizard.vdbNameContainsTooManyDotsErrorMessage = VDB "{0}" can only contain 1 '.' character followed by a version number.\n\
Example: SampleVDB.3
NewVdbWizard.vdbNameErrorVersionNotAnInteger = The version number "{0}" in VDB name is not an integer

VdbEditorUserFilesPage.title = User Files
VdbEditorUserFilesPage.filesGroup = User Files:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -84,6 +85,7 @@
import org.teiid.designer.vdb.Vdb;
import org.teiid.designer.vdb.VdbUtil;
import org.teiid.designer.vdb.ui.VdbUiConstants;
import org.teiid.designer.vdb.ui.VdbUiPlugin;
import org.teiid.designer.vdb.ui.editor.VdbEditor;


Expand Down Expand Up @@ -223,6 +225,19 @@ public void run( final IProgressMonitor monitor ) throws InvocationTargetExcepti
if( desc != null && desc.length() > 0 ) {
newVdb.setDescription(desc);
}

// Now parse the name to see if it contains a version
String fullVdbName = newVdb.getName().removeFileExtension().lastSegment();
int firstIndex = fullVdbName.indexOf('.');
String versionStr = fullVdbName.substring(firstIndex + 1);
int version = 1;
try {
version = Integer.parseInt(versionStr);
} catch (NumberFormatException e) {
// Do nothing.. shouldn't get here and swallow anyway cause version == 1 is back-up
}
newVdb.setVersion(version);;

newVdb.save(monitor);
NewVdbWizard.this.folder.refreshLocal(IResource.DEPTH_INFINITE, monitor);

Expand Down Expand Up @@ -683,7 +698,37 @@ private void validatePage() {
} else if (ModelUtilities.vdbNameReservedValidation(proposedName) != null) {
this.mainPage.setErrorMessage(ModelUtilities.vdbNameReservedValidation(proposedName));
this.mainPage.setPageComplete(false);
} else {
} else if (proposedName.indexOf('.') > -1) {
// VDB name can contain an integer value
// EXAMPLE: Customers.2.vdb
//
// make sure there is only 1 '.'
int firstIndex = proposedName.indexOf('.');
int lastIndex = proposedName.lastIndexOf('.');
if (lastIndex != -1 && firstIndex != lastIndex) {
String error = VdbUiPlugin.Util.getString(I18N_PREFIX + "vdbNameContainsTooManyDotsErrorMessage", proposedName); //$NON-NLS-1$)
this.mainPage.setErrorMessage(error);
this.mainPage.setPageComplete(false);
} else {
// Check for integer
String versionStr = proposedName.substring(firstIndex + 1);
boolean succeeded = false;
try {
Integer.parseInt(versionStr);
succeeded = true;
} catch (NumberFormatException e) {
this.mainPage.setErrorMessage(
VdbUiConstants.Util.getString(I18N_PREFIX
+ "vdbNameErrorVersionNotAnInteger", versionStr)); //$NON-NLS-1$);
this.mainPage.setPageComplete(false);
succeeded = false;
}
if (succeeded) {
this.mainPage.setErrorMessage(null);
this.mainPage.setPageComplete(true);
}
}
} else {
this.mainPage.setErrorMessage(null);
this.mainPage.setPageComplete(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,12 @@ public VdbElement() {
* @throws Exception
*/
public VdbElement( final Vdb vdb ) throws Exception {
name = vdb.getName().removeFileExtension().lastSegment();
String initialVdbName = vdb.getName().removeFileExtension().lastSegment();
int indexOfDot = initialVdbName.indexOf('.');
if( indexOfDot > -1 ) {
initialVdbName = initialVdbName.substring(0, indexOfDot);
}
name = initialVdbName;
description = vdb.getDescription();
version = vdb.getVersion();
for (final VdbEntry entry : vdb.getEntries())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public enum ExecutionAdmin {
validity_errors_describe,
data_permissions_describe,
mapped_role_names_describe,
cannotUndeployVdbNoDeploymentName;
cannotUndeployVdbNoDeploymentName,
invalidVdbName;

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,27 @@ public void deployVdb( IFile vdbFile ) throws Exception {
undeployVdb(vdbName);
}

doDeployVdb(vdbDeploymentName, vdbName, 1, vdbFile.getContents());
doDeployVdb(vdbDeploymentName, getVdbName(vdbName), 1, vdbFile.getContents());
}

@Override
public void deployVdb(IFile vdbFile, int version) throws Exception {
ArgCheck.isNotNull(vdbFile, "vdbFile"); //$NON-NLS-1$
String vdbDeploymentName = vdbFile.getFullPath().lastSegment();
String vdbName = vdbFile.getFullPath().removeFileExtension()
.lastSegment();
// For Teiid Version less than 8.7, do explicit undeploy (TEIID-2873)
if (isLessThanTeiidEightSeven()) {
undeployVdb(vdbName);
}
int vdbVersion = 1;
if (version > 1) {
vdbVersion = version;
}
doDeployVdb(vdbDeploymentName, getVdbName(vdbName), vdbVersion,
vdbFile.getContents());
}

@Override
public void deployDynamicVdb( String deploymentName, InputStream inStream ) throws Exception {
ArgCheck.isNotNull(deploymentName, "deploymentName"); //$NON-NLS-1$
Expand Down Expand Up @@ -241,6 +259,20 @@ private void doDeployVdb(String deploymentName, String vdbName, int vdbVersion,
this.eventManager.notifyListeners(ExecutionConfigurationEvent.createDeployVDBEvent(vdb.getName()));
}


private String getVdbName(String originalVdbName) throws Exception {
String vdbName = originalVdbName;
int firstIndex = vdbName.indexOf('.');
int lastIndex = vdbName.lastIndexOf('.');
if (firstIndex != -1) {
if (firstIndex != lastIndex) {
throw new Exception(Messages.getString(Messages.ExecutionAdmin.invalidVdbName, originalVdbName));
}
vdbName = vdbName.substring(0, firstIndex);
}
return vdbName;
}

@Override
public String getSchema(String vdbName, int vdbVersion, String modelName) throws Exception {
if (isLessThanTeiidEight()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ExecutionAdmin.cannotLoadDriverClass = Server cannot load the driver class "{0}"
ExecutionAdmin.admin_conn_closed = The Admin connection has been closed.
ExecutionAdmin.invalid_parameter = The user parameter may not be null or empty.
ExecutionAdmin.cannotUndeployVdbNoDeploymentName=The VDB {0} is missing a deployment-name so cannot be undeployed.
ExecutionAdmin.invalidVdbName=The VDB {0} name contains more than one '.' delimiter and cannot be deployed

TeiidURL.invalid_format=The required socket url format is mm[s]://server1:port1[,server2:port2]
TeiidURL.invalid_ipv6_hostport=The IPv6 host:port ''{0}'' is not valid. {1}
Expand Down

0 comments on commit fcaabcf

Please sign in to comment.