Skip to content

Commit

Permalink
Merge pull request pentaho#1978 from aliakseihaidukou/BACKLOG-5701
Browse files Browse the repository at this point in the history
[BACKLOG-5701] - Implement the static login message UI in client tools
  • Loading branch information
rmansoor committed Dec 1, 2015
2 parents f82576b + a7dfe25 commit 9859b8f
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2015 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/

package org.pentaho.di.core.exception;

public class KettleRepositoryStatusException extends KettleException {

private static final long serialVersionUID = 4238089755373930933L;
private String repositoryName;

/**
* Constructs a new throwable with null as its detail message.
*/
public KettleRepositoryStatusException() {
super();
}

/**
* Constructs a new throwable with the specified detail message.
*
* @param message
* - the detail message. The detail message is saved for later retrieval by the getMessage() method.
*/
public KettleRepositoryStatusException( String message ) {
super( message );
}

/**
* Constructs a new throwable with the specified cause and a detail message of (cause==null ? null : cause.toString())
* (which typically contains the class and detail message of cause).
*
* @param cause
* the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public KettleRepositoryStatusException( Throwable cause ) {
super( cause );
}

/**
* Constructs a new throwable with the specified detail message and cause.
*
* @param message
* the detail message (which is saved for later retrieval by the getMessage() method).
* @param cause
* the cause (which is saved for later retrieval by the getCause() method). (A null value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public KettleRepositoryStatusException( String message, Throwable cause ) {
super( message, cause );
}

public String getRepositoryName() {
return repositoryName;
}

public void setRepositoryName( String repositoryName ) {
this.repositoryName = repositoryName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@

import javax.xml.ws.WebServiceException;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.apache.commons.lang.BooleanUtils;
import org.pentaho.di.core.encryption.Encr;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleRepositoryStatusException;
import org.pentaho.di.core.exception.KettleSecurityException;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
Expand All @@ -44,6 +49,7 @@
import org.pentaho.di.ui.repository.pur.services.IRevisionService;
import org.pentaho.di.ui.repository.pur.services.IRoleSupportSecurityManager;
import org.pentaho.di.ui.repository.pur.services.ITrashService;
import org.pentaho.platform.api.engine.IServerStatusProvider;
import org.pentaho.platform.api.repository2.unified.IUnifiedRepository;
import org.pentaho.platform.engine.core.system.PentahoSessionHolder;
import org.pentaho.platform.engine.core.system.PentahoSystem;
Expand All @@ -55,6 +61,7 @@
import com.sun.xml.ws.client.ClientTransportException;

public class PurRepositoryConnector implements IRepositoryConnector {
public static final String SERVER_STATUS_ENDPOINT = "/GetResource?serverStatus";
private static final String SINGLE_DI_SERVER_INSTANCE = "singleDiServerInstance";
private static final String REMOTE_DI_SERVER_INSTANCE = "remoteDiServerInstance";
private static Class<?> PKG = PurRepository.class;
Expand Down Expand Up @@ -86,6 +93,10 @@ public synchronized RepositoryConnectResult connect( final String username, fina
if ( serviceManager != null ) {
disconnect();
}

// Check server status
checkServerStatus();

serviceManager = new WebServiceManager( repositoryMeta.getRepositoryLocation().getUrl(), username );
RepositoryServiceRegistry purRepositoryServiceRegistry = new RepositoryServiceRegistry();
IUser user1 = new EEUserInfo();
Expand All @@ -103,7 +114,7 @@ public synchronized RepositoryConnectResult connect( final String username, fina
result.setUser( user1 );

// We need to have the application context and the session available in order for us to skip authentication
if ( PentahoSystem.getApplicationContext() != null && PentahoSessionHolder.getSession() != null) {
if ( PentahoSystem.getApplicationContext() != null && PentahoSessionHolder.getSession() != null ) {
if ( inProcess() ) {
// connect to the IUnifiedRepository through PentahoSystem
// this assumes we're running in a BI Platform
Expand Down Expand Up @@ -182,7 +193,7 @@ public Exception call() throws Exception {
try {
LogChannel.GENERAL.logBasic( "Creating repository sync web service" );
IRepositorySyncWebService syncWebService =
serviceManager
serviceManager
.createService( username, decryptedPassword, IRepositorySyncWebService.class ); //$NON-NLS-1$
LogChannel.GENERAL.logBasic( "Synchronizing repository web service" ); //$NON-NLS-1$
syncWebService.sync( repositoryMeta.getName(), repositoryMeta.getRepositoryLocation().getUrl() );
Expand Down Expand Up @@ -254,6 +265,30 @@ public Exception call() throws Exception {
return result;
}

/**
* Check for the server for STARTING status
*
* @throws KettleRepositoryStatusException
*/
protected void checkServerStatus() throws KettleRepositoryStatusException {
Client client = getClient();
final WebResource resource = client
.resource( repositoryMeta.getRepositoryLocation().getUrl() + SERVER_STATUS_ENDPOINT );
final String status = resource.get( String.class );
if ( IServerStatusProvider.ServerStatus.valueOf( status ) == IServerStatusProvider.ServerStatus.STARTING ) {
final KettleRepositoryStatusException kettleRepositoryStatusException =
new KettleRepositoryStatusException( BaseMessages.getString( PKG, "PurRepository.Server.Status.Starting",
repositoryMeta.getName() ) );
kettleRepositoryStatusException.setRepositoryName( repositoryMeta.getName() );
throw kettleRepositoryStatusException;
}
}

protected Client getClient() {
final ClientConfig clientConfig = new DefaultClientConfig();
return Client.create( clientConfig );
}

@Override
public synchronized void disconnect() {
if ( serviceManager != null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ PurRepository.BAServerLogin.Message=Connecting to a BA-Server repository is not
PurRepository.FailedDirectoryCreation.Message=Creation of root directories is not allowed.
PurRepository.WarnLimitedPerms.Message=Due to users lack of basic Read, Create Content and Execute permissions, they will be limited in what they can do.
PurRepository.WarnLimitedPerms.Title=Limited Functionality
PurRepository.Server.Status.Starting=We''re sorry, [{0}] is not available right now. Please try connecting again later.\r\nIf you are an administrator, please do not shut down or restart the server at this time.

PurRepository.Dialog.WarnToCloseAllForce.Connect.Message=You have limited permissions. Some functionality may not be available to you.
PurRepository.Dialog.WarnToCloseAllForceAdditional.Connect.Message=Would you like to close all open files now?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,67 @@

package org.pentaho.di.repository.pur;

import static org.mockito.Mockito.mock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.*;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.exception.KettleRepositoryStatusException;
import org.pentaho.platform.api.engine.IServerStatusProvider;

public class PurRepositoryConnectorTest {
@Test
public void testPDI12439PurRepositoryConnectorDoesntNPEAfterMultipleDisconnects() {
private PurRepositoryConnector purRepositoryConnector;
private PurRepositoryMeta mockPurRepositoryMeta;

@Before
public void setUp() throws Exception {
PurRepository mockPurRepository = mock( PurRepository.class );
PurRepositoryMeta mockPurRepositoryMeta = mock( PurRepositoryMeta.class );
mockPurRepositoryMeta = mock( PurRepositoryMeta.class );
RootRef mockRootRef = mock( RootRef.class );
PurRepositoryConnector purRepositoryConnector =
new PurRepositoryConnector( mockPurRepository, mockPurRepositoryMeta, mockRootRef );
purRepositoryConnector = spy( new PurRepositoryConnector( mockPurRepository, mockPurRepositoryMeta, mockRootRef ) );
}

@Test
public void testPDI12439PurRepositoryConnectorDoesntNPEAfterMultipleDisconnects() {
purRepositoryConnector.disconnect();
purRepositoryConnector.disconnect();
}

@Test
public void testCheckServerStatus() throws Exception {
final PurRepositoryLocation purRepositoryLocation = mock( PurRepositoryLocation.class );
when( mockPurRepositoryMeta.getRepositoryLocation() ).thenReturn( purRepositoryLocation );
final String testRepoName = "testRepoName";
when( mockPurRepositoryMeta.getName() ).thenReturn( testRepoName );
final String testBaseUrl = "testBaseUrl";
when( purRepositoryLocation.getUrl() ).thenReturn( testBaseUrl );

final WebResource resource = mock( WebResource.class );

final Client client = mock( Client.class );
when( purRepositoryConnector.getClient() ).thenReturn( client );
when( client.resource( testBaseUrl + PurRepositoryConnector.SERVER_STATUS_ENDPOINT ) ).thenReturn( resource );

doCallRealMethod().when( purRepositoryConnector ).checkServerStatus();

// test starting
when( resource.get( String.class ) ).thenReturn( IServerStatusProvider.ServerStatus.STARTING.toString() );
try {
purRepositoryConnector.checkServerStatus();
fail();
} catch ( KettleRepositoryStatusException e ) {
assertEquals( testRepoName, e.getRepositoryName() );
}

// test started
when( resource.get( String.class ) ).thenReturn( IServerStatusProvider.ServerStatus.STARTED.toString() );
try {
purRepositoryConnector.checkServerStatus();
} catch ( KettleRepositoryStatusException e ) {
fail();
}
}
}
7 changes: 7 additions & 0 deletions ui/src/org/pentaho/di/ui/spoon/Spoon.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
import org.pentaho.di.core.exception.KettleRowException;
import org.pentaho.di.core.exception.KettleValueException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.exception.KettleRepositoryStatusException;
import org.pentaho.di.core.extension.ExtensionPointHandler;
import org.pentaho.di.core.extension.KettleExtensionPoint;
import org.pentaho.di.core.gui.GUIFactory;
Expand Down Expand Up @@ -9240,6 +9241,12 @@ private void onLoginError( Throwable t ) {
new ShowMessageDialog( loginDialog.getShell(), SWT.OK | SWT.ICON_ERROR, BaseMessages.getString(
PKG, "Spoon.Dialog.LoginFailed.Title" ), t.getLocalizedMessage() );
dialog.open();
} else if ( t instanceof KettleRepositoryStatusException ) {
ShowMessageDialog dialog =
new ShowMessageDialog( loginDialog.getShell(), SWT.CANCEL | SWT.ICON_ERROR, BaseMessages.getString(
PKG, "Spoon.Dialog.ConnectionRepo.Title", ( (KettleRepositoryStatusException) t ).getRepositoryName() ),
t.getLocalizedMessage() );
dialog.open();
} else {
new ErrorDialog(
loginDialog.getShell(), BaseMessages.getString( PKG, "Spoon.Dialog.LoginFailed.Title" ), BaseMessages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ TransLog.Button.Pause=Pause the log
Spoon.Log.NewHop=New hop\!
Spoon.Dialog.ErrorWritingSharedObjects.Message=Unexpected error writing to the shared objects file\!
Spoon.Dialog.LoginFailed.Title=Error
Spoon.Dialog.ConnectionRepo.Title=Unable to Connect to [{0}]
TransLog.Dialog.GiveTransformationANameBeforeRunning.Message=Please give your transformation a name to identify it by\!
Spoon.Menu.File.OpenVFS=Open &URL
Spoon.TransGraph.PerfTab.Name=Performance Graph
Expand Down

0 comments on commit 9859b8f

Please sign in to comment.