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

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

Introduction

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

Prototype

public static boolean isNotTrue(Boolean bool) 

Source Link

Document

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

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

Usage

From source file:jp.primecloud.auto.service.impl.ProcessServiceImpl.java

/**
 * {@inheritDoc}/*from   w  w  w.j  ava 2  s.  c  om*/
 */
@Override
public void stopLoadBalancerListeners(Long farmNo, Long loadBalancerNo, List<Integer> loadBalancerPorts) {
    if (loadBalancerPorts.isEmpty()) {
        return;
    }

    // ??
    List<LoadBalancerListener> listeners = loadBalancerListenerDao.readByLoadBalancerNo(loadBalancerNo);
    for (LoadBalancerListener listener : listeners) {
        if (!loadBalancerPorts.contains(listener.getLoadBalancerPort())) {
            continue;
        }
        if (BooleanUtils.isTrue(listener.getEnabled()) || BooleanUtils.isNotTrue(listener.getConfigure())) {
            listener.setEnabled(false);
            listener.setConfigure(true);
            loadBalancerListenerDao.update(listener);
        }
    }

    // ???
    LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo);
    if (BooleanUtils.isNotTrue(loadBalancer.getConfigure())) {
        loadBalancer.setConfigure(true);
        loadBalancerDao.update(loadBalancer);
    }

    // ????
    scheduleFarm(farmNo);
}

From source file:com.wineaccess.winepermit.WinePermitHelper.java

/**
 * @param sellInAltStatesModel/*  ww  w . j  av a 2s .c o  m*/
 * @param string 
 */
private void validateSellInAltModel(SellInAltStatesModel sellInAltStatesModel, String wineId) {

    Boolean isOptionSelectedKachinaAlt = BooleanUtils
            .toBoolean(sellInAltStatesModel.getIsOptionSelectedKachinaAlt());
    OptionSelectedAltStates optionSelectedAltStates = sellInAltStatesModel.getOptionSelectedAltStates();
    Boolean isOptionSelectedNoPermit = BooleanUtils.toBoolean(sellInAltStatesModel.getIsSelectedNoPermit());
    Boolean isSelectedAltStates = BooleanUtils.toBoolean(sellInAltStatesModel.getIsSelected());

    if (BooleanUtils.isTrue(isSelectedAltStates) && BooleanUtils.isNotTrue(isOptionSelectedKachinaAlt)
            && optionSelectedAltStates == null && BooleanUtils.isNotTrue(isOptionSelectedNoPermit)) {
        response.addError(
                new WineaccessError(SystemErrorCode.PERMIT_NO_OPTION_SELECTED_WINE_LICENCES_ERROR_WINE,
                        SystemErrorCode.PERMIT_NO_OPTION_SELECTED_WINE_LICENCES_ERROR_WINE_TEXT));
    } else if ((BooleanUtils.isTrue(isOptionSelectedKachinaAlt) && optionSelectedAltStates != null)
            || BooleanUtils.isTrue(isOptionSelectedKachinaAlt) && BooleanUtils.isTrue(isOptionSelectedNoPermit)
            || BooleanUtils.isTrue(isOptionSelectedNoPermit) && optionSelectedAltStates != null) {
        response.addError(new WineaccessError(SystemErrorCode.PERMIT_MORE_THAN_ONE_OPTION_SELECTED_ERROR_WINE,
                SystemErrorCode.PERMIT_MORE_THAN_ONE_OPTION_SELECTED_ERROR_WINE_TEXT));
    } else {
        if (optionSelectedAltStates != null) {
            validateoptionSelectedAltstates(optionSelectedAltStates, wineId);
        } else if (sellInAltStatesModel.getOptionSelectedNoPermit() != null)
            validateoptionSelectedNoPermit(isOptionSelectedNoPermit,
                    sellInAltStatesModel.getOptionSelectedNoPermit(), wineId);
        else {
            if (BooleanUtils.isTrue(isOptionSelectedNoPermit))
                response.addError(new WineaccessError(SystemErrorCode.WINE_PERMIT_SELECT_VALUE_NO_PERMIT,
                        SystemErrorCode.WINE_PERMIT_SELECT_VALUE_NO_PERMIT_TEXT));
        }
    }

}

From source file:au.org.theark.study.web.component.subject.SearchResultListPanel.java

/**
 * Create new parent relationship in database for valid relationship.
 * //from  www  . ja v  a 2s.  c  o  m
 * @param subject
 * @param modalWindow
 * @param relatives
 * @param feedbackPanel
 * @param target
 */
private void processParentSelection(final SubjectVO subject, final AbstractDetailModalWindow modalWindow,
        final List<RelationshipVo> relatives, final FeedbackPanel feedbackPanel, AjaxRequestTarget target) {

    String message;

    Boolean inbreedAllowed = (Boolean) SecurityUtils.getSubject().getSession()
            .getAttribute(Constants.INBREED_ALLOWED);

    if (BooleanUtils.isNotTrue(inbreedAllowed)
            && (message = getCircularRelationships(subject, relatives)) != null && message.length() > 0) {
        this.error(message);
        target.add(feedbackPanel);
        return;
    }

    LinkSubjectPedigree pedigreeRelationship = new LinkSubjectPedigree();

    Long sessionStudyId = (Long) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.STUDY_CONTEXT_ID);

    Study study = iArkCommonService.getStudy(sessionStudyId);

    String subjectUID = (String) SecurityUtils.getSubject().getSession()
            .getAttribute(au.org.theark.core.Constants.SUBJECTUID);

    String parentUID = subject.getLinkSubjectStudy().getSubjectUID();

    SubjectVO criteriaSubjectVo = new SubjectVO();
    criteriaSubjectVo.getLinkSubjectStudy().setStudy(study);
    criteriaSubjectVo.getLinkSubjectStudy().setSubjectUID(subjectUID);
    Collection<SubjectVO> subjects = iArkCommonService.getSubject(criteriaSubjectVo);
    SubjectVO subjectVo = subjects.iterator().next();
    pedigreeRelationship.setSubject(subjectVo.getLinkSubjectStudy());

    criteriaSubjectVo.getLinkSubjectStudy().setSubjectUID(parentUID);
    subjects = iArkCommonService.getSubject(criteriaSubjectVo);
    subjectVo = subjects.iterator().next();
    pedigreeRelationship.setRelative(subjectVo.getLinkSubjectStudy());

    String gender = subject.getLinkSubjectStudy().getPerson().getGenderType().getName();

    List<Relationship> relationships = iArkCommonService.getFamilyRelationships();
    for (Relationship relationship : relationships) {
        if ("Male".equalsIgnoreCase(gender) && "Father".equalsIgnoreCase(relationship.getName())) {
            pedigreeRelationship.setRelationship(relationship);
            break;
        }

        if ("Female".equalsIgnoreCase(gender) && "Mother".equalsIgnoreCase(relationship.getName())) {
            pedigreeRelationship.setRelationship(relationship);
            break;
        }
    }

    iStudyService.create(pedigreeRelationship);
    modalWindow.close(target);
}

