Skip to content

Commit

Permalink
[BACKLOG-11076] reset connection on repo loss detection (#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Ferreira authored and Ben Morrise committed Mar 28, 2017
1 parent 6dcecbb commit f833566
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
56 changes: 33 additions & 23 deletions ui/src/org/pentaho/di/ui/spoon/Spoon.java
Expand Up @@ -3297,9 +3297,12 @@ public boolean tabClose( TabItem item ) {

public boolean tabClose( TabItem item, boolean force ) {
try {
return delegates.tabs.tabClose( item, force );
} catch ( KettleRepositoryLostException e ) {
handleRepositoryLost( e );
try {
return delegates.tabs.tabClose( item, force );
} catch ( KettleRepositoryLostException e ) {
handleRepositoryLost( e );
return delegates.tabs.tabClose( item, force );
}
} catch ( Exception e ) {
new ErrorDialog( shell, "Error", "Unexpected error closing tab!", e );
}
Expand Down Expand Up @@ -5168,7 +5171,7 @@ public boolean saveToRepository( EngineMetaInterface meta, boolean ask_name ) th
}
}

if ( answer && !Utils.isEmpty( meta.getName() ) ) {
if ( answer && !Utils.isEmpty( meta.getName() ) && rep != null ) {

int response = SWT.YES;

Expand Down Expand Up @@ -6347,18 +6350,23 @@ public void refreshTree() {

DatabasesCollector collector = new DatabasesCollector( meta, rep );
try {
collector.collectDatabases();
try {
collector.collectDatabases();
} catch ( KettleException e ) {
if ( e.getCause() instanceof KettleRepositoryLostException ) {
handleRepositoryLost( (KettleRepositoryLostException) e.getCause() );
collector = new DatabasesCollector( meta, null );
collector.collectDatabases();
} else {
throw e;
}
}
} catch ( KettleException e ) {
if ( e.getCause() instanceof KettleRepositoryLostException ) {
handleRepositoryLost( (KettleRepositoryLostException) e.getCause() );
} else {
new ErrorDialog( shell,
new ErrorDialog( shell,
BaseMessages.getString( PKG, "Spoon.ErrorDialog.Title" ),
BaseMessages.getString( PKG, "Spoon.ErrorDialog.ErrorFetchingFromRepo.DbConnections" ),
e
);
}
return;
}

for ( String dbName : collector.getDatabaseNames() ) {
Expand All @@ -6374,21 +6382,19 @@ public void refreshTree() {
}
}

private void handleRepositoryLost( KettleRepositoryLostException e ) {
if ( closeRepositoryLost( e ) ) {
setRepository( null );
SpoonPluginManager.getInstance().notifyLifecycleListeners( SpoonLifeCycleEvent.REPOSITORY_DISCONNECTED );
setShellText();
enableMenus();
}
public void handleRepositoryLost( KettleRepositoryLostException e ) {
setRepository( null );
warnRepositoryLost( e );
SpoonPluginManager.getInstance().notifyLifecycleListeners( SpoonLifeCycleEvent.REPOSITORY_DISCONNECTED );
setShellText();
enableMenus();
}

private boolean closeRepositoryLost( KettleRepositoryLostException e ) {
MessageBox box = new MessageBox( shell, SWT.OK | SWT.CANCEL );
private void warnRepositoryLost( KettleRepositoryLostException e ) {
MessageBox box = new MessageBox( shell, SWT.OK | SWT.ICON_WARNING );
box.setText( BaseMessages.getString( PKG, "System.Warning" ) );
box.setMessage( e.getPrefaceMessage() );
int result = box.open();
return result == SWT.OK;
box.open();
}

private void refreshStepsSubtree( TreeItem tiRootName, TransMeta meta, GUIResource guiResource ) {
Expand Down Expand Up @@ -6825,7 +6831,11 @@ public void setShellText() {
filename = meta.getFilename();
name = meta.getName();
version = meta.getObjectRevision() == null ? null : meta.getObjectRevision().getName();
versioningEnabled = isVersionEnabled( rep, meta );
try {
versioningEnabled = isVersionEnabled( rep, meta );
} catch ( KettleRepositoryLostException krle ) {
handleRepositoryLost( krle );
}
}

String text = "";
Expand Down
3 changes: 2 additions & 1 deletion ui/src/org/pentaho/di/ui/spoon/job/JobGraph.java
Expand Up @@ -3,7 +3,7 @@
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2016 by Pentaho : http://www.pentaho.com
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
Expand Down Expand Up @@ -3617,6 +3617,7 @@ public void run() {
RepositoryOperation.EXECUTE_JOB );
} catch ( KettleRepositoryLostException krle ) {
log.logError( krle.getLocalizedMessage() );
spoon.handleRepositoryLost( krle );
}

// Start/Run button...
Expand Down
1 change: 1 addition & 0 deletions ui/src/org/pentaho/di/ui/spoon/trans/TransGraph.java
Expand Up @@ -4132,6 +4132,7 @@ public void run() {
RepositoryOperation.EXECUTE_TRANSFORMATION );
} catch ( KettleRepositoryLostException krle ) {
log.logError( krle.getLocalizedMessage() );
spoon.handleRepositoryLost( krle );
}

// Start/Run button...
Expand Down

0 comments on commit f833566

Please sign in to comment.