Пример #1
0
  @Test
  public void test() throws ApiSenderException, InterruptedException {
    long requiredSize = SizeUnit.GIGABYTE.toByte(10);
    SimulatorPrimaryStorageDetails sp = new SimulatorPrimaryStorageDetails();
    sp.setTotalCapacity(SizeUnit.TERABYTE.toByte(10));
    sp.setAvailableCapacity(sp.getTotalCapacity());
    sp.setUrl("nfs://simulator/primary/");
    PrimaryStorageInventory pinv = api.createSimulatoPrimaryStorage(1, sp).get(0);
    ZoneInventory zone = api.createZones(1).get(0);
    ClusterInventory cluster = api.createClusters(1, zone.getUuid()).get(0);
    HostInventory host = api.createHost(1, cluster.getUuid()).get(0);
    api.attachPrimaryStorage(cluster.getUuid(), pinv.getUuid());

    AllocatePrimaryStorageMsg msg = new AllocatePrimaryStorageMsg();
    msg.setRequiredHostUuid(host.getUuid());
    msg.setSize(requiredSize);
    msg.setServiceId(bus.makeLocalServiceId(PrimaryStorageConstant.SERVICE_ID));
    MessageReply reply = bus.call(msg);
    Assert.assertEquals(AllocatePrimaryStorageReply.class, reply.getClass());
    AllocatePrimaryStorageReply ar = (AllocatePrimaryStorageReply) reply;
    Assert.assertEquals(pinv.getUuid(), ar.getPrimaryStorageInventory().getUuid());

    ReturnPrimaryStorageCapacityMsg rmsg = new ReturnPrimaryStorageCapacityMsg();
    rmsg.setDiskSize(requiredSize);
    rmsg.setPrimaryStorageUuid(pinv.getUuid());
    rmsg.setServiceId(bus.makeLocalServiceId(PrimaryStorageConstant.SERVICE_ID));
    bus.send(rmsg);
    Thread.sleep(2000);
    PrimaryStorageVO pvo = dbf.findByUuid(pinv.getUuid(), PrimaryStorageVO.class);
    Assert.assertEquals(
        pvo.getCapacity().getTotalCapacity(), pvo.getCapacity().getAvailableCapacity());
  }
Пример #2
0
 @Override
 public void afterDeleteHost(final HostInventory inventory) {
   final String priUuid = getLocalStorageInCluster(inventory.getClusterUuid());
   if (priUuid != null) {
     RemoveHostFromLocalStorageMsg msg = new RemoveHostFromLocalStorageMsg();
     msg.setPrimaryStorageUuid(priUuid);
     msg.setHostUuid(inventory.getUuid());
     bus.makeTargetServiceIdByResourceUuid(msg, PrimaryStorageConstant.SERVICE_ID, priUuid);
     MessageReply reply = bus.call(msg);
     if (!reply.isSuccess()) {
       // TODO
       logger.warn(
           String.format(
               "failed to remove host[uuid:%s] from local primary storage[uuid:%s], %s",
               inventory.getUuid(), priUuid, reply.getError()));
     } else {
       logger.debug(
           String.format(
               "removed host[uuid:%s] from local primary storage[uuid:%s]",
               inventory.getUuid(), priUuid));
     }
   }
 }