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/01/31 15:56:34 UTC

[GitHub] brooklyn-server pull request #546: Sequencer entity

GitHub user grkvlt opened a pull request:

    https://github.com/apache/brooklyn-server/pull/546

    Sequencer entity

    An entity and a group that manage sequential sensor values

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/grkvlt/brooklyn-server feature/sequencer-entity

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/546.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 #546
    
----
commit 3a67126163db53e392f8523ecd400c71c2c7f3da
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date:   2017-01-31T09:32:29Z

    An entity that emits a sequence of integers

commit 196bb26cd6c685913c6b5957e5ac013cb23eab87
Author: Andrew Donald Kennedy <an...@cloudsoftcorp.com>
Date:   2017-01-31T10:27:27Z

    A group that sets a sequence of values as sensors on members

----


---
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] brooklyn-server issue #546: Sequencer entity

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    @grkvlt (cc @drigodwin) given we have `DynamicCluster.CLUSTER_MEMBER_ID`, where do we need this sequencer entity as opposed to just using 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] brooklyn-server pull request #546: Sequencer entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/546#discussion_r99817492
  
    --- Diff: core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java ---
    @@ -0,0 +1,84 @@
    +/*
    + * 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.entity.stock;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.ImplementedBy;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.annotation.Effector;
    +import org.apache.brooklyn.core.effector.MethodEffector;
    +import org.apache.brooklyn.core.entity.trait.Startable;
    +import org.apache.brooklyn.entity.group.SequenceGroup;
    +import org.apache.brooklyn.util.core.flags.SetFromFlag;
    +
    +/**
    + * An entity that supplies a sequence of values through an effector.
    + * <p>
    + * Usage:
    + * <pre>{@code
    + * - type: org.apache.brooklyn.entity.stock.SequenceEntity
    + *   id: global-sequence
    + *   brooklyn.config:
    + *     sequence.start: 0
    + *     sequence.increment: 1
    + *     sequence.format: "global-%03d"
    + * }</pre>
    + */
    +@ImplementedBy(SequenceEntityImpl.class)
    +public interface SequenceEntity extends Entity, Startable {
    +
    +    AttributeSensor<Integer> SEQUENCE_VALUE = SequenceGroup.SEQUENCE_VALUE;
    +
    +    AttributeSensor<String> SEQUENCE_STRING = SequenceGroup.SEQUENCE_STRING;
    +
    +    @SetFromFlag("sequenceStart")
    +    ConfigKey<Integer> SEQUENCE_START = SequenceGroup.SEQUENCE_START;
    +
    +    @SetFromFlag("sequenceIncrement")
    +    ConfigKey<Integer> SEQUENCE_INCREMENT = SequenceGroup.SEQUENCE_INCREMENT;
    +
    +    @SetFromFlag("sequenceFormat")
    +    ConfigKey<String> SEQUENCE_FORMAT = SequenceGroup.SEQUENCE_FORMAT;
    +
    +    MethodEffector<Void> RESET = new MethodEffector<Void>(SequenceEntity.class, "reset");
    +    MethodEffector<Void> INCREMENT = new MethodEffector<Void>(SequenceEntity.class, "increment");
    +    MethodEffector<Integer> CURRENT_VALUE = new MethodEffector<Integer>(SequenceEntity.class, "currentValue");
    +    MethodEffector<String> CURRENT_STRING = new MethodEffector<String>(SequenceEntity.class, "currentString");
    +    MethodEffector<Integer> NEXT_VALUE = new MethodEffector<Integer>(SequenceEntity.class, "nextValue");
    +    MethodEffector<String> NEXT_STRING = new MethodEffector<String>(SequenceEntity.class, "nextString");
    +
    +    @Effector(description = "Reset the sequence to initial value")
    +    Void reset();
    +
    +    @Effector(description = "Update the value of the sequence by the configured increment")
    +    Void increment();
    +
    +    @Effector(description = "Return the current numeric value of the sequence")
    +    Integer currentValue();
    +
    +    @Effector(description = "Return the current string representation of the sequence")
    +    String currentString();
    +
    +    @Effector(description = "Update and return the next numeric value of the sequence")
    +    Integer nextValue();
    --- End diff --
    
    Good idea, that would make things more obvious and simpler.


---
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] brooklyn-server pull request #546: Sequencer entity

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/546#discussion_r99814504
  
    --- Diff: core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java ---
    @@ -0,0 +1,165 @@
    +/*
    + * 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.entity.group;
    +
    +import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
    +import static org.apache.brooklyn.test.Asserts.*;
    +import static org.apache.brooklyn.core.entity.EntityAsserts.*;
    +
    +import java.util.Set;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.EntityPredicates;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
    +import org.apache.brooklyn.core.test.entity.TestApplication;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableSet;
    +
    +public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
    +
    +    private TestApplication app;
    +    private SequenceGroup group;
    +    private TestEntity e1, e2, e3;
    +
    +    @BeforeMethod(alwaysRun=true)
    +    @Override
    +    public void setUp() throws Exception {
    +        super.setUp();
    +
    +        app = TestApplication.Factory.newManagedInstanceForTests();
    +        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
    +                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, Sensors.newStringSensor("test.sequence"))
    +                .configure(SequenceGroup.SEQUENCE_FORMAT, "test-%02d"));
    +        e1 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        e2 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +        e3 = app.createAndManageChild(EntitySpec.create(TestEntity.class));
    +    }
    +
    +    @AfterMethod(alwaysRun=true)
    +    @Override
    +    public void tearDown() throws Exception {
    +        if (app != null) Entities.destroyAll(app.getManagementContext());
    +
    +        super.tearDown();
    +    }
    +
    +
    +    @Test
    +    public void testGroupDefaults() throws Exception {
    +        assertTrue(group.getMembers().isEmpty());
    +    }
    +
    +    @Test
    +    public void testGroupWithMatchingFilterReturnsOnlyMatchingMembers() throws Exception {
    +        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
    +        assertAttributeEquals(e1, SequenceGroup.SEQUENCE_VALUE, 1);
    +        assertAttributeEquals(group, SequenceGroup.SEQUENCE_NEXT, 2);
    +    }
    +
    +    @Test
    +    public void testGroupConfiguration() throws Exception {
    +        group.setEntityFilter(EntityPredicates.idEqualTo(e1.getId()));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableList.of(e1));
    +        assertAttributeEquals(e1, SequenceGroup.SEQUENCE_STRING, null);
    +        assertAttributeEquals(e1, Sensors.newStringSensor("test.sequence"), "test-01");
    +    }
    +
    +    @Test
    +    public void testAlternateGroupConfiguration() throws Exception {
    +        AttributeSensor<Integer> value = Sensors.newIntegerSensor("test.value");
    +        AttributeSensor<String> string = Sensors.newStringSensor("test.string");
    +        group = app.createAndManageChild(EntitySpec.create(SequenceGroup.class)
    +                .configure(SequenceGroup.SEQUENCE_START, 12345)
    +                .configure(SequenceGroup.SEQUENCE_INCREMENT, 678)
    +                .configure(SequenceGroup.SEQUENCE_VALUE_SENSOR, value)
    +                .configure(SequenceGroup.SEQUENCE_STRING_SENSOR, string)
    +                .configure(SequenceGroup.SEQUENCE_FORMAT, "0x%04X"));
    +        group.setEntityFilter(EntityPredicates.hasInterfaceMatching(".*TestEntity"));
    +
    +        assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(e1, e2, e3));
    +        assertAttributeEquals(e1, value, 12345);
    --- End diff --
    
    Can we be sure that `e1`, `e2`, e3` will be the order of the members? Is that because it is called sequentially with the order that the entities were created?


---
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] brooklyn-server pull request #546: Sequencer entity

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/546#discussion_r99815295
  
    --- Diff: core/src/main/java/org/apache/brooklyn/entity/stock/SequenceEntity.java ---
    @@ -0,0 +1,84 @@
    +/*
    + * 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.entity.stock;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.ImplementedBy;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.config.ConfigKey;
    +import org.apache.brooklyn.core.annotation.Effector;
    +import org.apache.brooklyn.core.effector.MethodEffector;
    +import org.apache.brooklyn.core.entity.trait.Startable;
    +import org.apache.brooklyn.entity.group.SequenceGroup;
    +import org.apache.brooklyn.util.core.flags.SetFromFlag;
    +
    +/**
    + * An entity that supplies a sequence of values through an effector.
    + * <p>
    + * Usage:
    + * <pre>{@code
    + * - type: org.apache.brooklyn.entity.stock.SequenceEntity
    + *   id: global-sequence
    + *   brooklyn.config:
    + *     sequence.start: 0
    + *     sequence.increment: 1
    + *     sequence.format: "global-%03d"
    + * }</pre>
    + */
    +@ImplementedBy(SequenceEntityImpl.class)
    +public interface SequenceEntity extends Entity, Startable {
    +
    +    AttributeSensor<Integer> SEQUENCE_VALUE = SequenceGroup.SEQUENCE_VALUE;
    +
    +    AttributeSensor<String> SEQUENCE_STRING = SequenceGroup.SEQUENCE_STRING;
    +
    +    @SetFromFlag("sequenceStart")
    +    ConfigKey<Integer> SEQUENCE_START = SequenceGroup.SEQUENCE_START;
    +
    +    @SetFromFlag("sequenceIncrement")
    +    ConfigKey<Integer> SEQUENCE_INCREMENT = SequenceGroup.SEQUENCE_INCREMENT;
    +
    +    @SetFromFlag("sequenceFormat")
    +    ConfigKey<String> SEQUENCE_FORMAT = SequenceGroup.SEQUENCE_FORMAT;
    +
    +    MethodEffector<Void> RESET = new MethodEffector<Void>(SequenceEntity.class, "reset");
    +    MethodEffector<Void> INCREMENT = new MethodEffector<Void>(SequenceEntity.class, "increment");
    +    MethodEffector<Integer> CURRENT_VALUE = new MethodEffector<Integer>(SequenceEntity.class, "currentValue");
    +    MethodEffector<String> CURRENT_STRING = new MethodEffector<String>(SequenceEntity.class, "currentString");
    +    MethodEffector<Integer> NEXT_VALUE = new MethodEffector<Integer>(SequenceEntity.class, "nextValue");
    +    MethodEffector<String> NEXT_STRING = new MethodEffector<String>(SequenceEntity.class, "nextString");
    +
    +    @Effector(description = "Reset the sequence to initial value")
    +    Void reset();
    +
    +    @Effector(description = "Update the value of the sequence by the configured increment")
    +    Void increment();
    +
    +    @Effector(description = "Return the current numeric value of the sequence")
    +    Integer currentValue();
    +
    +    @Effector(description = "Return the current string representation of the sequence")
    +    String currentString();
    +
    +    @Effector(description = "Update and return the next numeric value of the sequence")
    +    Integer nextValue();
    --- End diff --
    
    I'd prefer we follow the naming conventions of `AtomicInteger` - so rename `increment` to `incrementAndGet`, and delete `nextValue` + `nextString`.
    
    I'm inclined to let the caller do the formatting of the result, rather than having separate `nextValue` and `nextString`. The difference between those two methods, and their interaction, feels as though it might confuse.


---
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] brooklyn-server issue #546: Sequencer entity

