Skip to content

Commit 99ec65d

Browse files
Add files via upload
1 parent b33d9f8 commit 99ec65d

21 files changed

+798
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,67 @@
1+
<?xml version="1.0"?>
2+
<applications>
3+
<application name="app_1">
4+
<execution_time_limit>4.5</execution_time_limit>
5+
<computational_complexity>0.12</computational_complexity>
6+
<tasks>
7+
<task name="task_1">
8+
<datasize>1250</datasize>
9+
<output_datasize>700</output_datasize>
10+
</task>
11+
<task name="task_2">
12+
<datasize>1750</datasize>
13+
<output_datasize>800</output_datasize>
14+
</task>
15+
</tasks>
16+
</application>
17+
<application name="app_2">
18+
<execution_time_limit>6.0</execution_time_limit>
19+
<computational_complexity>0.18</computational_complexity>
20+
<tasks>
21+
<task name="task_1">
22+
<datasize>1350</datasize>
23+
<output_datasize>650</output_datasize>
24+
</task>
25+
<task name="task_2">
26+
<datasize>1850</datasize>
27+
<output_datasize>950</output_datasize>
28+
</task>
29+
<task name="task_3">
30+
<datasize>1450</datasize>
31+
<output_datasize>750</output_datasize>
32+
</task>
33+
</tasks>
34+
</application>
35+
<application name="app_3">
36+
<execution_time_limit>5.5</execution_time_limit>
37+
<computational_complexity>0.15</computational_complexity>
38+
<tasks>
39+
<task name="task_1">
40+
<datasize>1300</datasize>
41+
<output_datasize>700</output_datasize>
42+
</task>
43+
<task name="task_2">
44+
<datasize>1700</datasize>
45+
<output_datasize>800</output_datasize>
46+
</task>
47+
</tasks>
48+
</application>
49+
<application name="app_4">
50+
<execution_time_limit>6.2</execution_time_limit>
51+
<computational_complexity>0.20</computational_complexity>
52+
<tasks>
53+
<task name="task_1">
54+
<datasize>1275</datasize>
55+
<output_datasize>625</output_datasize>
56+
</task>
57+
<task name="task_2">
58+
<datasize>1825</datasize>
59+
<output_datasize>925</output_datasize>
60+
</task>
61+
<task name="task_3">
62+
<datasize>1375</datasize>
63+
<output_datasize>725</output_datasize>
64+
</task>
65+
</tasks>
66+
</application>
67+
</applications>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<edgeservers>
3+
<edgeserver name="edge_1">
4+
<memory_capacity>3000</memory_capacity>
5+
<computational_capacity>220</computational_capacity>
6+
<downlink_datarate>5000</downlink_datarate>
7+
<uplink_datarate>7000</uplink_datarate>
8+
</edgeserver>
9+
<edgeserver name="edge_2">
10+
<memory_capacity>2800</memory_capacity>
11+
<computational_capacity>270</computational_capacity>
12+
<downlink_datarate>8000</downlink_datarate>
13+
<uplink_datarate>6000</uplink_datarate>
14+
</edgeserver>
15+
<edgeserver name="edge_3">
16+
<memory_capacity>2500</memory_capacity>
17+
<computational_capacity>200</computational_capacity>
18+
<downlink_datarate>6000</downlink_datarate>
19+
<uplink_datarate>10000</uplink_datarate>
20+
</edgeserver>
21+
</edgeservers>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
edgeservers.xml;application.xml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
script_root_path="$(dirname "$(readlink -f "$0")")"
2+
output_folder_path=${script_root_path}/output
3+
4+
mkdir -p $output_folder_path
5+
6+
configurations=$(cat ${script_root_path}/configuration.list)
7+
8+
# read the all configuration file names from configuration.list
9+
for config_args in $configurations
10+
do
11+
edge_servers_file=$(echo $config_args | cut -d ';' -f1)
12+
application_file=$(echo $config_args | cut -d ';' -f2)
13+
done
14+
15+
edge_servers_file_path=${script_root_path}/config/${edge_servers_file}
16+
application_file_path=${script_root_path}/config/${application_file}
17+
18+
java -classpath '../bin' sample_app.MainApp $edge_servers_file_path $application_file_path $output_folder_path
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package core;
2+
3+
import java.io.File;
4+
5+
import javax.xml.parsers.DocumentBuilder;
6+
import javax.xml.parsers.DocumentBuilderFactory;
7+
8+
import org.w3c.dom.Document;
9+
import org.w3c.dom.Element;
10+
import org.w3c.dom.Node;
11+
import org.w3c.dom.NodeList;
12+
13+
import utils.Application;
14+
import utils.EdgeServer;
15+
16+
public class ConfigSettings {
17+
18+
private static ConfigSettings instance = null;
19+
private Document edgeServerDoc = null;
20+
private Document applicationDoc = null;
21+
22+
private int NUM_OF_EDGE_SERVER;
23+
private int NUM_OF_APPLICATION;
24+
25+
private ConfigSettings() {
26+
NUM_OF_EDGE_SERVER = 0;
27+
NUM_OF_APPLICATION = 0;
28+
}
29+
30+
public static ConfigSettings getInstance() {
31+
if(instance == null) {
32+
instance = new ConfigSettings();
33+
}
34+
return instance;
35+
}
36+
37+
/*
38+
* Reads configuration files and stores the information to local variables
39+
*/
40+
public boolean initialize(String edgeServerFile, String applicationFile) {
41+
boolean result = false;
42+
43+
// parse details of edge servers
44+
result = parseEdgeServerXML(edgeServerFile);
45+
46+
// parse details of applications
47+
result = parseApplicationXML(applicationFile);
48+
49+
return result;
50+
51+
}
52+
53+
// parse edgeservers.xml file
54+
private boolean parseEdgeServerXML(String edgeServerFilePath) {
55+
56+
try {
57+
int edgeServerMemoryCapacity;
58+
int edgeServerComputationalCapacity;
59+
int edgeServerDownlinkDatarate;
60+
int edgeServerUplinkDatarate;
61+
62+
File edgeServerFile = new File(edgeServerFilePath);
63+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
64+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
65+
edgeServerDoc = dBuilder.parse(edgeServerFile);
66+
edgeServerDoc.getDocumentElement().normalize();
67+
68+
NodeList edgeServerList = edgeServerDoc.getElementsByTagName("edgeserver");
69+
for(int i = 0; i < edgeServerList.getLength(); ++i) {
70+
NUM_OF_EDGE_SERVER++;
71+
Node EdgeServerNode = edgeServerList.item(i);
72+
73+
Element edgeServerElement = (Element) EdgeServerNode;
74+
isAttributePresent(edgeServerElement, "name");
75+
edgeServerMemoryCapacity = Integer.parseInt(isElementPresent(edgeServerElement, "memory_capacity"));
76+
edgeServerComputationalCapacity = Integer.parseInt(isElementPresent(edgeServerElement, "computational_capacity"));
77+
edgeServerDownlinkDatarate = Integer.parseInt(isElementPresent(edgeServerElement, "downlink_datarate"));
78+
edgeServerUplinkDatarate = Integer.parseInt(isElementPresent(edgeServerElement, "uplink_datarate"));
79+
EdgeServer.createInstance(i+1, edgeServerMemoryCapacity, edgeServerComputationalCapacity, edgeServerDownlinkDatarate, edgeServerUplinkDatarate);
80+
}
81+
82+
} catch(Exception e) {
83+
System.out.println("Edge server XML cannot be parsed! Terminating...");
84+
e.printStackTrace();
85+
System.exit(1);
86+
}
87+
88+
return true;
89+
}
90+
91+
// parse application.xml file
92+
private boolean parseApplicationXML(String applicationFilePath) {
93+
94+
try {
95+
double applicationExecutionTimeLimit;
96+
double applicationComputationalComplexity;
97+
int taskDataSize;
98+
int taskOutputDataSize;
99+
100+
File applicationFile = new File(applicationFilePath);
101+
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
102+
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
103+
applicationDoc = dBuilder.parse(applicationFile);
104+
applicationDoc.getDocumentElement().normalize();
105+
106+
NodeList applicationList = applicationDoc.getElementsByTagName("application");
107+
for(int i = 0; i < applicationList.getLength(); ++i) {
108+
NUM_OF_APPLICATION++;
109+
Node applicationNode = applicationList.item(i);
110+
111+
Element applicationElement = (Element) applicationNode;
112+
isAttributePresent(applicationElement, "name");
113+
applicationExecutionTimeLimit = Double.parseDouble(isElementPresent(applicationElement, "execution_time_limit"));
114+
applicationComputationalComplexity = Double.parseDouble(isElementPresent(applicationElement, "computational_complexity"));
115+
Application applicationInstance = Application.createInstance(i+1, applicationExecutionTimeLimit, applicationComputationalComplexity);
116+
117+
NodeList taskList = applicationElement.getElementsByTagName("task");
118+
for(int j = 0; j < taskList.getLength(); ++j) {
119+
Node taskNode = taskList.item(j);
120+
121+
Element taskElement = (Element) taskNode;
122+
isAttributePresent(taskElement, "name");
123+
taskDataSize = Integer.parseInt(isElementPresent(taskElement, "datasize"));
124+
taskOutputDataSize = Integer.parseInt(isElementPresent(taskElement, "output_datasize"));
125+
applicationInstance.addTask(j+1, taskDataSize, taskOutputDataSize);
126+
}
127+
128+
Application.addToApplicationList(applicationInstance);
129+
}
130+
131+
} catch(Exception e) {
132+
System.out.println("Application XML cannot be parsed! Terminating...");
133+
e.printStackTrace();
134+
System.exit(1);
135+
}
136+
137+
return true;
138+
}
139+
140+
private void isAttributePresent(Element element, String key) {
141+
String value = element.getAttribute(key);
142+
if(value.isEmpty() || value == null) {
143+
throw new IllegalArgumentException("Attribute '" + key + "' is not found in '" + element.getNodeName() + "'");
144+
}
145+
}
146+
147+
private String isElementPresent(Element element, String key) {
148+
try {
149+
String value = element.getElementsByTagName(key).item(0).getTextContent();
150+
if(value.isEmpty() || value == null) {
151+
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() + "'");
152+
}
153+
return value;
154+
} catch(Exception e) {
155+
throw new IllegalArgumentException("Element '" + key + "' is not found in '" + element.getNodeName() + "'");
156+
}
157+
}
158+
159+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* MainApp.java initializes all the parsing operations of the input files.
3+
* it triggers the task allocation algorithm
4+
*/
5+
6+
package sample_app;
7+
8+
import core.ConfigSettings;
9+
import task_allocation.TaskAllocation;
10+
11+
public class MainApp {
12+
public static void main(String[] args) {
13+
String edgeServerFile = args[0];
14+
String applicationFile = args[1];
15+
String ouputFolder = args[2];
16+
17+
// load the configurations from the config files
18+
ConfigSettings cs = ConfigSettings.getInstance();
19+
if(cs.initialize(edgeServerFile, applicationFile) == false) {
20+
System.out.println("cannot initialize the configuration settings");
21+
System.exit(0);
22+
}
23+
24+
// run task allocation algorithm
25+
TaskAllocation ta = TaskAllocation.getInstance();
26+
ta.init();
27+
28+
// Generate output
29+
}
30+
}

0 commit comments

Comments
 (0)