Beispiel #1
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    final BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    final ImageInventory img = new ImageInventory();
    img.setName("image");
    img.setPlatform(ImagePlatform.Linux.toString());
    img.setMediaType(ImageMediaType.RootVolumeTemplate.toString());
    img.setFormat("qcow2");
    img.setUrl("http://test.img");

    for (int i = 0; i < num; i++) {
      createVm(img, sftp.getUuid());
    }

    latch.await(5, TimeUnit.MINUTES);

    Assert.assertEquals(num, vms.size());

    fconfig.applyDhcpCmdList.clear();
    HostInventory host = deployer.hosts.get("host1");
    api.reconnectHost(host.getUuid());
    Assert.assertFalse(fconfig.applyDhcpCmdList.isEmpty());
    ApplyDhcpCmd cmd = fconfig.applyDhcpCmdList.get(0);
    Assert.assertEquals(num + 1, cmd.dhcp.size());

    List<VmInstanceVO> vms = dbf.listAll(VmInstanceVO.class);
    for (VmInstanceVO vm : vms) {
      checkNic(vm, cmd.dhcp);
    }
  }
  @Test
  public void test() throws ApiSenderException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    api.stopVmInstance(vm.getUuid());
    String rootVolumeUuid = vm.getRootVolumeUuid();
    VolumeVO vol = dbf.findByUuid(rootVolumeUuid, VolumeVO.class);

    BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    ImageInventory image =
        api.createTemplateFromRootVolume("testImage", rootVolumeUuid, (List) null);
    Assert.assertEquals(sftp.getUuid(), image.getBackupStorageRefs().get(0).getBackupStorageUuid());
    Assert.assertEquals(ImageStatus.Ready.toString(), image.getStatus());
    Assert.assertEquals(vol.getSize(), image.getSize());
    Assert.assertEquals(String.format("volume://%s", vol.getUuid()), image.getUrl());

    ImageVO ivo = dbf.findByUuid(image.getUuid(), ImageVO.class);
    Assert.assertNotNull(ivo);
  }
 @Override
 public BackupStorageInventory createBackupStorage(
     BackupStorageVO vo, APIAddBackupStorageMsg msg) {
   APIAddSimulatorBackupStorageMsg smsg = (APIAddSimulatorBackupStorageMsg) msg;
   vo.setTotalCapacity(smsg.getTotalCapacity());
   vo.setAvailableCapacity(smsg.getAvailableCapacity());
   vo = dbf.persistAndRefresh(vo);
   return BackupStorageInventory.valueOf(vo);
 }
Beispiel #4
0
  private void handle(BackupStorageDeletionMsg msg) {
    BackupStorageInventory inv = BackupStorageInventory.valueOf(self);
    extpEmitter.beforeDelete(inv);
    deleteHook();
    extpEmitter.afterDelete(inv);

    BackupStorageDeletionReply reply = new BackupStorageDeletionReply();
    tracker.untrackHook(self.getUuid());
    bus.reply(msg, reply);
  }
  @Test
  public void test() throws ApiSenderException {
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    VolumeInventory dataVol =
        CollectionUtils.find(
            vm.getAllVolumes(),
            new Function<VolumeInventory, VolumeInventory>() {
              @Override
              public VolumeInventory call(VolumeInventory arg) {
                if (arg.getType().equals(VolumeType.Data.toString())) {
                  return arg;
                }
                return null;
              }
            });

    String volUuid = dataVol.getUuid();
    VolumeSnapshotInventory inv1 = api.createSnapshot(volUuid);
    fullSnapshot(inv1, 0);

    VolumeSnapshotInventory inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 1);

    inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 2);

    inv = api.createSnapshot(volUuid);
    deltaSnapshot(inv, 3);

    BackupStorageInventory sftp = deployer.backupStorages.get("sftp");
    api.backupSnapshot(inv.getUuid());

    api.deleteSnapshotFromBackupStorage(inv1.getUuid(), sftp.getUuid());

    BackupStorageVO sftpvo = dbf.findByUuid(sftp.getUuid(), BackupStorageVO.class);
    Assert.assertEquals(sftp.getAvailableCapacity(), sftpvo.getAvailableCapacity());
  }
