source: DCWoRMS/trunk/build/classes/schedframe/resources/computing/description/ComputingResourceDescription.java @ 477

Revision 477, 11.6 KB checked in by wojtekp, 13 years ago (diff)
  • Property svn:mime-type set to text/plain
RevLine 
[477]1package schedframe.resources.computing.description;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import schedframe.Parameter;
7import schedframe.Parameters;
8import schedframe.Property;
9import schedframe.resources.ResourceTypeFactory;
10import schedframe.resources.computing.location.Location;
11import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile;
12import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState;
13import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirThroughputEstimationPlugin;
14import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirThroughputEstimationPlugin;
15import schedframe.resources.computing.profiles.energy.power.PState;
16import schedframe.resources.computing.profiles.energy.power.PowerProfile;
17import schedframe.resources.computing.profiles.energy.power.PowerState;
18import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory;
19import schedframe.resources.computing.profiles.energy.power.Transition;
20import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin;
21import schedframe.resources.units.ResourceUnit;
22import schedframe.resources.units.ResourceUnitFactory;
23import schedframe.resources.utils.ResourceIdGenerator;
24import schemas.ComputingResource;
25import schemas.Profile;
26import simulator.utils.InstanceFactory;
27import example.energy.DefaultEnergyEstimationPlugin;
28
29public class ComputingResourceDescription extends ExecutingResourceDescription {
30
31        //protected Map<ResourceUnitName, List<AbstractResourceUnit>> resUnits;
32        protected PowerProfile powerProfile;
33        protected AirThroughputProfile airThroughputProfile;
34        protected Location location;
35        //protected Parameters parameters;
36
37        public ComputingResourceDescription(ComputingResource computingResource) {
38
39                super(ResourceTypeFactory.createResourceType(computingResource.getClazz()));
40
41                initId(computingResource);
42
43                if (computingResource.getComputingResourceTypeChoiceSequence() != null) {
44                        initResourceUnits(computingResource.getComputingResourceTypeChoiceSequence().getResourceUnit());
45                        initProfiles(computingResource.getComputingResourceTypeChoiceSequence().getProfile());
46                        initLocation(computingResource.getComputingResourceTypeChoiceSequence().getLocation());
47                        this.parameters = extractParameters(computingResource.getComputingResourceTypeChoiceSequence().getParameter());
48                }
49        }
50
51        private void initId(ComputingResource computingResource){
52                this.id = computingResource.getName() != null ? computingResource.getName() : type.toString();
53                if(computingResource.getCount() > 1 || computingResource.getName() == null){
54                        this.id = id + "_" + String.valueOf(ResourceIdGenerator.getId(type));
55                }
56        }
57       
58        private void initResourceUnits(schemas.ResourceUnit[] resourceUnitCharacteristics) {
59                for (int i = 0; i < resourceUnitCharacteristics.length; i++) {
60                        schemas.ResourceUnit resourceUnitCharacteristic = resourceUnitCharacteristics[i];
61                        ResourceUnit resourceUnit = ResourceUnitFactory.createUnit(resourceUnitCharacteristic.getClazz(), this.id,
62                                         Double.valueOf(resourceUnitCharacteristic.getAmount().getContent()).intValue(), 0);
63                        Parameters params = extractParameters(resourceUnitCharacteristic.getParameter());
64                        resourceUnit.init(params);
65                        addResourceUnit(resourceUnit);
66                }
67        }
68
69        private void initProfiles(Profile profile) {
70                if (profile != null) {
71                        initPowerProfile(profile.getPowerProfile());
72                        initAirThroughputProfile(profile.getAirThroughputProfile());
73                }
74        }
75       
76        private void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) {
77               
78                if (powerProfileCharacteristic != null) {
79                        EnergyEstimationPlugin energyEstimationPlugin = null;
80                        List<PowerState> powerStates = null;
81                        List<PState> pStates = null;
82                        if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){
83                                String  energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName();
84                                if(energyEstimationPluginName != null) {
85                                        energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance(
86                                                        energyEstimationPluginName, EnergyEstimationPlugin.class);                     
87                                } else {
88                                        energyEstimationPlugin = new DefaultEnergyEstimationPlugin();
89                                }
90                                Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter());
91                                energyEstimationPlugin.init(params);
92                        }
93                       
94                        if (powerProfileCharacteristic.getPowerStates() != null) {
95                                powerStates = new ArrayList<PowerState>();
96                                int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount();
97                                for (int i = 0; i < powerStateCount ; i++) {
98                                        schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i);
99                                        List<Transition> transitions = new ArrayList<Transition>();
100                                        int transitionCount = ps.getTransitionCount();
101                                        for (int j = 0; j < transitionCount; j++) {
102                                                schemas.Transition t = ps.getTransition(j);
103                                                Transition transition = new Transition(PowerStateNameFactory.createPowerStateName(t.getTo()), t
104                                                                .getPowerUsage().getContent(), t.getTime().getContent());
105                                                Parameters params = extractParameters(t.getParameter());
106                                                transition.init(params);
107                                                transitions.add(transition);
108                                        }
109                                        PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps
110                                                        .getPowerUsage().getContent(), transitions);
111                                        Parameters params = extractParameters(ps.getParameter());
112                                        powerState.init(params);
113                                        powerStates.add(powerState);
114                                }
115                        }
116                       
117                        if(powerProfileCharacteristic.getParameter() != null){
118                                pStates = new ArrayList<PState>();
119                                int parameterCount =  powerProfileCharacteristic.getParameterCount();
120                                for(int i = 0; i < parameterCount; i++){
121                                        schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i);
122                                        if(parameter.getName().equals("pState")){
123                                                PState.Builder builder =  new PState.Builder();
124                                                int propertyCount = parameter.getParameterTypeSequence().getPropertyCount();
125                                                for(int j = 0; j < propertyCount; j++){
126                                                        schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);
127                                                        if(property.getName().equals("name")){
128                                                                 builder = builder.name(property.getStringValueWithUnit(0).getContent());
129                                                        } else if (property.getName().equals("frequency")){
130                                                                 builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent()));
131                                                        } else if (property.getName().equals("voltage")){
132                                                                builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent()));
133                                                        } else if (property.getName().equals("powerUsage")){
134                                                                builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent()));
135                                                        }
136                                                }
137                                                PState pState = builder.build();
138                                                pStates.add(pState);
139                                        }
140                                }       
141                        }
142                        this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates);
143                        Parameters params = extractParameters(powerProfileCharacteristic.getParameter());
144                        this.powerProfile.init(params);
145                }
146        }
147
148        private void initAirThroughputProfile(schemas.AirThroughputProfile airThroughputProfile) {
149                if (airThroughputProfile != null) {
150                       
151                        AirThroughputEstimationPlugin airThroughputEstimationPlugin = null;
152                        List<AirThroughputState> airThroughputStates = null;
153                        if(airThroughputProfile.getAirThroughputEstimationPlugin() != null){
154                                String airThroughputEstimationPluginName = airThroughputProfile.getAirThroughputEstimationPlugin().getName();
155                                if(airThroughputEstimationPluginName != null) {
156                                        airThroughputEstimationPlugin = (AirThroughputEstimationPlugin) InstanceFactory.createInstance(
157                                                        airThroughputEstimationPluginName, AirThroughputEstimationPlugin.class);                       
158                                } else {
159                                        airThroughputEstimationPlugin = new DefaultAirThroughputEstimationPlugin();
160                                }
161                                Parameters params = extractParameters(airThroughputProfile.getAirThroughputEstimationPlugin().getParameter());
162                                airThroughputEstimationPlugin.init(params);
163                        }
164                        if(airThroughputProfile.getAirThroughputStates() != null){
165                                airThroughputStates = new ArrayList<AirThroughputState>();
166                                int airThrouhputStateCount =  airThroughputProfile.getAirThroughputStates().getAirThroughputStateCount();
167                                for (int i = 0; i < airThrouhputStateCount; i++) {
168                                        schemas.AirThroughputState ats = airThroughputProfile.getAirThroughputStates().getAirThroughputState(i);
169                                        AirThroughputState airThroughputState = new AirThroughputState(ats.getName(), ats.getValue()
170                                                        .getContent(), ats.getPowerUsage().getContent());
171                                        Parameters params = extractParameters(ats.getParameter());
172                                        airThroughputState.init(params);
173                                        airThroughputStates.add(airThroughputState);
174                                }
175                        }
176                        this.airThroughputProfile = new AirThroughputProfile(airThroughputEstimationPlugin, airThroughputStates);
177                        Parameters params = extractParameters(airThroughputProfile.getParameter());
178                        this.airThroughputProfile.init(params);
179                }
180        }
181       
182        private void initLocation(schemas.Location l) {
183                if (location != null) {
184                        this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth());
185                        Parameters params = extractParameters(l.getParameter());
186                        this.location.init(params);
187                }
188        }
189
190
191
192        /*private Properties initProperties(schemas.Parameter[] parameters){
193                Properties prop = new Properties();
194               
195                for(int i = 0; i < parameters.length; i++){
196                        schemas.Parameter parameter = parameters[i];
197                        List values = new ArrayList();
198                        if(parameter.getParameterTypeSequence().getProperty() != null)
199                        {
200                                Map<String, List<StringValueWithUnit>> properties = new HashMap<String, List<StringValueWithUnit>>();
201                                List<StringValueWithUnit> propValues = new ArrayList<StringValueWithUnit>();
202                                for(int j = 0; j < parameter.getParameterTypeSequence().getPropertyCount(); j++){
203                                        schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);
204                                        for(int k = 0; k < property.getStringValueWithUnitCount(); k++){
205                                                propValues.add(property.getStringValueWithUnit(k));
206                                        }
207                                        properties.put(property.getName(), propValues);
208                                }
209                                values.add(properties);
210                        }else {
211                                for(int j = 0; j < parameter.getStringValueWithUnitCount(); j++){
212                                        values.add(parameter.getStringValueWithUnit(j));
213                                }
214                        }
215                        prop.put(parameter.getName(), values);
216                }
217                return prop;
218        }*/
219       
220        private Parameters extractParameters(schemas.Parameter[] parameters){
221               
222                Parameters params = null;
223               
224                if(parameters.length != 0)
225                        params = new Parameters();
226               
227                for(int i = 0; i < parameters.length; i++){
228                        schemas.Parameter parameter = parameters[i];
229                        Parameter param = new Parameter(parameter.getName());
230                        if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null)
231                        {                                                       
232                                int propertyCount = parameter.getParameterTypeSequence().getPropertyCount();
233                                for(int j = 0; j < propertyCount; j++){
234                                        schemas.Property property = parameter.getParameterTypeSequence().getProperty(j);
235                                        Property prop = new Property(property.getName());
236                                        int stringValueWithUnitCount = property.getStringValueWithUnitCount();
237                                        for(int k = 0; k < stringValueWithUnitCount; k++){
238                                                prop.add(property.getStringValueWithUnit(k));
239                                        }
240                                        param.addProperty(prop);
241                                }
242                        } else {
243                                int stringValueWithUnitCount =  parameter.getStringValueWithUnitCount();
244                                for(int j = 0; j < stringValueWithUnitCount; j++){
245                                        param.add(parameter.getStringValueWithUnit(j));
246                                }
247                        }
248                        params.put(parameter.getName(), param);
249                }
250                return params;
251        }
252
253        public PowerProfile getPowerProfile() {
254                return powerProfile;
255        }
256
257        public AirThroughputProfile getAirThroughputProfile() {
258                return airThroughputProfile;
259        }
260
261        public Location getLocation() {
262                return location;
263        }
264
265
266
267}
Note: See TracBrowser for help on using the repository browser.