예제 #1
0
  @Test
  public void testRenameFile() throws Exception {
    VOLUME_NAME = "testRenameFile";
    String fileName = "testfile";
    String renamedFileName = "renamed";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    FileHandle fh =
        volume.openFile(
            userCredentials,
            fileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);
    fh.close();
    // nothing should happen
    volume.rename(userCredentials, fileName, fileName);
    DirectoryEntries dir = volume.readDir(userCredentials, "/", 0, 100, true);
    assertEquals(fileName, dir.getEntries(2).getName());
    assertEquals(3, dir.getEntriesCount());

    volume.rename(userCredentials, fileName, renamedFileName);
    dir = volume.readDir(userCredentials, "/", 0, 100, true);
    assertEquals(renamedFileName, dir.getEntries(2).getName());
    assertEquals(3, dir.getEntriesCount());
  }
예제 #2
0
 @Test
 public void testGetXattrSize() throws Exception {
   VOLUME_NAME = "testGetXattrSize";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_SYNC.getNumber(),
           0777);
   fh.close();
   int size = volume.getXAttrSize(userCredentials, fileName, "xtreemfs.set_repl_update_policy");
   assertEquals(0, size);
   size = volume.getXAttrSize(userCredentials, fileName, "xtreemfs.owner");
   assertEquals(userCredentials.getUsername().length(), size);
   size = volume.getXAttrSize(userCredentials, fileName, "doesnt-exist");
   assertEquals(-1, size);
   volume.setXAttr(userCredentials, fileName, "foo", "bar", XATTR_FLAGS.XATTR_FLAGS_CREATE);
   size = volume.getXAttrSize(userCredentials, fileName, "foo");
   assertEquals(3, size);
   size = volume.getXAttrSize(userCredentials, fileName, "doesnt-exist-in-cache");
   assertEquals(-1, size);
 }
예제 #3
0
  @Test
  public void testReplicaAddListRemove() throws Exception {
    VOLUME_NAME = "testReplicaAddListRemove";
    final String fileName = "testfile";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // set replication update policy of the file
    int flags = ReplicationFlags.setSequentialStrategy(0);
    flags = ReplicationFlags.setFullReplica(flags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_WARONE, 2, flags);
    FileHandle fileHandle =
        volume.openFile(
            userCredentials, fileName, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(), 0777);
    fileHandle.close();

    assertEquals(2, volume.listReplicas(userCredentials, fileName).getReplicasCount());

    String osdUUID = volume.getSuitableOSDs(userCredentials, fileName, 1).get(0);
    Replica replica =
        Replica.newBuilder()
            .addOsdUuids(osdUUID)
            .setStripingPolicy(defaultStripingPolicy)
            .setReplicationFlags(flags)
            .build();
    volume.addReplica(userCredentials, fileName, replica);
    assertEquals(3, volume.listReplicas(userCredentials, fileName).getReplicasCount());

    volume.removeReplica(userCredentials, fileName, replica.getOsdUuids(0));
    assertEquals(2, volume.listReplicas(userCredentials, fileName).getReplicasCount());
  }
