[477] | 1 | package schedframe.scheduling; |
---|
| 2 | |
---|
| 3 | import eduni.simjava.Sim_event; |
---|
| 4 | import eduni.simjava.Sim_type_p; |
---|
| 5 | import gridsim.GridSimTags; |
---|
| 6 | import gridsim.IO_data; |
---|
[493] | 7 | import gridsim.dcworms.DCWormsTags; |
---|
[477] | 8 | |
---|
| 9 | import java.util.ArrayList; |
---|
| 10 | import java.util.List; |
---|
| 11 | import java.util.Map; |
---|
| 12 | import java.util.Properties; |
---|
| 13 | |
---|
| 14 | import schedframe.exceptions.ResourceException; |
---|
| 15 | import schedframe.resources.ResourceStatus; |
---|
| 16 | import schedframe.resources.ResourceType; |
---|
| 17 | import schedframe.resources.computing.ComputingResource; |
---|
| 18 | import schedframe.resources.providers.ResourceProvider; |
---|
| 19 | import schedframe.resources.units.ResourceUnit; |
---|
| 20 | import schedframe.resources.units.ResourceUnitName; |
---|
| 21 | import schedframe.scheduling.manager.resources.ResourceManager; |
---|
| 22 | import schedframe.scheduling.plugin.grid.ModuleType; |
---|
| 23 | import schedframe.scheduling.plugin.grid.ResourceDiscovery; |
---|
| 24 | import schedframe.scheduling.tasks.requirements.AbstractResourceRequirements; |
---|
| 25 | |
---|
| 26 | public class GridResourceDiscovery implements ResourceManager, ResourceDiscovery { |
---|
| 27 | |
---|
| 28 | protected Scheduler gridBroker; |
---|
| 29 | |
---|
| 30 | public GridResourceDiscovery(Scheduler broker){ |
---|
| 31 | this.gridBroker = broker; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | public List<String> getAdministrationDomains(SecurityContext secContext) { |
---|
| 35 | throw new RuntimeException("Not implemented."); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | public List<ResourceProvider> getProviders(SecurityContext secContext) { |
---|
| 39 | throw new RuntimeException("Not implemented."); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | public List<ResourceProvider> getProviders(String admDomain, SecurityContext secContext) { |
---|
| 43 | throw new RuntimeException("Not implemented."); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | public List<ResourceProvider> getProviders( |
---|
| 47 | AbstractResourceRequirements<?> reqDesc, SecurityContext secContext) { |
---|
| 48 | throw new RuntimeException("Not implemented."); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | public List<SchedulerDescription> getResources( |
---|
| 52 | AbstractResourceRequirements<?> reqDesc, SecurityContext secContext) { |
---|
| 53 | throw new RuntimeException("Not implemented."); |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | public List<SchedulerDescription> getResources(SecurityContext secContext) { |
---|
| 57 | List <Scheduler> resourceList = gridBroker.getChildren(); |
---|
| 58 | for(int i = 0; i < resourceList.size(); i++){ |
---|
| 59 | int resourceId = resourceList.get(i).get_id(); |
---|
[481] | 60 | gridBroker.send(resourceId, GridSimTags.SCHEDULE_NOW, DCWormsTags.QUERY_RESOURCE_DESC, null); |
---|
[477] | 61 | } |
---|
| 62 | |
---|
| 63 | //filter only the query response messages |
---|
[481] | 64 | Sim_type_p pred = new Sim_type_p(DCWormsTags.QUERY_RESOURCE_DESC_RESULT); |
---|
[477] | 65 | Sim_event ev = new Sim_event(); |
---|
| 66 | |
---|
| 67 | List<SchedulerDescription> result = new ArrayList<SchedulerDescription>(resourceList.size()); |
---|
| 68 | for (int i = 0; i < resourceList.size(); ++i) { |
---|
| 69 | gridBroker.sim_get_next(pred , ev); |
---|
| 70 | IO_data ioData = (IO_data) ev.get_data(); |
---|
| 71 | SchedulerDescription resDesc = (SchedulerDescription) ioData.getData(); |
---|
| 72 | result.add(resDesc); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | return result; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | public List<SchedulerDescription> getResources() { |
---|
| 79 | |
---|
| 80 | for(int i = 0; i < gridBroker.getChildren().size(); i++){ |
---|
| 81 | int resourceId = gridBroker.getChildren().get(i).get_id(); |
---|
[481] | 82 | gridBroker.send(resourceId, GridSimTags.SCHEDULE_NOW, DCWormsTags.QUERY_RESOURCE_DESC, null); |
---|
[477] | 83 | } |
---|
| 84 | |
---|
| 85 | //filter only the query response messages |
---|
[481] | 86 | Sim_type_p pred = new Sim_type_p(DCWormsTags.QUERY_RESOURCE_DESC_RESULT); |
---|
[477] | 87 | Sim_event ev = new Sim_event(); |
---|
| 88 | |
---|
| 89 | List<SchedulerDescription> result = new ArrayList<SchedulerDescription>(gridBroker.getChildren().size()); |
---|
| 90 | for (int i = 0; i < gridBroker.getChildren().size(); ++i) { |
---|
| 91 | gridBroker.sim_get_next(pred , ev); |
---|
| 92 | IO_data ioData = (IO_data) ev.get_data(); |
---|
| 93 | SchedulerDescription resDesc = (SchedulerDescription) ioData.getData(); |
---|
| 94 | result.add(resDesc); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | return result; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | public List<Scheduler> getSchedulers() { |
---|
| 101 | return gridBroker.getChildren(); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | @Override |
---|
| 105 | public boolean areResourcesAchievable(ResourceType type) { |
---|
| 106 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | @Override |
---|
| 110 | public List<? extends ComputingResource> getResourcesOfType(ResourceType type) throws ResourceException { |
---|
| 111 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | @Override |
---|
| 115 | public ComputingResource getResourceByName(String resourceName) { |
---|
| 116 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | @Override |
---|
| 120 | public List<? extends ComputingResource> getResourcesByTypeWithStatus(ResourceType type, ResourceStatus status) |
---|
| 121 | throws ResourceException { |
---|
| 122 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | /*@Override |
---|
| 126 | public ResourceCharacteristics getResourceCharacteristic() { |
---|
| 127 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 128 | }*/ |
---|
| 129 | |
---|
| 130 | @Override |
---|
| 131 | public Map<ResourceUnitName, List<ResourceUnit>> getSharedResourceUnits() { |
---|
| 132 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | @Override |
---|
| 136 | public List<ResourceUnit> getDistributedResourceUnits(ResourceUnitName unitName) { |
---|
| 137 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | @Override |
---|
| 141 | public List<ComputingResource> filterResources(Properties properties) { |
---|
| 142 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | @Override |
---|
| 146 | public String getSchedulerName(String resourceName) { |
---|
| 147 | throw new UnsupportedOperationException("Not available at Grid level. Please use getResources() method instead to explore available resource providers"); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | public void dispose() { |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | public ModuleType getType() { |
---|
| 155 | return ModuleType.RESOURCE_DISCOVERY; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | public void init(Properties properties) { |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | } |
---|