[104] | 1 | package test.rewolucja.modules; |
---|
| 2 | |
---|
| 3 | import eduni.simjava.Sim_event; |
---|
| 4 | import gridsim.GridSim; |
---|
| 5 | import gridsim.Gridlet; |
---|
| 6 | import gridsim.IO_data; |
---|
| 7 | import gridsim.gssim.GssimTags; |
---|
| 8 | import gridsim.gssim.SubmittedTask; |
---|
| 9 | import gridsim.gssim.network.ExtendedGridSimTags; |
---|
| 10 | import gssim.schedframe.scheduling.plugin.grid.network.manager.NetworkData; |
---|
| 11 | import gssim.schedframe.scheduling.plugin.grid.network.manager.SendOrder; |
---|
| 12 | import gssim.schedframe.scheduling.plugin.grid.network.manager.TaskInputFile; |
---|
| 13 | |
---|
| 14 | import java.util.ArrayList; |
---|
| 15 | import java.util.HashMap; |
---|
| 16 | import java.util.HashSet; |
---|
| 17 | import java.util.List; |
---|
| 18 | import java.util.Properties; |
---|
| 19 | |
---|
| 20 | import schedframe.exceptions.ModuleException; |
---|
| 21 | import schedframe.scheduling.plugin.grid.ModuleType; |
---|
| 22 | import test.rewolucja.extensions.Extension; |
---|
| 23 | import test.rewolucja.extensions.ExtensionException; |
---|
| 24 | import test.rewolucja.extensions.ExtensionType; |
---|
| 25 | import test.rewolucja.resources.test.Event; |
---|
| 26 | import test.rewolucja.scheduling.JobRegistry; |
---|
| 27 | import test.rewolucja.scheduling.implementation.LocalManagementSystem; |
---|
| 28 | |
---|
| 29 | public class DataManager implements Extension{ |
---|
| 30 | |
---|
| 31 | protected HashMap task_inputFiles; |
---|
| 32 | protected List<NetworkData> receivedNetData; |
---|
| 33 | |
---|
| 34 | LocalManagementSystem managementSystem; |
---|
| 35 | String resName; |
---|
| 36 | |
---|
| 37 | public DataManager(LocalManagementSystem managementSystem, String resName) { |
---|
| 38 | super(); |
---|
| 39 | this.managementSystem = managementSystem; |
---|
| 40 | task_inputFiles = new HashMap(); |
---|
| 41 | receivedNetData = new ArrayList<NetworkData>(); |
---|
| 42 | this.resName = resName; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | protected void processFileReceive(Sim_event ev) |
---|
| 46 | { |
---|
| 47 | NetworkData t = (NetworkData)ev.get_data(); |
---|
| 48 | TaskInputFile tif = (TaskInputFile)t.getData(); |
---|
| 49 | //log.info(get_name() + " received file"); |
---|
| 50 | System.out.println("---------------------FILE RECEIVED---------------- "); |
---|
| 51 | if(task_inputFiles.containsKey(tif.getJobID() + "_" + tif.getTaskID())) |
---|
| 52 | { |
---|
| 53 | ((HashSet)task_inputFiles.get(tif.getJobID() + "_" + tif.getTaskID())).add(tif.getFileName()); |
---|
| 54 | |
---|
| 55 | }else{ |
---|
| 56 | HashSet receivedFiles = new HashSet(); |
---|
| 57 | receivedFiles.add(tif.getFileName()); |
---|
| 58 | task_inputFiles.put(tif.getJobID() + "_" + tif.getTaskID(), receivedFiles); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | SubmittedTask subTask = new JobRegistry(resName).getSubmittedTask(tif.getJobID(), tif.getTaskID()); |
---|
| 62 | |
---|
| 63 | if(subTask != null && checkInputFiles(subTask) && subTask.getGridletStatus() == Gridlet.QUEUED){ |
---|
| 64 | this.managementSystem.getLogicalResource().sendInternal( Long.valueOf(0).doubleValue(), |
---|
| 65 | GssimTags.TASK_READY_FOR_EXECUTION, subTask.getGridlet()); |
---|
| 66 | } |
---|
| 67 | receivedNetData.add(t); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | protected boolean checkInputFiles(SubmittedTask subTask){ |
---|
| 71 | |
---|
| 72 | int nrOfRequestedFiles = 0; |
---|
| 73 | try{ |
---|
| 74 | nrOfRequestedFiles = subTask.getDescription().getExecution().getStageInOut().getStageInOutItem().length; |
---|
| 75 | } catch(Exception e){ |
---|
| 76 | e.printStackTrace(); |
---|
| 77 | } |
---|
| 78 | HashSet requestedFiles = new HashSet(); |
---|
| 79 | for(int i = 0; i < nrOfRequestedFiles; i++){ |
---|
| 80 | String fileName = subTask.getDescription().getExecution().getStageInOut().getStageInOutItem(i).getFile().getName(); |
---|
| 81 | requestedFiles.add(fileName); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | HashSet tempSet = (HashSet)task_inputFiles.get(subTask.getDescription().getJobId() + "_" + subTask.getDescription().getTaskId()); |
---|
| 85 | //log.info("Task " + subTask.getJobId() + "_"+ subTask.getId() + " - received input files " + tempSet); |
---|
| 86 | System.out.println("task input files " + tempSet); |
---|
| 87 | //log.info("Task " + subTask.getJobId() + "_"+ subTask.getId() + " - requested files " + requestedFiles); |
---|
| 88 | System.out.println("requested files " + requestedFiles); |
---|
| 89 | if(tempSet == null || !tempSet.containsAll(requestedFiles)) |
---|
| 90 | { |
---|
| 91 | return false; |
---|
| 92 | } |
---|
| 93 | //log.info(get_name() + " received all requested files for task " + subTask.getJobId() + "_"+ subTask.getId()); |
---|
| 94 | System.out.println(resName+"---------------------ALL FILES RECEIVED---------------- "+subTask.getJobId()); |
---|
| 95 | //System.out.println(GridSim.clock()+";"+VirtualClock.getStaticCurrentDateTimeMillis()+";"+ new DateTime(VirtualClock.getStaticCurrentDateTimeMillis())); |
---|
| 96 | return true; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | protected void sendFile(Sim_event ev) |
---|
| 100 | { |
---|
| 101 | SendOrder sendOrder = (SendOrder)ev.get_data(); |
---|
| 102 | |
---|
| 103 | //log.info(get_name() + " sending file to " + sendOrder.getRecipientName()); |
---|
| 104 | System.out.println(resName + " SENDING FILE TO " + sendOrder.getRecipientName()); |
---|
| 105 | //System.out.println(GridSim.clock()+";"+VirtualClock.getStaticCurrentDateTimeMillis()+";"+ new DateTime(VirtualClock.getStaticCurrentDateTimeMillis())); |
---|
| 106 | |
---|
| 107 | //NetworkData resData = new NetworkData(sendOrder.getTaskInputFile(), sendOrder.getRoute(), sendOrder.getReservationID()); |
---|
| 108 | NetworkData resData = sendOrder; |
---|
| 109 | |
---|
| 110 | IO_data data = new IO_data(resData, sendOrder.getFileSize(), GridSim.getEntityId(sendOrder.getRecipientName())); |
---|
| 111 | |
---|
| 112 | if(sendOrder.getRecipientName().compareTo(resName) == 0) |
---|
| 113 | |
---|
| 114 | managementSystem.getLogicalResource().send(GridSim.getEntityId(resName), ExtendedGridSimTags.SCHEDULE_NOW, ExtendedGridSimTags.FILE, resData); |
---|
| 115 | |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | String recipientName = sendOrder.getRecipientName(); |
---|
| 119 | int recipientId = GridSim.getEntityId(recipientName); |
---|
| 120 | |
---|
| 121 | if(sendOrder.getReservationID() > 0 && recipientId != -1) |
---|
| 122 | { |
---|
| 123 | managementSystem.getLogicalResource().send(recipientId, ExtendedGridSimTags.SCHEDULE_NOW, ExtendedGridSimTags.FLOW_RESERVATION, resData); |
---|
| 124 | } |
---|
| 125 | else |
---|
| 126 | { |
---|
| 127 | managementSystem.getLogicalResource().send(recipientId, ExtendedGridSimTags.SCHEDULE_NOW, ExtendedGridSimTags.FLOW_SUBMIT, resData); |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | public List<NetworkData> getReceivedNetData() { |
---|
| 133 | return receivedNetData; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | @Override |
---|
| 137 | public void init(Properties properties) throws ExtensionException { |
---|
| 138 | // TODO Auto-generated method stub |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | @Override |
---|
| 142 | public void dispose() throws ExtensionException { |
---|
| 143 | // TODO Auto-generated method stub |
---|
| 144 | |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | @Override |
---|
| 148 | public ExtensionType getType() { |
---|
| 149 | return ExtensionType.DATA_MANAGER; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | @Override |
---|
| 153 | public boolean supportsEvent(Event event) { |
---|
| 154 | switch (event.getTag()) { |
---|
| 155 | case ExtendedGridSimTags.SEND_ORDER: |
---|
| 156 | return true; |
---|
| 157 | case ExtendedGridSimTags.FILE: |
---|
| 158 | return true; |
---|
| 159 | case ExtendedGridSimTags.FLOW_SUBMIT: |
---|
| 160 | return true; |
---|
| 161 | case ExtendedGridSimTags.FLOW_RESERVATION: |
---|
| 162 | return true; |
---|
| 163 | default: |
---|
| 164 | return false; |
---|
| 165 | } |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | @Override |
---|
| 169 | public void handleEvent(Event event) { |
---|
| 170 | // TODO Auto-generated method stub |
---|
| 171 | switch (event.getTag()) { |
---|
| 172 | case ExtendedGridSimTags.SEND_ORDER: |
---|
| 173 | //sendFile(event.getTag()); |
---|
| 174 | break; |
---|
| 175 | |
---|
| 176 | case ExtendedGridSimTags.FILE: |
---|
| 177 | case ExtendedGridSimTags.FLOW_SUBMIT: |
---|
| 178 | case ExtendedGridSimTags.FLOW_RESERVATION: |
---|
| 179 | //processFileReceive(event.getTag()); |
---|
| 180 | break; |
---|
| 181 | } |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | } |
---|