updated set mobility to upload file to a upload directory and mark files used by set mobility config to look for the file within this directory
This commit is contained in:
parent
2815554487
commit
3dc9586817
8 changed files with 63 additions and 30 deletions
|
@ -176,6 +176,11 @@ public class CoreRestClient implements ICoreClient {
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean uploadFile(File file) throws IOException {
|
||||
String url = getUrl("upload");
|
||||
return WebUtils.postFile(url, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoreService getService(CoreNode node, String serviceName) throws IOException {
|
||||
String url = getUrl(String.format("sessions/%s/nodes/%s/services/%s", sessionId, node.getId(), serviceName));
|
||||
|
@ -266,7 +271,7 @@ public class CoreRestClient implements ICoreClient {
|
|||
@Override
|
||||
public void openSession(File file) throws IOException {
|
||||
String url = getUrl("sessions/xml");
|
||||
CreatedSession createdSession = WebUtils.putFile(url, file, CreatedSession.class);
|
||||
CreatedSession createdSession = WebUtils.postFile(url, file, CreatedSession.class);
|
||||
joinSession(createdSession.getId(), true);
|
||||
}
|
||||
|
||||
|
@ -336,7 +341,13 @@ public class CoreRestClient implements ICoreClient {
|
|||
|
||||
@Override
|
||||
public boolean setMobilityConfig(CoreNode node, MobilityConfig config) throws IOException {
|
||||
boolean uploaded = uploadFile(config.getScriptFile());
|
||||
if (!uploaded) {
|
||||
throw new IOException("failed to upload mobility script");
|
||||
}
|
||||
|
||||
String url = getUrl(String.format("sessions/%s/nodes/%s/mobility", sessionId, node.getId()));
|
||||
config.setFile(config.getScriptFile().getName());
|
||||
String data = JsonUtils.toString(config);
|
||||
return WebUtils.postJson(url, data);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.core.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Data
|
||||
public class MobilityConfig {
|
||||
private String file;
|
||||
@JsonIgnore
|
||||
private File scriptFile;
|
||||
@JsonProperty("refresh_ms")
|
||||
private Integer refresh;
|
||||
private String loop;
|
||||
|
|
|
@ -59,6 +59,7 @@ public class MobilityDialog extends StageDialog {
|
|||
saveButton.setOnAction(event -> {
|
||||
MobilityConfig mobilityConfig = new MobilityConfig();
|
||||
mobilityConfig.setFile(fileTextField.getText());
|
||||
mobilityConfig.setScriptFile(new File(mobilityConfig.getFile()));
|
||||
mobilityConfig.setAutostart(autoStartTextField.getText());
|
||||
String loop = loopToggleButton.isSelected() ? "1" : "";
|
||||
mobilityConfig.setLoop(loop);
|
||||
|
|
|
@ -51,11 +51,28 @@ public final class WebUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static <T> T putFile(String url, File file, Class<T> clazz) throws IOException {
|
||||
public static boolean postFile(String url, File file) throws IOException {
|
||||
MediaType mediaType = MediaType.parse("File/*");
|
||||
RequestBody requestBody = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("session", file.getName(), RequestBody.create(mediaType, file))
|
||||
.addFormDataPart("file", file.getName(), RequestBody.create(mediaType, file))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(requestBody)
|
||||
.build();
|
||||
|
||||
try (Response response = client.newCall(request).execute()) {
|
||||
return response.isSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T postFile(String url, File file, Class<T> clazz) throws IOException {
|
||||
MediaType mediaType = MediaType.parse("File/*");
|
||||
RequestBody requestBody = new MultipartBody.Builder()
|
||||
.setType(MultipartBody.FORM)
|
||||
.addFormDataPart("file", file.getName(), RequestBody.create(mediaType, file))
|
||||
.build();
|
||||
|
||||
Request request = new Request.Builder()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue