logo
Go to the homepage of the Vrije Universiteit. Goto the homepage of the faculty of sciences. Goto the homepage of the department of computer science.

Cluster and Grid Computing (Practical Work)


GAT Adaptors:

As explained in the first assignment, the GAT provides a set of interfaces which allow you to perform the basic tasks needed on a grid, such as copying files or scheduling jobs. Each of these interfaces in the GAT is implemented by one or more adaptors. Each adaptor provides an implementation of a GAT interface using specific libraries or services (such as Globus, GridFTP, SSH, etc.). When a GAT application is run, the GAT engine decides which of the available adaptors should be used to implement the interfaces that are used by the application.

For each of the interfaces of the GAT, there is a so called Capability Provider Interface (CPI) class. This is an abstract Java class which provides a default implementation of the interface. For example, the org.gridlab.gat.io.File interface looks like this (javadoc):

   public interface File extends Monitorable, Serializable, Advertisable, Comparable {

        public URI toURI();
        public void copy(URI loc) throws GATInvocationException;
        public boolean delete() throws GATInvocationException;
        public void move(URI location) throws GATInvocationException;
        public boolean canRead() throws GATInvocationException;     
        public boolean canWrite() throws GATInvocationException;
        .... (lots of other methods) ....
   }

The CPI for this File interface can be found in org.gridlab.gat.io.cpi.FileCPI and looks like this:

   public abstract class FileCpi implements FileInterface {

      protected GATContext gatContext;
      protected Preferences preferences;
      protected URI location;

      protected FileCpi(GATContext gatContext, Preferences preferences, URI location) {
          this.gatContext = gatContext;
          this.preferences = preferences;
          this.location = location;
      }

      public final URI toURI() {
          return location;
      }

      public void copy(URI loc) throws GATInvocationException {
          throw new UnsupportedOperationException("Not implemented");
      }

      public boolean delete() throws GATInvocationException {
          throw new UnsupportedOperationException("Not implemented");
      }

      public void move(URI destination) throws GATInvocationException {
          copy(destination);
          // We create a new File object for deleting the original file,
         as it might need a different adaptor.
          File f = GAT.createFile(gatContext, preferences, location);
          f.delete();       }

      public boolean canRead() throws GATInvocationException {
          throw new UnsupportedOperationException("Not implemented");
      }

      public boolean canWrite() throws GATInvocationException {
          throw new UnsupportedOperationException("Not implemented");
      }

      ....
   }

As you can see, the CPI class mostly consists of default method implementations that throw an Error, although some methods already contain a default implementation. The move method, for example, is implemented by first copying the file, and then deleting it. As a result, any adaptors implementing the File interface do not necessarily have to implement the move method (they can still override it if they want to provide an alternative implementation).

An adaptor consists of a class that extends a certain CPI class, implementing one or more of the unimplemented methods. For example, the local file adaptor consists of the following class:

   public class LocalFileAdaptor extends FileCpi {

      File f;

      public LocalFileAdaptor(GATContext gatContext, Preferences preferences, URI location) ... {           
         super(gatContext, preferences, location);
       
         if (location.getHost() != null && !location.getHost().equals("localhost")) {
            throw new GATObjectCreationException("Cannot use remote files with local adaptor");
         }

         if (!location.isCompatible("file")) {
            throw new GATObjectCreationException("cannot handle this URI");
         }
       
         location = correctURI(location);      
         ...
         f = new File(location.getPath());
      }

      public void copy(URI loc) throws GATInvocationException {
         // very long implementation ;-)
      }

      public boolean canRead() {
         return f.canRead();
      }

      public boolean canWrite() {
         return f.canWrite();
      }

      public boolean delete() {
         return f.delete();
      }
 
      ....
   }

As shown above, the local file adaptor implements the File CPI by creating a local java.io.File object and forwarding all invocations. Occasionally, it performs extra checks to make sure that is is only used for local files (such as in the constructor). The globus file adaptor looks very different:

   public class GlobusFileAdaptor extends FileCpi {
     
      public GlobusFileAdaptor(GATContext gatContext, Preferences prefs, URI location) ... {
         super(gatContext, prefs, location);
      }

      public void copy(URI dest) throws GATInvocationException {
         if (dest.refersToLocalHost() && (toURI().refersToLocalHost())) {
            throw new GATInvocationException("gridftp cannot copy local files");
         }

         if (dest.isLocal()) {
            copyToLocal(fixURI(toURI()), fixURI(dest));
         } else if (toURI().isLocal()) {
            copyToRemote(fixURI(toURI()), fixURI(dest));
         } else {
            copyThirdParty(fixURI(toURI()), fixURI(dest));
         }
      }

      protected void copyThirdParty(URI src, URI dest) throws GATInvocationException {
         try {
            FTPClient srcClient = createClient(src);
            FTPClient destClient = createClient(dest);
            HostPort hp = destClient.setPassive();
            srcClient.setActive(hp);

            boolean append = true;
            String remoteSrcFile = this.getPath();
            String remoteDestFile = dest.getPath();

            srcClient.transfer(remoteSrcFile, destClient, remoteDestFile, append, null);
         } catch ( ... ) {
               ....
         }
      }

      ....
   }

As shown above, the globus file adaptor works by creating FTPClient objects, and using these objects for sending FTP commands to the Globus FTP daemons running on the source and destination machines. In a similar way, File adaptors can be created that use SSH, HTTP, WebDAV, BitTorrent, etc.

For this assignment, you have to create a GAT adaptor that implements the ResourceBroker Interface


If you spot a mistake, please e-mail the maintainer of this page.
Your browser does not fully support CSS. This may result in visual artifacts.