CREATING RESOURCES

This is a code, demonstrating how to create 3 resources, with the same characteristics.

int 
i = 0;
int totalResource = 3;
ArrayList resList = new ArrayList(totalResource);
for (i = 0; i < totalResource; i++)
{
    DataGridResource res = createGridResource("Res_"+i, baud_rate,
     propDelay, mtu);
     resList.add(res);
}

How to create a DataGridResource?

DataGridResource is a GridResource with some additional features:
  1. A Replica Manager
  2. a storage list
  3. (optionally) a local Replica Catalogue



The differences between creating a regular GridResource and a DataGridResource in the addition of these entities and below it is shown how this creation is done.

DataGridResource gridRes = 
null;
//create the replica manager
SimpleReplicaManager rm = new SimpleReplicaManager("RM_" + name,
                    name);
//create a storage
Storage storage = new HarddriveStorage("storage"100000)
//100GB
            
gridRes = new DataGridResource(name, new SimpleLink(name + "_link",
                    baud_rate, delay, MTU), resConfig, cal, rm);
gridRes.addStorage(storage);
//create a local replica catalogue
gridRes.setLocalRC();
//set the higher level
gridRes.setHigherReplicaCatalogue(TopRegionalRC.DEFAULT_NAME);
            
//adding files to the resource
File f1 = new File("testFile1"100);//100MB
gridRes.addFile(f1);
File f2 = new File("testFile2"100);
//100MB
gridRes.addFile(f2);





Below is the full source code for the function createGridResource()

 private static DataGridResource createGridResource(String name,
            double baud_rate, double delay, int MTU) {
        System.out.println();
        System.out.println("Starting to create one Grid resource with "
                "3 Machines");
        
        // 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();
        //System.out.println("Creates a Machine list");
        
        // 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 peList1 = new PEList();
        //System.out.println("Creates a PE list for the 1st Machine");
        
        // 3. Create PEs and add these into an object of PEList.
        //    In this example, we are using a resource from
        //    hpc420.hpcc.jp, AIST, Tokyo, Japan
        //    Note: these data are taken the from GridSim paper, page 25.
        //          In this example, all PEs has the same MIPS (Millions
        //          Instruction Per Second) Rating for a Machine.
        peList1.add(new PE(0377))// need to store PE id and MIPS Rating
        peList1.add(new PE(1377));
        peList1.add(new PE(2377));
        peList1.add(new PE(3377));
        //System.out.println("Creates 4 PEs with same MIPS Rating and put
        // them"+
        //        " into the PE list");
        
        // 4. Create one Machine with its id and list of PEs or CPUs
        mList.add(new Machine(0, peList1))// First Machine
        //System.out.println("Creates the 1st Machine that has 4 PEs and " +
        //        "stores it into the Machine list");
        //System.out.println();
        
        // 5. Repeat the process from 2 if we want to create more Machines
        //    In this example, the AIST in Japan has 3 Machines with same
        //    MIPS Rating but different PEs.
        // NOTE: if you only want to create one Machine for one Grid resource,
        //       then you could skip this step.
        PEList peList2 = new PEList();
        //System.out.println("Creates a PE list for the 2nd Machine");
        
        peList2.add(new PE(0377));
        peList2.add(new PE(1377));
        peList2.add(new PE(2377));
        peList2.add(new PE(3377));
        //System.out.println("Creates 4 PEs with same MIPS Rating and put
        // them"+
        //        " into the PE list");
        
        mList.add(new Machine(1, peList2))// Second Machine
        //System.out.println("Creates the 2nd Machine that has 4 PEs and " +
        //        "stores it into the Machine list");
        //System.out.println();
        
        PEList peList3 = new PEList();
        //System.out.println("Creates a PE list for the 3rd Machine");
        
        peList3.add(new PE(0377));
        peList3.add(new PE(1377));
        //System.out.println("Creates 2 PEs with same MIPS Rating and put
        // them"+
        //        " into the PE list");
        
        mList.add(new Machine(2, peList3))// Third Machine
        //System.out.println("Creates the 3rd Machine that has 2 PEs and " +
        //        "stores it into the Machine list");
        //System.out.println();
        
        // 6. 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
        
        ResourceCharacteristics resConfig = new ResourceCharacteristics(arch,
                os, mList, ResourceCharacteristics.TIME_SHARED, time_zone, cost);
        
        //System.out.println("Creates the properties of a Grid resource and " +
        //        "stores the Machine list");
        
        // 7. 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();
        DataGridResource gridRes = null;
        try {
            // create the replica manager
            
            SimpleReplicaManager rm = new SimpleReplicaManager("RM_" + name,
                    name);
            
            // create the resource calendar
            ResourceCalendar cal = new ResourceCalendar(time_zone, peakLoad,
                    offPeakLoad, holidayLoad, Weekends, Holidays, seed);
            
            //create a storage
            Storage storage = new HarddriveStorage("storage"100000)//100GB
            
            gridRes = new DataGridResource(name, new SimpleLink(name + "_link",
                    baud_rate, delay, MTU), resConfig, cal, rm);
            gridRes.addStorage(storage);
            //create a local replica catalogue
            gridRes.setLocalRC();
            gridRes.setHigherReplicaCatalogue(TopRegionalRC.DEFAULT_NAME);
            
            File f1 = new File("testFile1"100);
            storage.addFile(f1);
            File f2 = new File("testFile2"100);
            storage.addFile(f2);
        catch (Exception e) {
            e.printStackTrace();
        }
        
        System.out.println("Finally, creates one Grid resource (name: " + name
                " - id: " + gridRes.get_id() ")");
        System.out.println();
        
        return gridRes;
    }