Java Code Examples for org.apache.commons.lang.BooleanUtils#isFalse()

The following examples show how to use org.apache.commons.lang.BooleanUtils#isFalse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListLoadBalancer.java    From primecloud-controller with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ロードバランサ情報一覧取得
 *
 * @param farmNo ファーム番号
 * @return ListLoadBalancerResponse
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public ListLoadBalancerResponse listLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo) {

    // 入力チェック
    // LoadBalancerNo
    ApiValidate.validateFarmNo(farmNo);

    // 権限チェック
    Farm farm = farmDao.read(Long.parseLong(farmNo));
    checkAndGetUser(farm);

    ListLoadBalancerResponse response = new ListLoadBalancerResponse();

    // ロードバランサ取得
    List<LoadBalancer> loadBalancers = loadBalancerDao.readByFarmNo(Long.parseLong(farmNo));
    if (BooleanUtils.isFalse(loadBalancers.isEmpty())) {
        //ソート
        Collections.sort(loadBalancers, Comparators.COMPARATOR_LOAD_BALANCER);
    }

    for (LoadBalancer loadBalancer : loadBalancers) {
        //ロードバランサ情報設定
        LoadBalancerResponse loadBalancerResponse = new LoadBalancerResponse(loadBalancer);

        // コンポーネント取得
        Component component = componentDao.read(loadBalancer.getComponentNo());
        if (component != null) {
            //コンポーネント名設定
            loadBalancerResponse.setComponentName(component.getComponentName());
        }
        response.getLoadBalancers().add(loadBalancerResponse);
    }

    return response;
}
 
Example 2
Source File: AbstractInputConfigHandler.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
protected void loadFilters(String serviceName, InputConfigHolder inputConfigHolder) {
  sortFilters(inputConfigHolder);

  List<Input> toRemoveInputList = new ArrayList<>();
  for (Input input : inputConfigHolder.getInputManager().getInputList(serviceName)) {
    for (FilterDescriptor filterDescriptor : inputConfigHolder.getFilterConfigList()) {
      if (filterDescriptor == null) {
        logger.warn("Filter descriptor is empty. Skipping...");
        continue;
      }
      if (BooleanUtils.isFalse(filterDescriptor.isEnabled())) {
        logger.debug("Ignoring filter " + filterDescriptor.getFilter() + " because it is disabled");
        continue;
      }
      if (!input.isFilterRequired(filterDescriptor)) {
        logger.debug("Ignoring filter " + filterDescriptor.getFilter() + " for input " + input.getShortDescription());
        continue;
      }

      String value = filterDescriptor.getFilter();
      if (StringUtils.isEmpty(value)) {
        logger.error("Filter block doesn't have filter element");
        continue;
      }
      Filter filter = (Filter) AliasUtil.getClassInstance(value, AliasUtil.AliasType.FILTER);
      if (filter == null) {
        logger.error("Filter object could not be found");
        continue;
      }
      filter.loadConfig(filterDescriptor);
      filter.setInput(input);

      filter.setOutputManager(inputConfigHolder.getOutputManager());
      input.addFilter(filter);
      filter.logConfigs();
    }

    if (input.getFirstFilter() == null) {
      toRemoveInputList.add(input);
    }
  }

  for (Input toRemoveInput : toRemoveInputList) {
    logger.warn("There are no filters, we will ignore this input. " + toRemoveInput.getShortDescription());
    inputConfigHolder.getInputManager().removeInput(toRemoveInput);
  }
}
 
