Exemplo n.º 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());
  }
  @Override
  public void run(final FlowTrigger trigger, final Map data) {
    final VmInstanceSpec spec =
        (VmInstanceSpec) data.get(VmInstanceConstant.Params.VmInstanceSpec.toString());
    VolumeInventory volume = spec.getDestDataVolumes().get(0);

    SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class);
    q.select(LocalStorageResourceRefVO_.hostUuid, LocalStorageResourceRefVO_.primaryStorageUuid);
    q.add(
        LocalStorageResourceRefVO_.resourceUuid, Op.EQ, spec.getVmInventory().getRootVolumeUuid());
    Tuple t = q.findTuple();
    final String hostUuid = t.get(0, String.class);
    String priUuid = t.get(1, String.class);

    AllocatePrimaryStorageMsg msg = new AllocatePrimaryStorageMsg();
    if (isThereOtherStorageForTheHost(hostUuid, priUuid)) {
      // use network-shared primary storage
      msg.addExcludeAllocatorStrategy(LocalStorageConstants.LOCAL_STORAGE_ALLOCATOR_STRATEGY);
      msg.addExcludePrimaryStoratgeUuid(priUuid);
    } else {
      msg.setAllocationStrategy(LocalStorageConstants.LOCAL_STORAGE_ALLOCATOR_STRATEGY);
      msg.setRequiredPrimaryStorageUuid(
          spec.getVmInventory().getRootVolume().getPrimaryStorageUuid());
    }

    msg.setRequiredHostUuid(hostUuid);
    msg.setVmInstanceUuid(spec.getVmInventory().getUuid());
    msg.setSize(volume.getSize());
    msg.setPurpose(PrimaryStorageAllocationPurpose.CreateVolume.toString());
    bus.makeLocalServiceId(msg, PrimaryStorageConstant.SERVICE_ID);
    bus.send(
        msg,
        new CloudBusCallBack(trigger) {
          @Override
          public void run(MessageReply reply) {
            if (!reply.isSuccess()) {
              trigger.fail(reply.getError());
              return;
            }

            spec.setDestHost(HostInventory.valueOf(dbf.findByUuid(hostUuid, HostVO.class)));

            AllocatePrimaryStorageReply ar = (AllocatePrimaryStorageReply) reply;
            data.put(
                VmInstanceConstant.Params.DestPrimaryStorageInventoryForAttachingVolume.toString(),
                ar.getPrimaryStorageInventory());
            data.put(LocalStorageAllocateCapacityForAttachingVolumeFlow.class, ar.getSize());
            trigger.next();
          }
        });
  }
Exemplo n.º 3
0
 @Override
 public String getId() {
   return bus.makeLocalServiceId(ZoneConstant.SERVICE_ID);
 }
 @Override
 public String getId() {
   return bus.makeLocalServiceId(NetworkServiceConstants.SERVICE_ID);
 }