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

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