예제 #4
0
  @Test
  public void testSetGetListXattr() throws Exception {
    VOLUME_NAME = "testSetGetListXattr";
    final String TESTFILE = "testfile";

    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    FileHandle fh =
        volume.openFile(
            userCredentials, TESTFILE, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
    fh.close();

    int initialNumberOfXattr = volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount();

    // This xattr should not exist
    String xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertNull(xattr);

    // and therefore should have no size
    assertEquals(-1, volume.getXAttrSize(userCredentials, TESTFILE, "foobarasdf"));

    // creating a new Xattr should increase the number of xattrs
    volume.setXAttr(
        userCredentials, TESTFILE, "foobarasdf", "nyancat", XATTR_FLAGS.XATTR_FLAGS_CREATE);

    assertEquals(
        initialNumberOfXattr + 1, volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount());

    xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertEquals("nyancat", xattr);

    // delete the created Xattr
    volume.removeXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertEquals(
        initialNumberOfXattr, volume.listXAttrs(userCredentials, TESTFILE).getXattrsCount());
    xattr = volume.getXAttr(userCredentials, TESTFILE, "foobarasdf");
    assertNull(xattr);

    // same with xtreemfs. attributes.
    try {
      xattr = volume.getXAttr(userCredentials, TESTFILE, "xtreemfs.nyancat");
      fail("nyancat is not a valid system attribute");
    } catch (Exception e) {
    }

    xattr =
        volume.getXAttr(
            userCredentials, TESTFILE, "xtreemfs." + SysAttrs.set_repl_update_policy.toString());
    assertEquals(ReplicaUpdatePolicies.REPL_UPDATE_PC_NONE, xattr);

    // read existing systemflag
    xattr =
        volume.getXAttr(userCredentials, TESTFILE, "xtreemfs." + SysAttrs.object_type.toString());
    assertEquals("1", xattr);
  }
예제 #5
0
  @Test
  public void testVolumeQuota() throws Exception {
    final String VOLUME_NAME = "testVolumeQuota";

    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    volume.setXAttr(userCredentials, "/", "xtreemfs.quota", "8", XATTR_FLAGS.XATTR_FLAGS_CREATE);

    assertEquals("8", volume.getXAttr(userCredentials, "/", "xtreemfs.quota"));

    int flags =
        SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
            | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber();

    byte[] content = "foo foo foo".getBytes(); // 11 bytes will exceed quota

    FileHandle file = volume.openFile(userCredentials, "/test1.txt", flags, 0777);

    boolean osdWriteException = false;
    try {
      file.write(userCredentials, content, content.length, 0);
    } catch (Exception ex) {
      osdWriteException = true;
    }

    if (!osdWriteException) {
      fail("OSD performed write operation although it exceeds the quota.");
    }

    content = "foo bar ".getBytes(); // 8 bytes to fit quota perfectly
    file.write(userCredentials, content, content.length, 0);
    file.close();

    try {
      file = volume.openFile(userCredentials, "/test2.txt", flags, 0777);
      assertTrue(false);
    } catch (PosixErrorException exc) {
      // check if right exception was thrown
      if (!exc.getMessage().contains("POSIX_ERROR_ENOSPC")) {
        assertTrue(false);
      }
    }
  }
예제 #6
0
 @Test(expected = PosixErrorException.class)
 public void testReadLinkWithoutLink() throws Exception {
   VOLUME_NAME = "testReadLinkWithoutLink";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials, fileName, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
   fh.close();
   volume.readLink(userCredentials, fileName);
 }
예제 #7
0
  @Test
  public void testTruncate() throws Exception {
    VOLUME_NAME = "testTruncate";
    String fileName = "testfile";
    String emptyFileName = "emptyFileName";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);
    FileHandle fileHandle =
        volume.openFile(
            userCredentials,
            fileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);

    String data = "1234567890";
    fileHandle.write(userCredentials, data.getBytes(), data.length(), 0);
    fileHandle.flush();

    assertEquals(data.length(), volume.getAttr(userCredentials, fileName).getSize());

    volume.truncate(userCredentials, fileName, 5);
    assertEquals(5, volume.getAttr(userCredentials, fileName).getSize());
    fileHandle.close();

    fileHandle =
        volume.openFile(
            userCredentials,
            emptyFileName,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
            0777);
    assertEquals(0, fileHandle.getAttr(userCredentials).getSize());
    volume.truncate(userCredentials, emptyFileName, 1000);
    assertEquals(1000, fileHandle.getAttr(userCredentials).getSize());
    fileHandle.close();
  }
예제 #8
0
 @Test
 public void testAccessSuccess() throws Exception {
   VOLUME_NAME = "testAccessSuccess";
   String fileName = "testfile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
           0753);
   fh.close();
   volume.access(userCredentials, fileName, 0753);
 }
