Skip to content

Commit

Permalink
Create connection for indirect datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
zhicwu committed Feb 1, 2017
1 parent 0f205b5 commit bf6c0a8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pentaho-kettle/src/main/java/org/pentaho/di/job/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class Job extends Thread implements VariableSpace, NamedParams, HasLogCha

public static final String CONFIGURATION_IN_EXPORT_FILENAME = "__job_execution_configuration__.xml";

public static final long MAX_JOB_DURATION_MS // by default, every job must be completed within 4 hours
= Integer.parseInt(System.getProperty("KETTLE_MAX_JOB_DURATION_MS", "14400000"));

private LogChannelInterface log;

private LogLevel logLevel = DefaultLogLevel.getLogLevel();
Expand Down Expand Up @@ -904,7 +907,9 @@ public void waitUntilFinished() {
*/
public void waitUntilFinished(long maxMiliseconds) {
long time = 0L;
while (isAlive() && (time < maxMiliseconds || maxMiliseconds <= 0)) {
maxMiliseconds =
maxMiliseconds <= 0 || maxMiliseconds > MAX_JOB_DURATION_MS ? MAX_JOB_DURATION_MS : maxMiliseconds;
while (isAlive() && (time < maxMiliseconds)) {
try {
Thread.sleep(1);
time += 1;
Expand Down
5 changes: 4 additions & 1 deletion pentaho-kettle/src/main/java/org/pentaho/di/trans/Trans.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public class Trans implements VariableSpace, NamedParams, HasLogChannelInterface
private static final boolean KETTLE_TRANS_PREVIEW_DISABLED
= "Y".equalsIgnoreCase(System.getProperty("KETTLE_TRANS_PREVIEW_DISABLED", "Y"));

private static final long MAX_TRANS_DURATION_MS // by default, every trans must be completed within 4 hours
= Integer.parseInt(System.getProperty("KETTLE_MAX_TRANS_DURATION_MS", "14400000"));

/**
* The replay date format.
*/
Expand Down Expand Up @@ -1623,7 +1626,7 @@ public void waitUntilFinished() {
}
boolean wait = true;
while (wait) {
wait = transFinishedBlockingQueue.poll(1, TimeUnit.DAYS) == null;
wait = transFinishedBlockingQueue.poll(MAX_TRANS_DURATION_MS, TimeUnit.MILLISECONDS) == null;
}
} catch (InterruptedException e) {
throw new RuntimeException("Waiting for transformation to be finished interrupted!", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
String identity = ServerCache.getCachedIdentity(resourceName);
if (!Strings.isNullOrEmpty(identity)) {
result.setId(identity);
} else {
result.setResult(WebResult.STRING_ERROR);
result.setMessage(
new StringBuilder().append('[').append(resourceName).append("] not found").toString());
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions pentaho-platform/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
<artifactId>pentaho-platform-api</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>pentaho-reporting-engine</groupId>
<artifactId>pentaho-reporting-engine-classic-core</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>pentaho-reporting-engine</groupId>
<artifactId>pentaho-reporting-engine-classic-core-platform-plugin</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>pentaho</groupId>
<artifactId>pentaho-platform-repository</artifactId>
Expand All @@ -33,6 +43,16 @@
<artifactId>pentaho-platform-scheduler</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-engine</artifactId>
<version>${pentaho-ce.version}</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@

package org.pentaho.reporting.platform.plugin.connection;

import com.google.common.base.Strings;
import org.pentaho.database.model.DatabaseAccessType;
import org.pentaho.database.model.IDatabaseConnection;
import org.pentaho.platform.api.data.IDBDatasourceService;
import org.pentaho.platform.api.engine.ObjectFactoryException;
import org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService;
import org.pentaho.platform.engine.core.system.PentahoSystem;
import org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.ConnectionProvider;

Expand Down Expand Up @@ -52,6 +56,15 @@ public PentahoJndiDatasourceConnectionProvider() {
*/
public Connection createConnection(final String user, final String password) throws SQLException {
try {
IDatasourceMgmtService dmService = PentahoSystem.get(IDatasourceMgmtService.class, null);
IDatabaseConnection dbConn = dmService == null ? null : dmService.getDatasourceByName(jndiName);

if (dbConn != null && dbConn.getAccessType() == DatabaseAccessType.JNDI
&& !Strings.isNullOrEmpty(dbConn.getDatabaseName())) {
// FIXME this is probably too tricky... let's do it just once for each call to avoid endless-loop
jndiName = dbConn.getDatabaseName();
}

final IDBDatasourceService datasourceService =
PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
final DataSource dataSource = datasourceService.getDataSource(jndiName);
Expand Down Expand Up @@ -120,13 +133,13 @@ public Connection createConnection(final String user, final String password) thr
Messages
.getInstance()
.getErrorString(
"PentahoDatasourceConnectionProvider.ERROR_0002_UNABLE_TO_FACTORY_OBJECT", jndiName, e.getLocalizedMessage())); //$NON-NLS-1$
"PentahoDatasourceConnectionProvider.ERROR_0002_UNABLE_TO_FACTORY_OBJECT", jndiName, e.getLocalizedMessage()), e); //$NON-NLS-1$
} catch (ObjectFactoryException objface) {
throw new SQLException(
Messages
.getInstance()
.getErrorString(
"PentahoDatasourceConnectionProvider.ERROR_0002_UNABLE_TO_FACTORY_OBJECT", jndiName, e.getLocalizedMessage())); //$NON-NLS-1$
"PentahoDatasourceConnectionProvider.ERROR_0002_UNABLE_TO_FACTORY_OBJECT", jndiName, e.getLocalizedMessage()), e); //$NON-NLS-1$
}
}
}
Expand Down

0 comments on commit bf6c0a8

Please sign in to comment.