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/07/18 08:12:31 UTC
[GitHub] incubator-brooklyn pull request: brooklyn node and effector parame...
GitHub user ahgittin opened a pull request:
https://github.com/apache/incubator-brooklyn/pull/78
brooklyn node and effector parameter improvements
adds a `BrooklynEntityMirror` which reflects what an entity in a remote brooklyn node is doing, and some nifty ways to test this
fixes a bug in effector parameters, was being dejsoned to `Map<String,String>`, now allows non-string parameters -- see https://github.com/ahgittin/incubator-brooklyn/commit/9ff81eaae79e14d7584a605ca41c948a9b19a45e for the fix and the unit test
also uses yaml to coerce strings to maps /cc @frontiertown - this was causing errors for people who couldn't get the json just right, yaml is much more forgiving of quotes etc (and in fact it supports key=value so the fallback strategy could be dropped!) - lots of tests for this in https://github.com/ahgittin/incubator-brooklyn/blob/96d631624eeea12dd724cc2899a17d1a062119c3/core/src/test/java/brooklyn/util/internal/TypeCoercionsTest.java
NOTE: this builds on #77 as there were merge conflicts otherwise; review and merge that PR first and this one will be much smaller (it's just the last 5 commits)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/ahgittin/incubator-brooklyn brooklyn-node-more-2
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-brooklyn/pull/78.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 #78
----
commit bf933a197b62b8390d045cae53c03253aecf8d25
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T16:37:29Z
suppress warning of DTO with no contents, when it has a description which says where the content comes from
commit 16894ff6c5ab590bed4408d253fa9f0eb3090dde
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T16:54:03Z
better warnings when icons are missing
commit fad97b318063da944af5bb07cd2dc488b070dc54
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T18:08:47Z
prevent warning of entitlement context on forwarded requests (eg /) and improve detail for logging REST info
commit ff5b6c768ff4500224ff365d82979770f0e044d7
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T18:55:32Z
Add a UserFacingException which can be used to indicate to suppress stack traces, and tidy up how REST errors are reported and returned
commit 99faa86be52e313918b66b7e15dce3da2cae0a4c
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T20:06:58Z
demote dull log messages to 'trace'
commit 0374a692ef9089b75b0f3befb0f1a7ff1539402b
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T20:07:59Z
allow a CREATE_UNMANAGED mode for locations, used when peeking, so that we don't get lots of logging on the frequent location listings from REST API
commit 9b6ff0b5cef3109ff4ad52574f1b822bce338c12
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T05:09:33Z
port WebAppRunnerTest to java and improve shutdown
commit 7c9a0b3e56e940038740362b3e027441e76294d5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T04:38:46Z
test and rat fixes, and log message tidy
commit 193ad569f4b7c8c0ccb6e867f4e44c9eac9289e5
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T05:26:47Z
deprecte ApplicationBuilder.newManagedInstance to encourage mgmt context to be supplied, and convert many existing usages to conveniences which load LocalManagementContextForTests (to speed up tests by preventng catalog parsing)
commit 7942e494cd0fb36371a06717f3aa2286b70f47b6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T06:02:50Z
move some many-times test to integration group so build runs faster
commit 10df5f4d3d28fd49ab4f4ac9b277b2f54b6b2ed0
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-17T16:40:58Z
tidies of Brooklyn node (warnings, logging)
commit 96d631624eeea12dd724cc2899a17d1a062119c3
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T03:29:12Z
promote snake-yaml dependency and Yamls utility to utils package, and use yaml parsing for map coercion to be much more flexible in terms of string-to-map coercion
commit a3342efca4d227f97ec462acac5eecbbeb91bd44
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T03:32:55Z
remove dead code and tidy warnings in camp code
commit 666d1bf7e10b99b00fc0b4fcecde0c8be9f2b1c6
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T03:50:20Z
more tests for BrooklynNode, including test which uses REST API of local instance (and new "SameBrooklynNodeImpl" semi-mock); and adds BrooklynEntityMirror with test
commit 9ff81eaae79e14d7584a605ca41c948a9b19a45e
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Date: 2014-07-18T04:39:24Z
support effector parameters which are maps
----
---
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 effector parame...
Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/78#issuecomment-49428664
See PR comments in #77, to be addressed and merged.
Then this PR will need rebased so it really just contains the last 5 commits.
---
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 effector parame...
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/78#issuecomment-49451472
thanks @neykov , i've cleaned up those bits, well found. merging.
---
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 effector parame...
Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/78#issuecomment-49433166
rebased, now just shows the recent changes, updated based on @sjcorbett's effector param fix (for which now this just provides a test, and better string-to-map parsing) as well as @neykov's cleanup of camp yaml parsing
---
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 effector parame...
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/78#discussion_r15118755
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java ---
@@ -0,0 +1,175 @@
+/*
+ * 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.net.URI;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.HttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.gson.Gson;
+
+import brooklyn.entity.basic.AbstractEntity;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.BrooklynTaskTags;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.trait.Startable;
+import brooklyn.event.AttributeSensor;
+import brooklyn.event.basic.Sensors;
+import brooklyn.event.feed.http.HttpFeed;
+import brooklyn.event.feed.http.HttpPollConfig;
+import brooklyn.util.collections.Jsonya;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.http.HttpTool;
+import brooklyn.util.http.HttpTool.HttpClientBuilder;
+import brooklyn.util.http.HttpToolResponse;
+import brooklyn.util.net.Urls;
+import brooklyn.util.stream.Streams;
+import brooklyn.util.task.Tasks;
+
+public class BrooklynEntityMirrorImpl extends AbstractEntity implements BrooklynEntityMirror {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynEntityMirrorImpl.class);
+
+ private HttpFeed mirror;
+
+ @Override
+ public void init() {
+ super.init();
+ connectSensors();
+ // tag this child with the tenant owner name
+ this.addTag(String.format("ibm.mms.tenant.entity:%s", getConfig(BrooklynNode.MANAGEMENT_USER)));
--- End diff --
MMS specific code in generic Brooklyn?
---
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 effector parame...
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/78#discussion_r15118769
--- Diff: software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynEntityMirrorImpl.java ---
@@ -0,0 +1,175 @@
+/*
+ * 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.net.URI;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.HttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.gson.Gson;
+
+import brooklyn.entity.basic.AbstractEntity;
+import brooklyn.entity.basic.Attributes;
+import brooklyn.entity.basic.BrooklynTaskTags;
+import brooklyn.entity.basic.Entities;
+import brooklyn.entity.basic.EntityFunctions;
+import brooklyn.entity.basic.Lifecycle;
+import brooklyn.entity.brooklynnode.BrooklynNode;
+import brooklyn.entity.effector.EffectorBody;
+import brooklyn.entity.effector.Effectors;
+import brooklyn.entity.trait.Startable;
+import brooklyn.event.AttributeSensor;
+import brooklyn.event.basic.Sensors;
+import brooklyn.event.feed.http.HttpFeed;
+import brooklyn.event.feed.http.HttpPollConfig;
+import brooklyn.util.collections.Jsonya;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.config.ConfigBag;
+import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.http.HttpTool;
+import brooklyn.util.http.HttpTool.HttpClientBuilder;
+import brooklyn.util.http.HttpToolResponse;
+import brooklyn.util.net.Urls;
+import brooklyn.util.stream.Streams;
+import brooklyn.util.task.Tasks;
+
+public class BrooklynEntityMirrorImpl extends AbstractEntity implements BrooklynEntityMirror {
+
+ private static final Logger log = LoggerFactory.getLogger(BrooklynEntityMirrorImpl.class);
+
+ private HttpFeed mirror;
+
+ @Override
+ public void init() {
+ super.init();
+ connectSensors();
+ // tag this child with the tenant owner name
+ this.addTag(String.format("ibm.mms.tenant.entity:%s", getConfig(BrooklynNode.MANAGEMENT_USER)));
+ getMutableEntityType().addEffector(Effectors.effector(Startable.STOP).impl(new StopAndExpungeEffector()).build());
+ }
+
+ protected void connectSensors() {
+ Function<HttpToolResponse, Void> mirrorSensors = new Function<HttpToolResponse,Void>() {
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Void apply(HttpToolResponse input) {
+ Map sensors = new Gson().fromJson(input.getContentAsString(), Map.class);
+ for (Object kv: sensors.entrySet())
+ setAttribute(Sensors.newSensor(Object.class, ""+((Map.Entry)kv).getKey()), ((Map.Entry)kv).getValue());
+ setAttribute(MIRROR_STATUS, "normal");
+ return null;
+ }
+ };
+
+ String sensorsUri = Urls.mergePaths(
+ Preconditions.checkNotNull(getConfig(MIRRORED_ENTITY_URL), "Required config: "+MIRRORED_ENTITY_URL),
+ "sensors/current-state");
+
+ mirror = HttpFeed.builder().entity(this)
+ .baseUri(sensorsUri)
+ .credentialsIfNotNull(getConfig(BrooklynNode.MANAGEMENT_USER), getConfig(BrooklynNode.MANAGEMENT_PASSWORD))
+ .period(getConfig(POLL_PERIOD))
+ .poll(HttpPollConfig.forMultiple()
+ .onSuccess(mirrorSensors)
+ .onFailureOrException(EntityFunctions.settingSensorsConstantFunction(this, MutableMap.<AttributeSensor<?>,Object>of(
+ Attributes.SERVICE_STATE, Lifecycle.ON_FIRE,
+ MIRROR_STATUS, "error contacting service"
+ ))) )
+ .build();
+ }
+
+ protected void disconnectSensors() {
+ if (mirror != null) mirror.stop();
+ }
+
+ @Override
+ public void destroy() {
+ disconnectSensors();
+ }
+
+ public static class RemoteEffector<T> extends EffectorBody<T> {
+ public final String remoteEffectorName;
+ public final Function<byte[], T> resultParser;
+
+ /** creates an effector implementation which POSTs to a remote effector endpoint, optionally converting
+ * the byte[] response (if resultParser is null then null is returned) */
+ public RemoteEffector(String remoteEffectorName, @Nullable Function<byte[],T> resultParser) {
+ this.remoteEffectorName = remoteEffectorName;
+ this.resultParser = resultParser;
+ }
+
+ @Override
+ public T call(ConfigBag parameters) {
+ String baseUri = Preconditions.checkNotNull(entity().getConfig(MIRRORED_ENTITY_URL), "Cannot be invoked without an entity URL");
+ HttpClientBuilder builder = HttpTool.httpClientBuilder()
+ .trustAll()
+ .laxRedirect(true)
+ .uri(baseUri);
+ if (entity().getConfig(MANAGEMENT_USER)!=null)
+ builder.credentials(new UsernamePasswordCredentials(entity().getConfig(MANAGEMENT_USER), entity().getConfig(MANAGEMENT_PASSWORD)));
+ HttpClient client = builder.build();
+
+ byte[] result = submit(client, URI.create(Urls.mergePaths(baseUri, "effectors/"+remoteEffectorName)), parameters.getAllConfig());
--- End diff --
Path escape remoteEffectorName?
---
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 effector parame...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/incubator-brooklyn/pull/78
---
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 effector parame...
Posted by richardcloudsoft <gi...@git.apache.org>.
Github user richardcloudsoft commented on the pull request:
https://github.com/apache/incubator-brooklyn/pull/78#issuecomment-49589730
@ahgittin does this *remove* the ability to parse JSON maps? (If I'm reading it correctly... Jackson `ObjectMapper` has been removed completely...)
I'm using this JSON parsing ability in a different project, so I'd quite like to keep it, if there is a sane way to support both JSON and YAML...
BTW my Twitter is @frontiertown but on GitHub I'm @richardcloudsoft
---
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.
---