コード例 #1
0
  @Override
  public void contextInitialized(ServletContextEvent event) {
    try {
      if (!isInit) {
        Platform.createComponentLoaderFromWebApplicationContext(
            WebApplicationContextUtils.getWebApplicationContext(event.getServletContext()));
        node = Platform.getComponentLoader().getComponent(ManagementNodeManager.class);
        bus = Platform.getComponentLoader().getComponent(CloudBus.class);
        node.startNode();
        isInit = true;
      }
    } catch (Throwable t) {
      logger.warn("failed to start management server", t);
      // have to call bus.stop() because its init has been called by spring
      if (bus != null) {
        bus.stop();
      }

      Throwable root = ExceptionDSL.getRootThrowable(t);
      new BootErrorLog().write(root.getMessage());
      if (CoreGlobalProperty.EXIT_JVM_ON_BOOT_FAILURE) {
        System.exit(1);
      } else {
        throw new CloudRuntimeException(t);
      }
    }
  }
コード例 #2
0
ファイル: ZoneManagerImpl.java プロジェクト: zouyapeng/zstack
  private void handle(APICreateZoneMsg msg) {
    String zoneType = msg.getType();
    if (zoneType == null) {
      zoneType = BaseZoneFactory.type.toString();
    }
    ZoneFactory factory = this.getZoneFactory(ZoneType.valueOf(zoneType));
    APICreateZoneEvent evt = new APICreateZoneEvent(msg.getId());
    ZoneVO vo = new ZoneVO();
    if (msg.getResourceUuid() != null) {
      vo.setUuid(msg.getResourceUuid());
    } else {
      vo.setUuid(Platform.getUuid());
    }
    vo.setName(msg.getName());
    vo.setDescription(msg.getDescription());
    vo = factory.createZone(vo, msg);

    tagMgr.createTagsFromAPICreateMessage(msg, vo.getUuid(), ZoneVO.class.getSimpleName());

    evt.setInventory(ZoneInventory.valueOf(vo));
    logger.debug("Created zone: " + vo.getName() + " uuid:" + vo.getUuid());
    if (logf.isEnabled()) {
      logf.info(vo.getUuid(), String.format("Create zone successfully"));
    }
    bus.publish(evt);
  }
  @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());
  }