/** * Finalises all relevant information before <tt>exiting</tt> the GridResource entity. This method * sets the final data of: * * <ul> * <li>wall clock time, i.e. the time of this Gridlet resides in a GridResource (from arrival * time until departure time). * <li>actual CPU time, i.e. the total execution time of this Gridlet in a GridResource. * <li>Gridlet's finished so far * </ul> * * @pre $none * @post $none */ public void finalizeGridlet() { // Sets the wall clock time and actual CPU time double wallClockTime = GridSim.clock() - arrivalTime; gridlet.setExecParam(wallClockTime, totalCompletionTime); double finished = 0; if (gridlet.getGridletLength() < finishedSoFar) { finished = gridlet.getGridletLength(); } else { finished = finishedSoFar; } gridlet.setGridletFinishedSoFar(finished); }
/** This method will show you how to create Gridlets */ private void createGridlet(int userID, int numGridlet, int[] data) { int k = 0; for (int i = 0; i < numGridlet; i++) { if (k == data.length) { k = 0; } // Creates a Gridlet Gridlet gl = new Gridlet(i, data[k], data[k], data[k]); gl.setUserID(userID); this.list_.add(gl); k++; } }
public GridletReply askGridletStatusToAgent(int dst_agentID, int dst_resID, Gridlet gridlet) { GridletRequest request = new GridletRequest(this.get_id(), this.get_id(), dst_agentID, dst_resID, gridlet); int requestID = request.getRequestID(); int reqrepID = request.getReqrepID(); super.send( super.output, GridSimTags.SCHEDULE_NOW, Tags.GRIDLET_STATUS_REQ, new IO_data(request, gridlet.getGridletFileSize(), request.getDst_agentID())); Sim_type_p ptag = new Sim_type_p(Tags.GRIDLET_STATUS_REP); Sim_event ev = new Sim_event(); super.sim_get_next(ptag, ev); // only look for this type of ack GridletReply gridletReply = GridletReply.get_data(ev); Assert.assertEquals(requestID, gridletReply.getRequestID()); Assert.assertEquals(Tags.GRIDLET_STATUS_REQ, gridletReply.getRequestTAG()); Assert.assertEquals(Tags.GRIDLET_STATUS_REP, ev.get_tag()); double evrecv_time = GridSim.clock(); String msg = String.format( "%1$f %2$d %3$s <-- GOT GRIDLET_STATUS_REP for Gridlet %4$d of Gridlet %5$d with status %6$d", evrecv_time, reqrepID, this.get_name(), gridletReply.getReceivedGridlet().getGridletID(), gridletReply.getRequest().getGridlet().getGridletID(), gridletReply.getRequest().getGridlet().getGridletStatus()); this.write(msg); return gridletReply; }
/** * Sets the Gridlet status. * * @param status the Gridlet status * @return <code>true</code> if the new status has been set, <code>false</code> otherwise * @pre status >= 0 * @post $none */ public boolean setStatus(int status) { // gets Gridlet's previous status int prevStatus = gridlet.getGridletStatus(); // if the status of a Gridlet is the same as last time, then ignore if (prevStatus == status) { return false; } boolean success = true; try { double clock = GridSim.clock(); // gets the current clock // sets Gridlet's current status try { gridlet.setGridletStatus(status); } catch (Exception e) { // It should not happen } // if a previous Gridlet status is INEXEC if (prevStatus == Gridlet.INEXEC) { // and current status is either CANCELED, PAUSED or SUCCESS if (status == Gridlet.CANCELED || status == Gridlet.PAUSED || status == Gridlet.SUCCESS) { // then update the Gridlet completion time totalCompletionTime += (clock - startExecTime); return true; } } if (prevStatus == Gridlet.RESUMED && status == Gridlet.SUCCESS) { // then update the Gridlet completion time totalCompletionTime += (clock - startExecTime); return true; } // if a Gridlet is now in execution if (status == Gridlet.INEXEC || (prevStatus == Gridlet.PAUSED && status == Gridlet.RESUMED)) { startExecTime = clock; gridlet.setExecStartTime(startExecTime); } } catch (IllegalArgumentException e) { success = false; } return success; }
/** * Creates a String representation of this Gridlet for displaying purposes * * @param timeUnit the time unit to be used * @return a string * @see ScheduleItem#TIME_UNIT_SECOND * @see ScheduleItem#TIME_UNIT_MINUTE * @see ScheduleItem#TIME_UNIT_HOUR */ public String toString(int timeUnit) { String timeDescr = " " + getTimeDescr(timeUnit); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Gridlet ID: " + gridlet.getGridletID()); stringBuilder.append("\nUser ID: " + gridlet.getUserID()); stringBuilder.append("\nStatus: " + Gridlet.getStatusString(gridlet.getGridletStatus())); stringBuilder.append("\nSub. Time: " + formatTime(getSubmissionTime(), timeUnit) + timeDescr); stringBuilder.append("\nStart Time: " + formatTime(startTime, timeUnit) + timeDescr); stringBuilder.append( "\nExp. Finish Time: " + formatTime(expectedFinishTime, timeUnit) + timeDescr); stringBuilder.append("\nFinish Time: " + formatTime(actualFinishTime, timeUnit) + timeDescr); stringBuilder.append( "\nDuration: " + formatTime(actualFinishTime - startTime, timeUnit) + timeDescr); stringBuilder.append("\nLength: " + gridlet.getGridletLength() + " MIs"); stringBuilder.append("\nNum. PEs: " + getNumPE()); return stringBuilder.toString(); }
/** * Gets the remaining gridlet length * * @return gridlet length * @pre $none * @post $result >= 0 */ public double getRemainingLength() { double length = gridlet.getGridletLength() - finishedSoFar; // Remaining Gridlet length can't be negative number. This can be // happening when this.updateGridletFinishedSoFar() keep calling. if (length < 0.0) { length = 0.0; } return length; }
/** Prints the Gridlet objects */ private void printGridletList(GridletList list, String name) { int size = list.size(); Gridlet gridlet = null; String indent = " "; System.out.println(); System.out.println("============= OUTPUT for " + name + " =========="); System.out.println("Gridlet ID" + indent + "STATUS" + indent + "Resource ID" + indent + "Cost"); // a loop to print the overall result int i = 0; for (i = 0; i < size; i++) { gridlet = (Gridlet) list.get(i); System.out.print(indent + gridlet.getGridletID() + indent + indent); System.out.print(gridlet.getGridletStatusString()); System.out.println( indent + indent + gridlet.getResourceID() + indent + indent + gridlet.getProcessingCost()); } // a loop to print each Gridlet's history for (i = 0; i < size; i++) { gridlet = (Gridlet) list.get(i); System.out.println(gridlet.getGridletHistory()); System.out.print("Gridlet #" + gridlet.getGridletID()); System.out.println( ", length = " + gridlet.getGridletLength() + ", finished so far = " + gridlet.getGridletFinishedSoFar()); System.out.println("===========================================\n"); } }
public GridletReply submitGridletToAgent(int dst_agentID, int dst_resID, Gridlet gridlet) { GridletRequest request = new GridletRequest(this.get_id(), this.get_id(), dst_agentID, dst_resID, gridlet); int requestID = request.getRequestID(); int reqrepID = request.getReqrepID(); super.send( super.output, GridSimTags.SCHEDULE_NOW, Tags.GRIDLET_SUBMIT_REQ, new IO_data(request, gridlet.getGridletFileSize(), request.getDst_agentID())); Sim_type_p ptag = new Sim_type_p(Tags.GRIDLET_SUBMIT_REP); Sim_event ev = new Sim_event(); super.sim_get_next(ptag, ev); // only look for this type of ack GridletReply reply = GridletReply.get_data(ev); Assert.assertEquals(requestID, reply.getRequestID()); Assert.assertEquals(Tags.GRIDLET_SUBMIT_REQ, reply.getRequestTAG()); Assert.assertEquals(Tags.GRIDLET_SUBMIT_REP, ev.get_tag()); double evrecv_time = GridSim.clock(); if (reply.isOk()) { String msg = String.format( "%1$f %2$d %3$s <-- GOT GRIDLET_REPLY for Gridlet %4$d of Gridlet %5$d with result TRUE on AM_%6$s", evrecv_time, reqrepID, this.get_name(), reply.getReceivedGridlet().getGridletID(), reply.getRequest().getGridlet().getGridletID(), super.getEntityName(reply.getRequest().getDst_resID())); this.write(msg); } else { String msg = String.format( "%1$f %2$d %3$s <-- GOT GRIDLET_REPLY for Gridlet %4$d of Gridlet %5$d with result FALSE on AM_%6$s", evrecv_time, reqrepID, this.get_name(), reply.getReceivedGridlet().getGridletID(), reply.getRequest().getGridlet().getGridletID(), super.getEntityName(reply.getRequest().getDst_resID())); this.write(msg); } return reply; }
/* * Initialises all local attributes * @pre $none * @post $none */ private void init() { this.arrivalTime = GridSim.clock(); this.gridlet.setSubmissionTime(arrivalTime); // default values this.actualFinishTime = NOT_FOUND; // Cannot finish in this hourly slot. this.expectedFinishTime = NOT_FOUND; this.startTime = NOT_FOUND; this.totalCompletionTime = 0L; this.startExecTime = 0L; this.partition = NOT_FOUND; this.priority = NOT_FOUND; // In case a Gridlet has been executed partially by some other grid // resources. this.finishedSoFar = gridlet.getGridletFinishedSoFar(); }
/** The core method that handles communications among GridSim entities. */ public void body() { // wait for a little while for about 3 seconds. // This to give a time for GridResource entities to register their // services to GIS (GridInformationService) entity. super.gridSimHold(3.0); LinkedList resList = super.getGridResourceList(); // initialises all the containers int totalResource = resList.size(); int resourceID[] = new int[totalResource]; String resourceName[] = new String[totalResource]; // a loop to get all the resources available int i = 0; for (i = 0; i < totalResource; i++) { // Resource list contains list of resource IDs resourceID[i] = ((Integer) resList.get(i)).intValue(); // get their names as well resourceName[i] = GridSim.getEntityName(resourceID[i]); } //////////////////////////////////////////////// // SUBMIT Gridlets // determines which GridResource to send to int index = myId_ % totalResource; if (index >= totalResource) { index = 0; } // sends all the Gridlets Gridlet gl = null; boolean success; for (i = 0; i < list_.size(); i++) { gl = (Gridlet) list_.get(i); // For even number of Gridlets, send with an acknowledgement if (i % 2 == 0) { success = super.gridletSubmit(gl, resourceID[index], 0.0, true); System.out.println( name_ + ": Sending Gridlet #" + gl.getGridletID() + " with status = " + success + " to " + resourceName[index]); } // For odd number of Gridlets, send without an acknowledgement else { success = super.gridletSubmit(gl, resourceID[index], 0.0, false); System.out.println( name_ + ": Sending Gridlet #" + gl.getGridletID() + " with NO ACK so status = " + success + " to " + resourceName[index]); } } ////////////////////////////////////////// // CANCELING Gridlets // hold for few period -- 100 seconds super.gridSimHold(15); System.out.println("<<<<<<<<< pause for 15 >>>>>>>>>>>"); // a loop that cancels an even number of Gridlet for (i = 0; i < list_.size(); i++) { if (i % 2 == 0) { gl = super.gridletCancel(i, myId_, resourceID[index], 0.0); System.out.print(name_ + ": Canceling Gridlet #" + i + " at time = " + GridSim.clock()); if (gl == null) { System.out.println(" result = NULL"); } else // if Cancel is successful, then add it into the list { System.out.println(" result = NOT null"); receiveList_.add(gl); } } } //////////////////////////////////////////////////////// // RECEIVES Gridlets back // hold for few period - 1000 seconds since the Gridlets length are // quite huge for a small bandwidth super.gridSimHold(1000); System.out.println("<<<<<<<<< pause for 1000 >>>>>>>>>>>"); // receives the gridlet back int size = list_.size() - receiveList_.size(); for (i = 0; i < size; i++) { gl = (Gridlet) super.receiveEventObject(); // gets the Gridlet receiveList_.add(gl); // add into the received list System.out.println( name_ + ": Receiving Gridlet #" + gl.getGridletID() + " at time = " + GridSim.clock()); } System.out.println(this.name_ + ":%%%% Exiting body() at time " + GridSim.clock()); // shut down I/O ports shutdownUserEntity(); terminateIOEntities(); // Prints the simulation output printGridletList(receiveList_, name_); }
/** * Gets the user or owner of this Gridlet * * @return the Gridlet's user Id * @pre $none * @post $none */ public int getSenderID() { return gridlet.getUserID(); }
/** * Allocates a new object upon the arrival of a Gridlet object. The arriving time is determined by * {@link gridsim.GridSim#clock()}. * * @param gridlet a gridlet object * @see gridsim.GridSim#clock() * @pre gridlet != null * @post $none */ public SSGridlet(Gridlet gridlet) { this.gridlet = gridlet; this.reservID = gridlet.getReservationID(); init(); }
/** * Gets the Gridlet status * * @return Gridlet status * @pre $none * @post $none */ public int getStatus() { return gridlet.getGridletStatus(); }
/** * Gets this Gridlet entity Id * * @return the Gridlet entity Id * @pre $none * @post $none */ public int getID() { return gridlet.getGridletID(); }
/** * Gets the Gridlet's execution start time * * @return Gridlet's execution start time * @pre $none * @post $none */ public double getExecStartTime() { return gridlet.getExecStartTime(); }
/** * Gets the Gridlet's class type * * @return class type of the Gridlet * @pre $none * @post $none */ public int getClassType() { return gridlet.getClassType(); }
/** * Gets the Gridlet's length * * @return Gridlet's length * @pre $none * @post $none */ public double getLength() { return gridlet.getGridletLength(); }
/** * Gets the submission or arrival time of this Gridlet from the latest GridResource * * @return the submission time or <code>0.0</code> if none */ public double getSubmissionTime() { return gridlet.getSubmissionTime(); }
/** * Gets the number of PEs required to execute this Gridlet. * * @return number of PE * @pre $none * @post $none */ public int getNumPE() { return gridlet.getNumPE(); }