private void applyAll() throws IOException {
   trace("applyAll");
   for (FileOperation op : notAppliedList) {
     op.apply(base);
   }
   notAppliedList.clear();
 }
Example #2
0
  private void givenFileOperationWith(String parent, String source, String target)
      throws CacheException {
    fileOperation = new FileOperation(aReplicaOnlineFileWithNoTags().getPnfsId(), 1, 2L);

    Integer p = parent != null ? poolInfoMap.getPoolIndex(parent) : null;
    Integer s = source != null ? poolInfoMap.getPoolIndex(source) : null;
    Integer t = target != null ? poolInfoMap.getPoolIndex(target) : null;

    fileOperation.setParentOrSource(p, p != null);
    fileOperation.setSource(s);
    fileOperation.setTarget(t);
  }
 /**
  * Check whether the file region of this operation overlaps with another operation.
  *
  * @param other the other operation
  * @return if there is an overlap
  */
 boolean overlaps(FileOperation other) {
   if (isTruncate() && other.isTruncate()) {
     // we just keep the latest truncate operation
     return true;
   }
   if (isTruncate()) {
     return position < other.getEndPosition();
   } else if (other.isTruncate()) {
     return getEndPosition() > other.position;
   }
   return position < other.getEndPosition() && getEndPosition() > other.position;
 }
Example #4
0
  /**
   * create a virtual disk.
   *
   * @param id disk id
   * @param format disk format
   * @param capacity disk capacity
   * @return file object
   * @throws Exception
   */
  public VAFile createDisk(VAFile vafile, long capacity) throws Exception {
    // check disk
    checkDiskType(vafile);

    // create a new disk
    VADisk vadisk = new VADisk(vafile);
    vadisk.setCapacity(capacity);

    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();
    // add the file to the database
    vafile = fileDao.add(vadisk);
    if (vafile == null) {
      throw new Exception("Can't add the file to the database.");
    }

    try {
      // create disk
      FileOperation.getInstance()
          .createDisk(
              VAMConfig.getNfsHost(),
              VAMConfig.getNfsUser(),
              vafile,
              vafile.getSavePath(),
              capacity);
    } catch (Exception e) {
      // remove file in the database
      DaoFactory.getVAFileDao().remove(vafile.getGuid());
      throw new Exception(e);
    }

    return vafile;
  }
  @Override
  public String generate(
      List<String> md5List, String absoluteWorkingDirPath, String absoluteOutputDirPath) {

    final StringBuilder sb = new StringBuilder();

    // check output file
    File outputFile = null;
    outputFile = FileOperation.createWriteFile(absoluteOutputDirPath, getFile());

    if (outputFile == null) {
      throw new RuntimeException("An unexpected error occured. File is null.");
    }

    // check md5
    if (isMd5()) {
      md5List.add(outputFile.getAbsolutePath());
    }

    // generate osmosis call
    sb.append("--rgw").append(" ");
    sb.append("file=").append(outputFile.getAbsolutePath()).append(" ");
    if (this.wayTypes != null) {
      sb.append("way-types").append(this.wayTypes).append(" ");
    }

    return sb.toString();
  }
 /**
  * Run the given operation, passing in a temporary directory that is newly created (implying that
  * it exists and is empty), and delete the directory after the operation has completed.
  *
  * @param operation the operation to be run
  * @throws Exception if the operation throws an Exception or if the directory either cannot be
  *     created or cannot be deleted
  */
 public static void runWithTempDirectory(FileOperation operation) throws Exception {
   File tempDir = createTempDirectory();
   try {
     operation.run(tempDir);
   } finally {
     FileUtilities.delete(tempDir);
   }
 }
Example #7
0
  // 更新
  public void update(float delta) {

    if (Gdx.input.isKeyPressed(Keys.A)) {
      FileOperation.LoadFile("data/test.txt");
      FileOperation.ExportFile("data/aaa.txt");
    }

    // エンターキーでコンティニュー 仮挿入中
    if (Gdx.input.isKeyPressed(Keys.ENTER)) scrollFlag = true; // スプライトを動かすフラグオン

    // クリックされたらゲームステート移行
    if (Gdx.input.isTouched()) {
      // クリック座標によってどにメニューが選択されたか判断
      int x = Gdx.input.getX();
      int y = Gdx.input.getY();

      // コンティニュー
      if (x > 530 && x < 770 && y > 105 && y < 140) {
        scrollFlag = true;
      }
      // ニューゲーム
      if (x > 530 && x < 770 && y > 140 && y < 175) {}

      // ロードゲーム
      if (x > 530 && x < 770 && y > 175 && y < 210) {}

      // ネットワーク
      if (x > 530 && x < 770 && y > 210 && y < 245) {}
      // オプション
      if (x > 530 && x < 770 && y > 245 && y < 280) {}

      // 終了
      if (x > 530 && x < 770 && y > 315 && y < 350) {
        int message =
            JOptionPane.showConfirmDialog(null, "終了しますか?", "Exit", JOptionPane.YES_NO_OPTION);
        if (message == JOptionPane.OK_OPTION) {
          System.exit(0);
        }
      }
    }

    // 選択肢をクリックしたら画像移動
    moveSprite();
  }
 private int addOperation(FileOperation op) throws IOException {
   trace("op " + op);
   checkError();
   notAppliedList.add(op);
   long now = op.getTime();
   for (int i = 0; i < notAppliedList.size() - 1; i++) {
     FileOperation old = notAppliedList.get(i);
     boolean applyOld = false;
     // String reason = "";
     if (old.getTime() + 45000 < now) {
       // reason = "old";
       applyOld = true;
     } else if (old.overlaps(op)) {
       // reason = "overlap";
       applyOld = true;
     } else if (file.getRandom().nextInt(100) < 10) {
       // reason = "random";
       applyOld = true;
     }
     if (applyOld) {
       trace("op apply " + op);
       old.apply(base);
       notAppliedList.remove(i);
       i--;
     }
   }
   return op.apply(readBase);
 }
