Exemplo n.º 1
0
  /**
   * add disc to the system. Need to set the id, location, srcLocation, format, discType, OS,
   * osVersion, APP list.
   *
   * @param disc need to set the id, location and format
   * @param srcLocation the temporary location of the disc
   * @param discType the disc's type
   * @param os operation system
   * @param appl application list
   * @return file object
   * @throws Exception
   */
  public VAFile addDisc(
      VAFile disc,
      String srcLocation,
      String discType,
      String os,
      String osVersion,
      List<String> appl)
      throws Exception {
    // create new VAFile object
    VAFile vafile =
        createFile(
            disc.getId(), disc.getLocation(), VAMConstants.VAF_FILE_TYPE_DISC, disc.getFormat(), 0);

    VADisk vadisk = new VADisk(vafile);

    vadisk.setDiskType(discType);
    if (discType.equals(VAMConstants.VAD_DISK_TYPE_OS)) {
      vadisk.setOs(os, osVersion);
    } else if (discType.equals(VAMConstants.VAD_DISK_TYPE_APP)) {
      vadisk.setApplications(appl);
    }

    // get upload directory path
    String uploadDir = VAMConfig.getDiscUploadDirLocation();

    return addFile(vadisk, uploadDir + srcLocation, false);
  }
Exemplo n.º 2
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;
  }