Example usage for org.apache.commons.lang BooleanUtils isFalse

List of usage examples for org.apache.commons.lang BooleanUtils isFalse

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils isFalse.

Prototype

public static boolean isFalse(Boolean bool) 

Source Link

Document

Checks if a Boolean value is false, handling null by returning false.

 BooleanUtils.isFalse(Boolean.TRUE)  = false BooleanUtils.isFalse(Boolean.FALSE) = true BooleanUtils.isFalse(null)          = false 

Usage

From source file:jp.primecloud.auto.tool.management.main.ConfigMain.java

public static void getPlatformNo(String platformName, String platformKind) {
    try {//from  www.  j a  v a 2 s.c o m
        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);
    }
}

From source file:jp.primecloud.auto.api.lb.EnableLBListener.java

/**
 *
 * ? /*from   w w  w. j  a v  a2 s .c o m*/
 *
 * @param farmNo ?
 * @param loadBalancerNo ??
 * @param loadBalancerPort ??
 *
 * @return EnableLBListenerResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public EnableLBListenerResponse enableLBListener(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_PORT) String loadBalancerPort) {

    EnableLBListenerResponse response = new EnableLBListenerResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);

        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            //?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }

        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());
        if (LoadBalancerStatus.RUNNING != status) {
            //???????
            throw new AutoApplicationException("EAPI-100028", loadBalancerNo, loadBalancerPort);
        }

        // ?
        // LoadBalancerPort
        ApiValidate.validateLoadBalancerPort(loadBalancer.getType(), loadBalancerPort);

        LoadBalancerListener loadBalancerListener = loadBalancerListenerDao.read(Long.parseLong(loadBalancerNo),
                Integer.parseInt(loadBalancerPort));
        if (loadBalancerListener == null) {
            //?????
            throw new AutoApplicationException("EAPI-100030", "LoadBalancerListener",
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo, PARAM_NAME_LOAD_BALANCER_PORT,
                    loadBalancerPort);
        }

        // ?
        Platform platform = platformDao.read(loadBalancer.getPlatformNo());
        if (platform == null) {
            //????
            throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO,
                    loadBalancer.getPlatformNo());
        }

        if (PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType())) {
            // ?CloudStack??????
            response.setSuccess(true);
            return response;
        }

        // ? 
        List<Integer> lbPorts = new ArrayList<Integer>();
        lbPorts.add(Integer.parseInt(loadBalancerPort));
        processService.startLoadBalancerListeners(Long.parseLong(farmNo), Long.parseLong(loadBalancerNo),
                lbPorts);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.lb.DisableLBListener.java