From source file:com.haulmont.cuba.security.app.EntityLog.java

protected Set<String> getAllAttributes(Entity entity) {
    if (entity == null) {
        return null;
    }//from  w w w . j a va2  s  .c om
    Set<String> attributes = new HashSet<>();
    MetaClass metaClass = metadata.getClassNN(entity.getClass());
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        Range range = metaProperty.getRange();
        if (range.isClass() && range.getCardinality().isMany()) {
            continue;
        }
        attributes.add(metaProperty.getName());
    }
    Collection<CategoryAttribute> categoryAttributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
    if (categoryAttributes != null) {
        for (CategoryAttribute categoryAttribute : categoryAttributes) {
            if (BooleanUtils.isNotTrue(categoryAttribute.getIsCollection())) {
                attributes.add(DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute)
                        .getMetaProperty().getName());
            }
        }
    }
    return attributes;
}

From source file:jp.primecloud.auto.process.puppet.PuppetComponentProcess.java

protected void configureInstance(Long componentNo, ComponentProcessContext context, boolean start,
        Long instanceNo, Map<String, Object> rootMap) {
    Component component = componentDao.read(componentNo);
    Instance instance = instanceDao.read(instanceNo);
    ComponentInstance componentInstance = componentInstanceDao.read(componentNo, instanceNo);

    if (start) {/*w  w w.ja v  a  2s. com*/
        // ??
        startVolume(componentNo, instanceNo);
    } else {
        // Zabbix??
        stopZabbixTemplate(componentNo, instanceNo);
    }

    // ?
    rootMap = createInstanceMap(componentNo, context, start, instanceNo, rootMap);

    // ?
    ComponentType componentType = componentTypeDao.read(component.getComponentTypeNo());
    File manifestName = new File(manifestDir, instance.getFqdn() + "." + component.getComponentName() + ".pp");

    // ????
    String digest = getFileDigest(manifestName, "UTF-8");

    // ???????????
    if (digest == null && !start) {
        return;
    }

    // ??
    String templateName = componentType.getComponentTypeName() + ".ftl";
    generateManifest(templateName, rootMap, manifestName, "UTF-8");

    // ????
    if (BooleanUtils.isNotTrue(componentInstance.getConfigure())) {
        // ???????????
        if (digest != null) {
            String newDigest = getFileDigest(manifestName, "UTF-8");
            if (digest.equals(newDigest)) {
                // ?????
                if (log.isDebugEnabled()) {
                    log.debug(MessageUtils.format("Not changed manifest.(file={0})", manifestName.getName()));
                }
                return;
            }
        }
    }

    // Puppet?
    runPuppet(instance, component);

    if (!start) {
        // ??
        stopVolume(componentNo, instanceNo);
    } else {
        // Zabbix??
        startZabbixTemplate(componentNo, instanceNo);
    }
}

From source file:jp.primecloud.auto.service.impl.InstanceServiceImpl.java

/**
 * {@inheritDoc}//from   w w w .j a  v  a  2  s. c  o  m
 */
