Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9C80C17F9A for ; Mon, 27 Oct 2014 20:21:35 +0000 (UTC) Received: (qmail 69342 invoked by uid 500); 27 Oct 2014 20:21:35 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 69308 invoked by uid 500); 27 Oct 2014 20:21:35 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 69294 invoked by uid 99); 27 Oct 2014 20:21:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Oct 2014 20:21:34 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 27 Oct 2014 20:21:12 +0000 Received: (qmail 68712 invoked by uid 99); 27 Oct 2014 20:21:10 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Oct 2014 20:21:10 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 32D7298423D; Mon, 27 Oct 2014 20:21:09 +0000 (UTC) From: sjcorbett To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: DNS entity improvements Content-Type: text/plain Message-Id: <20141027202109.32D7298423D@tyr.zones.apache.org> Date: Mon, 27 Oct 2014 20:21:09 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user sjcorbett commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/263#discussion_r19434229 --- Diff: software/network/src/main/java/brooklyn/entity/network/bind/BindDnsServerImpl.java --- @@ -143,124 +167,133 @@ protected void preStart() { String reverseLookupDomain = Joiner.on('.').join(Iterables.skip(Lists.reverse(Lists.newArrayList(Splitter.on('.').split(reverse))), 1)) + ".in-addr.arpa"; setAttribute(REVERSE_LOOKUP_DOMAIN, reverseLookupDomain); - Map flags = MutableMap.builder() - .build(); - policy = addPolicy(PolicySpec.create(MemberTrackingPolicy.class) + addPolicy(PolicySpec.create(MemberTrackingPolicy.class) .displayName("Address tracker") .configure("sensorsToTrack", ImmutableSet.of(getConfig(HOSTNAME_SENSOR))) - .configure("group", entities)); + .configure("group", getEntities())); + } - // For any entities that have already come up - for (Entity member : entities.getMembers()) { - if (Strings.isNonBlank(member.getAttribute(getConfig(HOSTNAME_SENSOR)))) added(member); // Ignore, unless hostname set - } + @Override + public void postStart() { + update(); } public static class MemberTrackingPolicy extends AbstractMembershipTrackingPolicy { @Override protected void onEntityChange(Entity member) { - // TODO Should we guard to only call if service_up and if hostname set? - ((BindDnsServerImpl)entity).added(member); + if (LOG.isTraceEnabled()) { + LOG.trace("State of {} on change: {}", member, member.getAttribute(Attributes.SERVICE_STATE_ACTUAL).name()); + } + ((BindDnsServerImpl) entity).update(); } @Override protected void onEntityAdded(Entity member) { - if (Strings.isNonBlank(member.getAttribute(getConfig(HOSTNAME_SENSOR)))) { - ((BindDnsServerImpl)entity).added(member); // Ignore, unless hostname set + if (LOG.isTraceEnabled()) { + LOG.trace("State of {} on added: {}", member, member.getAttribute(Attributes.SERVICE_STATE_ACTUAL).name()); } - } - @Override - protected void onEntityRemoved(Entity member) { - ((BindDnsServerImpl)entity).removed(member); + ((BindDnsServerImpl) entity).configureResolver(member); } } - @Override - public void postStart() { - update(); + private class HasHostnameAndValidLifecycle implements Predicate { + @Override + public boolean apply(Entity input) { + switch (input.getAttribute(Attributes.SERVICE_STATE_ACTUAL)) { + case STOPPED: + case STOPPING: + case DESTROYED: + return false; + } + return input.getAttribute(getConfig(HOSTNAME_SENSOR)) != null; + } } - public void added(Entity member) { - synchronized (mutex) { - Optional location = Iterables.tryFind(member.getLocations(), Predicates.instanceOf(SshMachineLocation.class)); - String hostname = member.getAttribute(getConfig(HOSTNAME_SENSOR)); - if (location.isPresent() && Strings.isNonBlank(hostname)) { - SshMachineLocation machine = (SshMachineLocation) location.get(); - String address = machine.getAddress().getHostAddress(); - if (!entityLocations.containsKey(machine)) { - entityLocations.put(machine, member); - addressMappings.putIfAbsent(address, hostname); + public void update() { + Lifecycle serverState = getAttribute(Attributes.SERVICE_STATE_ACTUAL); + if (Lifecycle.STOPPED.equals(serverState) || Lifecycle.STOPPING.equals(serverState) + || Lifecycle.DESTROYED.equals(serverState) || !getAttribute(Attributes.SERVICE_UP)) { + LOG.debug("Skipped update of {} when service state is {} and running is {}", + new Object[]{this, getAttribute(Attributes.SERVICE_STATE_ACTUAL), getAttribute(SERVICE_UP)}); + return; + } + synchronized (this) { --- End diff -- Why do you think it is better to synchronise on an explicit Object? I'm not really comfortable enough with Brooklyn's concurrency model to know for sure that `update` won't be called concurrently. If `MemberTrackingPolicy.onEntityChange` is guaranteed to be called synchronously then we should be able to drop the `synchronized` statement. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---