use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class HPCRemoteCluster method getFileNameFromExtension.
/**
* This method can be used to get the file name of a file giving the extension. It assumes that there will be only
* one file with that extension. In case if there are more than one file one random file name from the matching ones
* will be returned.
*
* @param fileRegex
* @param parentPath
* @param session
* @return
*/
// FIXME Find a better way to find wildcard file names
@Override
public List<String> getFileNameFromExtension(String fileRegex, String parentPath, Session session) throws GFacException {
try {
List<String> fileNames = SSHUtils.listDirectory(parentPath, session);
List<String> matchingNames = new ArrayList<>();
for (String fileName : fileNames) {
String tempFileName = fileName;
// FIXME Find better way to match wildcard file names
String[] splits = fileRegex.split("\\*");
boolean matching = true;
for (String split : splits) {
if (!tempFileName.contains(split)) {
matching = false;
break;
} else {
int idx = tempFileName.indexOf(split);
tempFileName = tempFileName.substring(idx + split.length());
}
}
if (matching) {
matchingNames.add(fileName);
}
}
log.warn("No matching file found for extension: " + fileRegex + " in the " + parentPath + " directory");
return matchingNames;
} catch (Exception e) {
e.printStackTrace();
throw new GFacException("Failed to list directory " + parentPath);
}
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class LSFOutputParser method main.
public static void main(String[] args) {
String test = "Job <2477982> is submitted to queue <short>.";
System.out.println(test.substring(test.indexOf("<") + 1, test.indexOf(">")));
String test1 = "JOBID USER STAT QUEUE FROM_HOST EXEC_HOST JOB_NAME SUBMIT_TIME\n" + "2636607 lg11w RUN long ghpcc06 c11b02 *069656647 Mar 7 00:58\n" + "2636582 lg11w RUN long ghpcc06 c02b01 2134490944 Mar 7 00:48";
Map<String, JobStatus> statusMap = new HashMap<String, JobStatus>();
statusMap.put("2477983,2134490944", new JobStatus(JobState.UNKNOWN));
LSFOutputParser lsfOutputParser = new LSFOutputParser();
try {
lsfOutputParser.parseJobStatuses("cjh", statusMap, test1);
} catch (GFacException e) {
logger.error(e.getMessage(), e);
}
System.out.println(statusMap.get("2477983,2134490944"));
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class ArchiveTask method executeCommand.
private void executeCommand(Session session, CommandInfo commandInfo, CommandOutput commandOutput) throws GFacException {
String command = commandInfo.getCommand();
ChannelExec channelExec = null;
try {
if (!session.isConnected()) {
// session = getOpenSession();
log.error("Error! client session is closed");
throw new JSchException("Error! client session is closed");
}
channelExec = ((ChannelExec) session.openChannel("exec"));
channelExec.setCommand(command);
channelExec.setInputStream(null);
channelExec.setErrStream(commandOutput.getStandardError());
log.info("Executing command {}", commandInfo.getCommand());
channelExec.connect();
commandOutput.onOutput(channelExec);
} catch (JSchException e) {
throw new GFacException("Unable to execute command - ", e);
} finally {
// Only disconnecting the channel, session can be reused
if (channelExec != null) {
commandOutput.exitCode(channelExec.getExitStatus());
channelExec.disconnect();
}
}
}
Aggregations