You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by aledsage <gi...@git.apache.org> on 2014/11/07 21:23:04 UTC

[GitHub] incubator-brooklyn pull request: Allow a UsageListener (i.e. for m...

GitHub user aledsage opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/310

    Allow a UsageListener (i.e. for metering info) to be registered

    @alasdairhodge can you review this please?

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

    $ git pull https://github.com/aledsage/incubator-brooklyn feature/metering-listener

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

    https://github.com/apache/incubator-brooklyn/pull/310.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 #310
    
----
commit e1ab21c8a0d29930f8ee7b34fb875171c5c429ac
Author: Aled Sage <al...@gmail.com>
Date:   2014-11-05T22:44:40Z

    Adds Listener support for usage/metering info

commit 8d488c1b51b05e4027c63fd97e63a86cd7256de5
Author: Aled Sage <al...@gmail.com>
Date:   2014-11-07T19:44:14Z

    TypeCoercions: recursively unpack for List<T>
    
    - e.g. if given “1,2” for type List<Integer>, then first pass will
      coerce to List.of(“1”, “2”), and second pass will coerce to
      List.of(1,2)

commit 3d0771014a0b42c31afd79ac43efa0f7713bf399
Author: Aled Sage <al...@gmail.com>
Date:   2014-11-07T19:44:34Z

    Read UsageListeners from config in brooklyn.properties

----


---
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: Allow a UsageListener (i.e. for m...

Posted by alasdairhodge <gi...@git.apache.org>.
Github user alasdairhodge commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/310#issuecomment-62361612
  
    Minor comments, but loooks 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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310


---
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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#issuecomment-62391558
  
    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: Allow a UsageListener (i.e. for m...

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/310#discussion_r20077066
  
    --- Diff: core/src/main/java/brooklyn/management/internal/UsageManager.java ---
    @@ -18,20 +18,47 @@
      */
     package brooklyn.management.internal;
     
    +import java.util.List;
    +import java.util.Map;
     import java.util.Set;
     
    +import brooklyn.config.ConfigKey;
     import brooklyn.entity.Application;
    +import brooklyn.entity.basic.ConfigKeys;
     import brooklyn.entity.basic.Lifecycle;
     import brooklyn.location.Location;
     import brooklyn.management.usage.ApplicationUsage;
    +import brooklyn.management.usage.ApplicationUsage.ApplicationEvent;
     import brooklyn.management.usage.LocationUsage;
    +import brooklyn.management.usage.LocationUsage.LocationEvent;
     
     import com.google.common.annotations.Beta;
     import com.google.common.base.Predicate;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.reflect.TypeToken;
     
     @Beta
     public interface UsageManager {
     
    +    @SuppressWarnings("serial")
    +    public static final ConfigKey<List<UsageListener>> USAGE_LISTENERS = ConfigKeys.newConfigKey(
    +            new TypeToken<List<UsageListener>>() {},
    +            "brooklyn.usageManager.listeners", "Optional usage listeners (i.e. for metering)",
    +            ImmutableList.<UsageListener>of());
    +
    +    public static interface UsageListener {
    --- End diff --
    
    Given it's in `UsageManager` then I'm ok with the name `UsageListener` rather than `ManagementEventListener` (the latter might suggest a wider range of events).


---
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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#discussion_r20072876
  
    --- Diff: software/base/src/test/java/brooklyn/management/usage/RecordingUsageListener.java ---
    @@ -0,0 +1,74 @@
    +/*
    + * 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.management.usage;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +import brooklyn.management.internal.UsageManager.UsageListener;
    +import brooklyn.management.usage.ApplicationUsage.ApplicationEvent;
    +import brooklyn.management.usage.LocationUsage.LocationEvent;
    +import brooklyn.util.collections.MutableList;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.Lists;
    +
    +public class RecordingUsageListener implements UsageListener {
    +
    +    private final List<List<?>> events = Lists.newCopyOnWriteArrayList();
    +    
    +    protected List<List<?>> getMutableEvents() {
    +        return events;
    +    }
    +    
    +    @Override
    +    public void onApplicationEvent(String applicationId, String applicationName, String entityType, 
    +            Map<String, String> metadata, ApplicationEvent event) {
    +        getMutableEvents().add(MutableList.of("application", applicationId, applicationName, entityType, metadata, event));
    --- End diff --
    
    Why insist on going through the public interface to access the field? Just curious.


---
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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#discussion_r20072489
  
    --- Diff: core/src/main/java/brooklyn/management/internal/UsageManager.java ---
    @@ -18,20 +18,47 @@
      */
     package brooklyn.management.internal;
     
    +import java.util.List;
    +import java.util.Map;
     import java.util.Set;
     
    +import brooklyn.config.ConfigKey;
     import brooklyn.entity.Application;
    +import brooklyn.entity.basic.ConfigKeys;
     import brooklyn.entity.basic.Lifecycle;
     import brooklyn.location.Location;
     import brooklyn.management.usage.ApplicationUsage;
    +import brooklyn.management.usage.ApplicationUsage.ApplicationEvent;
     import brooklyn.management.usage.LocationUsage;
    +import brooklyn.management.usage.LocationUsage.LocationEvent;
     
     import com.google.common.annotations.Beta;
     import com.google.common.base.Predicate;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.reflect.TypeToken;
     
     @Beta
     public interface UsageManager {
     
    +    @SuppressWarnings("serial")
    +    public static final ConfigKey<List<UsageListener>> USAGE_LISTENERS = ConfigKeys.newConfigKey(
    +            new TypeToken<List<UsageListener>>() {},
    +            "brooklyn.usageManager.listeners", "Optional usage listeners (i.e. for metering)",
    +            ImmutableList.<UsageListener>of());
    +
    +    public static interface UsageListener {
    --- End diff --
    
    Also, there's nothing about this interface's methods that suggests "usage" or "billing", despite the initial use-case. Perhaps a more neutral name is apt, how about `ManagementEventListener`?


---
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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#issuecomment-62373339
  
    Have incorporated comments. Will wait for jenkins to confirm all is fine, and then will 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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#discussion_r20072381
  
    --- Diff: core/src/main/java/brooklyn/management/internal/NonDeploymentUsageManager.java ---
    @@ -94,4 +94,22 @@ public ApplicationUsage getApplicationUsage(String appId) {
                 throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
             }
         }
    +
    +    @Override
    +    public void addUsageListener(UsageListener listener) {
    +        if (isInitialManagementContextReal()) {
    +            initialManagementContext.getUsageManager().addUsageListener(listener);
    +        } else {
    +            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
    +        }
    +    }
    +
    +    @Override
    +    public void removeUsageListener(UsageListener listener) {
    +        if (isInitialManagementContextReal()) {
    +            initialManagementContext.getUsageManager().removeUsageListener(listener);
    +        } else {
    +            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
    +        }
    +    }
    --- End diff --
    
    Those `isInitialManagementContextReal` checks are a code smell. Cleaner for the manager to always delegate to the context, and have the `NonDeploymentManagementContext` throw `UnsupportedOperationException` where appropriate.
    
    Happy for that to be done later,could use a TODO however.


---
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: Allow a UsageListener (i.e. for m...

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

    https://github.com/apache/incubator-brooklyn/pull/310#discussion_r20072171
  
    --- Diff: core/src/main/java/brooklyn/management/internal/UsageManager.java ---
    @@ -18,20 +18,47 @@
      */
     package brooklyn.management.internal;
     
    +import java.util.List;
    +import java.util.Map;
     import java.util.Set;
     
    +import brooklyn.config.ConfigKey;
     import brooklyn.entity.Application;
    +import brooklyn.entity.basic.ConfigKeys;
     import brooklyn.entity.basic.Lifecycle;
     import brooklyn.location.Location;
     import brooklyn.management.usage.ApplicationUsage;
    +import brooklyn.management.usage.ApplicationUsage.ApplicationEvent;
     import brooklyn.management.usage.LocationUsage;
    +import brooklyn.management.usage.LocationUsage.LocationEvent;
     
     import com.google.common.annotations.Beta;
     import com.google.common.base.Predicate;
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.reflect.TypeToken;
     
     @Beta
     public interface UsageManager {
     
    +    @SuppressWarnings("serial")
    +    public static final ConfigKey<List<UsageListener>> USAGE_LISTENERS = ConfigKeys.newConfigKey(
    +            new TypeToken<List<UsageListener>>() {},
    +            "brooklyn.usageManager.listeners", "Optional usage listeners (i.e. for metering)",
    +            ImmutableList.<UsageListener>of());
    +
    +    public static interface UsageListener {
    --- End diff --
    
    Redundant `static`


---
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: Allow a UsageListener (i.e. for m...

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/310#discussion_r20077403
  
    --- Diff: software/base/src/test/java/brooklyn/management/usage/RecordingUsageListener.java ---
    @@ -0,0 +1,74 @@
    +/*
    + * 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.management.usage;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +import brooklyn.management.internal.UsageManager.UsageListener;
    +import brooklyn.management.usage.ApplicationUsage.ApplicationEvent;
    +import brooklyn.management.usage.LocationUsage.LocationEvent;
    +import brooklyn.util.collections.MutableList;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.Lists;
    +
    +public class RecordingUsageListener implements UsageListener {
    +
    +    private final List<List<?>> events = Lists.newCopyOnWriteArrayList();
    +    
    +    protected List<List<?>> getMutableEvents() {
    +        return events;
    +    }
    +    
    +    @Override
    +    public void onApplicationEvent(String applicationId, String applicationName, String entityType, 
    +            Map<String, String> metadata, ApplicationEvent event) {
    +        getMutableEvents().add(MutableList.of("application", applicationId, applicationName, entityType, metadata, event));
    --- End diff --
    
    It was for another test to sub-class it, so that the `getMutableEvents()` returns a `static` events field. Thus we could test the instance that was created reflectively (whose class was defined in `brooklyn.properties`).
    
    I've changed this for the static instance to just record a reference to the listener instances, rather than relying on `getMutableEvents()`. The test-logic therefore doesn't leak into the other class as much.


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