Example #9
0
  /**
   * convert disk format.
   *
   * @param vafile file object
   * @param srcPath the source disk path
   * @param format disk format
   * @param deleteSrcFile whether delete the source disk after converting
   * @return a new file object
   * @throws Exception
   */
  public VAFile convertDiskFormat(
      VAFile vafile, String srcPath, String format, boolean deleteSrcFile) throws Exception {
    // check disk
    checkDiskType(vafile);

    // check state of the file
    if (vafile.getState() != VAMConstants.STATE_READY) {
      throw new Exception("The file's state is not correct");
    }

    // save old information
    String oldLocation = vafile.getLocation();
    String oldFormat = vafile.getFormat();
    // String oldParent = vafile.getParent();
    int oldState = vafile.getState();

    // set new information
    String newLocation = "file." + VAMUtil.genGuid();
    vafile.setSrcPath(srcPath);
    vafile.setLocation(newLocation);
    vafile.setFormat(format);
    // vafile.setParent(VAMConstants.NULL);
    vafile.setDeletefileAfterOperation(deleteSrcFile);

    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();
    fileDao.update(vafile);

    try {
      // convert disk format
      FileOperation.getInstance()
          .convertDiskFormat(
              VAMConfig.getNfsHost(),
              VAMConfig.getNfsUser(),
              vafile,
              srcPath,
              vafile.getSavePath(),
              format);
    } catch (Exception e) {
      // restore the old information
      vafile.setLocation(oldLocation);
      vafile.setFormat(oldFormat);
      vafile.setState(oldState);
      // vafile.setParent(oldParent);
      DaoFactory.getVAFileDao().update(vafile);
      throw new Exception(e);
    }

    return vafile;
  }
Example #10
0
  /**
   * copy disk.
   *
   * @param srcFile the source disk
   * @return a new disk object
   * @throws Exception
   */
  public VAFile copyDisk(VAFile srcFile) throws Exception {
    // check disk
    checkDiskType(srcFile);

    // if the file has parent file, it can't be copied
    VADisk srcDisk = new VADisk(srcFile);
    if (!srcDisk.getParent().equals(VAMConstants.NULL)) {
      throw new Exception("Can't copy the disk");
    }

    // create new VAFile object
    VAFile vafile =
        createFile(
            srcFile.getId(),
            null,
            VAMConstants.VAF_FILE_TYPE_DISK,
            srcFile.getFormat(),
            srcFile.getSize());

    VADisk vadisk = new VADisk(vafile);
    vadisk.setCapacity(srcDisk.getCapacity());
    vadisk.setParent(srcFile.getGuid());
    vadisk.setReplica(true);

    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();
    // add the file to the database
    vafile = fileDao.add(vadisk);
    if (vafile == null) {
      throw new Exception("Can't add the file to the database.");
    }

    try {
      // copy disk
      FileOperation.getInstance()
          .copyDisk(
              VAMConfig.getNfsHost(),
              VAMConfig.getNfsUser(),
              vafile,
              srcFile.getSavePath(),
              vafile.getSavePath());
    } catch (Exception e) {
      // remove file in the database
      DaoFactory.getVAFileDao().remove(vafile.getGuid());
      throw new Exception(e);
    }

    return vafile;
  }
Example #11
0
  /**
   * create snapshot of a disk.
   *
   * @param srcFile the parent disk file object
   * @param dstFile the snapshot file object
   * @param host the name or IP of host creating snapshot
   * @param user the user name or IP of host creating snapshot
   * @return snapshot file object
   * @throws Exception
   */
  public VAFile createSnapshot(VAFile srcFile, VAFile dstFile, String host, String user)
      throws Exception {
    // check file type
    checkDiskType(srcFile);

    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();

    VADisk instDisk = new VADisk(srcFile);

    // create new disk and set parent
    VADisk vadisk = new VADisk(dstFile);
    vadisk.setCapacity(instDisk.getCapacity());
    vadisk.setParent(srcFile.getGuid());

    // add the file to the database
    dstFile = fileDao.add(vadisk);
    if (dstFile == null) {
      throw new Exception("Can't add the file to the database.");
    }

    try {
      String path = null;
      String backingPath = null;
      if (host == null || user == null) {
        host = VAMConfig.getNfsHost();
        user = VAMConfig.getNfsUser();
      }

      path = dstFile.getSavePath();
      backingPath = srcFile.getSavePath();

      // create snapshot
      FileOperation.getInstance().createSnapshot(dstFile, host, user, path, backingPath);
    } catch (Exception e) {
      // remove file in the database
      fileDao.remove(dstFile.getGuid());
      throw new Exception(e);
    }

    return dstFile;
  }