Posted by mikezaccardo <gi...@git.apache.org>.
Github user mikezaccardo commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    @grkvlt this would indeed be useful for the Hyperledger Fabric multi-cluster in place of this entity: https://github.com/cloudsoft/brooklyn-hyperledger/blob/master/catalog/hyperledger/multi-cluster.bom#L205-L251


---
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] brooklyn-server pull request #546: Sequencer entity

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/546


---
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] brooklyn-server issue #546: Sequencer entity

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    I feel like this will soon be superseded, by being able to point at some shared-scoped atomic integer and request a `getAndIncrement` directly in YAML as part of `start`.  Haven't looked in detail but if that impl could be done as an extension of `DynamicGroup` could the code here be simplified?
    
    That said not that opposed to adding for now if useful with an expectation it might fall away.


---
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] brooklyn-server issue #546: Sequencer entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    @mikezaccardo is this still useful, e.g. for HLF blueprints?


---
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] brooklyn-server issue #546: Sequencer entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    @aledsage the use case in mind was to sequentially number across multiple clusters (i.e a fabric spread around several locations)


---
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] brooklyn-server issue #546: Sequencer entity

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/546
  
    @drigodwin we need to document this, I will add some descriptive text explaining this for Brooklyn docs


---
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] brooklyn-server pull request #546: Sequencer entity

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/546#discussion_r99813663
  
    --- Diff: core/src/test/java/org/apache/brooklyn/entity/group/SequenceGroupTest.java ---
    @@ -0,0 +1,165 @@
    +/*
    + * 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.entity.group;
    +
    +import static org.apache.brooklyn.test.Asserts.assertEqualsIgnoringOrder;
    +import static org.apache.brooklyn.test.Asserts.*;
    +import static org.apache.brooklyn.core.entity.EntityAsserts.*;
    +
    +import java.util.Set;
    +
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.entity.EntitySpec;
    +import org.apache.brooklyn.api.sensor.AttributeSensor;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.EntityPredicates;
    +import org.apache.brooklyn.core.sensor.Sensors;
    +import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
    +import org.apache.brooklyn.core.test.entity.TestApplication;
    +import org.apache.brooklyn.core.test.entity.TestEntity;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.base.Predicates;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableSet;
    +
    +public class SequenceGroupTest extends BrooklynAppUnitTestSupport {
    +
    +    private TestApplication app;
    +    private SequenceGroup group;
    +    private TestEntity e1, e2, e3;
    +
    +    @BeforeMethod(alwaysRun=true)
    +    @Override
    +    public void setUp() throws Exception {
    +        super.setUp();
    +
    +        app = TestApplication.Factory.newManagedInstanceForTests();
    --- End diff --
    
    super-class will have instantiated app - don't do it here, and delete the private field `app`. Also delete `tearDown` as that is done by super.


---
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.
---