|
From: <sul...@us...> - 2007-08-28 06:02:49
|
Revision: 33
http://gridsim.svn.sourceforge.net/gridsim/?rev=33&view=rev
Author: sulistio
Date: 2007-08-27 23:02:51 -0700 (Mon, 27 Aug 2007)
Log Message:
-----------
allowing printing debugging info when the trace option is set to true.
Modified Paths:
--------------
branches/gridsim4.0-branch1/source/gridsim/resFailure/GridResourceWithFailure.java
branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java
Modified: branches/gridsim4.0-branch1/source/gridsim/resFailure/GridResourceWithFailure.java
===================================================================
--- branches/gridsim4.0-branch1/source/gridsim/resFailure/GridResourceWithFailure.java 2007-08-28 06:00:14 UTC (rev 32)
+++ branches/gridsim4.0-branch1/source/gridsim/resFailure/GridResourceWithFailure.java 2007-08-28 06:02:51 UTC (rev 33)
@@ -745,14 +745,14 @@
}catch(Exception e) {}
- /*********
- //Uncomment this, if you want more info on the progress of sims
- System.out.println("################# " + super.get_name() +
- ". Received an event from " + GridSim.getEntityName(gl.getUserID()) +
- " while the resource was failed. So, event not processed. Event tag: " +
- ev.get_tag() +
- ". Returning GRIDLET_RETURN to the user.");
- *******/
+ /***********/
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": receives an event from " + GridSim.getEntityName(gl.getUserID()) +
+ " while resource is failed, so not processed. Event tag: " +
+ ev.get_tag() + ". Returning GRIDLET_RETURN to sender.");
+ }
+ /***********/
super.send(super.output, 0, GridSimTags.GRIDLET_RETURN,
new IO_data(gl,gl.getGridletOutputSize(),gl.getUserID()) );
@@ -1037,14 +1037,18 @@
AvailabilityInfo resAv = (AvailabilityInfo) ev.get_data();
- /****** // Uncomment this to get more info on the progress of sims
- System.out.println("++++++++++ " + super.get_name() +
- ". Received a poll request event from "+
+ /*******
+ // Uncomment this to get more info on the progress of sims
+ // NOTE: this keeps printing at every n seconds interval.
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": receives a poll request event from "+
GridSim.getEntityName(resAv.getSrcID()) +". Clock: " +
GridSim.clock() +". Is res failed?: "+ getResourceFailed());
+ }
*******/
- // if all the mahcines of the resource are out of order or not
+ // if all the machines of the resource are out of order or not
if (getResourceFailed())
{
resAv.setAvailability(false);
@@ -1103,10 +1107,9 @@
if (record_ == true) {
write("Failure", numMachines);
- System.out.println("################# " + super.get_name() +
- ".processFailure(): " +
- "Received an event GRIDRESOURCE_FAILURE. Clock:" +
- GridSim.clock() + " which will last until clock:" +
+ System.out.println(super.get_name() + ".processFailure(): " +
+ "receives an event GRIDRESOURCE_FAILURE. Clock: " +
+ GridSim.clock() + " which will last until clock: " +
(GridSim.clock() + time) +
". There are NO working machines in this resource.");
}
@@ -1131,9 +1134,8 @@
if (record_ == true) {
write("Failure", numFailedMachines);
- System.out.println("################# " + super.get_name() +
- ".processFailure(): " +
- "Received an event GRIDRESOURCE_FAILURE. Clock:" +
+ System.out.println(super.get_name() + ".processFailure(): " +
+ "receives an event GRIDRESOURCE_FAILURE. Clock: " +
GridSim.clock() +
". There are STILL working machines in this resource.");
}
@@ -1187,12 +1189,12 @@
System.out.println(super.get_name() + ": Resource recovered." +
" Registering the resource at the regional GIS AGAIN" +
- " after the failure at clock:" + GridSim.clock());
+ " after the failure at clock: " + GridSim.clock());
}
else {
System.out.println(super.get_name() +
- ": Resource recovered at clock:" + GridSim.clock());
+ ": Resource recovered at clock: " + GridSim.clock());
}
if (record_ == true) {
@@ -1260,30 +1262,31 @@
{
Machine mach;
- /************
- // Uncomment this if you want more info on the progress of sims
+ /************/
String status = null;
- if (b)
- status = "FAILED";
- else
- status = "WORKING";
- ************/
+ if (record_ == true) {
+ if (b)
+ status = "FAILED";
+ else
+ status = "WORKING";
+ }
+ /************/
for(int i = 0; i < numFailedMachines; i++)
{
mach = resource_.getMachineList().getMachineInPos(i);
if (mach != null)
{
- /*************
- // Uncomment htis if you want more info on the progress of sims
- System.out.println("$$$$$$ "+ super.get_name() +". Machine: "
- + i +": Setting this machine to "+ status+ "...");
- mach.setFailed(super.get_name(), i, b);
- *************/
-
- mach.setFailed(super.get_name(), b);
- }
- }
+ if (record_ == true) {
+ System.out.println(super.get_name() +" - Machine: "
+ + i + " is set to " + status);
+ mach.setFailed(super.get_name(), b);
+ }
+ else {
+ mach.setFailed(b);
+ }
+ } // end if
+ } // end for
}
/**
Modified: branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java
===================================================================
--- branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java 2007-08-28 06:00:14 UTC (rev 32)
+++ branches/gridsim4.0-branch1/source/gridsim/resFailure/RegionalGISWithFailure.java 2007-08-28 06:02:51 UTC (rev 33)
@@ -42,22 +42,15 @@
*/
public class RegionalGISWithFailure extends AbstractGIS
{
- // if there is a conflict, we can simply change this number
- private static final int GIS_WITH_FAILURE_BASE = 2000; // TODO
+ // for a RegionalGISWithFailure named "RegionalGIS_2", the gisID_ will be 2
+ // This is also the number of the VO.
+ public int gisID_; // TODO: redundant ??
- /** Denotes that an user has detected the failure of a resource.
- * So, the user sends
- * this tag to the GIS to make it update its list of resources.
- */
- public static final int RESOURCE_FAILED = GIS_WITH_FAILURE_BASE + 1; // TODO:
+
/** This entity ID in <tt>Integer</tt> object. */
protected Integer myID_;
- // for a RegionalGISWithFailure named "RegionalGIS_2", the gisID_ will be 2
- // This is also the number of the VO.
- public int gisID_; // TODO: redundant ??
-
// denotes whether sim has just began or it has been running for some time
private boolean begining;
@@ -101,7 +94,11 @@
// defines how GIS should decide how long the resource will be out of order
private Variate failureLengthPatternVariate_;
+ // a flag to denote whether to record events into a file or not
+ private boolean record_ = false;
+
+
/**
* Creates a new regional GIS entity
* @param name this regional GIS name
@@ -199,6 +196,16 @@
super.get_name() + " entity");
}
+ /**
+ * Asks this resource to record its activities. <br>
+ * NOTE: this method should be called <b>BEFORE</b> the ssimulation starts.
+ * @param trace <tt>true</tt> if you want to record this resource's
+ * activities, <tt>false</tt> otherwise
+ */
+ public void setTrace(boolean trace) {
+ record_ = trace;
+ }
+
/**
* Initialises all attributes
* @pre $none
@@ -244,20 +251,20 @@
Integer id = (Integer) obj;
list.add(id);
result = true;
- write("Registering", id.intValue(), GridSim.clock());
- if (list.size() == 1) { // REMOVE !!!
- System.out.println(super.get_name() +
- ": The list has one resource again. Clock:" + GridSim.clock());
- }
+ if (record_ == true) {
+ write("Registering", id.intValue(), GridSim.clock());
+ System.out.println();
+ System.out.println(super.get_name() + ": registering " +
+ GridSim.getEntityName(id));
- System.out.println();
- for (int i = 0; i< list.size() ; i++)
- {
- System.out.println(super.get_name() + ": list("+i+"): " +
- GridSim.getEntityName(((Integer)list.get(i)).intValue()));
+ for (int i = 0; i < list.size() ; i++)
+ {
+ System.out.println(super.get_name() + ": list["+ i +"] = " +
+ GridSim.getEntityName((Integer) list.get(i)) );
+ }
+ System.out.println();
}
- System.out.println();
}
return result;
@@ -307,7 +314,6 @@
".processRegisterResource(): Warning - can't register " +
"a resource ID.");
}
-
}
/**
@@ -339,12 +345,9 @@
"------- GRIDRESOURCE_FAILURE received at the " +
super.get_name() +
", but there is no resources available." +
- " So, scheduling a new GRIDRESOURCE_FAILURE to GIS in 2 min.");
+ " So, scheduling a new GRIDRESOURCE_FAILURE to GIS in 2 mins.");
- super.send(super.get_id(),
- Math.floor(GridSimTags.SCHEDULE_NOW + 120),
- GridSimTags.GRIDRESOURCE_FAILURE);
-
+ super.send(super.get_id(), 120, GridSimTags.GRIDRESOURCE_FAILURE);
}
// if the sim has just began, then we have to decide how many res
// will fail, when and for how long
@@ -359,13 +362,13 @@
if (numResFail > resList_.size())
numResFail = resList_.size();
- /****************
- // Uncomment this is you want more info on the progess of sims
- System.out.println("################# " +
- super.get_name() + ":" + numResFail +
+ /****************/
+ if (record_ == true) {
+ System.out.println(super.get_name() + ": " + numResFail +
" resources will fail in this simulation. " +
- "Number of failed machines in each resource will be decided later");
- *****************/
+ "Num of failed machines on each resource will be decided later");
+ }
+ /****************/
for (int i = 0; i < numResFail; i++)
{
@@ -377,22 +380,17 @@
// choose the resource which will fail and how long the failure
// will last. Then, it will send the failure signal to the resource.
- super.send(super.get_id(),
- Math.floor(GridSimTags.SCHEDULE_NOW + resTimeFail),
+ super.send(super.get_id(), resTimeFail,
GridSimTags.GRIDRESOURCE_FAILURE);
- /*********
- // Uncomment this is you want more info on the progess of sims
- System.out.println("################# " +
- super.get_name() +
- " entity sends an autogenerated GRIDRESOURCE_FAILURE to itself." +
- " GridSim.clock(): " + GridSim.clock() +
- // ". Calendar + resTimeFail: " +
- //((GridSim.getSimulationCalendar().getTimeInMillis() / 1000) + resTimeFail) + " seconds" +
- ". resTimeFail: " +
- (Math.floor(GridSimTags.SCHEDULE_NOW + resTimeFail)) +
- " seconds" + ". super.get_id(): " + super.get_id());
- ********/
+ /*********/
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": sends an autogenerated GRIDRESOURCE_FAILURE to itself." +
+ " Clock: " + GridSim.clock() + ", resTimeFail: " +
+ resTimeFail + " seconds");
+ }
+ /*********/
}
} // if (begining)
@@ -429,9 +427,7 @@
if (resChar == null)
{
- System.out.println(super.get_name() +
- " resChar == null");
-
+ System.out.println(super.get_name() + " resChar == null");
isWorking = false;
}
else
@@ -449,15 +445,16 @@
GridSimTags.SCHEDULE_NOW + failureLength,
GridSimTags.GRIDRESOURCE_RECOVERY, resFailure);
- /*****************
- // Uncomment this if you want more info on the progress
- System.out.println("################# " + super.get_name() +
- " sends a GRIDRESOURCE_FAILURE event to the resource " +
- GridSim.getEntityName(res_id) + ". numMachFailed: " +
- numMachFailed + ". GridSim.clock(): "
- + GridSim.clock() + ". Fail duration: " + (failureLength / 3600) +
- " hours. Some machines of the resource may still work, or not.");
- ******************/
+ /*****************/
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": sends a GRIDRESOURCE_FAILURE event to the resource " +
+ GridSim.getEntityName(res_id) + ". numMachFailed: " +
+ numMachFailed + ". Clock: " + GridSim.clock() +
+ ". Fail duration: " + (failureLength / 3600) +
+ " hours. Some machines may still work or may not.");
+ }
+ /*****************/
// Send the GRIDRESOURCE_FAILURE event to the resource.
super.send(super.output, 0.0, ev.get_tag(),
@@ -484,14 +481,14 @@
int resource_id = resfail.getRes();
- /***********
- // Uncomment this to get more info on the progress of the sims
- System.out.println("################# " +
- super.get_name() +
- " sends a GRIDRESOURCE_RECOVERY to the resource " +
+ /***********/
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": sends a GRIDRESOURCE_RECOVERY to the resource " +
GridSim.getEntityName(resource_id) +
". Clock: " + GridSim.clock());
- ***********/
+ }
+ /***********/
// Send the GRIDRESOURCE_RECOVERY event to the resource.
super.send(super.output, 0.0, ev.get_tag(),
@@ -499,7 +496,6 @@
resource_id));
} // if (obj instanceof FailureMsg)
-
}
@@ -516,11 +512,12 @@
Integer resID_Int = (Integer) ev.get_data();
int resID = resID_Int.intValue();
- // Uncomment this if you want more info on the progress of sims.
- System.out.println("+++++++++ " + super.get_name() +
- ": received a resource failure information event. Failed resource is " +
- GridSim.getEntityName(resID) + ". resID: " +
- resID + ". Clock: " + GridSim.clock());
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": receives a resource failure information event. " +
+ "Failed resource is " + GridSim.getEntityName(resID) +
+ ". resID: " + resID + ". Clock: " + GridSim.clock());
+ }
removeResource(resID);
}
@@ -539,27 +536,31 @@
if (((Integer) resList_.get(j)).intValue() == resID)
{
resList_.remove(j);
- write("Removing", resID, GridSim.clock());
- if (resList_.size() == 0) // REMOVE !!!
- {
- System.out.println(super.get_name() +
- ": No resources available at this moment. Clock:" +
+ if (record_ == true) {
+ write("Removing", resID, GridSim.clock());
+ if (resList_.size() == 0)
+ {
+ System.out.println(super.get_name() +
+ ": No resources available at this moment. Clock: " +
GridSim.clock());
+ }
}
}
}
- /***********
- // Uncomment this of you want more info on the progress of sims
- System.out.println("Resource list after removing one");
- for (int j = 0; j < resList_.size(); j++)
- {
- System.out.println(
- GridSim.getEntityName( ((Integer)resList_.get(j)).intValue()) );
-
+ /***********/
+ if (record_ == true) {
+ System.out.println();
+ System.out.println(super.get_name() + ": Resource list after removal");
+ for (int j = 0; j < resList_.size(); j++)
+ {
+ System.out.println(super.get_name() + ": list["+ j +"] = " +
+ GridSim.getEntityName((Integer)resList_.get(j)) );
+ }
+ System.out.println();
}
- **********/
+ /**********/
}
/**
@@ -570,6 +571,10 @@
*/
private void write(String event, int resID, double clock)
{
+ if (record_ == false) {
+ return;
+ }
+
// Write into a results file
FileWriter fwriter = null;
try
@@ -641,14 +646,16 @@
res_id = resAv.getResID();
- /*
- // Uncomment this if you want more info on the progress of sims.
- System.out.println("+++++++++ " + super.get_name() +
- ": received a poll response from " +
- GridSim.getEntityName(resID) + ". resID: " + resID +
+ /*****************
+ // NOTE: this keeps printing at every n seconds interval.
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": receives a poll response from " +
+ GridSim.getEntityName(res_id) + ". resID: " + res_id +
". Is res available? " + resAv.getAvailability() +
". Clock: " + GridSim.clock());
- */
+ }
+ ****************/
// Find the AvailabilityInfo object corresponding to the resource
// which has answered this poll request
@@ -665,28 +672,25 @@
removeResource(res_id);
}
}
- }
+ } // for
- } // for (int i = 0; i < resList_.size(); i++)
+ } // for
- /**********
- // Uncomment this if you want more info on the progress of sims.
- if (resList_.size() == 0)
- {
- System.out.println("+++++++++++++ " + super.get_name() +
- ": After polling, no resource in the GIS. ");
+ /**********/
+ if (record_ == true) {
+ if (resList_.size() == 0) {
+ System.out.println(super.get_name() +
+ ": After polling, no resource in the GIS. ");
+ }
+ }
+ /*********/
- }*/
-
// Schedule the following polling event.
- super.send(super.get_id(),
- Math.floor(GridSimTags.SCHEDULE_NOW +
- GridSimTags.POLLING_TIME_GIS),
+ super.send(super.get_id(), GridSimTags.POLLING_TIME_GIS,
GridSimTags.GRIDRESOURCE_POLLING);
}
-
/**
* Process an incoming request that uses a user-defined tag. <br>
* NOTE: This method can be overridden by its subclasses, provided
@@ -718,8 +722,8 @@
processGridResource_Polling(ev);
break;
- // An user tells the GIS that a resource is out of order
- case RESOURCE_FAILED:
+ // A user tells the GIS that a resource is out of order
+ case AbstractGIS.NOTIFY_GIS_RESOURCE_FAILURE:
processResourceFailed(ev);
break;
@@ -1044,8 +1048,6 @@
// send a request to a regional GIS
super.send( super.output, 0.0, eventTag,
new IO_data(myID_, Link.DEFAULT_MTU, obj.intValue()) );
-
-
}
return true;
@@ -1232,7 +1234,6 @@
*/
protected void registerOtherEntity()
{
-
double resTimeFail = getNextFailureTimeSample();
// the time when we will decide when a resource will fail
@@ -1242,23 +1243,20 @@
// will fail and how long the failure will last.
// Then, it will send the failure signal
// to the resource.
- super.send(super.get_id(),
- Math.floor(GridSimTags.SCHEDULE_NOW + resTimeFail),
- GridSimTags.GRIDRESOURCE_FAILURE);
+ super.send(super.get_id(), resTimeFail, GridSimTags.GRIDRESOURCE_FAILURE);
- /**************
- // Uncomment this is you want mor info on the progess of sims
- System.out.println("################# " + super.get_name() +
- " entity sends an autogenerated GRIDRESOURCE_FAILURE to itself."+
- " GridSim.clock(): " + GridSim.clock() + ". resTimeFail: " +
- (Math.floor(GridSimTags.SCHEDULE_NOW + resTimeFail)) +
- " seconds" + ". super.get_id(): " + super.get_id());
- ***************/
+ /**************/
+ if (record_ == true) {
+ System.out.println(super.get_name() +
+ ": sends an autogenerated GRIDRESOURCE_FAILURE to itself."+
+ " Clock(): " + GridSim.clock() + ". resTimeFail: " +
+ resTimeFail + " seconds");
+ }
+ /***************/
// Now, we have to start the polling functionality
- super.send(super.get_id(),
- Math.floor(GridSimTags.SCHEDULE_NOW + GridSimTags.POLLING_TIME_GIS),
- GridSimTags.GRIDRESOURCE_POLLING);
+ super.send(super.get_id(), GridSimTags.POLLING_TIME_GIS,
+ GridSimTags.GRIDRESOURCE_POLLING);
}
@@ -1403,7 +1401,7 @@
* discrete or continuous.
* @return the sample for the number of resources which will fail
*/
- public double getNextFailureNumResSample()
+ protected double getNextFailureNumResSample()
{
double sample;
if (failureNumResPatternDiscrete_ != null)
@@ -1432,7 +1430,7 @@
* discrete or continuous.
* @return the sample for the time when resources will fail
*/
- public double getNextFailureTimeSample() {
+ protected double getNextFailureTimeSample() {
double sample;
if (failureTimePatternDiscrete_ != null)
{
@@ -1461,7 +1459,7 @@
* discrete or continuous.
* @return the sample for the time when resources will fail
*/
- public double getNextFailureLengthSample() {
+ protected double getNextFailureLengthSample() {
double sample;
if (failureLengthPatternDiscrete_ != null)
{
@@ -1494,12 +1492,11 @@
* @return the sample for the number of machines which will fail
* in a resource
*/
- public double getNextNumMachinesFailedSample() {
+ protected double getNextNumMachinesFailedSample() {
return getNextFailureNumResSample();
}
-
/**
* Gets a ResourceCharacteristics object for a given GridResource ID. <br>
* NOTE: This method returns a reference of ResourceCharacteristics object,
@@ -1518,7 +1515,7 @@
* @pre resourceID > 0
* @post $none
*/
- public ResourceCharacteristics getResourceCharacteristics(int resourceID)
+ private ResourceCharacteristics getResourceCharacteristics(int resourceID)
{
// Get Resource Characteristic Info: Send Request and Receive Event/Msg
send(super.output, 0.0, GridSimTags.RESOURCE_CHARACTERISTICS,
@@ -1544,20 +1541,11 @@
}
/**
- * Returns the gisID_ attribute of this entity*/
- /*** // TODO: redundant ??
- public int getGisID()
- {
- return gisID_;
- }
- ***/
-
- /**
* This function is to poll the resources in order to check whether
* they are failed or not
* @return true if everything works well
*/
- public boolean pollResource(int resID)
+ protected boolean pollResource(int resID)
{
if (resID < 0)
{
@@ -1579,7 +1567,7 @@
* This function is to receive back the polls from the resources
* @return a AvailabilityInfo object
*/
- public AvailabilityInfo pollReturn()
+ protected AvailabilityInfo pollReturn()
{
Sim_event ev = new Sim_event();
@@ -1593,13 +1581,15 @@
try
{
resAv = (AvailabilityInfo) ev.get_data();
- } catch (Sim_exception sim)
+ }
+ catch (Sim_exception sim)
{
System.out.print(super.get_name() + ".pollReturn(): Error - ");
System.out.println("exception occurs. See the below message:");
System.out.println(sim.getMessage());
resAv = null;
- } catch (Exception e)
+ }
+ catch (Exception e)
{
System.out.print(super.get_name() + ".pollReturn(): Error - ");
System.out.println("exception occurs. See the below message:");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|