You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2014/11/04 15:30:02 UTC
[08/18] git commit: Initialize the context catalog item id from the
current task's context entity.
Initialize the context catalog item id from the current task's context entity.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/0eb67633
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/0eb67633
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/0eb67633
Branch: refs/heads/master
Commit: 0eb67633c168237154134af3028ba4048845efa5
Parents: 36ee1e0
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Fri Oct 31 14:41:50 2014 +0200
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Fri Oct 31 14:44:45 2014 +0200
----------------------------------------------------------------------
.../basic/AbstractBrooklynObjectSpec.java | 1 +
.../java/brooklyn/basic/ApiObjectsFactory.java | 41 ++++++++++++++++++++
.../brooklyn/basic/AbstractBrooklynObject.java | 2 +
.../brooklyn/basic/ApiObjectsFactoryImpl.java | 41 ++++++++++++++++++++
.../entity/rebind/RebindManagerImpl.java | 10 ++++-
...ApiObjectsFactory$ApiObjectsFactoryInterface | 19 +++++++++
6 files changed, 113 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/api/src/main/java/brooklyn/basic/AbstractBrooklynObjectSpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/basic/AbstractBrooklynObjectSpec.java b/api/src/main/java/brooklyn/basic/AbstractBrooklynObjectSpec.java
index 2ef4d67..867b509 100644
--- a/api/src/main/java/brooklyn/basic/AbstractBrooklynObjectSpec.java
+++ b/api/src/main/java/brooklyn/basic/AbstractBrooklynObjectSpec.java
@@ -41,6 +41,7 @@ public abstract class AbstractBrooklynObjectSpec<T,K extends AbstractBrooklynObj
protected AbstractBrooklynObjectSpec(Class<? extends T> type) {
checkValidType(type);
this.type = type;
+ this.contextCatalogItemId = ApiObjectsFactory.get().getContextCatalogItemId();
}
@SuppressWarnings("unchecked")
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/api/src/main/java/brooklyn/basic/ApiObjectsFactory.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/basic/ApiObjectsFactory.java b/api/src/main/java/brooklyn/basic/ApiObjectsFactory.java
new file mode 100644
index 0000000..f85e9c7
--- /dev/null
+++ b/api/src/main/java/brooklyn/basic/ApiObjectsFactory.java
@@ -0,0 +1,41 @@
+/*
+ * 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.basic;
+
+import java.util.ServiceLoader;
+
+public class ApiObjectsFactory {
+ public interface ApiObjectsFactoryInterface {
+ public String getContextCatalogItemId();
+ }
+
+ private static ApiObjectsFactoryInterface INSTANCE = getFactoryInstance();
+
+ private static ApiObjectsFactoryInterface getFactoryInstance() {
+ ServiceLoader<ApiObjectsFactoryInterface> LOADER = ServiceLoader.load(ApiObjectsFactoryInterface.class);
+ for (ApiObjectsFactoryInterface item : LOADER) {
+ return item;
+ }
+ throw new IllegalStateException("Implementation of " + ApiObjectsFactoryInterface.class + " not found on classpath");
+ }
+
+ public static ApiObjectsFactoryInterface get() {
+ return INSTANCE;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/core/src/main/java/brooklyn/basic/AbstractBrooklynObject.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/basic/AbstractBrooklynObject.java b/core/src/main/java/brooklyn/basic/AbstractBrooklynObject.java
index 8c2608d..8ff8776 100644
--- a/core/src/main/java/brooklyn/basic/AbstractBrooklynObject.java
+++ b/core/src/main/java/brooklyn/basic/AbstractBrooklynObject.java
@@ -74,6 +74,8 @@ public abstract class AbstractBrooklynObject implements BrooklynObjectInternal {
_legacyConstruction = true;
}
+ contextCatalogItemId = ApiObjectsFactory.get().getContextCatalogItemId();
+
// rely on sub-class to call configure(properties), because otherwise its fields will not have been initialised
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/core/src/main/java/brooklyn/basic/ApiObjectsFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/basic/ApiObjectsFactoryImpl.java b/core/src/main/java/brooklyn/basic/ApiObjectsFactoryImpl.java
new file mode 100644
index 0000000..8c95442
--- /dev/null
+++ b/core/src/main/java/brooklyn/basic/ApiObjectsFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ * 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.basic;
+
+import brooklyn.basic.ApiObjectsFactory.ApiObjectsFactoryInterface;
+import brooklyn.entity.Entity;
+import brooklyn.entity.basic.BrooklynTaskTags;
+import brooklyn.management.Task;
+import brooklyn.util.task.Tasks;
+
+public class ApiObjectsFactoryImpl implements ApiObjectsFactoryInterface {
+
+ @Override
+ public String getContextCatalogItemId() {
+ Task<?> currentTask = Tasks.current();
+ if (currentTask != null) {
+ Entity contextEntity = BrooklynTaskTags.getContextEntity(currentTask);
+ if (contextEntity != null) {
+ return contextEntity.getContextCatalogItemId();
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
index 807e6fb..6d6d6a1 100644
--- a/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
+++ b/core/src/main/java/brooklyn/entity/rebind/RebindManagerImpl.java
@@ -512,7 +512,15 @@ public class RebindManagerImpl implements RebindManager {
// * propagate the catalog item id when doing setEntity, addChild
// * fall back to the context entity of Tasks.current() (if set)
// * when none of the above work let the user specify the catalog item
-
+ //
+ // Precedence of setting the catalog item ID:
+ // 1. User-supplied catalog item ID.
+ // 2. Creating from a catalog item - all items resolved during the creation of a spec
+ // from a catalog item receive the catalog item's ID as context.
+ // 3. When using the Java API for creating specs get the catalog item ID from the
+ // context entity of the Tasks.current() task.
+ // 4. Propagate the context catalog item ID to children, adjuncts if they don't have one already.
+
//
// PHASE ONE
//
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0eb67633/core/src/main/resources/META-INF/services/brooklyn.basic.ApiObjectsFactory$ApiObjectsFactoryInterface
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/brooklyn.basic.ApiObjectsFactory$ApiObjectsFactoryInterface b/core/src/main/resources/META-INF/services/brooklyn.basic.ApiObjectsFactory$ApiObjectsFactoryInterface
new file mode 100644
index 0000000..007e088
--- /dev/null
+++ b/core/src/main/resources/META-INF/services/brooklyn.basic.ApiObjectsFactory$ApiObjectsFactoryInterface
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+brooklyn.basic.ApiObjectsFactoryImpl