|
From: <sul...@us...> - 2007-08-28 06:04:23
|
Revision: 34
http://gridsim.svn.sourceforge.net/gridsim/?rev=34&view=rev
Author: sulistio
Date: 2007-08-27 23:04:16 -0700 (Mon, 27 Aug 2007)
Log Message:
-----------
initial release. this example was done by Agustin but I did some changes to make it easier to understand.
Added Paths:
-----------
branches/gridsim4.0-branch1/examples/ResFailureEx01/GridUserFailureEx01.java
branches/gridsim4.0-branch1/examples/ResFailureEx01/GridletSubmission.java
branches/gridsim4.0-branch1/examples/ResFailureEx01/README.txt
branches/gridsim4.0-branch1/examples/ResFailureEx01/ResFailureEx01.java
branches/gridsim4.0-branch1/examples/ResFailureEx01/network_ex01.txt
Added: branches/gridsim4.0-branch1/examples/ResFailureEx01/GridUserFailureEx01.java
===================================================================
--- branches/gridsim4.0-branch1/examples/ResFailureEx01/GridUserFailureEx01.java (rev 0)
+++ branches/gridsim4.0-branch1/examples/ResFailureEx01/GridUserFailureEx01.java 2007-08-28 06:04:16 UTC (rev 34)
@@ -0,0 +1,736 @@
+/*
+ * Title: GridSim Toolkit
+ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation
+ * of Parallel and Distributed Systems such as Clusters and Grids
+ * An example of how to use the failure functionality.
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: UCLM (Spain)
+ * Created on: August 2007
+ */
+
+import gridsim.*;
+import gridsim.index.AbstractGIS;
+import gridsim.net.Link;
+import java.util.Random;
+import java.util.ArrayList;
+import java.io.FileWriter;
+import gridsim.resFailure.RegionalGISWithFailure;
+import eduni.simjava.Sim_system;
+import eduni.simjava.Sim_event;
+
+
+/**
+ * Creates a Grid User that also considers what happens if a resource fails.
+ * @author Agustin Caminero and Anthony Sulistio
+ * @since GridSim Toolkit 4.1
+ */
+public class GridUserFailureEx01 extends GridUser
+{
+ // the base for our constants (chosen at random)
+ private static final int BASE = 440000;
+
+ /** This constant is to tell the user when he should submit a gridlet */
+ private static final int SUBMIT_GRIDLET = BASE + 1;
+
+ private ArrayList GridletSubmittedList_; // list of submitted Gridlets
+ private GridletList GridletReceiveList_; // list of received Gridlets
+
+ private int NUM_GRIDLETS;
+ private double pollingTime_;
+
+ // The sizes of gridlets
+ private int gridletLength;
+ private int gridletInput;
+ private int gridletOutput;
+
+ // we keep here the time when each gridlet is submitted
+ private double gridletSubmissionTime [];
+ private double gridletLatencyTime [];
+
+ // a flag that denotes whether to trace GridSim events or not.
+ private boolean trace_flag;
+
+
+ /**
+ * Creates a GridUserFailure object
+ * @param name this entity name
+ * @param link a network link connecting this entity
+ * @param pollTime the time between polls
+ * @param glLength length (MI) for the gridlets of this user
+ * @param glIn input file size for the gridlets of this user
+ * @param glOut output file size for the gridlets of this user
+ * @param trace_flag a flag that denotes whether to trace this user events
+ * or not.
+ * @throws java.lang.Exception happens if either name or link is empty
+ */
+ public GridUserFailureEx01(String name, Link link, double pollTime,
+ int glLength, int glIn, int glOut, boolean trace_flag)
+ throws Exception
+ {
+ super(name, link);
+
+ this.GridletSubmittedList_ = new ArrayList();
+ this.GridletReceiveList_ = new GridletList();
+ pollingTime_ = pollTime;
+
+ gridletLength = glLength;
+ gridletInput = glIn;
+ gridletOutput = glOut;
+ this.trace_flag = trace_flag;
+ }
+
+ /**
+ * Sets the number of gridlets that this user has to submit.
+ * Also, create the submission and reception times arrays.
+ * @param gridlet_num the number of gridlets
+ */
+ public void setGridletNumber(int gridlet_num)
+ {
+ NUM_GRIDLETS = gridlet_num;
+
+ gridletSubmissionTime = new double[NUM_GRIDLETS];
+ gridletLatencyTime = new double[NUM_GRIDLETS];
+ }
+
+ /**
+ * This function retrieves a list of available resources from the GIS.
+ * @return an array containing the ids of the resources
+ */
+ private int[] getResList()
+ {
+ Object[] resList = super.getLocalResourceList();
+ int resourceID[] = null;
+
+ // if we have any resource
+ if ((resList != null) && (resList.length != 0))
+ {
+ resourceID = new int[resList.length];
+ for (int x = 0; x < resList.length; x++)
+ {
+ // Resource list contains list of resource IDs
+ resourceID[x] = ((Integer) resList[x]).intValue();
+
+ if (trace_flag == true)
+ {
+ System.out.println(super.get_name() +
+ ": resource[" + x + "] = " + resourceID[x]);
+ }
+ }
+
+ }
+
+ return resourceID;
+ }
+
+ /**
+ * Handles incoming requests to this entity.
+ */
+ public void body()
+ {
+ initializeResultsFile();
+ createGridlet(super.get_id(), NUM_GRIDLETS);
+
+ // schedule the initial sending of gridlets.
+ // The sending will start in a ramdom time within 5 min
+ Random random = new Random();
+ int init_time = random.nextInt(5*60);
+
+ // sends a reminder to itself
+ super.send(super.get_id(), init_time, SUBMIT_GRIDLET);
+ System.out.println(super.get_name() +
+ ": initial SUBMIT_GRIDLET event will be at clock: " +
+ init_time + ". Current clock: " + GridSim.clock());
+
+
+ ////////////////////////////////////////////////////////////
+ // Now, we have the framework of the entity:
+ while (Sim_system.running())
+ {
+ Sim_event ev = new Sim_event();
+ super.sim_get_next(ev); // get the next event in the queue
+
+ switch (ev.get_tag())
+ {
+ // submit a gridlet
+ case SUBMIT_GRIDLET:
+ processGridletSubmission(ev); // process the received event
+ break;
+
+ // Receive a gridlet back
+ case GridSimTags.GRIDLET_RETURN:
+ processGridletReturn(ev);
+ break;
+
+ case GridSimTags.END_OF_SIMULATION:
+ System.out.println("\n============== " + super.get_name() +
+ ". Ending simulation...");
+ break;
+
+ default:
+ System.out.println(super.get_name() +
+ ": Received an event: " + ev.get_tag());
+ break;
+
+ } // switch
+
+ } // while
+
+ // remove I/O entities created during construction of this entity
+ super.terminateIOEntities();
+
+ // prints the completed gridlets
+ printGridletList(GridletReceiveList_, super.get_name(), false,
+ gridletLatencyTime);
+ } // body()
+
+
+ /**
+ * This functions process the submission of a gridlet. We have to get the
+ * list of available resources from the RegGIS, choose one of them, and
+ * submit the gridlet.
+ * @param ev an incoming event
+ */
+ private void processGridletSubmission(Sim_event ev)
+ {
+ if (trace_flag)
+ {
+ System.out.println(super.get_name() +
+ ": received an SUBMIT_GRIDLET event. Clock: " + GridSim.clock());
+ }
+
+ /***********
+ We have to submit:
+ - the gridlet whose id comes with the event
+ - all the gridlets with the "gridletSub.getSubmitted() == false"
+
+ So, set the gridletSub.getSubmitted() to false for the gridlet whose
+ id comes with the event
+ ***********/
+
+ int i = 0;
+ GridletSubmission gridletSub;
+ int resourceID[];
+ Random random = new Random(5); // a random generator with a random seed
+ int index;
+ Gridlet gl;
+ Integer obj;
+ int glID;
+
+ // This is because the initial GRIDLET_SUBMIT event, at the beginning
+ // of sims, does not have any gridlet id. We have to submit
+ // all the gridlets.
+ if (ev.get_data() instanceof Integer)
+ {
+ obj = (Integer) ev.get_data();
+ glID = obj.intValue(); // get the gridlet id.
+ }
+ else {
+ glID = 99; // a value at random, not used at all in this case
+ }
+
+ while (i < GridletSubmittedList_.size())
+ {
+ gridletSub = (GridletSubmission)GridletSubmittedList_.get(i);
+
+ if ( (gridletSub.getGridlet()).getGridletID() == glID )
+ {
+ // set this gridlet whose id comes with the event as not submitted,
+ // so that it is submitted as soon as possible.
+ ((GridletSubmission) GridletSubmittedList_.get(i)).setSubmitted(false);
+ }
+
+ // Submit the gridlets with the "gridletSub.getSubmitted() == false"
+ if ( (gridletSub.getSubmitted() == false))
+ {
+ // we have to resubmit this gridlet
+ gl = ((GridletSubmission) GridletSubmittedList_.get(i)).getGridlet();
+ resourceID = getResList(); // Get list of resources from GIS
+
+ // If we have resources in the list
+ if ((resourceID != null) && (resourceID.length != 0))
+ {
+ index = random.nextInt(resourceID.length);
+
+ // make sure the gridlet will be executed from the begining
+ resetGridlet(gl);
+
+ // submits this gridlet to a resource
+ super.gridletSubmit(gl, resourceID[index]);
+ gridletSubmissionTime[gl.getGridletID()] = GridSim.clock();
+
+ // set this gridlet as submitted
+ ((GridletSubmission) GridletSubmittedList_.get(i)).setSubmitted(true);
+
+ if (trace_flag)
+ {
+ System.out.println(super.get_name() +
+ ": Sending Gridlet #" + i + " to " +
+ GridSim.getEntityName(resourceID[index]) +
+ " at clock: " + GridSim.clock());
+
+ // Write into a results file
+ write(super.get_name(), "Sending", gl.getGridletID(),
+ GridSim.getEntityName(resourceID[index]),
+ gl.getGridletStatusString(), GridSim.clock());
+ }
+
+ }
+ // No resources available at this moment, so schedule an event
+ // in the future. The event wil be in 15 min (900 sec), as
+ // resource failures may last several hours.
+ // This event includes the gridletID, so that the user will
+ // try to submit only this gridlet
+ else
+ {
+ super.send(super.get_id(), GridSimTags.SCHEDULE_NOW + 900,
+ SUBMIT_GRIDLET, new Integer(gl.getGridletID()) );
+ }
+
+ }// if (gridletSub.getSubmitted() == false)
+
+ i++;
+ } // while (i < GridletSubmittedList_.size())
+
+ } // processGridletSubmission
+
+
+ /**
+ * This functions process the return of a gridlet.
+ * We pay attention to the status of the gridlet
+ * and then decide what we have to do the next
+ * @param ev an incoming event
+ */
+ private void processGridletReturn(Sim_event ev)
+ {
+ if (trace_flag)
+ {
+ System.out.println(super.get_name() +
+ ": received an GRIDLET_RETURN event. Clock: " + GridSim.clock());
+ }
+
+ Object obj = (Object) ev.get_data();
+ Gridlet gl = null;
+ Random random = new Random(5); // a random generator with a random seed
+
+ if (obj instanceof Gridlet)
+ {
+ gl = (Gridlet) obj;
+ gridletLatencyTime[gl.getGridletID()] = GridSim.clock();
+
+ // Write into a results file
+ if (trace_flag)
+ {
+ write(super.get_name(), "Receiving", gl.getGridletID(),
+ GridSim.getEntityName(gl.getResourceID()),
+ gl.getGridletStatusString(), GridSim.clock());
+ }
+
+ ///////////////////////// Gridlet Success
+ if (gl.getGridletStatusString().compareTo("Success") == 0)
+ {
+ System.out.println(super.get_name() + ": Receiving Gridlet #" +
+ gl.getGridletID() + " with status Success at time = " +
+ GridSim.clock() + " from resource " +
+ GridSim.getEntityName(gl.getResourceID()));
+
+ this.GridletReceiveList_.add(gl); // add into the received list
+ gridletLatencyTime[gl.getGridletID()] =
+ gridletLatencyTime[gl.getGridletID()] -
+ gridletSubmissionTime[gl.getGridletID()];
+
+ // We have received all the gridlets. So, finish the simulation.
+ if (GridletReceiveList_.size() == GridletSubmittedList_.size())
+ {
+ super.finishSimulation();
+ }
+
+ } // if (gl.getGridletStatusString() == "Success")
+
+ //////////////////////// Gridlet Failed
+ else if (gl.getGridletStatusString().compareTo("Failed") == 0)
+ {
+ System.out.println(super.get_name() + ": Receiving Gridlet #" +
+ gl.getGridletID() + " with status Failed at time = " +
+ GridSim.clock() + " from resource " +
+ GridSim.getEntityName(gl.getResourceID()));
+
+ // Send the gridlet as soon as we have resources available.
+ // This gridlet will be resend as soon as possible,
+ // in the first loop.
+ int pos = findGridletInGridletSubmittedList(gl);
+ if (pos == -1) {
+ System.out.println(super.get_name() +
+ ". Gridlet not found in GridletSubmittedList.");
+ }
+ else
+ {
+ // set this gridlet as submitted, because otherwise
+ // this gridlet may be submitted several times.
+ // A gridlet will only be submitted when the event carrying
+ // its id reaches the user
+ ((GridletSubmission) GridletSubmittedList_.get(pos)).setSubmitted(true);
+
+ // Now, schedule an event to itself to submit the gridlet
+ // The gridlet will be sent as soon as possible
+ Integer glID_Int = new Integer(gl.getGridletID());
+
+ // This event includes the gridletID, so that the user
+ // will try to submit only this gridlet
+ super.send(super.get_id(), GridSimTags.SCHEDULE_NOW,
+ SUBMIT_GRIDLET, glID_Int);
+ }
+ } // if (gl.getGridletStatusString() == "Failed")
+
+ ////////////////////////////// Gridlet Failed_resource
+ else if (gl.getGridletStatusString().compareTo("Failed_resource_unavailable") == 0)
+ {
+ int pos = findGridletInGridletSubmittedList(gl);
+ if (pos == -1) {
+ System.out.println(super.get_name() +
+ ". Gridlet not found in GridletSubmittedList.");
+ }
+ else
+ {
+ // Now, set its submission time for a random time between
+ // 1 and the polling time
+ double resubmissionTime = random.nextDouble() * pollingTime_;
+
+ // this is to prevent the gridlet from being submitted
+ // before its resubmission time.
+ // This is different from the FAILED case, because
+ // in that case, the gridlet should be resubmited as soon
+ // as possible. As oppossed to that, this gridlet should
+ // not be resubmited before its resubmission time.
+ ((GridletSubmission) GridletSubmittedList_.get(pos)).setSubmitted(true);
+
+
+ System.out.println(super.get_name() + ": Receiving Gridlet #" +
+ gl.getGridletID() +
+ " with status Failed_resource_unavailable at time = " +
+ GridSim.clock() + " from resource " +
+ GridSim.getEntityName(gl.getResourceID()) +
+ "(resID: " + gl.getResourceID() +
+ "). Resubmission time will be: " +
+ resubmissionTime + GridSim.clock());
+
+ // Now, we have to inform the GIS about this failure, so it
+ // can keep the list of resources up-to-date.
+ informGIS(gl.getResourceID());
+
+ // Now, schedule an event to itself to submit the gridlet
+ Integer glID_Int = new Integer(gl.getGridletID());
+
+ // This event includes the gridletID, so that the user
+ // will try to submit only this gridlet
+ super.send(super.get_id(), resubmissionTime,
+ SUBMIT_GRIDLET, glID_Int);
+ }
+ } // else if
+ else
+ {
+ System.out.println(super.get_name() + ": Receiving Gridlet #" +
+ gl.getGridletID() + " with status " +
+ gl.getGridletStatusString() + " at time = " +
+ GridSim.clock() + " from resource " +
+ GridSim.getEntityName(gl.getResourceID()) +
+ " resID: " + gl.getResourceID());
+ }
+
+ } // if (obj instanceof Gridlet)
+ }
+
+ /**
+ * Prints the Gridlet objects
+ * @param list the list of gridlets
+ * @param name the name of the user
+ * @param detail if we want the gridlet's history or not
+ * @param gridletLatencyTime array containing the latencies of gridlets.
+ * Latencies are from the moment when the gridlet is sent, till
+ * the moment they are back at the user.
+ * They take into account the last submission of a gridlet
+ * (when the gridlet is successfully run)
+ */
+ private static void printGridletList(GridletList list, String name,
+ boolean detail, double gridletLatencyTime[])
+ {
+ 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" + indent +
+ "CPU Time"+ indent + "Latency");
+
+ // 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() +
+ indent + indent + gridlet.getActualCPUTime()+
+ indent + indent +
+ gridletLatencyTime[gridlet.getGridletID()]);
+
+ writeFin(name, gridlet.getGridletID(),
+ GridSim.getEntityName(gridlet.getResourceID()),
+ gridlet.getProcessingCost(), gridlet.getActualCPUTime(),
+ GridSim.clock());
+
+
+
+ }
+
+
+ if (detail == true)
+ {
+ // 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");
+ }
+ }
+
+ System.out.println("=================================================");
+
+ }
+
+ /**
+ * This method will show you on how to create Gridlets
+ * @param userID owner ID of a Gridlet
+ * @param numGridlet number of Gridlet to be created
+ */
+ private void createGridlet(int userID, int numGridlet)
+ {
+ for (int i = 0; i < numGridlet; i++)
+ {
+ // Creates a Gridlet
+ Gridlet gl = new Gridlet(i, gridletLength, gridletInput, gridletOutput);
+ gl.setUserID(userID);
+
+ // Originally, gridlets are created to be submitted
+ // as soon as possible (the 0.0 param)
+ GridletSubmission gst = new GridletSubmission(gl, false);
+
+ // add this gridlet into a list
+ this.GridletSubmittedList_.add(gst);
+ }
+ }
+
+ /**
+ * Gets a list of received Gridlets
+ * @return a list of received/completed Gridlets
+ */
+ public GridletList getGridletList() {
+ return GridletReceiveList_;
+ }
+
+ /**
+ * Tells you the possition of this gridlet in the GridletSubmittedList_
+ * @param gl the gridlet
+ * @return the position of this gridlet in the list of submitted gridlets
+ */
+ private int findGridletInGridletSubmittedList(Gridlet gl)
+ {
+ Gridlet g = null;
+ GridletSubmission gst = null;
+ for (int i = 0; i< GridletSubmittedList_.size(); i++)
+ {
+ gst = (GridletSubmission)GridletSubmittedList_.get(i);
+ g = gst.getGridlet();
+
+ if ( g.getGridletID() == gl.getGridletID() )
+ return i;
+ }
+
+ return -1;
+ }
+
+ /** This function resets the gridlet into its original values of
+ * length and gridletFinishedSoFar
+ * @param gl the gridlet to be resetted
+ */
+ private void resetGridlet (Gridlet gl)
+ {
+ gl.setGridletLength(gridletLength);
+ gl.setGridletFinishedSoFar(0);
+
+ }
+
+ /**
+ * Write some data into the final results file.
+ * @param user user name
+ * @param glID gridlet id
+ * @param resName Name of the resource
+ * @param cost the processing cost of the gridlet
+ * @param cpu the cpu time
+ * @param clock Current time
+ * */
+ private static void writeFin(String user, int glID, String resName,
+ double cost, double cpu, double clock)
+ {
+ // Write into a results file
+ FileWriter fwriter = null;
+ try
+ {
+ fwriter = new FileWriter(user+"_Fin", true);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while opening file " + user+"_Fin");
+ }
+
+ try
+ {
+ fwriter.write(user +"\t "+ glID + "\t" +
+ resName + "\t" + cost + "\t"+ cpu + "\t" + + clock + "\n");
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while writing on file " + user+"_Fin");
+ }
+
+ try
+ {
+ fwriter.close();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while closing file " + user+"_Fin");
+ }
+
+ }
+
+ /**
+ * Write some data into a results file.
+ * @param user user name
+ * @param event Values: "Sending" or "Receive" a gridlet
+ * @param glID gridlet id
+ * @param resName Name of the resource
+ * @param status Status of the gridlet
+ * @param clock Current time
+ * */
+ private void write(String user, String event, int glID, String resName,
+ String status, double clock)
+ {
+ // Write into a results file
+ FileWriter fwriter = null;
+ try
+ {
+ fwriter = new FileWriter(super.get_name(), true);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while opening file " + super.get_name());
+ }
+
+ try
+ {
+ fwriter.write(user + "\t " + event + "\t" + glID + "\t" +
+ resName + "\t" + status + "\t\t" + clock + "\t" + "\n");
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while writing on file " + super.get_name());
+ }
+
+
+ try
+ {
+ fwriter.close();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while closing file " + super.get_name());
+ }
+
+ }
+
+ /**
+ * This function informs the GIS of this user about the failure of a resource
+ * @param resID the id of the resource which has failed
+ */
+ private void informGIS(int resID)
+ {
+ Integer resID_Int = new Integer(resID);
+
+ super.send(super.output, 0.0, AbstractGIS.NOTIFY_GIS_RESOURCE_FAILURE,
+ new IO_data(resID_Int, Link.DEFAULT_MTU, super.getRegionalGISId()) );
+ }
+
+ /**
+ * Initialize the results files (put headers over each column)
+ * */
+ private void initializeResultsFile()
+ {
+ if (trace_flag == false) {
+ return;
+ }
+
+ // Initialize the results file
+ FileWriter fwriter = null;
+ FileWriter fwriterFin = null;
+ try
+ {
+ fwriter = new FileWriter(super.get_name(), true);
+ fwriterFin = new FileWriter(super.get_name() + "_Fin", true);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while opening file " + super.get_name() +
+ " or " + super.get_name()+"_Fin");
+ }
+
+ try
+ {
+ fwriter.write(
+ "User \t\t Event \t GridletID \t Resource \t GridletStatus \t\t\t Clock\n");
+ fwriterFin.write(
+ "User \t\t GridletID \t Resource \t Cost \t CPU time \t Latency\n");
+
+
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while writing on file " + super.get_name()+
+ " or " + super.get_name()+"_Fin");
+ }
+
+ try
+ {
+ fwriter.close();
+ fwriterFin.close();
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ System.out.println(
+ "Unwanted errors while closing file " + super.get_name()+
+ " or " + super.get_name()+"_Fin");
+ }
+ }
+
+} // end class
Added: branches/gridsim4.0-branch1/examples/ResFailureEx01/GridletSubmission.java
===================================================================
--- branches/gridsim4.0-branch1/examples/ResFailureEx01/GridletSubmission.java (rev 0)
+++ branches/gridsim4.0-branch1/examples/ResFailureEx01/GridletSubmission.java 2007-08-28 06:04:16 UTC (rev 34)
@@ -0,0 +1,54 @@
+/*
+ * Title: GridSim Toolkit
+ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation
+ * of Parallel and Distributed Systems such as Clusters and Grids
+ * An example of how to use the failure functionality.
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: UCLM (Spain)
+ * Created on: August 2007
+ */
+
+
+import gridsim.Gridlet;
+
+/**
+ * This class is just a wrapper to denote
+ * whether this gridlet has been already submitted or not
+ * @author Agustin Caminero and Anthony Sulistio
+ * @since GridSim Toolkit 4.1
+ */
+public class GridletSubmission
+{
+ private Gridlet gl;
+ private boolean submitted;
+
+
+ public GridletSubmission(Gridlet gl,boolean submitted)
+ {
+ this.gl = gl;
+ this.submitted = submitted;
+ }
+
+ public Gridlet getGridlet()
+ {
+ return gl;
+ }
+
+ public boolean getSubmitted()
+ {
+ return submitted;
+ }
+
+ public void setGridlet(Gridlet g)
+ {
+ this.gl = g;
+ }
+
+ public void setSubmitted(boolean submitted)
+ {
+ this.submitted = submitted;
+ }
+
+} // end class
Added: branches/gridsim4.0-branch1/examples/ResFailureEx01/README.txt
===================================================================
--- branches/gridsim4.0-branch1/examples/ResFailureEx01/README.txt (rev 0)
+++ branches/gridsim4.0-branch1/examples/ResFailureEx01/README.txt 2007-08-28 06:04:16 UTC (rev 34)
@@ -0,0 +1,68 @@
+/*
+ * Title: GridSim Toolkit
+ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation
+ * of Parallel and Distributed Systems such as Clusters and Grids
+ * An example of how to use the failure functionality.
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: UCLM (Spain)
+ * Created on: August 2007
+ */
+
+Welcome to the example of how to use the computing resource failure functionality
+To compile the example source code:
+ In Unix/Linux: javac -classpath $GRIDSIM/jars/gridsim.jar:. ResFailureEx01.java
+ In Windows: javac -classpath %GRIDSIM%\jars\gridsim.jar;. ResFailureEx01.java
+
+where $GRIDSIM or %GRIDSIM% is the location of the gridsimtoolkit package.
+
+
+To run the class file:
+ In Unix/Linux:
+ java -classpath $GRIDSIM/jars/gridsim.jar:. ResFailureEx01 network_ex01.txt > file.txt
+
+ In Windows:
+ java -classpath %GRIDSIM%\jars\gridsim.jar;. ResFailureEx01 network_ex01.txt > file.txt
+
+
+The above command means run the program and output the results into a file
+named "file.txt" rather than into screen or standard output.
+To prevent from overwriting an existing file, I renamed "file.txt" into
+"output.txt"
+NOTE: This example uses Java Random class to select a resource and user entity
+ to communicate to a regional GIS entity.
+ Hence, when running this example many times, the values will be different.
+
+
+When running the example file, it will produce the following files:
+
+ sim_trace -> created by the SimJava2 package (lower-level) to trace every
+ events (performed by SimJava and GridSim) during the simulation.
+ We don't need to worry about this file. Not to important for our
+ example.
+
+ sim_report -> created by the SimJava2 package (lower-level) of GridSim.
+ This is a simulation report that contains general information about
+ running this experiment. We don't need to worry about this file.
+ Not to important for our example.
+
+ Ex01_Regional_GIS -> contains one line describing each
+ registering/removing event that takes place at the GIS. Resources will
+ register at the begining of simulations, and after recovering from a
+ failure affecting all their machines. Resources will be removed when
+ they suffer a failure affecting all their machines.
+
+ Ex01_Res_0, Ex01_Res_1, Ex01_Res_2: these files record when a resource suffers a failure
+ and when it recovers from the failure. They also say how many machines
+ failed, and the time of the fail/recovery.
+
+ Ex01_User0: contains one line for each event regarding to the gridlets.
+ These events are the sending/reception of a gridlet, and each line include the status of the gridlet,
+ time, resource and VO. In this example we only have 1 VO.
+
+ Ex01_User0_Fin: contains one line for each gridlet, showing the resource
+ it has been executed, its cost, CPU time and total latency.
+
+NOTE: When you run the program multiple times, all existing files will be overwritten.
+
Added: branches/gridsim4.0-branch1/examples/ResFailureEx01/ResFailureEx01.java
===================================================================
--- branches/gridsim4.0-branch1/examples/ResFailureEx01/ResFailureEx01.java (rev 0)
+++ branches/gridsim4.0-branch1/examples/ResFailureEx01/ResFailureEx01.java 2007-08-28 06:04:16 UTC (rev 34)
@@ -0,0 +1,322 @@
+/*
+ * Title: GridSim Toolkit
+ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation
+ * of Parallel and Distributed Systems such as Clusters and Grids
+ * An example of how to use the failure functionality.
+ * Licence: GPL - http://www.gnu.org/copyleft/gpl.html
+ *
+ * Author: Agustin Caminero and Anthony Sulistio
+ * Organization: UCLM (Spain)
+ * Created on: August 2007
+ */
+
+import gridsim.resFailure.*;
+import gridsim.*;
+import gridsim.net.*;
+import java.util.*;
+import gridsim.util.NetworkReader;
+import gridsim.util.HyperExponential;
+
+
+/**
+ * This example shows a basic topology with 1 user, 3 resources and 1 GIS.
+ * All of them are connected by a router.
+ * There is only one VO in this example.
+ * @author Agustin Caminero and Anthony Sulistio
+ * @since GridSim Toolkit 4.1
+ */
+public class ResFailureEx01
+{
+ public static void main(String[] args)
+ {
+ System.out.println("Starting failure example 1...");
+
+ try
+ {
+ if (args.length < 1)
+ {
+ System.out.println("Usage: java ResFailureEx01 network_ex01.txt");
+ return;
+ }
+
+ //////////////////////////////////////////
+ // First step: Initialize the GridSim package. It should be called
+ // before creating any entities. We can't run this example without
+ // initializing GridSim first. We will get a run-time exception
+ // error.
+
+ // a flag that denotes whether to trace GridSim events or not.
+ boolean trace_flag = false; // dont use SimJava trace
+ int num_user = 1; // number of grid users
+ Calendar calendar = Calendar.getInstance();
+
+ // Initialize the GridSim package
+ System.out.println("Initializing GridSim package");
+ GridSim.init(num_user, calendar, trace_flag);
+ trace_flag = true;
+
+ //////////////////////////////////////////
+ // Second step: Builds the network topology among Routers.
+
+ String filename = args[0]; // get the network topology
+ System.out.println("Reading network from " + filename);
+ LinkedList routerList = NetworkReader.createFIFO(filename);
+
+
+ //////////////////////////////////////////
+ // Third step: Creates one RegionalGISWithFailure entity,
+ // linked to a router in the topology
+
+ Router router = null;
+ double baud_rate = 100000000; // 100Mbps, i.e. baud rate of links
+ double propDelay = 10; // propagation delay in milliseconds
+ int mtu = 1500; // max. transmission unit in byte
+ int totalMachines = 10; // num of machines each resource has
+
+ String NAME = "Ex01_"; // a common name
+ String gisName = NAME + "Regional_GIS"; // GIS name
+
+ // a network link attached to this regional GIS entity
+ Link link = new SimpleLink(gisName + "_link", baud_rate,
+ propDelay, mtu);
+
+
+ // HyperExponential: mean, standard deviation, stream
+ // how many resources will fail
+ HyperExponential failureNumResPattern =
+ new HyperExponential(totalMachines / 2, totalMachines, 4);
+
+ // when they will fail
+ HyperExponential failureTimePattern =
+ new HyperExponential(25, 100, 4);
+
+ // how long the failure will be
+ HyperExponential failureLengthPattern =
+ new HyperExponential(20, 25, 4); // big test: (20, 100, 4);
+
+
+ // creates a new Regional GIS entity that generates a resource
+ // failure message according to these patterns.
+ RegionalGISWithFailure gis = new RegionalGISWithFailure(gisName,
+ link, failureNumResPattern, failureTimePattern,
+ failureLengthPattern, 0); // TODO: 0 is redundant ?
+ gis.setTrace(trace_flag); // record this GIS activity
+
+ // link these GIS to a router
+ router = NetworkReader.getRouter("Router0", routerList);
+ linkNetwork(router, gis);
+
+ // print some info messages
+ System.out.println("Created a REGIONAL GIS with name " + gisName +
+ " and id = " + gis.get_id() + ", connected to " +
+ router.get_name() );
+
+
+ //////////////////////////////////////////
+ // Fourth step: Creates one or more GridResourceWithFailure
+ // entities, linked to a router in the topology
+
+ String sched_alg = "SPACE"; // use space-shared policy
+ int totalResource = 3; // number of resources
+ ArrayList resList = new ArrayList(totalResource);
+
+ // Each resource may have different baud rate,
+ // totalMachine, rating, allocation policy and the router to
+ // which it will be connected. However, in this example, we assume
+ // all have the same properties for simplicity.
+ int totalPE = 4; // num of PEs each machine has
+ int rating = 49000; // rating (MIPS) of PEs
+ int GB = 1000000000; // 1 GB in bits
+ baud_rate = 2.5 * GB;
+
+ for (int i = 0; i < totalResource; i++)
+ {
+ // gets the router object from the list
+ router = NetworkReader.getRouter("Router0", routerList);
+
+ // creates a new grid resource
+ String resName = NAME + "Res_" + i;
+ GridResourceWithFailure res = createGridResource(resName,
+ baud_rate, propDelay, mtu, totalPE, totalMachines,
+ rating, sched_alg);
+
+ // add a resource into a list
+ resList.add(res);
+ res.setRegionalGIS(gis); // set the regional GIS entity
+ res.setTrace(trace_flag); // record this resource activity
+
+ // link a resource to this router object
+ linkNetwork(router, res);
+
+ System.out.println("Created a RESOURCE (" + totalMachines +
+ " machines, each with " + totalPE + " PEs) with name = " +
+ resName + " and id = " + res.get_id() +
+ ", connected to router " + router.get_name() +
+ " and registered to " + gis.get_name() );
+ }
+
+ //////////////////////////////////////////
+ // Fifth step: Creates one GridUserFailure entity,
+ // linked to a router of the topology
+
+ int totalGridlet = 5; // total jobs
+ double pollTime = 100; // time between polls
+ int glSize = 100000; // the size of gridlets (input/output)
+ int glLength = 42000000; // the length (MI) of gridlets
+ String userName = NAME + "User0";
+
+ // gets the router object from the list
+ router = NetworkReader.getRouter("Router0", routerList);
+
+ // a network link attached to this entity
+ Link link2 = new SimpleLink(userName + "_link", baud_rate,
+ propDelay, mtu);
+
+ GridUserFailureEx01 user = new GridUserFailureEx01(userName, link2,
+ pollTime, glLength, glSize, glSize, trace_flag);
+ // The last parameter is the GIS this user will use to get resources
+ // for his gridlets
+
+ user.setRegionalGIS(gis); // set the regional GIS entity
+ user.setGridletNumber(totalGridlet);
+
+ System.out.println("Created a USER with name " + userName +
+ " and id = " + user.get_id() + ", connected to " +
+ router.get_name() + ", and with " + totalGridlet +
+ " gridlets. Registered to " + gis.get_name() );
+ System.out.println();
+
+
+ //////////////////////////////////////////
+ // Sixth step: Starts the simulation
+ GridSim.startGridSimulation();
+ System.out.println("\nFinish failure example 1... \n");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.out.println("Unwanted errors happen");
+ }
+ }
+
+ /**
+ * Links a particular entity with a given Router.
+ *
+ * @param router a Router object
+ * @param obj a GridSim entity to be attached to the Router
+ */
+ private static void linkNetwork(Router router, GridSimCore obj) throws Exception
+ {
+ if (router == null) {
+ System.out.println("Error - router is NULL.");
+ return;
+ }
+
+ // get the baud rate of a link
+ double baud_rate = obj.getLink().getBaudRate();
+
+ // create the packet scheduler for this link
+ PacketScheduler pktObj = new FIFOScheduler(router.get_name() +
+ "_to_" + obj.get_name() );
+
+ // attach this GridSim entity to a Router
+ router.attachHost(obj, pktObj);
+ }
+
+ /**
+ * Creates one Grid resource. A Grid resource contains one or more
+ * Machines. Similarly, a Machine contains one or more PEs (Processing
+ * Elements or CPUs).
+ * <p>
+ * In this simple example, we are simulating one Grid resource with three
+ * Machines that contains one or more PEs.
+ *
+ * @param name a Grid Resource name
+ * @param baud_rate the bandwidth of this entity
+ * @param delay the propagation delay
+ * @param MTU Maximum Transmission Unit
+ * @param totalPE number of PE per machine
+ * @param totalMachine number of machines in this resources
+ * @param rating rating of mahcines in this resource
+ * @param sched_alg the scheduling algorithm of this resource
+ * @return a GridResource object
+ */
+ private static GridResourceWithFailure createGridResource(String name,
+ double baud_rate, double delay, int MTU, int totalPE,
+ int totalMachine, int rating, String sched_alg)
+ {
+ // Here are the steps needed to create a Grid resource:
+ // 1. We need to create an object of MachineList to store one or more
+ // Machines
+ MachineList mList = new MachineList();
+ for (int i = 0; i < totalMachine; i++)
+ {
+ // 2. A Machine contains one or more PEs or CPUs. Therefore, should
+ // create an object of PEList to store these PEs before creating
+ // a Machine.
+ PEList peList = new PEList();
+
+ // 3. Create PEs and add these into an object of PEList.
+ for (int k = 0; k < totalPE; k++)
+ {
+ // need to store PE id and MIPS Rating
+ peList.add( new PE(k, rating) );
+ }
+
+ // 4. Create one Machine with its id and list of PEs or CPUs
+ mList.add( new Machine(i, peList) );
+ }
+
+
+ // 5. Create a ResourceCharacteristics object that stores the
+ // properties of a Grid resource: architecture, OS, list of
+ // Machines, allocation policy: time- or space-shared, time zone
+ // and its price (G$/PE time unit).
+ String arch = "Sun Ultra"; // system architecture
+ String os = "Solaris"; // operating system
+ double time_zone = 9.0; // time zone this resource located
+ double cost = 3.0; // the cost of using this resource
+
+ // we create Space_Shared_failure or Time_Shared_failure schedulers
+ int scheduling_alg = 0; // space_shared or time_shared
+ if (sched_alg.equals("SPACE") == true) {
+ scheduling_alg = ResourceCharacteristics.SPACE_SHARED;
+ }
+ else if (sched_alg.equals("TIME") == true) {
+ scheduling_alg = ResourceCharacteristics.TIME_SHARED;
+ }
+
+ ResourceCharacteristics resConfig = new ResourceCharacteristics(
+ arch, os, mList, scheduling_alg, time_zone, cost);
+
+
+ // 6. Finally, we need to create a GridResource object.
+ long seed = 11L*13*17*19*23+1;
+ double peakLoad = 0.0; // the resource load during peak hour
+ double offPeakLoad = 0.0; // the resource load during off-peak hr
+ double holidayLoad = 0.0; // the resource load during holiday
+
+ // incorporates weekends so the grid resource is on 7 days a week
+ LinkedList Weekends = new LinkedList();
+ Weekends.add(new Integer(Calendar.SATURDAY));
+ Weekends.add(new Integer(Calendar.SUNDAY));
+
+ // incorporates holidays. However, no holidays are set in this example
+ LinkedList Holidays = new LinkedList();
+ GridResourceWithFailure gridRes = null;
+ try
+ {
+ // creates a GridResource with a link
+ gridRes = new GridResourceWithFailure(name,
+ new SimpleLink(name + "_link", baud_rate, delay, MTU),
+ seed, resConfig, peakLoad, offPeakLoad, holidayLoad,
+ Weekends, Holidays);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return gridRes;
+ }
+
+} // end class
Added: branches/gridsim4.0-branch1/examples/ResFailureEx01/network_ex01.txt
===================================================================
--- branches/gridsim4.0-branch1/examples/ResFailureEx01/network_ex01.txt (rev 0)
+++ branches/gridsim4.0-branch1/examples/ResFailureEx01/network_ex01.txt 2007-08-28 06:04:16 UTC (rev 34)
@@ -0,0 +1,15 @@
+# The topology of this example is as follows (with 1 user and 1 resource)
+#
+# user --- Router0 ---- Resource0
+#
+# total number of Routers
+1
+
+# specifies each router name and whether to log its activities or not
+# by default no logging is required
+Router0
+
+# specify the link between two Routers
+# The format is:
+# Router_name1 Router_name2 baud_rate(GB/s) prop_delay(ms) mtu(byte)
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|