Search in sources :

Example 1 with RawCommandInfo

use of org.apache.airavata.gfac.core.cluster.RawCommandInfo in project airavata by apache.

the class SCPDataStageTask method localDataCopy.

private void localDataCopy(TaskContext taskContext, URI sourceURI, URI destinationURI) throws GFacException {
    StringBuilder sb = new StringBuilder("rsync -cr ");
    sb.append(sourceURI.getPath()).append(" ").append(destinationURI.getPath());
    CommandInfo commandInfo = new RawCommandInfo(sb.toString());
    taskContext.getParentProcessContext().getDataMovementRemoteCluster().execute(commandInfo);
}
Also used : CommandInfo(org.apache.airavata.gfac.core.cluster.CommandInfo) RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo) RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo)

Example 2 with RawCommandInfo

use of org.apache.airavata.gfac.core.cluster.RawCommandInfo in project airavata by apache.

the class HPCRemoteCluster method getJobStatuses.

@Override
public void getJobStatuses(String userName, Map<String, JobStatus> jobStatusMap) throws GFacException {
    RawCommandInfo userBasedMonitorCommand = jobManagerConfiguration.getUserBasedMonitorCommand(userName);
    StandardOutReader reader = new StandardOutReader();
    executeCommand(userBasedMonitorCommand, reader);
    throwExceptionOnError(reader, userBasedMonitorCommand);
    outputParser.parseJobStatuses(userName, jobStatusMap, reader.getStdOutputString());
}
Also used : RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo)

Example 3 with RawCommandInfo

use of org.apache.airavata.gfac.core.cluster.RawCommandInfo in project airavata by apache.

the class HPCRemoteCluster method submitBatchJob.

@Override
public JobSubmissionOutput submitBatchJob(String jobScriptFilePath, String workingDirectory) throws GFacException {
    JobSubmissionOutput jsoutput = new JobSubmissionOutput();
    // scp script file to working directory
    copyTo(jobScriptFilePath, workingDirectory);
    RawCommandInfo submitCommand = jobManagerConfiguration.getSubmitCommand(workingDirectory, jobScriptFilePath);
    submitCommand.setRawCommand("cd " + workingDirectory + "; " + submitCommand.getRawCommand());
    StandardOutReader reader = new StandardOutReader();
    executeCommand(submitCommand, reader);
    // throwExceptionOnError(reader, submitCommand);
    jsoutput.setJobId(outputParser.parseJobSubmission(reader.getStdOutputString()));
    if (jsoutput.getJobId() == null) {
        if (outputParser.isJobSubmissionFailed(reader.getStdOutputString())) {
            jsoutput.setJobSubmissionFailed(true);
            jsoutput.setFailureReason("stdout : " + reader.getStdOutputString() + "\n stderr : " + reader.getStdErrorString());
        }
    }
    jsoutput.setExitCode(reader.getExitCode());
    if (jsoutput.getExitCode() != 0) {
        jsoutput.setJobSubmissionFailed(true);
        jsoutput.setFailureReason("stdout : " + reader.getStdOutputString() + "\n stderr : " + reader.getStdErrorString());
    }
    jsoutput.setStdOut(reader.getStdOutputString());
    jsoutput.setStdErr(reader.getStdErrorString());
    return jsoutput;
}
Also used : JobSubmissionOutput(org.apache.airavata.gfac.core.cluster.JobSubmissionOutput) RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo)

Example 4 with RawCommandInfo

use of org.apache.airavata.gfac.core.cluster.RawCommandInfo in project airavata by apache.

the class HPCRemoteCluster method getJobStatus.

@Override
public JobStatus getJobStatus(String jobId) throws GFacException {
    RawCommandInfo monitorCommand = jobManagerConfiguration.getMonitorCommand(jobId);
    StandardOutReader reader = new StandardOutReader();
    executeCommand(monitorCommand, reader);
    throwExceptionOnError(reader, monitorCommand);
    return outputParser.parseJobStatus(jobId, reader.getStdOutputString());
}
Also used : RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo)

Example 5 with RawCommandInfo

use of org.apache.airavata.gfac.core.cluster.RawCommandInfo in project airavata by apache.

the class ArchiveTask method execute.