@Override
public List<InstanceDto> getInstances(Long farmNo) {
    // ?
    List<Instance> instances = new ArrayList<Instance>();
    List<Instance> allInstances = instanceDao.readByFarmNo(farmNo);
    for (Instance instance : allInstances) {
        // ???
        if (BooleanUtils.isTrue(instance.getLoadBalancer())) {
            continue;
        }
        instances.add(instance);
    }

    // ????
    List<Long> instanceNos = new ArrayList<Long>();
    for (Instance instance : instances) {
        instanceNos.add(instance.getInstanceNo());
    }

    // ZabbixInstance?
    List<ZabbixInstance> zabbixInstances = zabbixInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, ZabbixInstance> zabbixInstanceMap = new LinkedHashMap<Long, ZabbixInstance>();
    for (ZabbixInstance zabbixInstance : zabbixInstances) {
        zabbixInstanceMap.put(zabbixInstance.getInstanceNo(), zabbixInstance);
    }

    // ?
    List<Platform> platforms = platformDao.readAll();
    Map<Long, Platform> platformMap = new LinkedHashMap<Long, Platform>();
    for (Platform platform : platforms) {
        platformMap.put(platform.getPlatformNo(), platform);
    }

    // ?
    List<Image> images = imageDao.readAll();
    Map<Long, Image> imageMap = new LinkedHashMap<Long, Image>();
    for (Image image : images) {
        imageMap.put(image.getImageNo(), image);
    }

    // ??????
    Map<Long, List<ComponentInstance>> componentInstanceMap = new LinkedHashMap<Long, List<ComponentInstance>>();
    for (Long instanceNo : instanceNos) {
        componentInstanceMap.put(instanceNo, new ArrayList<ComponentInstance>());
    }
    List<ComponentInstance> tmpComponentInstances = componentInstanceDao.readInInstanceNos(instanceNos);
    for (ComponentInstance componentInstance : tmpComponentInstances) {
        // ?????????
        if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (status == ComponentInstanceStatus.STOPPED) {
                continue;
            }
        }
        componentInstanceMap.get(componentInstance.getInstanceNo()).add(componentInstance);
    }

    // ???
    Map<Long, Component> componentMap = new HashMap<Long, Component>();
    Set<Long> componentNos = new HashSet<Long>();
    for (ComponentInstance componentInstance : tmpComponentInstances) {
        componentNos.add(componentInstance.getComponentNo());
    }
    List<Component> components = componentDao.readInComponentNos(componentNos);
    for (Component component : components) {
        componentMap.put(component.getComponentNo(), component);
    }

    // TODO CLOUD BRANCHING
    // AWS 
    // AWS?
    List<PlatformAws> platformAwss = platformAwsDao.readAll();
    Map<Long, PlatformAws> platformAwsMap = new LinkedHashMap<Long, PlatformAws>();
    for (PlatformAws platformAws : platformAwss) {
        platformAwsMap.put(platformAws.getPlatformNo(), platformAws);
    }

    // AWS?
    List<ImageAws> imageAwss = imageAwsDao.readAll();
    Map<Long, ImageAws> imageAwsMap = new LinkedHashMap<Long, ImageAws>();
    for (ImageAws imageAws : imageAwss) {
        imageAwsMap.put(imageAws.getImageNo(), imageAws);
    }

    // AWS?
    List<AwsInstance> awsInstances = awsInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, AwsInstance> awsInstanceMap = new LinkedHashMap<Long, AwsInstance>();
    for (AwsInstance awsInstance : awsInstances) {
        awsInstanceMap.put(awsInstance.getInstanceNo(), awsInstance);
    }

    // AWS?
    Farm farm = farmDao.read(farmNo);
    List<AwsAddress> awsAddresses = awsAddressDao.readByUserNo(farm.getUserNo());
    Map<Long, AwsAddress> awsAddressMap = new LinkedHashMap<Long, AwsAddress>();
    for (AwsAddress awsAddress : awsAddresses) {
        if (awsAddress.getInstanceNo() != null) {
            awsAddressMap.put(awsAddress.getInstanceNo(), awsAddress);
        }
    }

    // AWS?
    List<AwsVolume> farmAwsVolumes = awsVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<AwsVolume>> awsVolumesMap = new LinkedHashMap<Long, List<AwsVolume>>();
    for (AwsVolume awsVolume : farmAwsVolumes) {
        Long instanceNo = awsVolume.getInstanceNo();
        if (instanceNo != null) {
            List<AwsVolume> awsVolumes = awsVolumesMap.get(instanceNo);
            if (awsVolumes == null) {
                awsVolumes = new ArrayList<AwsVolume>();
                awsVolumesMap.put(instanceNo, awsVolumes);
            }
            awsVolumes.add(awsVolume);
        }
    }

    // AWS??
    List<AwsCertificate> awsCertificates = awsCertificateDao.readByUserNo(farm.getUserNo());
    Map<Long, AwsCertificate> awsCertificateMap = new LinkedHashMap<Long, AwsCertificate>();
    for (AwsCertificate awsCertificate : awsCertificates) {
        awsCertificateMap.put(awsCertificate.getPlatformNo(), awsCertificate);
    }

    // CloudStack 
    // CloudStack?
    List<PlatformCloudstack> platformCloudstacks = platformCloudstackDao.readAll();
    Map<Long, PlatformCloudstack> platformCloudstackMap = new LinkedHashMap<Long, PlatformCloudstack>();
    for (PlatformCloudstack platformCloudstack : platformCloudstacks) {
        platformCloudstackMap.put(platformCloudstack.getPlatformNo(), platformCloudstack);
    }

    // CloudStack?
    List<ImageCloudstack> imageCloudstacks = imageCloudstackDao.readAll();
    Map<Long, ImageCloudstack> imageCloudstackMap = new LinkedHashMap<Long, ImageCloudstack>();
    for (ImageCloudstack imageCloudstack : imageCloudstacks) {
        imageCloudstackMap.put(imageCloudstack.getImageNo(), imageCloudstack);
    }

    // CloudStack?
    List<CloudstackInstance> cloudstackInstances = cloudstackInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, CloudstackInstance> cloudstackInstanceMap = new LinkedHashMap<Long, CloudstackInstance>();
    for (CloudstackInstance cloudstackInstance : cloudstackInstances) {
        cloudstackInstanceMap.put(cloudstackInstance.getInstanceNo(), cloudstackInstance);
    }

    // CloudStack?
    List<CloudstackAddress> cloudstackAddresses = cloudstackAddressDao.readByAccount(farm.getUserNo());
    Map<Long, CloudstackAddress> cloudstackAddressMap = new LinkedHashMap<Long, CloudstackAddress>();
    for (CloudstackAddress cloudstackAddress : cloudstackAddresses) {
        if (cloudstackAddress.getInstanceNo() != null) {
            cloudstackAddressMap.put(cloudstackAddress.getInstanceNo(), cloudstackAddress);
        }
    }

    // CloudStack?
    List<CloudstackVolume> farmCloudstackVolumes = cloudstackVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<CloudstackVolume>> cloudstackVolumesMap = new LinkedHashMap<Long, List<CloudstackVolume>>();
    for (CloudstackVolume cloudstackVolume : farmCloudstackVolumes) {
        Long instanceNo = cloudstackVolume.getInstanceNo();
        if (instanceNo != null) {
            List<CloudstackVolume> cloudstackVolumes = cloudstackVolumesMap.get(instanceNo);
            if (cloudstackVolumes == null) {
                cloudstackVolumes = new ArrayList<CloudstackVolume>();
                cloudstackVolumesMap.put(instanceNo, cloudstackVolumes);
            }
            cloudstackVolumes.add(cloudstackVolume);
        }
    }

    // VMware 
    // VMWare?
    List<PlatformVmware> platformVmwares = platformVmwareDao.readAll();
    Map<Long, PlatformVmware> platformVmwareMap = new LinkedHashMap<Long, PlatformVmware>();
    for (PlatformVmware platformVmware : platformVmwares) {
        platformVmwareMap.put(platformVmware.getPlatformNo(), platformVmware);
    }

    // VMware?
    List<ImageVmware> imageVmwares = imageVmwareDao.readAll();
    Map<Long, ImageVmware> imageVmwareMap = new LinkedHashMap<Long, ImageVmware>();
    for (ImageVmware imageVmware : imageVmwares) {
        imageVmwareMap.put(imageVmware.getImageNo(), imageVmware);
    }

    // VMware?
    List<VmwareInstance> vmwareInstances = vmwareInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, VmwareInstance> vmwareInstanceMap = new LinkedHashMap<Long, VmwareInstance>();
    for (VmwareInstance vmwareInstance : vmwareInstances) {
        vmwareInstanceMap.put(vmwareInstance.getInstanceNo(), vmwareInstance);
    }

    // VMwareAddress?
    Map<Long, VmwareAddress> vmwareAddressMap = new LinkedHashMap<Long, VmwareAddress>();
    List<VmwareAddress> vmwareAddresses = vmwareAddressDao.readByUserNo(farm.getUserNo());
    for (VmwareAddress vmwareAddress : vmwareAddresses) {
        if (vmwareAddress.getInstanceNo() != null) {
            vmwareAddressMap.put(vmwareAddress.getInstanceNo(), vmwareAddress);
        }
    }

    // VMware?
    Map<Long, VmwareKeyPair> vmwareKeyPairMap = new LinkedHashMap<Long, VmwareKeyPair>();
    if (!vmwareInstanceMap.isEmpty()) {
        List<VmwareKeyPair> vmwareKeyPairs = vmwareKeyPairDao.readByUserNo(farm.getUserNo());
        for (VmwareKeyPair vmwareKeyPair : vmwareKeyPairs) {
            vmwareKeyPairMap.put(vmwareKeyPair.getKeyNo(), vmwareKeyPair);
        }
    }

    // VMware?
    List<VmwareDisk> farmVmwareDisks = vmwareDiskDao.readByFarmNo(farmNo);
    Map<Long, List<VmwareDisk>> vmwareDisksMap = new LinkedHashMap<Long, List<VmwareDisk>>();
    for (VmwareDisk vmwareDisk : farmVmwareDisks) {
        Long instanceNo = vmwareDisk.getInstanceNo();
        if (instanceNo != null) {
            List<VmwareDisk> vmwareDisks = vmwareDisksMap.get(instanceNo);
            if (vmwareDisks == null) {
                vmwareDisks = new ArrayList<VmwareDisk>();
                vmwareDisksMap.put(instanceNo, vmwareDisks);
            }
            vmwareDisks.add(vmwareDisk);
        }
    }

    // Nifty 
    // Nifty?
    List<PlatformNifty> platformNifties = platformNiftyDao.readAll();
    Map<Long, PlatformNifty> platformNiftyMap = new LinkedHashMap<Long, PlatformNifty>();
    for (PlatformNifty platformNifty : platformNifties) {
        platformNiftyMap.put(platformNifty.getPlatformNo(), platformNifty);
    }

    // Nifty?
    List<ImageNifty> imageNifties = imageNiftyDao.readAll();
    Map<Long, ImageNifty> imageNiftyMap = new LinkedHashMap<Long, ImageNifty>();
    for (ImageNifty imageNifty : imageNifties) {
        imageNiftyMap.put(imageNifty.getImageNo(), imageNifty);
    }

    // Nifty?
    List<NiftyInstance> niftyInstances = niftyInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, NiftyInstance> niftyInstanceMap = new LinkedHashMap<Long, NiftyInstance>();
    for (NiftyInstance niftyInstance : niftyInstances) {
        niftyInstanceMap.put(niftyInstance.getInstanceNo(), niftyInstance);
    }

    // Nifty?
    Map<Long, NiftyKeyPair> niftyKeyPairMap = new LinkedHashMap<Long, NiftyKeyPair>();
    if (!niftyInstanceMap.isEmpty()) {
        List<NiftyKeyPair> niftyKeyPairs = niftyKeyPairDao.readByUserNo(farm.getUserNo());
        for (NiftyKeyPair niftyKeyPair : niftyKeyPairs) {
            niftyKeyPairMap.put(niftyKeyPair.getKeyNo(), niftyKeyPair);
        }
    }

    // Nifty?
    List<NiftyVolume> farmNiftyVolumes = niftyVolumeDao.readByFarmNo(farmNo);
    Map<Long, List<NiftyVolume>> niftyVolumesMap = new LinkedHashMap<Long, List<NiftyVolume>>();
    for (NiftyVolume niftyVolume : farmNiftyVolumes) {
        Long instanceNo = niftyVolume.getInstanceNo();
        if (instanceNo != null) {
            List<NiftyVolume> niftyVolumes = niftyVolumesMap.get(instanceNo);
            if (niftyVolumes == null) {
                niftyVolumes = new ArrayList<NiftyVolume>();
                niftyVolumesMap.put(instanceNo, niftyVolumes);
            }
            niftyVolumes.add(niftyVolume);
        }
    }

    // VCloud 
    // VCloudPlatform?
    List<PlatformVcloud> platformVclouds = platformVcloudDao.readAll();
    Map<Long, PlatformVcloud> platformVcloudMap = new LinkedHashMap<Long, PlatformVcloud>();
    for (PlatformVcloud platformVcloud : platformVclouds) {
        platformVcloudMap.put(platformVcloud.getPlatformNo(), platformVcloud);
    }

    // VCloudImage?
    List<ImageVcloud> imageVclouds = imageVcloudDao.readAll();
    Map<Long, ImageVcloud> imageVcloudMap = new LinkedHashMap<Long, ImageVcloud>();
    for (ImageVcloud imageVcloud : imageVclouds) {
        imageVcloudMap.put(imageVcloud.getImageNo(), imageVcloud);
    }

    // VCloudInstance?
    List<VcloudInstance> vcloudInstances = vcloudInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, VcloudInstance> vcloudInstanceMap = new LinkedHashMap<Long, VcloudInstance>();
    for (VcloudInstance vcloudInstance : vcloudInstances) {
        vcloudInstanceMap.put(vcloudInstance.getInstanceNo(), vcloudInstance);
    }

    // VCloudKeyPair?
    Map<Long, VcloudKeyPair> vcloudKeyPairMap = new LinkedHashMap<Long, VcloudKeyPair>();
    List<VcloudKeyPair> vcloudKeyPairs = vcloudKeyPairDao.readByUserNo(farm.getUserNo());
    for (VcloudKeyPair vcloudKeyPair : vcloudKeyPairs) {
        vcloudKeyPairMap.put(vcloudKeyPair.getKeyNo(), vcloudKeyPair);
    }

    // VCloudDisk?
    List<VcloudDisk> farmVcloudDisks = vcloudDiskDao.readByFarmNo(farmNo);
    Map<Long, List<VcloudDisk>> vcloudDiskMap = new LinkedHashMap<Long, List<VcloudDisk>>();
    for (VcloudDisk vcloudDisk : farmVcloudDisks) {
        Long instanceNo = vcloudDisk.getInstanceNo();
        if (instanceNo != null) {
            List<VcloudDisk> vcloudDisks = vcloudDiskMap.get(instanceNo);
            if (vcloudDisks == null) {
                vcloudDisks = new ArrayList<VcloudDisk>();
            }
            vcloudDisks.add(vcloudDisk);
            vcloudDiskMap.put(instanceNo, vcloudDisks);
        }
    }

    //VCloudNetwork?
    List<VcloudInstanceNetwork> allVcloudInstanceNetworks = vcloudInstanceNetworkDao.readByFarmNo(farmNo);
    Map<Long, List<VcloudInstanceNetwork>> vcloudInstanceNetworkMap = new LinkedHashMap<Long, List<VcloudInstanceNetwork>>();
    for (VcloudInstanceNetwork vcloudInstanceNetwork : allVcloudInstanceNetworks) {
        List<VcloudInstanceNetwork> instanceNetworks = vcloudInstanceNetworkMap
                .get(vcloudInstanceNetwork.getInstanceNo());
        if (instanceNetworks == null) {
            instanceNetworks = new ArrayList<VcloudInstanceNetwork>();
        }
        instanceNetworks.add(vcloudInstanceNetwork);
        vcloudInstanceNetworkMap.put(vcloudInstanceNetwork.getInstanceNo(), instanceNetworks);
    }

    //PlatformVcloudStorageType?
    List<PlatformVcloudStorageType> platformVcloudStorageTypes = platformVcloudStorageTypeDao.readAll();
    Map<Long, PlatformVcloudStorageType> platformVcloudStorageTypeMap = new LinkedHashMap<Long, PlatformVcloudStorageType>();
    for (PlatformVcloudStorageType platformVcloudStorageType : platformVcloudStorageTypes) {
        platformVcloudStorageTypeMap.put(platformVcloudStorageType.getStorageTypeNo(),
                platformVcloudStorageType);
    }

    // Azure 
    // Azure?
    List<PlatformAzure> platformAzures = platformAzureDao.readAll();
    Map<Long, PlatformAzure> platformAzureMap = new LinkedHashMap<Long, PlatformAzure>();
    for (PlatformAzure platformAzure : platformAzures) {
        platformAzureMap.put(platformAzure.getPlatformNo(), platformAzure);
    }

    // Azure?
    List<ImageAzure> imageAzures = imageAzureDao.readAll();
    Map<Long, ImageAzure> imageAzureMap = new LinkedHashMap<Long, ImageAzure>();
    for (ImageAzure imageAzure : imageAzures) {
        imageAzureMap.put(imageAzure.getImageNo(), imageAzure);
    }

    // Azure?
    List<AzureInstance> azureInstances = azureInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, AzureInstance> azureInstanceMap = new LinkedHashMap<Long, AzureInstance>();
    for (AzureInstance azureInstance : azureInstances) {
        azureInstanceMap.put(azureInstance.getInstanceNo(), azureInstance);
    }

    // Azure??   ??????????
    //        List<AzureSubnet> azureAddresses = azureSubnetDao.readByAccount(farm.getUserNo());
    //        Map<Long, AzureSubnet> azureAddressMap = new LinkedHashMap<Long, AzureSubnet>();
    //        for (CloudstackAddress azureAddress : azureAddresses) {
    //            if (azureAddress.getInstanceNo() != null) {
    //                cloudstackAddressMap.put(azureAddress.getInstanceNo(), azureAddress);
    //            }
    //        }

    // Azure?
    List<AzureDisk> farmAzureDisks = azureDiskDao.readByFarmNo(farmNo);
    Map<Long, List<AzureDisk>> azureDisksMap = new LinkedHashMap<Long, List<AzureDisk>>();
    for (AzureDisk azureDisk : farmAzureDisks) {
        Long instanceNo = azureDisk.getInstanceNo();
        if (instanceNo != null) {
            List<AzureDisk> azureDisks = azureDisksMap.get(instanceNo);
            if (azureDisks == null) {
                azureDisks = new ArrayList<AzureDisk>();
                azureDisksMap.put(instanceNo, azureDisks);
            }
            azureDisks.add(azureDisk);
        }
    }

    // OpenStack 
    // OpenStack?
    List<PlatformOpenstack> platformOpenstacks = platformOpenstackDao.readAll();
    Map<Long, PlatformOpenstack> platformOpenstackMap = new LinkedHashMap<Long, PlatformOpenstack>();
    for (PlatformOpenstack platformOpenstack : platformOpenstacks) {
        platformOpenstackMap.put(platformOpenstack.getPlatformNo(), platformOpenstack);
    }

    // OpenStack?
    List<ImageOpenstack> imageOpenstacks = imageOpenstackDao.readAll();
    Map<Long, ImageOpenstack> imageOpenstackMap = new LinkedHashMap<Long, ImageOpenstack>();
    for (ImageOpenstack imageOpenstack : imageOpenstacks) {
        imageOpenstackMap.put(imageOpenstack.getImageNo(), imageOpenstack);
    }

    // OpenStack?
    List<OpenstackInstance> openstackInstances = openstackInstanceDao.readInInstanceNos(instanceNos);
    Map<Long, OpenstackInstance> openstackInstanceMap = new LinkedHashMap<Long, OpenstackInstance>();
    for (OpenstackInstance openstackInstance : openstackInstances) {
        openstackInstanceMap.put(openstackInstance.getInstanceNo(), openstackInstance);
    }

    // ????????
    List<InstanceDto> dtos = new ArrayList<InstanceDto>();
    for (Instance instance : instances) {
        ZabbixInstance zabbixInstance = zabbixInstanceMap.get(instance.getInstanceNo());

        PlatformDto platformDto = new PlatformDto();
        ImageDto imageDto = new ImageDto();

        Platform platform = platformMap.get(instance.getPlatformNo());
        platformDto.setPlatform(platform);

        Image image = imageMap.get(instance.getImageNo());
        imageDto.setImage(image);
        // TODO CLOUD BRANCHING
        if (PCCConstant.PLATFORM_TYPE_AWS.equals(platform.getPlatformType())) {
            platformDto.setPlatformAws(platformAwsMap.get(instance.getPlatformNo()));
            imageDto.setImageAws(imageAwsMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_CLOUDSTACK.equals(platform.getPlatformType())) {
            platformDto.setPlatformCloudstack(platformCloudstackMap.get(instance.getPlatformNo()));
            imageDto.setImageCloudstack(imageCloudstackMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_VMWARE.equals(platform.getPlatformType())) {
            platformDto.setPlatformVmware(platformVmwareMap.get(instance.getPlatformNo()));
            imageDto.setImageVmware(imageVmwareMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_NIFTY.equals(platform.getPlatformType())) {
            platformDto.setPlatformNifty(platformNiftyMap.get(instance.getPlatformNo()));
            imageDto.setImageNifty(imageNiftyMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_VCLOUD.equals(platform.getPlatformType())) {
            platformDto.setPlatformVcloud(platformVcloudMap.get(instance.getPlatformNo()));
            imageDto.setImageVcloud(imageVcloudMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_AZURE.equals(platform.getPlatformType())) {
            platformDto.setPlatformAzure(platformAzureMap.get(instance.getPlatformNo()));
            imageDto.setImageAzure(imageAzureMap.get(instance.getImageNo()));
        } else if (PCCConstant.PLATFORM_TYPE_OPENSTACK.equals(platform.getPlatformType())) {
            platformDto.setPlatformOpenstack(platformOpenstackMap.get(instance.getPlatformNo()));
            imageDto.setImageOpenstack(imageOpenstackMap.get(instance.getImageNo()));
        }

        List<InstanceConfig> instanceConfigs = instanceConfigDao.readByInstanceNo(instance.getInstanceNo());

        List<ComponentInstanceDto> componentInstances = new ArrayList<ComponentInstanceDto>();
        for (ComponentInstance componentInstance : componentInstanceMap.get(instance.getInstanceNo())) {
            ComponentInstanceDto componentInstanceDto = new ComponentInstanceDto();
            componentInstanceDto.setComponentInstance(componentInstance);

            Component component = componentMap.get(componentInstance.getComponentNo());
            String url;
            Boolean showPublicIp = BooleanUtils.toBooleanObject(Config.getProperty("ui.showPublicIp"));
            if (BooleanUtils.isTrue(showPublicIp)) {
                //ui.showPublicIp = true ???URL?PublicIp
                url = createUrl(instance.getPublicIp(), component.getComponentTypeNo());
            } else {
                //ui.showPublicIp = false ???URL?PrivateIp
                url = createUrl(instance.getPrivateIp(), component.getComponentTypeNo());
            }
            componentInstanceDto.setUrl(url);
            componentInstances.add(componentInstanceDto);
        }

        // ?????
        InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
        if (BooleanUtils.isTrue(instance.getEnabled())) {
            if (instanceStatus == InstanceStatus.STOPPED) {
                instance.setStatus(InstanceStatus.STARTING.toString());
            }
        } else {
            if (instanceStatus == InstanceStatus.RUNNING || instanceStatus == InstanceStatus.WARNING) {
                instance.setStatus(InstanceStatus.STOPPING.toString());
            }
        }

        // ???
        //    ? ?   ??
        //        Running         Coodinating            Configuring
        //        Running         Warning                Warning
        instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
        InstanceCoodinateStatus insCoodiStatus = InstanceCoodinateStatus
                .fromStatus(instance.getCoodinateStatus());
        // ?(Running)???(Coodinating)Configuring?
        if (instanceStatus == InstanceStatus.RUNNING && insCoodiStatus == InstanceCoodinateStatus.COODINATING) {
            instance.setStatus(InstanceStatus.CONFIGURING.toString());
            // ?(Running)???(Warning)Warning?
        } else if (instanceStatus == InstanceStatus.RUNNING
                && insCoodiStatus == InstanceCoodinateStatus.WARNING) {
            instance.setStatus(InstanceStatus.WARNING.toString());
        }

        // ????????
        instanceStatus = InstanceStatus.fromStatus(instance.getStatus());
        for (ComponentInstanceDto componentInstanceDto : componentInstances) {
            ComponentInstance componentInstance = componentInstanceDto.getComponentInstance();
            ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
            if (BooleanUtils.isTrue(componentInstance.getEnabled())) {
                if (status == ComponentInstanceStatus.STOPPED) {
                    if (instanceStatus == InstanceStatus.WARNING) {
                        // ?Waring??????Warning??
                        componentInstance.setStatus(ComponentInstanceStatus.WARNING.toString());
                    } else if (BooleanUtils.isTrue(farm.getScheduled())) {
                        componentInstance.setStatus(ComponentInstanceStatus.STARTING.toString());
                    }
                }
            } else {
                if (status == ComponentInstanceStatus.RUNNING || status == ComponentInstanceStatus.WARNING) {
                    if (BooleanUtils.isTrue(farm.getScheduled())) {
                        // ??????Stopping??
                        componentInstance.setStatus(ComponentInstanceStatus.STOPPING.toString());
                    }
                }
            }
        }

        AwsInstance awsInstance = awsInstanceMap.get(instance.getInstanceNo());
        AwsAddress awsAddress = awsAddressMap.get(instance.getInstanceNo());
        List<AwsVolume> awsVolumes = awsVolumesMap.get(instance.getInstanceNo());
        AwsCertificate awsCertificate = awsCertificateMap.get(instance.getPlatformNo());

        CloudstackInstance cloudstackInstance = cloudstackInstanceMap.get(instance.getInstanceNo());
        CloudstackAddress cloudstackAddress = cloudstackAddressMap.get(instance.getInstanceNo());
        List<CloudstackVolume> cloudstackVolumes = cloudstackVolumesMap.get(instance.getInstanceNo());

        VmwareInstance vmwareInstance = vmwareInstanceMap.get(instance.getInstanceNo());
        VmwareAddress vmwareAddress = vmwareAddressMap.get(instance.getInstanceNo());
        VmwareKeyPair vmwareKeyPair = null;
        if (vmwareInstance != null) {
            vmwareKeyPair = vmwareKeyPairMap.get(vmwareInstance.getKeyPairNo());
        }
        List<VmwareDisk> vmwareDisks = vmwareDisksMap.get(instance.getInstanceNo());

        NiftyInstance niftyInstance = niftyInstanceMap.get(instance.getInstanceNo());
        NiftyKeyPair niftyKeyPair = null;
        if (niftyInstance != null) {
            niftyKeyPair = niftyKeyPairMap.get(niftyInstance.getKeyPairNo());
        }
        List<NiftyVolume> niftyVolumes = niftyVolumesMap.get(instance.getInstanceNo());

        VcloudInstance vcloudInstance = vcloudInstanceMap.get(instance.getInstanceNo());
        VcloudKeyPair vcloudKeyPair = null;
        if (vcloudInstance != null) {
            vcloudKeyPair = vcloudKeyPairMap.get(vcloudInstance.getKeyPairNo());
        }
        List<VcloudDisk> vcloudDisks = vcloudDiskMap.get(instance.getInstanceNo());
        List<VcloudInstanceNetwork> vcloudInstanceNetworks = vcloudInstanceNetworkMap
                .get(instance.getInstanceNo());
        if (vcloudInstanceNetworks != null) {
            Collections.sort(vcloudInstanceNetworks, Comparators.COMPARATOR_VCLOUD_INSTANCE_NETWORK);
        }
        PlatformVcloudStorageType platformVcloudStorageType = null;
        if (vcloudInstance != null) {
            platformVcloudStorageType = platformVcloudStorageTypeMap.get(vcloudInstance.getStorageTypeNo());
        }

        AzureInstance azureInstance = azureInstanceMap.get(instance.getInstanceNo());
        List<AzureDisk> azureDisks = azureDisksMap.get(instance.getInstanceNo());

        OpenstackInstance openstackInstance = openstackInstanceMap.get(instance.getInstanceNo());

        // 
        Collections.sort(componentInstances, Comparators.COMPARATOR_COMPONENT_INSTANCE_DTO);

        InstanceDto dto = new InstanceDto();
        dto.setInstance(instance);
        dto.setZabbixInstance(zabbixInstance);
        dto.setPlatform(platformDto);
        dto.setImage(imageDto);
        dto.setInstanceConfigs(instanceConfigs);
        dto.setComponentInstances(componentInstances);

        dto.setAwsInstance(awsInstance);
        dto.setAwsAddress(awsAddress);
        dto.setAwsVolumes(awsVolumes);
        dto.setAwsCertificate(awsCertificate);

        dto.setCloudstackInstance(cloudstackInstance);
        dto.setCloudstackAddress(cloudstackAddress);
        dto.setCloudstackVolumes(cloudstackVolumes);

        dto.setVmwareInstance(vmwareInstance);
        dto.setVmwareAddress(vmwareAddress);
        dto.setVmwareKeyPair(vmwareKeyPair);
        dto.setVmwareDisks(vmwareDisks);

        dto.setNiftyInstance(niftyInstance);
        dto.setNiftyKeyPair(niftyKeyPair);
        dto.setNiftyVolumes(niftyVolumes);

        dto.setVcloudInstance(vcloudInstance);
        dto.setVcloudKeyPair(vcloudKeyPair);
        dto.setVcloudDisks(vcloudDisks);
        dto.setVcloudInstanceNetworks(vcloudInstanceNetworks);
        dto.setPlatformVcloudStorageType(platformVcloudStorageType);

        dto.setAzureInstance(azureInstance);
        dto.setAzureDisks(azureDisks);

        dto.setOpenstackInstance(openstackInstance);

        dtos.add(dto);
    }

    // 
    Collections.sort(dtos, Comparators.COMPARATOR_INSTANCE_DTO);

    return dtos;
}

From source file:jp.primecloud.auto.process.ProcessManager.java

protected boolean processStopLoadBalancer(final Farm farm) {
    // ???/*  w w w.j  av  a  2s.com*/
    List<LoadBalancer> loadBalancers = new ArrayList<LoadBalancer>();
    List<LoadBalancer> allLoadBalancers = loadBalancerDao.readByFarmNo(farm.getFarmNo());
    for (LoadBalancer loadBalancer : allLoadBalancers) {
        if (BooleanUtils.isNotTrue(loadBalancer.getEnabled())) {
            loadBalancers.add(loadBalancer);
        }
    }

    // ?????
    if (loadBalancers.isEmpty()) {
        return true;
    }

    // ???
    boolean processing = false;
    List<Long> targetLoadBalancerNos = new ArrayList<Long>();
    for (LoadBalancer loadBalancer : loadBalancers) {
        LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus());

        if (status != LoadBalancerStatus.STOPPED) {
            processing = true;

            if (status == LoadBalancerStatus.RUNNING || status == LoadBalancerStatus.WARNING) {
                targetLoadBalancerNos.add(loadBalancer.getLoadBalancerNo());
            }
        }
    }

    // ??????
    if (!targetLoadBalancerNos.isEmpty()) {
        final User user = userDao.read(farm.getUserNo());
        for (final Long loadBalancerNo : targetLoadBalancerNos) {
            Runnable runnable = new Runnable() {
                @Override
                public void run() {
                    LoggingUtils.setUserNo(user.getMasterUser());
                    LoggingUtils.setUserName(user.getUsername());
                    LoggingUtils.setFarmNo(farm.getFarmNo());
                    LoggingUtils.setFarmName(farm.getFarmName());
                    LoggingUtils.setLoginUserNo(user.getUserNo());
                    try {
                        loadBalancerProcess.stop(loadBalancerNo);
                    } catch (MultiCauseException ignore) {
                    } catch (Throwable e) {
                        log.error(e.getMessage(), e);

                        // 
                        eventLogger.error("SystemError", new Object[] { e.getMessage() });
                    } finally {
                        LoggingUtils.removeContext();
                    }
                }
            };
            executorService.execute(runnable);
        }
    }

    // ?????
    if (processing) {
        return false;
    }

    return true;
}

From source file:jp.primecloud.auto.service.impl.ProcessServiceImpl.java

protected void scheduleFarm(Long farmNo) {
    Farm farm = farmDao.read(farmNo);//from w w w. j  av  a 2s  .  c om
    if (BooleanUtils.isNotTrue(farm.getScheduled())) {
        farm.setScheduled(true);
        farmDao.update(farm);
    }
}

From source file:jp.primecloud.auto.process.puppet.PuppetComponentProcess.java

protected void deleteAssociate(Long componentNo, Long instanceNo) {
    ComponentInstance componentInstance = componentInstanceDao.read(componentNo, instanceNo);

    // ??????????????????
    if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
        ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus());
        if (status == ComponentInstanceStatus.STOPPED) {
            componentInstanceDao.delete(componentInstance);
        }/*from   www  .  ja  v a2 s. c  om*/
    }
}

From source file:jp.primecloud.auto.service.impl.LoadBalancerServiceImpl.java

protected void registerInstances(LoadBalancer loadBalancer) {
    // ??????/*from w  w  w. j  a va 2  s .  c o  m*/
    List<ComponentInstance> componentInstances = componentInstanceDao
            .readByComponentNo(loadBalancer.getComponentNo());
    List<Long> instanceNos = new ArrayList<Long>();
    for (ComponentInstance componentInstance : componentInstances) {
        if (BooleanUtils.isNotTrue(componentInstance.getAssociate())) {
            continue;
        }
        instanceNos.add(componentInstance.getInstanceNo());
    }
    List<Instance> instances = instanceDao.readInInstanceNos(instanceNos);

    if (instanceNos.isEmpty()) {
        return;
    }

    // ?????
    List<LoadBalancer> allLoadBalancers = loadBalancerDao.readByFarmNo(loadBalancer.getFarmNo());
    List<Long> loadBalancerNos = new ArrayList<Long>();
    for (LoadBalancer tmpLoadBalancer : allLoadBalancers) {
        loadBalancerNos.add(tmpLoadBalancer.getLoadBalancerNo());
    }
    List<LoadBalancerInstance> allLbInstances = loadBalancerInstanceDao.readInLoadBalancerNos(loadBalancerNos);

    List<Instance> tmpInstances = new ArrayList<Instance>();
    for (Instance instance : instances) {
        boolean check = checkAssociate(loadBalancer, instance, allLoadBalancers, allLbInstances);
        if (check) {
            tmpInstances.add(instance);
        }
    }
    instances = tmpInstances;

    // ????
    for (Instance instance : instances) {
        LoadBalancerInstance lbInstance = new LoadBalancerInstance();
        lbInstance.setLoadBalancerNo(loadBalancer.getLoadBalancerNo());
        lbInstance.setInstanceNo(instance.getInstanceNo());
        lbInstance.setEnabled(true);
        lbInstance.setStatus(LoadBalancerInstanceStatus.STOPPED.toString());
        loadBalancerInstanceDao.create(lbInstance);
    }
}