Search in sources :

Example 71 with GFacException

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);
    }
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) ArrayList(java.util.ArrayList) AiravataException(org.apache.airavata.common.exception.AiravataException) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 72 with GFacException

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"));
}
Also used : JobStatus(org.apache.airavata.model.status.JobStatus) GFacException(org.apache.airavata.gfac.core.GFacException) HashMap(java.util.HashMap)

Example 73 with GFacException

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();
        }
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) GFacException(org.apache.airavata.gfac.core.GFacException) ChannelExec(com.jcraft.jsch.ChannelExec)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)73 IOException (java.io.IOException)24 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)19 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)16 JSchException (com.jcraft.jsch.JSchException)15 RegistryException (org.apache.airavata.registry.cpi.RegistryException)15 AiravataException (org.apache.airavata.common.exception.AiravataException)14 TaskStatus (org.apache.airavata.model.status.TaskStatus)13 URISyntaxException (java.net.URISyntaxException)12 ErrorModel (org.apache.airavata.model.commons.ErrorModel)11 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)10 TException (org.apache.thrift.TException)9 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 DefaultClientConfiguration (eu.unicore.util.httpclient.DefaultClientConfiguration)7 URI (java.net.URI)7 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)7 Session (com.jcraft.jsch.Session)6 InvalidKeyException (java.security.InvalidKeyException)6 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)6 JobModel (org.apache.airavata.model.job.JobModel)6