ComputingNodesGenerator
用来生成计算资源
获得所有的资源编排器
/**
* The list that contains all orchestrators. It is used by the computing node.
* In this case, the tasks are sent over the network to one of the orchestrators
* to make decisions.
*
* @see #generateDataCenters(String, TYPES)
* @see com.mechalikh.pureedgesim.simulationmanager.DefaultSimulationManager#sendTaskToOrchestrator(Task)
*/
//获得所有的编排器
protected List<ComputingNode> orchestratorsList;
仿真管理
/**
* The simulation manager.
*/
protected SimulationManager simulationManager;
场景的移动模型
/**
* The Mobility Model to be used in this scenario
*
* @see com.mechalikh.pureedgesim.simulationmanager.SimulationThread#loadModels(DefaultSimulationManager)
*/
protected Class<? extends MobilityModel> mobilityModelClass;
场景的计算节点
/**
* The Computing Node Class to be used in this scenario
*
* @see com.mechalikh.pureedgesim.simulationmanager.SimulationThread#loadModels(DefaultSimulationManager)
*/
protected Class<? extends ComputingNode> computingNodeClass;
边缘设备列表
/**
* A list that contains all edge devices including sensors (i.e., devices
* without computing capacities).
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#mistOnly(Task
* task)
*/
protected List<ComputingNode> mistOnlyList;
有计算能力的边缘设备
/**
* A list that contains all edge devices except sensors (i.e., devices without
* computing capacities).
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#mistOnly(Task
* task)
*/
protected List<ComputingNode> mistOnlyListSensorsExcluded;
包含边缘计算中心的列表
/**
* A list that contains only edge data centers and servers.
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#edgeOnly(Task
* task)
*/
protected List<ComputingNode> edgeOnlyList = new ArrayList<>(SimulationParameters.numberOfEdgeDataCenters);
包含所有云计算中心的列表
/**
* A list that contains only cloud data centers.
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#cloudOnly(Task
* task)
*/
protected List<ComputingNode> cloudOnlyList = new ArrayList<>(SimulationParameters.numberOfCloudDataCenters);
云数据中心和边缘设备(有计算能力)列表
/**
* A list that contains cloud data centers and edge devices (except sensors).
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#mistAndCloud(Task
* task)
*/
protected List<ComputingNode> mistAndCloudListSensorsExcluded;
包含所有云数据中心和边缘数据中的列表
/**
* A list that contains cloud and edge data centers.
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#edgeAndCloud(Task
* task)
*/
protected List<ComputingNode> edgeAndCloudList = new ArrayList<>(
SimulationParameters.numberOfCloudDataCenters + SimulationParameters.numberOfEdgeDataCenters);
包括边缘数据中心和边缘设备(不包括无计算能力)
/**
* A list that contains edge data centers and edge devices (except sensors).
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#mistAndEdge(Task
* task)
*/
protected List<ComputingNode> mistAndEdgeListSensorsExcluded;
包括传感器的所有设备列表
/**
* A list that contains all generated nodes including sensors
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#all(Task task)
*/
protected List<ComputingNode> allNodesList;
不包括无计算能力边缘设备的列表
/**
* A list that contains all generated nodes (sensors excluded)
*
* @see com.mechalikh.pureedgesim.taskorchestrator.Orchestrator#all(Task task)
*/
protected List<ComputingNode> allNodesListSensorsExcluded;
构造函数
/**
* Constructs a new instance of the computing nodes generator.
*
* @param simulationManager The simulation manager to use.
* @param mobilityModelClass The mobility model to use.
* @param computingNodeClass The computing node class to use.
*/
public ComputingNodesGenerator(SimulationManager simulationManager,
Class<? extends MobilityModel> mobilityModelClass, Class<? extends ComputingNode> computingNodeClass) {
this.simulationManager = simulationManager;
this.mobilityModelClass = mobilityModelClass;
this.computingNodeClass = computingNodeClass;
this.orchestratorsList = new ArrayList<>(simulationManager.getScenario().getDevicesCount());
this.mistOnlyList = new ArrayList<>(simulationManager.getScenario().getDevicesCount());
this.mistOnlyListSensorsExcluded = new ArrayList<>(simulationManager.getScenario().getDevicesCount());
this.mistAndCloudListSensorsExcluded = new ArrayList<>(
simulationManager.getScenario().getDevicesCount() + SimulationParameters.numberOfCloudDataCenters);
this.mistAndEdgeListSensorsExcluded = new ArrayList<>(
simulationManager.getScenario().getDevicesCount() + SimulationParameters.numberOfEdgeDataCenters);
this.allNodesList = new ArrayList<>(simulationManager.getScenario().getDevicesCount()
+ SimulationParameters.numberOfEdgeDataCenters + SimulationParameters.numberOfCloudDataCenters);
this.allNodesListSensorsExcluded = new ArrayList<>(simulationManager.getScenario().getDevicesCount()
+ SimulationParameters.numberOfEdgeDataCenters + SimulationParameters.numberOfCloudDataCenters);
}
生成所有节点
/**
* Generates all computing nodes, including the Cloud data centers, the edge
* ones, and the edge devices.
*/
public void generateDatacentersAndDevices() {
// Generate Edge and Cloud data centers.
generateDataCenters(SimulationParameters.cloudDataCentersFile, SimulationParameters.TYPES.CLOUD);
generateDataCenters(SimulationParameters.edgeDataCentersFile, SimulationParameters.TYPES.EDGE_DATACENTER);
// Generate edge devices.
generateEdgeDevices();
getSimulationManager().getSimulationLogger().print("%s - Datacenters and devices were generated",
getClass().getSimpleName());
}
生成所有边缘设备
/**
* Generates edge devices
*/
public void generateEdgeDevices() {
// Generate edge devices instances from edge devices types in xml file.
try (InputStream devicesFile = new FileInputStream(SimulationParameters.edgeDevicesFile)) {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
// Disable access to external entities in XML parsing, by disallowing DocType
// declaration
dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(devicesFile);
NodeList nodeList = doc.getElementsByTagName("device");
Element edgeElement = null;
// Load all devices types in edge_devices.xml file.
for (int i = 0; i < nodeList.getLength(); i++) {
Node edgeNode = nodeList.item(i);
edgeElement = (Element) edgeNode;
generateDevicesInstances(edgeElement);
}
// if percentage of generated devices is < 100%.
if (mistOnlyList.size() < getSimulationManager().getScenario().getDevicesCount())
getSimulationManager().getSimulationLogger().print(
"%s - Wrong percentages values (the sum is inferior than 100%), check edge_devices.xml file !",
getClass().getSimpleName());
// Add more devices.
if (edgeElement != null) {
int missingInstances = getSimulationManager().getScenario().getDevicesCount() - mistOnlyList.size();
for (int k = 0; k < missingInstances; k++) {
ComputingNode newDevice = createComputingNode(edgeElement, SimulationParameters.TYPES.EDGE_DEVICE);
insertEdgeDevice(newDevice);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
将新产生的边缘设备放入列表
/**
* Puts the newly generated edge device in corresponding lists.
*/
protected void insertEdgeDevice(ComputingNode newDevice) {
mistOnlyList.add(newDevice);
allNodesList.add(newDevice);
if (!newDevice.isSensor()) {
mistOnlyListSensorsExcluded.add(newDevice);
mistAndCloudListSensorsExcluded.add(newDevice);
mistAndEdgeListSensorsExcluded.add(newDevice);
allNodesListSensorsExcluded.add(newDevice);
}
}
产生边缘设备实例
/**
* Generates the required number of instances for each type of edge devices.
*
* @param type The type of edge devices.
*/
protected void generateDevicesInstances(Element type) {
int instancesPercentage = Integer.parseInt(type.getElementsByTagName("percentage").item(0).getTextContent());
// Find the number of instances of this type of devices
int devicesInstances = getSimulationManager().getScenario().getDevicesCount() * instancesPercentage / 100;
for (int j = 0; j < devicesInstances; j++) {
if (mistOnlyList.size() > getSimulationManager().getScenario().getDevicesCount()) {
getSimulationManager().getSimulationLogger().print(
"%s - Wrong percentages values (the sum is superior than 100%%), check edge_devices.xml file !",
getClass().getSimpleName());
break;
}
try {
insertEdgeDevice(createComputingNode(type, SimulationParameters.TYPES.EDGE_DEVICE));
} catch (NoSuchAlgorithmException | NoSuchMethodException | SecurityException | InstantiationException
| IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
产生云和边缘数据中心
/**
* Generates the Cloud and Edge data centers.
*
* @param file The configuration file.
* @param type The type, whether a CLOUD data center or an EDGE one.
*/
protected void generateDataCenters(String file, TYPES type) {
// Fill list with edge data centers
try (InputStream serversFile = new FileInputStream(file)) {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
// Disable access to external entities in XML parsing, by disallowing DocType
// declaration
dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(serversFile);
NodeList datacenterList = doc.getElementsByTagName("datacenter");
for (int i = 0; i < datacenterList.getLength(); i++) {
Element datacenterElement = (Element) datacenterList.item(i);
ComputingNode computingNode = createComputingNode(datacenterElement, type);
if (computingNode.getType() == TYPES.CLOUD) {
cloudOnlyList.add(computingNode);
mistAndCloudListSensorsExcluded.add(computingNode);
if (SimulationParameters.enableOrchestrators
&& SimulationParameters.deployOrchestrators == "CLOUD") {
orchestratorsList.add(computingNode);
}
} else {
edgeOnlyList.add(computingNode);
mistAndEdgeListSensorsExcluded.add(computingNode);
if (SimulationParameters.enableOrchestrators
&& SimulationParameters.deployOrchestrators == "EDGE") {
orchestratorsList.add(computingNode);
}
}
allNodesList.add(computingNode);
allNodesListSensorsExcluded.add(computingNode);
edgeAndCloudList.add(computingNode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
创建计算节点
/**
* Creates the computing nodes.
*
* @see #generateDataCenters(String, TYPES)
* @see #generateDevicesInstances(Element)
*
* @param datacenterElement The configuration file.
* @param type The type, whether an MIST (edge) device, an EDGE
* data center, or a CLOUD one.
* @throws NoSuchAlgorithmException
* @throws SecurityException
* @throws NoSuchMethodException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws InstantiationException
*/
protected ComputingNode createComputingNode(Element datacenterElement, SimulationParameters.TYPES type)
throws NoSuchAlgorithmException, NoSuchMethodException, SecurityException, InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// SecureRandom is preferred to generate random values.
Random random = SecureRandom.getInstanceStrong();
Boolean mobile = false;
double speed = 0;
double minPauseDuration = 0;
double maxPauseDuration = 0;
double minMobilityDuration = 0;
double maxMobilityDuration = 0;
int xPosition = -1;
int yPosition = -1;
double idleConsumption = Double
.parseDouble(datacenterElement.getElementsByTagName("idleConsumption").item(0).getTextContent());
double maxConsumption = Double
.parseDouble(datacenterElement.getElementsByTagName("maxConsumption").item(0).getTextContent());
Location datacenterLocation = new Location(xPosition, yPosition);
int numOfCores = Integer.parseInt(datacenterElement.getElementsByTagName("cores").item(0).getTextContent());
double mips = Double.parseDouble(datacenterElement.getElementsByTagName("mips").item(0).getTextContent());
double storage = Double.parseDouble(datacenterElement.getElementsByTagName("storage").item(0).getTextContent());
double ram = Double.parseDouble(datacenterElement.getElementsByTagName("ram").item(0).getTextContent());
Constructor<?> datacenterConstructor = computingNodeClass.getConstructor(SimulationManager.class, double.class,
int.class, double.class, double.class);
ComputingNode computingNode = (ComputingNode) datacenterConstructor.newInstance(getSimulationManager(), mips,
numOfCores, storage, ram);
computingNode.setAsOrchestrator(Boolean
.parseBoolean(datacenterElement.getElementsByTagName("isOrchestrator").item(0).getTextContent()));
if (computingNode.isOrchestrator())
orchestratorsList.add(computingNode);
computingNode.setEnergyModel(new EnergyModelComputingNode(maxConsumption, idleConsumption));
if (type == SimulationParameters.TYPES.EDGE_DATACENTER) {
String name = datacenterElement.getAttribute("name");
computingNode.setName(name);
Element location = (Element) datacenterElement.getElementsByTagName("location").item(0);
xPosition = Integer.parseInt(location.getElementsByTagName("x_pos").item(0).getTextContent());
yPosition = Integer.parseInt(location.getElementsByTagName("y_pos").item(0).getTextContent());
datacenterLocation = new Location(xPosition, yPosition);
for (int i = 0; i < edgeOnlyList.size(); i++)
if (datacenterLocation.equals(edgeOnlyList.get(i).getMobilityModel().getCurrentLocation()))
throw new IllegalArgumentException(
" Each Edge Data Center must have a different location, check the \"edge_datacenters.xml\" file!");
computingNode.setPeriphery(
Boolean.parseBoolean(datacenterElement.getElementsByTagName("periphery").item(0).getTextContent()));
} else if (type == SimulationParameters.TYPES.EDGE_DEVICE) {
mobile = Boolean.parseBoolean(datacenterElement.getElementsByTagName("mobility").item(0).getTextContent());
speed = Double.parseDouble(datacenterElement.getElementsByTagName("speed").item(0).getTextContent());
minPauseDuration = Double
.parseDouble(datacenterElement.getElementsByTagName("minPauseDuration").item(0).getTextContent());
maxPauseDuration = Double
.parseDouble(datacenterElement.getElementsByTagName("maxPauseDuration").item(0).getTextContent());
minMobilityDuration = Double.parseDouble(
datacenterElement.getElementsByTagName("minMobilityDuration").item(0).getTextContent());
maxMobilityDuration = Double.parseDouble(
datacenterElement.getElementsByTagName("maxMobilityDuration").item(0).getTextContent());
computingNode.getEnergyModel().setBattery(
Boolean.parseBoolean(datacenterElement.getElementsByTagName("battery").item(0).getTextContent()));
computingNode.getEnergyModel().setBatteryCapacity(Double
.parseDouble(datacenterElement.getElementsByTagName("batteryCapacity").item(0).getTextContent()));
computingNode.getEnergyModel().setIntialBatteryPercentage(Double.parseDouble(
datacenterElement.getElementsByTagName("initialBatteryLevel").item(0).getTextContent()));
computingNode.getEnergyModel().setConnectivityType(
datacenterElement.getElementsByTagName("connectivity").item(0).getTextContent());
computingNode.enableTaskGeneration(Boolean
.parseBoolean(datacenterElement.getElementsByTagName("generateTasks").item(0).getTextContent()));
// Generate random location for edge devices
datacenterLocation = new Location(random.nextInt(SimulationParameters.simulationMapLength),
random.nextInt(SimulationParameters.simulationMapLength));
getSimulationManager().getSimulationLogger()
.deepLog("ComputingNodesGenerator- Edge device:" + mistOnlyList.size() + " location: ( "
+ datacenterLocation.getXPos() + "," + datacenterLocation.getYPos() + " )");
}
computingNode.setType(type);
Constructor<?> mobilityConstructor = mobilityModelClass.getConstructor(SimulationManager.class, Location.class);
MobilityModel mobilityModel = ((MobilityModel) mobilityConstructor.newInstance(simulationManager,
datacenterLocation)).setMobile(mobile).setSpeed(speed).setMinPauseDuration(minPauseDuration)
.setMaxPauseDuration(maxPauseDuration).setMinMobilityDuration(minMobilityDuration)
.setMaxMobilityDuration(maxMobilityDuration);
computingNode.setMobilityModel(mobilityModel);
return computingNode;
}
返回所有被设为编排器的计算机节点列表
/**
* Returns the list containing computing nodes that have been selected as
* orchestrators (i.e. to make offloading decisions).
*
* @return The list of orchestrators
*/
public List<ComputingNode> getOrchestratorsList() {
return orchestratorsList;
}
返回SimulationManager
/**
* Returns the simulation Manager.
*
* @return The simulation manager
*/
public SimulationManager getSimulationManager() {
return simulationManager;
}
得到所有的设备列表
/**
* Gets the list containing all generated computing nodes.
*
* @see #generateDatacentersAndDevices()
*
* @return the list containing all generated computing nodes.
*/
public List<ComputingNode> getAllNodesList() {
return this.allNodesList;
}
得到边缘设备(包括传感器)
/**
* Gets the list containing all generated edge devices including sensors (i.e.,
* devices with no computing resources).
*
* @see #generateDevicesInstances(Element)
*
* @return the list containing all edge devices including sensors.
*/
public List<ComputingNode> getMistOnlyList() {
return this.mistOnlyList;
}
返回所有边缘数据中心
/**
* Gets the list containing all generated edge data centers / servers.
*
* @see #generateDataCenters(String, TYPES)
*
* @return the list containing all edge data centers and servers.
*/
public List<ComputingNode> getEdgeOnlyList() {
return this.edgeOnlyList;
}
返回所有云数据中心
/**
* Gets the list containing only cloud data centers.
*
* @see #generateDataCenters(String, TYPES)
*
* @return the list containing all generated cloud data centers.
*/
public List<ComputingNode> getCloudOnlyList() {
return this.cloudOnlyList;
}
得到边缘设备(不包括传感器)和云数据中心
/**
* Gets the list containing cloud data centers and edge devices (except
* sensors).
*
* @see #generateDataCenters(String, TYPES)
* @see #generateDevicesInstances(Element)
*
* @return the list containing cloud data centers and edge devices.
*/
public List<ComputingNode> getMistAndCloudListSensorsExcluded() {
return this.mistAndCloudListSensorsExcluded;
}
返回云和边缘计算中心
/**
* Gets the list containing cloud and edge data centers.
*
* @see #generateDataCenters(String, TYPES)
*
* @return the list containing cloud and edge data centers.
*/
public List<ComputingNode> getEdgeAndCloudList() {
return this.edgeAndCloudList;
}
返回边缘数据中心和
/**
* Gets the list containing edge data centers and edge devices (except sensors).
*
* @see #generateDataCenters(String, TYPES)
* @see #generateDevicesInstances(Element)
*
* @return the list containing edge data centers and edge devices.
*/
public List<ComputingNode> getMistAndEdgeListSensorsExcluded() {
return this.mistAndEdgeListSensorsExcluded;
}
返回所有边缘设备(不包括传感器)
/**
* Gets the list containing all generated edge devices except sensors (i.e.,
* devices with no computing resources).
*
* @see #generateDevicesInstances(Element)
*
* @return the list containing all edge devices except sensors.
*/
public List<ComputingNode> getMistOnlyListSensorsExcluded() {
return this.mistOnlyListSensorsExcluded;
}
返回所有计算中心和设备(不包括传感器)
/**
* Gets the list containing all computing nodes (except sensors).
*
* @see #generateDataCenters(String, TYPES)
* @see #generateDevicesInstances(Element)
*
* @return the list containing all data centers and devices except sensors.
*/
public List<ComputingNode> getAllNodesListSensorsExcluded() {
return this.allNodesListSensorsExcluded;
}