@Override
public TaskStatus execute(TaskContext taskContext) {
    // implement archive logic with jscp
    TaskStatus status = new TaskStatus(TaskState.EXECUTING);
    ProcessContext processContext = taskContext.getParentProcessContext();
    RemoteCluster remoteCluster = processContext.getJobSubmissionRemoteCluster();
    AuthenticationInfo authenticationInfo = null;
    DataStagingTaskModel subTaskModel = null;
    try {
        subTaskModel = (DataStagingTaskModel) ThriftUtils.getSubTaskModel(taskContext.getTaskModel());
    } catch (TException e) {
        String msg = "Error! Deserialization issue with SubTask Model";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
        return status;
    }
    try {
        StorageResourceDescription storageResource = taskContext.getParentProcessContext().getStorageResource();
        if (storageResource != null) {
            hostName = storageResource.getHostName();
        } else {
            throw new GFacException("Storage Resource is null");
        }
        userName = processContext.getStorageResourceLoginUserName();
        inputPath = processContext.getStorageFileSystemRootLocation();
        inputPath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator);
        status = new TaskStatus(TaskState.COMPLETED);
        Session srcSession = Factory.getSSHSession(Factory.getComputerResourceSSHKeyAuthentication(processContext), processContext.getComputeResourceServerInfo());
        Session destSession = Factory.getSSHSession(Factory.getStorageSSHKeyAuthentication(processContext), processContext.getStorageResourceServerInfo());
        URI sourceURI = new URI(subTaskModel.getSource());
        URI destinationURI = null;
        String workingDirName = null, path = null;
        if (sourceURI.getPath().endsWith("/")) {
            path = sourceURI.getPath().substring(0, sourceURI.getPath().length() - 1);
        } else {
            path = sourceURI.getPath();
        }
        workingDirName = path.substring(path.lastIndexOf(File.separator) + 1, path.length());
        // tar working dir
        // cd /Users/syodage/Desktop/temp/.. && tar -cvf path/workingDir.tar temp
        String archiveTar = "archive.tar";
        String resourceAbsTarFilePath = path + "/" + archiveTar;
        CommandInfo commandInfo = new RawCommandInfo("cd " + path + " && tar -cvf " + resourceAbsTarFilePath + " ./* ");
        // move tar to storage resource
        remoteCluster.execute(commandInfo);
        destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, archiveTar);
        remoteCluster.scpThirdParty(resourceAbsTarFilePath, srcSession, destinationURI.getPath(), destSession, RemoteCluster.DIRECTION.FROM, true);
        // delete tar in remote computer resource
        commandInfo = new RawCommandInfo("rm " + resourceAbsTarFilePath);
        remoteCluster.execute(commandInfo);
        // untar file and delete tar in storage resource
        String destPath = destinationURI.getPath();
        String destParent = destPath.substring(0, destPath.lastIndexOf("/"));
        String storageArchiveDir = "ARCHIVE";
        commandInfo = new RawCommandInfo("cd " + destParent + " && mkdir " + storageArchiveDir + " && tar -xvf " + archiveTar + " -C " + storageArchiveDir + " && rm " + archiveTar + " && chmod 755 -R " + storageArchiveDir + "/*");
        executeCommand(destSession, commandInfo, new StandardOutReader());
    } catch (CredentialStoreException e) {
        String msg = "Storage authentication issue, make sure you are passing valid credential token";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    } catch (URISyntaxException | GFacException e) {
        String msg = "Error! Archive task failed";
        log.error(msg, e);
        status.setState(TaskState.FAILED);
        status.setReason(msg);
        status.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
        ErrorModel errorModel = new ErrorModel();
        errorModel.setActualErrorMessage(e.getMessage());
        errorModel.setUserFriendlyMessage(msg);
        taskContext.getTaskModel().setTaskErrors(Arrays.asList(errorModel));
    }
    return status;
}
Also used : TException(org.apache.thrift.TException) RemoteCluster(org.apache.airavata.gfac.core.cluster.RemoteCluster) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) URISyntaxException(java.net.URISyntaxException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URI(java.net.URI) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) AuthenticationInfo(org.apache.airavata.gfac.core.authentication.AuthenticationInfo) CommandInfo(org.apache.airavata.gfac.core.cluster.CommandInfo) RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo) StandardOutReader(org.apache.airavata.gfac.impl.StandardOutReader) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) GFacException(org.apache.airavata.gfac.core.GFacException) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) ErrorModel(org.apache.airavata.model.commons.ErrorModel) RawCommandInfo(org.apache.airavata.gfac.core.cluster.RawCommandInfo) Session(com.jcraft.jsch.Session)

Aggregations

RawCommandInfo (org.apache.airavata.gfac.core.cluster.RawCommandInfo)9 CommandInfo (org.apache.airavata.gfac.core.cluster.CommandInfo)3 JobSubmissionOutput (org.apache.airavata.gfac.core.cluster.JobSubmissionOutput)2 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)2 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)2 ErrorModel (org.apache.airavata.model.commons.ErrorModel)2 Session (com.jcraft.jsch.Session)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)1 GFacException (org.apache.airavata.gfac.core.GFacException)1 AuthenticationInfo (org.apache.airavata.gfac.core.authentication.AuthenticationInfo)1 StandardOutReader (org.apache.airavata.gfac.impl.StandardOutReader)1 ComputeResourceDescription (org.apache.airavata.model.appcatalog.computeresource.ComputeResourceDescription)1 ResourceJobManager (org.apache.airavata.model.appcatalog.computeresource.ResourceJobManager)1 StorageResourceDescription (org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription)1