You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by ahgittin <gi...@git.apache.org> on 2014/10/25 01:36:13 UTC
[GitHub] incubator-brooklyn pull request: [WIP] Brooklyn node and cluster u...
GitHub user ahgittin opened a pull request:
https://github.com/apache/incubator-brooklyn/pull/272
[WIP] Brooklyn node and cluster upgrade
Merges #266 (cluster upgrade) with work I've been doing on node upgrade.
Builds on #260 so please ensure that is merged first.
Needs further testing (by me at this point) but wanted to push it in case @neykov you have comments, especially on the last commit.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/incubator-brooklyn brooklyn-node-upgrade
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-brooklyn/pull/272.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #272
----
commit 7d280e091e49c5765f1a93a41ea8a8458bc2ced9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T01:45:01Z
allow parameters for restart effector, including children and the machine for SoftwareProcess.restart;
if this model is sensible we might apply it more widely to effectors, to allow parameters to tune behaviour.
(eg for stop, to allow controlling whether it is the machine or just the process which is stopped,
and on start, to allow forcing reinstall)
commit 1fd9b160153fee26d2755336917180ab80c2f28b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T13:56:46Z
fix error where collapsed text would leave out interesting messages included with the propagation, with tests
commit 4b6f331d705cc890fbc30d8487b537e0a722e4dc
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T13:57:03Z
fix failures introduced by dynamic/parametrized RESTART effector; main items are:
* factory not calling init (deprecate EntityFactory);
* do{Start,Stop,Restart} methods not getting invoked (deprecated, replaced by pre- and post- start overrides)
commit 83dd703a566018d92fe93d9c43ce7626b3256095
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T21:24:02Z
propagate entitlements as tasks are submitted, to fix failing AcmeEntitlementManagerTest
commit cc5ac565051ab4a3673cbaa8124810f27b2b6574
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T21:51:28Z
add missing @EffectorParam for policy test; also tweak the test so build completes a bit faster
commit 0918608c829c398cd9aa5cabfa0612b4af44866d
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date: 2014-10-22T08:51:19Z
BrooklynNode cluster + upgrade effector
Also effectors to:
* select master in the cluster
* set HA priority
* set HA state
commit 02d72aa11c9e58bc409e1f65e94e758d412f59a8
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T01:45:01Z
allow parameters for restart effector, including children and the machine for SoftwareProcess.restart;
if this model is sensible we might apply it more widely to effectors, to allow parameters to tune behaviour.
(eg for stop, to allow controlling whether it is the machine or just the process which is stopped,
and on start, to allow forcing reinstall)
commit fb968577af6237725060cb7464681704281c3071
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T13:56:46Z
fix error where collapsed text would leave out interesting messages included with the propagation, with tests
commit 12491c26261cc97ffbd57068ad93925fa27b8056
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T13:57:03Z
fix failures introduced by dynamic/parametrized RESTART effector; main items are:
* factory not calling init (deprecate EntityFactory);
* do{Start,Stop,Restart} methods not getting invoked (deprecated, replaced by pre- and post- start overrides)
commit ee862fa7937c0ffc42cbace3c9e9d8d7140dae8b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T21:24:02Z
propagate entitlements as tasks are submitted, to fix failing AcmeEntitlementManagerTest
commit 008b6945155bde323f10fac3f78ac5a0a6b135bb
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T21:51:28Z
add missing @EffectorParam for policy test; also tweak the test so build completes a bit faster
commit 4ca1c327263d8454785930701c41715492392bbb
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-20T13:51:17Z
clean up of anonymous internal classes, and some minor extensions to predicates available on Entity and String
commit 54b7949998abcebb54c13f1c23f4acbf2923967b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T18:12:09Z
add an upgrade effector for the BrooklynNode, and a sample yaml, and improve lifecycle so that stop_* methods destroy the VM and set a STOPPING state
commit 912d348e2a98653f964db0be32f86bee28ac3dcc
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-18T00:44:32Z
WIP brooklyn HA and upgrade
commit 58d3c68ff8d4dc49e925974c4d1add4f399d59ee
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-23T07:38:55Z
minor cleanups to software, allowing start with no locations, and including stdin for driver.execute commands
commit 74a49e59d808c857278ba5a1f16e24f5e354cc2d
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T12:18:47Z
This closes #266
commit 05ca2e0d42cefce5714b3e94e8fb75094ed894a4
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T12:19:04Z
Merge branch 'restart-parameters' into misc5
commit f8b1bc36b8634ebad55fa7f3cda5c80463cec0e2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T12:21:35Z
Merge alex's brooklyn node upgrade WIP into svet's cluster upgrade PR
commit 2b6ef76b4a105e76195e1478c2a113ddd551445e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:51:36Z
fix bug where tasks (eg pollers) are not stopped on unmanagement if the task which started the tasks is the same one which is unmanaging the entity
commit c9554ba10f7bc31dee347da033f612ca30d68b7c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:52:37Z
add support for extra CLI parameters to BrooklynNode, use those to run in persistence mode, and final fixes to the in-place upgrade effector
commit fc1a8c40706c1f20dd7e9dd489d8a2398cd49b51
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T23:32:24Z
bunch of clean ups - mainly addressing @aledsage's comments on @neykov's cluster upgrade PR, plus misc things i've noticed.
needs further testing though.
----
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19522974
--- Diff: core/src/main/java/brooklyn/util/task/Tasks.java ---
@@ -421,5 +423,38 @@ public static boolean isInterrupted() {
if (t==null) return false;
return t.isCancelled();
}
+
+ private static class WaitForRepeaterCallable implements Callable<Boolean> {
+ protected Repeater repeater;
+ protected boolean requireTrue;
+
+ public WaitForRepeaterCallable(Repeater repeater, boolean requireTrue) {
+ this.repeater = repeater;
+ this.requireTrue = requireTrue;
+ }
+
+ @Override
+ public Boolean call() {
+ ReferenceWithError<Boolean> result = repeater.runKeepingError();
+ if (Boolean.TRUE.equals(result.getWithoutError()))
+ return true;
+ if (result.hasError())
+ throw Exceptions.propagate(result.getError());
--- End diff --
If it's across thread boundaries or even in the same thread but far away then I think I agree with you. But here the `throw` is just a few lines after the method call which originally threw and caught the exception.
What would be the right solution? Some sort of `Exceptions.propagateFromExecution(exception)` which you invoke if not in the original thread context and which throws an `ExecutionException` (and does not interrupt the current thread)?
Since this is all same thread can we keep this code and in another PR address the places where we blithely do `Exceptions.propagate` across thread boundaries?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19421675
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
--- End diff --
declare `final`, because one can.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60558656
ready for review /cc @neykov
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61269906
rebased to resolve merge conflicts (addition of `validate()` calls in `DependentConfiguration` which was easy to slot in, and suppression of env vars in `AbstractSshSoftwareProcessDriver` which was already done here by virtue of calling `SshEffectorTasks` instead)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19601078
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,207 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private final AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> origMemberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(origMemberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+origMemberSpec+" / "+origMemberSpec.getConfig());
+
+ boolean success = false;
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+
+ EntitySpec<?> newMemberSpec = EntitySpec.create(origMemberSpec);
+
+ ConfigBag newConfig = ConfigBag.newInstance();
+ newConfig.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ newConfig.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+ newConfig.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+ newMemberSpec.configure(newConfig.getAllConfigAsConfigKeyMap());
--- End diff --
Longer term (not for this PR)...
Feels like it should be unnecessary to create a `ConfigBag` just to set config on the `newMemberSpec`. Particularly because we then unpack the ConfigBag again to call the actual `.configure()` method. Perhaps we should have more `.configure()` method variants, including `.configureIfNotNull(...)`?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19425754
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
+ //if the new master will be what we expect.
+ if (oldMaster != null) {
+ setNodeState(oldMaster, HighAvailabilityMode.HOT_STANDBY);
+ }
+
+ waitMasterHandover(oldMaster, newMaster);
+ } finally {
+ //3. Revert the priority of the node once it has become master
+ setNodePriority(newMaster, HA_STANDBY_PRIORITY);
+ }
+
+ checkMasterSelected(newMaster);
+ }
+
+ private void waitMasterHandover(final Entity oldMaster, final Entity newMaster) {
+ boolean masterChanged = Repeater.create()
+ .backoff(Duration.millis(500), 1.2, Duration.FIVE_SECONDS)
--- End diff --
5 seconds doesn't seem long to wait. I'd go for at least 30 seconds before failing.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19409664
--- Diff: utils/common/src/main/java/brooklyn/util/collections/QuorumCheck.java ---
@@ -0,0 +1,106 @@
+/*
+ * 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.util.collections;
+
+import java.io.Serializable;
+
+/**
+ * For checking if a group/cluster is quorate. That is, whether the group has sufficient
+ * healthy members.
+ */
+public interface QuorumCheck {
--- End diff --
The package `brooklyn.util.collections` feels like the wrong place for `QuorumCheck`. However, I can see it can be applied to arbitrary collections of things.
What was the reason for moving it from brooklyn-core to brooklyn-utils-common? Was it just because it's generic, or because we wanted to use it from somewhere else?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19462694
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
+ }
+ }).build());
+
+ entity().getConfigMap().addToLocalBag(parameters.getAllConfig());
+
+ // 6 start this entity, running the new version
+ DynamicTasks.queue(Effectors.invocation(entity(), BrooklynNode.START, ConfigBag.EMPTY));
+
+ DynamicTasks.waitForLast();
+ Entities.unmanage(dryRunChild);
+
+ return null;
+ }
+
+ @Beta
+ static boolean isPersistenceModeEnabled(Entity entity) {
+ // TODO when there are PERSIST* options in BrooklynNode, look at them here!
+ // or, better, have a sensor for persistence
+ String params = null;
+ if (entity instanceof BrooklynCluster) {
+ EntitySpec<?> spec = entity.getConfig(BrooklynCluster.MEMBER_SPEC);
+ params = Strings.toString( spec.getConfig().get(BrooklynNode.EXTRA_LAUNCH_PARAMETERS) );
+ }
+ if (params==null) params = entity.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (params==null) return false;
+ if (params.indexOf("persist")==0) return false;
--- End diff --
Persistence options need not be specified at the command line for it to be active. The main method could be activating it instead. The only way to find out what's the persistence mode is through the REST API.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60520632
Minor cluster improvements, @neykov can you review? Otherwise cluster things look great (I've tested @neykov's work).
Node upgrade is new and so needs review.
BTW this is damn cool! upgrade effectors on cluster and on node. Use `brooklyn-cluster.yaml` for a file with the right persistence settings. And make sure you "download" the right version (install in your `.brooklyn/repository` and wipe the `installs/BrooklynNode_*` dirs!)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19445553
--- Diff: core/src/main/java/brooklyn/entity/basic/EntityPredicates.java ---
@@ -129,11 +337,45 @@ public boolean apply(@Nullable Entity input) {
};
}
+ // ---------------------------
+
/**
* Create a predicate that matches any entity who has an exact match for the given location
* (i.e. {@code entity.getLocations().contains(location)}).
*/
+ public static <T> Predicate<Entity> locationsInclude(Location location) {
--- End diff --
the verb is conjugated based on the subject (`locations`) not the object (`location`). ;)
however my ear agrees with yours so maybe the case could be made that `locations` here is a variable name, or maybe a collective noun, either which would justify the singular verb form?
i will change it for now. if any grammarians out there feel strongly i will ultimately defer to you.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19588780
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
--- End diff --
cleaned up this test a lot -- @neykov take a quick look?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19588760
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
--- End diff --
fixed the test. the problem was that we were queueing a task in a finally block after a previous queued task failed. fixed it by saying to `DynamicTasks.swallowChildrenExceptions()`.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19555048
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
--- End diff --
+1
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19464216
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
--- End diff --
It's referring to the call below. Better to remove it?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19465904
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
+ }
+ }).build());
+
+ entity().getConfigMap().addToLocalBag(parameters.getAllConfig());
+
+ // 6 start this entity, running the new version
+ DynamicTasks.queue(Effectors.invocation(entity(), BrooklynNode.START, ConfigBag.EMPTY));
+
+ DynamicTasks.waitForLast();
+ Entities.unmanage(dryRunChild);
+
+ return null;
+ }
+
+ @Beta
+ static boolean isPersistenceModeEnabled(Entity entity) {
+ // TODO when there are PERSIST* options in BrooklynNode, look at them here!
+ // or, better, have a sensor for persistence
+ String params = null;
+ if (entity instanceof BrooklynCluster) {
+ EntitySpec<?> spec = entity.getConfig(BrooklynCluster.MEMBER_SPEC);
+ params = Strings.toString( spec.getConfig().get(BrooklynNode.EXTRA_LAUNCH_PARAMETERS) );
+ }
+ if (params==null) params = entity.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (params==null) return false;
+ if (params.indexOf("persist")==0) return false;
--- End diff --
But still, checking the startup params is worse than doing nothing at all. Better always return true until we have the correct sensors in place.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19439690
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -49,7 +65,55 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsLiteralCaseInsensitive(final String fragment) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsLiteralCaseInsensitive(final String fragment) {
--- End diff --
I'd prefer consistency of naming. Should we have `containsLiteralIgnoreCase(String)` here, or should `Strings.containsLiteralIgnoreCase` be renamed to `Strings.containsLiteralCaseInsensitive`?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19421548
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java ---
@@ -285,6 +285,9 @@ public void launch() {
if (getEntity().getConfig(BrooklynNode.NO_SHUTDOWN_ON_EXIT)) {
cmd += " --noShutdownOnExit ";
}
+ if (!Strings.isBlank(getEntity().getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS))) {
--- End diff --
Minor preference: `Strings.isNonBlank` rather than `!Strings.isBlank`
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19439561
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -49,7 +65,55 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsLiteralCaseInsensitive(final String fragment) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsLiteralCaseInsensitive(final String fragment) {
--- End diff --
Should this just return `Predicate<CharSequence>`?
There should not be anywhere that expects `Predicate<String>` that does not accept `Predicate<CharSequence>`. If there is, we should fix it.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19424370
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
--- End diff --
`Sets.newLinkedHashSet(initialMembers)`. I much prefer the determinism of a LinkedHashSet. But probably not important here as we'll execute stop in parallel on them all.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19555990
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
+ //if the new master will be what we expect.
+ if (oldMaster != null) {
+ setNodeState(oldMaster, HighAvailabilityMode.HOT_STANDBY);
+ }
+
+ waitMasterHandover(oldMaster, newMaster);
+ } finally {
+ //3. Revert the priority of the node once it has become master
+ setNodePriority(newMaster, HA_STANDBY_PRIORITY);
+ }
+
+ checkMasterSelected(newMaster);
+ }
+
+ private void waitMasterHandover(final Entity oldMaster, final Entity newMaster) {
+ boolean masterChanged = Repeater.create()
+ .backoff(Duration.millis(500), 1.2, Duration.FIVE_SECONDS)
+ .limitTimeTo(Duration.ONE_MINUTE)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ Entity master = getMasterNode();
+ return master != oldMaster && master != null;
+ }
+ })
+ .run();
+ if (!masterChanged) {
+ LOG.warn("Timeout waiting for node to become master: " + newMaster + ".");
+ }
+ }
+
+ private void setNodeState(Entity oldMaster, HighAvailabilityMode mode) {
+ ManagementNodeState oldState = DynamicTasks.queue(
+ Effectors.invocation(
+ oldMaster,
+ BrooklynNode.SET_HIGH_AVAILABILITY_MODE,
+ MutableMap.of(SetHighAvailabilityModeEffector.MODE, mode))
+ ).asTask().getUnchecked();
+
+ if (oldState != ManagementNodeState.MASTER) {
+ LOG.warn("The previous HA state on node " + oldMaster.getId() + " was " + oldState +
+ ", while the expected value is " + ManagementNodeState.MASTER + ".");
+ }
+ }
+
+ private void setNodePriority(Entity newMaster, int newPriority) {
+ Integer oldPriority = DynamicTasks.queue(
+ Effectors.invocation(
+ newMaster,
+ BrooklynNode.SET_HIGH_AVAILABILITY_PRIORITY,
+ MutableMap.of(SetHighAvailabilityPriorityEffector.PRIORITY, newPriority))
+ ).asTask().getUnchecked();
+
+ Integer expectedPriority = (newPriority == HA_MASTER_PRIORITY ? HA_STANDBY_PRIORITY : HA_MASTER_PRIORITY);
--- End diff --
changed to `toggleNodePriority`, a bit better. it's private anyway.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438844
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node1);
+ }
+
+ private void checkMaster(Group cluster, Entity node) {
+ assertEquals(node.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.MASTER);
+ assertEquals(cluster.getAttribute(BrooklynCluster.MASTER_NODE), node);
+ for (Entity member : cluster.getMembers()) {
+ if (member != node) {
+ assertEquals(member.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.HOT_STANDBY);
+ }
+ assertEquals((int)member.getAttribute(TestHttpEntity.HA_PRIORITY), 0);
+ }
+ }
+
+ private static class HttpCallback implements Function<CallbackEntityHttpClient.Request, String> {
+ private enum State {
+ INITIAL,
+ PROMOTED
+ }
+ private State state = State.INITIAL;
+ private boolean failAtStateChange;
+
+ @Override
+ public String apply(Request input) {
+ if ("/v1/server/ha/state".equals(input.getPath())) {
+ if (failAtStateChange) {
+ throw new RuntimeException("Testing failure at chaning node state");
+ }
+
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/state", "mode", "HOT_STANDBY");
+ Entity entity = input.getEntity();
+ EntityTestUtils.assertAttributeEquals(entity, BrooklynNode.MANAGEMENT_NODE_STATE, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEquals(entity, TestHttpEntity.HA_PRIORITY, 0);
+
+ setManagementState(entity, ManagementNodeState.HOT_STANDBY);
+
+ return "MASTER";
+ } else {
+ switch(state) {
+ case INITIAL:
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/priority", "priority", "1");
+ state = State.PROMOTED;
+ setPriority(input.getEntity(), Integer.parseInt(input.getParams().get("priority")));
+ return "0";
+ case PROMOTED:
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/priority", "priority", "0");
+ state = State.INITIAL;
+ setPriority(input.getEntity(), Integer.parseInt(input.getParams().get("priority")));
+ return "1";
+ default: throw new IllegalStateException("Illegal call at state " + state + ". Request = " + input.getMethod() + " " + input.getPath());
+ }
+ }
+ }
+
+ public void checkRequest(Request input, String methodName, String path, String... keyValue) {
+ if (!input.getMethod().equals(methodName) || !input.getPath().equals(path)) {
+ throw new IllegalStateException("Request doesn't match expected state. Expected = " + input.getMethod() + " " + input.getPath() + ". " +
+ "Actual = " + methodName + " " + path);
+ }
+ for(int i = 0; i < keyValue.length / 2; i++) {
--- End diff --
Use of `keyValue` looks wrong. Are we expecting things like `key1, val1, key2, val2`?
Need to increment i by 2 each time, or do `i*2` and `i*2 + 1`.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600720
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -158,49 +176,83 @@ private DependentConfiguration() {}
}
// TODO would be nice to have an easy semantics for whenServiceUp (cf DynamicWebAppClusterImpl.whenServiceUp)
- // and TODO would be nice to have it stop when source is unmanaged (with ability to define post-processing)
- // probably using the builder for both of these...
+
public static <T> T waitInTaskForAttributeReady(final Entity source, final AttributeSensor<T> sensor, Predicate<? super T> ready, List<AttributeAndSensorCondition<?>> abortConditions, String blockingDetails) {
+ return new WaitInTaskForAttributeReady<T,T>(source, sensor, ready, abortConditions, blockingDetails).call();
+ }
+
+ protected static class WaitInTaskForAttributeReady<T,V> implements Callable<V> {
+
+ /* This is a change since before Oct 2014. Previously it would continue to poll,
+ * (maybe finding a different error) if the target entity becomes unmanaged.
+ * Now it actively checks unmanaged by default, and still throws although it might
+ * now find a different problem. */
+ private final static boolean DEFAULT_IGNORE_UNMANAGED = false;
- T value = source.getAttribute(sensor);
- final List<Exception> abortionExceptions = Lists.newCopyOnWriteArrayList();
-
- // return immediately if either the ready predicate or the abort conditions hold
- if (ready==null) ready = GroovyJavaMethods.truthPredicate();
- if (ready.apply(value)) return value;
- for (AttributeAndSensorCondition abortCondition : abortConditions) {
- Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
- if (abortCondition.predicate.apply(abortValue)) {
- abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
- }
+ final Entity source;
+ final AttributeSensor<T> sensor;
+ final Predicate<? super T> ready;
+ final List<AttributeAndSensorCondition<?>> abortSensorConditions;
+ final String blockingDetails;
+ final Function<? super T,? extends V> postProcess;
+ final Duration timeout;
+ final Maybe<V> onTimeout;
+ final boolean ignoreUnmanaged;
+ final Maybe<V> onUnmanaged;
+ // TODO onError Continue / Throw / Return(V)
+
+ protected WaitInTaskForAttributeReady(Builder<T, V> builder) {
+ this.source = builder.source;
+ this.sensor = builder.sensor;
+ this.ready = builder.readiness;
+ this.abortSensorConditions = builder.abortSensorConditions;
+ this.blockingDetails = builder.blockingDetails;
+ this.postProcess = builder.postProcess;
+ this.timeout = builder.timeout;
+ this.onTimeout = builder.onTimeout;
+ this.ignoreUnmanaged = builder.ignoreUnmanaged;
+ this.onUnmanaged = builder.onUnmanaged;
--- End diff --
This field seems to be ignored.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19648538
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,207 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private final AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> origMemberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(origMemberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+origMemberSpec+" / "+origMemberSpec.getConfig());
+
+ boolean success = false;
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+
+ EntitySpec<?> newMemberSpec = EntitySpec.create(origMemberSpec);
+
+ ConfigBag newConfig = ConfigBag.newInstance();
+ newConfig.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ newConfig.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+ newConfig.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+ newMemberSpec.configure(newConfig.getAllConfigAsConfigKeyMap());
--- End diff --
i don't mind it as is
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19557082
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
--- End diff --
not currently but worth a TODO
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19463630
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
--- End diff --
Also we could be upgrading a cluster with failed nodes to fix a rebind bug, can we force new instances to stay in HOT_STANDBY?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600780
--- Diff: core/src/test/java/brooklyn/util/task/TasksTest.java ---
@@ -127,4 +130,30 @@ public void testErrorsResolvingPropagatesOrSwallowedAllCorrectly() throws Except
assertResolvesValue(v, Object.class, "foo");
}
+ @Test
+ public void testRepeater() throws Exception {
+ Task<?> t;
+
+ t = Tasks.requiring(Repeater.create().until(Callables.returning(true)).every(Duration.millis(1))).build();
+ app.getExecutionContext().submit(t);
+ t.get(Duration.ONE_SECOND);
--- End diff --
Don't use short timeouts in non-integration tests. We've seen things timing out in cloudbees, and presume it will be the same in apace jenkins. Unless this is a performance test, then set it higher (e.g. 30 seconds).
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61089510
@aledsage agree with all your comments here, updated, and rebased so hopefully tests will pass then we can merge
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19417303
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklynnode;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.enricher.Enrichers;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
+import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody;
+import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody;
+import brooklyn.entity.group.DynamicClusterImpl;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.event.feed.function.FunctionPollConfig;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster {
+
+ private static final String MSG_NO_MASTER = "No master node in cluster";
+ private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster";
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password
+
+ @SuppressWarnings("unused")
+ private FunctionFeed scanMaster;
+
+ @Override
+ public void init() {
+ super.init();
+ getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER);
+ getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER);
+
+ ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER);
+ scanMaster = FunctionFeed.builder()
+ .entity(this)
+ .poll(new FunctionPollConfig<Object, BrooklynNode>(MASTER_NODE)
+ .period(Duration.ONE_SECOND)
+ .callable(new MasterChildFinder()))
+ .build();
+
+ addEnricher( Enrichers.builder().transforming(MASTER_NODE)
+ .uniqueTag("master-node-web-uri")
+ .publishing(BrooklynNode.WEB_CONSOLE_URI)
+ .computing(EntityFunctions.attribute(BrooklynNode.WEB_CONSOLE_URI))
+ .build() );
+ }
+
+ private final class MasterChildFinder implements Callable<BrooklynNode> {
--- End diff --
Does this really work for rebind, using a non-static class? I'd have written:
private static class MasterChildFinder implements Callable<BrooklynNode> {
private BrooklynClusterImpl entity;
MasterChildFinder(BrooklynClusterImpl entity) {
this.entity = entity;
}
@Override public BrooklynNode call() throws Exception {
return entity.findMasterChild();
}
}
However, on rebind that might well inject the dynamic proxy rather than the impl, so it might fail on rebind because the proxy does not implement `BrooklynClusterImpl`!
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61205646
ran in to some pain when upgrading a brooklyn instance to a project based on brooklyn but with different internal archive structure; @aledsage can you review the last two commits again please? (and then hopefully this can be put to bed!)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19463305
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
+ oldMembers.removeAll(initialNodeTask.asTask().getUnchecked());
+ DynamicTasks.queue(Effectors.invocation(BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, Collections.emptyMap(), oldMembers)).asTask().getUnchecked();
+ }
+
+ private TaskAdaptable<Collection<Entity>> newCreateNodesTask(int size, String name) {
+ return Tasks.<Collection<Entity>>builder().name(name).body(new CreateNodesCallable(size)).build();
+ }
+
+ protected class CreateNodesCallable implements Callable<Collection<Entity>> {
+ private final int size;
+ public CreateNodesCallable(int size) {
+ this.size = size;
+ }
+ @Override
+ public Collection<Entity> call() throws Exception {
+ return createNodes(size);
+ }
+ }
+
+ protected Collection<Entity> createNodes(int nodeCnt) {
+ DynamicCluster cluster = (DynamicCluster)entity();
+
+ //1. Create the nodes
+ Collection<Entity> newNodes = cluster.resizeByDelta(nodeCnt);
+
+ //2. Wait for them to be RUNNING (or at least STARTING to have completed)
+ // (should already be the case, because above is synchronous and, we think, it will fail if start does not succeed)
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(newNodes, Attributes.SERVICE_STATE_ACTUAL,
+ Predicates.not(Predicates.equalTo(Lifecycle.STARTING)), Duration.minutes(30)));
+
+ //3. Set HOT_STANDBY in case it is not enabled on the command line ...
--- End diff --
Relying on the command-line arguments to infer persistence state is not reliable, the cluster could be used with a brooklyn downstream project which sets a default persistence in its launcher.
On the other hand you are right that the spec might configure the instance so that the cluster members don't use the same storage for persistence. We need to check whether (at least one of the) new instances reports the master id in /v1/server/ha/states.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19426439
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
+ //if the new master will be what we expect.
+ if (oldMaster != null) {
+ setNodeState(oldMaster, HighAvailabilityMode.HOT_STANDBY);
+ }
+
+ waitMasterHandover(oldMaster, newMaster);
+ } finally {
+ //3. Revert the priority of the node once it has become master
+ setNodePriority(newMaster, HA_STANDBY_PRIORITY);
+ }
+
+ checkMasterSelected(newMaster);
+ }
+
+ private void waitMasterHandover(final Entity oldMaster, final Entity newMaster) {
+ boolean masterChanged = Repeater.create()
+ .backoff(Duration.millis(500), 1.2, Duration.FIVE_SECONDS)
+ .limitTimeTo(Duration.ONE_MINUTE)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ Entity master = getMasterNode();
+ return master != oldMaster && master != null;
+ }
+ })
+ .run();
+ if (!masterChanged) {
+ LOG.warn("Timeout waiting for node to become master: " + newMaster + ".");
+ }
+ }
+
+ private void setNodeState(Entity oldMaster, HighAvailabilityMode mode) {
+ ManagementNodeState oldState = DynamicTasks.queue(
+ Effectors.invocation(
+ oldMaster,
+ BrooklynNode.SET_HIGH_AVAILABILITY_MODE,
+ MutableMap.of(SetHighAvailabilityModeEffector.MODE, mode))
+ ).asTask().getUnchecked();
+
+ if (oldState != ManagementNodeState.MASTER) {
+ LOG.warn("The previous HA state on node " + oldMaster.getId() + " was " + oldState +
+ ", while the expected value is " + ManagementNodeState.MASTER + ".");
+ }
+ }
+
+ private void setNodePriority(Entity newMaster, int newPriority) {
+ Integer oldPriority = DynamicTasks.queue(
+ Effectors.invocation(
+ newMaster,
+ BrooklynNode.SET_HIGH_AVAILABILITY_PRIORITY,
+ MutableMap.of(SetHighAvailabilityPriorityEffector.PRIORITY, newPriority))
+ ).asTask().getUnchecked();
+
+ Integer expectedPriority = (newPriority == HA_MASTER_PRIORITY ? HA_STANDBY_PRIORITY : HA_MASTER_PRIORITY);
--- End diff --
Again this logic is surprising given the method name.
Also, the parameter name `newMaster` doesn't feel right, given we're either setting it to be master or standby.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438199
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
--- End diff --
Why not extend `BrooklynAppUnitTestSupport`?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19439729
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -49,7 +65,55 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsLiteralCaseInsensitive(final String fragment) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsLiteralCaseInsensitive(final String fragment) {
+ return new ContainsLiteralCaseInsensitive<T>(fragment);
+ }
+
+ private static final class ContainsLiteralCaseInsensitive<T extends CharSequence> implements Predicate<T> {
+ private final String fragment;
--- End diff --
Does xstream handle final fields ok?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19409348
--- Diff: utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java ---
@@ -153,4 +157,61 @@ private LimitFunction(int max) {
}
}
+ // ---------
+ public static <I,T extends Collection<I>> Predicate<T> contains(I item) {
+ return new CollectionContains<I,T>(item);
+ }
+
+ private static final class CollectionContains<I,T extends Collection<I>> implements Predicate<T> {
+ private final I item;
+ private CollectionContains(I item) {
+ this.item = item;
+ }
+ @Override
+ public boolean apply(T input) {
+ if (input==null) return false;
+ return input.contains(item);
+ }
+ @Override
+ public String toString() {
+ return "contains("+item+")";
+ }
+ }
+
+ // ---------
+
+ public static <T,TT extends Iterable<T>> Predicate<TT> all(Predicate<T> attributeSatisfies) {
--- End diff --
I wouldn't expect a method named `CollectionFunctionals.all(Predicate)` to go into the `QuorumChecks` code.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19463881
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
--- End diff --
Could also check that the original instance id is mentioned in /v1/server/ha/states making sure we have a correctly configured persistence.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438631
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node1);
+ }
+
+ private void checkMaster(Group cluster, Entity node) {
+ assertEquals(node.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.MASTER);
+ assertEquals(cluster.getAttribute(BrooklynCluster.MASTER_NODE), node);
+ for (Entity member : cluster.getMembers()) {
+ if (member != node) {
+ assertEquals(member.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.HOT_STANDBY);
+ }
+ assertEquals((int)member.getAttribute(TestHttpEntity.HA_PRIORITY), 0);
+ }
+ }
+
+ private static class HttpCallback implements Function<CallbackEntityHttpClient.Request, String> {
+ private enum State {
+ INITIAL,
+ PROMOTED
+ }
+ private State state = State.INITIAL;
+ private boolean failAtStateChange;
+
+ @Override
+ public String apply(Request input) {
+ if ("/v1/server/ha/state".equals(input.getPath())) {
+ if (failAtStateChange) {
+ throw new RuntimeException("Testing failure at chaning node state");
--- End diff --
Typo: "changing"
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19464551
--- Diff: software/base/src/main/resources/brooklyn/entity/brooklynnode/brooklyn-cluster.yaml ---
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+name: Example Brooklyn Cluster
+
+services:
+- type: brooklyn.entity.brooklynnode.BrooklynCluster
+ initialSize: 2
+ memberSpec:
+ $brooklyn:entitySpec:
+# type: classpath://brooklyn/entity/brooklynnode/brooklyn-node-persisting-to-tmp.yaml
+ type: brooklyn.entity.brooklynnode.BrooklynNode
+ brooklyn.config:
+ brooklynnode.launch.parameters.extra: --persist auto --persistenceDir /tmp/brooklyn-persistence-example/
--- End diff --
Cluster HA requires a shared persistence location, easiest to set up from an example yaml is a cloud object storage?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin closed the pull request at:
https://github.com/apache/incubator-brooklyn/pull/272
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19440320
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -98,8 +204,17 @@ public boolean apply(CharSequence input) {
};
}
- /** true if the object *is* a string starting with the given prefix */
+ // -----------------
+
+ /** true if the object *is* a {@link CharSequence} starting with the given prefix */
public static Predicate<Object> isStringStartingWith(final String prefix) {
+ return Predicates.<Object>and(Predicates.instanceOf(CharSequence.class),
+ Predicates.compose(new StartsWith<String>(prefix), StringFunctions.toStringFunction()));
--- End diff --
I'd use `startsWith(prefix)`, rather than calling this constructor directly.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19440228
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -75,7 +141,22 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsAllLiterals(final String... fragments) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsAllLiterals(final String... fragments) {
--- End diff --
I'd just go for the code below, as it feels a lot simpler to me:
public static Predicate<CharSequence> containsAllLiterals(final String... fragments) {
List<Predicate<CharSequence>> fragmentPredicates = Lists.newArrayList();
for (String fragment : fragments) {
fragmentPredicates.add(containsLiteral(fragment));
}
return Predicates.and(fragmentPredicates);
}
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19425342
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
--- End diff --
typo: Demote
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61497766
For your commit:
change test logic to match EntityConfigMap behaviour for inheritance
two implications of recent changes to EntityConfigMap caused failures in these tests,
i think the new behaviour is desired:
* any unknown flags/config set at parent remain is now NOT interpreted as flags at children
* getAllConfig() includes unknown config
Not sure what this will break, by not interpreting string config keys as flags in children. Guessing there will be some examples that rely on this.
I expect the inconsistency for inherited config (i.e. flags work when it's top-level, but not when it's inherited) will confuse some people.
On balance, I'm ok with this change but not particularly happy with the behaviour either way round.
I wonder about the flags - is the convenience worth it for any confusion caused?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19460443
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
--- End diff --
getProtocol() already calls toLowerCase
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19426239
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
+ //if the new master will be what we expect.
+ if (oldMaster != null) {
+ setNodeState(oldMaster, HighAvailabilityMode.HOT_STANDBY);
+ }
+
+ waitMasterHandover(oldMaster, newMaster);
+ } finally {
+ //3. Revert the priority of the node once it has become master
+ setNodePriority(newMaster, HA_STANDBY_PRIORITY);
+ }
+
+ checkMasterSelected(newMaster);
+ }
+
+ private void waitMasterHandover(final Entity oldMaster, final Entity newMaster) {
+ boolean masterChanged = Repeater.create()
+ .backoff(Duration.millis(500), 1.2, Duration.FIVE_SECONDS)
+ .limitTimeTo(Duration.ONE_MINUTE)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ Entity master = getMasterNode();
+ return master != oldMaster && master != null;
+ }
+ })
+ .run();
+ if (!masterChanged) {
+ LOG.warn("Timeout waiting for node to become master: " + newMaster + ".");
+ }
+ }
+
+ private void setNodeState(Entity oldMaster, HighAvailabilityMode mode) {
+ ManagementNodeState oldState = DynamicTasks.queue(
+ Effectors.invocation(
+ oldMaster,
+ BrooklynNode.SET_HIGH_AVAILABILITY_MODE,
+ MutableMap.of(SetHighAvailabilityModeEffector.MODE, mode))
+ ).asTask().getUnchecked();
+
+ if (oldState != ManagementNodeState.MASTER) {
--- End diff --
This method name does not imply the node should have been master (though the parameter name does).
No strong feelings, but perhaps it should be renamed `demoteMasterNode(oldMaster, mode)`.
Or it could return the oldState, and have the assertion in the caller.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19423553
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
--- End diff --
I'd probably have gone for `EntitySpec newMemberSpec = EntitySpec.create(memberSpec)`, and modified that copy. It feels cleaner rather than modifying the live config object.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600271
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -209,31 +261,101 @@ private DependentConfiguration() {}
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
+
+ TaskInternal<?> current = (TaskInternal<?>) Tasks.current();
+ if (current == null) throw new IllegalStateException("Should only be invoked in a running task");
+ Entity entity = BrooklynTaskTags.getTargetOrContextEntity(current);
+ if (entity == null) throw new IllegalStateException("Should only be invoked in a running task with an entity tag; "+
--- End diff --
I can see why you're doing this, but it does make code harder to test and makes it tightly coupled to a particular mode of usage, which doesn't feel good.
The name of the class does suggest that it will be inside a task though!
I'm fine with leaving as-is.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61079949
Failure is the old `brooklyn.management.ha.HighAvailabilityManagerSplitBrainTest.testDoubleRebindFails`, which should have been fixed in #278 (merged into master, but is not in this branch).
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523069
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklynnode;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.enricher.Enrichers;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
+import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody;
+import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody;
+import brooklyn.entity.group.DynamicClusterImpl;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.event.feed.function.FunctionPollConfig;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster {
+
+ private static final String MSG_NO_MASTER = "No master node in cluster";
+ private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster";
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password
+
+ @SuppressWarnings("unused")
+ private FunctionFeed scanMaster;
+
+ @Override
+ public void init() {
+ super.init();
+ getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER);
+ getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER);
+
+ ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER);
+ scanMaster = FunctionFeed.builder()
+ .entity(this)
+ .poll(new FunctionPollConfig<Object, BrooklynNode>(MASTER_NODE)
+ .period(Duration.ONE_SECOND)
+ .callable(new MasterChildFinder()))
+ .build();
+
+ addEnricher( Enrichers.builder().transforming(MASTER_NODE)
+ .uniqueTag("master-node-web-uri")
+ .publishing(BrooklynNode.WEB_CONSOLE_URI)
+ .computing(EntityFunctions.attribute(BrooklynNode.WEB_CONSOLE_URI))
+ .build() );
+ }
+
+ private final class MasterChildFinder implements Callable<BrooklynNode> {
--- End diff --
will test rebind but i think i also question whether the code as is will rebind properly. we should put `findMasterChild()` on the interface i think.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19424728
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
+ oldMembers.removeAll(initialNodeTask.asTask().getUnchecked());
+ DynamicTasks.queue(Effectors.invocation(BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, Collections.emptyMap(), oldMembers)).asTask().getUnchecked();
+ }
+
+ private TaskAdaptable<Collection<Entity>> newCreateNodesTask(int size, String name) {
+ return Tasks.<Collection<Entity>>builder().name(name).body(new CreateNodesCallable(size)).build();
+ }
+
+ protected class CreateNodesCallable implements Callable<Collection<Entity>> {
+ private final int size;
+ public CreateNodesCallable(int size) {
+ this.size = size;
+ }
+ @Override
+ public Collection<Entity> call() throws Exception {
+ return createNodes(size);
+ }
+ }
+
+ protected Collection<Entity> createNodes(int nodeCnt) {
+ DynamicCluster cluster = (DynamicCluster)entity();
+
+ //1. Create the nodes
+ Collection<Entity> newNodes = cluster.resizeByDelta(nodeCnt);
+
+ //2. Wait for them to be RUNNING (or at least STARTING to have completed)
+ // (should already be the case, because above is synchronous and, we think, it will fail if start does not succeed)
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(newNodes, Attributes.SERVICE_STATE_ACTUAL,
+ Predicates.not(Predicates.equalTo(Lifecycle.STARTING)), Duration.minutes(30)));
+
+ //3. Set HOT_STANDBY in case it is not enabled on the command line ...
--- End diff --
Should we just set this on the memberSpec when we're creating the replacement members, rather than calling here?
Could the memberSpec config have said "master", or `--perist clean`?!
Overriding things in the memberSpec to do exactly what we want safely feels better.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19424477
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
--- End diff --
Why would `oldMembers` ever contain the nodes added with `newCreateNodesTask`? If it did, that sounds like a bug?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19555008
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
--- End diff --
much cleaner, +1
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19557332
--- Diff: software/base/src/main/resources/brooklyn/entity/brooklynnode/brooklyn-cluster.yaml ---
@@ -0,0 +1,32 @@
+#
+# 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.
+#
+
+name: Example Brooklyn Cluster
+
+services:
+- type: brooklyn.entity.brooklynnode.BrooklynCluster
+ initialSize: 2
+ memberSpec:
+ $brooklyn:entitySpec:
+# type: classpath://brooklyn/entity/brooklynnode/brooklyn-node-persisting-to-tmp.yaml
+ type: brooklyn.entity.brooklynnode.BrooklynNode
+ brooklyn.config:
+ brooklynnode.launch.parameters.extra: --persist auto --persistenceDir /tmp/brooklyn-persistence-example/
--- End diff --
added comment
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600483
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -209,31 +261,101 @@ private DependentConfiguration() {}
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
+
+ TaskInternal<?> current = (TaskInternal<?>) Tasks.current();
+ if (current == null) throw new IllegalStateException("Should only be invoked in a running task");
+ Entity entity = BrooklynTaskTags.getTargetOrContextEntity(current);
+ if (entity == null) throw new IllegalStateException("Should only be invoked in a running task with an entity tag; "+
+ current+" has no entity tag ("+current.getStatusDetail(false)+")");
+
+ final LinkedList<T> publishedValues = new LinkedList<T>();
+ final Semaphore semaphore = new Semaphore(0); // could use Exchanger
+ SubscriptionHandle subscription = null;
+ List<SubscriptionHandle> abortSubscriptions = Lists.newArrayList();
- value = source.getAttribute(sensor);
- while (!ready.apply(value)) {
- String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
- try {
- semaphore.acquire();
- } finally {
- current.setBlockingDetails(prevBlockingDetails);
+ try {
+ subscription = ((EntityInternal)entity).getSubscriptionContext().subscribe(source, sensor, new SensorEventListener<T>() {
+ @Override public void onEvent(SensorEvent<T> event) {
+ synchronized (publishedValues) { publishedValues.add(event.getValue()); }
+ semaphore.release();
+ }});
+ for (final AttributeAndSensorCondition abortCondition : abortSensorConditions) {
+ abortSubscriptions.add(((EntityInternal)entity).getSubscriptionContext().subscribe(abortCondition.source, abortCondition.sensor, new SensorEventListener<Object>() {
+ @Override public void onEvent(SensorEvent<Object> event) {
+ if (abortCondition.predicate.apply(event.getValue())) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ semaphore.release();
+ }
+ }}));
+ Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
+ if (abortCondition.predicate.apply(abortValue)) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ }
}
-
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
- value = data.get();
- }
- if (LOG.isDebugEnabled()) LOG.debug("Attribute-ready for {} in entity {}", sensor, source);
- return value;
- } catch (InterruptedException e) {
- throw Exceptions.propagate(e);
- } finally {
- if (subscription != null) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(subscription);
- }
- for (SubscriptionHandle handle : abortSubscriptions) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(handle);
+
+ CountdownTimer timer = timeout!=null ? timeout.countdownTimer() : null;
+ Duration maxPeriod = Duration.millis(200);
+ Duration nextPeriod = Duration.millis(10);
+ while (true) {
+ // check the source on initial run (could be done outside the loop)
+ // and also (optionally) on each iteration in case it is more recent
+ value = source.getAttribute(sensor);
+ if (ready(value)) break;
+
+ if (timer!=null) {
+ if (timer.getDurationRemaining().isShorterThan(nextPeriod)) {
+ nextPeriod = timer.getDurationRemaining();
+ }
+ if (timer.isExpired()) {
+ if (onTimeout.isPresent()) return onTimeout.get();
+ throw new TimeoutException("Unsatisfied after "+Duration.sinceUtc(start));
+ }
+ }
+
+ String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
+ try {
+ if (semaphore.tryAcquire(nextPeriod.toMilliseconds(), TimeUnit.MILLISECONDS)) {
+ // immediately release so we are available for the next check
+ semaphore.release();
+ // if other permits have been made available (e.g. multiple notifications) drain them all as no point running multiple times
+ semaphore.drainPermits();
+ }
+ } finally {
+ current.setBlockingDetails(prevBlockingDetails);
+ }
+
+ // check any subscribed values which have come in first
+ while (!publishedValues.isEmpty()) {
--- End diff --
Should probably access `publishedValues.isEmpty` while synchronized.
But you'll probably get away without, given it is piggie-backing on the "happens-before" of the `semaphore.tryAcquire`, so no strong feelings.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438388
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
--- End diff --
Should first call `Entities.manage(cluster)`, or better if we use `TestApplication` then can do `app.createAndManageChild(spec)`
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19425699
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
+ //if the new master will be what we expect.
+ if (oldMaster != null) {
+ setNodeState(oldMaster, HighAvailabilityMode.HOT_STANDBY);
+ }
+
+ waitMasterHandover(oldMaster, newMaster);
+ } finally {
+ //3. Revert the priority of the node once it has become master
+ setNodePriority(newMaster, HA_STANDBY_PRIORITY);
+ }
+
+ checkMasterSelected(newMaster);
+ }
+
+ private void waitMasterHandover(final Entity oldMaster, final Entity newMaster) {
+ boolean masterChanged = Repeater.create()
+ .backoff(Duration.millis(500), 1.2, Duration.FIVE_SECONDS)
+ .limitTimeTo(Duration.ONE_MINUTE)
+ .until(new Callable<Boolean>() {
+ @Override
+ public Boolean call() throws Exception {
+ Entity master = getMasterNode();
+ return master != oldMaster && master != null;
--- End diff --
I think this is safe (because always get back the same dynamic proxy), but I'd prefer a `.equals()` or `Objects.equal()` rather than `==`.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19554628
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
--- End diff --
+1
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19417017
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklynnode;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.enricher.Enrichers;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
+import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody;
+import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody;
+import brooklyn.entity.group.DynamicClusterImpl;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.event.feed.function.FunctionPollConfig;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster {
+
+ private static final String MSG_NO_MASTER = "No master node in cluster";
+ private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster";
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password
+
+ @SuppressWarnings("unused")
+ private FunctionFeed scanMaster;
+
+ @Override
+ public void init() {
+ super.init();
+ getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER);
+ getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER);
+
+ ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER);
+ scanMaster = FunctionFeed.builder()
--- End diff --
As commented in https://github.com/apache/incubator-brooklyn/pull/266, do we also need `addFeed(FunctionFeed.builder()...)`, or is something else controlling that the feeds be persisted?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61049244
addressed all review comments, ready for merge once it passes tests
(i did not do a REST call to check persistence but there are some TODO's which would allow that)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19555350
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
--- End diff --
done
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19556769
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
+ }
+ }).build());
+
+ entity().getConfigMap().addToLocalBag(parameters.getAllConfig());
+
+ // 6 start this entity, running the new version
+ DynamicTasks.queue(Effectors.invocation(entity(), BrooklynNode.START, ConfigBag.EMPTY));
+
+ DynamicTasks.waitForLast();
+ Entities.unmanage(dryRunChild);
+
+ return null;
+ }
+
+ @Beta
+ static boolean isPersistenceModeEnabled(Entity entity) {
+ // TODO when there are PERSIST* options in BrooklynNode, look at them here!
+ // or, better, have a sensor for persistence
+ String params = null;
+ if (entity instanceof BrooklynCluster) {
+ EntitySpec<?> spec = entity.getConfig(BrooklynCluster.MEMBER_SPEC);
+ params = Strings.toString( spec.getConfig().get(BrooklynNode.EXTRA_LAUNCH_PARAMETERS) );
+ }
+ if (params==null) params = entity.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (params==null) return false;
+ if (params.indexOf("persist")==0) return false;
--- End diff --
good idea to check the sensors
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19556678
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -75,7 +141,22 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsAllLiterals(final String... fragments) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsAllLiterals(final String... fragments) {
--- End diff --
good catch FunctionalOverboardException :)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19421807
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
--- End diff --
We should put this in the try-block as well, to guarantee that we unset `upgradeInProgress`, even if there `checkNotNull` below fails.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523089
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java ---
@@ -213,6 +227,11 @@ private static String toNullableString(Object obj) {
}
+ @Override
+ protected void preStart() {
--- End diff --
+1
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19602900
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -209,31 +261,101 @@ private DependentConfiguration() {}
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
+
+ TaskInternal<?> current = (TaskInternal<?>) Tasks.current();
+ if (current == null) throw new IllegalStateException("Should only be invoked in a running task");
+ Entity entity = BrooklynTaskTags.getTargetOrContextEntity(current);
+ if (entity == null) throw new IllegalStateException("Should only be invoked in a running task with an entity tag; "+
+ current+" has no entity tag ("+current.getStatusDetail(false)+")");
+
+ final LinkedList<T> publishedValues = new LinkedList<T>();
+ final Semaphore semaphore = new Semaphore(0); // could use Exchanger
+ SubscriptionHandle subscription = null;
+ List<SubscriptionHandle> abortSubscriptions = Lists.newArrayList();
- value = source.getAttribute(sensor);
- while (!ready.apply(value)) {
- String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
- try {
- semaphore.acquire();
- } finally {
- current.setBlockingDetails(prevBlockingDetails);
+ try {
+ subscription = ((EntityInternal)entity).getSubscriptionContext().subscribe(source, sensor, new SensorEventListener<T>() {
+ @Override public void onEvent(SensorEvent<T> event) {
+ synchronized (publishedValues) { publishedValues.add(event.getValue()); }
+ semaphore.release();
+ }});
+ for (final AttributeAndSensorCondition abortCondition : abortSensorConditions) {
+ abortSubscriptions.add(((EntityInternal)entity).getSubscriptionContext().subscribe(abortCondition.source, abortCondition.sensor, new SensorEventListener<Object>() {
+ @Override public void onEvent(SensorEvent<Object> event) {
+ if (abortCondition.predicate.apply(event.getValue())) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ semaphore.release();
+ }
+ }}));
+ Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
+ if (abortCondition.predicate.apply(abortValue)) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ }
}
-
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
- value = data.get();
- }
- if (LOG.isDebugEnabled()) LOG.debug("Attribute-ready for {} in entity {}", sensor, source);
- return value;
- } catch (InterruptedException e) {
- throw Exceptions.propagate(e);
- } finally {
- if (subscription != null) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(subscription);
- }
- for (SubscriptionHandle handle : abortSubscriptions) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(handle);
+
+ CountdownTimer timer = timeout!=null ? timeout.countdownTimer() : null;
+ Duration maxPeriod = Duration.millis(200);
+ Duration nextPeriod = Duration.millis(10);
+ while (true) {
+ // check the source on initial run (could be done outside the loop)
+ // and also (optionally) on each iteration in case it is more recent
+ value = source.getAttribute(sensor);
+ if (ready(value)) break;
+
+ if (timer!=null) {
+ if (timer.getDurationRemaining().isShorterThan(nextPeriod)) {
+ nextPeriod = timer.getDurationRemaining();
+ }
+ if (timer.isExpired()) {
+ if (onTimeout.isPresent()) return onTimeout.get();
+ throw new TimeoutException("Unsatisfied after "+Duration.sinceUtc(start));
+ }
+ }
+
+ String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
+ try {
+ if (semaphore.tryAcquire(nextPeriod.toMilliseconds(), TimeUnit.MILLISECONDS)) {
+ // immediately release so we are available for the next check
+ semaphore.release();
+ // if other permits have been made available (e.g. multiple notifications) drain them all as no point running multiple times
+ semaphore.drainPermits();
+ }
+ } finally {
+ current.setBlockingDetails(prevBlockingDetails);
+ }
+
+ // check any subscribed values which have come in first
+ while (!publishedValues.isEmpty()) {
+ synchronized (publishedValues) { value = publishedValues.pop(); }
+ if (ready(value)) break;
+ }
+
+ // if unmanaged then ignore the other abort conditions
+ if (!ignoreUnmanaged && Entities.isNoLongerManaged(entity)) {
+ if (onTimeout.isPresent()) return onTimeout.get();
+ throw new NotManagedException(entity);
+ }
+
+ if (abortionExceptions.size() > 0) {
+ throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
+ }
+
+ nextPeriod = nextPeriod.times(2).maximum(maxPeriod);
--- End diff --
`upperBound(..)` and `lowerBound(..)` ?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19463961
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
--- End diff --
It's worth overwriting the install folder as well. Could happen to use the same machine (especially during testing) to spawn a second instance.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19443194
--- Diff: utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java ---
@@ -153,4 +157,61 @@ private LimitFunction(int max) {
}
}
+ // ---------
+ public static <I,T extends Collection<I>> Predicate<T> contains(I item) {
+ return new CollectionContains<I,T>(item);
+ }
+
+ private static final class CollectionContains<I,T extends Collection<I>> implements Predicate<T> {
+ private final I item;
+ private CollectionContains(I item) {
+ this.item = item;
+ }
+ @Override
+ public boolean apply(T input) {
+ if (input==null) return false;
+ return input.contains(item);
+ }
+ @Override
+ public String toString() {
+ return "contains("+item+")";
+ }
+ }
+
+ // ---------
+
+ public static <T,TT extends Iterable<T>> Predicate<TT> all(Predicate<T> attributeSatisfies) {
--- End diff --
why not? simpler to re-use the quorum check implementation with a quorum of `all` ?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19672833
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java ---
@@ -76,18 +77,54 @@ protected String getPidFile() {
@Override
protected String getInstallLabelExtraSalt() {
- return Identifiers.makeIdFromHash(Objects.hashCode(entity.getConfig(BrooklynNode.DOWNLOAD_URL), entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL)));
+ String downloadUrl = entity.getConfig(BrooklynNode.DOWNLOAD_URL);
+ String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL);
+ if (Objects.equal(downloadUrl, BrooklynNode.DOWNLOAD_URL.getConfigKey().getDefaultValue()) &&
+ Objects.equal(uploadUrl, BrooklynNode.DISTRO_UPLOAD_URL.getDefaultValue())) {
+ // if both are at the default value, then no salt
+ return null;
+ }
+ return Identifiers.makeIdFromHash(Objects.hashCode(downloadUrl, uploadUrl));
}
@Override
public void preInstall() {
resolver = Entities.newDownloader(this);
String subpath = entity.getConfig(BrooklynNode.SUBPATH_IN_ARCHIVE);
- if (Strings.isBlank(subpath)) subpath = format("brooklyn-%s", getVersion());
+ if (subpath==null) {
+ // assume the dir name is `basename-VERSION` where download link is `basename-VERSION-dist.tar.gz`
+ String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL);
+ String origDownloadName = uploadUrl;
+ if (origDownloadName==null) {
+ String downloadUrlTemplate = entity.getAttribute(BrooklynNode.DOWNLOAD_URL);
+ if (downloadUrlTemplate!=null) {
+ // BasicDownloadResolver makes it crazy hard to get the template-evaluated value of DOWNLOAD_URL
+ origDownloadName = DownloadSubstituters.substitute(downloadUrlTemplate, DownloadSubstituters.getBasicEntitySubstitutions(this));
+ }
+ }
+ if (origDownloadName!=null) {
+ origDownloadName = Urls.getBasename(origDownloadName);
--- End diff --
Make sure to unescape the url path before using it. I've hit this in actual usage.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61269937
ready for final (hopefully) review
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-brooklyn/pull/272
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600881
--- Diff: utils/common/src/main/java/brooklyn/util/exceptions/TimeoutException.java ---
@@ -0,0 +1,36 @@
+/*
+ * 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.util.exceptions;
+
+public class TimeoutException extends IllegalStateException {
--- End diff --
Don't like this class name because it clashes with `java.util.concurrent.TimeoutException`. That will just confuse people, including when looking at code and when writing catch blocks. How about `RuntimeTimeoutException`?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19557043
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
--- End diff --
agree, removed comment
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60743115
Finished review, overall looks great.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19409028
--- Diff: api/src/main/java/brooklyn/entity/proxying/EntitySpec.java ---
@@ -229,6 +230,12 @@ public Entity getParent() {
public Map<ConfigKey<?>, Object> getConfig() {
return Collections.unmodifiableMap(config);
}
+
+ /** @return Live instance of the config map, for instance in case mass clearances are desired */
+ @Beta
+ public Map<ConfigKey<?>, Object> getConfigLive() {
--- End diff --
I don't like exposing the underlying state; I'd prefer we had a `clearConfig()` method if that is the use-case.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19422057
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
--- End diff --
should this be `"file".equalsIgnoreCase`?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19463485
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
--- End diff --
Just occurred to me that we could get a failover event during an upgrade which would mess the assumptions below. We could boost the HA priority of the existing nodes during the upgrade but this doesn't solve the case when we are upgrading a single node.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438455
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
--- End diff --
Why do we need this line? Have called `cluster.addMemberChild(spec)` to create `node1` originally.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438531
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
--- End diff --
Again, can we delete these lines?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19557240
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
--- End diff --
install folder name should come from a hash of the download url and version, so we should be okay (in my tests it has been)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19462961
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
--- End diff --
That's a leftover from a previous version where the nodes to stop were taken from the currently running. No need for oldMembers now, just stop initialMembers.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19410583
--- Diff: core/src/main/java/brooklyn/entity/basic/EntityTasks.java ---
@@ -0,0 +1,63 @@
+/*
+ * 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 brooklyn.entity.Entity;
+import brooklyn.event.AttributeSensor;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.util.collections.CollectionFunctionals;
+import brooklyn.util.guava.Functionals;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/** Generally useful tasks related to entities */
+public class EntityTasks {
+
+ /** creates an (unsubmitted) task which waits for the attribute to satisfy the given predicate,
+ * with an optional timeout */
+ public static <T> TaskAdaptable<Boolean> awaitingAttribute(Entity entity, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
+ return Tasks.awaitingBuilder(Repeater.create("waiting on "+sensor.getName())
--- End diff --
This feels like yet another variant of `DependentConfiguration.attributeWhenReady`. I'd prefer us to have this code just once. For example, in `attributeWhenReady` you can pass in abort criteria, such as the entity being on-fire.
Also see `DependentConfiguration.builder()`. The number of options being passed to `attributeWhenReady` was getting so big that it called for a builder. Should that code re-use the `Tasks.awaitingBuilder` that you use here?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19471502
--- Diff: utils/common/src/main/java/brooklyn/util/collections/CollectionFunctionals.java ---
@@ -153,4 +157,61 @@ private LimitFunction(int max) {
}
}
+ // ---------
+ public static <I,T extends Collection<I>> Predicate<T> contains(I item) {
+ return new CollectionContains<I,T>(item);
+ }
+
+ private static final class CollectionContains<I,T extends Collection<I>> implements Predicate<T> {
+ private final I item;
+ private CollectionContains(I item) {
+ this.item = item;
+ }
+ @Override
+ public boolean apply(T input) {
+ if (input==null) return false;
+ return input.contains(item);
+ }
+ @Override
+ public String toString() {
+ return "contains("+item+")";
+ }
+ }
+
+ // ---------
+
+ public static <T,TT extends Iterable<T>> Predicate<TT> all(Predicate<T> attributeSatisfies) {
--- End diff --
Ok; it's just an implementation detail so agreed.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19421438
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java ---
@@ -213,6 +227,11 @@ private static String toNullableString(Object obj) {
}
+ @Override
+ protected void preStart() {
--- End diff --
I'd order the methods so that `preStart()` comes before `preStop()`. My rule of thumb is to order them as one might think about the lifecycle (e.g. for a driver then install, customize, launch, isRunning, stop, kill).
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523015
--- Diff: core/src/main/java/brooklyn/util/task/Tasks.java ---
@@ -421,5 +423,38 @@ public static boolean isInterrupted() {
if (t==null) return false;
return t.isCancelled();
}
+
+ private static class WaitForRepeaterCallable implements Callable<Boolean> {
+ protected Repeater repeater;
+ protected boolean requireTrue;
+
+ public WaitForRepeaterCallable(Repeater repeater, boolean requireTrue) {
+ this.repeater = repeater;
+ this.requireTrue = requireTrue;
+ }
+
+ @Override
+ public Boolean call() {
+ ReferenceWithError<Boolean> result = repeater.runKeepingError();
+ if (Boolean.TRUE.equals(result.getWithoutError()))
+ return true;
+ if (result.hasError())
+ throw Exceptions.propagate(result.getError());
+ if (requireTrue)
+ throw new IllegalStateException("timeout - "+repeater.getDescription());
+ return false;
+ }
+ }
+ /** creates an (unsubmitted) task which waits for the given repeater, optionally failing if it does not complete with success */
+ public static TaskAdaptable<Boolean> awaiting(Repeater repeater, boolean requireTrue) {
+ return awaitingBuilder(repeater, requireTrue).build();
+ }
+
+ /** creates a partially instantiated builder which waits for the given repeater, optionally failing if it does not complete with success,
+ * for further task customization and then {@link TaskBuilder#build()} */
+ public static TaskBuilder<Boolean> awaitingBuilder(Repeater repeater, boolean requireTrue) {
--- End diff --
agree - have refactored, actually preferring to return a builder. putting `body(Repeater)` on the builder feels to specialized so instead there are now methods in `Tasks` which generate a builder from a `Repeater`.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600565
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -209,31 +261,101 @@ private DependentConfiguration() {}
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
+
+ TaskInternal<?> current = (TaskInternal<?>) Tasks.current();
+ if (current == null) throw new IllegalStateException("Should only be invoked in a running task");
+ Entity entity = BrooklynTaskTags.getTargetOrContextEntity(current);
+ if (entity == null) throw new IllegalStateException("Should only be invoked in a running task with an entity tag; "+
+ current+" has no entity tag ("+current.getStatusDetail(false)+")");
+
+ final LinkedList<T> publishedValues = new LinkedList<T>();
+ final Semaphore semaphore = new Semaphore(0); // could use Exchanger
+ SubscriptionHandle subscription = null;
+ List<SubscriptionHandle> abortSubscriptions = Lists.newArrayList();
- value = source.getAttribute(sensor);
- while (!ready.apply(value)) {
- String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
- try {
- semaphore.acquire();
- } finally {
- current.setBlockingDetails(prevBlockingDetails);
+ try {
+ subscription = ((EntityInternal)entity).getSubscriptionContext().subscribe(source, sensor, new SensorEventListener<T>() {
+ @Override public void onEvent(SensorEvent<T> event) {
+ synchronized (publishedValues) { publishedValues.add(event.getValue()); }
+ semaphore.release();
+ }});
+ for (final AttributeAndSensorCondition abortCondition : abortSensorConditions) {
+ abortSubscriptions.add(((EntityInternal)entity).getSubscriptionContext().subscribe(abortCondition.source, abortCondition.sensor, new SensorEventListener<Object>() {
+ @Override public void onEvent(SensorEvent<Object> event) {
+ if (abortCondition.predicate.apply(event.getValue())) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ semaphore.release();
+ }
+ }}));
+ Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
+ if (abortCondition.predicate.apply(abortValue)) {
+ abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
+ }
}
-
if (abortionExceptions.size() > 0) {
throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
}
- value = data.get();
- }
- if (LOG.isDebugEnabled()) LOG.debug("Attribute-ready for {} in entity {}", sensor, source);
- return value;
- } catch (InterruptedException e) {
- throw Exceptions.propagate(e);
- } finally {
- if (subscription != null) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(subscription);
- }
- for (SubscriptionHandle handle : abortSubscriptions) {
- ((EntityInternal)entity).getSubscriptionContext().unsubscribe(handle);
+
+ CountdownTimer timer = timeout!=null ? timeout.countdownTimer() : null;
+ Duration maxPeriod = Duration.millis(200);
+ Duration nextPeriod = Duration.millis(10);
+ while (true) {
+ // check the source on initial run (could be done outside the loop)
+ // and also (optionally) on each iteration in case it is more recent
+ value = source.getAttribute(sensor);
+ if (ready(value)) break;
+
+ if (timer!=null) {
+ if (timer.getDurationRemaining().isShorterThan(nextPeriod)) {
+ nextPeriod = timer.getDurationRemaining();
+ }
+ if (timer.isExpired()) {
+ if (onTimeout.isPresent()) return onTimeout.get();
+ throw new TimeoutException("Unsatisfied after "+Duration.sinceUtc(start));
+ }
+ }
+
+ String prevBlockingDetails = current.setBlockingDetails(blockingDetails);
+ try {
+ if (semaphore.tryAcquire(nextPeriod.toMilliseconds(), TimeUnit.MILLISECONDS)) {
+ // immediately release so we are available for the next check
+ semaphore.release();
+ // if other permits have been made available (e.g. multiple notifications) drain them all as no point running multiple times
+ semaphore.drainPermits();
+ }
+ } finally {
+ current.setBlockingDetails(prevBlockingDetails);
+ }
+
+ // check any subscribed values which have come in first
+ while (!publishedValues.isEmpty()) {
+ synchronized (publishedValues) { value = publishedValues.pop(); }
+ if (ready(value)) break;
+ }
+
+ // if unmanaged then ignore the other abort conditions
+ if (!ignoreUnmanaged && Entities.isNoLongerManaged(entity)) {
+ if (onTimeout.isPresent()) return onTimeout.get();
+ throw new NotManagedException(entity);
+ }
+
+ if (abortionExceptions.size() > 0) {
+ throw new CompoundRuntimeException("Aborted waiting for ready from "+source+" "+sensor, abortionExceptions);
+ }
+
+ nextPeriod = nextPeriod.times(2).maximum(maxPeriod);
--- End diff --
The `maximum(maxPeriod)` threw me there! It has the opposite behaviour to `Math,max(nextPeriod, maxPeriod)`.
I'd prefer us to rename the `maximum` to something less ambiguous, but not in this PR.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19462865
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
--- End diff --
In what case would we get nodes with the old version? Before starting the upgrade the member_spec is updated with the URL of the new version.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438511
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
--- End diff --
I'd add a FIXME or a TODO to comments like this.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19443079
--- Diff: api/src/main/java/brooklyn/entity/proxying/EntitySpec.java ---
@@ -229,6 +230,12 @@ public Entity getParent() {
public Map<ConfigKey<?>, Object> getConfig() {
return Collections.unmodifiableMap(config);
}
+
+ /** @return Live instance of the config map, for instance in case mass clearances are desired */
+ @Beta
+ public Map<ConfigKey<?>, Object> getConfigLive() {
--- End diff --
makes sense
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19439021
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node1);
+ }
+
+ private void checkMaster(Group cluster, Entity node) {
+ assertEquals(node.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.MASTER);
+ assertEquals(cluster.getAttribute(BrooklynCluster.MASTER_NODE), node);
+ for (Entity member : cluster.getMembers()) {
+ if (member != node) {
+ assertEquals(member.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.HOT_STANDBY);
+ }
+ assertEquals((int)member.getAttribute(TestHttpEntity.HA_PRIORITY), 0);
+ }
+ }
+
+ private static class HttpCallback implements Function<CallbackEntityHttpClient.Request, String> {
--- End diff --
Gut feel is that something more like the expects in a mock would be cleaner to use. Or caller could list the expected calls in order, and the response for each.
But no strong feelings. This looks fine.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
GitHub user ahgittin reopened a pull request:
https://github.com/apache/incubator-brooklyn/pull/272
Brooklyn node and cluster upgrade
Merges #266 (cluster upgrade) with work I've been doing on node upgrade.
Builds on #260 so please ensure that is merged first.
Needs further testing (by me at this point) but wanted to push it in case @neykov you have comments, especially on the last commit.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/incubator-brooklyn brooklyn-node-upgrade
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-brooklyn/pull/272.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #272
----
commit 390654f775780792dcb57caf7bccf0871d456d54
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date: 2014-10-22T08:51:19Z
BrooklynNode cluster + upgrade effector
Also effectors to:
* select master in the cluster
* set HA priority
* set HA state
commit f99cdf70611f05658b924fb718a284545fa6a0e5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T18:12:09Z
add an upgrade effector for the BrooklynNode, and a sample yaml, and improve lifecycle so that stop_* methods destroy the VM and set a STOPPING state
commit 16121fe72bfa3aa90e46acc72f562ddc6c44cab7
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-20T13:51:17Z
clean up of anonymous internal classes, and some minor extensions to predicates available on Entity and String
commit db0a6465447dec4c4b035dfa881ecae3d81a9315
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-23T07:38:55Z
minor cleanups to software, allowing start with no locations, and including stdin for driver.execute commands
commit 9896d58f40a282b1f3625e9dfdb5e21de6fa7a58
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-18T00:44:32Z
WIP brooklyn HA and upgrade
commit ca1c2ad35f2af638ec6094720c53c4c3296ff678
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:51:36Z
fix bug where tasks (eg pollers) are not stopped on unmanagement if the task which started the tasks is the same one which is unmanaging the entity
commit 620d99b68fb23ba8ee31bd6514f0de18b9c58071
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:52:37Z
add support for extra CLI parameters to BrooklynNode, use those to run in persistence mode, and final fixes to the in-place upgrade effector
commit e7b278dc0b9b686c096a0579dda49779aeb4b9ed
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T23:32:24Z
bunch of clean ups - mainly addressing @aledsage's comments on @neykov's cluster upgrade PR, plus misc things i've noticed.
needs further testing though.
commit 070848e54425502a5d633f9877824ea0fdf76a04
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-25T00:45:36Z
fix swallowed error in dynamic cluster
commit e6ee417bf2f03438563d0c236b1aaa434b91485e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-25T00:46:19Z
WIP smoothing out the experience when setting up the cluster
TODO:
* cluster should take extra config, and then set them as config after we've failed over
* better names of phases
commit 4870dc2baab2300c7d53cacd9f312a64893b9c5e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:11:56Z
more QuorumCheck to util package, using it for new CollectionFunctionals defining a predicate which applies a predicate to a collection
commit 68348cd8345c917b4f029d60e6e692c6918fbb54
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:12:33Z
broolyn cluster upgrade should take extra config, and then set them as config after we've failed over, and has nice names of phases, plus refactor/tidy
commit 839b3a83d2e9d1040bd22702d959985114f2e911
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:22:11Z
remove renderer hint for MASTER_NODE -- it is not needed as type Entity gets this automatically, plus it was broken (it needs a special post processing);
and add an enricher to publish at the cluster the url for that node
commit 2a73a6554344ac90ea0b2103dacb5f26a93485b3
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T17:26:14Z
rename HAMode to HighAvailabilityMode, and same for priority
(this brings us in line with convention on treatment of abbrs being camel case,
preferring HttpRestApi over HTTPRESTAPI, but without the weirdness of HaMode; easy enough to be explicit on this API, imho)
commit e703bbeba9bc4b886f72dfc96bf528ab42c351a2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T17:41:30Z
increase the brooklyn node poll frequency to every 2s, to prevent saturating it with monitoring, and other minor tunings to BrooklynNode
commit 3f1df58935eefb4afd9c67d5c19fe5af46acc9d1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T07:42:16Z
add apache header to new java to kill the RAT problem
commit 9d533192e580233868f5e1a42391ef36146ff1e9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T13:09:12Z
have deprecated predicates methods point to new classes, use a private unused to preserve the anonymous inner (code review)
commit f04ba23ee8f46c6cab685781ac98646ff2c08ee6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T13:48:32Z
fix merge conflicts
----
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60971160
have updated most changes, still todo:
* fix the unit test
* check sensors to confirm persistence, etc
will check this all in once finished
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19522817
--- Diff: utils/common/src/main/java/brooklyn/util/collections/QuorumCheck.java ---
@@ -0,0 +1,106 @@
+/*
+ * 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.util.collections;
+
+import java.io.Serializable;
+
+/**
+ * For checking if a group/cluster is quorate. That is, whether the group has sufficient
+ * healthy members.
+ */
+public interface QuorumCheck {
--- End diff --
my logic was that asking whether a quorum of item passes a given check is a natural predicate to apply to a collection, so `CollectionFunctionals.quorum` is natural and that requires something like `QuorumCheck`. there is nothing brooklyn-specific about `QuorumCheck`. do you not think so?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523113
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java ---
@@ -285,6 +285,9 @@ public void launch() {
if (getEntity().getConfig(BrooklynNode.NO_SHUTDOWN_ON_EXIT)) {
cmd += " --noShutdownOnExit ";
}
+ if (!Strings.isBlank(getEntity().getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS))) {
--- End diff --
oooh, I prefer that too. have changed here. there are probably other places throughout the code where this should be changed.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60599543
I believe test failures are unrelated. There are 2 different ones:
* brooklyn.management.ha.HighAvailabilityManagerSplitBrainTest.testDoubleRebindFails
* brooklyn.event.feed.jmx.JmxFeedTest.setUp
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin closed the pull request at:
https://github.com/apache/incubator-brooklyn/pull/272
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19600044
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -158,49 +176,83 @@ private DependentConfiguration() {}
}
// TODO would be nice to have an easy semantics for whenServiceUp (cf DynamicWebAppClusterImpl.whenServiceUp)
- // and TODO would be nice to have it stop when source is unmanaged (with ability to define post-processing)
- // probably using the builder for both of these...
+
public static <T> T waitInTaskForAttributeReady(final Entity source, final AttributeSensor<T> sensor, Predicate<? super T> ready, List<AttributeAndSensorCondition<?>> abortConditions, String blockingDetails) {
+ return new WaitInTaskForAttributeReady<T,T>(source, sensor, ready, abortConditions, blockingDetails).call();
+ }
+
+ protected static class WaitInTaskForAttributeReady<T,V> implements Callable<V> {
+
+ /* This is a change since before Oct 2014. Previously it would continue to poll,
+ * (maybe finding a different error) if the target entity becomes unmanaged.
+ * Now it actively checks unmanaged by default, and still throws although it might
+ * now find a different problem. */
+ private final static boolean DEFAULT_IGNORE_UNMANAGED = false;
- T value = source.getAttribute(sensor);
- final List<Exception> abortionExceptions = Lists.newCopyOnWriteArrayList();
-
- // return immediately if either the ready predicate or the abort conditions hold
- if (ready==null) ready = GroovyJavaMethods.truthPredicate();
- if (ready.apply(value)) return value;
- for (AttributeAndSensorCondition abortCondition : abortConditions) {
- Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
- if (abortCondition.predicate.apply(abortValue)) {
- abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
- }
+ final Entity source;
--- End diff --
If making this class public, then should make fields protected. Otherwise will be hard to sub-class.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19588737
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
+ public void setUp() {
+ mgmt = new LocalManagementContextForTests();
+ EntitySpec<BasicApplication> appSpec = EntitySpec.create(BasicApplication.class)
+ .child(EntitySpec.create(BrooklynCluster.class));
+ app = ApplicationBuilder.newManagedApp(appSpec, mgmt);
+ cluster = (BrooklynCluster)Iterables.getOnlyElement(app.getChildren());
+
+ BasicExecutionManager em = new BasicExecutionManager("mycontext");
+ ec = new BasicExecutionContext(em);
+
+ poller = new Poller<Void>((EntityLocal)app, false);
+ poller.scheduleAtFixedRate(
+ new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ masterFailoverIfNeeded();
+ return null;
+ }
+ },
+ new DelegatingPollHandler<Void>(Collections.<AttributePollHandler<? super Void>>emptyList()),
+ Duration.millis(200));
+ poller.start();
+ }
+
+ @AfterMethod
+ public void tearDown() {
+ poller.stop();
+ }
+
+ @Test
+ public void testInvalidNewMasterIdFails() {
+ try {
+ BrooklynCluster cluster = app.addChild(EntitySpec.create(BrooklynCluster.class));
+ selectMaster(cluster, "1234");
+ fail("Non-existend entity ID provided.");
+ } catch (Exception e) {
+ assertTrue(e.toString().contains("1234 is not an ID of brooklyn node in this cluster"));
+ }
+ }
+
+ @Test
+ public void testSelectMaster() {
+ HttpCallback cb = new HttpCallback();
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node2);
+ }
+
+ @Test(groups="WIP")
+ //after throwing an exception in HttpCallback tasks are no longer executed, why?
+ public void testSelectMasterFailsAtChangeState() {
+ HttpCallback cb = new HttpCallback();
+ cb.setFailAtStateChange(true);
+
+ BrooklynNode node1 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+ BrooklynNode node2 = cluster.addMemberChild(EntitySpec.create(BrooklynNode.class)
+ .impl(TestHttpEntity.class)
+ .configure(TestHttpEntity.HTTP_CLIENT_CALLBACK, cb));
+
+ cluster.addMemberChild(node1);
+ cluster.addMemberChild(node2);
+
+ setManagementState(node1, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEqualsEventually(cluster, BrooklynCluster.MASTER_NODE, node1);
+
+ selectMaster(cluster, node2.getId());
+ checkMaster(cluster, node1);
+ }
+
+ private void checkMaster(Group cluster, Entity node) {
+ assertEquals(node.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.MASTER);
+ assertEquals(cluster.getAttribute(BrooklynCluster.MASTER_NODE), node);
+ for (Entity member : cluster.getMembers()) {
+ if (member != node) {
+ assertEquals(member.getAttribute(BrooklynNode.MANAGEMENT_NODE_STATE), ManagementNodeState.HOT_STANDBY);
+ }
+ assertEquals((int)member.getAttribute(TestHttpEntity.HA_PRIORITY), 0);
+ }
+ }
+
+ private static class HttpCallback implements Function<CallbackEntityHttpClient.Request, String> {
+ private enum State {
+ INITIAL,
+ PROMOTED
+ }
+ private State state = State.INITIAL;
+ private boolean failAtStateChange;
+
+ @Override
+ public String apply(Request input) {
+ if ("/v1/server/ha/state".equals(input.getPath())) {
+ if (failAtStateChange) {
+ throw new RuntimeException("Testing failure at chaning node state");
+ }
+
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/state", "mode", "HOT_STANDBY");
+ Entity entity = input.getEntity();
+ EntityTestUtils.assertAttributeEquals(entity, BrooklynNode.MANAGEMENT_NODE_STATE, ManagementNodeState.MASTER);
+ EntityTestUtils.assertAttributeEquals(entity, TestHttpEntity.HA_PRIORITY, 0);
+
+ setManagementState(entity, ManagementNodeState.HOT_STANDBY);
+
+ return "MASTER";
+ } else {
+ switch(state) {
+ case INITIAL:
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/priority", "priority", "1");
+ state = State.PROMOTED;
+ setPriority(input.getEntity(), Integer.parseInt(input.getParams().get("priority")));
+ return "0";
+ case PROMOTED:
+ checkRequest(input, HttpPost.METHOD_NAME, "/v1/server/ha/priority", "priority", "0");
+ state = State.INITIAL;
+ setPriority(input.getEntity(), Integer.parseInt(input.getParams().get("priority")));
+ return "1";
+ default: throw new IllegalStateException("Illegal call at state " + state + ". Request = " + input.getMethod() + " " + input.getPath());
+ }
+ }
+ }
+
+ public void checkRequest(Request input, String methodName, String path, String... keyValue) {
+ if (!input.getMethod().equals(methodName) || !input.getPath().equals(path)) {
+ throw new IllegalStateException("Request doesn't match expected state. Expected = " + input.getMethod() + " " + input.getPath() + ". " +
+ "Actual = " + methodName + " " + path);
+ }
+ for(int i = 0; i < keyValue.length / 2; i++) {
--- End diff --
correct. turns out we only ever pass one key-value pair, have simplified code to reflect
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19740222
--- Diff: utils/common/src/main/java/brooklyn/util/net/Urls.java ---
@@ -142,6 +143,11 @@ public static String mergePaths(String ...items) {
public static String encode(String text) {
return URLEncoder.encode(text);
}
+ /** As {@link #encode(String)} */
+ @SuppressWarnings("deprecation")
+ public static String decode(String text) {
+ return URLDecoder.decode(text);
--- End diff --
Will this work as expected? The `java.net.URLDecoder` is for "HTML form decoding" (e.g. "+" is converted to a space). But quite a few stackoverflow answers talk about just using `URLDecoder` for each part of the URI.
There is also a guava discussion about adding a decoder to complement `com.google.common.net.UrlEscapers` (https://github.com/google/guava/issues/1691) but that functionality is not available in guava yet.
Also, why not pass "UTF-8" as the encoding scheme, rather than calling the deprecated method? The javadoc says "Note: The World Wide Web Consortium Recommendation states that UTF-8 should be used. Not doing so may introduce incompatibilites."
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19438116
--- Diff: software/base/src/test/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorTest.java ---
@@ -0,0 +1,267 @@
+/*
+ * 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.brooklynnode.effector;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.Callable;
+
+import org.apache.http.client.methods.HttpPost;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.ApplicationBuilder;
+import brooklyn.entity.basic.BasicApplication;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynClusterImpl;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.effector.CallbackEntityHttpClient.Request;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.event.feed.AttributePollHandler;
+import brooklyn.event.feed.DelegatingPollHandler;
+import brooklyn.event.feed.Poller;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.management.ManagementContext;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.test.EntityTestUtils;
+import brooklyn.test.entity.LocalManagementContextForTests;
+import brooklyn.util.task.BasicExecutionContext;
+import brooklyn.util.task.BasicExecutionManager;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorTest {
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ protected ManagementContext mgmt;
+ protected BasicApplication app;
+ protected BasicExecutionContext ec;
+ protected BrooklynCluster cluster;
+ protected FunctionFeed scanMaster;
+ protected Poller<Void> poller;
+
+ @BeforeMethod
--- End diff --
Add `(alwaysRun=true)`; and same for `@AfterMethod.
Otherwise if someone marks a test as `@Integration` it will fail at command line but pass in Eclipse.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19471632
--- Diff: utils/common/src/main/java/brooklyn/util/collections/QuorumCheck.java ---
@@ -0,0 +1,106 @@
+/*
+ * 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.util.collections;
+
+import java.io.Serializable;
+
+/**
+ * For checking if a group/cluster is quorate. That is, whether the group has sufficient
+ * healthy members.
+ */
+public interface QuorumCheck {
--- End diff --
Not sure I follow. Seems like a circular argument that `CollectionFunctionals.quorum` has been added, which uses `QuorumCheck`. That `quorum` method could have been added anywhere we chose.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19413578
--- Diff: core/src/main/java/brooklyn/util/task/Tasks.java ---
@@ -421,5 +423,38 @@ public static boolean isInterrupted() {
if (t==null) return false;
return t.isCancelled();
}
+
+ private static class WaitForRepeaterCallable implements Callable<Boolean> {
+ protected Repeater repeater;
+ protected boolean requireTrue;
+
+ public WaitForRepeaterCallable(Repeater repeater, boolean requireTrue) {
+ this.repeater = repeater;
+ this.requireTrue = requireTrue;
+ }
+
+ @Override
+ public Boolean call() {
+ ReferenceWithError<Boolean> result = repeater.runKeepingError();
+ if (Boolean.TRUE.equals(result.getWithoutError()))
+ return true;
+ if (result.hasError())
+ throw Exceptions.propagate(result.getError());
--- End diff --
I don't like the way we propagate `result.getError()` here, as though the exception happened in this thread. If the repeater was executed in this thread, it's almost ok (except we lose some context of what called `WaitForRepeaterCallable.call`). If it's a different thread, then it's a bad idea to just throw the exception this thread, rather than wrapping it in something equivalent of an `ExecutionException`. For example, if that particular thread was interrupted then it doesn't mean we should interrupt this thread by re-throwing the exception!
The same applies to `ReferenceWithError.get()`.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19425484
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/SelectMasterEffectorBody.java ---
@@ -0,0 +1,173 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.NoSuchElementException;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityPriorityEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.collect.Iterables;
+
+public class SelectMasterEffectorBody extends EffectorBody<Void> implements SelectMasterEffector {
+ public static final Effector<Void> SELECT_MASTER = Effectors.effector(SelectMasterEffector.SELECT_MASTER).impl(new SelectMasterEffectorBody()).build();
+
+ private static final Logger LOG = LoggerFactory.getLogger(SelectMasterEffectorBody.class);
+
+ private static final int HA_STANDBY_PRIORITY = 0;
+ private static final int HA_MASTER_PRIORITY = 1;
+
+ private AtomicBoolean selectMasterInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!selectMasterInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("A master change is already in progress.");
+ }
+
+ try {
+ selectMaster(parameters);
+ } finally {
+ selectMasterInProgress.set(false);
+ }
+ return null;
+ }
+
+ private void selectMaster(ConfigBag parameters) {
+ String newMasterId = parameters.get(NEW_MASTER_ID);
+ Preconditions.checkNotNull(newMasterId, NEW_MASTER_ID.getName() + " parameter is required");
+
+ final Entity oldMaster = entity().getAttribute(BrooklynCluster.MASTER_NODE);
+ if (oldMaster != null && oldMaster.getId().equals(newMasterId)) {
+ LOG.info(newMasterId + " is already the current master, no change needed.");
+ return;
+ }
+
+ final Entity newMaster = getMember(newMasterId);
+
+ //1. Increase the priority of the node we wish to become master
+ setNodePriority(newMaster, HA_MASTER_PRIORITY);
+
+ //2. Denote the existing master so a new election takes place
+ try {
+ //If no master was yet selected, at least wait to see
--- End diff --
I believe this comment requires a `TODO`, rather than it explaining what the following lines of code do.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19557349
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
--- End diff --
added TODO
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19522831
--- Diff: core/src/main/java/brooklyn/entity/basic/EntityTasks.java ---
@@ -0,0 +1,63 @@
+/*
+ * 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 brooklyn.entity.Entity;
+import brooklyn.event.AttributeSensor;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.util.collections.CollectionFunctionals;
+import brooklyn.util.guava.Functionals;
+import brooklyn.util.repeat.Repeater;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/** Generally useful tasks related to entities */
+public class EntityTasks {
+
+ /** creates an (unsubmitted) task which waits for the attribute to satisfy the given predicate,
+ * with an optional timeout */
+ public static <T> TaskAdaptable<Boolean> awaitingAttribute(Entity entity, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
+ return Tasks.awaitingBuilder(Repeater.create("waiting on "+sensor.getName())
--- End diff --
great idea. i have added 3727b07b9d8f46cd629c5ec9e992bf67db7c54a0:
refactor recent changes so that Repeater tasks are in Tasks and EntityTasks reuse cleaned up DependentCongifuration,
with DependentConfiguration now relying on an internal class and:
* checking for unmanaged (and now this is the default)
* supporting a timeout
* ensuring that all values put into the subscription queue are read (previously it could miss a value if subscriptions were updated twice in succession)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19419115
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklynnode;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.enricher.Enrichers;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
+import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody;
+import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody;
+import brooklyn.entity.group.DynamicClusterImpl;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.event.feed.function.FunctionPollConfig;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster {
+
+ private static final String MSG_NO_MASTER = "No master node in cluster";
+ private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster";
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password
+
+ @SuppressWarnings("unused")
+ private FunctionFeed scanMaster;
+
+ @Override
+ public void init() {
+ super.init();
+ getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER);
+ getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER);
+
+ ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER);
+ scanMaster = FunctionFeed.builder()
--- End diff --
i think you're right. there is a feature enablement which controls whether `FunctionFeed.setEntity` does the `addFeed` call but it defaults to false. i think i vote in favour of the API adding it explicitly, as is done for enrichers etc. (but for true API parity we'd have `Spec` classes.) wdyt?
without this it will work the first time but will not get updated on rebind.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19523045
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynClusterImpl.java ---
@@ -0,0 +1,119 @@
+/*
+ * 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.brooklynnode;
+
+import java.util.Collection;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.enricher.Enrichers;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.ServiceStateLogic;
+import brooklyn.entity.basic.ServiceStateLogic.ServiceProblemsLogic;
+import brooklyn.entity.brooklynnode.effector.BrooklynClusterUpgradeEffectorBody;
+import brooklyn.entity.brooklynnode.effector.SelectMasterEffectorBody;
+import brooklyn.entity.group.DynamicClusterImpl;
+import brooklyn.event.feed.function.FunctionFeed;
+import brooklyn.event.feed.function.FunctionPollConfig;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.time.Duration;
+
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterImpl extends DynamicClusterImpl implements BrooklynCluster {
+
+ private static final String MSG_NO_MASTER = "No master node in cluster";
+ private static final String MSG_TOO_MANY_MASTERS = "Too many master nodes in cluster";
+
+ private static final Logger LOG = LoggerFactory.getLogger(BrooklynClusterImpl.class);
+
+ // TODO should we set a default MEMBER_SPEC ? difficult though because we'd need to set a password
+
+ @SuppressWarnings("unused")
+ private FunctionFeed scanMaster;
+
+ @Override
+ public void init() {
+ super.init();
+ getMutableEntityType().addEffector(SelectMasterEffectorBody.SELECT_MASTER);
+ getMutableEntityType().addEffector(BrooklynClusterUpgradeEffectorBody.UPGRADE_CLUSTER);
+
+ ServiceProblemsLogic.updateProblemsIndicator(this, MASTER_NODE, MSG_NO_MASTER);
+ scanMaster = FunctionFeed.builder()
--- End diff --
have changed to use `addFeed`. let's keep an eye on this paradigm to see if it is a good one!
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19556562
--- Diff: utils/common/src/main/java/brooklyn/util/text/StringPredicates.java ---
@@ -49,7 +65,55 @@ public String toString() {
};
}
- public static Predicate<CharSequence> containsLiteralCaseInsensitive(final String fragment) {
+ // -----------------
+
+ public static <T extends CharSequence> Predicate<T> containsLiteralCaseInsensitive(final String fragment) {
--- End diff --
+1 going with `IgnoreCase` cf `equalsIgnoreCase`
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60595219
thanks for all the comments @neykov - i had some questions, but one needed attention, added above as https://github.com/ahgittin/incubator-brooklyn/commit/9d533192e580233868f5e1a42391ef36146ff1e9
i've also rebased to solve apparent merge conflicts
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61497940
@ahgittin I think this is good to merge. Too much good stuff to delay further (and to risk diverging for the 3000+ lines of new code here).
Merging now.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60604988
@neykov let me know if my responses to your other comments are okay, then we can merge
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-61083582
Finished review of newly change code. Ready to merge, once you've looked through those comments.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19555616
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynClusterUpgradeEffectorBody.java ---
@@ -0,0 +1,211 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.EntityPredicates;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynCluster.SelectMasterEffector;
+import brooklyn.entity.brooklynnode.BrooklynCluster.UpgradeClusterEffector;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.brooklynnode.BrooklynNode.SetHighAvailabilityModeEffector;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.group.DynamicCluster;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.management.TaskAdaptable;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.time.Duration;
+
+import com.google.api.client.util.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+
+public class BrooklynClusterUpgradeEffectorBody extends EffectorBody<Void> implements UpgradeClusterEffector {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynClusterUpgradeEffectorBody.class);
+
+ public static final Effector<Void> UPGRADE_CLUSTER = Effectors.effector(UpgradeClusterEffector.UPGRADE_CLUSTER)
+ .impl(new BrooklynClusterUpgradeEffectorBody()).build();
+
+ private AtomicBoolean upgradeInProgress = new AtomicBoolean();
+
+ @Override
+ public Void call(ConfigBag parameters) {
+ if (!upgradeInProgress.compareAndSet(false, true)) {
+ throw new IllegalStateException("An upgrade is already in progress.");
+ }
+
+ EntitySpec<?> memberSpec = entity().getConfig(BrooklynCluster.MEMBER_SPEC);
+ Preconditions.checkNotNull(memberSpec, BrooklynCluster.MEMBER_SPEC.getName() + " is required for " + UpgradeClusterEffector.class.getName());
+
+ ConfigBag specCfg = ConfigBag.newInstance( memberSpec.getConfig() );
+ ConfigBag origSpecCfg = ConfigBag.newInstanceCopying(specCfg);
+ log.debug("Upgrading "+entity()+", changing "+BrooklynCluster.MEMBER_SPEC+" from "+memberSpec+" / "+origSpecCfg);
+
+ try {
+ String newDownloadUrl = parameters.get(DOWNLOAD_URL);
+ specCfg.putIfNotNull(DOWNLOAD_URL, newDownloadUrl);
+ specCfg.put(BrooklynNode.DISTRO_UPLOAD_URL, inferUploadUrl(newDownloadUrl));
+
+ specCfg.putAll(ConfigBag.newInstance(parameters.get(EXTRA_CONFIG)).getAllConfigAsConfigKeyMap());
+
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(specCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+ log.debug("Upgrading "+entity()+", new "+BrooklynCluster.MEMBER_SPEC+": "+memberSpec+" / "+specCfg);
+
+ upgrade(parameters);
+ } catch (Exception e) {
+ log.debug("Upgrading "+entity()+" failed, will rethrow after restoring "+BrooklynCluster.MEMBER_SPEC+" to: "+origSpecCfg);
+ Map<ConfigKey<?>, Object> cfgLive = memberSpec.getConfigLive();
+ cfgLive.clear();
+ cfgLive.putAll(origSpecCfg.getAllConfigAsConfigKeyMap());
+ // not necessary, but good practice
+ entity().setConfig(BrooklynCluster.MEMBER_SPEC, memberSpec);
+
+ throw Exceptions.propagate(e);
+
+ } finally {
+ upgradeInProgress.set(false);
+ }
+ return null;
+ }
+
+ private String inferUploadUrl(String newDownloadUrl) {
+ if (newDownloadUrl==null) return null;
+ boolean isLocal = "file".equals(Urls.getProtocol(newDownloadUrl)) || new File(newDownloadUrl).exists();
+ if (isLocal) {
+ return newDownloadUrl;
+ } else {
+ return null;
+ }
+ }
+
+ protected void upgrade(ConfigBag parameters) {
+ //TODO currently this will fight with auto-scaler policies; they must be turned off for upgrade to work
+
+ Group cluster = (Group)entity();
+ Collection<Entity> initialMembers = cluster.getMembers();
+ int initialClusterSize = initialMembers.size();
+
+ if (!BrooklynNodeUpgradeEffectorBody.isPersistenceModeEnabled(cluster)) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "Cluster upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ //1. Initially create a single node to check if it will launch successfully
+ TaskAdaptable<Collection<Entity>> initialNodeTask = DynamicTasks.queue(newCreateNodesTask(1, "Creating first upgraded version node"));
+
+ //2. If everything is OK with the first node launch the rest as well
+ TaskAdaptable<Collection<Entity>> remainingNodesTask = DynamicTasks.queue(newCreateNodesTask(initialClusterSize - 1, "Creating remaining upgraded version nodes ("+(initialClusterSize - 1)+")"));
+
+ //3. Once we have all nodes running without errors switch master
+ DynamicTasks.queue(Effectors.invocation(cluster, BrooklynCluster.SELECT_MASTER, MutableMap.of(SelectMasterEffector.NEW_MASTER_ID,
+ Iterables.getOnlyElement(initialNodeTask.asTask().getUnchecked()).getId()))).asTask().getUnchecked();
+
+ //4. Stop the nodes which were running at the start of the upgrade call, but keep them around.
+ // Should we create a quarantine-like zone for old stopped version?
+ // For members that were created meanwhile - they will be using the new version already. If the new version
+ // isn't good then they will fail to start as well, forcing the policies to retry (and succeed once the
+ // URL is reverted).
+ //TODO can get into problem state if more old nodes are created; better might be to set the
+ //version on this cluster before the above select-master call, and then delete any which are running the old
+ //version (would require tracking the version number at the entity)
+ HashSet<Entity> oldMembers = new HashSet<Entity>(initialMembers);
+ oldMembers.removeAll(remainingNodesTask.asTask().getUnchecked());
+ oldMembers.removeAll(initialNodeTask.asTask().getUnchecked());
+ DynamicTasks.queue(Effectors.invocation(BrooklynNode.STOP_NODE_BUT_LEAVE_APPS, Collections.emptyMap(), oldMembers)).asTask().getUnchecked();
+ }
+
+ private TaskAdaptable<Collection<Entity>> newCreateNodesTask(int size, String name) {
+ return Tasks.<Collection<Entity>>builder().name(name).body(new CreateNodesCallable(size)).build();
+ }
+
+ protected class CreateNodesCallable implements Callable<Collection<Entity>> {
+ private final int size;
+ public CreateNodesCallable(int size) {
+ this.size = size;
+ }
+ @Override
+ public Collection<Entity> call() throws Exception {
+ return createNodes(size);
+ }
+ }
+
+ protected Collection<Entity> createNodes(int nodeCnt) {
+ DynamicCluster cluster = (DynamicCluster)entity();
+
+ //1. Create the nodes
+ Collection<Entity> newNodes = cluster.resizeByDelta(nodeCnt);
+
+ //2. Wait for them to be RUNNING (or at least STARTING to have completed)
+ // (should already be the case, because above is synchronous and, we think, it will fail if start does not succeed)
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(newNodes, Attributes.SERVICE_STATE_ACTUAL,
+ Predicates.not(Predicates.equalTo(Lifecycle.STARTING)), Duration.minutes(30)));
+
+ //3. Set HOT_STANDBY in case it is not enabled on the command line ...
--- End diff --
have added TODO comments for these, including adding EntitySpec support to control HA mode via config (not currently there)
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19410243
--- Diff: core/src/main/java/brooklyn/entity/basic/EntityPredicates.java ---
@@ -129,11 +337,45 @@ public boolean apply(@Nullable Entity input) {
};
}
+ // ---------------------------
+
/**
* Create a predicate that matches any entity who has an exact match for the given location
* (i.e. {@code entity.getLocations().contains(location)}).
*/
+ public static <T> Predicate<Entity> locationsInclude(Location location) {
--- End diff --
Very minor: should this be `locationsIncludes(Location)`, because the given location is singular?
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19413836
--- Diff: core/src/main/java/brooklyn/util/task/Tasks.java ---
@@ -421,5 +423,38 @@ public static boolean isInterrupted() {
if (t==null) return false;
return t.isCancelled();
}
+
+ private static class WaitForRepeaterCallable implements Callable<Boolean> {
+ protected Repeater repeater;
+ protected boolean requireTrue;
+
+ public WaitForRepeaterCallable(Repeater repeater, boolean requireTrue) {
+ this.repeater = repeater;
+ this.requireTrue = requireTrue;
+ }
+
+ @Override
+ public Boolean call() {
+ ReferenceWithError<Boolean> result = repeater.runKeepingError();
+ if (Boolean.TRUE.equals(result.getWithoutError()))
+ return true;
+ if (result.hasError())
+ throw Exceptions.propagate(result.getError());
+ if (requireTrue)
+ throw new IllegalStateException("timeout - "+repeater.getDescription());
+ return false;
+ }
+ }
+ /** creates an (unsubmitted) task which waits for the given repeater, optionally failing if it does not complete with success */
+ public static TaskAdaptable<Boolean> awaiting(Repeater repeater, boolean requireTrue) {
+ return awaitingBuilder(repeater, requireTrue).build();
+ }
+
+ /** creates a partially instantiated builder which waits for the given repeater, optionally failing if it does not complete with success,
+ * for further task customization and then {@link TaskBuilder#build()} */
+ public static TaskBuilder<Boolean> awaitingBuilder(Repeater repeater, boolean requireTrue) {
--- End diff --
I'm unconvinced this method is pulling its weight. Perhaps the builder should have a method `body(Repeater)` rather than having this extra method here? That could set the name if it did not already have a name.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19603384
--- Diff: core/src/main/java/brooklyn/event/basic/DependentConfiguration.java ---
@@ -158,49 +176,83 @@ private DependentConfiguration() {}
}
// TODO would be nice to have an easy semantics for whenServiceUp (cf DynamicWebAppClusterImpl.whenServiceUp)
- // and TODO would be nice to have it stop when source is unmanaged (with ability to define post-processing)
- // probably using the builder for both of these...
+
public static <T> T waitInTaskForAttributeReady(final Entity source, final AttributeSensor<T> sensor, Predicate<? super T> ready, List<AttributeAndSensorCondition<?>> abortConditions, String blockingDetails) {
+ return new WaitInTaskForAttributeReady<T,T>(source, sensor, ready, abortConditions, blockingDetails).call();
+ }
+
+ protected static class WaitInTaskForAttributeReady<T,V> implements Callable<V> {
+
+ /* This is a change since before Oct 2014. Previously it would continue to poll,
+ * (maybe finding a different error) if the target entity becomes unmanaged.
+ * Now it actively checks unmanaged by default, and still throws although it might
+ * now find a different problem. */
+ private final static boolean DEFAULT_IGNORE_UNMANAGED = false;
- T value = source.getAttribute(sensor);
- final List<Exception> abortionExceptions = Lists.newCopyOnWriteArrayList();
-
- // return immediately if either the ready predicate or the abort conditions hold
- if (ready==null) ready = GroovyJavaMethods.truthPredicate();
- if (ready.apply(value)) return value;
- for (AttributeAndSensorCondition abortCondition : abortConditions) {
- Object abortValue = abortCondition.source.getAttribute(abortCondition.sensor);
- if (abortCondition.predicate.apply(abortValue)) {
- abortionExceptions.add(new Exception("Abort due to "+abortCondition.source+" -> "+abortCondition.sensor));
- }
+ final Entity source;
+ final AttributeSensor<T> sensor;
+ final Predicate<? super T> ready;
+ final List<AttributeAndSensorCondition<?>> abortSensorConditions;
+ final String blockingDetails;
+ final Function<? super T,? extends V> postProcess;
+ final Duration timeout;
+ final Maybe<V> onTimeout;
+ final boolean ignoreUnmanaged;
+ final Maybe<V> onUnmanaged;
+ // TODO onError Continue / Throw / Return(V)
+
+ protected WaitInTaskForAttributeReady(Builder<T, V> builder) {
+ this.source = builder.source;
+ this.sensor = builder.sensor;
+ this.ready = builder.readiness;
+ this.abortSensorConditions = builder.abortSensorConditions;
+ this.blockingDetails = builder.blockingDetails;
+ this.postProcess = builder.postProcess;
+ this.timeout = builder.timeout;
+ this.onTimeout = builder.onTimeout;
+ this.ignoreUnmanaged = builder.ignoreUnmanaged;
+ this.onUnmanaged = builder.onUnmanaged;
--- End diff --
oops, good catch, was using `onTimeout` in two places, wrongly
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60676334
Finished reviewing; looks good!
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19464172
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/effector/BrooklynNodeUpgradeEffectorBody.java ---
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklynnode.effector;
+
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.Effector;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityInternal;
+import brooklyn.entity.basic.EntityTasks;
+import brooklyn.entity.basic.SoftwareProcess;
+import brooklyn.entity.brooklynnode.BrooklynCluster;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.proxying.EntitySpec;
+import brooklyn.entity.software.SshEffectorTasks;
+import brooklyn.event.basic.MapConfigKey;
+import brooklyn.management.ha.HighAvailabilityMode;
+import brooklyn.management.ha.ManagementNodeState;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.net.Urls;
+import brooklyn.util.task.DynamicTasks;
+import brooklyn.util.task.Tasks;
+import brooklyn.util.text.Identifiers;
+import brooklyn.util.text.Strings;
+import brooklyn.util.time.Duration;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Predicates;
+import com.google.common.reflect.TypeToken;
+
+@SuppressWarnings("serial")
+/** Upgrades a brooklyn node in-place on the box,
+ * by creating a child brooklyn node and ensuring it can rebind in HOT_STANDBY
+ * <p>
+ * Requires the target node to have persistence enabled.
+ */
+public class BrooklynNodeUpgradeEffectorBody extends EffectorBody<Void> {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynNodeUpgradeEffectorBody.class);
+
+ public static final ConfigKey<String> DOWNLOAD_URL = BrooklynNode.DOWNLOAD_URL.getConfigKey();
+ public static final ConfigKey<Map<String,Object>> EXTRA_CONFIG = MapConfigKey.builder(new TypeToken<Map<String,Object>>() {})
+ .name("extraConfig")
+ .description("Additional new config to set on the BrooklynNode as part of upgrading")
+ .build();
+
+ public static final Effector<Void> UPGRADE = Effectors.effector(Void.class, "upgrade")
+ .description("Changes the Brooklyn build used to run this node, "
+ + "by spawning a dry-run node then copying the installed files across. "
+ + "This node must be running for persistence for in-place upgrading to work.")
+ .parameter(BrooklynNode.SUGGESTED_VERSION)
+ .parameter(DOWNLOAD_URL)
+ .parameter(EXTRA_CONFIG)
+ .impl(new BrooklynNodeUpgradeEffectorBody()).build();
+
+ @Override
+ public Void call(ConfigBag parametersO) {
+ if (!isPersistenceModeEnabled(entity())) {
+ // would could try a `forcePersistNow`, but that's sloppy;
+ // for now, require HA/persistence for upgrading
+ DynamicTasks.queue( Tasks.warning("Check persistence",
+ new IllegalStateException("Persistence does not appear to be enabled at this cluster. "
+ + "In-place node upgrade will not succeed unless a custom launch script enables it.")) );
+ }
+
+ ConfigBag parameters = ConfigBag.newInstanceCopying(parametersO);
+
+ /*
+ * all parameters are passed to children, apart from EXTRA_CONFIG
+ * whose value (as a map) is so passed; it provides an easy way to set extra config in the gui.
+ * (IOW a key-value mapping can be passed either inside EXTRA_CONFIG or as a sibling to EXTRA_CONFIG)
+ */
+ if (parameters.containsKey(EXTRA_CONFIG)) {
+ Map<String, Object> extra = parameters.get(EXTRA_CONFIG);
+ parameters.remove(EXTRA_CONFIG);
+ parameters.putAll(extra);
+ }
+ log.debug(this+" upgrading, using "+parameters);
+
+ // TODO require entity() node state master or hot standby AND require persistence enabled, or a new 'force_attempt_upgrade' parameter to be applied
+ // TODO could have a 'skip_dry_run_upgrade' parameter
+ // TODO could support 'dry_run_only' parameter, with optional resumption tasks (eg new dynamic effector)
+
+ // 1 add new brooklyn version entity as child (so uses same machine), with same config apart from things in parameters
+ final BrooklynNode dryRunChild = entity().addChild(EntitySpec.create(BrooklynNode.class).configure(parameters.getAllConfig())
+ .displayName("Upgraded Version Dry-Run Node")
+ // force dir and label back to their defaults (do not piggy back on what may have already been installed)
+ .configure(BrooklynNode.INSTALL_DIR, BrooklynNode.INSTALL_DIR.getConfigKey().getDefaultValue())
+ .configure(BrooklynNode.INSTALL_UNIQUE_LABEL, "upgrade-tmp-"+Identifiers.makeRandomId(8))
+ .configure(parameters.getAllConfig()));
+
+ //force this to start as hot-standby
+ // TODO alternatively could use REST API as in BrooklynClusterUpgradeEffectorBody
+ String launchParameters = dryRunChild.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (Strings.isBlank(launchParameters)) launchParameters = "";
+ else launchParameters += " ";
+ launchParameters += "--highAvailability "+HighAvailabilityMode.HOT_STANDBY;
+ ((EntityInternal)dryRunChild).setConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS, launchParameters);
+
+ Entities.manage(dryRunChild);
+ final String dryRunNodeUid = dryRunChild.getId();
+ ((EntityInternal)dryRunChild).setDisplayName("Dry-Run Upgraded Brooklyn Node ("+dryRunNodeUid+")");
+
+ DynamicTasks.queue(Effectors.invocation(dryRunChild, BrooklynNode.START, ConfigBag.EMPTY));
+
+ // 2 confirm hot standby status
+ DynamicTasks.queue(EntityTasks.awaitingAttribute(dryRunChild, BrooklynNode.MANAGEMENT_NODE_STATE,
+ Predicates.equalTo(ManagementNodeState.HOT_STANDBY), Duration.FIVE_MINUTES));
+
+ // 3 stop new version
+ // 4 stop old version
+ DynamicTasks.queue(Tasks.builder().name("shutdown original and transient nodes")
+ .add(Effectors.invocation(dryRunChild, BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .add(Effectors.invocation(entity(), BrooklynNode.SHUTDOWN, ConfigBag.EMPTY))
+ .build());
+
+ // 5 move old files, and move new files
+ DynamicTasks.queue(Tasks.builder().name("setup new version").body(new Runnable() {
+ @Override
+ public void run() {
+ String runDir = entity().getAttribute(SoftwareProcess.RUN_DIR);
+ String bkDir = Urls.mergePaths(runDir, "..", Urls.getBasename(runDir)+"-backups", dryRunNodeUid);
+ String dryRunDir = Preconditions.checkNotNull(dryRunChild.getAttribute(SoftwareProcess.RUN_DIR));
+ log.debug(this+" storing backup of previous version in "+bkDir);
+ DynamicTasks.queue(SshEffectorTasks.ssh(
+ "cd "+runDir,
+ "mkdir -p "+bkDir,
+ "mv * "+bkDir,
+ "cd "+dryRunDir,
+ "mv * "+runDir
+ ).summary("move files"));
+ }
+ }).build());
+
+ entity().getConfigMap().addToLocalBag(parameters.getAllConfig());
+
+ // 6 start this entity, running the new version
+ DynamicTasks.queue(Effectors.invocation(entity(), BrooklynNode.START, ConfigBag.EMPTY));
+
+ DynamicTasks.waitForLast();
+ Entities.unmanage(dryRunChild);
+
+ return null;
+ }
+
+ @Beta
+ static boolean isPersistenceModeEnabled(Entity entity) {
+ // TODO when there are PERSIST* options in BrooklynNode, look at them here!
+ // or, better, have a sensor for persistence
+ String params = null;
+ if (entity instanceof BrooklynCluster) {
+ EntitySpec<?> spec = entity.getConfig(BrooklynCluster.MEMBER_SPEC);
+ params = Strings.toString( spec.getConfig().get(BrooklynNode.EXTRA_LAUNCH_PARAMETERS) );
+ }
+ if (params==null) params = entity.getConfig(BrooklynNode.EXTRA_LAUNCH_PARAMETERS);
+ if (params==null) return false;
+ if (params.indexOf("persist")==0) return false;
--- End diff --
OK, I see your comment above addresses this.
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
GitHub user ahgittin reopened a pull request:
https://github.com/apache/incubator-brooklyn/pull/272
Brooklyn node and cluster upgrade
Merges #266 (cluster upgrade) with work I've been doing on node upgrade.
Builds on #260 so please ensure that is merged first.
Needs further testing (by me at this point) but wanted to push it in case @neykov you have comments, especially on the last commit.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/incubator-brooklyn brooklyn-node-upgrade
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-brooklyn/pull/272.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #272
----
commit 390654f775780792dcb57caf7bccf0871d456d54
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Date: 2014-10-22T08:51:19Z
BrooklynNode cluster + upgrade effector
Also effectors to:
* select master in the cluster
* set HA priority
* set HA state
commit f99cdf70611f05658b924fb718a284545fa6a0e5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-21T18:12:09Z
add an upgrade effector for the BrooklynNode, and a sample yaml, and improve lifecycle so that stop_* methods destroy the VM and set a STOPPING state
commit 16121fe72bfa3aa90e46acc72f562ddc6c44cab7
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-20T13:51:17Z
clean up of anonymous internal classes, and some minor extensions to predicates available on Entity and String
commit db0a6465447dec4c4b035dfa881ecae3d81a9315
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-23T07:38:55Z
minor cleanups to software, allowing start with no locations, and including stdin for driver.execute commands
commit 9896d58f40a282b1f3625e9dfdb5e21de6fa7a58
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-18T00:44:32Z
WIP brooklyn HA and upgrade
commit ca1c2ad35f2af638ec6094720c53c4c3296ff678
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:51:36Z
fix bug where tasks (eg pollers) are not stopped on unmanagement if the task which started the tasks is the same one which is unmanaging the entity
commit 620d99b68fb23ba8ee31bd6514f0de18b9c58071
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T22:52:37Z
add support for extra CLI parameters to BrooklynNode, use those to run in persistence mode, and final fixes to the in-place upgrade effector
commit e7b278dc0b9b686c096a0579dda49779aeb4b9ed
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-24T23:32:24Z
bunch of clean ups - mainly addressing @aledsage's comments on @neykov's cluster upgrade PR, plus misc things i've noticed.
needs further testing though.
commit 070848e54425502a5d633f9877824ea0fdf76a04
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-25T00:45:36Z
fix swallowed error in dynamic cluster
commit e6ee417bf2f03438563d0c236b1aaa434b91485e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-25T00:46:19Z
WIP smoothing out the experience when setting up the cluster
TODO:
* cluster should take extra config, and then set them as config after we've failed over
* better names of phases
commit 4870dc2baab2300c7d53cacd9f312a64893b9c5e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:11:56Z
more QuorumCheck to util package, using it for new CollectionFunctionals defining a predicate which applies a predicate to a collection
commit 68348cd8345c917b4f029d60e6e692c6918fbb54
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:12:33Z
broolyn cluster upgrade should take extra config, and then set them as config after we've failed over, and has nice names of phases, plus refactor/tidy
commit 839b3a83d2e9d1040bd22702d959985114f2e911
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T14:22:11Z
remove renderer hint for MASTER_NODE -- it is not needed as type Entity gets this automatically, plus it was broken (it needs a special post processing);
and add an enricher to publish at the cluster the url for that node
commit 2a73a6554344ac90ea0b2103dacb5f26a93485b3
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T17:26:14Z
rename HAMode to HighAvailabilityMode, and same for priority
(this brings us in line with convention on treatment of abbrs being camel case,
preferring HttpRestApi over HTTPRESTAPI, but without the weirdness of HaMode; easy enough to be explicit on this API, imho)
commit e703bbeba9bc4b886f72dfc96bf528ab42c351a2
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-26T17:41:30Z
increase the brooklyn node poll frequency to every 2s, to prevent saturating it with monitoring, and other minor tunings to BrooklynNode
commit 3f1df58935eefb4afd9c67d5c19fe5af46acc9d1
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T07:42:16Z
add apache header to new java to kill the RAT problem
commit 9d533192e580233868f5e1a42391ef36146ff1e9
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T13:09:12Z
have deprecated predicates methods point to new classes, use a private unused to preserve the anonymous inner (code review)
commit f04ba23ee8f46c6cab685781ac98646ff2c08ee6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-10-27T13:48:32Z
fix merge conflicts
----
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#issuecomment-60628684
@aledsage all good comments, will address
---
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.
---
[GitHub] incubator-brooklyn pull request: Brooklyn node and cluster upgrade
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/272#discussion_r19418869
--- Diff: utils/common/src/main/java/brooklyn/util/collections/QuorumCheck.java ---
@@ -0,0 +1,106 @@
+/*
+ * 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.util.collections;
+
+import java.io.Serializable;
+
+/**
+ * For checking if a group/cluster is quorate. That is, whether the group has sufficient
+ * healthy members.
+ */
+public interface QuorumCheck {
--- End diff --
used now for collections predicates in `CollectionFunctionals`
---
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.
---