Beispiel #1
0
  protected void exceptionIfImageSizeGreaterThanAvailableCapacity(String url) {
    if (CoreGlobalProperty.UNIT_TEST_ON) {
      return;
    }

    url = url.trim();
    if (!url.startsWith("http") && !url.startsWith("https")) {
      return;
    }

    String len;
    try {
      HttpHeaders header = restf.getRESTTemplate().headForHeaders(url);
      len = header.getFirst("Content-Length");
    } catch (Exception e) {
      logger.warn(String.format("cannot get image.  The image url : %s.", url));
      return;
    }
    if (len == null) {
      return;
    }

    long size = Long.valueOf(len);
    if (size > self.getAvailableCapacity()) {
      throw new OperationFailureException(
          errf.stringToOperationError(
              String.format(
                  "the backup storage[uuid:%s, name:%s] has not enough capacity to download the image[%s]."
                      + "Required size:%s, available size:%s",
                  self.getUuid(), self.getName(), url, size, self.getAvailableCapacity())));
    }
  }
Beispiel #2
0
  @Transactional
  private void handle(ReturnBackupStorageMsg msg) {
    self =
        dbf.getEntityManager()
            .find(BackupStorageVO.class, self.getUuid(), LockModeType.PESSIMISTIC_WRITE);
    long availSize = self.getAvailableCapacity() + msg.getSize();
    if (availSize > self.getTotalCapacity()) {
      availSize = self.getTotalCapacity();
    }

    self.setAvailableCapacity(availSize);
    dbf.getEntityManager().merge(self);
    bus.reply(msg, new ReturnBackupStorageReply());
  }