Beispiel #6
0
  protected void changeStatus(BackupStorageStatus status) {
    if (status == self.getStatus()) {
      return;
    }

    BackupStorageStatus oldStatus = self.getStatus();

    self.setStatus(status);
    dbf.update(self);

    BackupStorageStatusChangedData d = new BackupStorageStatusChangedData();
    d.setBackupStorageUuid(self.getUuid());
    d.setNewStatus(status.toString());
    d.setOldStatus(oldStatus.toString());
    d.setInventory(BackupStorageInventory.valueOf(self));
    evtf.fire(BackupStorageCanonicalEvents.BACKUP_STORAGE_STATUS_CHANGED, d);

    logger.debug(
        String.format("change backup storage[uuid:%s] status to %s", self.getUuid(), status));
  }
Beispiel #7
0
  protected void handle(APIDeleteBackupStorageMsg msg) {
    final APIDeleteBackupStorageEvent evt = new APIDeleteBackupStorageEvent(msg.getId());

    final String issuer = BackupStorageVO.class.getSimpleName();
    final List<BackupStorageInventory> ctx = BackupStorageInventory.valueOf(Arrays.asList(self));
    FlowChain chain = FlowChainBuilder.newSimpleFlowChain();
    chain.setName(String.format("delete-backup-storage-%s", msg.getUuid()));
    if (msg.getDeletionMode() == APIDeleteMessage.DeletionMode.Permissive) {
      chain
          .then(
              new NoRollbackFlow() {
                @Override
                public void run(final FlowTrigger trigger, Map data) {
                  casf.asyncCascade(
                      CascadeConstant.DELETION_CHECK_CODE,
                      issuer,
                      ctx,
                      new Completion(trigger) {
                        @Override
                        public void success() {
                          trigger.next();
                        }

                        @Override
                        public void fail(ErrorCode errorCode) {
                          trigger.fail(errorCode);
                        }
                      });
                }
              })
          .then(
              new NoRollbackFlow() {
                @Override
                public void run(final FlowTrigger trigger, Map data) {
                  casf.asyncCascade(
                      CascadeConstant.DELETION_DELETE_CODE,
                      issuer,
                      ctx,
                      new Completion(trigger) {
                        @Override
                        public void success() {
                          trigger.next();
                        }

                        @Override
                        public void fail(ErrorCode errorCode) {
                          trigger.fail(errorCode);
                        }
                      });
                }
              });
    } else {
      chain.then(
          new NoRollbackFlow() {
            @Override
            public void run(final FlowTrigger trigger, Map data) {
              casf.asyncCascade(
                  CascadeConstant.DELETION_FORCE_DELETE_CODE,
                  issuer,
                  ctx,
                  new Completion(trigger) {
                    @Override
                    public void success() {
                      trigger.next();
                    }

                    @Override
                    public void fail(ErrorCode errorCode) {
                      trigger.fail(errorCode);
                    }
                  });
            }
          });
    }

    chain
        .done(
            new FlowDoneHandler(msg) {
              @Override
              public void handle(Map data) {
                casf.asyncCascadeFull(
                    CascadeConstant.DELETION_CLEANUP_CODE, issuer, ctx, new NopeCompletion());
                bus.publish(evt);
              }
            })
        .error(
            new FlowErrorHandler(msg) {
              @Override
              public void handle(ErrorCode errCode, Map data) {
                evt.setErrorCode(
                    errf.instantiateErrorCode(SysErrors.DELETE_RESOURCE_ERROR, errCode));
                bus.publish(evt);
              }
            })
        .start();
  }
