use of org.pentaho.di.cluster.SlaveServer in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryJobDelegate method saveJob.
/**
* Stored a job in the repository
*
* @param jobMeta
* The job to store
* @param monitor
* the (optional) UI progress monitor
* @param overwrite
* Overwrite existing object(s)?
* @throws KettleException
* in case some IO error occurs.
*/
public void saveJob(JobMeta jobMeta, String versionComment, ProgressMonitorListener monitor, boolean overwrite) throws KettleException {
try {
// Before saving the job, see if it's not locked by someone else...
//
int nrWorks = 2 + jobMeta.nrDatabases() + jobMeta.nrNotes() + jobMeta.nrJobEntries() + jobMeta.nrJobHops();
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "JobMeta.Monitor.SavingTransformation") + jobMeta.getRepositoryDirectory() + Const.FILE_SEPARATOR + jobMeta.getName(), nrWorks);
}
repository.insertLogEntry("save job '" + jobMeta.getName() + "'");
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.HandlingPreviousVersionOfJob"));
}
jobMeta.setObjectId(getJobID(jobMeta.getName(), jobMeta.getRepositoryDirectory().getObjectId()));
// If no valid id is available in the database, assign one...
if (jobMeta.getObjectId() == null) {
jobMeta.setObjectId(repository.connectionDelegate.getNextJobID());
} else {
// If we have a valid ID, we need to make sure everything is
// cleared out
// of the database for this id_job, before we put it back in...
repository.deleteJob(jobMeta.getObjectId());
}
if (monitor != null) {
monitor.worked(1);
}
//
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "JobMeta.Log.SavingDatabaseConnections"));
}
for (int i = 0; i < jobMeta.nrDatabases(); i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.SavingDatabaseTask.Title") + (i + 1) + "/" + jobMeta.nrDatabases());
}
DatabaseMeta databaseMeta = jobMeta.getDatabase(i);
// nothing was saved in the repository)
if (overwrite || databaseMeta.hasChanged() || databaseMeta.getObjectId() == null) {
repository.save(databaseMeta, versionComment, monitor, overwrite);
}
if (monitor != null) {
monitor.worked(1);
}
}
// entries to the save job. (retry)
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.SavingJobDetails"));
}
if (log.isDetailed()) {
log.logDetailed("Saving job info to repository...");
}
insertJob(jobMeta);
if (monitor != null) {
monitor.worked(1);
}
// Save the group attributes map
//
saveJobAttributesMap(jobMeta.getObjectId(), jobMeta.getAttributesMap());
//
for (int i = 0; i < jobMeta.getSlaveServers().size(); i++) {
SlaveServer slaveServer = jobMeta.getSlaveServers().get(i);
repository.save(slaveServer, versionComment, null, jobMeta.getObjectId(), false, overwrite);
}
//
if (log.isDetailed()) {
log.logDetailed("Saving notes to repository...");
}
for (int i = 0; i < jobMeta.nrNotes(); i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.SavingNoteNr") + (i + 1) + "/" + jobMeta.nrNotes());
}
NotePadMeta ni = jobMeta.getNote(i);
repository.saveNotePadMeta(ni, jobMeta.getObjectId());
if (ni.getObjectId() != null) {
repository.insertJobNote(jobMeta.getObjectId(), ni.getObjectId());
}
if (monitor != null) {
monitor.worked(1);
}
}
//
if (log.isDetailed()) {
log.logDetailed("Saving " + jobMeta.nrJobEntries() + " Job enty copies to repository...");
}
repository.updateJobEntryTypes();
for (int i = 0; i < jobMeta.nrJobEntries(); i++) {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "JobMeta.Monitor.SavingJobEntryNr") + (i + 1) + "/" + jobMeta.nrJobEntries());
}
JobEntryCopy cge = jobMeta.getJobEntry(i);
repository.jobEntryDelegate.saveJobEntryCopy(cge, jobMeta.getObjectId(), repository.metaStore);
if (monitor != null) {
monitor.worked(1);
}
}
if (log.isDetailed()) {
log.logDetailed("Saving job hops to repository...");
}
for (int i = 0; i < jobMeta.nrJobHops(); i++) {
if (monitor != null) {
monitor.subTask("Saving job hop #" + (i + 1) + "/" + jobMeta.nrJobHops());
}
JobHopMeta hi = jobMeta.getJobHop(i);
saveJobHopMeta(hi, jobMeta.getObjectId());
if (monitor != null) {
monitor.worked(1);
}
}
saveJobParameters(jobMeta);
// Commit this transaction!!
repository.commit();
jobMeta.clearChanged();
if (monitor != null) {
monitor.done();
}
} catch (KettleDatabaseException dbe) {
repository.rollback();
throw new KettleException(BaseMessages.getString(PKG, "JobMeta.Exception.UnableToSaveJobInRepositoryRollbackPerformed"), dbe);
}
}
use of org.pentaho.di.cluster.SlaveServer in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryJobDelegate method readSlaves.
/**
* Read the slave servers in the repository and add them to this transformation if they are not yet present.
*
* @param jobMeta
* The job to put the slave servers in
* @param overWriteShared
* if an object with the same name exists, overwrite
* @throws KettleException
*/
public void readSlaves(JobMeta jobMeta, boolean overWriteShared) throws KettleException {
try {
ObjectId[] dbids = repository.getSlaveIDs(false);
for (int i = 0; i < dbids.length; i++) {
// Load last version
SlaveServer slaveServer = repository.loadSlaveServer(dbids[i], null);
slaveServer.shareVariablesWith(jobMeta);
// Check if there already is one in the
SlaveServer check = jobMeta.findSlaveServer(slaveServer.getName());
// transformation
if (check == null || overWriteShared) {
if (!Utils.isEmpty(slaveServer.getName())) {
jobMeta.addOrReplaceSlaveServer(slaveServer);
if (!overWriteShared) {
slaveServer.setChanged(false);
}
}
}
}
} catch (KettleDatabaseException dbe) {
throw new KettleException(BaseMessages.getString(PKG, "JobMeta.Log.UnableToReadSlaveServersFromRepository"), dbe);
}
}
use of org.pentaho.di.cluster.SlaveServer in project pentaho-kettle by pentaho.
the class RepositoryExplorerDialog method newSlaveServer.
public void newSlaveServer() {
try {
SlaveServer slaveServer = new SlaveServer();
SlaveServerDialog dd = new SlaveServerDialog(shell, slaveServer, rep.getSlaveServers());
if (dd.open()) {
// See if this slave server already exists...
ObjectId idSlave = rep.getSlaveID(slaveServer.getName());
if (idSlave == null) {
rep.insertLogEntry("Creating new slave server '" + slaveServer.getName() + "'");
rep.save(slaveServer, Const.VERSION_COMMENT_INITIAL_VERSION, null);
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Create.AlreadyExists.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Create.AlreadyExists.Title"));
mb.open();
}
// Refresh tree...
refreshTree();
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Connection.Create.UnexpectedError.Message"), e);
}
}
use of org.pentaho.di.cluster.SlaveServer in project pentaho-kettle by pentaho.
the class SlavesController method removeSlave.
public void removeSlave() {
String slaveServerName = "";
try {
Collection<UISlave> slaves = slavesTable.getSelectedItems();
if (slaves != null && !slaves.isEmpty()) {
for (Object obj : slaves) {
if (obj != null && obj instanceof UISlave) {
UISlave slave = (UISlave) obj;
SlaveServer slaveServer = slave.getSlaveServer();
slaveServerName = slaveServer.getName();
// Make sure the slave to delete exists in the repository
ObjectId slaveId = repository.getSlaveID(slaveServer.getName());
if (slaveId == null) {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.DoesNotExists.Message", slaveServerName));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Delete.Title"));
mb.open();
} else {
repository.deleteSlave(slaveId);
if (getSharedObjectSyncUtil() != null) {
getSharedObjectSyncUtil().deleteSlaveServer(slaveServer);
}
}
}
}
} else {
MessageBox mb = new MessageBox(shell, SWT.ICON_ERROR | SWT.OK);
mb.setMessage(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.NoItemSelected.Message"));
mb.setText(BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Delete.Title"));
mb.open();
}
} catch (KettleException e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Delete.Title"), BaseMessages.getString(PKG, "RepositoryExplorerDialog.Slave.Delete.UnexpectedError.Message") + slaveServerName + "]", e);
}
} finally {
refreshSlaves();
}
}
use of org.pentaho.di.cluster.SlaveServer in project pentaho-kettle by pentaho.
the class SlavesController method refreshSlaves.
public void refreshSlaves() {
if (repository != null) {
final List<UISlave> tmpList = new ArrayList<UISlave>();
Runnable r = () -> {
try {
List<SlaveServer> slaveServers;
if (repository instanceof RepositoryExtended) {
slaveServers = ((RepositoryExtended) repository).getSlaveServers(false);
} else {
slaveServers = repository.getSlaveServers();
}
if (slaveServers != null) {
slaveServers.forEach(slaveServer -> tmpList.add(new UISlave(slaveServer)));
}
} catch (KettleException e) {
if (mainController == null || !mainController.handleLostRepository(e)) {
// convert to runtime exception so it bubbles up through the UI
throw new RuntimeException(e);
}
}
};
doWithBusyIndicator(r);
slaveList.setChildren(tmpList);
}
}
Aggregations