/**
 *
 * ? //from   www .  j a  v a2  s .com
 *
 * @param farmNo ?
 * @param loadBalancerNo ??
 * @param loadBalancerPort ??
 *
 * @return DisableLBListenerResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DisableLBListenerResponse disableLBListener(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_PORT) String loadBalancerPort) {

    DisableLBListenerResponse response = new DisableLBListenerResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);

        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            //?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }

        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());
        if (LoadBalancerStatus.RUNNING != status) {
            //???????
            throw new AutoApplicationException("EAPI-100029", loadBalancerNo, loadBalancerPort);
        }

        // ?
        // LoadBalancerPort
        ApiValidate.validateLoadBalancerPort(loadBalancer.getType(), loadBalancerPort);

        LoadBalancerListener loadBalancerListener = loadBalancerListenerDao.read(Long.parseLong(loadBalancerNo),
                Integer.parseInt(loadBalancerPort));
        if (loadBalancerListener == null) {
            //?????
            throw new AutoApplicationException("EAPI-100030", "LoadBalancerListener",
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo, PARAM_NAME_LOAD_BALANCER_PORT,
                    loadBalancerPort);
        }

        // ?
        Platform platform = platformDao.read(loadBalancer.getPlatformNo());
        if (platform == null) {
            //????
            throw new AutoApplicationException("EAPI-100000", "Platform", PARAM_NAME_PLATFORM_NO,
                    loadBalancer.getPlatformNo());
        }

        if (PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType())) {
            // ?CloudStack??????
            response.setSuccess(true);
            return response;
        }

        // ? 
        List<Integer> lbPorts = new ArrayList<Integer>();
        lbPorts.add(Integer.parseInt(loadBalancerPort));
        processService.stopLoadBalancerListeners(Long.parseLong(farmNo), Long.parseLong(loadBalancerNo),
                lbPorts);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.lb.DetachLoadBalancer.java

/**
 *
 * ? ??/* ww  w .j  ava  2 s  .  c  o m*/
 * @param farmNo ?
 * @param loadBalancerNo ??
 * @param instanceNo ?
 *
 * @return DetachLoadBalancerResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DetachLoadBalancerResponse detachLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    DetachLoadBalancerResponse response = new DetachLoadBalancerResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);
        // InstanceNo
        ApiValidate.validateInstanceNo(instanceNo);

        // ??
        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }
        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        // ?
        Instance instance = instanceDao.read(Long.parseLong(instanceNo));
        if (instance == null) {
            // ????
            throw new AutoApplicationException("EAPI-100000", "Instance", PARAM_NAME_INSTANCE_NO, instanceNo);
        }
        if (BooleanUtils.isFalse(instance.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //?????
            throw new AutoApplicationException("EAPI-100022", "Instance", farmNo, 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);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.instance.StoptInstance.java

/**
 *
 * ???/*ww w . ja  v  a2 s. co m*/
 *
 * @param farmNo ?
 * @param instanceNo ?
 *
 * @return StopInstanceResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public StopInstanceResponse stoptInstance(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    StopInstanceResponse response = new StopInstanceResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // InstanceNo
        ApiValidate.validateInstanceNo(instanceNo);

        // ?
        Instance instance = instanceDao.read(Long.parseLong(instanceNo));
        if (instance == null || BooleanUtils.isTrue(instance.getLoadBalancer())) {
            // ???? or ????
            throw new AutoApplicationException("EAPI-100000", "Instance", PARAM_NAME_INSTANCE_NO, instanceNo);
        }

        InstanceStatus status = InstanceStatus.fromStatus(instance.getStatus());
        if (InstanceStatus.RUNNING != status && InstanceStatus.WARNING != status) {
            // ?? ? or  ????
            throw new AutoApplicationException("EAPI-100024", instanceNo);
        }

        if (BooleanUtils.isFalse(instance.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //?????
            throw new AutoApplicationException("EAPI-100022", "Instance", farmNo, PARAM_NAME_INSTANCE_NO,
                    instanceNo);
        }

        // ???
        List<Long> instanceNos = new ArrayList<Long>();
        instanceNos.add(Long.parseLong(instanceNo));
        processService.stopInstances(Long.parseLong(farmNo), instanceNos);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.component.DetachComponent.java

/**
 *
 * ??????// www .j  av  a2 s  .  c  om
 *
 * @param farmNo ?
 * @param componentNo ???
 * @param instanceNo ?
 * @return DetachComponentResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DetachComponentResponse detachComponent(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    DetachComponentResponse response = new DetachComponentResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // ComponentNo
        ApiValidate.validateComponentNo(componentNo);
        // InstanceNo
        ApiValidate.validateInstanceNo(instanceNo);

        // ???
        Component component = componentDao.read(Long.parseLong(componentNo));
        if (component == null) {
            // ??????
            throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO,
                    componentNo);
        }

        if (BooleanUtils.isFalse(component.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //???????
            throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO,
                    componentNo);
        }

        // ???????????
        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>();
        Instance instance = instanceDao.read(Long.parseLong(instanceNo));
        // ???????????????
        notSelectedItem = instance.getInstanceName();
        // ???????????
        moveList = componentService.checkAttachDisk(Long.parseLong(farmNo), Long.parseLong(componentNo),
                instance.getInstanceName(), notSelectedItem, moveList);
        if (!moveList.isEmpty()) {
            // ??????????????
            throw new AutoApplicationException("EAPI-100037", componentNo, instanceNo);
        }

        // ??????(?)
        componentService.associateInstances(Long.parseLong(componentNo), instanceNos);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.lb.AttachLoadBalancer.java

/**
 *
 * ? ??//from w  w  w.  jav a2s  . co  m
 * @param farmNo ?
 * @param loadBalancerNo ??
 * @param instanceNo ?
 *
 * @return AttachLoadBalancerResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public AttachLoadBalancerResponse attachLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    AttachLoadBalancerResponse response = new AttachLoadBalancerResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);
        // InstanceNo
        ApiValidate.validateInstanceNo(instanceNo);

        // ??
        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }
        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        // ?
        Instance instance = instanceDao.read(Long.parseLong(instanceNo));
        if (instance == null) {
            // ????
            throw new AutoApplicationException("EAPI-100000", "Instance", PARAM_NAME_INSTANCE_NO, instanceNo);
        }
        if (BooleanUtils.isFalse(instance.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //?????
            throw new AutoApplicationException("EAPI-100022", "Instance", farmNo, 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);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.lb.StopLoadBalancer.java

/**
 *
 * ??/*from   www. j  a v  a2s .  co m*/
 *
 * @param farmNo ?
 * @param loadBalancerNo ??
 *
 * @return StopLoadBalancerResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public StopLoadBalancerResponse stopLoadBalancer(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo) {

    StopLoadBalancerResponse response = new StopLoadBalancerResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);

        // ??
        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }

        // ???
        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());
        if (LoadBalancerStatus.RUNNING != status && LoadBalancerStatus.WARNING != status) {
            // ? ? or  ????
            throw new AutoApplicationException("EAPI-100021", loadBalancerNo);
        }

        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        // ? ??
        List<Long> lbNos = new ArrayList<Long>();
        lbNos.add(Long.parseLong(loadBalancerNo));
        processService.stopLoadBalancers(Long.parseLong(farmNo), lbNos);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.component.AttachComponent.java

/**
 *
 * ??????/*from   w w  w  .j a va  2  s.c om*/
 *
 * @param farmNo ?
 * @param componentNo ???
 * @param instanceNo ?
 * @return AttachComponentResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public AttachComponentResponse attachComponent(@QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_COMPONENT_NO) String componentNo,
        @QueryParam(PARAM_NAME_INSTANCE_NO) String instanceNo) {

    AttachComponentResponse response = new AttachComponentResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // ComponentNo
        ApiValidate.validateComponentNo(componentNo);
        // InstanceNo
        ApiValidate.validateInstanceNo(instanceNo);

        // ???
        Component component = componentDao.read(Long.parseLong(componentNo));
        if (component == null) {
            // ??????
            throw new AutoApplicationException("EAPI-100000", "Component", PARAM_NAME_COMPONENT_NO,
                    componentNo);
        }

        if (BooleanUtils.isFalse(component.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //???????
            throw new AutoApplicationException("EAPI-100022", "Component", farmNo, PARAM_NAME_COMPONENT_NO,
                    componentNo);
        }

        // ?
        Instance instance = instanceDao.read(Long.parseLong(instanceNo));
        if (instance == null) {
            // ????
            throw new AutoApplicationException("EAPI-100000", "Instance", "InstanceNo", instanceNo);
        }

        if (BooleanUtils.isFalse(instance.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //?????
            throw new AutoApplicationException("EAPI-100022", "Instance", farmNo, PARAM_NAME_INSTANCE_NO,
                    instanceNo);
        }

        // ?
        Image image = imageDao.read(instance.getImageNo());
        List<Long> componentTypeNos = new ArrayList<Long>();
        for (String componentTypeNo : image.getComponentTypeNos().split(",")) {
            componentTypeNos.add(Long.parseLong(componentTypeNo.trim()));
        }

        // ?????
        if (!componentTypeNos.contains(component.getComponentTypeNo())) {
            // ??????????????
            throw new AutoApplicationException("EAPI-100003", componentNo, instanceNo);
        }

        // ?????????
        ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());
        List<ComponentInstance> instanceComponents = componentInstanceDao
                .readByInstanceNo(Long.parseLong(instanceNo));
        for (ComponentInstance componentInstance : instanceComponents) {
            if (componentInstance.getComponentNo().equals(Long.parseLong(componentNo))) {
                // ???ComponentInstance?????
                continue;
            }
            Component tmpComponent = componentDao.read(componentInstance.getComponentNo());
            ComponentType componentType2 = componentTypeDao.read(tmpComponent.getComponentTypeNo());
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (StringUtils.equals(componentType.getLayer(), componentType2.getLayer())
                    && (BooleanUtils.isTrue(componentInstance.getAssociate())
                            || status != ComponentInstanceStatus.STOPPED)) {
                // ? ?? ????? ??? ?????????????
                throw new AutoApplicationException("EAPI-100009", componentNo, instanceNo);
            }
        }

        // ???????????
        List<Long> instanceNos = new ArrayList<Long>();
        List<ComponentInstance> componentInstances = componentInstanceDao
                .readByComponentNo(Long.parseLong(componentNo));
        for (ComponentInstance componentInstance : componentInstances) {
            instanceNos.add(componentInstance.getInstanceNo());
        }

        // ???????
        instanceNos.add(Long.valueOf(instanceNo));

        // ??????
        componentService.associateInstances(Long.parseLong(componentNo), instanceNos);

        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}

From source file:jp.primecloud.auto.api.lb.DescribeLoadBalancerHealthCheck.java

/**
 *
 * ?(?)?/*www  . j a  v  a2s. co  m*/
 *
 * @param farmNo ?
 * @param loadBalancerNo ??
 *
 * @return DescribeLoadBalancerHealthCheckResponse
 */
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DescribeLoadBalancerHealthCheckResponse describeLoadBalancerHealthCheck(
        @QueryParam(PARAM_NAME_FARM_NO) String farmNo,
        @QueryParam(PARAM_NAME_LOAD_BALANCER_NO) String loadBalancerNo) {

    DescribeLoadBalancerHealthCheckResponse response = new DescribeLoadBalancerHealthCheckResponse();

    try {
        // ?
        // FarmNo
        ApiValidate.validateFarmNo(farmNo);
        // LoadBalancerNo
        ApiValidate.validateLoadBalancerNo(loadBalancerNo);

        // ??
        LoadBalancer loadBalancer = loadBalancerDao.read(Long.parseLong(loadBalancerNo));
        if (loadBalancer == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancer", PARAM_NAME_LOAD_BALANCER_NO,
                    loadBalancerNo);
        }

        // ??
        LoadBalancerHealthCheck healthCheck = loadBalancerHealthCheckDao.read(Long.parseLong(loadBalancerNo));
        if (healthCheck == null) {
            // ?????
            throw new AutoApplicationException("EAPI-100000", "LoadBalancerHealthCheck",
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        if (BooleanUtils.isFalse(loadBalancer.getFarmNo().equals(Long.parseLong(farmNo)))) {
            //??????
            throw new AutoApplicationException("EAPI-100022", "LoadBalancer", farmNo,
                    PARAM_NAME_LOAD_BALANCER_NO, loadBalancerNo);
        }

        response = new DescribeLoadBalancerHealthCheckResponse(loadBalancer, healthCheck);
        response.setSuccess(true);
    } catch (Throwable e) {
        String message = "";
        if (e instanceof AutoException || e instanceof AutoApplicationException) {
            message = e.getMessage();
        } else {
            message = MessageUtils.getMessage("EAPI-000000");
        }
        log.error(message, e);
        response.setMessage(message);
        response.setSuccess(false);
    }

    return response;
}