Example #12
0
  /**
   * remove file by GUID.
   *
   * @param guid file GUID
   * @return whether remove the file successfully
   * @throws Exception
   */
  public boolean removeFile(String host, String user, String guid) throws Exception {
    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();

    // get the VAFile object with the GUID
    VAFile vafile = fileDao.query(guid);

    if (vafile == null) {
      // if the file is already deleted, should not throw exception
      return true;
      // throw new Exception("The file with guid \"" + guid
      //		+ "\" is not existed or available");
    }

    if (vafile.getParent().equals(VAMConstants.NULL)) {
      if (fileDao.getActiveReference(vafile.getGuid()) > 0) {
        throw new Exception("The file is in used");
      }
    } else {
      if (vafile.getRef() > 0) {
        throw new Exception("The file is in used");
      }
    }

    int oldState = vafile.getState();
    try {
      // remove file
      FileOperation.getInstance().removeFile(host, user, vafile, vafile.getSavePath());
    } catch (RuntimeException e) {
      // restore state
      vafile.setState(oldState);
      fileDao.update(vafile);
      throw new Exception(e);
    }

    return true;
  }
Example #13
0
  @Override
  public final boolean isFileOperationSupported(FileOperation op) {
    Class<? extends AbstractFile> thisClass = getClass();
    Method opMethod = op.getCorrespondingMethod(thisClass);
    // If the method corresponding to the file operation has been overridden by this class (a
    // ProxyFile subclass),
    // check the presence of the UnsupportedFileOperation annotation in this class.
    try {
      if (!thisClass
          .getMethod(opMethod.getName(), opMethod.getParameterTypes())
          .getDeclaringClass()
          .equals(ProxyFile.class)) {
        return AbstractFile.isFileOperationSupported(op, thisClass);
      }
    } catch (Exception e) {
      // Should never happen, unless AbstractFile method signatures have changed and FileOperation
      // has not been updated
      LOGGER.warn("Exception caught, this should not have happened", e);
    }

    // Otherwise, check for the presence of the UnsupportedFileOperation annotation in the wrapped
    // AbstractFile.
    return file.isFileOperationSupported(op);
  }
Example #14
0
  /**
   * add file.
   *
   * @param vafile file object
   * @param storeLoc the file location
   * @param deleteSrcFile whether delete the source file after add file
   * @return file object
   * @throws Exception
   */
  public VAFile addFile(VAFile vafile, String storeLoc, boolean deleteSrcFile) throws Exception {
    // check whether the store file is existed
    String storePath = storeLoc;
    if (storePath != null) {
      File storeFile = new File(storePath);
      if (!storeFile.exists()) {
        throw new Exception("The file \"" + storePath + "\" is not existed!");
      }

      vafile.setSize(storeFile.length());
    }

    // check file path
    VAMUtil.checkFile(null, vafile.getLocation());

    // get file data access object
    VAFileDao fileDao = DaoFactory.getVAFileDao();
    // add the file to the database
    vafile = fileDao.add(vafile);
    if (vafile == null) {
      throw new Exception("Can't add the file to the database.");
    }

    try {
      // if the file type is disk, convert disk format
      if (vafile.getFileType().equals(VAMConstants.VAF_FILE_TYPE_DISK)) {
        vafile.setSrcPath(storeLoc);
        DiskInfo info = VAMUtil.getDiskInfo(storeLoc);
        String format = null;
        String backingFile = null;
        if (info != null) {
          format = info.getFormat();
          backingFile = info.getBackingFile();
        }
        if (format != null
            && format.equalsIgnoreCase(VAMConfig.getImageFormat())
            && backingFile == null) {
          VADisk disk = new VADisk(vafile);
          disk.setCapacity(info.getVirtualSize());
          disk.setSize(info.getDiskSize());

          FileOperation.getInstance()
              .moveFile(
                  VAMConfig.getNfsHost(),
                  VAMConfig.getNfsUser(),
                  disk,
                  storeLoc,
                  disk.getSavePath());
        } else {
          convertDiskFormat(vafile, storeLoc, VAMConfig.getImageFormat(), deleteSrcFile);
        }

      } else if (storeLoc != null) { // move file
        FileOperation.getInstance()
            .moveFile(
                VAMConfig.getNfsHost(),
                VAMConfig.getNfsUser(),
                vafile,
                storeLoc,
                vafile.getSavePath());
      }
    } catch (Exception e) {
      // remove the file in the database
      DaoFactory.getVAFileDao().remove(vafile.getGuid());
      throw new Exception(e);
    }

    return vafile;
  }