Search in sources :

Example 1 with ServerInfo

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

the class BESJobSubmissionTask method copyInputFilesToLocal.

private void copyInputFilesToLocal(TaskContext taskContext) throws GFacException {
    ProcessContext pc = taskContext.getParentProcessContext();
    StorageResourceDescription storageResource = pc.getStorageResource();
    if (storageResource != null) {
        hostName = storageResource.getHostName();
    } else {
        throw new GFacException("Storage Resource is null");
    }
    inputPath = pc.getStorageFileSystemRootLocation();
    inputPath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator);
    String remoteFilePath = null, fileName = null, localFilePath = null;
    URI remoteFileURI = null;
    try {
        authenticationInfo = Factory.getStorageSSHKeyAuthentication(pc);
        ServerInfo serverInfo = pc.getStorageResourceServerInfo();
        Session sshSession = Factory.getSSHSession(authenticationInfo, serverInfo);
        List<InputDataObjectType> processInputs = pc.getProcessModel().getProcessInputs();
        for (InputDataObjectType input : processInputs) {
            if (input.getType() == DataType.URI) {
                remoteFileURI = new URI(input.getValue());
                remoteFilePath = remoteFileURI.getPath();
                fileName = remoteFilePath.substring(remoteFilePath.lastIndexOf("/") + 1);
                localFilePath = pc.getInputDir() + File.separator + fileName;
                log.info("SCP remote file :{} -> to local :{}", remoteFilePath, localFilePath);
                SSHUtils.scpFrom(remoteFilePath, localFilePath, sshSession);
                input.setValue("file:/" + localFilePath);
            }
        }
    } catch (IOException | JSchException | SSHApiException | URISyntaxException e) {
        log.error("Error while coping remote file " + remoteFilePath + " to local " + localFilePath, e);
        throw new GFacException("Error while scp input files to local file location", e);
    } catch (CredentialStoreException e) {
        String msg = "Authentication issue, make sure you are passing valid credential token";
        log.error(msg, e);
        throw new GFacException(msg, e);
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) InputDataObjectType(org.apache.airavata.model.application.io.InputDataObjectType) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) URI(java.net.URI) SSHApiException(org.apache.airavata.gfac.core.SSHApiException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) GFacException(org.apache.airavata.gfac.core.GFacException) Session(com.jcraft.jsch.Session)

Example 2 with ServerInfo

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

the class ProcessContext method getComputeResourceServerInfo.

