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