Search in sources :

Example 66 with SlaveServer

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobHopMeta(org.pentaho.di.job.JobHopMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) NotePadMeta(org.pentaho.di.core.NotePadMeta) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 67 with SlaveServer

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SlaveServer(org.pentaho.di.cluster.SlaveServer)

Example 68 with SlaveServer

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);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ObjectId(org.pentaho.di.repository.ObjectId) SlaveServerDialog(org.pentaho.di.ui.cluster.dialog.SlaveServerDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SlaveServer(org.pentaho.di.cluster.SlaveServer) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 69 with SlaveServer

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();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) UISlave(org.pentaho.di.ui.repository.repositoryexplorer.model.UISlave) ObjectId(org.pentaho.di.repository.ObjectId) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) SlaveServer(org.pentaho.di.cluster.SlaveServer) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 70 with SlaveServer

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);
    }
}
Also used : RepositoryExplorerDialog(org.pentaho.di.ui.repository.dialog.RepositoryExplorerDialog) BindingFactory(org.pentaho.ui.xul.binding.BindingFactory) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) UISlaves(org.pentaho.di.ui.repository.repositoryexplorer.model.UISlaves) SwtDialog(org.pentaho.ui.xul.swt.tags.SwtDialog) ArrayList(java.util.ArrayList) Const(org.pentaho.di.core.Const) SwtBindingFactory(org.pentaho.ui.xul.swt.SwtBindingFactory) BaseMessages(org.pentaho.di.i18n.BaseMessages) Shell(org.eclipse.swt.widgets.Shell) SlaveServerDialog(org.pentaho.di.ui.cluster.dialog.SlaveServerDialog) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended) Repository(org.pentaho.di.repository.Repository) Collection(java.util.Collection) SlaveServer(org.pentaho.di.cluster.SlaveServer) UISlave(org.pentaho.di.ui.repository.repositoryexplorer.model.UISlave) SharedObjectSyncUtil(org.pentaho.di.ui.spoon.SharedObjectSyncUtil) XulTree(org.pentaho.ui.xul.containers.XulTree) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) Binding(org.pentaho.ui.xul.binding.Binding) XulButton(org.pentaho.ui.xul.components.XulButton) List(java.util.List) ObjectId(org.pentaho.di.repository.ObjectId) SWT(org.eclipse.swt.SWT) MessageBox(org.eclipse.swt.widgets.MessageBox) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IUISupportController(org.pentaho.di.ui.repository.repositoryexplorer.IUISupportController) KettleException(org.pentaho.di.core.exception.KettleException) UISlave(org.pentaho.di.ui.repository.repositoryexplorer.model.UISlave) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryExtended(org.pentaho.di.repository.RepositoryExtended)

Aggregations

SlaveServer (org.pentaho.di.cluster.SlaveServer)110 KettleException (org.pentaho.di.core.exception.KettleException)35 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)32 Test (org.junit.Test)22 ClusterSchema (org.pentaho.di.cluster.ClusterSchema)22 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)18 PartitionSchema (org.pentaho.di.partition.PartitionSchema)18 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)17 JobMeta (org.pentaho.di.job.JobMeta)16 ObjectId (org.pentaho.di.repository.ObjectId)16 StepMeta (org.pentaho.di.trans.step.StepMeta)14 ArrayList (java.util.ArrayList)13 TransMeta (org.pentaho.di.trans.TransMeta)11 Result (org.pentaho.di.core.Result)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)10 NotePadMeta (org.pentaho.di.core.NotePadMeta)9 Point (org.pentaho.di.core.gui.Point)8 List (java.util.List)7 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)7