public ServerInfo getComputeResourceServerInfo() throws GFacException {
    if (this.jobSubmissionProtocol == JobSubmissionProtocol.SSH) {
        Optional<JobSubmissionInterface> firstJobSubmissionIface = getComputeResourceDescription().getJobSubmissionInterfaces().stream().filter(iface -> iface.getJobSubmissionProtocol() == JobSubmissionProtocol.SSH).findFirst();
        if (firstJobSubmissionIface.isPresent()) {
            try {
                SSHJobSubmission sshJobSubmission = appCatalog.getComputeResource().getSSHJobSubmission(firstJobSubmissionIface.get().getJobSubmissionInterfaceId());
                String alternateHostName = sshJobSubmission.getAlternativeSSHHostName();
                String hostName = !(alternateHostName == null || alternateHostName.length() == 0) ? alternateHostName : getComputeResourceDescription().getHostName();
                if (sshJobSubmission.getSshPort() > 0) {
                    return new ServerInfo(getComputeResourceLoginUserName(), hostName, getComputeResourceCredentialToken(), sshJobSubmission.getSshPort());
                } else {
                    return new ServerInfo(getComputeResourceLoginUserName(), hostName, getComputeResourceCredentialToken());
                }
            } catch (AppCatalogException e) {
                throw new GFacException("Failed to fetch ssh job submission for interface " + firstJobSubmissionIface.get().getJobSubmissionInterfaceId(), e);
            }
        }
    }
    return new ServerInfo(getComputeResourceLoginUserName(), getComputeResourceDescription().getHostName(), getComputeResourceCredentialToken());
}
Also used : ExperimentCatalog(org.apache.airavata.registry.cpi.ExperimentCatalog) java.util(java.util) DataMovementProtocol(org.apache.airavata.model.data.movement.DataMovementProtocol) JobModel(org.apache.airavata.model.job.JobModel) LoggerFactory(org.slf4j.LoggerFactory) UserComputeResourcePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserComputeResourcePreference) UserResourceProfile(org.apache.airavata.model.appcatalog.userresourceprofile.UserResourceProfile) Publisher(org.apache.airavata.messaging.core.Publisher) TaskModel(org.apache.airavata.model.task.TaskModel) StorageResourceDescription(org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription) UserStoragePreference(org.apache.airavata.model.appcatalog.userresourceprofile.UserStoragePreference) Logger(org.slf4j.Logger) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationInterfaceDescription(org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDescription) ProcessState(org.apache.airavata.model.status.ProcessState) ProcessStatus(org.apache.airavata.model.status.ProcessStatus) RemoteCluster(org.apache.airavata.gfac.core.cluster.RemoteCluster) SSHKeyAuthentication(org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication) StoragePreference(org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference) ComputeResourcePreference(org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference) GatewayResourceProfile(org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile) AppCatalog(org.apache.airavata.registry.cpi.AppCatalog) CuratorFramework(org.apache.curator.framework.CuratorFramework) ApplicationDeploymentDescription(org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription) ComputationalResourceSchedulingModel(org.apache.airavata.model.scheduling.ComputationalResourceSchedulingModel) AiravataUtils(org.apache.airavata.common.utils.AiravataUtils) ProcessModel(org.apache.airavata.model.process.ProcessModel) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) org.apache.airavata.model.appcatalog.computeresource(org.apache.airavata.model.appcatalog.computeresource) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo)

Example 3 with ServerInfo

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

the class GFacEngineImpl method getDataStagingTaskContext.

private TaskContext getDataStagingTaskContext(ProcessContext processContext, OutputDataObjectType processOutput) throws TException, TaskException, GFacException {
    TaskContext taskCtx = new TaskContext();
    taskCtx.setParentProcessContext(processContext);
    // create new task model for this task
    TaskModel taskModel = new TaskModel();
    taskModel.setParentProcessId(processContext.getProcessId());
    taskModel.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
    taskModel.setLastUpdateTime(taskModel.getCreationTime());
    TaskStatus taskStatus = new TaskStatus(TaskState.CREATED);
    taskStatus.setTimeOfStateChange(AiravataUtils.getCurrentTimestamp().getTime());
    taskModel.setTaskStatuses(Arrays.asList(taskStatus));
    taskModel.setTaskType(TaskTypes.DATA_STAGING);
    // create data staging sub task model
    String remoteOutputDir = processContext.getOutputDir();
    remoteOutputDir = remoteOutputDir.endsWith("/") ? remoteOutputDir : remoteOutputDir + "/";
    DataStagingTaskModel submodel = new DataStagingTaskModel();
    ServerInfo serverInfo = processContext.getComputeResourceServerInfo();
    URI source = null;
    try {
        source = new URI(processContext.getDataMovementProtocol().name(), serverInfo.getHost(), serverInfo.getUserName(), serverInfo.getPort(), remoteOutputDir + processOutput.getValue(), null, null);
    } catch (URISyntaxException e) {
        throw new TaskException("Error while constructing source file URI");
    }
    submodel.setSource(source.toString());
    // We don't know destination location at this time, data staging task will set this.
    // because destination is required field we set dummy destination
    submodel.setDestination("dummy://temp/file/location");
    taskModel.setSubTaskModel(ThriftUtils.serializeThriftObject(submodel));
    taskCtx.setTaskModel(taskModel);
    taskCtx.setProcessOutput(processOutput);
    return taskCtx;
}
Also used : TaskContext(org.apache.airavata.gfac.core.context.TaskContext) TaskException(org.apache.airavata.gfac.core.task.TaskException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) URISyntaxException(java.net.URISyntaxException) TaskStatus(org.apache.airavata.model.status.TaskStatus) URI(java.net.URI) EnvironmentSetupTaskModel(org.apache.airavata.model.task.EnvironmentSetupTaskModel) JobSubmissionTaskModel(org.apache.airavata.model.task.JobSubmissionTaskModel) MonitorTaskModel(org.apache.airavata.model.task.MonitorTaskModel) DataStagingTaskModel(org.apache.airavata.model.task.DataStagingTaskModel) TaskModel(org.apache.airavata.model.task.TaskModel)

