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);
}
}
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);
}
}
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);
}
}
}
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);
}
}
}
}
}
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);
}
}
}
}
}
Aggregations