-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BXC-4689 - Source File Processing Command (#111)
* Add command for processing source files, and configuration for boxctron jobs * Separate ssh host for transfer and running scripts * Change script path to script directory path so it can be used for multiple jobs, and have job specify the specific filename * Change user and key to being options exclusively rather than coming from config. Setup a default email address * Throw error if command fails based on exit status. Add logging and cleanup * Add umask for directory creation * Add environment to config for job. Extend timeout for starting job and handling of responses. Add some logging to help track what's happening * Update test ssh server to respond to sbatch commands, to get IT test working
- Loading branch information
Showing
11 changed files
with
421 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/main/java/edu/unc/lib/boxc/migration/cdm/ProcessSourceFilesCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package edu.unc.lib.boxc.migration.cdm; | ||
|
||
import edu.unc.lib.boxc.migration.cdm.exceptions.MigrationException; | ||
import edu.unc.lib.boxc.migration.cdm.jobs.VelocicroptorRemoteJob; | ||
import edu.unc.lib.boxc.migration.cdm.model.BxcEnvironment; | ||
import edu.unc.lib.boxc.migration.cdm.model.MigrationProject; | ||
import edu.unc.lib.boxc.migration.cdm.options.ProcessSourceFilesOptions; | ||
import edu.unc.lib.boxc.migration.cdm.services.CdmIndexService; | ||
import edu.unc.lib.boxc.migration.cdm.services.MigrationProjectFactory; | ||
import edu.unc.lib.boxc.migration.cdm.services.SourceFileService; | ||
import edu.unc.lib.boxc.migration.cdm.services.SourceFilesToRemoteService; | ||
import edu.unc.lib.boxc.migration.cdm.util.SshClientService; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.slf4j.Logger; | ||
import picocli.CommandLine; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.Callable; | ||
|
||
import static edu.unc.lib.boxc.migration.cdm.util.CLIConstants.outputLogger; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
/** | ||
* @author bbpennel | ||
*/ | ||
@CommandLine.Command(name = "process_source_files", | ||
description = { | ||
"Perform a processing job on the source files mapped in this project."}) | ||
public class ProcessSourceFilesCommand implements Callable<Integer> { | ||
private static final Logger log = getLogger(ProcessSourceFilesCommand.class); | ||
private static final String DEFAULT_EMAIL_DOMAIN = "@ad.unc.edu"; | ||
|
||
@CommandLine.ParentCommand | ||
private CLIMain parentCommand; | ||
private VelocicroptorRemoteJob velocicroptorRemoteJob; | ||
|
||
private MigrationProject project; | ||
private BxcEnvironment boxcEnv; | ||
|
||
@CommandLine.Mixin | ||
private ProcessSourceFilesOptions options; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
long start = System.nanoTime(); | ||
try { | ||
validateActionName(options.getActionName()); | ||
loadProjectEnvironment(); | ||
setDefaultOptions(); | ||
initialize(); | ||
velocicroptorRemoteJob.run(options); | ||
outputLogger.info("Completed {} job to process source files for {} in {}s", | ||
options.getActionName(), project.getProjectName(), (System.nanoTime() - start) / 1e9); | ||
return 0; | ||
} catch (MigrationException | IllegalArgumentException e) { | ||
outputLogger.info("Source file processing command failed: {}", e.getMessage()); | ||
log.warn("Source file processing command failed", e); | ||
return 1; | ||
} catch (Exception e) { | ||
log.error("Source file processing command failed", e); | ||
outputLogger.info("Source file processing command failed: {}", e.getMessage(), e); | ||
return 1; | ||
} | ||
} | ||
|
||
private void validateActionName(String actionName) { | ||
if (!actionName.equals("velocicroptor")) { | ||
throw new IllegalArgumentException("Invalid action name provided: " + actionName); | ||
} | ||
} | ||
|
||
private void setDefaultOptions() { | ||
if (options.getEmailAddress() == null) { | ||
options.setEmailAddress(options.getUsername() + DEFAULT_EMAIL_DOMAIN); | ||
} | ||
} | ||
|
||
private void loadProjectEnvironment() throws IOException { | ||
Path currentPath = parentCommand.getWorkingDirectory(); | ||
project = MigrationProjectFactory.loadMigrationProject(currentPath); | ||
var config = parentCommand.getChompbConfig(); | ||
boxcEnv = config.getBxcEnvironments().get(project.getProjectProperties().getBxcEnvironmentId()); | ||
} | ||
|
||
private void initialize() throws IOException { | ||
// Separate service for executing scripts on the remote server | ||
var sshClientScriptService = new SshClientService(); | ||
sshClientScriptService.setSshHost(boxcEnv.getBoxctronScriptHost()); | ||
sshClientScriptService.setSshPort(boxcEnv.getBoxctronPort()); | ||
sshClientScriptService.setSshKeyPath(options.getSshKeyPath()); | ||
sshClientScriptService.setSshUsername(options.getUsername()); | ||
sshClientScriptService.initialize(); | ||
// Separate service for transferring files to the remote server | ||
var sshClientTransferService = new SshClientService(); | ||
sshClientTransferService.setSshHost(boxcEnv.getBoxctronTransferHost()); | ||
sshClientTransferService.setSshPort(boxcEnv.getBoxctronPort()); | ||
sshClientTransferService.setSshKeyPath(options.getSshKeyPath()); | ||
sshClientTransferService.setSshUsername(options.getUsername()); | ||
sshClientTransferService.initialize(); | ||
var cdmIndexService = new CdmIndexService(); | ||
cdmIndexService.setProject(project); | ||
var sourceFileService = new SourceFileService(); | ||
sourceFileService.setProject(project); | ||
sourceFileService.setIndexService(cdmIndexService); | ||
var sourceFilesToRemoteService = new SourceFilesToRemoteService(); | ||
sourceFilesToRemoteService.setSourceFileService(sourceFileService); | ||
sourceFilesToRemoteService.setSshClientService(sshClientTransferService); | ||
velocicroptorRemoteJob = new VelocicroptorRemoteJob(); | ||
velocicroptorRemoteJob.setProject(project); | ||
velocicroptorRemoteJob.setSshClientService(sshClientScriptService); | ||
velocicroptorRemoteJob.setOutputServer(boxcEnv.getBoxctronOutputServer()); | ||
velocicroptorRemoteJob.setOutputPath(boxcEnv.getBoxctronOutputBasePath()); | ||
velocicroptorRemoteJob.setRemoteProjectsPath(boxcEnv.getBoxctronRemoteProjectsPath()); | ||
velocicroptorRemoteJob.setAdminEmail(boxcEnv.getBoxctronAdminEmail()); | ||
velocicroptorRemoteJob.setRemoteJobScriptsPath(boxcEnv.getBoxctronRemoteJobScriptsPath()); | ||
velocicroptorRemoteJob.setSourceFilesToRemoteService(sourceFilesToRemoteService); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.