source: DCWoRMS/branches/coolemall/src/schedframe/resources/devices/description/PhysicalResourceDescription.java @ 1317

Revision 1317, 13.4 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package schedframe.resources.devices.description;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import schedframe.Parameter;
7import schedframe.Parameters;
8import schedframe.Property;
9import schedframe.resources.ResourceType;
10import schedframe.resources.computing.description.ResourceDescription;
11import schedframe.resources.computing.location.Location;
12import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile;
13import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState;
14import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirThroughputEstimationPlugin;
15import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirThroughputEstimationPlugin;
16import schedframe.resources.computing.profiles.energy.power.PState;
17import schedframe.resources.computing.profiles.energy.power.PowerProfile;
18import schedframe.resources.computing.profiles.energy.power.PowerState;
19import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory;
20import schedframe.resources.computing.profiles.energy.power.Transition;
21import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin;
22import schedframe.resources.computing.profiles.energy.thermal.ThermalProfile;
23import schedframe.resources.computing.profiles.energy.thermal.plugin.DefaultTemperatureEstimationPlugin;
24import schedframe.resources.computing.profiles.energy.thermal.plugin.TemperatureEstimationPlugin;
25import schedframe.resources.computing.profiles.load.LoadEstimationPluginFactory;
26import schedframe.resources.computing.profiles.load.LoadProfile;
27import schedframe.resources.computing.profiles.load.ResourceLoadCalendar;
28import schedframe.resources.computing.profiles.load.plugin.LoadEstimationPlugin;
29import schemas.PowerUsage;
30import schemas.Profile;
31import simulator.utils.InstanceFactory;
32import example.energy.DefaultEnergyEstimationPlugin;
33import example.load.DefaultLoadEstimationPlugin;
34
35public class PhysicalResourceDescription extends ResourceDescription{
36
37        protected PowerProfile powerProfile;
38        protected AirThroughputProfile airThroughputProfile;
39        protected ThermalProfile thermalProfile;
40        protected LoadProfile loadProfile;
41       
42        protected String category;
43        protected Location location;
44       
45        public PhysicalResourceDescription(ResourceType type) {
46                super(type);
47                // TODO Auto-generated constructor stub
48        }
49
50        public void addChildren(PhysicalResourceDescription child) {
51                super.addChildren(child);
52                if(child.getLoadProfile().getLoadCalendar().getLoadDistribution().size() == 0){
53                        child.getLoadProfile().getLoadCalendar().getLoadDistribution().addAll(this.getLoadProfile().getLoadCalendar().getLoadDistribution());
54                }
55        }
56       
57        protected void initProfiles(Profile profile) {
58                if (profile != null) {
59                        initPowerProfile(profile.getPowerProfile());
60                        initAirThroughputProfile(profile.getAirThroughputProfile());
61                        initThermalProfile(profile.getThermalProfile());
62                        initLoadProfile(profile.getLoadProfile());
63                } else {
64                        initLoadProfile(null);
65                }
66        }
67       
68        protected void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) {
69               
70                if (powerProfileCharacteristic != null) {
71                        EnergyEstimationPlugin energyEstimationPlugin = null;
72                        List<PowerState> powerStates = null;
73                        List<PState> pStates = null;
74                        if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){
75                                String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName();
76                                if(energyEstimationPluginName != null) {
77                                        energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance(
78                                                        energyEstimationPluginName, EnergyEstimationPlugin.class);                     
79                                } else {
80                                        energyEstimationPlugin = new DefaultEnergyEstimationPlugin();
81                                }
82                                Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter());
83                                energyEstimationPlugin.init(params);
84                        }
85                       
86                        if(powerProfileCharacteristic.getPowerStates() != null) {
87                                powerStates = new ArrayList<PowerState>();
88                                int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount();
89                                for (int i = 0; i < powerStateCount ; i++) {
90                                        schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i);
91                                        List<Transition> transitions = new ArrayList<Transition>();
92                                        int transitionCount = ps.getTransitionCount();
93                                        for (int j = 0; j < transitionCount; j++) {
94                                                schemas.Transition t = ps.getTransition(j);
95                                                Transition transition = new Transition(PowerStateNameFactory.createPowerStateName(t.getTo()), t
96                                                                .getPowerUsage().getContent(), t.getTime().getContent());
97                                                Parameters params = extractParameters(t.getParameter());
98                                                transition.init(params);
99                                                transitions.add(transition);
100                                        }
101                                        //CoolEmAll DEBB description case
102                                        if(ps.getPowerUsage() == null){
103                                                ps.setPowerUsage(new PowerUsage("0"));
104                                        }
105                                        PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps
106                                                        .getPowerUsage().getContent(), transitions);
107                                        Parameters params = extractParameters(ps.getParameter());
108                                        powerState.init(params);
109                                        powerStates.add(powerState);
110                                }
111                        }
112                       
113                        if(powerProfileCharacteristic.getParameter() != null){
114                                pStates = new ArrayList<PState>();
115                                int parameterCount = powerProfileCharacteristic.getParameterCount();
116                                for(int i = 0; i < parameterCount; i++){
117                                        schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i);
118                                        if(parameter.getName().equals("pState")){
119                                                PState.Builder builder = new PState.Builder();
120                                                int propertyCount = parameter.getParameterTypeSequence().getPropertyCount();
121                                                for(int j = 0; j < propertyCount; j++){
122                                                        schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);
123                                                        if(property.getName().equals("name")){
124                                                                 builder = builder.name(property.getStringValueWithUnit(0).getContent());
125                                                        } else if (property.getName().equals("frequency")){
126                                                                 builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent()));
127                                                        } else if (property.getName().equals("voltage")){
128                                                                builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent()));
129                                                        } else if (property.getName().equals("powerUsage")){
130                                                                if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0){
131                                                                        builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); 
132                                                                }
133                                                        } else if (property.getName().equals("loadPowerUsage")){
134                                                                if(property.getStringValueWithUnit(0).getContent() != null && property.getStringValueWithUnit(0).getContent().length() > 0 &&
135                                                                                property.getStringValueWithUnit(1).getContent() != null && property.getStringValueWithUnit(1).getContent().length() > 0){
136                                                                        //LoadPowerUsage lpu = new LoadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent()));
137                                                                        //builder = builder.loadPowerUsage(lpu);
138                                                                        builder.loadPowerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()), Double.valueOf(property.getStringValueWithUnit(1).getContent()));
139                                                                }
140                                                        }
141                                                }
142                                                PState pState = builder.build();
143                                                pStates.add(pState);
144                                        }
145                                }       
146                        }
147                        this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates);
148                        Parameters params = extractParameters(powerProfileCharacteristic.getParameter());
149                        this.powerProfile.init(params);
150                }
151        }
152
153        protected void initAirThroughputProfile(schemas.AirThroughputProfile airThroughputProfile) {
154                if (airThroughputProfile != null) {
155                       
156                        AirThroughputEstimationPlugin airThroughputEstimationPlugin = null;
157                        List<AirThroughputState> airThroughputStates = null;
158                        if(airThroughputProfile.getAirThroughputEstimationPlugin() != null){
159                                String airThroughputEstimationPluginName = airThroughputProfile.getAirThroughputEstimationPlugin().getName();
160                                if(airThroughputEstimationPluginName != null) {
161                                        airThroughputEstimationPlugin = (AirThroughputEstimationPlugin) InstanceFactory.createInstance(
162                                                        airThroughputEstimationPluginName, AirThroughputEstimationPlugin.class);                       
163                                } else {
164                                        airThroughputEstimationPlugin = new DefaultAirThroughputEstimationPlugin();
165                                }
166                                Parameters params = extractParameters(airThroughputProfile.getAirThroughputEstimationPlugin().getParameter());
167                                airThroughputEstimationPlugin.init(params);
168                        }
169                        if(airThroughputProfile.getAirThroughputStates() != null){
170                                airThroughputStates = new ArrayList<AirThroughputState>();
171                                int airThrouhputStateCount = airThroughputProfile.getAirThroughputStates().getAirThroughputStateCount();
172                                for (int i = 0; i < airThrouhputStateCount; i++) {
173                                        schemas.AirThroughputState ats = airThroughputProfile.getAirThroughputStates().getAirThroughputState(i);
174                                        AirThroughputState airThroughputState = new AirThroughputState(ats.getName(), ats.getValue()
175                                                        .getContent(), ats.getPowerUsage().getContent());
176                                        Parameters params = extractParameters(ats.getParameter());
177                                        airThroughputState.init(params);
178                                        airThroughputStates.add(airThroughputState);
179                                }
180                        }
181                        this.airThroughputProfile = new AirThroughputProfile(airThroughputEstimationPlugin, airThroughputStates);
182                        Parameters params = extractParameters(airThroughputProfile.getParameter());
183                        this.airThroughputProfile.init(params);
184                }
185        }
186       
187        protected void initThermalProfile(schemas.ThermalProfile thermalProfile) {
188               
189                if (thermalProfile != null) {
190                       
191                        TemperatureEstimationPlugin temperatureEstimationPlugin = null;
192
193                        if(thermalProfile.getTemperatureEstimationPlugin() != null){
194                                String temperatureEstimationPluginName = thermalProfile.getTemperatureEstimationPlugin().getName();
195                                if(temperatureEstimationPluginName != null) {
196                                        temperatureEstimationPlugin = (TemperatureEstimationPlugin) InstanceFactory.createInstance(
197                                                        temperatureEstimationPluginName, TemperatureEstimationPlugin.class);                   
198                                } else {
199                                        temperatureEstimationPlugin = new DefaultTemperatureEstimationPlugin();
200                                }
201                                Parameters params = extractParameters(thermalProfile.getTemperatureEstimationPlugin().getParameter());
202                                temperatureEstimationPlugin.init(params);
203                        }
204                        this.thermalProfile = new ThermalProfile();
205                        Parameters params = extractParameters(thermalProfile.getParameter());
206                        this.thermalProfile.init(params);
207                }
208        }
209       
210        protected void initLoadProfile(schemas.LoadProfile loadProfile) {
211               
212                if (loadProfile != null) {
213                       
214                        LoadEstimationPlugin loadEstimationPlugin = null;
215
216                        if(loadProfile.getLoadEstimationPlugin() != null){
217                                String loadEstimationPluginName = loadProfile.getLoadEstimationPlugin().getName();
218                                if(loadEstimationPluginName != null) {
219                                        loadEstimationPlugin = (LoadEstimationPlugin) InstanceFactory.createInstance(
220                                                        loadEstimationPluginName, LoadEstimationPlugin.class);                 
221                                } else {
222                                        loadEstimationPlugin = new DefaultLoadEstimationPlugin();
223                                }
224                                Parameters params = extractParameters(loadProfile.getLoadEstimationPlugin().getParameter());
225                                loadEstimationPlugin.init(params);
226                        }
227                        ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar(loadProfile.getLoadCalendar());
228                        this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander);
229                        Parameters params = extractParameters(loadProfile.getParameter());
230                        this.loadProfile.init(params);
231                } else {
232                        ResourceLoadCalendar resLoadCalander = new ResourceLoadCalendar();
233                        LoadEstimationPlugin loadEstimationPlugin = LoadEstimationPluginFactory.createLoadEstimationPlugi(getType());
234                        this.loadProfile = new LoadProfile(loadEstimationPlugin, resLoadCalander);
235                }
236        }
237       
238        protected void initLocation(schemas.Location l) {
239                if (location != null) {
240                        this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth());
241                        Parameters params = extractParameters(l.getParameter());
242                        this.location.init(params);
243                }
244        }
245
246        protected Parameters extractParameters(schemas.Parameter[] parameters){
247               
248                Parameters params = null;
249               
250                if(parameters.length != 0)
251                        params = new Parameters();
252               
253                for(int i = 0; i < parameters.length; i++){
254                        schemas.Parameter parameter = parameters[i];
255                        Parameter param = new Parameter(parameter.getName());
256                        if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null)
257                        {                                                       
258                                int propertyCount = parameter.getParameterTypeSequence().getPropertyCount();
259                                for(int j = 0; j < propertyCount; j++){
260                                        schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);
261                                        Property prop = new Property(property.getName());
262                                        int stringValueWithUnitCount = property.getStringValueWithUnitCount();
263                                        for(int k = 0; k < stringValueWithUnitCount; k++){
264                                                prop.add(property.getStringValueWithUnit(k));
265                                        }
266                                        param.addProperty(prop);
267                                }
268                        } else {
269                                int stringValueWithUnitCount =  parameter.getStringValueWithUnitCount();
270                                for(int j = 0; j < stringValueWithUnitCount; j++){
271                                        param.add(parameter.getStringValueWithUnit(j));
272                                }
273                        }
274                        params.put(parameter.getName(), param);
275                }
276                return params;
277        }
278       
279        public PowerProfile getPowerProfile() {
280                return powerProfile;
281        }
282
283        public AirThroughputProfile getAirThroughputProfile() {
284                return airThroughputProfile;
285        }
286
287        public ThermalProfile getThermalProfile() {
288                return thermalProfile;
289        }
290
291        public LoadProfile getLoadProfile() {
292                return loadProfile;
293        }
294       
295        public Location getLocation() {
296                return location;
297        }
298       
299        public String getCategory() {
300                return category;
301        }
302}
Note: See TracBrowser for help on using the repository browser.