Search in sources :

Example 1 with WebResult

use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.

the class Trans method executeClustered.

/**
 * Executes an existing TransSplitter, with the transformation already split.
 *
 * @param transSplitter          the trans splitter
 * @param executionConfiguration the execution configuration
 * @throws KettleException the kettle exception
 * @see org.pentaho.di.ui.spoon.delegates.SpoonTransformationDelegate
 */
public static void executeClustered(final TransSplitter transSplitter, final TransExecutionConfiguration executionConfiguration) throws KettleException {
    try {
        // Send the transformations to the servers...
        // 
        // First the master and the slaves...
        // 
        TransMeta master = transSplitter.getMaster();
        final SlaveServer[] slaves = transSplitter.getSlaveTargets();
        final Thread[] threads = new Thread[slaves.length];
        final Throwable[] errors = new Throwable[slaves.length];
        // Keep track of the various Carte object IDs
        // 
        final Map<TransMeta, String> carteObjectMap = transSplitter.getCarteObjectMap();
        // 
        // Send them all on their way...
        // 
        SlaveServer masterServer = null;
        List<StepMeta> masterSteps = master.getTransHopSteps(false);
        if (masterSteps.size() > 0) {
            // If there is something that needs to be done on the master...
            masterServer = transSplitter.getMasterServer();
            if (executionConfiguration.isClusterPosting()) {
                TransConfiguration transConfiguration = new TransConfiguration(master, executionConfiguration);
                Map<String, String> variables = transConfiguration.getTransExecutionConfiguration().getVariables();
                variables.put(Const.INTERNAL_VARIABLE_CLUSTER_SIZE, Integer.toString(slaves.length));
                variables.put(Const.INTERNAL_VARIABLE_CLUSTER_MASTER, "Y");
                // Parameters override the variables but they need to pass over the configuration too...
                // 
                Map<String, String> params = transConfiguration.getTransExecutionConfiguration().getParams();
                TransMeta ot = transSplitter.getOriginalTransformation();
                for (String param : ot.listParameters()) {
                    String value = Const.NVL(ot.getParameterValue(param), Const.NVL(ot.getParameterDefault(param), ot.getVariable(param)));
                    params.put(param, value);
                }
                String masterReply = masterServer.sendXML(transConfiguration.getXML(), RegisterTransServlet.CONTEXT_PATH + "/?xml=Y");
                WebResult webResult = WebResult.fromXMLString(masterReply);
                if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                    throw new KettleException("An error occurred sending the master transformation: " + webResult.getMessage());
                }
                carteObjectMap.put(master, webResult.getId());
            }
        }
        // 
        for (int i = 0; i < slaves.length; i++) {
            final int index = i;
            final TransMeta slaveTrans = transSplitter.getSlaveTransMap().get(slaves[i]);
            if (executionConfiguration.isClusterPosting()) {
                Runnable runnable = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            // Create a copy for local use... We get race-conditions otherwise...
                            // 
                            TransExecutionConfiguration slaveTransExecutionConfiguration = (TransExecutionConfiguration) executionConfiguration.clone();
                            TransConfiguration transConfiguration = new TransConfiguration(slaveTrans, slaveTransExecutionConfiguration);
                            Map<String, String> variables = slaveTransExecutionConfiguration.getVariables();
                            variables.put(Const.INTERNAL_VARIABLE_SLAVE_SERVER_NUMBER, Integer.toString(index));
                            variables.put(Const.INTERNAL_VARIABLE_SLAVE_SERVER_NAME, slaves[index].getName());
                            variables.put(Const.INTERNAL_VARIABLE_CLUSTER_SIZE, Integer.toString(slaves.length));
                            variables.put(Const.INTERNAL_VARIABLE_CLUSTER_MASTER, "N");
                            // Parameters override the variables but they need to pass over the configuration too...
                            // 
                            Map<String, String> params = slaveTransExecutionConfiguration.getParams();
                            TransMeta ot = transSplitter.getOriginalTransformation();
                            for (String param : ot.listParameters()) {
                                String value = Const.NVL(ot.getParameterValue(param), Const.NVL(ot.getParameterDefault(param), ot.getVariable(param)));
                                params.put(param, value);
                            }
                            String slaveReply = slaves[index].sendXML(transConfiguration.getXML(), RegisterTransServlet.CONTEXT_PATH + "/?xml=Y");
                            WebResult webResult = WebResult.fromXMLString(slaveReply);
                            if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                                throw new KettleException("An error occurred sending a slave transformation: " + webResult.getMessage());
                            }
                            carteObjectMap.put(slaveTrans, webResult.getId());
                        } catch (Throwable t) {
                            errors[index] = t;
                        }
                    }
                };
                threads[i] = new Thread(runnable);
            }
        }
        // Start the slaves
        for (int i = 0; i < threads.length; i++) {
            if (threads[i] != null) {
                threads[i].start();
            }
        }
        // 
        for (int i = 0; i < threads.length; i++) {
            if (threads[i] != null) {
                threads[i].join();
                if (errors[i] != null) {
                    throw new KettleException(errors[i]);
                }
            }
        }
        if (executionConfiguration.isClusterPosting()) {
            if (executionConfiguration.isClusterPreparing()) {
                // Prepare the master...
                if (masterSteps.size() > 0) {
                    // If there is something that needs to be done on the master...
                    String carteObjectId = carteObjectMap.get(master);
                    String masterReply = masterServer.execService(PrepareExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(master.getName(), "UTF-8") + "&id=" + URLEncoder.encode(carteObjectId, "UTF-8") + "&xml=Y");
                    WebResult webResult = WebResult.fromXMLString(masterReply);
                    if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                        throw new KettleException("An error occurred while preparing the execution of the master transformation: " + webResult.getMessage());
                    }
                }
                // WG: Should these be threaded like the above initialization?
                for (int i = 0; i < slaves.length; i++) {
                    TransMeta slaveTrans = transSplitter.getSlaveTransMap().get(slaves[i]);
                    String carteObjectId = carteObjectMap.get(slaveTrans);
                    String slaveReply = slaves[i].execService(PrepareExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(slaveTrans.getName(), "UTF-8") + "&id=" + URLEncoder.encode(carteObjectId, "UTF-8") + "&xml=Y");
                    WebResult webResult = WebResult.fromXMLString(slaveReply);
                    if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                        throw new KettleException("An error occurred while preparing the execution of a slave transformation: " + webResult.getMessage());
                    }
                }
            }
            if (executionConfiguration.isClusterStarting()) {
                // Start the master...
                if (masterSteps.size() > 0) {
                    // If there is something that needs to be done on the master...
                    String carteObjectId = carteObjectMap.get(master);
                    String masterReply = masterServer.execService(StartExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(master.getName(), "UTF-8") + "&id=" + URLEncoder.encode(carteObjectId, "UTF-8") + "&xml=Y");
                    WebResult webResult = WebResult.fromXMLString(masterReply);
                    if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                        throw new KettleException("An error occurred while starting the execution of the master transformation: " + webResult.getMessage());
                    }
                }
                // WG: Should these be threaded like the above initialization?
                for (int i = 0; i < slaves.length; i++) {
                    TransMeta slaveTrans = transSplitter.getSlaveTransMap().get(slaves[i]);
                    String carteObjectId = carteObjectMap.get(slaveTrans);
                    String slaveReply = slaves[i].execService(StartExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(slaveTrans.getName(), "UTF-8") + "&id=" + URLEncoder.encode(carteObjectId, "UTF-8") + "&xml=Y");
                    WebResult webResult = WebResult.fromXMLString(slaveReply);
                    if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
                        throw new KettleException("An error occurred while starting the execution of a slave transformation: " + webResult.getMessage());
                    }
                }
            }
        }
    } catch (KettleException ke) {
        throw ke;
    } catch (Exception e) {
        throw new KettleException("There was an error during transformation split", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SlaveServer(org.pentaho.di.cluster.SlaveServer) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RunThread(org.pentaho.di.trans.step.RunThread) StepInitThread(org.pentaho.di.trans.step.StepInitThread) WebResult(org.pentaho.di.www.WebResult)

Example 2 with WebResult

use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.

the class Trans method cleanupSlaveServer.

/**
 * Cleanup the slave server as part of a clustered transformation.
 *
 * @param transSplitter  the TransSplitter object
 * @param slaveServer    the slave server
 * @param slaveTransMeta the slave transformation meta-data
 * @throws KettleException if any errors occur during cleanup
 */
public static void cleanupSlaveServer(TransSplitter transSplitter, SlaveServer slaveServer, TransMeta slaveTransMeta) throws KettleException {
    String transName = slaveTransMeta.getName();
    try {
        String carteObjectId = transSplitter.getCarteObjectMap().get(slaveTransMeta);
        WebResult webResult = slaveServer.cleanupTransformation(transName, carteObjectId);
        if (!WebResult.STRING_OK.equals(webResult.getResult())) {
            throw new KettleException("Unable to run clean-up on slave server '" + slaveServer + "' for transformation '" + transName + "' : " + webResult.getMessage());
        }
    } catch (Exception e) {
        throw new KettleException("Unexpected error contacting slave server '" + slaveServer + "' to clear up transformation '" + transName + "'", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) WebResult(org.pentaho.di.www.WebResult) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleTransException(org.pentaho.di.core.exception.KettleTransException) DuplicateParamException(org.pentaho.di.core.parameters.DuplicateParamException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

Example 3 with WebResult

use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.

the class SpoonSlave method pause.

protected void pause() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        try {
            WebResult webResult = slaveServer.pauseResumeTransformation(treeEntry.name, treeEntry.id);
            if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorPausingOrResumingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorPausingOrResumingTrans.Message"), webResult.getMessage());
                dialog.setReadOnly();
                dialog.open();
            }
        } catch (Exception e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorPausingOrResumingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorPausingOrResumingTrans.Message"), e);
        }
    }
}
Also used : EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) WebResult(org.pentaho.di.www.WebResult)

Example 4 with WebResult

use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.

the class SpoonSlave method start.

protected void start() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        SlaveServerTransStatus transStatus = slaveServerStatus.findTransStatus(treeEntry.name, treeEntry.id);
        if (transStatus != null) {
            if (!transStatus.isRunning()) {
                try {
                    WebResult webResult = slaveServer.startTransformation(treeEntry.name, transStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingTrans.Message"), e);
                }
            }
        }
    } else if (treeEntry.isJob()) {
        // Job
        SlaveServerJobStatus jobStatus = slaveServerStatus.findJobStatus(treeEntry.name, treeEntry.id);
        if (jobStatus != null) {
            if (!jobStatus.isRunning()) {
                try {
                    WebResult webResult = slaveServer.startJob(treeEntry.name, jobStatus.getId());
                    if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStartingJob.Message"), e);
                }
            }
        }
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) WebResult(org.pentaho.di.www.WebResult)

Example 5 with WebResult

use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.

the class SpoonSlave method remove.

protected void remove() {
    TreeEntry treeEntry = getTreeEntry();
    if (treeEntry == null) {
        return;
    }
    if (treeEntry.isTransformation()) {
        // Transformation
        SlaveServerTransStatus transStatus = slaveServerStatus.findTransStatus(treeEntry.name, treeEntry.id);
        if (transStatus != null) {
            if (!transStatus.isRunning() && !transStatus.isPaused() && !transStatus.isStopped()) {
                try {
                    WebResult webResult = slaveServer.removeTransformation(treeEntry.name, transStatus.getId());
                    if (WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        // Force refresh in order to give faster visual feedback and reengage the timer
                        wTree.deselectAll();
                        engageViewAndLogUpdateTimer();
                    } else {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingTrans.Message"), e);
                }
            }
        }
    } else if (treeEntry.isJob()) {
        // Job
        SlaveServerJobStatus jobStatus = slaveServerStatus.findJobStatus(treeEntry.name, treeEntry.id);
        if (jobStatus != null) {
            if (!jobStatus.isRunning()) {
                try {
                    WebResult webResult = slaveServer.removeJob(treeEntry.name, jobStatus.getId());
                    if (WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
                        // Force refresh in order to give faster visual feedback and reengage the timer
                        wTree.deselectAll();
                        engageViewAndLogUpdateTimer();
                    } else {
                        EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Message"), webResult.getMessage());
                        dialog.setReadOnly();
                        dialog.open();
                    }
                } catch (Exception e) {
                    new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorRemovingJob.Message"), e);
                }
            }
        }
    }
}
Also used : SlaveServerJobStatus(org.pentaho.di.www.SlaveServerJobStatus) SlaveServerTransStatus(org.pentaho.di.www.SlaveServerTransStatus) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) WebResult(org.pentaho.di.www.WebResult)

Aggregations

WebResult (org.pentaho.di.www.WebResult)10 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 KettleException (org.pentaho.di.core.exception.KettleException)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 DuplicateParamException (org.pentaho.di.core.parameters.DuplicateParamException)6 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 KettleFileException (org.pentaho.di.core.exception.KettleFileException)5 KettleTransException (org.pentaho.di.core.exception.KettleTransException)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5 SlaveServerTransStatus (org.pentaho.di.www.SlaveServerTransStatus)5 SlaveServer (org.pentaho.di.cluster.SlaveServer)4 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)4 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)4 SlaveServerJobStatus (org.pentaho.di.www.SlaveServerJobStatus)3 FileObject (org.apache.commons.vfs2.FileObject)2 Result (org.pentaho.di.core.Result)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 TopLevelResource (org.pentaho.di.resource.TopLevelResource)2 HashMap (java.util.HashMap)1