Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #410 from osbornjd/jay/MarkIII
Browse files Browse the repository at this point in the history
FileHandler Changed to Using Accessors
Signed-off-by: Jay Jay Billings <billingsjj@ornl.gov>
  • Loading branch information
Jay Jay Billings committed Sep 9, 2019
2 parents 8580529 + d0b65c6 commit 5d74654
Show file tree
Hide file tree
Showing 20 changed files with 658 additions and 272 deletions.
Expand Up @@ -168,8 +168,7 @@ protected CommandStatus setConfiguration() {
// Check the info and return failure if something was not set
if (commandConfig.getExecutable() == null || commandConfig.getInputFile() == null
|| commandConfig.getOutFileName() == null || commandConfig.getErrFileName() == null
|| commandConfig.getNumProcs() == null || commandConfig.getOS() == null
|| commandConfig.getWorkingDirectory() == null)
|| commandConfig.getNumProcs() == null || commandConfig.getWorkingDirectory() == null)
return CommandStatus.INFOERROR;

// Set the command to actually run and execute
Expand Down Expand Up @@ -435,6 +434,8 @@ protected boolean logOutput(final InputStream output, final InputStream errors)
// Write to the stdOut file
while ((nextLine = stdOutReader.readLine()) != null) {
commandConfig.getStdOut().write(nextLine);

commandConfig.addToStdOutputString(nextLine);
// MUST put a new line for this type of writer. "\r\n" works on
// Windows and Unix-based systems.
commandConfig.getStdOut().write("\r\n");
Expand Down
Expand Up @@ -81,17 +81,16 @@ public class CommandConfiguration {
*/
private String installDirectory;

/**
* The operating system on which the job will run
*/
private String os;

/**
* The working directory for the job to be executed in, and thus where e.g. the
* output files will be located
*/
private String workingDirectory;

/**
* The operating system that the command will be run on. Set as a default to the local OS
*/
private String os;
/**
* The hostname that the command will be executed on. This is the same as the
* hostname in {@link org.eclipse.ice.commands.Connection} and is just used for
Expand All @@ -104,6 +103,13 @@ public class CommandConfiguration {
*/
private BufferedWriter stdOut = null, stdErr = null;

/**
* This is a string that contains all of the output of the job. This is the same
* text that gets written out to
* {@link org.eclipse.ice.commands.CommandConfiguration#stdOut}
*/
String stdOutput = "";

/**
* A flag to mark whether or not the input file name should be appended to the
* executable command. Marked as true by default so that the user (by default)
Expand All @@ -129,6 +135,7 @@ public class CommandConfiguration {
public CommandConfiguration() {
// Assume some default variables
commandId = -999;
os = System.getProperty("os.name");
}

/**
Expand Down Expand Up @@ -210,7 +217,7 @@ public String createOutputHeader(String logName) {
header += new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + "\n";

// Add the point of origin
header += "# Launch host: " + localHostname + "\n";
header += "# Launch host: " + hostname + "\n";

// Add the target machine
header += "# Target host: " + hostname + "\n";
Expand Down Expand Up @@ -446,24 +453,24 @@ public String getInstallDirectory() {
}

/**
* Setter for operating system, see
* Getter for os, see
* {@link org.eclipse.ice.commands.CommandConfiguration#os}
* Note that this is set to the default of the local OS
*
* @param operatingSys
* @return os
*/
public void setOS(String operatingSys) {
os = operatingSys;
return;
public String getOS() {
return os;
}

/**
* Getter for operating system, see
* Setter for operating system, see
* {@link org.eclipse.ice.commands.CommandConfiguration#os}
*
* @return os
* @param OS
*/
public String getOS() {
return os;
public void setOS(String OS) {
os = OS;
}

/**
Expand Down Expand Up @@ -573,6 +580,36 @@ public BufferedWriter getStdOut() {
return stdOut;
}

/**
* Setter for stdOutput, see
* {@link org.eclipse.ice.commands.CommandConfiguration#stdOutput}
*
* @return stdOutput
*/
public void setStdOutputString(String out) {
stdOutput = out;
}

/**
* This function adds the String string to the String
* {@link org.eclipse.ice.commands.CommandConfiguration#stdOutput}
*
* @param string
*/
public void addToStdOutputString(String string) {
stdOutput += " " + string;
}

/**
* Getter for stdOutput, see
* {@link org.eclipse.ice.commands.CommandConfiguration#stdOutput}
*
* @return stdOutput
*/
public String getStdOutputString() {
return stdOutput;
}

/**
* Getter for splitCommand, see
* {@link org.eclipse.ice.commands.CommandConfiguration#splitCommand} No setter
Expand Down
Expand Up @@ -37,21 +37,11 @@ public abstract class FileHandler implements IFileHandler {
protected static final Logger logger = LoggerFactory.getLogger(FileHandler.class);

/**
* The command member variable that will actually execute the move or copy that
* was requested by the user
* The command member variable that will actually execute the transfer that was
* requested by the user
*/
Command command;

/**
* The ConnectionConfiguration associated with the source file
*/
ConnectionConfiguration sourceConfiguration;

/**
* The ConnectionConfiguration associated with the destination file
*/
ConnectionConfiguration destinationConfiguration;

/**
* A status member variable that indicates the status of the file transfer. See
* also {@link org.eclipse.ice.commands.CommandStatus}
Expand All @@ -72,7 +62,20 @@ public FileHandler() {
* was successful
* @throws IOException
*/
public abstract CommandStatus move(final String source, final String destination) throws IOException;
public CommandStatus move(final String source, final String destination) throws IOException {

// Check the file existence. If they don't exist, an exception is thrown
checkExistence(source, destination);

// Set the commands to have the appropriate properties
configureMoveCommand(source, destination);

// Execute and process the file transfer
transferStatus = executeTransfer(destination);

// Return whether or not it succeeded
return transferStatus;
}

/**
* This method is responsible for copying a file from a source to a destination
Expand All @@ -82,8 +85,41 @@ public FileHandler() {
* was successful
* @throws IOException
*/
public abstract CommandStatus copy(final String source, final String destination) throws IOException;
public CommandStatus copy(final String source, final String destination) throws IOException {
// Check the file existence. If one or both don't exist, an exception is thrown
checkExistence(source, destination);

// Set the commands to have the appropriate properties
configureCopyCommand(source, destination);

// Execute and process the file transfer
transferStatus = executeTransfer(destination);

// Return whether or not it succeeded
return transferStatus;
}

/**
* This function sets the command member variables to have the source and
* destination strings. It is delegated to the subclasses so that the commands
* can be cast appropriately
*
* @param source
* @param destination
*/
protected abstract void configureMoveCommand(final String source, final String destination);

/**
* This function sets the command member variables to have the source and
* destination strings. It is delegated to the subclasses so that the commands
* can be cast appropriately
*
* @param source
* @param destination
*/
protected abstract void configureCopyCommand(final String source, final String destination);


/**
* This method is responsible for determining whether or not a file or directory
* already exists for a given path.
Expand All @@ -109,15 +145,16 @@ public FileHandler() {
public abstract void checkExistence(final String source, final String destination) throws IOException;

/**
* This function gets and returns the private member variable command of type
* Command
* This function gets and returns the private member variable command of
* type Command
*
* @return Command - the command associated with this FileHandler
*/
public Command getCommand() {
return command;
}


/**
* This operation creates all the directories that are parents of the
* destination.
Expand All @@ -144,6 +181,14 @@ protected boolean createDirectories(String dest) throws IOException {
return exists;
}

/**
* This function actually executes the file transfer and then checks that it was
* completed correctly
*
* @param destination - destination for the file to go to
* @return - CommandStatus indicating whether or not the transfer completed
* successfully
*/
protected CommandStatus executeTransfer(final String destination) {
// Execute the file transfer
transferStatus = command.execute();
Expand All @@ -163,13 +208,14 @@ protected CommandStatus executeTransfer(final String destination) {
}

/**
* This function returns the current status of the copy or move, as it is given
* by the member variable {@link org.eclipse.ice.commands.FileHandler#command}
* This function returns the current status of the transfer, as it is given by the
* member variable {@link org.eclipse.ice.commands.FileHandler#copyCommand}
*
* @return - CommandStatus indicating the status of the file transfer
*/
public CommandStatus getStatus() {
return command.getStatus();
}


}
Expand Up @@ -44,19 +44,6 @@ public class LocalCopyFileCommand extends LocalCommand {
public LocalCopyFileCommand() {
}

/**
* Constructor which sets the two paths, source and destination, to those given
* by the arguments of the constructor. See
* {@link org.eclipse.ice.tests.commands.CopyFileCommand} for member variable
* descriptions.
*
* @param src
* @param dest
*/
public LocalCopyFileCommand(final String src, final String dest) {
source = Paths.get(src);
destination = Paths.get(dest);
}

/**
* This function actually executes the copy file command. It checks that the
Expand Down Expand Up @@ -103,6 +90,18 @@ public CommandStatus cancel() {
return CommandStatus.CANCELED;
}


/**
* This function sets the Paths for source and destination to the given strings
* @param src - string corresponding to the source file
* @param dest - string corresponding to the destination file
*/
public void setConfiguration(String src, String dest) {
source = Paths.get(src);
destination = Paths.get(dest);
return;
}

/**
* A function that returns the source path in string form
*
Expand All @@ -111,7 +110,8 @@ public CommandStatus cancel() {
public String getSource() {
return source.toString();
}



/**
* A function that returns the destination path in string form
*
Expand All @@ -120,4 +120,5 @@ public String getSource() {
public String getDestination() {
return destination.toString();
}

}
Expand Up @@ -29,47 +29,30 @@ public class LocalFileHandler extends FileHandler {
* Default constructor
*/
public LocalFileHandler() {

}

/**
* See {@link org.eclipse.ice.commands.FileHandler#move()}
* See {@link org.eclipse.ice.commands.FileHandler#setConfiguration(String, String)}
*/
@Override
public CommandStatus move(final String source, final String destination) throws IOException {

// Check the file existence. If they don't exist, an exception is thrown
checkExistence(source, destination);

// Make the command
command = new LocalMoveFileCommand(source, destination);

// Execute and process the file transfer
transferStatus = executeTransfer(destination);

// Return whether or not it succeeded
return transferStatus;
protected void configureMoveCommand(final String source, final String destination) {
command = new LocalMoveFileCommand();
// Cast the Command as a LocalMoveFileCommand to set the source and destination paths
((LocalMoveFileCommand) command).setConfiguration(source, destination);
}

/**
* See {@link org.eclipse.ice.commands.FileHandler#copy()}
* See {@link org.eclipse.ice.commands.FileHandler#setConfiguration(String, String)}
*/
@Override
public CommandStatus copy(final String source, final String destination) throws IOException {
// Check the file existence. If one or both don't exist, an exception is thrown
checkExistence(source, destination);

// Make the command
command = new LocalCopyFileCommand(source, destination);

// Execute and process the file transfer
transferStatus = executeTransfer(destination);

// Return whether or not it succeeded
return transferStatus;
protected void configureCopyCommand(final String source, final String destination) {
command = new LocalCopyFileCommand();
// Cast the Command as a LocalCopyFileCommand to set the source and destination paths
((LocalCopyFileCommand) command).setConfiguration(source, destination);

}


/**
* See {@link org.eclipse.ice.commands.FileHandler#exists(String)}
*/
Expand Down

0 comments on commit 5d74654

Please sign in to comment.