From: <aca...@us...> - 2008-07-29 14:28:38
|
Revision: 191 http://gridsim.svn.sourceforge.net/gridsim/?rev=191&view=rev Author: acaminero Date: 2008-07-29 14:28:46 +0000 (Tue, 29 Jul 2008) Log Message: ----------- to allow future extensions (drop other things than files and gridlets) Modified Paths: -------------- branches/gridsim4.0-branch2/source/gridsim/datagrid/DataGridUser.java Modified: branches/gridsim4.0-branch2/source/gridsim/datagrid/DataGridUser.java =================================================================== --- branches/gridsim4.0-branch2/source/gridsim/datagrid/DataGridUser.java 2008-07-29 14:27:35 UTC (rev 190) +++ branches/gridsim4.0-branch2/source/gridsim/datagrid/DataGridUser.java 2008-07-29 14:28:46 UTC (rev 191) @@ -3,6 +3,11 @@ * Description: GridSim (Grid Simulation) Toolkit for Modeling and Simulation * of Parallel and Distributed Systems such as Clusters and Grids * Licence: GPL - http://www.gnu.org/copyleft/gpl.html + * + * + * + * Modified: + * - addMaster(..) */ package gridsim.datagrid; @@ -12,6 +17,7 @@ import gridsim.net.Link; import gridsim.datagrid.filter.*; import java.util.*; +import gridsim.net.fnb.*; /** @@ -19,11 +25,12 @@ * @author Uros Cibej and Anthony Sulistio * @since GridSim Toolkit 4.0 */ -public class DataGridUser extends GridUser { +public class DataGridUser extends GridUser +{ - private String rcName_; // replica catalogue name - private int rcID_; // replica catalogue ID - private Integer myID_; // this entity ID + private String rcName_; // replica catalogue name + private int rcID_; // replica catalogue ID + private Integer myID_; // this entity ID /** @@ -55,8 +62,8 @@ * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(String) * @see gridsim.datagrid.DataGridUser#setReplicaCatalogue(AbstractRC) */ - public DataGridUser(String name, Link link, String regionalGIS) - throws Exception + public DataGridUser(String name, Link link, String regionalGIS) throws + Exception { super(name, link, regionalGIS); init(); @@ -67,7 +74,7 @@ { rcName_ = null; rcID_ = -1; - myID_ = new Integer( super.get_id() ); + myID_ = new Integer(super.get_id()); } /** @@ -83,12 +90,13 @@ { super(name, link, regionalGIS); rcID_ = GridSim.getEntityId(rcName); - if (rcName == null || rcID_ == -1) { + if (rcName == null || rcID_ == -1) + { throw new Exception(name + ": Error - invalid RC name"); } rcName_ = rcName; - myID_ = new Integer( super.get_id() ); + myID_ = new Integer(super.get_id()); } /** @@ -100,7 +108,8 @@ public boolean setReplicaCatalogue(String rcName) { int id = GridSim.getEntityId(rcName); - if (rcName == null || id == -1) { + if (rcName == null || id == -1) + { return false; } rcName_ = rcName; @@ -116,10 +125,11 @@ */ public boolean setReplicaCatalogue(AbstractRC rc) { - if (rc == null) { + if (rc == null) + { return false; } - return setReplicaCatalogue( rc.get_name() ); + return setReplicaCatalogue(rc.get_name()); } /** @@ -142,9 +152,9 @@ if (rcID_ == -1) { result = false; - rcName_ = null; // change the RC name to null + rcName_ = null; // change the RC name to null System.out.println(super.get_name() + - ": Error - no TopRegionalRC entity exists."); + ": Error - no TopRegionalRC entity exists."); } } @@ -177,7 +187,8 @@ * @return a list of local RC IDs in <tt>Integer</tt> object * or <tt>null</tt> if RCs do not exist. */ - public Object[] getLocalRCList() { + public Object[] getLocalRCList() + { return super.getList(DataGridTags.INQUIRY_LOCAL_RC_LIST); } @@ -188,7 +199,8 @@ * @return a list of global RC IDs in <tt>Integer</tt> object * or <tt>null</tt> if RCs do not exist. */ - public Object[] getGlobalRCList() { + public Object[] getGlobalRCList() + { return super.getList(DataGridTags.INQUIRY_GLOBAL_RC_LIST); } @@ -204,16 +216,18 @@ */ public int getReplicaLocation(String lfn) { - if (lfn == null) { + if (lfn == null) + { return -1; } int resourceID = -1; - int eventTag = DataGridTags.CTLG_GET_REPLICA; // set tag name + int eventTag = DataGridTags.CTLG_GET_REPLICA; // set tag name // consult with the RC first int rcID = getReplicaCatalogueID(); - if (rcID == -1) { + if (rcID == -1) + { return -1; } @@ -221,28 +235,60 @@ sendEvent(eventTag, lfn, rcID); // waiting for a response from the RC - Sim_type_p tag = new Sim_type_p(DataGridTags.CTLG_REPLICA_DELIVERY); + while (Sim_system.running()) + { + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue - // only look for this type of ack - Sim_event ev = new Sim_event(); - super.sim_get_next(tag, ev); + switch (ev.get_tag()) + { + // if everything works fine + case DataGridTags.CTLG_REPLICA_DELIVERY: + try + { + Object[] data = (Object[]) ev.get_data(); // get the data + Integer resID = (Integer) data[1]; // get the resource ID + if (resID != null) + { + resourceID = resID.intValue(); + } + } catch (Exception e) + { + resourceID = -1; + System.out.println(super.get_name() + + ".getReplicaLocation(): Exception"); + } - try - { - Object[] data = (Object[]) ev.get_data(); // get the data - Integer resID = (Integer) data[1]; // get the resource ID - if (resID != null) { - resourceID = resID.intValue(); - } - } - catch (Exception e) - { - resourceID = -1; - System.out.println(super.get_name() - + ".getReplicaLocation(): Exception"); - } + return resourceID; - return resourceID; + // if there is a dropped pkt + case GridSimTags.FNB_FILE_FAILED_BECAUSE_PACKET_DROPPED: + + // check that this event is for the current file + FnbMessageDropFile msgDropGl = ((FnbMessageDropFile)ev.get_data()); + + String filename = msgDropGl.getFilename(); + + System.out.println(super.get_name() + + ".getReplicaLocation(): FNB_FILE_FAILED_BECAUSE_PACKET_DROPPED." + + " filename: " + filename); + + if (filename.compareTo(lfn) == 0) + { + // the file we are wating for has been dropped + return -1; + + } + // keep waiting + break; + + } //switch (ev.get_tag()) + + } // while (Sim_system.running()) + + return -1; + + } /** @@ -268,7 +314,8 @@ */ public List getReplicaLocationList(String lfn, int rcID) { - if (lfn == null || rcID == -1) { + if (lfn == null || rcID == -1) + { return null; } @@ -277,23 +324,22 @@ sendEvent(eventTag, lfn, rcID); // waiting for a response from the RC - Sim_type_p tag =new Sim_type_p(DataGridTags.CTLG_REPLICA_LIST_DELIVERY); + Sim_type_p tag = new Sim_type_p(DataGridTags.CTLG_REPLICA_LIST_DELIVERY); // only look for this type of ack Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); - List resList = null; // a list of resource IDs storing lfn + List resList = null; // a list of resource IDs storing lfn try { - Object[] data = (Object[]) ev.get_data(); // get the data - resList = (List) data[1]; // get the resource list - } - catch (Exception e) + Object[] data = (Object[]) ev.get_data(); // get the data + resList = (List) data[1]; // get the resource list + } catch (Exception e) { resList = null; System.out.println(super.get_name() - + ".getReplicaLocationList(): Exception."); + + ".getReplicaLocationList(): Exception."); } return resList; @@ -308,7 +354,8 @@ { // check first int rcID = getReplicaCatalogueID(); - if (rcID == -1 || lfn == null) { + if (rcID == -1 || lfn == null) + { return null; } @@ -325,14 +372,14 @@ Sim_event ev = new Sim_event(); super.sim_get_next(tag, ev); - try { + try + { fAttr = (FileAttribute) ev.get_data(); - } - catch (Exception e) + } catch (Exception e) { fAttr = null; System.out.println(super.get_name() - + ".getFileAttribute(): Exception"); + + ".getFileAttribute(): Exception"); } return fAttr; } @@ -345,7 +392,8 @@ */ public boolean addMaster(File file, int resID) { - if (file == null || resID == -1) { + if (file == null || resID == -1) + { return false; } @@ -354,39 +402,89 @@ packet[0] = file; packet[1] = myID_; + int fileID = file.getRegistrationID(); + //System.out.println(super.get_name() + ": addMaster. FileID: " + fileID + ". FileName: " + file.getName() ); + int tag = DataGridTags.FILE_ADD_MASTER; - super.send(super.output, 0.0, tag, new IO_data(packet,fileSize,resID)); + super.send(super.output, 0.0, tag, new IO_data(packet, fileSize, resID)); // wait for the result back - tag = DataGridTags.FILE_ADD_MASTER_RESULT; - FilterDataResult type = new FilterDataResult(file.getName(), tag); - Sim_event ev = new Sim_event(); - super.sim_get_next(type, ev); + //tag = DataGridTags.FILE_ADD_MASTER_RESULT; - boolean result = false; - try + //FilterDataResult type = new FilterDataResult(file.getName(), tag); + + while (Sim_system.running()) { - packet = (Object[]) ev.get_data(); // get the data - String resName = GridSim.getEntityName(resID); // resource name - int msg = ((Integer) packet[2]).intValue(); // get the result - if (msg == DataGridTags.FILE_ADD_SUCCESSFUL) + Sim_event ev = new Sim_event(); + super.sim_get_next(ev); // get the next event in the queue + + switch (ev.get_tag()) { - result = true; - System.out.println(super.get_name() + ".addMaster(): " + - file.getName() + " has been added to " + resName); - } - else { - System.out.println(super.get_name() + ".addMaster(): " + - "Error in adding " + file.getName() + " to " + resName); - } - } - catch (Exception e) - { - result = false; - System.out.println(super.get_name() + ".addMaster(): Exception"); - } + // if everything works fine + case DataGridTags.FILE_ADD_MASTER_RESULT: - return result; + boolean result = false; + try + { + packet = (Object[]) ev.get_data(); // get the data + String resName = GridSim.getEntityName(resID); // resource name + int msg = ((Integer) packet[2]).intValue(); // get the result + if (msg == DataGridTags.FILE_ADD_SUCCESSFUL) + { + result = true; + fileID = file.getRegistrationID(); + + System.out.println(super.get_name() + + ".addMaster(): " + + file.getName() + + " has been added to " + resName + + ". FileID: " + fileID); + } + else + { + System.out.println(super.get_name() + + ".addMaster(): " + + "Error in adding " + + file.getName() + " to " + + resName); + } + } catch (Exception e) + { + result = false; + System.out.println(super.get_name() + + ".addMaster(): Exception"); + } + + return result; + + // if there is a dropped pkt + case GridSimTags.FNB_FILE_FAILED_BECAUSE_PACKET_DROPPED: + + // check that this event is for the current file + FnbMessageDropFile msgDropGl = ((FnbMessageDropFile)ev.get_data()); + + String filename = msgDropGl.getFilename(); + + System.out.println(super.get_name() + + ".addMaster(): FNB_FILE_FAILED_BECAUSE_PACKET_DROPPED." + + " filename: " + filename); + + if (filename.compareTo(file.getName()) == 0) + { + // the file we are wating for has been dropped + return false; + + } + + // keep waiting + break; + + } //switch (ev.get_tag()) + + } // while (Sim_system.running()) + + return false; + } /** @@ -398,12 +496,13 @@ public boolean replicateFile(File master, int resID) { // check for errors first - if (master == null || resID == -1) { + if (master == null || resID == -1) + { return false; } - File file = master.makeReplica(); // makes a replica of this file - int fileSize = file.getSizeInByte(); // size of the replica file + File file = master.makeReplica(); // makes a replica of this file + int fileSize = file.getSizeInByte(); // size of the replica file Object[] packet = new Object[2]; packet[0] = file; packet[1] = myID_; @@ -429,16 +528,19 @@ { result = true; System.out.println(super.get_name() + ".replicateFile(): " + - filename + " has been replicated to " + resName); + filename + " has been replicated to " + + resName); } - else { + else + { System.out.println(super.get_name() + ".replicateFile(): " + - "There was an error in replicating " + filename + - " to " + resName); + "There was an error in replicating " + + filename + + " to " + resName); } - } - catch (Exception e) { - System.out.println(super.get_name()+".replicateFile(): Exception"); + } catch (Exception e) + { + System.out.println(super.get_name() + ".replicateFile(): Exception"); result = false; } @@ -454,7 +556,8 @@ public boolean deleteFile(String filename, int resID) { // check for errors first - if (resID == -1 || filename == null) { + if (resID == -1 || filename == null) + { return false; } @@ -478,19 +581,22 @@ packet = (Object[]) ev.get_data(); String resName = GridSim.getEntityName(resID); int msg = ((Integer) packet[1]).intValue(); - if (msg == DataGridTags.FILE_DELETE_SUCCESSFUL) { + if (msg == DataGridTags.FILE_DELETE_SUCCESSFUL) + { result = true; System.out.println(super.get_name() + ".deleteFile(): " + - filename + " has been deleted from " + resName); + filename + " has been deleted from " + + resName); } - else { + else + { System.out.println(super.get_name() + ".deleteFile(): " + - "There was an error in deleting " + filename + - " from " + resName); + "There was an error in deleting " + filename + + " from " + resName); } - } - catch (Exception e) { + } catch (Exception e) + { System.out.println(super.get_name() + ".deleteFile(): Exception"); result = false; } @@ -506,7 +612,8 @@ public boolean deleteMaster(String filename, int resID) { // check for errors first - if (resID == -1 || filename == null) { + if (resID == -1 || filename == null) + { return false; } @@ -530,27 +637,29 @@ packet = (Object[]) ev.get_data(); String resName = GridSim.getEntityName(resID); int msg = ((Integer) packet[1]).intValue(); - if (msg == DataGridTags.FILE_DELETE_SUCCESSFUL) { + if (msg == DataGridTags.FILE_DELETE_SUCCESSFUL) + { result = true; System.out.println(super.get_name() + ".deleteMaster(): " + - filename + " has been deleted from " + resName); + filename + " has been deleted from " + + resName); } - else { + else + { System.out.println(super.get_name() + ".deleteMaster(): " + - "There was an error in deleting " + filename + - " from " + resName); + "There was an error in deleting " + filename + + " from " + resName); } - } - catch (Exception e) { + } catch (Exception e) + { System.out.println(super.get_name() + ".masterFile(): Exception"); result = false; } return result; } - - + /** * Gets a list of file attributes from a given filter * @param filter a filtering function @@ -560,7 +669,8 @@ { // check for errors first int rcID = getReplicaCatalogueID(); - if (filter == null || rcID == -1) { + if (filter == null || rcID == -1) + { return null; } @@ -577,15 +687,16 @@ // waiting for a response from the RC Sim_type_p tag = new Sim_type_p(DataGridTags.CTLG_FILTER_DELIVERY); Sim_event ev = new Sim_event(); - super.sim_get_next(tag, ev); // only look for this type of ack + super.sim_get_next(tag, ev); // only look for this type of ack - try { + try + { attrList = (ArrayList) ev.get_data(); - } - catch (Exception e) { + } catch (Exception e) + { attrList = null; System.out.println(super.get_name() + - ".getAttributeList(): Exception"); + ".getAttributeList(): Exception"); } return attrList; } @@ -598,7 +709,8 @@ */ public File getFile(String lfn, int resID) { - if (lfn == null || resID == -1) { + if (lfn == null || resID == -1) + { return null; } @@ -609,13 +721,14 @@ // waiting for a response from the resource Sim_type_p tag = new Sim_type_p(DataGridTags.FILE_DELIVERY); Sim_event ev = new Sim_event(); - super.sim_get_next(tag, ev); // only look for this type of ack + super.sim_get_next(tag, ev); // only look for this type of ack File file = null; - try { + try + { file = (File) ev.get_data(); - } - catch (Exception e) { + } catch (Exception e) + { file = null; System.out.println(super.get_name() + ".getFile(): Exception"); } @@ -636,7 +749,8 @@ public String getFullFilename(String filename) { ArrayList list = getAttributeList(new FileNameFilter(filename)); - if (list != null && list.size() > 0) { + if (list != null && list.size() > 0) + { FileAttribute att = (FileAttribute) list.get(0); return att.getName(); } @@ -652,7 +766,8 @@ private void sendEvent(int eventTag, String lfn, int resID) { int size = lfn.length(); - if (size < DataGridTags.PKT_SIZE) { + if (size < DataGridTags.PKT_SIZE) + { size = DataGridTags.PKT_SIZE; } Object[] packet = new Object[2]; @@ -660,7 +775,7 @@ packet[1] = myID_; // send a message - super.send(super.output, 0, eventTag, new IO_data(packet,size,resID)); + super.send(super.output, 0, eventTag, new IO_data(packet, size, resID)); } } // end class This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |