Skip to content
Snippets Groups Projects

Updates to Commands

Merged Eclipse Webmaster requested to merge github/fork/osbornjd/jay/MarkIII into next
68 files
+ 3395
914
Compare changes
  • Side-by-side
  • Inline
Files
68
@@ -70,6 +70,12 @@ public abstract class Command {
@@ -70,6 +70,12 @@ public abstract class Command {
*/
*/
protected ConnectionManager manager = ConnectionManagerFactory.getConnectionManager();
protected ConnectionManager manager = ConnectionManagerFactory.getConnectionManager();
 
 
/**
 
* An optional update handler that can provide status updates for the command
 
*/
 
ICommandUpdateHandler updater = null;
 
/**
/**
* Default constructor
* Default constructor
*/
*/
@@ -104,6 +110,18 @@ public abstract class Command {
@@ -104,6 +110,18 @@ public abstract class Command {
// Confirm the job finished with some status
// Confirm the job finished with some status
logger.info("The job finished with status: " + status);
logger.info("The job finished with status: " + status);
 
if(updater != null) {
 
String message = "Job number " + commandConfig.getCommandId()
 
+ " finished with status " + status +"\n "
 
+ "Check your log/out/error files for more details";
 
updater.setMessage(message);
 
try {
 
updater.postUpdate();
 
} catch (IOException e) {
 
// Just warn since it is not indicative of a job failing
 
logger.warn("Couldn't post update. Check stack trace" , e);
 
}
 
}
return status;
return status;
}
}
@@ -161,7 +179,7 @@ public abstract class Command {
@@ -161,7 +179,7 @@ public abstract class Command {
* This function is intended to clean up any (possible) remaining loose ends
* This function is intended to clean up any (possible) remaining loose ends
* after the job is finished processing.
* after the job is finished processing.
*
*
* @return
* @return CommandStatus - indicating that the configuration completed clean up
*/
*/
protected CommandStatus cleanUp() {
protected CommandStatus cleanUp() {
@@ -182,7 +200,7 @@ public abstract class Command {
@@ -182,7 +200,7 @@ public abstract class Command {
* log/error information.
* log/error information.
*
*
* @return - CommandStatus indicating that configuration completed and job can
* @return - CommandStatus indicating that configuration completed and job can
* start running
* start running
*/
*/
protected CommandStatus setConfiguration() {
protected CommandStatus setConfiguration() {
@@ -201,34 +219,37 @@ public abstract class Command {
@@ -201,34 +219,37 @@ public abstract class Command {
String separator = "/";
String separator = "/";
if (commandConfig.getOS().toLowerCase().contains("win"))
if (commandConfig.getOS().toLowerCase().contains("win"))
separator = "\\";
separator = "\\";
// Check if the working directory exists
// Check if the working directory exists
String workingDir = commandConfig.getWorkingDirectory();
String workingDir = commandConfig.getWorkingDirectory();
 
boolean exists = false, execExists = false;
 
if(workingDir != null) {
if (!workingDir.endsWith(separator))
if (!workingDir.endsWith(separator))
workingDir += separator;
workingDir += separator;
// Check that the directory exists
// Check that the directory exists
// Get the file handler factory
// Get the file handler factory
FileHandlerFactory factory = new FileHandlerFactory();
FileHandlerFactory factory = new FileHandlerFactory();
boolean exists = false, execExists = false;
try {
try {
// Get the handler for this particular connection, whether local or remote
// Get the handler for this particular connection, whether local or remote
FileHandler handler = factory.getFileHandler(connectionConfig);
FileHandler handler = factory.getFileHandler(connectionConfig);
// If the working directory was set, check that it exists. If it wasn't set,
// If the working directory was set, check that it exists. If it wasn't set,
// then the paths should have been explicitly identified
// then the paths should have been explicitly identified
if (workingDir != null)
exists = handler.exists(workingDir);
exists = handler.exists(workingDir);
// Check if the executable exists in the working directory
// Check if the executable exists in the working directory
execExists = handler.exists(workingDir + exec);
execExists = handler.exists(workingDir + exec);
} catch (IOException e) {
} catch (IOException e) {
// If we can't get the file handler, then there was an error in the connection
// If we can't get the file handler, then there was an error in the connection
// configuration
// configuration
logger.error("Unable to connect to filehandler and check file existence. Exiting.", e);
logger.error("Unable to connect to filehandler and check file existence. Exiting.", e);
return CommandStatus.INFOERROR;
return CommandStatus.INFOERROR;
}
}
 
}
// If the working directory doesn't exist, we won't be able to continue the job
// If the working directory doesn't exist, we won't be able to continue the job
// processing unless the full paths were specified. Warn the user
// processing unless the full paths were specified. Warn the user
if (!exists) {
if (!exists) {
@@ -330,7 +351,7 @@ public abstract class Command {
@@ -330,7 +351,7 @@ public abstract class Command {
* This function is a simple helper function to check and make sure that the
* This function is a simple helper function to check and make sure that the
* command status is not set to a flagged error, e.g. failed.
* command status is not set to a flagged error, e.g. failed.
*
*
* @param current_status
* @param current_status to be checked
* @return boolean indicating whether or not status is good to continue (true)
* @return boolean indicating whether or not status is good to continue (true)
* or whether or not job has failed (returns false)
* or whether or not job has failed (returns false)
*/
*/
@@ -340,8 +361,12 @@ public abstract class Command {
@@ -340,8 +361,12 @@ public abstract class Command {
logger.info("The current status is: " + current_status);
logger.info("The current status is: " + current_status);
return true;
return true;
} else {
} else {
logger.error("The job failed with status: " + current_status);
String statusString = "The job failed with status: " + current_status;
logger.error("Check your error logfile for more details! Exiting now!");
String checkString = "Check your error logfile for more details! Exiting now!";
 
 
logger.error(statusString);
 
logger.error(checkString);
 
return false;
return false;
}
}
@@ -371,7 +396,7 @@ public abstract class Command {
@@ -371,7 +396,7 @@ public abstract class Command {
* This function returns to the user the configuration that was used to create a
* This function returns to the user the configuration that was used to create a
* particular command.
* particular command.
*
*
* @return - the particular configuration for this command
* @return - the particular CommandConfiguration for this command
*/
*/
public CommandConfiguration getCommandConfiguration() {
public CommandConfiguration getCommandConfiguration() {
return commandConfig;
return commandConfig;
@@ -380,7 +405,7 @@ public abstract class Command {
@@ -380,7 +405,7 @@ public abstract class Command {
/**
/**
* This function sets the command configuration for a particular command
* This function sets the command configuration for a particular command
*
*
* @param config
* @param commandConfig - CommandConfiguration to be set
*/
*/
public void setCommandConfiguration(CommandConfiguration commandConfig) {
public void setCommandConfiguration(CommandConfiguration commandConfig) {
this.commandConfig = commandConfig;
this.commandConfig = commandConfig;
@@ -400,7 +425,7 @@ public abstract class Command {
@@ -400,7 +425,7 @@ public abstract class Command {
* This function sets the configuration that is to be used to set up a
* This function sets the configuration that is to be used to set up a
* particular connection.
* particular connection.
*
*
* @param connect
* @param connectionConfig - ConnectionConfiguration to be set
*/
*/
public void setConnectionConfiguration(ConnectionConfiguration connectionConfig) {
public void setConnectionConfiguration(ConnectionConfiguration connectionConfig) {
this.connectionConfig = connectionConfig;
this.connectionConfig = connectionConfig;
@@ -427,4 +452,12 @@ public abstract class Command {
@@ -427,4 +452,12 @@ public abstract class Command {
public ConnectionManager getConnectionManager() {
public ConnectionManager getConnectionManager() {
return manager;
return manager;
}
}
 
 
/**
 
* Setter for update handler, see {@link org.eclipse.ice.commands.Command#updater}
 
* @param updater
 
*/
 
public void setUpdateHandler(ICommandUpdateHandler updater) {
 
this.updater = updater;
 
}
}
}
Loading