simple cleaned up illustration of service_up from not_up computation
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/843f1fca Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/843f1fca Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/843f1fca Branch: refs/heads/master Commit: 843f1fcaa28331e5b3e9b3325899366d0588601f Parents: 41deca4 Author: Alex Heneveld <[email protected]> Authored: Wed Aug 6 23:47:59 2014 -0400 Committer: Alex Heneveld <[email protected]> Committed: Wed Aug 27 02:07:49 2014 -0400 ---------------------------------------------------------------------- .../entity/basic/ServiceStatusLogic.java | 73 ++++++++++++++++++++ .../entity/basic/SoftwareProcessImpl.java | 13 ++-- .../entity/webapp/jboss/JBoss7ServerImpl.java | 16 +++-- 3 files changed, 89 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/843f1fca/core/src/main/java/brooklyn/entity/basic/ServiceStatusLogic.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/basic/ServiceStatusLogic.java b/core/src/main/java/brooklyn/entity/basic/ServiceStatusLogic.java new file mode 100644 index 0000000..056334c --- /dev/null +++ b/core/src/main/java/brooklyn/entity/basic/ServiceStatusLogic.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.entity.basic; + +import java.util.Map; + +import brooklyn.enricher.Enrichers; +import brooklyn.event.AttributeSensor; +import brooklyn.policy.EnricherSpec; +import brooklyn.util.collections.CollectionFunctionals; +import brooklyn.util.collections.MutableMap; + +import com.google.common.base.Functions; + +/** Logic, sensors and enrichers, and conveniences, for computing service status */ +public class ServiceStatusLogic { + + public static final AttributeSensor<Boolean> SERVICE_UP = Attributes.SERVICE_UP; + public static final AttributeSensor<Map<String,Object>> SERVICE_NOT_UP_INDICATORS = Attributes.SERVICE_NOT_UP_INDICATORS; + + public static final EnricherSpec<?> newEnricherForServiceUpIfNoNotUpIndicators() { + return Enrichers.builder() + .transforming(SERVICE_NOT_UP_INDICATORS).publishing(Attributes.SERVICE_UP) + .computing( Functions.forPredicate(CollectionFunctionals.<String>mapSizeEquals(0)) ) + .uniqueTag("service.isUp if no service.notUp.indicators") + .build(); + } + + @SuppressWarnings("unchecked") + public static <TKey,TVal> void updateMapSensor(EntityLocal entity, AttributeSensor<Map<TKey,TVal>> sensor, + TKey key, Object v) { + Map<TKey, TVal> map = entity.getAttribute(sensor); + + // TODO synchronize + + boolean created = (map==null); + if (created) map = MutableMap.of(); + + boolean changed; + if (v == Entities.REMOVE) { + changed = map.containsKey(key); + if (changed) + map.remove(key); + } else { + TVal oldV = map.get(key); + if (oldV==null) + changed = (v!=null || !map.containsKey(key)); + else + changed = !oldV.equals(v); + if (changed) + map.put(key, (TVal)v); + } + if (changed || created) + entity.setAttribute(sensor, map); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/843f1fca/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java index 56bb319..e376bee 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java +++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java @@ -46,7 +46,6 @@ import brooklyn.location.basic.LocationConfigKeys; import brooklyn.location.basic.Machines; import brooklyn.location.cloud.CloudLocationConfig; import brooklyn.management.Task; -import brooklyn.util.collections.CollectionFunctionals; import brooklyn.util.collections.MutableMap; import brooklyn.util.collections.MutableSet; import brooklyn.util.config.ConfigBag; @@ -153,7 +152,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft protected void connectServiceUpIsRunning() { serviceProcessIsRunning = FunctionFeed.builder() .entity(this) - .period(5000) + .period(Duration.FIVE_SECONDS) .poll(new FunctionPollConfig<Boolean, Boolean>(SERVICE_PROCESS_IS_RUNNING) .onException(Functions.constant(Boolean.FALSE)) .callable(new Callable<Boolean>() { @@ -165,12 +164,11 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft addEnricher(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) .from(SERVICE_PROCESS_IS_RUNNING) - .computing(Functionals.when(false).value("Process not running (according to driver checkRunning)")) + .computing(Functionals.when(false).value("Process not running (according to driver checkRunning)") + .when((Boolean)null).value("Process not running (no data for "+SERVICE_PROCESS_IS_RUNNING.getName()+")") ) .build()); - - // FIXME lives elsewhere - addEnricher(Enrichers.builder().transforming(Attributes.SERVICE_NOT_UP_INDICATORS).publishing(Attributes.SERVICE_UP) - .computing( Functions.forPredicate(CollectionFunctionals.<String>mapSizeEquals(0)) ).build()); + + addEnricher(ServiceStatusLogic.newEnricherForServiceUpIfNoNotUpIndicators()); } /** @@ -182,6 +180,7 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft */ protected void disconnectServiceUpIsRunning() { if (serviceProcessIsRunning != null) serviceProcessIsRunning.stop(); + ServiceStatusLogic.updateMapSensor(this, Attributes.SERVICE_NOT_UP_INDICATORS, SERVICE_PROCESS_IS_RUNNING.getName(), "Disabled checking whether service process is running"); } /** http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/843f1fca/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java ---------------------------------------------------------------------- diff --git a/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java b/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java index 2cb1303..05421d0 100644 --- a/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java +++ b/software/webapp/src/main/java/brooklyn/entity/webapp/jboss/JBoss7ServerImpl.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import brooklyn.enricher.Enrichers; import brooklyn.entity.Entity; +import brooklyn.entity.basic.Attributes; import brooklyn.entity.webapp.HttpsSslConfig; import brooklyn.entity.webapp.JavaWebAppSoftwareProcessImpl; import brooklyn.entity.webapp.WebAppServiceMethods; @@ -33,8 +34,10 @@ import brooklyn.event.feed.http.HttpPollConfig; import brooklyn.event.feed.http.HttpValueFunctions; import brooklyn.location.access.BrooklynAccessUtils; import brooklyn.policy.Enricher; +import brooklyn.util.guava.Functionals; import com.google.common.base.Functions; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMap; import com.google.common.net.HostAndPort; @@ -43,7 +46,6 @@ public class JBoss7ServerImpl extends JavaWebAppSoftwareProcessImpl implements J public static final Logger log = LoggerFactory.getLogger(JBoss7ServerImpl.class); private volatile HttpFeed httpFeed; - private Enricher serviceUpEnricher; public JBoss7ServerImpl(){ super(); @@ -114,14 +116,16 @@ public class JBoss7ServerImpl extends JavaWebAppSoftwareProcessImpl implements J } protected void connectServiceUp() { - serviceUpEnricher = addEnricher(Enrichers.builder() - .propagating(ImmutableMap.of(MANAGEMENT_URL_UP, SERVICE_UP)) - .from(this) - .build()); + connectServiceUpIsRunning(); + + addEnricher(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) + .from(MANAGEMENT_URL_UP) + .computing(Functionals.when(Predicates.not(Predicates.equalTo(true))).value("Management URL not reachable") ) + .build()); } protected void disconnectServiceUp() { - if (serviceUpEnricher != null) removeEnricher(serviceUpEnricher); + disconnectServiceUpIsRunning(); } @Override
