[ 
https://issues.apache.org/jira/browse/BROOKLYN-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15957112#comment-15957112
 ] 

ASF GitHub Bot commented on BROOKLYN-460:
-----------------------------------------

Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/612#discussion_r109958476
  
    --- Diff: 
camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/TagsYamlTest.java
 ---
    @@ -0,0 +1,171 @@
    +/*
    + * Copyright 2016 The Apache Software Foundation.
    + *
    + * Licensed 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.camp.brooklyn.spi.dsl;
    +
    +import com.google.common.base.Predicate;
    +import com.google.common.collect.Iterables;
    +import org.apache.brooklyn.api.entity.Entity;
    +import org.apache.brooklyn.api.mgmt.Task;
    +import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
    +import org.apache.brooklyn.core.entity.EntityInternal;
    +import org.apache.brooklyn.core.mgmt.BrooklynTags;
    +import org.apache.brooklyn.entity.stock.BasicApplication;
    +import org.apache.brooklyn.test.Asserts;
    +import org.apache.brooklyn.util.exceptions.CompoundRuntimeException;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
    +import org.testng.annotations.Test;
    +
    +import javax.annotation.Nullable;
    +import java.io.Serializable;
    +import java.util.Set;
    +import java.util.concurrent.Callable;
    +
    +import static org.testng.Assert.assertTrue;
    +import static org.testng.Assert.fail;
    +
    +public class TagsYamlTest extends AbstractYamlTest {
    +    @Test
    +    public void testBrooklynCampSingleTag() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "    - hi");
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("hi")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampMultipleTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - \"2\"",
    +                "  - \"- 3\"");
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("2")));
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("- 
3")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampTagsFailNonList() throws Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "    tag1: true",
    +                    "    tag2: 2");
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            
Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
 must be a list, is: ");
    +        }
    +    }
    +
    +    @Test
    +    public void testBrooklynCampKnowsIntegerTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - 3");
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag(3)));
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampObjectTags() throws Exception {
    +        final Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - tag1",
    +                "  - $brooklyn:object:",
    +                "      type: " + 
TagsTestSerializableObject.class.getName());
    +        assertTrue(Iterables.any(getTagsEventually(app), new 
Predicate<Object>() {
    +            @Override
    +            public boolean apply(@Nullable Object input) {
    +                return input instanceof BrooklynTags.CampBrooklynTag && 
((BrooklynTags.CampBrooklynTag)input).getContents() instanceof 
TagsTestSerializableObject;
    +            }
    +        }));
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("tag1")));
    +    }
    +
    +    @Test
    +    public void testBrooklynCampFailDslTags() throws Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "  - tag1",
    +                    "  - $brooklyn:object:",
    +                    "      type: 
"+TagsTestSerializableObject.class.getName(),
    +                    "      constructor.args:",
    +                    "      - $brooklyn:attributeWhenReady(\"host.name\")");
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            
Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
 should not contain DeferredSupplier objects, such example is using 
$brooklyn:attributeWhenReady");
    +        }
    +    }
    +
    +    @Test
    +    public void testBrooklynCampFailNonSerializableDslTags() throws 
Exception {
    +        try {
    +            final Entity app = createAndStartApplication(
    +                    "services:",
    +                    "- type: " + BasicApplication.class.getName(),
    +                    "  brooklyn.tags:",
    +                    "  - tag1",
    +                    "  - $brooklyn:object:",
    +                    "      type: "+NonSerializable.class.getName());
    +            fail("Should throw IllegalArgumentException exception.");
    +        } catch (CompoundRuntimeException e) {
    +            
Asserts.assertStringContainsAtLeastOne(Exceptions.getFirstInteresting(e).getMessage(),"brooklyn.tags
 should not contain DeferredSupplier objects, such example is using 
$brooklyn:attributeWhenReady");
    +        }
    +    }
    +
    +    public static class NonSerializable {}
    +
    +    @Test
    +    public void testTagWithDslValue() throws Exception {
    +        Entity app = createAndStartApplication(
    +                "services:",
    +                "- type: " + BasicApplication.class.getName(),
    +                "  brooklyn.tags:",
    +                "  - $brooklyn:literal(\"myval\")");
    +        
assertTrue(getTagsEventually(app).contains(BrooklynTags.newCampBrooklynTag("myval")));
    +    }
    +
    +    public static class TagsTestSerializableObject implements Serializable 
{
    +        private static final long serialVersionUID = -5150802977330637460L;
    +
    +        public TagsTestSerializableObject() {}
    +        public TagsTestSerializableObject(Object arg1) {}
    +    }
    +
    +    private static Set<Object> getTagsEventually(final Entity entity) 
throws Exception {
    +        Task<Set<Object>> result = 
((EntityInternal)entity).getExecutionContext().submit(new 
Callable<Set<Object>>() {
    +            @Override
    +            public Set<Object> call() throws Exception {
    +                return entity.tags().getTags();
    --- End diff --
    
    Agree, should be there since app creation.


> Brooklyn Camp syntax for adding tags to an entity spec
> ------------------------------------------------------
>
>                 Key: BROOKLYN-460
>                 URL: https://issues.apache.org/jira/browse/BROOKLYN-460
>             Project: Brooklyn
>          Issue Type: New Feature
>            Reporter: Valentin Aitken
>            Priority: Minor
>
> Current requirement is to be able to supply String tags in an entity spec in 
> YAML so it can be then retrieved via REST API with {{GET 
> /v1/applications/<appId>/entities/<entityId>/tags}}.
> Example usage in a YAML blueprint:
> {noformat}
> services:
> - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
>   brooklyn.tags:
>   - tag1
>   - tag2
> {noformat}
> Please shout if you have further requirements for {{brooklyn.tags}}.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to