Example 4 with ServerInfo

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

the class BESJobSubmissionTask method copyOutputFilesToStorage.

private void copyOutputFilesToStorage(TaskContext taskContext, List<OutputDataObjectType> copyOutput) throws GFacException {
    ProcessContext pc = taskContext.getParentProcessContext();
    String remoteFilePath = null, fileName = null, localFilePath = null;
    try {
        authenticationInfo = Factory.getStorageSSHKeyAuthentication(pc);
        ServerInfo serverInfo = pc.getComputeResourceServerInfo();
        Session sshSession = Factory.getSSHSession(authenticationInfo, serverInfo);
        for (OutputDataObjectType output : copyOutput) {
            switch(output.getType()) {
                case STDERR:
                case STDOUT:
                case STRING:
                case URI:
                    localFilePath = output.getValue();
                    if (localFilePath.contains("://")) {
                        localFilePath = localFilePath.substring(localFilePath.indexOf("://") + 2, localFilePath.length());
                    }
                    fileName = localFilePath.substring(localFilePath.lastIndexOf("/") + 1);
                    URI destinationURI = TaskUtils.getDestinationURI(taskContext, hostName, inputPath, fileName);
                    remoteFilePath = destinationURI.getPath();
                    log.info("SCP local file :{} -> from remote :{}", localFilePath, remoteFilePath);
                    SSHUtils.scpTo(localFilePath, remoteFilePath, sshSession);
                    output.setValue(destinationURI.toString());
                    break;
                default:
                    break;
            }
        }
    } catch (IOException | JSchException | SSHApiException | URISyntaxException | CredentialStoreException e) {
        log.error("Error while coping local file " + localFilePath + " to remote " + remoteFilePath, e);
        throw new GFacException("Error while scp output files to remote storage file location", e);
    }
}
Also used : JSchException(com.jcraft.jsch.JSchException) ServerInfo(org.apache.airavata.gfac.core.cluster.ServerInfo) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) CredentialStoreException(org.apache.airavata.credential.store.store.CredentialStoreException) URI(java.net.URI) SSHApiException(org.apache.airavata.gfac.core.SSHApiException) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext) OutputDataObjectType(org.apache.airavata.model.application.io.OutputDataObjectType) GFacException(org.apache.airavata.gfac.core.GFacException) Session(com.jcraft.jsch.Session)

Aggregations

ServerInfo (org.apache.airavata.gfac.core.cluster.ServerInfo)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 GFacException (org.apache.airavata.gfac.core.GFacException)3 JSchException (com.jcraft.jsch.JSchException)2 Session (com.jcraft.jsch.Session)2 IOException (java.io.IOException)2 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)2 SSHApiException (org.apache.airavata.gfac.core.SSHApiException)2 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)2 StorageResourceDescription (org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription)2 TaskModel (org.apache.airavata.model.task.TaskModel)2 java.util (java.util)1 AiravataUtils (org.apache.airavata.common.utils.AiravataUtils)1 SSHKeyAuthentication (org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication)1 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)1 TaskContext (org.apache.airavata.gfac.core.context.TaskContext)1 TaskException (org.apache.airavata.gfac.core.task.TaskException)1 Publisher (org.apache.airavata.messaging.core.Publisher)1 ApplicationDeploymentDescription (org.apache.airavata.model.appcatalog.appdeployment.ApplicationDeploymentDescription)1