コード例 #1
0
ファイル: VolumeBase.java プロジェクト: xujun10110/zstack
  private void syncVolumeVolumeSize(final ReturnValueCompletion<VolumeSize> completion) {
    SyncVolumeSizeOnPrimaryStorageMsg smsg = new SyncVolumeSizeOnPrimaryStorageMsg();
    smsg.setPrimaryStorageUuid(self.getPrimaryStorageUuid());
    smsg.setVolumeUuid(self.getUuid());
    smsg.setInstallPath(self.getInstallPath());
    bus.makeTargetServiceIdByResourceUuid(
        smsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
    bus.send(
        smsg,
        new CloudBusCallBack(completion) {
          @Override
          public void run(MessageReply reply) {
            if (!reply.isSuccess()) {
              completion.fail(reply.getError());
              return;
            }

            SyncVolumeSizeOnPrimaryStorageReply r = reply.castReply();
            self.setActualSize(r.getActualSize());
            self.setSize(r.getSize());
            self = dbf.updateAndRefresh(self);

            VolumeSize size = new VolumeSize();
            size.actualSize = r.getActualSize();
            size.size = r.getSize();
            completion.success(size);
          }
        });
  }
コード例 #2
0
ファイル: VolumeBase.java プロジェクト: xujun10110/zstack
  private void handle(final CreateDataVolumeTemplateFromDataVolumeMsg msg) {
    final CreateTemplateFromVolumeOnPrimaryStorageMsg cmsg =
        new CreateTemplateFromVolumeOnPrimaryStorageMsg();
    cmsg.setBackupStorageUuid(msg.getBackupStorageUuid());
    cmsg.setImageInventory(
        ImageInventory.valueOf(dbf.findByUuid(msg.getImageUuid(), ImageVO.class)));
    cmsg.setVolumeInventory(getSelfInventory());
    bus.makeTargetServiceIdByResourceUuid(
        cmsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
    bus.send(
        cmsg,
        new CloudBusCallBack(msg) {
          @Override
          public void run(MessageReply r) {
            CreateDataVolumeTemplateFromDataVolumeReply reply =
                new CreateDataVolumeTemplateFromDataVolumeReply();
            if (!r.isSuccess()) {
              reply.setError(r.getError());
            } else {
              CreateTemplateFromVolumeOnPrimaryStorageReply creply = r.castReply();
              String backupStorageInstallPath = creply.getTemplateBackupStorageInstallPath();
              reply.setFormat(creply.getFormat());
              reply.setInstallPath(backupStorageInstallPath);
              reply.setMd5sum(null);
              reply.setBackupStorageUuid(msg.getBackupStorageUuid());
            }

            bus.reply(msg, reply);
          }
        });
  }
コード例 #3
0
 private void fullSnapshot(VolumeSnapshotInventory inv, int distance) {
   Assert.assertEquals(VolumeSnapshotState.Enabled.toString(), inv.getState());
   Assert.assertEquals(VolumeSnapshotStatus.Ready.toString(), inv.getStatus());
   VolumeVO vol = dbf.findByUuid(inv.getVolumeUuid(), VolumeVO.class);
   VolumeSnapshotVO svo = dbf.findByUuid(inv.getUuid(), VolumeSnapshotVO.class);
   Assert.assertNotNull(svo);
   Assert.assertTrue(svo.isFullSnapshot());
   Assert.assertTrue(svo.isLatest());
   Assert.assertNull(svo.getParentUuid());
   Assert.assertEquals(distance, svo.getDistance());
   Assert.assertEquals(vol.getPrimaryStorageUuid(), svo.getPrimaryStorageUuid());
   Assert.assertNotNull(svo.getPrimaryStorageInstallPath());
   VolumeSnapshotTreeVO cvo = dbf.findByUuid(svo.getTreeUuid(), VolumeSnapshotTreeVO.class);
   Assert.assertNotNull(cvo);
   Assert.assertTrue(cvo.isCurrent());
 }
コード例 #4
0
ファイル: VolumeBase.java プロジェクト: xujun10110/zstack
  private void expunge(final Completion completion) {
    if (self.getStatus() != VolumeStatus.Deleted) {
      throw new OperationFailureException(
          errf.stringToOperationError(
              String.format(
                  "the volume[uuid:%s, name:%s] is not deleted yet, can't expunge it",
                  self.getUuid(), self.getName())));
    }

    final VolumeInventory inv = getSelfInventory();
    CollectionUtils.safeForEach(
        pluginRgty.getExtensionList(VolumeBeforeExpungeExtensionPoint.class),
        new ForEachFunction<VolumeBeforeExpungeExtensionPoint>() {
          @Override
          public void run(VolumeBeforeExpungeExtensionPoint arg) {
            arg.volumeBeforeExpunge(inv);
          }
        });

    if (self.getPrimaryStorageUuid() != null) {
      DeleteVolumeOnPrimaryStorageMsg dmsg = new DeleteVolumeOnPrimaryStorageMsg();
      dmsg.setVolume(getSelfInventory());
      dmsg.setUuid(self.getPrimaryStorageUuid());
      bus.makeTargetServiceIdByResourceUuid(
          dmsg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
      bus.send(
          dmsg,
          new CloudBusCallBack(completion) {
            @Override
            public void run(MessageReply r) {
              if (!r.isSuccess()) {
                completion.fail(r.getError());
              } else {
                ReturnPrimaryStorageCapacityMsg msg = new ReturnPrimaryStorageCapacityMsg();
                msg.setPrimaryStorageUuid(self.getPrimaryStorageUuid());
                msg.setDiskSize(self.getSize());
                bus.makeTargetServiceIdByResourceUuid(
                    msg, PrimaryStorageConstant.SERVICE_ID, self.getPrimaryStorageUuid());
                bus.send(msg);

                CollectionUtils.safeForEach(
                    pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class),
                    new ForEachFunction<VolumeAfterExpungeExtensionPoint>() {
                      @Override
                      public void run(VolumeAfterExpungeExtensionPoint arg) {
                        arg.volumeAfterExpunge(inv);
                      }
                    });

                dbf.remove(self);
                completion.success();
              }
            }
          });
    } else {
      CollectionUtils.safeForEach(
          pluginRgty.getExtensionList(VolumeAfterExpungeExtensionPoint.class),
          new ForEachFunction<VolumeAfterExpungeExtensionPoint>() {
            @Override
            public void run(VolumeAfterExpungeExtensionPoint arg) {
              arg.volumeAfterExpunge(inv);
            }
          });

      dbf.remove(self);
      completion.success();
    }
  }
コード例 #5
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    HostInventory host2 = deployer.hosts.get("host2");
    HostInventory host1 = deployer.hosts.get("host1");
    VmInstanceInventory vm = deployer.vms.get("TestVm");
    PrimaryStorageInventory local = deployer.primaryStorages.get("local");

    List<VolumeVO> vols = dbf.listAll(VolumeVO.class);
    List<VolumeVO> volumesOnLocal = new ArrayList<VolumeVO>();

    ImageCacheVO cacheVO = dbf.listAll(ImageCacheVO.class).get(0);
    long imageSize = cacheVO.getSize();
    long usedVolumeSize = 0;
    for (VolumeVO vol : vols) {
      if (vol.getPrimaryStorageUuid().equals(local.getUuid())) {
        volumesOnLocal.add(vol);
        usedVolumeSize += ratioMgr.calculateByRatio(vol.getPrimaryStorageUuid(), vol.getSize());
      }
    }

    config.createEmptyVolumeCmds.clear();
    config.deleteBitsCmds.clear();
    vm = api.migrateVmInstance(vm.getUuid(), host2.getUuid());
    TimeUnit.SECONDS.sleep(5);
    LocalStorageHostRefVO ref1 = dbf.findByUuid(host1.getUuid(), LocalStorageHostRefVO.class);
    Assert.assertEquals(ref1.getTotalCapacity() - imageSize, ref1.getAvailableCapacity());
    LocalStorageHostRefVO ref2 = dbf.findByUuid(host2.getUuid(), LocalStorageHostRefVO.class);
    Assert.assertEquals(
        ref2.getTotalCapacity() - imageSize - usedVolumeSize, ref2.getAvailableCapacity());

    Assert.assertEquals(volumesOnLocal.size(), config.createEmptyVolumeCmds.size());
    for (final VolumeVO vol : volumesOnLocal) {
      // volumes are created on dst host
      CreateEmptyVolumeCmd cmd =
          CollectionUtils.find(
              config.createEmptyVolumeCmds,
              new Function<CreateEmptyVolumeCmd, CreateEmptyVolumeCmd>() {
                @Override
                public CreateEmptyVolumeCmd call(CreateEmptyVolumeCmd arg) {
                  return arg.getVolumeUuid().equals(vol.getUuid()) ? arg : null;
                }
              });
      Assert.assertNotNull(cmd);
      Assert.assertEquals(vol.getInstallPath(), cmd.getInstallUrl());

      LocalStorageResourceRefVO r = dbf.findByUuid(vol.getUuid(), LocalStorageResourceRefVO.class);
      Assert.assertEquals(host2.getUuid(), r.getHostUuid());

      // volumes are deleted on src host
      DeleteBitsCmd dcmd =
          CollectionUtils.find(
              config.deleteBitsCmds,
              new Function<DeleteBitsCmd, DeleteBitsCmd>() {
                @Override
                public DeleteBitsCmd call(DeleteBitsCmd arg) {
                  return arg.getPath().equals(vol.getInstallPath()) ? arg : null;
                }
              });
      Assert.assertNotNull(
          String.format(
              "no delete command for volume[uuid:%s, path:%s]",
              vol.getUuid(), vol.getInstallPath()),
          dcmd);
    }

    Assert.assertFalse(kconfig.migrateVmCmds.isEmpty());
    MigrateVmCmd mcmd = kconfig.migrateVmCmds.get(0);
    Assert.assertEquals(host2.getManagementIp(), mcmd.getDestHostIp());
    Assert.assertEquals(vm.getUuid(), mcmd.getVmUuid());
    Assert.assertEquals(
        StorageMigrationPolicy.IncCopy.toString(), mcmd.getStorageMigrationPolicy());
  }