Skip to content
Snippets Groups Projects
Commit 8396c156 authored by Unknown's avatar Unknown Committed by Jan Kožusznik
Browse files

methods for uploading config file

parent 00d3b6d0
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,6 @@ package cz.it4i.fiji.haas; ...@@ -3,8 +3,6 @@ package cz.it4i.fiji.haas;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.time.Instant; import java.time.Instant;
import java.util.Collections; import java.util.Collections;
...@@ -17,33 +15,38 @@ public class BenchmarkJobManager { ...@@ -17,33 +15,38 @@ public class BenchmarkJobManager {
private JobManager jobManager; private JobManager jobManager;
private Progress progress; private Progress progress;
private Path workDirectory; private Path workDirectory;
private static final String CONFIG_FOR_MODIFICATION = "not-set-config.yaml"; private static final String CONFIG_FOR_MODIFICATION = "not-set-config.yaml";
private static final String CONFIG_MODIFIED = "config.yaml"; private static final String CONFIG_MODIFIED = "config.yaml";
public BenchmarkJobManager(Path workDirectory, Progress progress) throws IOException { public BenchmarkJobManager(Path workDirectory, Progress progress) throws IOException {
this.workDirectory = workDirectory; this.workDirectory = workDirectory;
jobManager = new JobManager(workDirectory, TestingConstants.getSettings(3, 6)); jobManager = new JobManager(workDirectory, TestingConstants.getSettings(3, 6));
this.progress = progress; this.progress = progress;
} }
public JobInfo startJob() throws IOException { public JobInfo startJob() throws IOException {
JobInfo jobInfo = jobManager.startJob( Collections.emptyList(), null); JobInfo jobInfo = jobManager.startJob(Collections.emptyList(), null);
jobInfo.waitForStart(); jobInfo.waitForStart();
if(jobInfo.getState() != JobState.Running) { if (jobInfo.getState() != JobState.Running) {
throw new IllegalStateException("start of job: " + jobInfo + " failed"); throw new IllegalStateException("start of job: " + jobInfo + " failed");
} }
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
jobInfo.downloadFileData(CONFIG_FOR_MODIFICATION,os); jobInfo.downloadFileData(CONFIG_FOR_MODIFICATION, os);
byte[]data = updateConfigFile(os.toByteArray()); byte[] data = updateConfigFile(os.toByteArray());
jobInfo.uploadFile (new ByteArrayInputStream(data),CONFIG_MODIFIED, data.length ,Instant.now().getEpochSecond()); jobInfo.uploadFile(new ByteArrayInputStream(data), CONFIG_MODIFIED, data.length,
Instant.now().getEpochSecond());
return jobInfo; return jobInfo;
} }
public JobState getState(long jobId) {
return jobManager.getState(jobId);
}
private byte[] updateConfigFile(byte[] data) throws IOException { private byte[] updateConfigFile(byte[] data) throws IOException {
return data; return data;
} }
} }
...@@ -134,9 +134,12 @@ public class Job { ...@@ -134,9 +134,12 @@ public class Job {
} }
public void downloadFileData(String fileName, OutputStream bos) { public void downloadFileData(String fileName, OutputStream bos) {
haasClientSupplier.get().downloadFileData(jobId,fileName, bos); haasClientSupplier.get().downloadFileData(jobId, fileName, bos);
}
public void uploadFileData(InputStream inputStream, String fileName, int length, long lastModification) {
haasClientSupplier.get().uploadFileData(jobId, inputStream, fileName, length, lastModification);
} }
public JobState getState() { public JobState getState() {
return state; return state;
...@@ -223,6 +226,4 @@ public class Job { ...@@ -223,6 +226,4 @@ public class Job {
} }
} }
package cz.it4i.fiji.haas; package cz.it4i.fiji.haas;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
...@@ -145,10 +145,10 @@ public class JobManager { ...@@ -145,10 +145,10 @@ public class JobManager {
job.downloadFileData(fileName, bos); job.downloadFileData(fileName, bos);
} }
public void uploadFile(ByteArrayInputStream byteArrayInputStream, String configModified, int length, public void uploadFile(InputStream inputStream, String name, int length,
long epochSecond) { long lastModification) {
//TODO job.uploadFileData(inputStream, name, length, lastModification);
} }
private String getStringFromTimeSafely(Calendar time) { private String getStringFromTimeSafely(Calendar time) {
......
package cz.it4i.fiji.haas_java_client; package cz.it4i.fiji.haas_java_client;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -284,6 +285,20 @@ public class HaaSClient { ...@@ -284,6 +285,20 @@ public class HaaSClient {
FileTransferMethodExt ft = getFileTransfer().getFileTransferMethod(jobId, getSessionID()); FileTransferMethodExt ft = getFileTransfer().getFileTransferMethod(jobId, getSessionID());
try (ScpClient scpClient = getScpClient(ft)) { try (ScpClient scpClient = getScpClient(ft)) {
scpClient.download(fileName, os, new TransferFileProgressForHaaSClient(0, dummyNotifier)); scpClient.download(fileName, os, new TransferFileProgressForHaaSClient(0, dummyNotifier));
getFileTransfer().endFileTransfer(jobId, ft, getSessionID());
}
} catch (IOException | JSchException | ServiceException e) {
throw new HaaSClientException(e);
}
}
public void uploadFileData(Long jobId, InputStream inputStream, String fileName, long length,
long lastModification) {
try {
FileTransferMethodExt ft = getFileTransfer().getFileTransferMethod(jobId, getSessionID());
try (ScpClient scpClient = getScpClient(ft)) {
scpClient.upload(inputStream,fileName,length,lastModification, new TransferFileProgressForHaaSClient(0, dummyNotifier));
getFileTransfer().endFileTransfer(jobId, ft, getSessionID());
} }
} catch (IOException | JSchException | ServiceException e) { } catch (IOException | JSchException | ServiceException e) {
throw new HaaSClientException(e); throw new HaaSClientException(e);
...@@ -448,4 +463,6 @@ public class HaaSClient { ...@@ -448,4 +463,6 @@ public class HaaSClient {
} }
} }
} }
...@@ -66,7 +66,7 @@ public class ScpClient implements Closeable { ...@@ -66,7 +66,7 @@ public class ScpClient implements Closeable {
} }
public boolean download(String lfile, Path rfile, TransferFileProgress progress) throws JSchException, IOException { public boolean download(String lfile, Path rfile, TransferFileProgress progress) throws JSchException, IOException {
try(OutputStream os = Files.newOutputStream(rfile)) { try (OutputStream os = Files.newOutputStream(rfile)) {
return download(lfile, os, progress); return download(lfile, os, progress);
} }
} }
...@@ -174,17 +174,16 @@ public class ScpClient implements Closeable { ...@@ -174,17 +174,16 @@ public class ScpClient implements Closeable {
public boolean upload(Path file, String rfile, TransferFileProgress progress) throws JSchException, IOException { public boolean upload(Path file, String rfile, TransferFileProgress progress) throws JSchException, IOException {
try (InputStream is = Files.newInputStream(file)) { try (InputStream is = Files.newInputStream(file)) {
return upload(is, file.getFileName().toString(), file.toFile().length(), file.toFile().lastModified(), return upload(is, rfile, file.toFile().length(), file.toFile().lastModified(), progress);
rfile, progress);
} }
} }
public boolean upload(InputStream is, String fileName, long length, long lastModified, String rfile, public boolean upload(InputStream is, String fileName, long length, long lastModified,
TransferFileProgress progress) throws JSchException, IOException { TransferFileProgress progress) throws JSchException, IOException {
Session session = connectionSession(); Session session = connectionSession();
boolean ptimestamp = true; boolean ptimestamp = true;
// exec 'scp -t rfile' remotely // exec 'scp -t rfile' remotely
String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + rfile; String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + fileName;
Channel channel = session.openChannel("exec"); Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand(command); ((ChannelExec) channel).setCommand(command);
// get I/O streams for remote scp // get I/O streams for remote scp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment