Skip to content

Commit 82a3e43

Browse files
committed
Add possibility to send created json file to docker
1 parent f68dff7 commit 82a3e43

File tree

10 files changed

+297
-14
lines changed

10 files changed

+297
-14
lines changed

org.sofproject.gst.topo/.classpath

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@
1010
<classpathentry exported="true" kind="lib" path="lib/jackson-core-2.10.1.jar"/>
1111
<classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.10.1.jar"/>
1212
<classpathentry kind="src" path="src"/>
13-
<classpathentry kind="lib" path="C:/Users/edominia/Downloads/jackson-annotations-2.10.1.jar" sourcepath="C:/Users/edominia/Downloads/jackson-annotations-master.zip"/>
14-
<classpathentry kind="lib" path="C:/Users/edominia/Downloads/jackson-core-2.10.1.jar" sourcepath="C:/Users/edominia/Downloads/jackson-core-master.zip"/>
15-
<classpathentry kind="lib" path="C:/Users/edominia/Downloads/jackson-databind-2.10.1.jar" sourcepath="C:/Users/edominia/Downloads/jackson-databind-master.zip"/>
1613
<classpathentry kind="output" path="bin"/>
1714
</classpath>

org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonCustomOptionPane.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Intel Corporation
2+
* Copyright (c) 2019, Intel Corporation
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -64,7 +64,7 @@ private static boolean isInteger(String s) {
6464
return true;
6565
}
6666

