You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by grkvlt <gi...@git.apache.org> on 2017/09/13 17:07:05 UTC
[GitHub] brooklyn-server pull request #822: New periodic and scheduled effector polic...
GitHub user grkvlt opened a pull request:
https://github.com/apache/brooklyn-server/pull/822
New periodic and scheduled effector policies
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/grkvlt/brooklyn-server feature/time-policies
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/brooklyn-server/pull/822.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 #822
----
commit 060d7d114cd89050bdcbdecb3129e1425f944f61
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date: 2017-09-13T17:03:56Z
New periodic and scedukled effector policies
----
---
[GitHub] brooklyn-server pull request #822: New periodic and scheduled effector polic...
Posted by drigodwin <gi...@git.apache.org>.
Github user drigodwin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/822#discussion_r138886618
--- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/PeriodicEffectorPolicy.java ---
@@ -0,0 +1,151 @@
+/*
+ * 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 org.apache.brooklyn.policy.action;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.brooklyn.api.effector.Effector;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.DurationPredicates;
+import org.apache.brooklyn.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.reflect.TypeToken;
+
+/**
+ * A {@link Policy} that executes an {@link Effector} at specific intervals.
+ * <p>
+ * The following example shows a pair of policies that resize a cluster
+ * from one to ten entities during the day and back to one at night,:
+ * <pre>{@code
+ * brooklyn.policies:
+ * - type: org.apache.brooklyn.policy.action.ScheduledEffectorPolicy
+ * brooklyn.config:
+ * effector: resize
+ * args:
+ * desiredSize: 10
+ * period: 1 day
+ * time: 08:00:00
+ * - type: org.apache.brooklyn.policy.action.ScheduledEffectorPolicy
+ * brooklyn.config:
+ * effector: resize
+ * args:
+ * desiredSize: 1
+ * period: 1 day
+ * time: 18:00:00
+ * }</pre>
--- End diff --
This example is for the `ScheduledEffectorPolicy` not the `PeriodicEffectorPolicy`
---
[GitHub] brooklyn-server issue #822: New periodic and scheduled effector policies
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:
https://github.com/apache/brooklyn-server/pull/822
(yaml could be used in a test :nudge:)
---
[GitHub] brooklyn-server issue #822: New periodic and scheduled effector policies
Posted by drigodwin <gi...@git.apache.org>.
Github user drigodwin commented on the issue:
https://github.com/apache/brooklyn-server/pull/822
I have added a PR for the documentation for this [here](https://github.com/apache/brooklyn-docs/pull/213).
---
[GitHub] brooklyn-server issue #822: New periodic and scheduled effector policies
Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:
https://github.com/apache/brooklyn-server/pull/822
@ahgittin I will do some testing of how this interacts with #818 but it will be in a separate PR so that this can get into the 0.12 RC
---
[GitHub] brooklyn-server pull request #822: New periodic and scheduled effector polic...
Posted by drigodwin <gi...@git.apache.org>.
Github user drigodwin commented on a diff in the pull request:
https://github.com/apache/brooklyn-server/pull/822#discussion_r138886787
--- Diff: policy/src/main/java/org/apache/brooklyn/policy/action/PeriodicEffectorPolicy.java ---
@@ -0,0 +1,151 @@
+/*
+ * 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 org.apache.brooklyn.policy.action;
+
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.brooklyn.api.effector.Effector;
+import org.apache.brooklyn.api.entity.EntityLocal;
+import org.apache.brooklyn.api.policy.Policy;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
+import org.apache.brooklyn.api.sensor.SensorEvent;
+import org.apache.brooklyn.api.sensor.SensorEventListener;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.sensor.Sensors;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.time.Duration;
+import org.apache.brooklyn.util.time.DurationPredicates;
+import org.apache.brooklyn.util.time.Time;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
+import com.google.common.reflect.TypeToken;
+
+/**
+ * A {@link Policy} that executes an {@link Effector} at specific intervals.
+ * <p>
+ * The following example shows a pair of policies that resize a cluster
+ * from one to ten entities during the day and back to one at night,:
+ * <pre>{@code
+ * brooklyn.policies:
+ * - type: org.apache.brooklyn.policy.action.ScheduledEffectorPolicy
+ * brooklyn.config:
+ * effector: resize
+ * args:
+ * desiredSize: 10
+ * period: 1 day
+ * time: 08:00:00
+ * - type: org.apache.brooklyn.policy.action.ScheduledEffectorPolicy
+ * brooklyn.config:
+ * effector: resize
+ * args:
+ * desiredSize: 1
+ * period: 1 day
+ * time: 18:00:00
+ * }</pre>
+ */
+@Beta
+public class PeriodicEffectorPolicy extends AbstractScheduledEffectorPolicy {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PeriodicEffectorPolicy.class);
+
+ public static final ConfigKey<Boolean> RUNNING = ConfigKeys.builder(Boolean.class)
+ .name("running")
+ .description("Set if the executor has started")
+ .defaultValue(Boolean.FALSE)
+ .build();
+
+ public static final ConfigKey<Duration> PERIOD = ConfigKeys.builder(Duration.class)
+ .name("period")
+ .description("The duration between executions of this policy")
+ .constraint(DurationPredicates.positive())
+ .defaultValue(Duration.hours(1))
+ .build();
+
+ public static final ConfigKey<AttributeSensor<Boolean>> START_SENSOR = ConfigKeys.builder(new TypeToken<AttributeSensor<Boolean>>() { })
+ .name("start.sensor")
+ .description("The sensor which should trigger starting the periodic execution scheduler")
+ .defaultValue(Startable.SERVICE_UP)
+ .build();
+
+ protected AtomicBoolean running = new AtomicBoolean(false);
+
+ public PeriodicEffectorPolicy() {
+ this(MutableMap.<String,Object>of());
+ }
+
+ public PeriodicEffectorPolicy(Map<String,?> props) {
+ super(props);
+ }
+
+ @Override
+ public void setEntity(final EntityLocal entity) {
+ super.setEntity(entity);
+
+ AttributeSensor<Boolean> sensor = config().get(START_SENSOR);
+ subscriptions().subscribe(entity, sensor, handler);
+ }
+
+ @Override
+ public void rebind() {
+ // XXX Will the AtomicBoolean field be saved during rebind?
--- End diff --
Probably resolve this question before merging...
---
[GitHub] brooklyn-server issue #822: New periodic and scheduled effector policies
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:
https://github.com/apache/brooklyn-server/pull/822
cool @grkvlt - wonder if you could do two things:
* merge #818 here for testing and follow the pattern there to set trigger and action highlights
* include a YAML illustrating use of these policies
---
[GitHub] brooklyn-server pull request #822: New periodic and scheduled effector polic...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/brooklyn-server/pull/822
---