Skip to content

Commit 0bd4168

Browse files
Add files via upload
1 parent 2d0ddeb commit 0bd4168

23 files changed

+1091
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
rm -rf ../bin
2+
mkdir ../bin
3+
javac -classpath "" -sourcepath ../src ../src/sample_app/MainApp.java -d ../bin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<edgeservers>
3+
<edgeserver name="server_0">
4+
<cores>4</cores>
5+
<memory>10</memory>
6+
</edgeserver>
7+
<edgeserver name="server_1">
8+
<cores>6</cores>
9+
<memory>20</memory>
10+
</edgeserver>
11+
<edgeserver name="server_2">
12+
<cores>8</cores>
13+
<memory>15</memory>
14+
</edgeserver>
15+
<edgeserver name="server_3">
16+
<cores>4</cores>
17+
<memory>10</memory>
18+
</edgeserver>
19+
<edgeserver name="server_4">
20+
<cores>10</cores>
21+
<memory>30</memory>
22+
</edgeserver>
23+
</edgeservers>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0"?>
2+
<graph>
3+
<node name="node_0">
4+
<edges>
5+
<edge>
6+
<vertex>1</vertex>
7+
<weight>10</weight>
8+
</edge>
9+
<edge>
10+
<vertex>2</vertex>
11+
<weight>15</weight>
12+
</edge>
13+
<edge>
14+
<vertex>3</vertex>
15+
<weight>12</weight>
16+
</edge>
17+
</edges>
18+
</node>
19+
<node name="node_1">
20+
<edges>
21+
<edge>
22+
<vertex>4</vertex>
23+
<weight>20</weight>
24+
</edge>
25+
</edges>
26+
</node>
27+
<node name="node_2">
28+
<edges>
29+
<edge>
30+
<vertex>4</vertex>
31+
<weight>18</weight>
32+
</edge>
33+
<edge>
34+
<vertex>5</vertex>
35+
<weight>23</weight>
36+
</edge>
37+
</edges>
38+
</node>
39+
<node name="node_3">
40+
<edges>
41+
<edge>
42+
<vertex>6</vertex>
43+
<weight>12</weight>
44+
</edge>
45+
</edges>
46+
</node>
47+
<node name="node_4">
48+
<edges>
49+
<edge>
50+
<vertex>7</vertex>
51+
<weight>15</weight>
52+
</edge>
53+
</edges>
54+
</node>
55+
<node name="node_5">
56+
<edges>
57+
<edge>
58+
<vertex>6</vertex>
59+
<weight>14</weight>
60+
</edge>
61+
</edges>
62+
</node>
63+
<node name="node_6">
64+
<edges>
65+
<edge>
66+
<vertex>7</vertex>
67+
<weight>20</weight>
68+
</edge>
69+
</edges>
70+
</node>
71+
<node name="node_7">
72+
<edges></edges>
73+
</node>
74+
</graph>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<microservices>
3+
<microservice name="MICROSERVICE_0">
4+
<cores>1</cores>
5+
<memory>4</memory>
6+
<execution_time>8</execution_time>
7+
</microservice>
8+
<microservice name="MICROSERVICE_1">
9+
<cores>2</cores>
10+
<memory>2</memory>
11+
<execution_time>12</execution_time>
12+
</microservice>
13+
<microservice name="MICROSERVICE_2">
14+
<cores>2</cores>
15+
<memory>8</memory>
16+
<execution_time>150</execution_time>
17+
</microservice>
18+
<microservice name="MICROSERVICE_3">
19+
<cores>3</cores>
20+
<memory>4</memory>
21+
<execution_time>40</execution_time>
22+
</microservice>
23+
<microservice name="MICROSERVICE_4">
24+
<cores>2</cores>
25+
<memory>2</memory>
26+
<execution_time>15</execution_time>
27+
</microservice>
28+
<microservice name="MICROSERVICE_5">
29+
<cores>1</cores>
30+
<memory>8</memory>
31+
<execution_time>10</execution_time>
32+
</microservice>
33+
<microservice name="MICROSERVICE_6">
34+
<cores>3</cores>
35+
<memory>4</memory>
36+
<execution_time>18</execution_time>
37+
</microservice>
38+
<microservice name="MICROSERVICE_7">
39+
<cores>2</cores>
40+
<memory>2</memory>
41+
<execution_time>180</execution_time>
42+
</microservice>
43+
</microservices>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edgeservers.xml;microservice.xml;inputgraph.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
script_root_path="$(dirname "$(readlink -f "$0")")"
2+
output_folder_path=${script_root_path}/output
3+
4+
date=$(date '+%d-%m-%Y_%H-%M')
5+
output_folder=${output_folder_path}/${date}
6+
mkdir -p $output_folder
7+
8+
configurations=$(cat ${script_root_path}/configuration.list)
9+
10+
# read the all configuration file names from configuration.list
11+
for config_args in $configurations
12+
do
13+
edge_servers_file=$(echo $config_args | cut -d ';' -f1)
14+
micro_service_file=$(echo $config_args | cut -d ';' -f2)
15+
input_graph_file=$(echo $config_args | cut -d ';' -f3)
16+
done
17+
18+
edge_servers_file_path=${script_root_path}/config/${edge_servers_file}
19+
micro_service_file_path=${script_root_path}/config/${micro_service_file}
20+
input_graph_file_path=${script_root_path}/config/${input_graph_file}
21+
22+
java -classpath '../bin' sample_app.MainApp $edge_servers_file_path $micro_service_file_path $input_graph_file_path $output_folder
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/**
2+
* configSettings parse the EdgeServer XML file and set all the parameters of the edge server.
3+
* parse the MicroService XML file to set all the parameyters of the microservices
4+
* parse the inputGraph XML file to set the input graph
5+
*/
6+
7+
package core;
8+
9+
import java.io.File;
10+
import java.util.ArrayList;
11+
12+
import javax.xml.parsers.DocumentBuilder;
13+
import javax.xml.parsers.DocumentBuilderFactory;
14+
15+
import org.w3c.dom.Document;
16+
import org.w3c.dom.Element;
17+
import org.w3c.dom.Node;
18+
import org.w3c.dom.NodeList;
19+
20+
import utils.EdgeServer;
21+
import utils.InputGraph;
22+
import utils.MicroService;
23+
24+
25+
public class ConfigSettings {
26+
27+
private static ConfigSettings instance = null;
28+
private Document edgeServerDoc = null;
29+
private Document microServiceDoc = null;
30+
private Document microServiceGraphInputDoc = null;
31+
32+
private int NUM_OF_EDGE_SERVER;
33+
private int NUM_OF_MICRO_SERVICES;
34+
private int NUM_OF_VERTEX;
35+
private int NUM_OF_EDGES;
36+
37+
private ConfigSettings() {
38+
NUM_OF_EDGE_SERVER = 0;
39+
NUM_OF_MICRO_SERVICES = 0;
40+
}
41+
42+
public static ConfigSettings getInstance() {
43+
if(instance == null) {
44+
instance = new ConfigSettings();
45+
}
46+
return instance;
47+
}
48+
49+
/*
50+
* Reads configuration files and stores the information to local variables
51+
*/
52+
public boolean initialize(String edgeServerFile, String microServiceFile, String microServiceGraphInputFile) {
53+
boolean result = false;
54+
55+
// parse details of Edge Servers
56+
result = parseEdgeServerXML(edgeServerFile);
57+
58+
// parse details of Microservices
59+
result = parseMicroServicesXML(microServiceFile);
60+
61+
// parse details of Microservice Graph Input File
62+
result = parseMicroServiceGraphInputXML(microServiceGraphInputFile);
63+
64+
return result;
65+
66+
}
67+
68+
// parse the input graph XML file
69+
private boolean parseMicroServiceGraphInputXML(String microServiceGraphInputFilePath) {
70+
71+
try {
72+
int destVertex;
73+
int edgeWeight;
74+
75+
File microServiceGraphInputFile = new File(microServiceGraphInputFilePath);
76+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
77+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
78+
microServiceGraphInputDoc = dBuilder.parse(microServiceGraphInputFile);
79+
microServiceGraphInputDoc.getDocumentElement().normalize();
80+
81+
InputGraph graphInstance = InputGraph.getInstance();
82+
NodeList vertexList = microServiceGraphInputDoc.getElementsByTagName("node");
83+
for(int i = 0; i < vertexList.getLength(); ++i) {
84+
NUM_OF_VERTEX++;
85+
Node inputGraphVertex = vertexList.item(i);
86+
87+
Element inputGraphVertexElement = (Element) inputGraphVertex;
88+
isAttributePresent(inputGraphVertexElement, "name");
89+
90+
NodeList edgeList = inputGraphVertexElement.getElementsByTagName("edge");
91+
for(int j = 0; j < edgeList.getLength(); ++j) {
92+
NUM_OF_EDGES++;
93+
Node edge = edgeList.item(j);
94+
95+
Element edgeElement = (Element) edge;
96+
destVertex = Integer.parseInt(isElementPresent(edgeElement, "vertex"));
97+
edgeWeight = Integer.parseInt(isElementPresent(edgeElement, "weight"));
98+
graphInstance.addEdge(i, destVertex, edgeWeight);
99+
}
100+
}
101+
102+
} catch(Exception e) {
103+
System.out.println("Microservice Graph input XML cannot be parsed! Terminating...");
104+
e.printStackTrace();
105+
System.exit(1);
106+
}
107+
108+
return true;
109+
}
110+
111+
// parse the microservice XML file
112+
private boolean parseMicroServicesXML(String microServiceFilePath) {
113+
114+
try {
115+
int microServiceCore;
116+
int microServiceMemory;
117+
double microServiceExecutionTime;
118+
119+
File microServiceFile = new File(microServiceFilePath);
120+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
121+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
122+
microServiceDoc = dBuilder.parse(microServiceFile);
123+
microServiceDoc.getDocumentElement().normalize();
124+
125+
NodeList microServiceList = microServiceDoc.getElementsByTagName("microservice");
126+
for(int i = 0; i < microServiceList.getLength(); ++i) {
127+
NUM_OF_MICRO_SERVICES++;
128+
Node microServiceNode = microServiceList.item(i);
129+
130+
Element microServiceElement = (Element) microServiceNode;
131+
isAttributePresent(microServiceElement, "name");
132+
microServiceCore = Integer.parseInt(isElementPresent(microServiceElement, "cores"));
133+
microServiceMemory = Integer.parseInt(isElementPresent(microServiceElement, "memory"));
134+
microServiceExecutionTime = Double.parseDouble(isElementPresent(microServiceElement, "execution_time"));
135+
MicroService.createInstance(i, microServiceCore, microServiceMemory, microServiceExecutionTime);
136+
}
137+
138+
} catch(Exception e) {
139+
System.out.println("Microservice XML cannot be parsed! Terminating...");
140+
e.printStackTrace();
141+
System.exit(1);
142+
}
143+
144+
return true;
145+
}
146+
147+
// parse the edge server XML file
148+
private boolean parseEdgeServerXML(String edgeServerFilePath) {
149+
150+
try {
151+
int edgeServerCore;
152+
int edgeServerMemory;
153+
154+
File edgeServerFile = new File(edgeServerFilePath);
155+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
156+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
157+
edgeServerDoc = dBuilder.parse(edgeServerFile);
158+
edgeServerDoc.getDocumentElement().normalize();
159+
160+
NodeList edgeServerList = edgeServerDoc.getElementsByTagName("edgeserver");
161+
for(int i = 0; i < edgeServerList.getLength(); ++i) {
162+
NUM_OF_EDGE_SERVER++;
163+
Node edgeServerNode = edgeServerList.item(i);
164+
165+
Element edgeServerElement = (Element) edgeServerNode;
166+
isAttributePresent(edgeServerElement, "name");
167+
edgeServerCore = Integer.parseInt(isElementPresent(edgeServerElement, "cores"));
168+
edgeServerMemory = Integer.parseInt(isElementPresent(edgeServerElement, "memory"));
169+
EdgeServer.createInstance(i, edgeServerCore, edgeServerMemory);
170+
171+
}
172+
} catch(Exception e) {
173+
System.out.println("Edge server XML cannot be parsed! Terminating...");
174+
e.printStackTrace();
175+
System.exit(1);
176+
}
177+
178+
return true;
179+
}
180+
181+
private void isAttributePresent(Element element, String key) {
182+
String value = element.getAttribute(key);
183+
if(value.isEmpty() || value == null) {
184+
throw new IllegalArgumentException("Attribute '" + key + "' is not found in '" + element.getNodeName() + "'");
185+
}
186+
}
187+
188+
private String isElementPresent(Element element, String key) {
189+
try {
190+
String value = element.getElementsByTagName(key).item(0).getTextContent();
191+
if(value.isEmpty() || value == null) {
192+
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() + "'");
193+
}
194+
return value;
195+
} catch(Exception e) {
196+
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() + "'");
197+
}
198+
}
199+
200+
}

0 commit comments

Comments
 (0)