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

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