/**
  * Convert the specified object into a Boolean. Internally the {@code
  * org.apache.commons.lang.BooleanUtils} class from the <a
  * href="http://commons.apache.org/lang/">Commons Lang</a> project is used to perform this
  * conversion. This class accepts some more tokens for the boolean value of <b>true</b>, e.g.
  * {@code yes} and {@code on}. Please refer to the documentation of this class for more details.
  *
  * @param value the value to convert
  * @return the converted value
  * @throws ConversionException thrown if the value cannot be converted to a boolean
  */
 public static Boolean toBoolean(Object value) throws ConversionException {
   if (value instanceof Boolean) {
     return (Boolean) value;
   } else if (value instanceof String) {
     Boolean b = BooleanUtils.toBooleanObject((String) value);
     if (b == null) {
       throw new ConversionException(
           "The value " + value + " can't be converted to a Boolean object");
     }
     return b;
   } else {
     throw new ConversionException(
         "The value " + value + " can't be converted to a Boolean object");
   }
 }
Exemplo n.º 2
0
  static {
    Properties properties = new Properties();
    try {
      properties.load(TestFactory.class.getResourceAsStream("/test.properties"));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    String url = properties.getProperty("url");
    String accessId = properties.getProperty("accessId");
    String accessKey = properties.getProperty("accessKey");
    String ignoreCerts = properties.getProperty("ignoreCerts");

    PccOptions options = new PccOptions();
    options.withIgnoreCerts(BooleanUtils.toBooleanObject(ignoreCerts));

    requester = new Requester(url, accessId, accessKey, options);
    pcc = new Pcc(requester);
  }
Exemplo n.º 3
0
 /**
  * 获取配置文件中的布尔参数值.
  *
  * @param key 参数名称.
  * @return 布尔参数值.
  */
 public static Boolean getBool(String key) {
   return BooleanUtils.toBooleanObject(get(key));
 }
Exemplo n.º 4
0
 /**
  * Gets the value as a Boolean instance.
  *
  * @return the value as a Boolean, never null
  */
 public Object getValue() {
   return BooleanUtils.toBooleanObject(this.value);
 }
Exemplo n.º 5
0
 /**
  * Gets this mutable as an instance of Boolean.
  *
  * @return a Boolean instance containing the value from this mutable, never null
  * @since 2.5
  */
 public Boolean toBoolean() {
   return BooleanUtils.toBooleanObject(this.value);
 }
  public Object getSelectorContext(Map objectModel, Parameters parameters) {
    Request req = ObjectModelHelper.getRequest(objectModel);

    return BooleanUtils.toBooleanObject(req.getParameter(LIGHTBOX_REQUEST) != null);
  }
Exemplo n.º 7
0
  /**
   * Updates the default/template rule options with those in the defaults element
   *
   * @param defaultsElement the ruleDefaults element
   * @param updatedRuleTemplate the Rule Template being updated
   * @return whether this is a delegation rule template
   */
  protected boolean updateRuleDefaults(Element defaultsElement, RuleTemplateBo updatedRuleTemplate)
      throws XmlException {
    // NOTE: implementation detail: in contrast with the other options, the delegate template, and
    // the rule attributes,
    // we unconditionally blow away the default rule and re-create it (we don't update the existing
    // one, if there is one)
    if (updatedRuleTemplate.getId() != null) {
      RuleBaseValues ruleDefaults =
          KEWServiceLocator.getRuleService()
              .findDefaultRuleByRuleTemplateId(updatedRuleTemplate.getId());
      if (ruleDefaults != null) {
        List ruleDelegationDefaults =
            KEWServiceLocator.getRuleDelegationService().findByDelegateRuleId(ruleDefaults.getId());
        // delete the rule
        KEWServiceLocator.getRuleService().delete(ruleDefaults.getId());
        // delete the associated rule delegation defaults
        for (Iterator iterator = ruleDelegationDefaults.iterator(); iterator.hasNext(); ) {
          RuleDelegationBo ruleDelegation = (RuleDelegationBo) iterator.next();
          KEWServiceLocator.getRuleDelegationService().delete(ruleDelegation.getRuleDelegationId());
        }
      }
    }

    boolean isDelegation = false;

    if (defaultsElement != null) {
      String delegationTypeCode =
          defaultsElement.getChildText(DELEGATION_TYPE, RULE_TEMPLATE_NAMESPACE);
      DelegationType delegationType = null;
      isDelegation = !org.apache.commons.lang.StringUtils.isEmpty(delegationTypeCode);

      String description = defaultsElement.getChildText(DESCRIPTION, RULE_TEMPLATE_NAMESPACE);

      // would normally be validated via schema but might not be present if invoking RuleXmlParser
      // directly
      if (description == null) {
        throw new XmlException("Description must be specified in rule defaults");
      }

      String fromDate = defaultsElement.getChildText(FROM_DATE, RULE_TEMPLATE_NAMESPACE);
      String toDate = defaultsElement.getChildText(TO_DATE, RULE_TEMPLATE_NAMESPACE);
      // toBooleanObject ensures that if the value is null (not set) that the Boolean object will
      // likewise be null (will not default to a value)
      Boolean forceAction =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(FORCE_ACTION, RULE_TEMPLATE_NAMESPACE));
      Boolean active =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(ACTIVE, RULE_TEMPLATE_NAMESPACE));

      if (isDelegation) {
        delegationType = DelegationType.parseCode(delegationTypeCode);
        if (delegationType == null) {
          throw new XmlException(
              "Invalid delegation type '"
                  + delegationType
                  + "'."
                  + "  Expected one of: "
                  + DelegationType.PRIMARY.getCode()
                  + ","
                  + DelegationType.SECONDARY.getCode());
        }
      }

      // create our "default rule" which encapsulates the defaults for the rule
      RuleBaseValues ruleDefaults = new RuleBaseValues();

      // set simple values
      ruleDefaults.setRuleTemplate(updatedRuleTemplate);
      ruleDefaults.setRuleTemplateId(updatedRuleTemplate.getId());
      ruleDefaults.setDocTypeName(DUMMY_DOCUMENT_TYPE);
      ruleDefaults.setTemplateRuleInd(Boolean.TRUE);
      ruleDefaults.setCurrentInd(Boolean.TRUE);
      ruleDefaults.setVersionNbr(new Integer(0));
      ruleDefaults.setDescription(description);

      // these are non-nullable fields, so default them if they were not set in the defaults section
      ruleDefaults.setForceAction(Boolean.valueOf(BooleanUtils.isTrue(forceAction)));
      ruleDefaults.setActive(Boolean.valueOf(BooleanUtils.isTrue(active)));

      if (ruleDefaults.getActivationDate() == null) {
        ruleDefaults.setActivationDate(new Timestamp(System.currentTimeMillis()));
      }

      ruleDefaults.setFromDateValue(formatDate("fromDate", fromDate));
      ruleDefaults.setToDateValue(formatDate("toDate", toDate));

      // ok, if this is a "Delegate Template", then we need to set this other RuleDelegation object
      // which contains
      // some delegation-related info
      RuleDelegationBo ruleDelegationDefaults = null;
      if (isDelegation) {
        ruleDelegationDefaults = new RuleDelegationBo();
        ruleDelegationDefaults.setDelegationRule(ruleDefaults);
        ruleDelegationDefaults.setDelegationType(delegationType);
        ruleDelegationDefaults.setResponsibilityId(KewApiConstants.ADHOC_REQUEST_RESPONSIBILITY_ID);
      }

      // explicitly save the new rule delegation defaults and default rule
      KEWServiceLocator.getRuleTemplateService()
          .saveRuleDefaults(ruleDelegationDefaults, ruleDefaults);
    } else {
      // do nothing, rule defaults will be deleted if ruleDefaults element is omitted
    }

    return isDelegation;
  }
