List of usage examples for org.apache.commons.lang BooleanUtils isTrue
public static boolean isTrue(Boolean bool)
Checks if a Boolean
value is true
, handling null
by returning false
.
BooleanUtils.isTrue(Boolean.TRUE) = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null) = false
From source file:jp.primecloud.auto.process.ComponentProcess.java
protected ComponentProcessContext createContext(Long farmNo) { ComponentProcessContext context = new ComponentProcessContext(); context.setFarmNo(farmNo);//from ww w . ja v a2 s .c o m // ???? List<Instance> instances = instanceDao.readByFarmNo(farmNo); List<Long> runningInstanceNos = new ArrayList<Long>(); for (Instance instance : instances) { // ????????? if (InstanceStatus.fromStatus(instance.getStatus()) != InstanceStatus.RUNNING) { continue; } // ???? if (BooleanUtils.isTrue(instance.getLoadBalancer())) { continue; } // PuppetInstance???? ???OS?windows???? PuppetInstance puppetInstance = puppetInstanceDao.read(instance.getInstanceNo()); Image image = imageDao.read(instance.getImageNo()); if (puppetInstance == null && !StringUtils.startsWithIgnoreCase(image.getOs(), PCCConstant.OS_NAME_WIN)) { continue; } runningInstanceNos.add(instance.getInstanceNo()); } context.setRunningInstanceNos(runningInstanceNos); // ????? List<ComponentInstance> componentInstances = componentInstanceDao.readInInstanceNos(runningInstanceNos); Map<Long, List<Long>> enableInstanceNoMap = new HashMap<Long, List<Long>>(); Map<Long, List<Long>> disableInstanceNoMap = new HashMap<Long, List<Long>>(); for (ComponentInstance componentInstance : componentInstances) { Map<Long, List<Long>> map; if (BooleanUtils.isTrue(componentInstance.getEnabled())) { map = enableInstanceNoMap; } else { map = disableInstanceNoMap; } List<Long> list = map.get(componentInstance.getComponentNo()); if (list == null) { list = new ArrayList<Long>(); map.put(componentInstance.getComponentNo(), list); } list.add(componentInstance.getInstanceNo()); } context.setEnableInstanceNoMap(enableInstanceNoMap); context.setDisableInstanceNoMap(disableInstanceNoMap); // ???? List<LoadBalancer> loadBalancers = loadBalancerDao.readByFarmNo(farmNo); List<Long> loadBalancerNos = new ArrayList<Long>(); for (LoadBalancer loadBalancer : loadBalancers) { LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); if (BooleanUtils.isTrue(loadBalancer.getEnabled())) { // ????????? if (status != LoadBalancerStatus.RUNNING) { continue; } } else { // ???????????? if (status != LoadBalancerStatus.RUNNING && status != LoadBalancerStatus.WARNING) { continue; } } loadBalancerNos.add(loadBalancer.getLoadBalancerNo()); } context.setTargetLoadBalancerNos(loadBalancerNos); return context; }
From source file:com.haulmont.cuba.gui.components.filter.edit.DynamicAttributesConditionFrame.java
@Override public boolean commit() { if (!super.commit()) return false; String error = checkCondition(); if (error != null) { showNotification(messages.getMainMessage(error), Frame.NotificationType.TRAY); return false; }/* w ww . ja v a 2 s . c o m*/ CategoryAttribute attribute = attributeLookup.getValue(); String alias = condition.getEntityAlias(); String cavAlias = "cav" + RandomStringUtils.randomNumeric(5); String paramName; String operation = operationLookup.<Op>getValue().forJpql(); Op op = operationLookup.getValue(); Class javaClass = DynamicAttributesUtils.getAttributeClass(attribute); String propertyPath = Strings.isNullOrEmpty(condition.getPropertyPath()) ? "" : "." + condition.getPropertyPath(); ConditionParamBuilder paramBuilder = AppBeans.get(ConditionParamBuilder.class); paramName = paramBuilder.createParamName(condition); String cavEntityId = referenceToEntitySupport .getReferenceIdPropertyName(condition.getDatasource().getMetaClass()); String where; if (op == Op.NOT_EMPTY) { where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; } else { String valueFieldName = "stringValue"; if (Entity.class.isAssignableFrom(javaClass)) valueFieldName = "entityValue." + referenceToEntitySupport.getReferenceIdPropertyName(metadata.getClassNN(javaClass)); else if (String.class.isAssignableFrom(javaClass)) valueFieldName = "stringValue"; else if (Integer.class.isAssignableFrom(javaClass)) valueFieldName = "intValue"; else if (Double.class.isAssignableFrom(javaClass)) valueFieldName = "doubleValue"; else if (Boolean.class.isAssignableFrom(javaClass)) valueFieldName = "booleanValue"; else if (Date.class.isAssignableFrom(javaClass)) valueFieldName = "dateValue"; if (!attribute.getIsCollection()) { condition.setJoin(", sys$CategoryAttributeValue " + cavAlias + " "); String paramStr = " ? "; where = cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " " + operation + (op.isUnary() ? " " : paramStr) + "and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'"; where = where.replace("?", ":" + paramName); } else { where = "(exists (select " + cavAlias + " from sys$CategoryAttributeValue " + cavAlias + " where " + cavAlias + ".entity." + cavEntityId + "=" + "{E}" + propertyPath + ".id and " + cavAlias + "." + valueFieldName + " = :" + paramName + " and " + cavAlias + ".categoryAttribute.id='" + attributeLookup.<CategoryAttribute>getValue().getId() + "'))"; } } condition.setWhere(where); condition.setUnary(op.isUnary()); condition.setEntityParamView(null); condition.setEntityParamWhere(null); condition.setInExpr(Op.IN.equals(op) || Op.NOT_IN.equals(op)); condition.setOperator(operationLookup.<Op>getValue()); Class paramJavaClass = op.isUnary() ? Boolean.class : javaClass; condition.setJavaClass(javaClass); Param param = Param.Builder.getInstance().setName(paramName).setJavaClass(paramJavaClass) .setDataSource(condition.getDatasource()) .setProperty(DynamicAttributesUtils.getMetaPropertyPath(null, attribute).getMetaProperty()) .setInExpr(condition.getInExpr()).setRequired(condition.getRequired()) .setCategoryAttrId(attribute.getId()).build(); Object defaultValue = condition.getParam().getDefaultValue(); param.setDefaultValue(defaultValue); condition.setParam(param); condition.setCategoryId(categoryLookup.<Category>getValue().getId()); condition.setCategoryAttributeId(attributeLookup.<CategoryAttribute>getValue().getId()); condition.setIsCollection( BooleanUtils.isTrue(attributeLookup.<CategoryAttribute>getValue().getIsCollection())); condition.setLocCaption(attribute.getLocaleName()); condition.setCaption(caption.getValue()); return true; }
From source file:com.evolveum.midpoint.web.component.data.paging.NavigatorPanel.java
private void initLast() { WebMarkupContainer last = new WebMarkupContainer(ID_LAST); last.add(new AttributeModifier("class", new AbstractReadOnlyModel<String>() { @Override/*from w ww .j a v a 2 s. c o m*/ public String getObject() { return isLastEnabled() ? "" : "disabled"; } })); add(last); AjaxLink lastLink = new AjaxLink(ID_LAST_LINK) { @Override public void onClick(AjaxRequestTarget target) { lastPerformed(target); } }; lastLink.add(new VisibleEnableBehaviour() { @Override public boolean isEnabled() { return BooleanUtils.isTrue(showPageListingModel.getObject()) && isLastEnabled(); } }); last.add(lastLink); }
From source file:com.evolveum.midpoint.model.impl.importer.ObjectImporter.java
private void importObjectsInternal(InputStream input, final ImportOptionsType options, final boolean raw, final Task task, final OperationResult parentResult) { EventHandler handler = new EventHandler() { @Override//from ww w. ja va 2 s .c om public EventResult preMarshall(Element objectElement, Node postValidationTree, OperationResult objectResult) { return EventResult.cont(); } @Override public <T extends Objectable> EventResult postMarshall(PrismObject<T> prismObjectObjectable, Element objectElement, OperationResult objectResult) { LOGGER.debug("Importing object {}", prismObjectObjectable); T objectable = prismObjectObjectable.asObjectable(); if (!(objectable instanceof ObjectType)) { String message = "Cannot process type " + objectable.getClass() + " as it is not a subtype of " + ObjectType.class; objectResult.recordFatalError(message); LOGGER.error("Import of object {} failed: {}", new Object[] { prismObjectObjectable, message }); return EventResult.skipObject(message); } PrismObject<? extends ObjectType> object = (PrismObject<? extends ObjectType>) prismObjectObjectable; if (LOGGER.isTraceEnabled()) { LOGGER.trace("IMPORTING object:\n{}", object.debugDump()); } object = migrator.migrate(object); Utils.resolveReferences(object, repository, (options == null || options.isReferentialIntegrity() == null) ? false : options.isReferentialIntegrity(), false, prismContext, objectResult); objectResult.computeStatus(); if (!objectResult.isAcceptable()) { return EventResult.skipObject(objectResult.getMessage()); } generateIdentifiers(object, repository, objectResult); objectResult.computeStatus(); if (!objectResult.isAcceptable()) { return EventResult.skipObject(objectResult.getMessage()); } if (options != null && BooleanUtils.isTrue(options.isValidateDynamicSchema())) { validateWithDynamicSchemas(object, objectElement, repository, objectResult); } objectResult.computeStatus(); if (!objectResult.isAcceptable()) { return EventResult.skipObject(objectResult.getMessage()); } if (options != null && BooleanUtils.isTrue(options.isEncryptProtectedValues())) { OperationResult opResult = objectResult .createMinorSubresult(ObjectImporter.class.getName() + ".encryptValues"); try { CryptoUtil.encryptValues(protector, object); opResult.recordSuccess(); } catch (EncryptionException e) { opResult.recordFatalError(e); } } if (options == null || (options != null && !BooleanUtils.isTrue(options.isKeepMetadata()))) { MetadataType metaData = new MetadataType(); String channel = SchemaConstants.CHANNEL_OBJECT_IMPORT_URI; metaData.setCreateChannel(channel); metaData.setCreateTimestamp(clock.currentTimeXMLGregorianCalendar()); if (task.getOwner() != null) { metaData.setCreatorRef(ObjectTypeUtil.createObjectRef(task.getOwner())); } object.asObjectable().setMetadata(metaData); } objectResult.computeStatus(); if (!objectResult.isAcceptable()) { return EventResult.skipObject(objectResult.getMessage()); } try { importObjectToRepository(object, options, raw, task, objectResult); LOGGER.info("Imported object {}", object); } catch (SchemaException e) { objectResult.recordFatalError("Schema violation: " + e.getMessage(), e); LOGGER.error("Import of object {} failed: Schema violation: {}", new Object[] { object, e.getMessage(), e }); } catch (ObjectAlreadyExistsException e) { objectResult.recordFatalError("Object already exists: " + e.getMessage(), e); LOGGER.error("Import of object {} failed: Object already exists: {}", new Object[] { object, e.getMessage(), e }); LOGGER.error("Object already exists", e); } catch (RuntimeException e) { objectResult.recordFatalError("Unexpected problem: " + e.getMessage(), e); LOGGER.error("Import of object {} failed: Unexpected problem: {}", new Object[] { object, e.getMessage(), e }); } catch (ObjectNotFoundException e) { LOGGER.error("Import of object {} failed: Object referred from this object was not found: {}", new Object[] { object, e.getMessage(), e }); } catch (ExpressionEvaluationException e) { LOGGER.error("Import of object {} failed: Expression evaluation error: {}", new Object[] { object, e.getMessage(), e }); } catch (CommunicationException e) { LOGGER.error("Import of object {} failed: Communication error: {}", new Object[] { object, e.getMessage(), e }); } catch (ConfigurationException e) { LOGGER.error("Import of object {} failed: Configuration error: {}", new Object[] { object, e.getMessage(), e }); } catch (PolicyViolationException e) { LOGGER.error("Import of object {} failed: Policy violation: {}", new Object[] { object, e.getMessage(), e }); } catch (SecurityViolationException e) { LOGGER.error("Import of object {} failed: Security violation: {}", new Object[] { object, e.getMessage(), e }); } objectResult.recordSuccessIfUnknown(); if (objectResult.isAcceptable()) { // Continue import return EventResult.cont(); } else { return EventResult.skipObject(objectResult.getMessage()); } } @Override public void handleGlobalError(OperationResult currentResult) { // No reaction } }; Validator validator = new Validator(prismContext, handler); validator.setVerbose(true); if (options != null) { validator.setValidateSchema(BooleanUtils.isTrue(options.isValidateStaticSchema())); if (options.getStopAfterErrors() != null) { validator.setStopAfterErrors(options.getStopAfterErrors().longValue()); } if (BooleanUtils.isTrue(options.isSummarizeErrors())) { parentResult.setSummarizeErrors(true); } if (BooleanUtils.isTrue(options.isSummarizeSucceses())) { parentResult.setSummarizeSuccesses(true); } } validator.validate(input, parentResult, OperationConstants.IMPORT_OBJECT); }
From source file:gov.nih.nci.cabig.caaers.web.study.StudyCommand.java
@Deprecated public boolean isTherapyTypeSelected(StudyTherapyType therapyType) { switch (therapyType) { case DRUG_ADMINISTRATION: return BooleanUtils.isTrue(drugAdministrationTherapyType); case BEHAVIORAL: return BooleanUtils.isTrue(behavioralTherapyType); case BIOLOGICAL_VACCINE: return BooleanUtils.isTrue(biologicalTherapyType); case DEVICE:/* w w w.j a va 2s . c o m*/ return BooleanUtils.isTrue(deviceTherapyType); case DIETARY_SUPPLEMENT: return BooleanUtils.isTrue(diaterySupplementTherapyType); case GENETIC: return BooleanUtils.isTrue(geneticTherapyType); case OTHER: return BooleanUtils.isTrue(otherTherapyType); case RADIATION: return BooleanUtils.isTrue(radiationTherapyType); case SURGERY: return BooleanUtils.isTrue(surgeryTherapyType); default: return false; } }
From source file:com.haulmont.cuba.gui.app.security.user.edit.UserEditor.java
@Override protected void postInit() { setCaption(PersistenceHelper.isNew(getItem()) ? getMessage("createCaption") : formatMessage("editCaption", getItem().getLogin())); timeZoneLookup.setEnabled(!Boolean.TRUE.equals(getItem().getTimeZoneAuto())); // Do not show roles which are not allowed by security constraints LoadContext<Role> lc = new LoadContext<>(Role.class); lc.setQueryString("select r from sec$Role r"); lc.setView(View.MINIMAL);//from w w w. j a v a2s . c o m List<Role> allowedRoles = dataSupplier.loadList(lc); Collection<UserRole> userRoles = new ArrayList<>(rolesDs.getItems()); for (UserRole userRole : userRoles) { if (!allowedRoles.contains(userRole.getRole())) { rolesDs.excludeItem(userRole); } } if (BooleanUtils.isTrue(initCopy)) { initCopy(); } // if we add default roles, rolesDs becomes modified on setItem ((AbstractDatasource) rolesDs).setModified(false); }
From source file:jp.primecloud.auto.component.windows.process.WindowsComponentProcess.java
private void doConfigureInstance(Long componentNo, ComponentProcessContext context, boolean start, Long instanceNo, Map<String, Object> rootMap) { Component component = componentDao.read(componentNo); Instance instance = instanceDao.read(instanceNo); // ?// w w w . ja v a 2s . c om LoggingUtils.setInstanceNo(instanceNo); LoggingUtils.setInstanceName(instance.getInstanceName()); LoggingUtils.setInstanceType(processLogger.getInstanceType(instanceNo)); LoggingUtils.setPlatformNo(instance.getPlatformNo()); if (log.isInfoEnabled()) { String code = start ? "IPROCESS-100221" : "IPROCESS-100223"; log.info(MessageUtils.getMessage(code, componentNo, instanceNo, component.getComponentName(), instance.getInstanceName())); } try { configureInstance(componentNo, context, start, instanceNo, rootMap); } catch (RuntimeException e) { if (start) { ComponentInstance componentInstance = componentInstanceDao.read(componentNo, instanceNo); ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); // if (BooleanUtils.isTrue(componentInstance.getConfigure())) { if (status == ComponentInstanceStatus.STARTING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStartFail", null); } else if (status == ComponentInstanceStatus.CONFIGURING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentReloadFail", null); } else if (status == ComponentInstanceStatus.STOPPING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStopFail", null); } } // if (status != ComponentInstanceStatus.WARNING || BooleanUtils.isTrue(componentInstance.getConfigure())) { componentInstance.setStatus(ComponentInstanceStatus.WARNING.toString()); componentInstance.setConfigure(false); componentInstanceDao.update(componentInstance); } throw e; } else { // ??????? log.warn(e.getMessage()); } } ComponentInstance componentInstance = componentInstanceDao.read(componentNo, instanceNo); ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); // if (BooleanUtils.isTrue(componentInstance.getConfigure())) { if (status == ComponentInstanceStatus.STARTING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStartFinish", null); } else if (status == ComponentInstanceStatus.CONFIGURING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentReloadFinish", null); } else if (status == ComponentInstanceStatus.STOPPING) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, component, instance, "ComponentStopFinish", null); } } // if (start) { if (status == ComponentInstanceStatus.CONFIGURING || status == ComponentInstanceStatus.STARTING || BooleanUtils.isTrue(componentInstance.getConfigure())) { componentInstance.setStatus(ComponentInstanceStatus.RUNNING.toString()); componentInstance.setConfigure(false); componentInstanceDao.update(componentInstance); } } else { if (status == ComponentInstanceStatus.STOPPING || BooleanUtils.isTrue(componentInstance.getConfigure())) { componentInstance.setStatus(ComponentInstanceStatus.STOPPED.toString()); componentInstance.setConfigure(false); componentInstanceDao.update(componentInstance); } } if (!start) { // ????? deleteAssociate(componentNo, instanceNo); } if (log.isInfoEnabled()) { String code = start ? "IPROCESS-100222" : "IPROCESS-100224"; log.info(MessageUtils.getMessage(code, componentNo, instanceNo, component.getComponentName(), instance.getInstanceName())); } }
From source file:com.haulmont.cuba.gui.components.filter.edit.FilterEditor.java
@Override public void init(Map<String, Object> params) { super.init(params); if (Boolean.TRUE.equals(useShortConditionForm)) { setCaption(messages.getMainMessage("filter.editor.captionShortForm")); }/*from w w w . ja va2 s .co m*/ getDialogOptions().setWidth(theme.get("cuba.gui.filterEditor.dialog.width")) .setHeight(theme.get("cuba.gui.filterEditor.dialog.height")).setResizable(true); filterEntity = (FilterEntity) params.get("filterEntity"); if (filterEntity == null) { throw new RuntimeException("Filter entity was not passed to filter editor"); } filter = (Filter) params.get("filter"); ConditionsTree paramConditions = (ConditionsTree) params.get("conditions"); conditions = paramConditions.createCopy(); refreshConditionsDs(); conditionsTree.expandTree(); if (!messages.getMainMessage("filter.adHocFilter").equals(filterEntity.getName())) { filterName.setValue(filterEntity.getName()); } availableForAllCb.setValue(filterEntity.getUser() == null); defaultCb.setValue(filterEntity.getIsDefault()); applyDefaultCb.setValue(filterEntity.getApplyDefault()); globalDefaultCb.setValue(filterEntity.getGlobalDefault()); if (filterEntity.getUser() != null) { globalDefaultCb.setEnabled(false); } if (!userSessionSource.getUserSession().isSpecificPermitted(GLOBAL_FILTER_PERMISSION)) { availableForAllCb.setVisible(false); availableForAllLabel.setVisible(false); globalDefaultCb.setVisible(false); globalDefaultLabel.setVisible(false); } availableForAllCb.addValueChangeListener(e -> { Boolean isFilterAvailableForAll = (Boolean) e.getValue(); globalDefaultCb.setEnabled(isFilterAvailableForAll); if (!isFilterAvailableForAll) { globalDefaultCb.setValue(null); } }); Configuration configuration = AppBeans.get(Configuration.NAME); boolean manualApplyRequired = filter.getManualApplyRequired() != null ? filter.getManualApplyRequired() : configuration.getConfig(ClientConfig.class).getGenericFilterManualApplyRequired(); if (!manualApplyRequired) { applyDefaultCb.setVisible(manualApplyRequired); applyDefaultLabel.setVisible(manualApplyRequired); } if (filterEntity.getFolder() != null) { defaultCb.setVisible(false); defaultLabel.setVisible(false); } conditionsDs.addItemChangeListener(e -> { if (!treeItemChangeListenerEnabled) { return; } //commit previously selected condition if (activeConditionFrame != null) { List<Validatable> validatables = new ArrayList<>(); Collection<Component> frameComponents = ComponentsHelper.getComponents(activeConditionFrame); for (Component frameComponent : frameComponents) { if (frameComponent instanceof Validatable) { validatables.add((Validatable) frameComponent); } } if (validate(validatables)) { activeConditionFrame.commit(); } else { treeItemChangeListenerEnabled = false; conditionsTree.setSelected(e.getPrevItem()); treeItemChangeListenerEnabled = true; return; } } if (e.getItem() == null) { activeConditionFrame = null; } else { if (e.getItem() instanceof PropertyCondition) { activeConditionFrame = propertyConditionFrame; } else if (e.getItem() instanceof DynamicAttributesCondition) { activeConditionFrame = dynamicAttributesConditionFrame; } else if (e.getItem() instanceof CustomCondition) { activeConditionFrame = customConditionFrame; } else if (e.getItem() instanceof GroupCondition) { activeConditionFrame = groupConditionFrame; } else if (e.getItem() instanceof FtsCondition) { activeConditionFrame = ftsConditionFrame; } else { log.warn("Conditions frame for condition with type " + e.getItem().getClass().getSimpleName() + " not found"); } } propertyConditionFrame.setVisible(false); customConditionFrame.setVisible(false); dynamicAttributesConditionFrame.setVisible(false); groupConditionFrame.setVisible(false); ftsConditionFrame.setVisible(false); if (activeConditionFrame != null) { activeConditionFrame.setVisible(true); activeConditionFrame.setCondition(e.getItem()); if (Boolean.TRUE.equals(useShortConditionForm)) { for (String componentName : componentsToHideInShortForm) { Component component = activeConditionFrame.getComponent(componentName); if (component != null) { if (BooleanUtils.isTrue(showConditionHiddenOption) && componentsForHiddenOption.contains(componentName)) { continue; } component.setVisible(false); } } } } }); addConditionHelper = new AddConditionHelper(filter, BooleanUtils.isTrue(hideDynamicAttributes), BooleanUtils.isTrue(hideCustomConditions), condition -> { AbstractCondition item = conditionsDs.getItem(); if (item != null && item instanceof GroupCondition) { Node<AbstractCondition> newNode = new Node<>(condition); Node<AbstractCondition> selectedNode = conditions.getNode(item); selectedNode.addChild(newNode); refreshConditionsDs(); conditionsTree.expand(item.getId()); } else { conditions.getRootNodes().add(new Node<>(condition)); refreshConditionsDs(); } conditionsTree.setSelected(condition); }); FilterHelper filterHelper = AppBeans.get(FilterHelper.class); filterHelper.initConditionsDragAndDrop(conditionsTree, conditions); if (Boolean.TRUE.equals(useShortConditionForm)) { filterPropertiesGrid.setVisible(false); } }
From source file:jp.primecloud.auto.process.ProcessManager.java
protected boolean processConfigureComponent(final Farm farm) { // ??????//from w w w . ja v a2s .c om if (BooleanUtils.isTrue(farm.getComponentProcessing())) { return false; } boolean configured = true; // ?Instance?ComponentInstnace?? List<Instance> instances = instanceDao.readByFarmNo(farm.getFarmNo()); List<Long> instanceNos = new ArrayList<Long>(); for (Instance instance : instances) { // ?? if (BooleanUtils.isTrue(instance.getLoadBalancer())) { continue; } if (InstanceStatus.fromStatus(instance.getStatus()) == InstanceStatus.RUNNING) { instanceNos.add(instance.getInstanceNo()); } } List<ComponentInstance> componentInstances = componentInstanceDao.readInInstanceNos(instanceNos); // ComponentInstance???????? for (ComponentInstance componentInstance : componentInstances) { ComponentInstanceStatus status = ComponentInstanceStatus.fromStatus(componentInstance.getStatus()); if (BooleanUtils.isTrue(componentInstance.getEnabled())) { if (status == ComponentInstanceStatus.WARNING) { // ????????? unscheduled(farm.getFarmNo()); return false; } else if (status != ComponentInstanceStatus.RUNNING) { configured = false; } } else { if (status != ComponentInstanceStatus.STOPPED) { configured = false; } } } // ??? List<LoadBalancer> loadBalancers = null; List<LoadBalancerListener> listeners = null; List<LoadBalancerInstance> lbInstances = null; Map<Long, LoadBalancer> loadBalancerMap = null; Map<Long, Instance> instanceMap = null; if (configured) { loadBalancers = loadBalancerDao.readByFarmNo(farm.getFarmNo()); loadBalancerMap = new HashMap<Long, LoadBalancer>(); for (LoadBalancer loadBalancer : loadBalancers) { loadBalancerMap.put(loadBalancer.getLoadBalancerNo(), loadBalancer); } listeners = loadBalancerListenerDao.readInLoadBalancerNos(loadBalancerMap.keySet()); lbInstances = loadBalancerInstanceDao.readInLoadBalancerNos(loadBalancerMap.keySet()); instanceMap = new HashMap<Long, Instance>(); for (Instance instance : instances) { instanceMap.put(instance.getInstanceNo(), instance); } } // ???????? if (configured) { for (LoadBalancerListener listener : listeners) { LoadBalancer loadBalancer = loadBalancerMap.get(listener.getLoadBalancerNo()); LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); LoadBalancerListenerStatus status2 = LoadBalancerListenerStatus.fromStatus(listener.getStatus()); if (BooleanUtils.isTrue(loadBalancer.getEnabled())) { if (status == LoadBalancerStatus.RUNNING) { // ????? if (BooleanUtils.isTrue(listener.getEnabled())) { if (status2 == LoadBalancerListenerStatus.WARNING) { // ??????? unscheduled(farm.getFarmNo()); return false; } else if (status2 != LoadBalancerListenerStatus.RUNNING) { configured = false; } } else { if (status2 != LoadBalancerListenerStatus.STOPPED) { configured = false; } } } } else { if (status == LoadBalancerStatus.RUNNING || status == LoadBalancerStatus.WARNING) { // ???????? if (status2 != LoadBalancerListenerStatus.STOPPED) { configured = false; } } } } } // ???????? if (configured) { for (LoadBalancerInstance lbInstance : lbInstances) { LoadBalancer loadBalancer = loadBalancerMap.get(lbInstance.getLoadBalancerNo()); LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); LoadBalancerInstanceStatus status2 = LoadBalancerInstanceStatus.fromStatus(lbInstance.getStatus()); Instance instance = instanceMap.get(lbInstance.getInstanceNo()); InstanceStatus instanceStatus = InstanceStatus.fromStatus(instance.getStatus()); // ??????? if (instanceStatus == InstanceStatus.RUNNING) { if (BooleanUtils.isTrue(loadBalancer.getEnabled()) && BooleanUtils.isTrue(instance.getEnabled())) { if (status == LoadBalancerStatus.RUNNING) { // ????????? if (BooleanUtils.isTrue(lbInstance.getEnabled())) { if (status2 == LoadBalancerInstanceStatus.WARNING) { // ???????? unscheduled(farm.getFarmNo()); return false; } else if (status2 != LoadBalancerInstanceStatus.RUNNING) { configured = false; } } else { if (status2 != LoadBalancerInstanceStatus.STOPPED) { configured = false; } } } } else { if (status == LoadBalancerStatus.RUNNING || status == LoadBalancerStatus.WARNING) { // ?????????????? if (status2 != LoadBalancerInstanceStatus.STOPPED) { configured = false; } } } } } } // ????????? if (configured) { for (ComponentInstance componentInstance : componentInstances) { if (BooleanUtils.isTrue(componentInstance.getConfigure())) { configured = false; break; } } } // ???????? if (configured) { for (LoadBalancer loadBalancer : loadBalancers) { if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); if (BooleanUtils.isTrue(loadBalancer.getEnabled())) { if (status == LoadBalancerStatus.RUNNING) { configured = false; break; } } else { if (status == LoadBalancerStatus.RUNNING || status == LoadBalancerStatus.WARNING) { configured = false; break; } } } } } // ???????? if (configured) { for (LoadBalancerListener listener : listeners) { if (BooleanUtils.isTrue(listener.getConfigure())) { LoadBalancer loadBalancer = loadBalancerMap.get(listener.getLoadBalancerNo()); LoadBalancerStatus status = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); if (BooleanUtils.isTrue(loadBalancer.getEnabled())) { if (status == LoadBalancerStatus.RUNNING) { configured = false; break; } } else { if (status == LoadBalancerStatus.RUNNING || status == LoadBalancerStatus.WARNING) { configured = false; break; } } } } } // ?????????? if (!configured) { final User user = userDao.read(farm.getUserNo()); 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 { componentProcess.configure(farm.getFarmNo()); } catch (MultiCauseException ignore) { } catch (Throwable e) { log.error(e.getMessage(), e); // eventLogger.error("SystemError", new Object[] { e.getMessage() }); } finally { LoggingUtils.removeContext(); } } }; executorService.execute(runnable); } return configured; }
From source file:jp.primecloud.auto.process.lb.LoadBalancerProcess.java
public void configure(Long loadBalancerNo) { LoadBalancer loadBalancer = loadBalancerDao.read(loadBalancerNo); if (loadBalancer == null) { // ?????/*from www .j a v a 2 s . c om*/ throw new AutoException("EPROCESS-000010", loadBalancerNo); } if (log.isInfoEnabled()) { log.info( MessageUtils.getMessage("IPROCESS-200011", loadBalancerNo, loadBalancer.getLoadBalancerName())); } LoadBalancerStatus initStatus = LoadBalancerStatus.fromStatus(loadBalancer.getStatus()); // ? if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { loadBalancer.setStatus(LoadBalancerStatus.CONFIGURING.toString()); loadBalancerDao.update(loadBalancer); } // if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, null, null, "LoadBalancerConfig", new Object[] { loadBalancer.getLoadBalancerName() }); } try { // ?? configureLoadBalancer(loadBalancer); } catch (RuntimeException e) { // if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, null, null, "LoadBalancerConfigFail", new Object[] { loadBalancer.getLoadBalancerName() }); } // ? if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { loadBalancer = loadBalancerDao.read(loadBalancerNo); loadBalancer.setStatus(initStatus.toString()); loadBalancer.setConfigure(false); loadBalancerDao.update(loadBalancer); } // ????? if (BooleanUtils.isNotTrue(loadBalancer.getEnabled())) { log.warn(e.getMessage()); return; } throw e; } // if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { processLogger.writeLogSupport(ProcessLogger.LOG_INFO, null, null, "LoadBalancerConfigFinish", new Object[] { loadBalancer.getLoadBalancerName() }); } // ? if (BooleanUtils.isTrue(loadBalancer.getConfigure())) { loadBalancer = loadBalancerDao.read(loadBalancerNo); loadBalancer.setStatus(initStatus.toString()); loadBalancer.setConfigure(false); loadBalancerDao.update(loadBalancer); } if (log.isInfoEnabled()) { log.info( MessageUtils.getMessage("IPROCESS-200012", loadBalancerNo, loadBalancer.getLoadBalancerName())); } }