use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SpoonJobDelegate method pasteXML.
public void pasteXML(JobMeta jobMeta, String clipcontent, Point loc) {
try {
Document doc = XMLHandler.loadXMLString(clipcontent);
// De-select all, re-select pasted steps...
jobMeta.unselectAll();
Node entriesnode = XMLHandler.getSubNode(doc, Spoon.XML_TAG_JOB_JOB_ENTRIES);
int nr = XMLHandler.countNodes(entriesnode, "entry");
spoon.getLog().logDebug(spoon.toString(), "I found " + nr + " job entries to paste on location: " + loc);
List<JobEntryCopy> entryList = new ArrayList<>(nr);
// Point min = new Point(loc.x, loc.y);
Point min = new Point(99999999, 99999999);
for (int i = 0; i < nr; i++) {
Node entrynode = XMLHandler.getSubNodeByNr(entriesnode, "entry", i);
JobEntryCopy copy = new JobEntryCopy(entrynode, jobMeta.getDatabases(), jobMeta.getSlaveServers(), spoon.getRepository(), spoon.getMetaStore());
if (copy.isStart() && (jobMeta.findStart() != null)) {
JobGraph.showOnlyStartOnceMessage(spoon.getShell());
continue;
}
String name = jobMeta.getAlternativeJobentryName(copy.getName());
copy.setName(name);
if (loc != null) {
Point p = copy.getLocation();
if (min.x > p.x) {
min.x = p.x;
}
if (min.y > p.y) {
min.y = p.y;
}
}
entryList.add(copy);
}
JobEntryCopy[] entries = entryList.toArray(new JobEntryCopy[] {});
// What's the difference between loc and min?
// This is the offset:
Point offset = new Point(loc.x - min.x, loc.y - min.y);
// Undo/redo object positions...
int[] position = new int[entries.length];
for (int i = 0; i < entries.length; i++) {
Point p = entries[i].getLocation();
String name = entries[i].getName();
entries[i].setLocation(p.x + offset.x, p.y + offset.y);
// Check the name, find alternative...
entries[i].setName(jobMeta.getAlternativeJobentryName(name));
jobMeta.addJobEntry(entries[i]);
position[i] = jobMeta.indexOfJobEntry(entries[i]);
}
// Save undo information too...
spoon.addUndoNew(jobMeta, entries, position);
if (jobMeta.hasChanged()) {
spoon.refreshTree();
spoon.refreshGraph();
}
} catch (KettleException e) {
new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.ErrorDialog.ErrorPasingJobEntries.Title"), BaseMessages.getString(PKG, "Spoon.ErrorDialog.ErrorPasingJobEntries.Message"), e);
}
}
use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SpoonJobDelegate method executeJob.
public void executeJob(JobMeta jobMeta, boolean local, boolean remote, Date replayDate, boolean safe, String startCopyName, int startCopyNr) throws KettleException {
if (jobMeta == null) {
return;
}
JobExecutionConfiguration executionConfiguration = spoon.getJobExecutionConfiguration();
// Remember the variables set previously
//
Object[] data = spoon.variables.getData();
String[] fields = spoon.variables.getRowMeta().getFieldNames();
Map<String, String> variableMap = new HashMap<>();
for (int idx = 0; idx < fields.length; idx++) {
variableMap.put(fields[idx], data[idx].toString());
}
executionConfiguration.setVariables(variableMap);
executionConfiguration.getUsedVariables(jobMeta);
executionConfiguration.setReplayDate(replayDate);
executionConfiguration.setRepository(spoon.rep);
executionConfiguration.setSafeModeEnabled(safe);
executionConfiguration.setStartCopyName(startCopyName);
executionConfiguration.setStartCopyNr(startCopyNr);
executionConfiguration.getUsedArguments(jobMeta, spoon.getArguments(), spoon.getMetaStore());
executionConfiguration.setLogLevel(DefaultLogLevel.getLogLevel());
JobExecutionConfigurationDialog dialog = newJobExecutionConfigurationDialog(executionConfiguration, jobMeta);
if (!jobMeta.isShowDialog() || dialog.open()) {
JobGraph jobGraph = spoon.getActiveJobGraph();
jobGraph.jobLogDelegate.addJobLog();
//
for (String varName : executionConfiguration.getVariables().keySet()) {
String varValue = executionConfiguration.getVariables().get(varName);
jobMeta.setVariable(varName, varValue);
}
//
for (String paramName : executionConfiguration.getParams().keySet()) {
String paramValue = executionConfiguration.getParams().get(paramName);
jobMeta.setParameterValue(paramName, paramValue);
}
jobMeta.activateParameters();
//
if (executionConfiguration.getLogLevel() != null) {
jobMeta.setLogLevel(executionConfiguration.getLogLevel());
}
//
if (executionConfiguration.getStartCopyName() != null) {
jobMeta.setStartCopyName(executionConfiguration.getStartCopyName());
}
// Set the run options
//
jobMeta.setClearingLog(executionConfiguration.isClearingLog());
jobMeta.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled());
jobMeta.setExpandingRemoteJob(executionConfiguration.isExpandingRemoteJob());
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobMetaExecutionStart.id, jobMeta);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobExecutionConfiguration.id, executionConfiguration);
try {
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransBeforeStart.id, new Object[] { executionConfiguration, jobMeta, jobMeta, spoon.getRepository() });
} catch (KettleException e) {
log.logError(e.getMessage(), jobMeta.getFilename());
return;
}
if (!executionConfiguration.isExecutingLocally() && !executionConfiguration.isExecutingRemotely()) {
if (jobMeta.hasChanged()) {
jobGraph.showSaveFileMessage();
}
}
//
if (executionConfiguration.isExecutingLocally()) {
jobGraph.startJob(executionConfiguration);
} else if (executionConfiguration.isExecutingRemotely()) {
// Executing remotely
// Check if jobMeta has changed
jobGraph.handleJobMetaChanges(jobMeta);
// Activate the parameters, turn them into variables...
// jobMeta.hasChanged()
jobMeta.activateParameters();
if (executionConfiguration.getRemoteServer() != null) {
Job.sendToSlaveServer(jobMeta, executionConfiguration, spoon.rep, spoon.metaStore);
spoon.delegates.slaves.addSpoonSlave(executionConfiguration.getRemoteServer());
} else {
MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Message"));
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Title"));
mb.open();
}
}
}
}
use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SpoonPartitionsDelegate method newPartitioningSchema.
public void newPartitioningSchema(TransMeta transMeta) {
PartitionSchema partitionSchema = new PartitionSchema();
PartitionSchemaDialog dialog = new PartitionSchemaDialog(spoon.getShell(), partitionSchema, transMeta.getPartitionSchemas(), transMeta.getDatabases(), transMeta);
if (dialog.open()) {
List<PartitionSchema> partitions = transMeta.getPartitionSchemas();
if (isDuplicate(partitions, partitionSchema)) {
new ErrorDialog(spoon.getShell(), getMessage("Spoon.Dialog.ErrorSavingPartition.Title"), getMessage("Spoon.Dialog.ErrorSavingPartition.Message", partitionSchema.getName()), new KettleException(getMessage("Spoon.Dialog.ErrorSavingPartition.NotUnique")));
return;
}
partitions.add(partitionSchema);
if (spoon.rep != null) {
try {
if (!spoon.rep.getSecurityProvider().isReadOnly()) {
spoon.rep.save(partitionSchema, Const.VERSION_COMMENT_INITIAL_VERSION, null);
if (sharedObjectSyncUtil != null) {
sharedObjectSyncUtil.reloadTransformationRepositoryObjects(false);
}
} else {
throw new KettleException(BaseMessages.getString(PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser"));
}
} catch (KettleException e) {
showSaveErrorDialog(partitionSchema, e);
}
}
spoon.refreshTree();
}
}
use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SpoonSharedObjectDelegate method saveSharedObjectToRepository.
protected <T extends SharedObjectInterface & RepositoryElementInterface & ChangedFlagInterface> void saveSharedObjectToRepository(T sharedObject, String versionComment) throws KettleException {
Repository rep = spoon.getRepository();
if (rep != null) {
if (!rep.getSecurityProvider().isReadOnly()) {
rep.save(sharedObject, versionComment, null);
sharedObject.clearChanged();
} else {
throw new KettleException(BaseMessages.getString(PKG, "Spoon.Dialog.Exception.ReadOnlyRepositoryUser"));
}
}
}
use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SpoonSlaveDelegate method edit.
public boolean edit(SlaveServer slaveServer, List<SlaveServer> existingServers) {
String originalName = slaveServer.getName();
SlaveServerDialog dialog = new SlaveServerDialog(spoon.getShell(), slaveServer, existingServers);
if (dialog.open()) {
if (spoon.rep != null) {
try {
saveSharedObjectToRepository(slaveServer, null);
} catch (KettleException e) {
showSaveErrorDialog(slaveServer, e);
}
}
if (sharedObjectSyncUtil != null) {
sharedObjectSyncUtil.synchronizeSlaveServers(slaveServer, originalName);
}
spoon.refreshTree();
spoon.refreshGraph();
return true;
}
return false;
}
Aggregations