Exemplo n.º 8
0
  /**
   * Updates the rule template defaults options with those in the defaults element
   *
   * @param defaultsElement the ruleDefaults element
   * @param updatedRuleTemplate the Rule Template being updated
   */
  protected void updateRuleTemplateOptions(
      Element defaultsElement, RuleTemplateBo updatedRuleTemplate, boolean isDelegation)
      throws XmlException {
    // the possible defaults options
    // NOTE: the current implementation will remove any existing RuleTemplateOption records for any
    // values which are null, i.e. not set in the incoming XML.
    // to pro-actively set default values for omitted options, simply set those values here, and
    // records will be added if not present
    String defaultActionRequested = null;
    Boolean supportsComplete = null;
    Boolean supportsApprove = null;
    Boolean supportsAcknowledge = null;
    Boolean supportsFYI = null;

    // remove any RuleTemplateOptions the template may have but that we know we aren't going to
    // update/reset
    // (not sure if this case even exists...does anything else set rule template options?)
    updatedRuleTemplate.removeNonDefaultOptions();

    // read in new settings
    if (defaultsElement != null) {

      defaultActionRequested =
          defaultsElement.getChildText(DEFAULT_ACTION_REQUESTED, RULE_TEMPLATE_NAMESPACE);
      supportsComplete =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(SUPPORTS_COMPLETE, RULE_TEMPLATE_NAMESPACE));
      supportsApprove =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(SUPPORTS_APPROVE, RULE_TEMPLATE_NAMESPACE));
      supportsAcknowledge =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(SUPPORTS_ACKNOWLEDGE, RULE_TEMPLATE_NAMESPACE));
      supportsFYI =
          BooleanUtils.toBooleanObject(
              defaultsElement.getChildText(SUPPORTS_FYI, RULE_TEMPLATE_NAMESPACE));
    }

    if (!isDelegation) {
      // if this is not a delegation template, store the template options that govern rule action
      // constraints
      // in the RuleTemplateOptions of the template
      // we have two options for this behavior:
      // 1) conditionally parse above, and then unconditionally set/unset the properties; this will
      // have the effect of REMOVING
      //    any of these previously specified rule template options (and is arguably the right thing
      // to do)
      // 2) unconditionally parse above, and then conditionally set/unset the properties; this will
      // have the effect of PRESERVING
      //    the existing rule template options on this template if it is a delegation template
      // (which of course will be overwritten
      //    by this very same code if they subsequently upload without the delegation flag)
      // This is a minor point, but the second implementation is chosen as it preserved the current
      // behavior
      updateOrDeleteRuleTemplateOption(
          updatedRuleTemplate, KewApiConstants.ACTION_REQUEST_DEFAULT_CD, defaultActionRequested);
      updateOrDeleteRuleTemplateOption(
          updatedRuleTemplate, KewApiConstants.ACTION_REQUEST_APPROVE_REQ, supportsApprove);
      updateOrDeleteRuleTemplateOption(
          updatedRuleTemplate, KewApiConstants.ACTION_REQUEST_ACKNOWLEDGE_REQ, supportsAcknowledge);
      updateOrDeleteRuleTemplateOption(
          updatedRuleTemplate, KewApiConstants.ACTION_REQUEST_FYI_REQ, supportsFYI);
      updateOrDeleteRuleTemplateOption(
          updatedRuleTemplate, KewApiConstants.ACTION_REQUEST_COMPLETE_REQ, supportsComplete);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void deleteFarm(Long farmNo) {
    // 引数チェック
    if (farmNo == null) {
      throw new AutoApplicationException("ECOMMON-000003", "farmNo");
    }

    // ファームの存在チェック
    Farm farm = farmDao.read(farmNo);
    if (farm == null) {
      // ファームが存在しない場合
      return;
    }

    // コンポーネントが停止しているかどうかのチェック
    List<Component> components = componentDao.readByFarmNo(farmNo);
    for (Component component : components) {
      // ロードバランサのコンポーネントはチェックしない
      if (BooleanUtils.isTrue(component.getLoadBalancer())) {
        continue;
      }

      List<ComponentInstance> componentInstances =
          componentInstanceDao.readByComponentNo(component.getComponentNo());
      for (ComponentInstance componentInstance : componentInstances) {
        ComponentInstanceStatus status =
            ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
        if (status != ComponentInstanceStatus.STOPPED) {
          // コンポーネントが停止状態でない場合
          throw new AutoApplicationException("ESERVICE-000202", component.getComponentName());
        }
      }
    }

    // インスタンスが停止しているかどうかのチェック
    List<Instance> instances = instanceDao.readByFarmNo(farmNo);
    for (Instance instance : instances) {
      // ロードバランサのインスタンスはチェックしない
      if (BooleanUtils.isTrue(instance.getLoadBalancer())) {
        continue;
      }

      if (InstanceStatus.fromStatus(instance.getStatus()) != InstanceStatus.STOPPED) {
        // インスタンスが停止状態でない場合
        throw new AutoApplicationException("ESERVICE-000203", instance.getInstanceName());
      }
    }

    // ロードバランサが停止しているかどうかのチェック
    List<LoadBalancer> loadBalancers = loadBalancerDao.readByFarmNo(farmNo);
    for (LoadBalancer loadBalancer : loadBalancers) {
      if (LoadBalancerStatus.fromStatus(loadBalancer.getStatus()) != LoadBalancerStatus.STOPPED) {
        // ロードバランサが停止状態でない場合
        throw new AutoApplicationException("ESERVICE-000207", loadBalancer.getLoadBalancerName());
      }
    }

    // ホストグループの削除処理
    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isTrue(useZabbix)) {
      zabbixHostProcess.deleteFarmHostgroup(farmNo);
    }

    // ロードバランサの削除処理
    for (LoadBalancer loadBalancer : loadBalancers) {
      loadBalancerService.deleteLoadBalancer(loadBalancer.getLoadBalancerNo());
    }

    // コンポーネントの削除処理
    for (Component component : components) {
      componentService.deleteComponent(component.getComponentNo());
    }

    // インスタンスの削除処理
    for (Instance instance : instances) {
      instanceService.deleteInstance(instance.getInstanceNo());
    }

    // AWS関連の削除処理
    // AWSボリュームの削除処理
    // TODO: ボリューム自体の削除処理を別で行うようにする
    List<AwsVolume> awsVolumes = awsVolumeDao.readByFarmNo(farmNo);
    for (AwsVolume awsVolume : awsVolumes) {
      if (StringUtils.isEmpty(awsVolume.getVolumeId())) {
        continue;
      }

      IaasGatewayWrapper gateway =
          iaasGatewayFactory.createIaasGateway(farm.getUserNo(), awsVolume.getPlatformNo());
      try {
        // ボリュームの削除
        gateway.deleteVolume(awsVolume.getVolumeId());

        // EC2ではDeleteVolumeに時間がかかるため、Waitしない
        // awsProcessClient.waitDeleteVolume(volumeId);
      } catch (AutoException ignore) {
        // ボリュームが存在しない場合などに備えて例外を握りつぶす
      }
    }
    awsVolumeDao.deleteByFarmNo(farmNo);

    // VMware関連の削除処理
    // VLANの割り当てを解除
    List<VmwareNetwork> vmwareNetworks = vmwareNetworkDao.readByFarmNo(farmNo);
    for (VmwareNetwork vmwareNetwork : vmwareNetworks) {
      // PortGroupを削除
      VmwareProcessClient vmwareProcessClient =
          vmwareProcessClientFactory.createVmwareProcessClient(vmwareNetwork.getPlatformNo());
      try {
        vmwareNetworkProcess.removeNetwork(vmwareProcessClient, vmwareNetwork.getNetworkNo());
      } finally {
        vmwareProcessClient.getVmwareClient().logout();
      }

      // VLAN割り当てを解除
      vmwareNetwork.setFarmNo(null);
      vmwareNetworkDao.update(vmwareNetwork);
    }

    // ユーザ権限の削除
    userAuthDao.deleteByFarmNo(farmNo);

    // ファームの削除処理
    farmDao.deleteByFarmNo(farmNo);

    // イベントログ出力
    eventLogger.log(
        EventLogLevel.INFO,
        farmNo,
        farm.getFarmName(),
        null,
        null,
        null,
        null,
        "FarmDelete",
        null,
        null,
        null);
  }
  /** {@inheritDoc} */
  @Override
  public Long createFarm(Long userNo, String farmName, String comment) {
    // 引数チェック
    if (userNo == null) {
      throw new AutoApplicationException("ECOMMON-000003", "userNo");
    }
    if (farmName == null || farmName.length() == 0) {
      throw new AutoApplicationException("ECOMMON-000003", "farmName");
    }

    // 形式チェック
    if (!Pattern.matches("^[0-9a-z]|[0-9a-z][0-9a-z-]*[0-9a-z]$", farmName)) {
      throw new AutoApplicationException("ECOMMON-000012", "farmName");
    }

    // TODO: 長さチェック

    // ファーム名の一意チェック
    Farm checkFarm = farmDao.readByFarmName(farmName);
    if (checkFarm != null) {
      // 同名のファームが存在する場合
      throw new AutoApplicationException("ESERVICE-000201", farmName);
    }

    // ファームのドメイン名
    // TODO: 設定値の取得方法をうまくする
    String domainName = farmName + "." + Config.getProperty("dns.domain");

    // ファームの作成
    Farm farm = new Farm();
    farm.setFarmName(farmName);
    farm.setUserNo(userNo);
    farm.setComment(comment);
    farm.setDomainName(domainName);
    farm.setScheduled(false);
    farm.setComponentProcessing(false);
    farmDao.create(farm);

    // ファームごとのホストグループ作成
    Boolean useZabbix = BooleanUtils.toBooleanObject(Config.getProperty("zabbix.useZabbix"));
    if (BooleanUtils.isTrue(useZabbix)) {
      zabbixHostProcess.createFarmHostgroup(farm.getFarmNo());
    }

    // VMware関連情報の作成
    List<Platform> platforms = platformDao.readAll();
    for (Platform platform : platforms) {
      if ("vmware".equals(platform.getPlatformType()) == false) {
        continue;
      }

      if (vmwareKeyPairDao.countByUserNoAndPlatformNo(userNo, platform.getPlatformNo()) > 0) {
        // 空いているVLANを取得
        VmwareNetwork publicNetwork = null;
        VmwareNetwork privateNetwork = null;
        List<VmwareNetwork> vmwareNetworks =
            vmwareNetworkDao.readByPlatformNo(platform.getPlatformNo());
        for (VmwareNetwork vmwareNetwork : vmwareNetworks) {
          if (vmwareNetwork.getFarmNo() != null) {
            continue;
          }
          if (BooleanUtils.isTrue(vmwareNetwork.getPublicNetwork())) {
            if (publicNetwork == null) {
              publicNetwork = vmwareNetwork;
            }
          } else {
            if (privateNetwork == null) {
              privateNetwork = vmwareNetwork;
            }
          }
        }

        // VLANを割り当て
        if (publicNetwork != null) {
          publicNetwork.setFarmNo(farm.getFarmNo());
          vmwareNetworkDao.update(publicNetwork);
        }
        if (privateNetwork != null) {
          privateNetwork.setFarmNo(farm.getFarmNo());
          vmwareNetworkDao.update(privateNetwork);
        }
      }
    }

    // イベントログ出力
    eventLogger.log(
        EventLogLevel.INFO,
        farm.getFarmNo(),
        farmName,
        null,
        null,
        null,
        null,
        "FarmCreate",
        null,
        null,
        null);

    return farm.getFarmNo();
  }
 public boolean getBoolean(String key, boolean defaultValue) {
   return getBoolean(key, BooleanUtils.toBooleanObject(defaultValue)).booleanValue();
 }