use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.
the class Trans method monitorRemoteTransformation.
/**
* Monitors a remote transformation at the specified interval.
*
* @param log
* the log channel interface
* @param carteObjectId
* the Carte object ID
* @param transName
* the transformation name
* @param remoteSlaveServer
* the remote slave server
* @param sleepTimeSeconds
* the sleep time (in seconds)
*/
public static void monitorRemoteTransformation(LogChannelInterface log, String carteObjectId, String transName, SlaveServer remoteSlaveServer, int sleepTimeSeconds) {
long errors = 0;
boolean allFinished = false;
while (!allFinished && errors == 0) {
allFinished = true;
errors = 0L;
// Check the remote server
if (allFinished && errors == 0) {
try {
SlaveServerTransStatus transStatus = remoteSlaveServer.getTransStatus(transName, carteObjectId, 0);
if (transStatus.isRunning()) {
if (log.isDetailed()) {
log.logDetailed(transName, "Remote transformation is still running.");
}
allFinished = false;
} else {
if (log.isDetailed()) {
log.logDetailed(transName, "Remote transformation has finished.");
}
}
Result result = transStatus.getResult();
errors += result.getNrErrors();
} catch (Exception e) {
errors += 1;
log.logError(transName, "Unable to contact remote slave server '" + remoteSlaveServer.getName() + "' to check transformation status : " + e.toString());
}
}
//
if (!allFinished) {
// Not finished or error: wait a bit longer
if (log.isDetailed()) {
log.logDetailed(transName, "The remote transformation is still running, waiting a few seconds...");
}
try {
Thread.sleep(sleepTimeSeconds * 1000);
} catch (Exception e) {
// Ignore errors
}
// Check all slaves every x seconds.
}
}
log.logMinimal(transName, "The remote transformation has finished.");
//
try {
WebResult webResult = remoteSlaveServer.cleanupTransformation(transName, carteObjectId);
if (!WebResult.STRING_OK.equals(webResult.getResult())) {
log.logError(transName, "Unable to run clean-up on remote transformation '" + transName + "' : " + webResult.getMessage());
errors += 1;
}
} catch (Exception e) {
errors += 1;
log.logError(transName, "Unable to contact slave server '" + remoteSlaveServer.getName() + "' to clean up transformation : " + e.toString());
}
}
use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.
the class Trans method sendToSlaveServer.
/**
* Send the transformation for execution to a Carte slave server.
*
* @param transMeta
* the transformation meta-data
* @param executionConfiguration
* the transformation execution configuration
* @param repository
* the repository
* @return The Carte object ID on the server.
* @throws KettleException
* if any errors occur during the dispatch to the slave server
*/
public static String sendToSlaveServer(TransMeta transMeta, TransExecutionConfiguration executionConfiguration, Repository repository, IMetaStore metaStore) throws KettleException {
String carteObjectId;
SlaveServer slaveServer = executionConfiguration.getRemoteServer();
if (slaveServer == null) {
throw new KettleException("No slave server specified");
}
if (Utils.isEmpty(transMeta.getName())) {
throw new KettleException("The transformation needs a name to uniquely identify it by on the remote server.");
}
// Inject certain internal variables to make it more intuitive.
//
Map<String, String> vars = new HashMap<>();
for (String var : Const.INTERNAL_TRANS_VARIABLES) {
vars.put(var, transMeta.getVariable(var));
}
for (String var : Const.INTERNAL_JOB_VARIABLES) {
vars.put(var, transMeta.getVariable(var));
}
executionConfiguration.getVariables().putAll(vars);
slaveServer.injectVariables(executionConfiguration.getVariables());
slaveServer.getLogChannel().setLogLevel(executionConfiguration.getLogLevel());
try {
if (executionConfiguration.isPassingExport()) {
// First export the job...
//
FileObject tempFile = KettleVFS.createTempFile("transExport", KettleVFS.Suffix.ZIP, transMeta);
TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(tempFile.getName().toString(), transMeta, transMeta, repository, metaStore, executionConfiguration.getXML(), CONFIGURATION_IN_EXPORT_FILENAME);
// Send the zip file over to the slave server...
//
String result = slaveServer.sendExport(topLevelResource.getArchiveName(), RegisterPackageServlet.TYPE_TRANS, topLevelResource.getBaseResourceName());
WebResult webResult = WebResult.fromXMLString(result);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error passing the exported transformation to the remote server: " + Const.CR + webResult.getMessage());
}
carteObjectId = webResult.getId();
} else {
// Now send it off to the remote server...
//
String xml = new TransConfiguration(transMeta, executionConfiguration).getXML();
String reply = slaveServer.sendXML(xml, RegisterTransServlet.CONTEXT_PATH + "/?xml=Y");
WebResult webResult = WebResult.fromXMLString(reply);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error posting the transformation on the remote server: " + Const.CR + webResult.getMessage());
}
carteObjectId = webResult.getId();
}
// Prepare the transformation
//
String reply = slaveServer.execService(PrepareExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(transMeta.getName(), "UTF-8") + "&xml=Y&id=" + carteObjectId);
WebResult webResult = WebResult.fromXMLString(reply);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error preparing the transformation for excution on the remote server: " + Const.CR + webResult.getMessage());
}
// Start the transformation
//
reply = slaveServer.execService(StartExecutionTransServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(transMeta.getName(), "UTF-8") + "&xml=Y&id=" + carteObjectId);
webResult = WebResult.fromXMLString(reply);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error starting the transformation on the remote server: " + Const.CR + webResult.getMessage());
}
return carteObjectId;
} catch (KettleException ke) {
throw ke;
} catch (Exception e) {
throw new KettleException(e);
}
}
use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.
the class Job method sendToSlaveServer.
/**
* Send to slave server.
*
* @param jobMeta
* the job meta
* @param executionConfiguration
* the execution configuration
* @param repository
* the repository
* @param metaStore
* the metaStore
* @return the string
* @throws KettleException
* the kettle exception
*/
public static String sendToSlaveServer(JobMeta jobMeta, JobExecutionConfiguration executionConfiguration, Repository repository, IMetaStore metaStore) throws KettleException {
String carteObjectId;
SlaveServer slaveServer = executionConfiguration.getRemoteServer();
if (slaveServer == null) {
throw new KettleException(BaseMessages.getString(PKG, "Job.Log.NoSlaveServerSpecified"));
}
if (Utils.isEmpty(jobMeta.getName())) {
throw new KettleException(BaseMessages.getString(PKG, "Job.Log.UniqueJobName"));
}
// Align logging levels between execution configuration and remote server
slaveServer.getLogChannel().setLogLevel(executionConfiguration.getLogLevel());
try {
//
for (String var : Const.INTERNAL_TRANS_VARIABLES) {
executionConfiguration.getVariables().put(var, jobMeta.getVariable(var));
}
for (String var : Const.INTERNAL_JOB_VARIABLES) {
executionConfiguration.getVariables().put(var, jobMeta.getVariable(var));
}
if (executionConfiguration.isPassingExport()) {
// First export the job... slaveServer.getVariable("MASTER_HOST")
//
FileObject tempFile = KettleVFS.createTempFile("jobExport", ".zip", System.getProperty("java.io.tmpdir"), jobMeta);
TopLevelResource topLevelResource = ResourceUtil.serializeResourceExportInterface(tempFile.getName().toString(), jobMeta, jobMeta, repository, metaStore, executionConfiguration.getXML(), CONFIGURATION_IN_EXPORT_FILENAME);
// Send the zip file over to the slave server...
String result = slaveServer.sendExport(topLevelResource.getArchiveName(), RegisterPackageServlet.TYPE_JOB, topLevelResource.getBaseResourceName());
WebResult webResult = WebResult.fromXMLString(result);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error passing the exported job to the remote server: " + Const.CR + webResult.getMessage());
}
carteObjectId = webResult.getId();
} else {
String xml = new JobConfiguration(jobMeta, executionConfiguration).getXML();
String reply = slaveServer.sendXML(xml, RegisterJobServlet.CONTEXT_PATH + "/?xml=Y");
WebResult webResult = WebResult.fromXMLString(reply);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error posting the job on the remote server: " + Const.CR + webResult.getMessage());
}
carteObjectId = webResult.getId();
}
// Start the job
//
String reply = slaveServer.execService(StartJobServlet.CONTEXT_PATH + "/?name=" + URLEncoder.encode(jobMeta.getName(), "UTF-8") + "&xml=Y&id=" + carteObjectId);
WebResult webResult = WebResult.fromXMLString(reply);
if (!webResult.getResult().equalsIgnoreCase(WebResult.STRING_OK)) {
throw new KettleException("There was an error starting the job on the remote server: " + Const.CR + webResult.getMessage());
}
return carteObjectId;
} catch (KettleException ke) {
throw ke;
} catch (Exception e) {
throw new KettleException(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);
}
}
}
}
}
use of org.pentaho.di.www.WebResult in project pentaho-kettle by pentaho.
the class SpoonSlave method stop.
protected void stop() {
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()) {
try {
WebResult webResult = slaveServer.stopTransformation(treeEntry.name, transStatus.getId());
if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Message"), webResult.getMessage());
dialog.setReadOnly();
dialog.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingTrans.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.stopJob(treeEntry.name, jobStatus.getId());
if (!WebResult.STRING_OK.equalsIgnoreCase(webResult.getResult())) {
EnterTextDialog dialog = new EnterTextDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Message"), webResult.getMessage());
dialog.setReadOnly();
dialog.open();
}
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Title"), BaseMessages.getString(PKG, "SpoonSlave.ErrorStoppingJob.Message"), e);
}
}
}
}
}
Aggregations