Example #1
0
  @Override
  public Response debug(Debug debug) throws TException {
    Set<Byte> partitions;
    if (debug.getType() == DebugCommands.POPULATE_FILE.getId()) {
      partitions = oracle.partitionsOf("/");
    } else {
      partitions = new HashSet<>();
      partitions.add(Byte.valueOf(Byte.parseByte(debug.getData().get("partition"))));
    }

    Command cmd = newCommand(CommandType.DEBUG, partitions, null);
    cmd.setDebug(debug);
    replica.submitCommand(cmd);
    Response r = new Response(replica.getInstanceMap());
    return r;
  }
Example #2
0
 @Override
 public Response getattr(String path, Map<Byte, Long> instanceMap) throws TException {
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   path = makePathAbsolute(path);
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.ATTR, parts, instanceMap);
   AttrCmd attr = new AttrCmd(path, parts);
   cmd.setAttr(attr);
   Attr result = (Attr) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setGetattr(result);
   return r;
 }
Example #3
0
 @Override
 public Response readlink(String path, Map<Byte, Long> instanceMap) throws TException {
   path = makePathAbsolute(path);
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.READLINK, parts, instanceMap);
   ReadlinkCmd readlink = new ReadlinkCmd(path, parts);
   cmd.setReadlink(readlink);
   String result = (String) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setReadlink(result);
   return r;
 }
Example #4
0
 @Override
 public Response getdir(String path, Map<Byte, Long> instanceMap) throws TException {
   // can be sent to ANY partition that replicates the path - we send it to the first returned by
   // the oracle
   path = makePathAbsolute(path);
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.GETDIR, parts, instanceMap);
   GetdirCmd getdir = new GetdirCmd(path, parts);
   cmd.setGetdir(getdir);
   @SuppressWarnings("unchecked")
   List<DirEntry> entries = (List<DirEntry>) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setGetdir(entries);
   return r;
 }
Example #5
0
 @Override
 public Response readBlocks(
     String path, FileHandle fh, long offset, long bytes, Map<Byte, Long> instanceMap)
     throws TException {
   path = makePathAbsolute(path);
   // assuming this replica replicates the file, send to own partition
   Set<Byte> parts = Sets.newHashSet(Byte.valueOf(partition));
   Command cmd = newCommand(CommandType.READ_BLOCKS, parts, instanceMap);
   ReadBlocksCmd read = new ReadBlocksCmd(path, fh, offset, bytes, parts);
   cmd.setRead(read);
   ReadResult readResult = (ReadResult) replica.submitCommand(cmd);
   Response r = new Response(replica.getInstanceMap());
   r.setReadBlocks(readResult);
   return r;
 }