Example 3
Source File: ConfigMain.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
public static void getPlatformNo(String platformName, String platformKind) {
    try {
        String platformSql = "SELECT * FROM PLATFORM";
        List<Platform> platforms = SQLMain.selectExecuteWithResult(platformSql, Platform.class);
        if (platforms == null || platforms.isEmpty()) {
            System.out.println("NULL");
            return;
        }
        for (Platform platform : platforms) {
            if (StringUtils.equals(platform.getPlatformName(), platformName)) {
                if (BooleanUtils.isNotTrue(platform.getSelectable())) {
                    //使用不可なプラットフォーム
                    System.out.println("DISABLE");
                    return;
                }

                String platformAwsSql = "SELECT * FROM PLATFORM_AWS WHERE PLATFORM_NO=" + platform.getPlatformNo();
                List<PlatformAws> platformAwses = SQLMain.selectExecuteWithResult(platformAwsSql, PlatformAws.class);
                if ("ec2".equals(platformKind) && "aws".equals(platform.getPlatformType()) &&
                    BooleanUtils.isFalse(platformAwses.get(0).getEuca())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("vmware".equals(platformKind) && "vmware".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("eucalyptus".equals(platformKind) && "aws".equals(platform.getPlatformType()) &&
                           BooleanUtils.isTrue(platformAwses.get(0).getEuca())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("nifty".equals(platformKind) && "nifty".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("cloudstack".equals(platformKind) && "cloudstack".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("vcloud".equals(platformKind) && "vcloud".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("azure".equals(platformKind) && "azure".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                } else if ("openstack".equals(platformKind) && "openstack".equals(platform.getPlatformType())) {
                    System.out.println(platform.getPlatformNo().toString());
                    return;
                }
            }
        }
        System.out.println("OTHER");
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e.getMessage(), e);
    }
}
 
Example 4
Source File: DetachLoadBalancer.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ロードバランサ サーバ割り当て無効化
 * 
 * @param loadBalancerNo ロードバランサ番号
 * @param instanceNo インスタンス番号
 * @return DetachLoadBalancerResponse
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public DetachLoadBalancerResponse detachLoadBalancer(@QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    // 入力チェック
    // LoadBalancerNo
    ApiValidate.validateLoadBalancerNo(loadBalancerNo);
    // InstanceNo
    ApiValidate.validateInstanceNo(instanceNo);

    // ロードバランサ取得
    LoadBalancer loadBalancer = getLoadBalancer(Long.parseLong(loadBalancerNo));

    // 権限チェック
    checkAndGetUser(loadBalancer);

    // インスタンス取得
    Instance instance = getInstance(Long.parseLong(instanceNo));

    if (BooleanUtils.isFalse(instance.getFarmNo().equals(loadBalancer.getFarmNo()))) {
        //ファームとインスタンスが一致しない
        throw new AutoApplicationException("EAPI-100022", "Instance", loadBalancer.getFarmNo(),
                PARAM_NAME_INSTANCE_NO, instanceNo);
    }

    // サーバのステータスチェック
    InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
    if (instanceStatus == InstanceStatus.CONFIGURING) {
        // ステータスが Configuring の場合は割り当て解除不可
        throw new AutoApplicationException("EAPI-100002", loadBalancerNo, instanceNo);
    }

    // ロードバランサ サーバ割り当て無効化設定処理
    List<Long> instanceNos = new ArrayList<Long>();
    instanceNos.add(Long.parseLong(instanceNo));
    loadBalancerService.disableInstances(Long.parseLong(loadBalancerNo), instanceNos);

    DetachLoadBalancerResponse response = new DetachLoadBalancerResponse();

    return response;
}
 
Example 5
Source File: CreateLoadBalancer.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ロードバランサリスナ作成
 *
 * @param farmNo ファーム番号
 * @param loadBalancerName ロードバランサ番号
 * @param platformNo プラットフォーム番号
 * @param loadBalancerType ロードバランサー種別(aws or ultramonkey)
 * @param componentNo コンポーネント番号
 * @param comment コメント
 * @return CreateLoadBalancerResponse
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public CreateLoadBalancerResponse createLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NAME) String loadBalancerName,
        @QueryParam(PARAM_NAME_PLATFORM_NO) String platformNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_TYPE) String loadBalancerType,
        @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo, @QueryParam(PARAM_NAME_COMMENT) String comment,
        @QueryParam(PARAM_NAME_IS_INTERNAL) String isInternal) {

    // 入力チェック
    // FarmNo
    ApiValidate.validateFarmNo(farmNo);

    // ファーム取得
    Farm farm = farmDao.read(Long.parseLong(farmNo));

    // 権限チェック
    User user = checkAndGetUser(farm);

    // LoadBalancerName
    ApiValidate.validateLoadBalancerName(loadBalancerName);
    // PlatformNo
    ApiValidate.validatePlatformNo(platformNo);
    Platform platform = platformDao.read(Long.parseLong(platformNo));
    if (platform == null) {
        //プラットフォームが存在しない
        throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO, platformNo);
    }
    if (!platformService.isUsablePlatform(user.getUserNo(), platform)
            || BooleanUtils.isNotTrue(platform.getSelectable())) {
        //認証情報が存在しない or 有効ではないプラットフォーム
        throw new AutoApplicationException("EAPI-000020", "Platform", PARAM_NAME_PLATFORM_NO, platformNo);
    }

    // LoadBalancerType
    ApiValidate.validateLoadBalancerType(loadBalancerType);
    PlatformAws platformAws = platformAwsDao.read(Long.parseLong(platformNo));
    if (LB_TYPE_ELB.equals(loadBalancerType)
            && (PLATFORM_TYPE_AWS.equals(platform.getPlatformType()) == false || platformAws.getEuca())) {
        //loadBalancerType=ELB、プラットフォーム=EC2以外の場合→エラー
        //EC2プラットフォームのみ ELB(Elastic Load Balancing)が使用可能
        throw new AutoApplicationException("EAPI-000015", platform.getPlatformNo(), loadBalancerType);
    }
    // ComponentNo
    ApiValidate.validateComponentNo(componentNo);
    // Comment
    ApiValidate.validateComment(comment);
    // isInternal
    boolean internal = false;
    if (isInternal != null) {
        ApiValidate.validateIsInternal(isInternal);
        internal = Boolean.parseBoolean(isInternal);
    }
    if (!LB_TYPE_ELB.equals(loadBalancerType) || !platformAws.getVpc()) {
        if (BooleanUtils.isTrue(internal)) {
            // ELB かつプラットフォームがVPC以外の場合は内部ロードバランサ指定不可
            throw new AutoApplicationException("EAPI -100041", loadBalancerName);
        }
    }

    // コンポーネント取得
    Component component = getComponent(Long.parseLong(componentNo));

    if (BooleanUtils.isFalse(component.getFarmNo().equals(farm.getFarmNo()))) {
        //ファームとコンポーネントが一致しない
        throw new AutoApplicationException("EAPI-100022", "Component", farm.getFarmNo(), PARAM_NAME_COMPONENT_NO,
                componentNo);
    }

    // ロードバランサー作成
    Long loadBalancerNo = null;
    if (LB_TYPE_ELB.equals(loadBalancerType)) {
        //AWS ELB(Elastic Load Balancing)
        loadBalancerNo = loadBalancerService.createAwsLoadBalancer(Long.parseLong(farmNo), loadBalancerName,
                comment, Long.parseLong(platformNo), Long.parseLong(componentNo), internal);
    } else if (LB_TYPE_ULTRA_MONKEY.equals(loadBalancerType)) {
        //ultraMonkey
        loadBalancerNo = loadBalancerService.createUltraMonkeyLoadBalancer(Long.parseLong(farmNo), loadBalancerName,
                comment, Long.parseLong(platformNo), Long.parseLong(componentNo));

    } else if (LB_TYPE_CLOUDSTACK.equals(loadBalancerType)) {
        //cloudstack
        loadBalancerNo = loadBalancerService.createCloudstackLoadBalancer(Long.parseLong(farmNo), loadBalancerName,
                comment, Long.parseLong(platformNo), Long.parseLong(componentNo));
    }

    CreateLoadBalancerResponse response = new CreateLoadBalancerResponse(loadBalancerNo);

    return response;
}
 
Example 6
Source File: AttachLoadBalancer.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ロードバランサ サーバ割り当て有効化
 * 
 * @param loadBalancerNo ロードバランサ番号
 * @param instanceNo インスタンス番号
 * @return AttachLoadBalancerResponse
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public AttachLoadBalancerResponse attachLoadBalancer(@QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    // 入力チェック
    // LoadBalancerNo
    ApiValidate.validateLoadBalancerNo(loadBalancerNo);
    // InstanceNo
    ApiValidate.validateInstanceNo(instanceNo);

    // ロードバランサ取得
    LoadBalancer loadBalancer = getLoadBalancer(Long.parseLong(loadBalancerNo));

    // 権限チェック
    checkAndGetUser(loadBalancer);

    // インスタンス取得
    Instance instance = getInstance(Long.parseLong(instanceNo));

    if (BooleanUtils.isFalse(instance.getFarmNo().equals(loadBalancer.getFarmNo()))) {
        //ファームとインスタンスが一致しない
        throw new AutoApplicationException("EAPI-100022", "Instance", loadBalancer.getFarmNo(),
                PARAM_NAME_INSTANCE_NO, instanceNo);
    }

    // サーバのステータスチェック
    InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
    if (instanceStatus == InstanceStatus.CONFIGURING || instanceStatus == InstanceStatus.WARNING) {
        // ステータスが Configuring 及び Warning の場合は割り当て不可
        throw new AutoApplicationException("EAPI-100001", loadBalancerNo, instanceNo);
    }

    // コンポーネントのチェック
    List<ComponentInstance> componentInstances = componentInstanceDao
            .readByComponentNo(loadBalancer.getComponentNo());
    boolean isContain = false;
    for (ComponentInstance componentInstance : componentInstances) {
        if (BooleanUtils.isFalse(componentInstance.getAssociate())) {
            continue;
        }
        if (componentInstance.getInstanceNo().equals(instance.getInstanceNo())) {
            isContain = true;
            break;
        }
    }
    if (BooleanUtils.isFalse(isContain)) {
        // インスタンスがコンポーネントに含まれていない場合
        throw new AutoApplicationException("EAPI-100012", Long.parseLong(loadBalancerNo),
                loadBalancer.getComponentNo(), Long.parseLong(instanceNo));
    }

    // ロードバランサ サーバ割り当て有効化設定処理
    List<Long> instanceNos = new ArrayList<Long>();
    instanceNos.add(Long.parseLong(instanceNo));
    loadBalancerService.enableInstances(Long.parseLong(loadBalancerNo), instanceNos);

    AttachLoadBalancerResponse response = new AttachLoadBalancerResponse();

    return response;
}
 
Example 7
Source File: DetachComponent.java    From primecloud-controller with GNU General Public License v2.0 4 votes vote down vote up
/**
 * サービスとインスタンスの紐づけの解除
 *
 * @param componentNo コンポーネント番号
 * @param instanceNo インスタンス番号
 * @return DetachComponentResponse
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
public DetachComponentResponse detachComponent(@QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    // 入力チェック
    // ComponentNo
    ApiValidate.validateComponentNo(componentNo);
    // InstanceNo
    ApiValidate.validateInstanceNo(instanceNo);

    // コンポーネント取得
    Component component = getComponent(Long.parseLong(componentNo));

    // 権限チェック
    checkAndGetUser(component);

    // インスタンス取得
    Instance instance = getInstance(Long.parseLong(instanceNo));

    if (BooleanUtils.isFalse(instance.getFarmNo().equals(component.getFarmNo()))) {
        //ファームとインスタンスが一致しない
        throw new AutoApplicationException("EAPI-100022", "Instance", component.getFarmNo(), PARAM_NAME_INSTANCE_NO,
                instanceNo);
    }

    // 現在サービスに紐づいているサーバの一覧を取得する
    List<Long> instanceNos = new ArrayList<Long>();
    List<ComponentInstance> componentInstances = componentInstanceDao
            .readByComponentNo(Long.parseLong(componentNo));
    for (ComponentInstance componentInstance : componentInstances) {
        if (componentInstance.getInstanceNo().equals(Long.parseLong(instanceNo))) {
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (status == ComponentInstanceStatus.RUNNING) {
                // サービス起動中は割り当て解除できない
                throw new AutoApplicationException("EAPI-100013", componentNo, instanceNo);
            }
        }
        if (!instanceNos.contains(componentInstance.getInstanceNo())) {
            instanceNos.add(componentInstance.getInstanceNo());
        }
    }

    // サーバの一覧から当該サーバのインスタンス番号を削除
    instanceNos.remove(Long.parseLong(instanceNo));

    // サービス割り当て解除するディスクがアタッチされたままのものがあるかどうかチェック
    String notSelectedItem;
    Collection<Object> moveList = new ArrayList<Object>();
    // 画面の再選択項目に使用するので値はなんでもよいが、値は必須
    notSelectedItem = instance.getInstanceName();
    // サービス画面でも同様の処理が必要の為、サービスに切り出す
    moveList = componentService.checkAttachDisk(component.getFarmNo(), Long.parseLong(componentNo),
            instance.getInstanceName(), notSelectedItem, moveList);
    if (!moveList.isEmpty()) {
        // アタッチされたままのものは、解除できない
        throw new AutoApplicationException("EAPI-100037", componentNo, instanceNo);
    }

    // サービスとサーバの紐づけ解除(プロセス処理)
    componentService.associateInstances(Long.parseLong(componentNo), instanceNos);

    DetachComponentResponse response = new DetachComponentResponse();

    return response;
}