-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDefaultZoneHandler.java
142 lines (114 loc) · 4.85 KB
/
DefaultZoneHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* cloudsim-express
* Copyright (C) 2023 CLOUDS Lab
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cloudbus.cloudsim.express.handler.impl.cloudsim;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.express.handler.ElementHandler;
import org.cloudbus.cloudsim.express.handler.impl.BaseElementHandler;
import org.cloudbus.cloudsim.express.resolver.ExtensionsResolver;
import org.cloudbus.cloudsim.express.resolver.environment.definitions.model.Broker;
import org.cloudbus.cloudsim.express.resolver.environment.definitions.model.Extension;
import org.cloudbus.cloudsim.express.resolver.environment.definitions.model.WorkloadGenerator;
import org.cloudbus.cloudsim.express.resolver.environment.definitions.model.Zone;
import org.crunchycookie.research.distributed.computing.cloudsim.workload.CloudSimWorkloadGenerator;
import java.util.List;
/**
* This class handles the {@link Zone} DTO.
*/
public class DefaultZoneHandler extends BaseElementHandler {
public static final String KEY_ZONE_ID = "DATACENTER";
public static final String KEY_ZONE_NAME = "ZONE_NAME";
public static final String RECEIVED_CLOUDLETS = "RECEIVED_CLOUDLETS";
protected Zone zoneDTO;
protected int zoneId;
protected String name;
protected DatacenterBroker broker;
protected CloudSimWorkloadGenerator generator;
protected Datacenter datacenter;
protected List<Cloudlet> completedCloudlets;
@Override
public void init(Object componentDTO, ExtensionsResolver resolver) {
super.init(componentDTO, resolver);
this.zoneDTO = (Zone) componentDTO;
}
@Override
public void handle() {
this.name = zoneDTO.getName();
this.generator = getWorkloadGenerator();
this.broker = getBroker();
this.datacenter = getDatacenter();
List<Cloudlet> cloudletList = generator.getCloudletsList();
cloudletList.forEach(cloudlet -> cloudlet.setUserId(broker.getId()));
// // TODO: 27/3/23 Broker ID should be handled by the zone handler, rather than passing it to the generator.
List<Vm> vmList = generator.getVmList(broker.getId());
// Submit to the broker.
broker.submitVmList(vmList);
broker.submitCloudletList(cloudletList);
}
@Override
public boolean isSimulated() {
// A blocking operation.
this.completedCloudlets = this.broker.getCloudletReceivedList();
return true;
}
@Override
public boolean canHandle(Object componentDTO) {
return componentDTO instanceof Zone;
}
@Override
public Object getProperty(String key) {
return switch (key) {
case KEY_ZONE_ID -> this.zoneId;
case KEY_ZONE_NAME -> this.name;
case RECEIVED_CLOUDLETS -> this.completedCloudlets;
default -> null;
};
}
protected CloudSimWorkloadGenerator getWorkloadGenerator() {
WorkloadGenerator generatorDTO = zoneDTO.getWorkloadGenerator();
Extension generatorVariant = generatorDTO.getVariant();
return (CloudSimWorkloadGenerator) this.getResolver().getExtension(
generatorVariant.getClassName(),
new Class[]{},
new Object[]{},
getExtensionProperties(generatorVariant)
);
}
protected DatacenterBroker getBroker() {
Broker brokerDTO = zoneDTO.getBroker();
Extension brokerVariant = brokerDTO.getVariant();
return (DatacenterBroker) this.getResolver().getExtension(
brokerVariant.getClassName(),
new Class[]{String.class},
new Object[]{brokerDTO.getName()},
getExtensionProperties(brokerVariant)
);
}
protected Datacenter getDatacenter() {
ElementHandler handler = getHandler(zoneDTO.getDatacenter());
handler.init(zoneDTO.getDatacenter(), this.resolver);
handler.handle();
org.cloudbus.cloudsim.Datacenter datacenter = (org.cloudbus.cloudsim.Datacenter) handler.getProperty(
DefaultDatacenterHandler.KEY_DATACENTER
);
this.zoneId = datacenter.getId();
return datacenter;
}
}