package schedframe.resources.computing.description; import java.util.ArrayList; import java.util.List; import schedframe.Parameter; import schedframe.Parameters; import schedframe.Property; import schedframe.resources.ResourceTypeFactory; import schedframe.resources.computing.location.Location; import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputProfile; import schedframe.resources.computing.profiles.energy.airthroughput.AirThroughputState; import schedframe.resources.computing.profiles.energy.airthroughput.plugin.AirThroughputEstimationPlugin; import schedframe.resources.computing.profiles.energy.airthroughput.plugin.DefaultAirThroughputEstimationPlugin; import schedframe.resources.computing.profiles.energy.power.PState; import schedframe.resources.computing.profiles.energy.power.PowerProfile; import schedframe.resources.computing.profiles.energy.power.PowerState; import schedframe.resources.computing.profiles.energy.power.PowerStateNameFactory; import schedframe.resources.computing.profiles.energy.power.Transition; import schedframe.resources.computing.profiles.energy.power.plugin.EnergyEstimationPlugin; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitFactory; import schedframe.resources.utils.ResourceIdGenerator; import schemas.ComputingResource; import schemas.Profile; import simulator.utils.InstanceFactory; import example.energy.DefaultEnergyEstimationPlugin; public class ComputingResourceDescription extends ExecutingResourceDescription { //protected Map> resUnits; protected PowerProfile powerProfile; protected AirThroughputProfile airThroughputProfile; protected Location location; protected String category; //protected Parameters parameters; public ComputingResourceDescription(ComputingResource computingResource) { super(ResourceTypeFactory.createResourceType(computingResource.getClazz())); initId(computingResource); this.category = computingResource.getType(); if (computingResource.getComputingResourceTypeChoiceSequence() != null) { initResourceUnits(computingResource.getComputingResourceTypeChoiceSequence().getResourceUnit()); initProfiles(computingResource.getComputingResourceTypeChoiceSequence().getProfile()); initLocation(computingResource.getComputingResourceTypeChoiceSequence().getLocation()); this.parameters = extractParameters(computingResource.getComputingResourceTypeChoiceSequence().getParameter()); } } private void initId(ComputingResource computingResource){ this.id = computingResource.getName() != null ? computingResource.getName() : type.toString(); if(computingResource.getCount() > 1 || computingResource.getName() == null){ this.id = id + "_" + String.valueOf(ResourceIdGenerator.getId(type)); } } private void initResourceUnits(schemas.ResourceUnit[] resourceUnitCharacteristics) { for (int i = 0; i < resourceUnitCharacteristics.length; i++) { schemas.ResourceUnit resourceUnitCharacteristic = resourceUnitCharacteristics[i]; ResourceUnit resourceUnit = ResourceUnitFactory.createUnit(resourceUnitCharacteristic.getClazz(), this.id, Double.valueOf(resourceUnitCharacteristic.getAmount().getContent()).intValue(), 0); Parameters params = extractParameters(resourceUnitCharacteristic.getParameter()); resourceUnit.init(params); addResourceUnit(resourceUnit); } } private void initProfiles(Profile profile) { if (profile != null) { initPowerProfile(profile.getPowerProfile()); initAirThroughputProfile(profile.getAirThroughputProfile()); } } private void initPowerProfile(schemas.PowerProfile powerProfileCharacteristic) { if (powerProfileCharacteristic != null) { EnergyEstimationPlugin energyEstimationPlugin = null; List powerStates = null; List pStates = null; if(powerProfileCharacteristic.getEnergyEstimationPlugin() != null){ String energyEstimationPluginName = powerProfileCharacteristic.getEnergyEstimationPlugin().getName(); if(energyEstimationPluginName != null) { energyEstimationPlugin = (EnergyEstimationPlugin) InstanceFactory.createInstance( energyEstimationPluginName, EnergyEstimationPlugin.class); } else { energyEstimationPlugin = new DefaultEnergyEstimationPlugin(); } Parameters params = extractParameters(powerProfileCharacteristic.getEnergyEstimationPlugin().getParameter()); energyEstimationPlugin.init(params); } if (powerProfileCharacteristic.getPowerStates() != null) { powerStates = new ArrayList(); int powerStateCount = powerProfileCharacteristic.getPowerStates().getPowerStateCount(); for (int i = 0; i < powerStateCount ; i++) { schemas.PowerState ps = powerProfileCharacteristic.getPowerStates().getPowerState(i); List transitions = new ArrayList(); int transitionCount = ps.getTransitionCount(); for (int j = 0; j < transitionCount; j++) { schemas.Transition t = ps.getTransition(j); Transition transition = new Transition(PowerStateNameFactory.createPowerStateName(t.getTo()), t .getPowerUsage().getContent(), t.getTime().getContent()); Parameters params = extractParameters(t.getParameter()); transition.init(params); transitions.add(transition); } PowerState powerState = new PowerState(PowerStateNameFactory.createPowerStateName(ps.getName()), ps .getPowerUsage().getContent(), transitions); Parameters params = extractParameters(ps.getParameter()); powerState.init(params); powerStates.add(powerState); } } if(powerProfileCharacteristic.getParameter() != null){ pStates = new ArrayList(); int parameterCount = powerProfileCharacteristic.getParameterCount(); for(int i = 0; i < parameterCount; i++){ schemas.Parameter parameter = powerProfileCharacteristic.getParameter(i); if(parameter.getName().equals("pState")){ PState.Builder builder = new PState.Builder(); int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); for(int j = 0; j < propertyCount; j++){ schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); if(property.getName().equals("name")){ builder = builder.name(property.getStringValueWithUnit(0).getContent()); } else if (property.getName().equals("frequency")){ builder = builder.frequency(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } else if (property.getName().equals("voltage")){ builder = builder.voltage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } else if (property.getName().equals("powerUsage")){ builder = builder.powerUsage(Double.valueOf(property.getStringValueWithUnit(0).getContent())); } } PState pState = builder.build(); pStates.add(pState); } } } this.powerProfile = new PowerProfile(energyEstimationPlugin, powerStates, pStates); Parameters params = extractParameters(powerProfileCharacteristic.getParameter()); this.powerProfile.init(params); } } private void initAirThroughputProfile(schemas.AirThroughputProfile airThroughputProfile) { if (airThroughputProfile != null) { AirThroughputEstimationPlugin airThroughputEstimationPlugin = null; List airThroughputStates = null; if(airThroughputProfile.getAirThroughputEstimationPlugin() != null){ String airThroughputEstimationPluginName = airThroughputProfile.getAirThroughputEstimationPlugin().getName(); if(airThroughputEstimationPluginName != null) { airThroughputEstimationPlugin = (AirThroughputEstimationPlugin) InstanceFactory.createInstance( airThroughputEstimationPluginName, AirThroughputEstimationPlugin.class); } else { airThroughputEstimationPlugin = new DefaultAirThroughputEstimationPlugin(); } Parameters params = extractParameters(airThroughputProfile.getAirThroughputEstimationPlugin().getParameter()); airThroughputEstimationPlugin.init(params); } if(airThroughputProfile.getAirThroughputStates() != null){ airThroughputStates = new ArrayList(); int airThrouhputStateCount = airThroughputProfile.getAirThroughputStates().getAirThroughputStateCount(); for (int i = 0; i < airThrouhputStateCount; i++) { schemas.AirThroughputState ats = airThroughputProfile.getAirThroughputStates().getAirThroughputState(i); AirThroughputState airThroughputState = new AirThroughputState(ats.getName(), ats.getValue() .getContent(), ats.getPowerUsage().getContent()); Parameters params = extractParameters(ats.getParameter()); airThroughputState.init(params); airThroughputStates.add(airThroughputState); } } this.airThroughputProfile = new AirThroughputProfile(airThroughputEstimationPlugin, airThroughputStates); Parameters params = extractParameters(airThroughputProfile.getParameter()); this.airThroughputProfile.init(params); } } private void initLocation(schemas.Location l) { if (location != null) { this.location = new Location(l.getHorizontal(), l.getVertical(), l.getDepth()); Parameters params = extractParameters(l.getParameter()); this.location.init(params); } } /*private Properties initProperties(schemas.Parameter[] parameters){ Properties prop = new Properties(); for(int i = 0; i < parameters.length; i++){ schemas.Parameter parameter = parameters[i]; List values = new ArrayList(); if(parameter.getParameterTypeSequence().getProperty() != null) { Map> properties = new HashMap>(); List propValues = new ArrayList(); for(int j = 0; j < parameter.getParameterTypeSequence().getPropertyCount(); j++){ schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); for(int k = 0; k < property.getStringValueWithUnitCount(); k++){ propValues.add(property.getStringValueWithUnit(k)); } properties.put(property.getName(), propValues); } values.add(properties); }else { for(int j = 0; j < parameter.getStringValueWithUnitCount(); j++){ values.add(parameter.getStringValueWithUnit(j)); } } prop.put(parameter.getName(), values); } return prop; }*/ private Parameters extractParameters(schemas.Parameter[] parameters){ Parameters params = null; if(parameters.length != 0) params = new Parameters(); for(int i = 0; i < parameters.length; i++){ schemas.Parameter parameter = parameters[i]; Parameter param = new Parameter(parameter.getName()); if(parameter.getParameterTypeSequence() != null && parameter.getParameterTypeSequence().getProperty() != null) { int propertyCount = parameter.getParameterTypeSequence().getPropertyCount(); for(int j = 0; j < propertyCount; j++){ schemas.Property property = parameter.getParameterTypeSequence().getProperty(j); Property prop = new Property(property.getName()); int stringValueWithUnitCount = property.getStringValueWithUnitCount(); for(int k = 0; k < stringValueWithUnitCount; k++){ prop.add(property.getStringValueWithUnit(k)); } param.addProperty(prop); } } else { int stringValueWithUnitCount = parameter.getStringValueWithUnitCount(); for(int j = 0; j < stringValueWithUnitCount; j++){ param.add(parameter.getStringValueWithUnit(j)); } } params.put(parameter.getName(), param); } return params; } public PowerProfile getPowerProfile() { return powerProfile; } public AirThroughputProfile getAirThroughputProfile() { return airThroughputProfile; } public Location getLocation() { return location; } public String getCategory() { return category; } }