@Test
  public void test() throws ApiSenderException, InterruptedException {
    CoreGlobalProperty.VM_TRACER_ON = false;
    IdentityGlobalConfig.SESSION_TIMEOUT.updateValue(TimeUnit.HOURS.toSeconds(1000));
    api.prepare();
    InstanceOfferingInventory ioinv = api.listInstanceOffering(null).get(0);
    ImageInventory iminv = api.listImage(null).get(0);
    List<DiskOfferingInventory> dinvs = api.listDiskOffering(null);
    List<L3NetworkInventory> nwinvs = api.listL3Network(null);
    List<String> nws = new ArrayList<String>(nwinvs.size());
    for (L3NetworkInventory nwinv : nwinvs) {
      nws.add(nwinv.getUuid());
    }

    for (int i = 0; i < vmNum; i++) {
      VmInstanceInventory vm = new VmInstanceInventory();
      vm.setDescription("TestVm");
      vm.setName("TestVm");
      vm.setType(VmInstanceConstant.USER_VM_TYPE);
      vm.setInstanceOfferingUuid(ioinv.getUuid());
      vm.setImageUuid(iminv.getUuid());
      createVm(vm, dinvs.get(0).getUuid(), nws, new ArrayList<String>());
    }
    latch.await(600, TimeUnit.MINUTES);
    long totalTime = 0;
    long minTime = 0;
    long maxTime = 0;
    for (Long t : timeCost) {
      minTime = Math.min(minTime, t);
      maxTime = Math.max(maxTime, t);
      totalTime += t;
    }
    System.out.println(
        String.format(
            "total time: %s, min time: %s, max time: %s, avg  time: %s",
            TimeUnit.MILLISECONDS.toSeconds(totalTime),
            TimeUnit.MILLISECONDS.toSeconds(minTime),
            TimeUnit.MILLISECONDS.toSeconds(maxTime),
            TimeUnit.MILLISECONDS.toSeconds(totalTime / timeCost.size())));

    /*
    SimpleQuery<VmInstanceVO> q = dbf.createQuery(VmInstanceVO.class);
    q.add(VmInstanceVO_.state, Op.EQ, VmInstanceState.Running);
    long count = q.count();
    Assert.assertEquals(vmNum, count);
    */
    TimeUnit.HOURS.sleep(1000);
  }
 @Test
 public void test() throws ApiSenderException {
   ImageInventory iminv = deployer.images.get("TestImage");
   InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("TestInstanceOffering");
   L3NetworkInventory l3inv = deployer.l3Networks.get("TestL3Network2");
   APICreateVmInstanceMsg msg = new APICreateVmInstanceMsg();
   msg.setImageUuid(iminv.getUuid());
   msg.setInstanceOfferingUuid(ioinv.getUuid());
   List<String> l3uuids = new ArrayList<String>();
   l3uuids.add(l3inv.getUuid());
   msg.setL3NetworkUuids(l3uuids);
   msg.setName("TestVm");
   msg.setSession(session);
   msg.setServiceId(ApiMediatorConstant.SERVICE_ID);
   msg.setType(VmInstanceConstant.USER_VM_TYPE);
   ApiSender sender = api.getApiSender();
   sender.send(msg, APICreateVmInstanceEvent.class);
 }
  @Test
  public void test() throws ApiSenderException {
    L3NetworkInventory l3 = deployer.l3Networks.get("l3Network1");
    InstanceOfferingInventory instanceOffering =
        deployer.instanceOfferings.get("instanceOffering512M512HZ");
    ImageInventory imageInventory = deployer.images.get("image1");
    ZoneInventory zone1 = deployer.zones.get("zone1");

    VmCreator creator = new VmCreator();
    creator.addL3Network(l3.getUuid());
    creator.imageUuid = imageInventory.getUuid();
    creator.instanceOfferingUuid = instanceOffering.getUuid();
    creator.zoneUuid = zone1.getUuid();
    VmInstanceInventory vm = creator.create();
    HostCapacityVO cvo = dbf.findByUuid(vm.getHostUuid(), HostCapacityVO.class);
    Assert.assertEquals(instanceOffering.getCpuNum(), cvo.getUsedCpu());
    Assert.assertEquals(instanceOffering.getMemorySize(), cvo.getUsedMemory());
    Assert.assertEquals(zone1.getUuid(), vm.getZoneUuid());
  }
Exemple #4
0
 @AsyncThread
 private void createVm(ImageInventory img, String bsUuid) throws ApiSenderException {
   img = api.addImage(img, bsUuid);
   InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("small");
   L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network1");
   VmCreator creator = new VmCreator(api);
   creator.imageUuid = img.getUuid();
   creator.session = api.getAdminSession();
   creator.instanceOfferingUuid = ioinv.getUuid();
   creator.name = "vm";
   creator.addL3Network(l3.getUuid());
   try {
     synchronized (vms) {
       vms.add(creator.create());
     }
   } finally {
     latch.countDown();
   }
 }