Beispiel #8
0
 protected BackupStorageInventory getSelfInventory() {
   return BackupStorageInventory.valueOf(self);
 }
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("TestInstanceOffering");
    ImageInventory img = deployer.images.get("TestImage");
    L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network1");
    DiskOfferingInventory disk = deployer.diskOfferings.get("disk50G");

    IdentityCreator identityCreator = new IdentityCreator(api);
    AccountInventory test = identityCreator.useAccount("test");

    // some image set in xml,some below,the amount should one more than the quota to get expected
    // exceeding exception.
    api.updateQuota(test.getUuid(), ImageConstant.QUOTA_IMAGE_NUM, 4);

    BackupStorageInventory bsInv = deployer.backupStorages.get("TestImageStoreBackupStorage");

    // add image by http
    ImageInventory iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("http://192.168.200.1/mirror/diskimages/centos6-test.qcow2");
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by local file
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("file://///home/miao/Desktop/zstack2/imageStore1.zip");
    // for getImageSize response
    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(2));
    // for download response
    iConfig.imageSizes.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(1));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by local file
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image1");
    iinv.setDescription("Test Image1");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("file://///home/miao/Desktop/zstack2/imageStore2.zip");
    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.GIGABYTE.toByte(2));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());

    // add image by http to exceed quota:image.num
    iinv = new ImageInventory();
    iinv.setUuid(Platform.getUuid());
    iinv.setName("Test Image2");
    iinv.setDescription("Test Image2");
    iinv.setMediaType(ImageConstant.ImageMediaType.RootVolumeTemplate.toString());
    iinv.setGuestOsType("Window7");
    iinv.setFormat("simulator");
    iinv.setUrl("http://192.168.200.1/mirror/diskimages/exceed.img");

    thrown.expect(ApiSenderException.class);
    thrown.expectMessage("The user exceeds a quota of a resource");
    thrown.expectMessage(ImageConstant.QUOTA_IMAGE_NUM);

    iConfig.getImageSizeCmdSize.put(iinv.getUuid(), SizeUnit.MEGABYTE.toByte(233));
    iinv = api.addImage(iinv, identityCreator.getAccountSession(), bsInv.getUuid());
    //
    List<Quota.QuotaUsage> usages = api.getQuotaUsage(test.getUuid(), null);
    //
    Quota.QuotaUsage imageNum =
        CollectionUtils.find(
            usages,
            new Function<Quota.QuotaUsage, Quota.QuotaUsage>() {
              @Override
              public Quota.QuotaUsage call(Quota.QuotaUsage arg) {
                return ImageConstant.QUOTA_IMAGE_NUM.equals(arg.getName()) ? arg : null;
              }
            });
    Assert.assertNotNull(imageNum);
    QuotaInventory qvm =
        api.getQuota(
            ImageConstant.QUOTA_IMAGE_NUM, test.getUuid(), identityCreator.getAccountSession());
    Assert.assertEquals(qvm.getValue(), imageNum.getTotal().longValue());
    Assert.assertEquals(2, imageNum.getUsed().longValue());
    //
    Quota.QuotaUsage imageSize =
        CollectionUtils.find(
            usages,
            new Function<Quota.QuotaUsage, Quota.QuotaUsage>() {
              @Override
              public Quota.QuotaUsage call(Quota.QuotaUsage arg) {
                return ImageConstant.QUOTA_IMAGE_SIZE.equals(arg.getName()) ? arg : null;
              }
            });
    Assert.assertNotNull(imageSize);
    qvm =
        api.getQuota(
            ImageConstant.QUOTA_IMAGE_SIZE, test.getUuid(), identityCreator.getAccountSession());
    Assert.assertEquals(qvm.getValue(), imageSize.getTotal().longValue());
    Assert.assertTrue(imageSize.getUsed().longValue() <= imageSize.getTotal().longValue());
  }
 @Override
 public BackupStorageInventory reload(String uuid) {
   BackupStorageVO vo = dbf.findByUuid(uuid, BackupStorageVO.class);
   return BackupStorageInventory.valueOf(vo);
 }