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);
}
}
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());
}
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;
}
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);
}
}
Aggregations