use of org.pentaho.di.job.JobAdapter in project pentaho-kettle by pentaho.
the class JobGraph method startJob.
public synchronized void startJob(JobExecutionConfiguration executionConfiguration) throws KettleException {
//
if (job == null || job.isFinished() && !job.isActive()) {
// Auto save feature...
//
handleJobMetaChanges(jobMeta);
//
if (((jobMeta.getName() != null && jobMeta.getObjectId() != null && spoon.rep != null) || (jobMeta.getFilename() != null && spoon.rep == null)) && // Didn't change
!jobMeta.hasChanged()) {
if (job == null || (job != null && !job.isActive())) {
try {
//
if (executionConfiguration.isClearingLog()) {
jobLogDelegate.clearLog();
}
//
if (job != null) {
KettleLogStore.discardLines(job.getLogChannelId(), true);
}
JobMeta runJobMeta;
if (spoon.rep != null) {
runJobMeta = spoon.rep.loadJob(jobMeta.getName(), jobMeta.getRepositoryDirectory(), null, null);
} else {
runJobMeta = new JobMeta(null, jobMeta.getFilename(), null, jobMeta.getMetaStore(), null);
}
String spoonObjectId = UUID.randomUUID().toString();
SimpleLoggingObject spoonLoggingObject = new SimpleLoggingObject("SPOON", LoggingObjectType.SPOON, null);
spoonLoggingObject.setContainerObjectId(spoonObjectId);
spoonLoggingObject.setLogLevel(executionConfiguration.getLogLevel());
job = new Job(spoon.rep, runJobMeta, spoonLoggingObject);
job.setLogLevel(executionConfiguration.getLogLevel());
job.shareVariablesWith(jobMeta);
job.setInteractive(true);
job.setGatheringMetrics(executionConfiguration.isGatheringMetrics());
job.setArguments(executionConfiguration.getArgumentStrings());
// Pass specific extension points...
//
job.getExtensionDataMap().putAll(executionConfiguration.getExtensionOptions());
// Add job entry listeners
//
job.addJobEntryListener(createRefreshJobEntryListener());
//
if (!Utils.isEmpty(executionConfiguration.getStartCopyName())) {
JobEntryCopy startJobEntryCopy = runJobMeta.findJobEntry(executionConfiguration.getStartCopyName(), executionConfiguration.getStartCopyNr(), false);
job.setStartJobEntryCopy(startJobEntryCopy);
}
// Set the named parameters
Map<String, String> paramMap = executionConfiguration.getParams();
Set<String> keys = paramMap.keySet();
for (String key : keys) {
job.getJobMeta().setParameterValue(key, Const.NVL(paramMap.get(key), ""));
}
job.getJobMeta().activateParameters();
log.logMinimal(BaseMessages.getString(PKG, "JobLog.Log.StartingJob"));
job.start();
jobGridDelegate.previousNrItems = -1;
// Link to the new jobTracker!
jobGridDelegate.jobTracker = job.getJobTracker();
// Attach a listener to notify us that the transformation has
// finished.
job.addJobListener(new JobAdapter() {
public void jobFinished(Job job) {
JobGraph.this.jobFinished();
}
});
// Show the execution results views
//
addAllTabs();
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "JobLog.Dialog.CanNotOpenJob.Title"), BaseMessages.getString(PKG, "JobLog.Dialog.CanNotOpenJob.Message"), e);
job = null;
}
} else {
MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.JobIsAlreadyRunning.Title"));
m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.JobIsAlreadyRunning.Message"));
m.open();
}
} else {
if (jobMeta.hasChanged()) {
showSaveFileMessage();
} else if (spoon.rep != null && jobMeta.getName() == null) {
MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.PleaseGiveThisJobAName.Title"));
m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.PleaseGiveThisJobAName.Message"));
m.open();
} else {
MessageBox m = new MessageBox(shell, SWT.OK | SWT.ICON_WARNING);
m.setText(BaseMessages.getString(PKG, "JobLog.Dialog.NoFilenameSaveYourJobFirst.Title"));
m.setMessage(BaseMessages.getString(PKG, "JobLog.Dialog.NoFilenameSaveYourJobFirst.Message"));
m.open();
}
}
setControlStates();
}
}
use of org.pentaho.di.job.JobAdapter in project pentaho-kettle by pentaho.
the class MLLPSocketCache method getServerSocketStreamSource.
public MLLPSocketCacheEntry getServerSocketStreamSource(String server, int port) throws Exception {
final String key = createKey(server, port);
MLLPSocketCacheEntry s = map.get(key);
if (s != null) {
return s;
}
// Open the socket for this server/port combination.
//
ServerSocket serverSocket = new ServerSocket(port);
StreamSource streamSource = new ServerSocketStreamSource(serverSocket, server);
MLLPTransport transport = new MLLPTransport(streamSource);
transport.connect();
final MLLPSocketCacheEntry entry = new MLLPSocketCacheEntry(serverSocket, streamSource, transport);
entry.setJobListener(new JobAdapter() {
@Override
public void jobFinished(Job job) throws KettleException {
KettleException exception = null;
try {
entry.getTransport().disconnect();
} catch (Exception e) {
exception = new KettleException(e);
}
try {
entry.getStreamSource().disconnect();
} catch (Exception e) {
exception = new KettleException(e);
}
try {
entry.getServerSocket().close();
} catch (Exception e) {
exception = new KettleException(e);
}
map.remove(key);
if (exception != null) {
throw exception;
}
}
});
// Store a copy in our map to make sure that only the first return value contains the job listener.
//
map.put(key, new MLLPSocketCacheEntry(serverSocket, streamSource, transport));
return entry;
}
Aggregations