67-
public JsonCustomOptionPane(Display display, ITopoGraph graph) {
67+
public JsonCustomOptionPane(Display display, ITopoGraph graph, JsonUtils jsonUtils) {
6868
this.graph = graph;
6969
Shell shell = new Shell(display, SWT.CLOSE | SWT.TITLE | SWT.MIN);
7070

@@ -97,7 +97,7 @@ public JsonCustomOptionPane(Display display, ITopoGraph graph) {
9797
new Label(shell, SWT.NULL).setText("Type:");
9898
Combo typeCombo = new Combo(shell, SWT.READ_ONLY);
9999
typeCombo.setBounds(50, 50, 200, 65);
100-
String items[] = { "Gstreamer", "Ffmpeg" };
100+
String items[] = { "GStreamer", "Ffmpeg" };
101101
typeCombo.setItems(items);
102102
typeCombo.setText(items[0]);
103103
GridData typeGridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
@@ -124,7 +124,7 @@ public void widgetSelected(SelectionEvent e) {
124124
try {
125125
JsonProperty jsonProperty = new JsonProperty(nameText.getText(), descriptionText.getText(),
126126
versionText.getText(), typeCombo.getItem(typeCombo.getSelectionIndex()));
127-
new JsonUtils().serializeJson(jsonProperty, graph.getPipelineString());
127+
jsonUtils.serializeJson(jsonProperty, graph.getPipelineString());
128128
shell.close();
129129
} catch (CoreException | IOException error) {
130130
error.printStackTrace(); // TODO:

org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonProperty.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,26 @@
2929

3030
package org.sofproject.gst.json;
3131

32+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
33+
34+
@JsonSerialize
3235
public class JsonProperty {
3336

3437
private String name;
3538
private String description;
3639
private String version;
3740
private String type;
3841
private String template;
42+
private Parameters parameters;
3943

4044
public JsonProperty(String name, String description, String version, String type) {
4145
this.name = name;
4246
this.description = description;
4347
this.version = version;
4448
this.type = type;
49+
50+
// set default parameters
51+
this.parameters = new Parameters("object", new Properties());
4552
}
4653

4754
public String getName() {
@@ -64,7 +71,40 @@ public String getTemplate() {
6471
return template;
6572
}
6673

74+
public Parameters getParameters() {
75+
return parameters;
76+
}
77+
6778
public void setTemplate(String newTemplate) {
6879
this.template = newTemplate;
6980
}
81+
82+
public void setParameters(Parameters parameters) {
83+
this.parameters = parameters;
84+
}
85+
}
86+
87+
@JsonSerialize
88+
class Parameters {
89+
private String type;
90+
private Properties properties;
91+
92+
public Parameters(String type, Properties properties) {
93+
this.type = type;
94+
this.properties = properties;
95+
}
96+
97+
public String getType() {
98+
return type;
99+
}
100+
101+
public Properties getProperties() {
102+
return properties;
103+
}
104+
}
105+
106+
@JsonSerialize
107+
class Properties {
108+
public Properties() {
109+
}
70110
}

org.sofproject.gst.topo/src/org/sofproject/gst/json/JsonUtils.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,29 @@
4444
import org.eclipse.ui.IWorkbenchPage;
4545
import org.eclipse.ui.IWorkbenchWindow;
4646
import org.eclipse.ui.PlatformUI;
47+
import org.sofproject.core.ops.IRemoteOpsProvider;
48+
import org.sofproject.gst.topo.ops.GstDockerOpsProvider;
4749

4850
import com.fasterxml.jackson.databind.ObjectMapper;
4951

5052
public class JsonUtils {
5153

54+
JsonProperty jsonProperty_;
55+
5256
public void serializeJson(JsonProperty jsonProperty, String pipelineString) throws CoreException, IOException {
5357
try {
5458
String projectPath = getProjectPath();
5559
File file;
5660
if (projectPath != null) {
57-
String path = Paths.get(projectPath, jsonProperty.getName(), jsonProperty.getVersion()).toString();
61+
String path = Paths.get(projectPath, jsonProperty.getType().toLowerCase(), jsonProperty.getName(),
62+
jsonProperty.getVersion()).toString();
5863
new File(path).mkdirs();
5964
file = new File(Paths.get(path, "pipeline.json").toString());
6065
} else {
6166
file = new File(jsonProperty.getName() + ".json");
6267
}
6368
jsonProperty.setTemplate(pipelineString);
69+
jsonProperty_ = jsonProperty;
6470
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
6571
ObjectMapper obj = new ObjectMapper();
6672
obj.writeValue(writer, jsonProperty);
@@ -94,4 +100,12 @@ public String getProjectPath() {
94100
return null;
95101
}
96102

103+
public IRemoteOpsProvider getDockerOpsProvider() {
104+
return new GstDockerOpsProvider(this);
105+
}
106+
107+
public JsonProperty getJsonProperty() {
108+
return jsonProperty_;
109+
}
110+
97111
}

org.sofproject.gst.topo/src/org/sofproject/gst/topo/model/GstTopoNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public GstTopoConnection getOutgoingConnection() {
100100
public void serialize(Writer writer) throws IOException {
101101
writer.write(elem.getName());
102102
for (GstProperty prop : properties.values()) {
103-
//if (!prop.isChanged())
104-
// continue;
103+
if (!prop.isChanged())
104+
continue;
105105
writer.write(" ");
106106
prop.serialize(writer);
107107
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2019, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
*/
29+
30+
package org.sofproject.gst.topo.ops;
31+
32+
import java.io.BufferedReader;
33+
import java.io.FileReader;
34+
import java.io.IOException;
35+
import java.lang.reflect.InvocationTargetException;
36+
import java.nio.file.FileSystem;
37+
import java.nio.file.Path;
38+
import java.nio.file.Paths;
39+
40+
import org.eclipse.core.runtime.IProgressMonitor;
41+
import org.sofproject.core.AudioDevNodeProject;
42+
import org.sofproject.core.connection.AudioDevNodeConnection;
43+
import org.sofproject.core.ops.SimpleRemoteOp;
44+
import org.sofproject.gst.json.JsonProperty;
45+
import org.sofproject.gst.json.JsonUtils;
46+
47+
import com.jcraft.jsch.ChannelExec;
48+
import com.jcraft.jsch.JSchException;
49+
import com.jcraft.jsch.Session;
50+
51+
public class GstDockerOperation extends SimpleRemoteOp {
52+
53+
private JsonUtils jsonUtils;
54+
55+
public GstDockerOperation(AudioDevNodeConnection conn, JsonUtils jsonUtils) {
56+
super(conn);
57+
this.jsonUtils = jsonUtils;
58+
}
59+
60+
@Override
61+
public boolean isCancelable() {
62+
return true;
63+
}
64+
65+
@Override
66+
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
67+
monitor.beginTask("Sending json to docker", 100);
68+
69+
try {
70+
if (!conn.isConnected()) {
71+
throw new InvocationTargetException(new IllegalStateException("Node not connected"));
72+
}
73+
74+
JsonProperty jsonProperty = jsonUtils.getJsonProperty();
75+
76+
AudioDevNodeProject proj = conn.getProject();
77+
Session session = conn.getSession();
78+
ChannelExec channel = (ChannelExec) session.openChannel("exec");
79+
channel.setInputStream(null);
80+
81+
String jsonFileName = "pipeline.json";
82+
String projectPath = proj.getProject().getLocation().toString();
83+
Path partPathToJson = Paths.get(jsonProperty.getType().toLowerCase(), jsonProperty.getName(), jsonProperty.getVersion());
84+
Path fullPathToJson = Paths.get(projectPath, partPathToJson.toString(), jsonFileName);
85+
String linuxPartPathToJson = partPathToJson.toString();
86+
linuxPartPathToJson = linuxPartPathToJson.replace("\\", "/");
87+
88+
BufferedReader reader = new BufferedReader(new FileReader(fullPathToJson.toString()));
89+
String currentLine = reader.readLine();
90+
reader.close();
91+
92+
channel.setPty(true); // for ctrl+c sending
93+
String command = String.format(
94+
"docker exec -t video_analytics_serving_gstreamer /bin/bash -c \"cd pipelines; mkdir -p %s; cd %s; touch %s; echo \'%s\' > %s\"",
95+
linuxPartPathToJson, linuxPartPathToJson, jsonFileName, currentLine.replace("\"", "\\\""), jsonFileName);
96+
channel.setCommand(command);
97+
98+
channel.connect();
99+
100+
while (!channel.isEOF())
101+
;
102+
channel.disconnect();
103+
monitor.beginTask("Sending json to docker", 1000);
104+
105+
} catch (JSchException | IOException e) {
106+
throw new InvocationTargetException(e);
107+
}
108+
}
109+
110+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2019, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
*/
29+
30+
package org.sofproject.gst.topo.ops;
31+
32+
import org.sofproject.core.connection.AudioDevNodeConnection;
33+
import org.sofproject.core.ops.IRemoteOp;
34+
import org.sofproject.core.ops.IRemoteOpsProvider;
35+
import org.sofproject.gst.json.JsonUtils;
36+
37+
public class GstDockerOpsProvider implements IRemoteOpsProvider {
38+
39+
public static final String SEND_DOCKER = "org.sofproject.gst.topo.ops.senddocker";
40+
41+
public static final String[] OPS = { SEND_DOCKER };
42+
43+
JsonUtils jsonUtils;
44+
45+
public GstDockerOpsProvider(JsonUtils jsonUtils) {
46+
this.jsonUtils = jsonUtils;
47+
}
48+
49+
@Override
50+
public String[] getRemoteOpsIds() {
51+
return OPS;
52+
}
53+
54+
@Override
55+
public String getRemoteOpDisplayName(String opId) {
56+
switch (opId) {
57+
case SEND_DOCKER:
58+
return "Serialize Topology to Json & send to Docker";
59+
default:
60+
return null;
61+
}
62+
}
63+
64+
@Override
65+
public IRemoteOp createRemoteOp(String opId, AudioDevNodeConnection conn) {
66+
switch (opId) {
67+
case SEND_DOCKER:
68+
return new GstDockerOperation(conn, jsonUtils);
69+
default:
70+
return null;
71+
}
72+
}
73+
74+
}

org.sofproject.gst.topo/src/org/sofproject/gst/topo/ops/GstGraphOpsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public IRemoteOp createRemoteOp(String opId, AudioDevNodeConnection conn) {
6767
switch (opId) {
6868
case TEST_TOPO:
6969
if (conn == null) {
70-
conn = AudioDevNodeConnectionManager.getInstance().getConnection(graph.getFileInput().getProject());;
70+
conn = AudioDevNodeConnectionManager.getInstance().getConnection(graph.getFileInput().getProject());
7171
}
7272
return new GstTopoTestOperation(graph, conn);
7373
default:

org.sofproject.topo.ui/.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
</classpathentry>
88
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
99
<classpathentry kind="src" path="src"/>
10-
<classpathentry kind="lib" path="C:/Users/edominia/Downloads/javax-inject.jar"/>
1110
<classpathentry kind="output" path="bin"/>
1211
</classpath>

0 commit comments

Comments
 (0)