예제 #9
0
  @Test
  public void testReadDirMultipleChunks() throws Exception {
    options.setReaddirChunkSize(2);

    VOLUME_NAME = "testReadDirMultipleChunks";
    final String TESTFILE = "test";
    final int fileCount = 10;

    // create volume
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // create some files
    for (int i = 0; i < fileCount; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // test 'readDir' across multiple readDir chunks.
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "/", 0, 1000, false);
    assertEquals(2 + fileCount, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    for (int i = 0; i < fileCount; i++) {
      assertEquals(TESTFILE + i, entrySet.getEntries(2 + i).getName());
    }
  }
예제 #10
0
 @Test
 public void testReadLinkWithLink() throws Exception {
   VOLUME_NAME = "testReadLinkWithLink";
   String fileName = "testfile";
   String linkName = "linkToFile";
   client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
   Volume volume = client.openVolume(VOLUME_NAME, null, options);
   FileHandle fh =
       volume.openFile(
           userCredentials,
           fileName,
           SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
               | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
           0777);
   fh.close();
   volume.symlink(userCredentials, fileName, linkName);
   assertEquals(fileName, volume.readLink(userCredentials, linkName));
 }
예제 #11
0
  /**
   * Test if files inherit the group from its parent if the setgid bit is set, and if subdirectories
   * inherit the group and the setgid bit.
   */
  @Test
  public void testSetgid() throws Exception {
    VOLUME_NAME = "testSetgid";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    volume.createDirectory(userCredentials, "/DIR1", 0777);

    Stat stat;
    stat = volume.getAttr(userCredentials, "/DIR1");

    int mode = stat.getMode() | 02000;
    stat = stat.toBuilder().setGroupId("foobar").setMode(mode).build();

    UserCredentials rootCreds =
        userCredentials.toBuilder().setUsername("root").setGroups(0, "root").build();
    volume.setAttr(
        rootCreds,
        "/DIR1",
        stat,
        Setattrs.SETATTR_MODE.getNumber() | Setattrs.SETATTR_GID.getNumber());

    // Test if the setgid bit and the group is set
    stat = volume.getAttr(userCredentials, "/DIR1");
    assertEquals(02000, stat.getMode() & 02000);
    assertEquals("foobar", stat.getGroupId());

    // Test if new subdirectories inherit the setgid bit and the group
    volume.createDirectory(userCredentials, "/DIR1/DIR2", 0777);
    stat = volume.getAttr(userCredentials, "/DIR1/DIR2");
    assertEquals(02000, stat.getMode() & 02000);
    assertEquals("foobar", stat.getGroupId());

    // Test if new files inherit the group
    FileHandle fh =
        volume.openFile(
            userCredentials, "/DIR1/FILE1", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
    fh.close();
    stat = volume.getAttr(userCredentials, "/DIR1/FILE1");
    assertEquals("foobar", stat.getGroupId());

    volume.close();
  }
  /**
   * @param args args[0] = URL to existing volume e.g., pbrpcs://localhost/regular
   * @return
   * @throws Exception
   */
  public static void main(String[] args) {
    if (args.length < 1) {
      System.out.println("usage: <URL to existing volume e.g., pbrpcs://localhost/regular>");
      return;
    }

    Client client = null;
    FileHandle fileHandle = null;
    try {
      // Parse command line parameter.
      int lastSlashIndex = args[0].lastIndexOf('/');
      final ONCRPCServiceURL url =
          new ONCRPCServiceURL(
              args[0].substring(0, lastSlashIndex),
              Schemes.SCHEME_PBRPC,
              PORTS.DIR_PBRPC_PORT_DEFAULT.getNumber());
      final String volumeName = args[0].substring(lastSlashIndex + 1);

      // Init libxtreemfs
      final Options options = new Options();
      final UserCredentials userCredentials =
          UserCredentials.newBuilder()
              .setUsername(System.getProperty("user.name"))
              .addGroups("root")
              .build();
      final SSLOptions sslOptions =
          url.getProtocol().equals(Schemes.SCHEME_PBRPC)
              ? null
              : new SSLOptions(
                  new FileInputStream(CERT_DIR + "Client.p12"),
                  "passphrase",
                  SSLOptions.PKCS12_CONTAINER,
                  new FileInputStream(CERT_DIR + "trusted.jks"),
                  "passphrase",
                  SSLOptions.JKS_CONTAINER,
                  false,
                  false,
                  null);

      // Alternatively, specify own certificate files for debugging:
      // final SSLOptions sslOptions = new SSLOptions(
      // new FileInputStream(
      // "/home/mberlin/ZIB/XtreemFS/tasks archive/2013-08-05 Debug SSL
      // issues/xtfsclient/config/xtfs-vm-certs/TestUser01.p12"),
      // "test123",
      // SSLOptions.PKCS12_CONTAINER,
      // new FileInputStream(
      // "/home/mberlin/ZIB/XtreemFS/tasks archive/2013-08-05 Debug SSL
      // issues/xtfsclient/config/xtfs-vm-certs/trusted.jks"),
      // "J9AUcbrdVkFg75kcqumz", SSLOptions.JKS_CONTAINER, false, false, null);

      Logging.start(Logging.LEVEL_WARN);
      client =
          ClientFactory.createClient(
              url.getHost() + ":" + url.getPort(), userCredentials, sslOptions, options);
      client.start();

      Volume volume = client.openVolume(volumeName, sslOptions, options);

      // Open a file.
      fileHandle =
          volume.openFile(
              userCredentials,
              "/example_libxtreemfs_test_"
                  + String.format("%03d", (int) (Math.random() * 1000))
                  + ".bin",
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber()
                  | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_EXCL.getNumber()
                  | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_RDWR.getNumber(),
              0644);

      // Init chunk to be written.
      byte[] data = new byte[1 << 17]; // 128 kB chunk.
      Arrays.fill(data, (byte) 0xAB);

      // Write 1 MB to file.
      for (int offset = 0; offset < (1 << 20); offset += data.length) {
        fileHandle.write(userCredentials, data, data.length, offset);
      }

      // Read 1 MB from file.
      byte[] readData = new byte[data.length];
      for (int offset = 0; offset < (1 << 20); offset += data.length) {
        int readCount = fileHandle.read(userCredentials, readData, data.length, offset);
        if (readCount != data.length) {
          throw new IOException(
              "Read less data than expected: " + readCount + " bytes instead of: " + data.length);
        }
        if (!Arrays.equals(readData, data)) {
          throw new IOException("Read data differs from written chunk at offset: " + offset);
        }
      }
    } catch (Exception e) {
      System.err.println(
          "An error occurred: " + e.getMessage() + "\n Full Stacktrace:\n" + e.getStackTrace());
      return;
    } finally {
      if (fileHandle != null) {
        try {
          fileHandle.close();
        } catch (IOException e) {
          System.err.println(
              "Failed to close() the file: "
                  + e.getMessage()
                  + "\n Full Stacktrace:\n"
                  + e.getStackTrace());
          return;
        }
      }
      if (client != null) {
        client.shutdown();
      }
      System.out.println("If no errors are shown, the example was successfully executed.");
    }

    return;
  }
예제 #13
0
  @Test
  public void testGetSetAttr() throws Exception {
    VOLUME_NAME = "testGetSetAttr";

    final String TESTFILE = "testfile";
    final String TESTDIR = "testdir";

    final int TESTMODE = 0731;

    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    volume.createDirectory(userCredentials, TESTDIR, TESTMODE);
    FileHandle fh =
        volume.openFile(
            userCredentials,
            TESTDIR + "/" + TESTFILE,
            SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(),
            TESTMODE);
    fh.close();

    Stat stat = volume.getAttr(userCredentials, TESTDIR);
    assertEquals(userCredentials.getUsername(), stat.getUserId());
    assertEquals(userCredentials.getGroups(0), stat.getGroupId());
    assertEquals(0, stat.getSize());
    assertTrue(stat.getAtimeNs() > 0);
    assertTrue(stat.getCtimeNs() > 0);
    assertTrue(stat.getMtimeNs() > 0);
    assertTrue((stat.getMode() & TESTMODE) > 0);
    assertEquals(1, stat.getNlink());

    stat = volume.getAttr(userCredentials, TESTDIR + "/" + TESTFILE);
    assertEquals(userCredentials.getUsername(), stat.getUserId());
    assertEquals(userCredentials.getGroups(0), stat.getGroupId());
    assertEquals(0, stat.getSize());
    assertTrue(stat.getAtimeNs() > 0);
    assertTrue(stat.getCtimeNs() > 0);
    assertTrue(stat.getMtimeNs() > 0);
    assertTrue((stat.getMode() & TESTMODE) == TESTMODE);
    assertEquals(1, stat.getNlink());

    stat = stat.toBuilder().setGroupId("foobar").setUserId("FredFoobar").build();
    try {
      volume.setAttr(
          userCredentials,
          TESTDIR,
          stat,
          Setattrs.SETATTR_UID.getNumber() | Setattrs.SETATTR_GID.getNumber());
      fail("changing username and groups should be restricted to superuser");
    } catch (PosixErrorException e) {
    }

    UserCredentials rootCreds =
        userCredentials.toBuilder().setUsername("root").setGroups(0, "root").build();

    volume.setAttr(
        rootCreds,
        TESTDIR,
        stat,
        Setattrs.SETATTR_UID.getNumber() | Setattrs.SETATTR_GID.getNumber());

    stat = volume.getAttr(userCredentials, TESTDIR);
    assertEquals("FredFoobar", stat.getUserId());
    assertEquals("foobar", stat.getGroupId());
    assertTrue((stat.getMode() & TESTMODE) > 0);

    stat = stat.toBuilder().setMode(0777).build();
    volume.setAttr(
        userCredentials, TESTDIR + "/" + TESTFILE, stat, Setattrs.SETATTR_MODE.getNumber());
    stat = volume.getAttr(userCredentials, TESTDIR + "/" + TESTFILE);
    assertTrue((stat.getMode() & 0777) == 0777);
  }
예제 #14
0
  @Test
  public void testCreateDelete() throws Exception {
    VOLUME_NAME = "testCreateDelete";
    // Both directories should be created under "/"
    final String DIR1 = "/testdir1";
    final String DIR2 = "testdir2";

    final String TESTFILE = "testfile";
    // create volume
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_NULL,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        defaultStripingPolicy.getStripeSize(),
        defaultStripingPolicy.getWidth(),
        new ArrayList<KeyValuePair>());

    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // create some files and directories
    try {
      volume.createDirectory(userCredentials, DIR1, 0755);
      volume.createDirectory(userCredentials, DIR2, 0755);
    } catch (IOException ioe) {
      fail("failed to create testdirs");
    }

    for (int i = 0; i < 10; i++) {
      FileHandle fh =
          volume.openFile(
              userCredentials,
              DIR1 + "/" + TESTFILE + i,
              SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fh.close();
    }

    // // try to create a file w/o a name
    try {
      volume.openFile(userCredentials, "", SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("missing filename");
    } catch (Exception e) {
    }

    // try to create an already existing file
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_EXCL.getNumber()
              | SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file already exists");
    } catch (Exception e) {
    }

    // file in file creation should fail
    try {
      volume.openFile(
          userCredentials,
          DIR1 + "/" + TESTFILE + "1/foo.txt",
          SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber());
      fail("file in file creation");
    } catch (Exception e) {
    }

    // should fail
    try {
      volume.createDirectory(userCredentials, "/", 0);
      fail("directory already exists");
    } catch (PosixErrorException exc) {
    }

    // test 'readDir' and 'stat'
    DirectoryEntries entrySet = null;

    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(4, entrySet.getEntriesCount());
    assertEquals("..", entrySet.getEntries(0).getName());
    assertEquals(".", entrySet.getEntries(1).getName());
    assertEquals(DIR1, "/" + entrySet.getEntries(2).getName());
    assertEquals("/" + DIR2, "/" + entrySet.getEntries(3).getName());

    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(12, entrySet.getEntriesCount());

    // test 'delete'
    volume.unlink(userCredentials, DIR1 + "/" + TESTFILE + "4");
    entrySet = volume.readDir(userCredentials, DIR1, 0, 1000, false);
    assertEquals(11, entrySet.getEntriesCount());

    volume.removeDirectory(userCredentials, DIR2);
    entrySet = volume.readDir(userCredentials, "", 0, 1000, false);
    assertEquals(3, entrySet.getEntriesCount());
  }
예제 #15
0
  @Test
  public void testGetStripeLocationsWithMultipleStripes() throws Exception {
    VOLUME_NAME = "testGetStripeLocatationsWithMultipleStripes";
    client.createVolume(
        mrcAddress,
        auth,
        userCredentials,
        VOLUME_NAME,
        0777,
        userCredentials.getUsername(),
        userCredentials.getGroups(0),
        AccessControlPolicyType.ACCESS_CONTROL_POLICY_POSIX,
        StripingPolicyType.STRIPING_POLICY_RAID0,
        2,
        1,
        new ArrayList<GlobalTypes.KeyValuePair>());
    Volume volume = client.openVolume(VOLUME_NAME, options.generateSSLOptions(), options);

    // set replication update policy of the file
    int replicationFlags = ReplicationFlags.setSequentialStrategy(0);
    replicationFlags = ReplicationFlags.setFullReplica(replicationFlags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY, 2, replicationFlags);

    // create new striping policy with width 2
    StripingPolicy stripingPolicy =
        StripingPolicy.newBuilder()
            .setStripeSize(2)
            .setWidth(2)
            .setType(StripingPolicyType.STRIPING_POLICY_RAID0)
            .build();

    // create file
    final String FILENAME = "/foobar.tzt";
    int flags = SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber();
    FileHandle fileHandle = volume.openFile(userCredentials, FILENAME, flags, 0777);

    // write more than 2kb to the byte to ensure the second stripe is used
    byte[] data = new byte[3000];
    for (int i = 0; i < data.length; i++) {
      data[i] = 'F';
    }
    fileHandle.write(userCredentials, data, data.length, 0);
    fileHandle.close();

    // create replica and add it
    List<String> suitableOsds = volume.getSuitableOSDs(userCredentials, FILENAME, 2);
    Replica replica =
        Replica.newBuilder()
            .setReplicationFlags(replicationFlags)
            .setStripingPolicy(stripingPolicy)
            .addAllOsdUuids(suitableOsds)
            .build();
    volume.addReplica(userCredentials, FILENAME, replica);

    List<StripeLocation> stripeLocations =
        volume.getStripeLocations(userCredentials, FILENAME, 0, 4000);
    assertEquals(2, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);

    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(2048, stripeLocations.get(0).getLength());
    assertEquals(2048, stripeLocations.get(1).getStartSize());
    assertEquals(4000 - 2048, stripeLocations.get(1).getLength());

    assertEquals(stripeLocations.get(0).getUuids()[0], stripeLocations.get(1).getUuids()[0]);
    assertEquals(stripeLocations.get(0).getUuids()[1], stripeLocations.get(1).getUuids()[1]);
    assertNotSame(stripeLocations.get(0).getUuids()[2], stripeLocations.get(1).getUuids()[2]);
  }
예제 #16
0
  @Test
  public void testGetStripeLocations() throws Exception {
    VOLUME_NAME = "testGetStripeLocatations";
    client.createVolume(mrcAddress, auth, userCredentials, VOLUME_NAME);
    Volume volume = client.openVolume(VOLUME_NAME, null, options);

    // set replication update policy of the file
    int flags = ReplicationFlags.setSequentialStrategy(0);
    flags = ReplicationFlags.setFullReplica(flags);
    volume.setDefaultReplicationPolicy(
        userCredentials, "/", ReplicaUpdatePolicies.REPL_UPDATE_PC_RONLY, 2, flags);

    final String FILENAME = "/foobar.tzt";
    FileHandle fileHandle =
        volume.openFile(
            userCredentials, FILENAME, SYSTEM_V_FCNTL.SYSTEM_V_FCNTL_H_O_CREAT.getNumber(), 0777);
    byte[] data = new byte[6];
    for (int i = 0; i < data.length; i++) {
      data[i] = (byte) "FOOBAR".charAt(i);
    }
    fileHandle.write(userCredentials, data, data.length, 0);
    fileHandle.close();
    List<StripeLocation> stripeLocations =
        volume.getStripeLocations(userCredentials, FILENAME, 0, 100);
    assertEquals(1, stripeLocations.size());
    assertEquals(2, stripeLocations.get(0).getUuids().length);
    assertEquals(2, stripeLocations.get(0).getHostnames().length);
    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(100, stripeLocations.get(0).getLength());

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 200, 123);
    assertEquals(1, stripeLocations.size());
    assertEquals(2, stripeLocations.get(0).getUuids().length);
    assertEquals(2, stripeLocations.get(0).getHostnames().length);
    assertEquals(200, stripeLocations.get(0).getStartSize());
    assertEquals(123, stripeLocations.get(0).getLength());

    List<String> suitableOsds = volume.getSuitableOSDs(userCredentials, FILENAME, 1);
    Replica replica =
        Replica.newBuilder()
            .setStripingPolicy(defaultStripingPolicy)
            .setReplicationFlags(flags)
            .addOsdUuids(suitableOsds.get(0))
            .build();
    volume.addReplica(userCredentials, FILENAME, replica);

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 0, 100);
    assertEquals(1, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);
    assertEquals(0, stripeLocations.get(0).getStartSize());
    assertEquals(100, stripeLocations.get(0).getLength());

    stripeLocations = volume.getStripeLocations(userCredentials, FILENAME, 200, 123);
    assertEquals(1, stripeLocations.size());
    assertEquals(3, stripeLocations.get(0).getUuids().length);
    assertEquals(3, stripeLocations.get(0).getHostnames().length);
    assertEquals(200, stripeLocations.get(0).getStartSize());
    assertEquals(123, stripeLocations.get(0).getLength());

    volume.close();
  }