Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.MetaFileSmall


    this.profileManager = profileManager;
  }

  @Override
  protected void doExecute() throws ProcessExecutionException {
    MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();
    byte[] newMD5;
    try {
      newMD5 = EncryptionUtil.generateMD5Hash(context.getFile());
    } catch (IOException e) {
      throw new ProcessExecutionException(
          "The new MD5 hash for the user profile could not be generated.", e);
    }

    try {
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);
      FileIndex index = (FileIndex) userProfile.getFileById(metaFileSmall.getId());

      // store hash of meta file
      index.setMetaFileHash(context.consumeHash());

      // store for backup
View Full Code Here


    }
  }

  @Override
  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();
    if (metaFileSmall != null) {
      try {
        // return to original MD5 and put the userProfile
        UserProfile userProfile = profileManager.getUserProfile(getID(), true);
        FileIndex fileNode = (FileIndex) userProfile.getFileById(metaFileSmall.getId());
        fileNode.setMD5(originalMD5);
        profileManager.readyToPut(userProfile, getID());
      } catch (Exception e) {
        // ignore
      }
View Full Code Here

    }

    logger.debug("Adding a new version to the meta file.");

    // create a new version and add it to the meta file
    MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();
    newVersion = new FileVersion(metaFileSmall.getVersions().size(), FileUtil.getFileSize(context
        .getFile()), System.currentTimeMillis(), context.getMetaChunks());
    metaFileSmall.getVersions().add(newVersion);

    initiateCleanup();
  }
View Full Code Here

    initiateCleanup();
  }

  private void initiateCleanup() {
    MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();

    // remove files when the number of allowed versions is exceeded or when the total file size (sum
    // of all versions) exceeds the allowed file size
    while (metaFileSmall.getVersions().size() > config.getMaxNumOfVersions()
        || metaFileSmall.getTotalSize().compareTo(config.getMaxSizeAllVersions()) == 1) {
      // more versions than allowed or size is larger

      // keep at least one version
      if (metaFileSmall.getVersions().size() == 1)
        break;

      // remove the version of the meta file
      deletedFileVersions.add(metaFileSmall.getVersions().remove(0));
    }

    logger.debug("Need to remove {} old versions.", deletedFileVersions.size());
    List<MetaChunk> chunksToDelete = new ArrayList<MetaChunk>();
    for (FileVersion fileVersion : deletedFileVersions) {
View Full Code Here

  }

  @Override
  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    if (context.consumeMetaFile() != null) {
      MetaFileSmall metaFileSmall = (MetaFileSmall) context.consumeMetaFile();
      // remove the new version
      metaFileSmall.getVersions().remove(newVersion);

      // add the cleaned up versions
      metaFileSmall.getVersions().addAll(deletedFileVersions);
    }
  }
View Full Code Here

    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    FileIndex fileNode = (FileIndex) userProfile.getFileByPath(file, uploaderRoot);
    Assert.assertTrue(H2HEncryptionUtil.compareMD5(file, fileNode.getMD5()));

    // verify that only one version was created
    MetaFileSmall metaDocument = (MetaFileSmall) UseCaseTestUtil.getMetaFile(downloader,
        fileNode.getFileKeys());
    Assert.assertEquals(1, metaDocument.getVersions().size());
  }
View Full Code Here

    UseCaseTestUtil.uploadNewVersion(uploader, file);

    // verify that only one version is online
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    Index fileNode = userProfile.getFileByPath(file, uploaderRoot);
    MetaFileSmall metaFileSmall = (MetaFileSmall) UseCaseTestUtil.getMetaFile(downloader,
        fileNode.getFileKeys());
    Assert.assertEquals(1, metaFileSmall.getVersions().size());
  }
View Full Code Here

    UseCaseTestUtil.uploadNewVersion(uploader, file);

    // verify that only one version is online
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(downloader, userCredentials);
    Index fileNode = userProfile.getFileByPath(file, uploaderRoot);
    MetaFileSmall metaFileSmall = (MetaFileSmall) UseCaseTestUtil.getMetaFile(downloader,
        fileNode.getFileKeys());
    Assert.assertEquals(1, metaFileSmall.getVersions().size());
  }
View Full Code Here

    UseCaseTestUtil.uploadNewFile(client, file);

    // store the keys of the meta file to verify them later
    UserProfile userProfileBeforeDeletion = UseCaseTestUtil.getUserProfile(client, userCredentials);
    KeyPair metaKeyPair = userProfileBeforeDeletion.getFileByPath(file, root).getFileKeys();
    MetaFileSmall metaDocumentBeforeDeletion = (MetaFileSmall) UseCaseTestUtil.getMetaFile(client,
        metaKeyPair);
    Assert.assertNotNull(metaDocumentBeforeDeletion);

    // delete the file
    UseCaseTestUtil.deleteFile(client, file);

    // check if the file is still in the DHT
    UserProfile userProfile = UseCaseTestUtil.getUserProfile(client, userCredentials);
    Assert.assertNull(userProfile.getFileById(metaKeyPair.getPublic()));

    MetaFile metaDocument = UseCaseTestUtil.getMetaFile(client, metaKeyPair, false);
    Assert.assertNull(metaDocument);

    for (FileVersion version : metaDocumentBeforeDeletion.getVersions()) {
      for (MetaChunk metaChunks : version.getMetaChunks()) {
        FutureGet get = client.getDataManager().getUnblocked(
            new Parameters().setLocationKey(metaChunks.getChunkId()).setContentKey(
                H2HConstants.FILE_CHUNK));
        get.awaitUninterruptibly();
View Full Code Here

    // store some things to be able to test later
    UserProfile userProfileBeforeDeletion = UseCaseTestUtil.getUserProfile(client, userCredentials);
    KeyPair metaKeyPairFolder = userProfileBeforeDeletion.getFileByPath(folder, root).getFileKeys();
    KeyPair metaKeyPairFile = userProfileBeforeDeletion.getFileByPath(file, root).getFileKeys();
    MetaFileSmall metaFileBeforeDeletion = (MetaFileSmall) UseCaseTestUtil.getMetaFile(client,
        metaKeyPairFile);
    Assert.assertNotNull(metaFileBeforeDeletion);

    // delete the file
    UseCaseTestUtil.deleteFile(client, file);
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.MetaFileSmall

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.