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 2016/02/01 18:51:05 UTC
[23/51] [abbrv] [partial] brooklyn-server git commit: move subdir
from incubator up a level as it is promoted to its own repo (first
non-incubator commit!)
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
deleted file mode 100644
index 6f2aba8..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDto.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-
-import com.google.common.collect.ImmutableList;
-
-@Deprecated
-public class CatalogLibrariesDto implements CatalogItem.CatalogItemLibraries {
-
- private final Collection<String> bundles;
-
- public CatalogLibrariesDto() {
- this.bundles = Collections.emptyList();
- }
-
- public CatalogLibrariesDto(Collection<String> bundles) {
- this.bundles = bundles;
- }
-
- /**
- * @return An immutable copy of the bundle URLs referenced by this object
- */
- @Override
- public Collection<String> getBundles() {
- if (bundles == null) {
- // can be null on deserialization
- return Collections.emptyList();
- }
- return ImmutableList.copyOf(bundles);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
deleted file mode 100644
index c8206ce..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLocationItemDto.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.location.LocationSpec;
-
-
-public class CatalogLocationItemDto extends CatalogItemDtoAbstract<Location,LocationSpec<?>> {
-
- @Override
- public CatalogItemType getCatalogItemType() {
- return CatalogItemType.LOCATION;
- }
-
- @Override
- public Class<Location> getCatalogItemJavaType() {
- return Location.class;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Class<LocationSpec<?>> getSpecType() {
- return (Class)LocationSpec.class;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
deleted file mode 100644
index 1c7e6fe..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogPolicyItemDto.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.policy.PolicySpec;
-
-
-public class CatalogPolicyItemDto extends CatalogItemDtoAbstract<Policy,PolicySpec<?>> {
-
- @Override
- public CatalogItemType getCatalogItemType() {
- return CatalogItemType.POLICY;
- }
-
- @Override
- public Class<Policy> getCatalogItemJavaType() {
- return Policy.class;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Class<PolicySpec<?>> getSpecType() {
- return (Class)PolicySpec.class;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
deleted file mode 100644
index 688b814..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogTemplateItemDto.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.EntitySpec;
-
-public class CatalogTemplateItemDto extends CatalogItemDtoAbstract<Application,EntitySpec<? extends Application>> {
-
- @Override
- public CatalogItemType getCatalogItemType() {
- return CatalogItemType.TEMPLATE;
- }
-
- @Override
- public Class<Application> getCatalogItemJavaType() {
- return Application.class;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Class<EntitySpec<? extends Application>> getSpecType() {
- return (Class)EntitySpec.class;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
deleted file mode 100644
index dce5493..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUtils.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import java.util.Collection;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.catalog.BrooklynCatalog;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
-import org.apache.brooklyn.api.objs.BrooklynObject;
-import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
-import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
-import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.core.BrooklynLogging;
-import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog.BrooklynLoaderTracker;
-import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.core.mgmt.classloading.BrooklynClassLoadingContextSequential;
-import org.apache.brooklyn.core.mgmt.classloading.JavaBrooklynClassLoadingContext;
-import org.apache.brooklyn.core.mgmt.classloading.OsgiBrooklynClassLoadingContext;
-import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.core.mgmt.rebind.RebindManagerImpl.RebindTracker;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
-import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
-import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
-import org.apache.brooklyn.core.typereg.RegisteredTypes;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.text.Strings;
-import org.apache.brooklyn.util.time.Time;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Stopwatch;
-
-public class CatalogUtils {
- private static final Logger log = LoggerFactory.getLogger(CatalogUtils.class);
-
- public static final char VERSION_DELIMITER = ':';
-
- public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, CatalogItem<?, ?> item) {
- // TODO getLibraries() should never be null but sometimes it is still
- // e.g. run CatalogResourceTest without the above check
- if (item.getLibraries() == null) {
- log.debug("CatalogItemDtoAbstract.getLibraries() is null.", new Exception("Trace for null CatalogItemDtoAbstract.getLibraries()"));
- }
- return newClassLoadingContext(mgmt, item.getId(), item.getLibraries());
- }
-
- public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, RegisteredType item) {
- return newClassLoadingContext(mgmt, item.getId(), item.getLibraries(), null);
- }
-
- /** made @Beta in 0.9.0 because we're not sure to what extent to support stacking loaders;
- * only a couple places currently rely on such stacking, in general the item and the bundles *are* the context,
- * and life gets hard if we support complex stacking! */
- @Beta
- public static BrooklynClassLoadingContext newClassLoadingContext(ManagementContext mgmt, RegisteredType item, BrooklynClassLoadingContext loader) {
- return newClassLoadingContext(mgmt, item.getId(), item.getLibraries(), loader);
- }
-
- public static BrooklynClassLoadingContext getClassLoadingContext(Entity entity) {
- ManagementContext mgmt = ((EntityInternal)entity).getManagementContext();
- String catId = entity.getCatalogItemId();
- if (Strings.isBlank(catId)) return JavaBrooklynClassLoadingContext.create(mgmt);
- Maybe<RegisteredType> cat = RegisteredTypes.tryValidate(mgmt.getTypeRegistry().get(catId), RegisteredTypeLoadingContexts.spec(Entity.class));
- if (cat.isNull()) {
- log.warn("Cannot load "+catId+" to get classloader for "+entity+"; will try with standard loader, but might fail subsequently");
- return JavaBrooklynClassLoadingContext.create(mgmt);
- }
- return newClassLoadingContext(mgmt, cat.get());
- }
-
- public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext mgmt, String catalogItemId, Collection<? extends OsgiBundleWithUrl> libraries) {
- return newClassLoadingContext(mgmt, catalogItemId, libraries, null);
- }
-
- @Deprecated /** @deprecated since 0.9.0; becoming private because we should now always have a registered type callers can pass instead of the catalog item id */
- public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext mgmt, String catalogItemId, Collection<? extends OsgiBundleWithUrl> libraries, BrooklynClassLoadingContext loader) {
- BrooklynClassLoadingContextSequential result = new BrooklynClassLoadingContextSequential(mgmt);
-
- if (libraries!=null && !libraries.isEmpty()) {
- result.add(new OsgiBrooklynClassLoadingContext(mgmt, catalogItemId, libraries));
- }
-
- if (loader !=null) {
- // TODO determine whether to support stacking
- result.add(loader);
- }
- BrooklynClassLoadingContext threadLocalLoader = BrooklynLoaderTracker.getLoader();
- if (threadLocalLoader != null) {
- // TODO and determine if this is needed/wanted
- result.add(threadLocalLoader);
- }
-
- result.addSecondary(JavaBrooklynClassLoadingContext.create(mgmt));
- return result;
- }
-
- /**
- * @deprecated since 0.7.0 only for legacy catalog items which provide a non-osgi loader; see {@link #newDefault(ManagementContext)}
- */ @Deprecated
- public static BrooklynClassLoadingContext newClassLoadingContext(@Nullable ManagementContext mgmt, String catalogItemId, Collection<CatalogBundle> libraries, ClassLoader customClassLoader) {
- BrooklynClassLoadingContextSequential result = new BrooklynClassLoadingContextSequential(mgmt);
-
- if (libraries!=null && !libraries.isEmpty()) {
- result.add(new OsgiBrooklynClassLoadingContext(mgmt, catalogItemId, libraries));
- }
-
- BrooklynClassLoadingContext loader = BrooklynLoaderTracker.getLoader();
- if (loader != null) {
- result.add(loader);
- }
-
- result.addSecondary(JavaBrooklynClassLoadingContext.create(mgmt, customClassLoader));
- return result;
- }
-
- /**
- * Registers all bundles with the management context's OSGi framework.
- */
- public static void installLibraries(ManagementContext managementContext, @Nullable Collection<CatalogBundle> libraries) {
- if (libraries == null) return;
-
- ManagementContextInternal mgmt = (ManagementContextInternal) managementContext;
- if (!libraries.isEmpty()) {
- Maybe<OsgiManager> osgi = mgmt.getOsgiManager();
- if (osgi.isAbsent()) {
- throw new IllegalStateException("Unable to load bundles "+libraries+" because OSGi is not running.");
- }
- if (log.isDebugEnabled())
- logDebugOrTraceIfRebinding(log,
- "Loading bundles in {}: {}",
- new Object[] {managementContext, Joiner.on(", ").join(libraries)});
- Stopwatch timer = Stopwatch.createStarted();
- for (CatalogBundle bundleUrl : libraries) {
- osgi.get().registerBundle(bundleUrl);
- }
- if (log.isDebugEnabled())
- logDebugOrTraceIfRebinding(log,
- "Registered {} bundles in {}",
- new Object[]{libraries.size(), Time.makeTimeStringRounded(timer)});
- }
- }
-
- /** Scans the given {@link BrooklynClassLoadingContext} to detect what catalog item id is in effect. */
- public static String getCatalogItemIdFromLoader(BrooklynClassLoadingContext loader) {
- if (loader instanceof OsgiBrooklynClassLoadingContext) {
- return ((OsgiBrooklynClassLoadingContext)loader).getCatalogItemId();
- } else {
- return null;
- }
- }
-
- public static void setCatalogItemIdOnAddition(Entity entity, BrooklynObject itemBeingAdded) {
- if (entity.getCatalogItemId()!=null) {
- if (itemBeingAdded.getCatalogItemId()==null) {
- if (log.isDebugEnabled())
- BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
- "Catalog item addition: "+entity+" from "+entity.getCatalogItemId()+" applying its catalog item ID to "+itemBeingAdded);
- ((BrooklynObjectInternal)itemBeingAdded).setCatalogItemId(entity.getCatalogItemId());
- } else {
- if (!itemBeingAdded.getCatalogItemId().equals(entity.getCatalogItemId())) {
- // not a problem, but something to watch out for
- log.debug("Cross-catalog item detected: "+entity+" from "+entity.getCatalogItemId()+" has "+itemBeingAdded+" from "+itemBeingAdded.getCatalogItemId());
- }
- }
- } else if (itemBeingAdded.getCatalogItemId()!=null) {
- if (log.isDebugEnabled())
- BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
- "Catalog item addition: "+entity+" without catalog item ID has "+itemBeingAdded+" from "+itemBeingAdded.getCatalogItemId());
- }
- }
-
- @Beta
- public static void logDebugOrTraceIfRebinding(Logger log, String message, Object ...args) {
- if (RebindTracker.isRebinding())
- log.trace(message, args);
- else
- log.debug(message, args);
- }
-
- public static boolean looksLikeVersionedId(String versionedId) {
- if (versionedId==null) return false;
- int fi = versionedId.indexOf(VERSION_DELIMITER);
- if (fi<0) return false;
- int li = versionedId.lastIndexOf(VERSION_DELIMITER);
- if (li!=fi) {
- // if multiple colons, we say it isn't a versioned reference; the prefix in that case must understand any embedded versioning scheme
- // this fixes the case of: http://localhost:8080
- return false;
- }
- String candidateVersion = versionedId.substring(li+1);
- if (!candidateVersion.matches("[0-9]+(|(\\.|_).*)")) {
- // version must start with a number, followed if by anything with full stop or underscore before any other characters
- // e.g. foo:1 or foo:1.1 or foo:1_SNAPSHOT all supported, but not e.g. foo:bar (or chef:cookbook or docker:my/image)
- return false;
- }
- return true;
- }
-
- /** @deprecated since 0.9.0 use {@link #getSymbolicNameFromVersionedId(String)} */
- // all uses removed
- @Deprecated
- public static String getIdFromVersionedId(String versionedId) {
- return getSymbolicNameFromVersionedId(versionedId);
- }
-
- public static String getSymbolicNameFromVersionedId(String versionedId) {
- if (versionedId == null) return null;
- int versionDelimiterPos = versionedId.lastIndexOf(VERSION_DELIMITER);
- if (versionDelimiterPos != -1) {
- return versionedId.substring(0, versionDelimiterPos);
- } else {
- return null;
- }
- }
-
- public static String getVersionFromVersionedId(String versionedId) {
- if (versionedId == null) return null;
- int versionDelimiterPos = versionedId.lastIndexOf(VERSION_DELIMITER);
- if (versionDelimiterPos != -1) {
- return versionedId.substring(versionDelimiterPos+1);
- } else {
- return null;
- }
- }
-
- public static String getVersionedId(String id, String version) {
- // TODO null checks
- return id + VERSION_DELIMITER + version;
- }
-
- /** @deprecated since 0.9.0 use {@link BrooklynTypeRegistry#get(String, org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind, Class)} */
- // only a handful of items remaining, and those require a CatalogItem
- public static CatalogItem<?, ?> getCatalogItemOptionalVersion(ManagementContext mgmt, String versionedId) {
- if (versionedId == null) return null;
- if (looksLikeVersionedId(versionedId)) {
- String id = getSymbolicNameFromVersionedId(versionedId);
- String version = getVersionFromVersionedId(versionedId);
- return mgmt.getCatalog().getCatalogItem(id, version);
- } else {
- return mgmt.getCatalog().getCatalogItem(versionedId, BrooklynCatalog.DEFAULT_VERSION);
- }
- }
-
- public static boolean isBestVersion(ManagementContext mgmt, CatalogItem<?,?> item) {
- RegisteredType best = RegisteredTypes.getBestVersion(mgmt.getTypeRegistry().getMatching(
- RegisteredTypePredicates.symbolicName(item.getSymbolicName())));
- if (best==null) return false;
- return (best.getVersion().equals(item.getVersion()));
- }
-
- /** @deprecated since 0.9.0 use {@link BrooklynTypeRegistry#get(String, org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind, Class)} */
- // only a handful of items remaining, and those require a CatalogItem
- public static <T,SpecT> CatalogItem<T, SpecT> getCatalogItemOptionalVersion(ManagementContext mgmt, Class<T> type, String versionedId) {
- if (looksLikeVersionedId(versionedId)) {
- String id = getSymbolicNameFromVersionedId(versionedId);
- String version = getVersionFromVersionedId(versionedId);
- return mgmt.getCatalog().getCatalogItem(type, id, version);
- } else {
- return mgmt.getCatalog().getCatalogItem(type, versionedId, BrooklynCatalog.DEFAULT_VERSION);
- }
- }
-
- /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
- public static void setDeprecated(ManagementContext mgmt, String symbolicNameAndOptionalVersion, boolean newValue) {
- RegisteredType item = mgmt.getTypeRegistry().get(symbolicNameAndOptionalVersion);
- Preconditions.checkNotNull(item, "No such item: " + symbolicNameAndOptionalVersion);
- setDeprecated(mgmt, item.getSymbolicName(), item.getVersion(), newValue);
- }
-
- /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
- public static void setDisabled(ManagementContext mgmt, String symbolicNameAndOptionalVersion, boolean newValue) {
- RegisteredType item = mgmt.getTypeRegistry().get(symbolicNameAndOptionalVersion);
- Preconditions.checkNotNull(item, "No such item: "+symbolicNameAndOptionalVersion);
- setDisabled(mgmt, item.getSymbolicName(), item.getVersion(), newValue);
- }
-
- /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
- @Deprecated
- public static void setDeprecated(ManagementContext mgmt, String symbolicName, String version, boolean newValue) {
- CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicName, version);
- Preconditions.checkNotNull(item, "No such item: "+symbolicName+" v "+version);
- item.setDeprecated(newValue);
- mgmt.getCatalog().persist(item);
- }
-
- /** @deprecated since it was introduced in 0.9.0; TBD where this should live */
- @Deprecated
- public static void setDisabled(ManagementContext mgmt, String symbolicName, String version, boolean newValue) {
- CatalogItem<?, ?> item = mgmt.getCatalog().getCatalogItem(symbolicName, version);
- Preconditions.checkNotNull(item, "No such item: "+symbolicName+" v "+version);
- item.setDisabled(newValue);
- mgmt.getCatalog().persist(item);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
deleted file mode 100644
index 3cf686e..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogXmlSerializer.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
-import org.apache.brooklyn.core.mgmt.persist.DeserializingClassRenamesProvider;
-import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
-import org.apache.brooklyn.util.core.xstream.EnumCaseForgivingSingleValueConverter;
-import org.apache.brooklyn.util.core.xstream.XmlSerializer;
-
-public class CatalogXmlSerializer extends XmlSerializer<Object> {
-
- @SuppressWarnings("deprecation")
- public CatalogXmlSerializer() {
- super(DeserializingClassRenamesProvider.loadDeserializingClassRenames());
-
- xstream.addDefaultImplementation(ArrayList.class, Collection.class);
-
- //Doesn't work well for non-standard lists, like Lists.transform results
- xstream.aliasType("list", List.class);
- xstream.aliasType("map", Map.class);
-
- xstream.useAttributeFor("id", String.class);
-
- xstream.aliasType("catalog", CatalogDto.class);
- xstream.useAttributeFor(CatalogDto.class, "url");
- xstream.addImplicitCollection(CatalogDto.class, "catalogs", CatalogDto.class);
- xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogTemplateItemDto.class);
- xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogEntityItemDto.class);
- xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogPolicyItemDto.class);
- xstream.addImplicitCollection(CatalogDto.class, "entries", CatalogLocationItemDto.class);
-
- xstream.aliasType("template", CatalogTemplateItemDto.class);
- xstream.aliasType("entity", CatalogEntityItemDto.class);
- xstream.aliasType("policy", CatalogPolicyItemDto.class);
- xstream.aliasType("location", CatalogPolicyItemDto.class);
-
- xstream.aliasField("registeredType", CatalogItemDtoAbstract.class, "symbolicName");
- xstream.aliasAttribute(CatalogItemDtoAbstract.class, "displayName", "name");
- xstream.useAttributeFor(CatalogItemDtoAbstract.class, "type");
- xstream.useAttributeFor(CatalogItemDtoAbstract.class, "version");
- xstream.aliasType("bundle", CatalogBundleDto.class);
- xstream.registerConverter(new CatalogBundleConverter(xstream.getMapper(), xstream.getReflectionProvider()));
-
- xstream.useAttributeFor(CatalogClasspathDto.class, "scan");
- xstream.addImplicitCollection(CatalogClasspathDto.class, "entries", "entry", String.class);
- xstream.registerConverter(new EnumCaseForgivingSingleValueConverter(CatalogScanningModes.class));
-
- // Note: the management context is being omitted because it is unnecessary for
- // representations of catalogues generated with this serializer.
- xstream.omitField(AbstractBrooklynObject.class, "managementContext");
- xstream.omitField(AbstractBrooklynObject.class, "_legacyConstruction");
- xstream.omitField(AbstractBrooklynObject.class, "hasWarnedOfNoManagementContextWhenPersistRequested");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
deleted file mode 100644
index 4e15d24..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/JavaCatalogToSpecTransformer.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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.core.catalog.internal;
-
-import java.util.Set;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.policy.PolicySpec;
-import org.apache.brooklyn.api.typereg.RegisteredType;
-import org.apache.brooklyn.core.objs.BasicSpecParameter;
-import org.apache.brooklyn.core.plan.PlanNotRecognizedException;
-import org.apache.brooklyn.core.plan.PlanToSpecTransformer;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Instantiates classes from a registered type which simply
- * defines the java class name and OSGi bundles to use.
- * <p>
- * This is used where a {@link RegisteredType} is defined simply with the name of a java class
- * (no YAML etc); and for legacy old-style (c0.7.0) catalog items (defined in catalog.xml only)
- * with structure, only a single type.
- */
-public class JavaCatalogToSpecTransformer implements PlanToSpecTransformer {
- private static final Logger log = LoggerFactory.getLogger(JavaCatalogToSpecTransformer.class);
-
- private ManagementContext mgmt;
-
- @Override
- public void setManagementContext(ManagementContext mgmt) {
- this.mgmt = mgmt;
- }
-
- @Override
- public String getShortDescription() {
- return "Java type instantiator";
- }
-
- @Override
- public boolean accepts(String planType) {
- return false;
- }
-
- @Override
- public EntitySpec<? extends Application> createApplicationSpec(String plan) throws PlanNotRecognizedException {
- throw new PlanNotRecognizedException(getClass().getName() + " doesn't parse application plans.");
- }
-
- @Override
- public <T, SpecT extends AbstractBrooklynObjectSpec<? extends T, SpecT>> SpecT createCatalogSpec(
- CatalogItem<T, SpecT> item, Set<String> encounteredTypes) throws PlanNotRecognizedException {
- @SuppressWarnings("deprecation")
- String javaType = item.getJavaType();
- if (javaType != null) {
- log.warn("Deprecated functionality (since 0.9.0). Using old-style xml catalog items with java type attribute for " + item);
- Class<?> type;
- try {
- // java types were deprecated before we added osgi support so this isn't necessary,
- // but it doesn't hurt (and if we re-instate a class+bundle approach for RegisteredType
- // we will want to do this)
- type = CatalogUtils.newClassLoadingContext(mgmt, item).loadClass(javaType);
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- throw new IllegalStateException("Unable to load old-style java catalog item type " + javaType + " for item " + item, e);
- }
- AbstractBrooklynObjectSpec<?,?> spec;
- if (Entity.class.isAssignableFrom(type)) {
- @SuppressWarnings("unchecked")
- Class<Entity> entityType = (Class<Entity>)type;
- spec = EntitySpec.create(entityType)
- .parameters(BasicSpecParameter.fromClass(mgmt, entityType));
- } else if (Policy.class.isAssignableFrom(type)) {
- @SuppressWarnings("unchecked")
- Class<Policy> policyType = (Class<Policy>)type;
- spec = PolicySpec.create(policyType);
- } else {
- throw new IllegalStateException("Catalog item " + item + " java type " + javaType + " is not a Brooklyn supported object.");
- }
- spec.catalogItemId(item.getCatalogItemId());
- @SuppressWarnings("unchecked")
- SpecT untypedSpc = (SpecT) spec;
- return untypedSpc;
- } else {
- throw new PlanNotRecognizedException(getClass().getName() + " parses only old-style catalog items containing javaType");
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
deleted file mode 100644
index f158c2c..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * 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.core.config;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Map;
-import java.util.concurrent.ExecutionException;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.mgmt.ExecutionContext;
-import org.apache.brooklyn.config.ConfigInheritance;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.util.core.internal.ConfigKeySelfExtracting;
-import org.apache.brooklyn.util.core.task.Tasks;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.guava.TypeTokens;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Lists;
-import com.google.common.reflect.TypeToken;
-
-public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializable {
-
- private static final Logger log = LoggerFactory.getLogger(BasicConfigKey.class);
- private static final long serialVersionUID = -1762014059150215376L;
-
- private static final Splitter dots = Splitter.on('.');
-
- public static <T> Builder<T> builder(TypeToken<T> type) {
- return new Builder<T>().type(type);
- }
-
- public static <T> Builder<T> builder(Class<T> type) {
- return new Builder<T>().type(type);
- }
-
- public static <T> Builder<T> builder(TypeToken<T> type, String name) {
- return new Builder<T>().type(type).name(name);
- }
-
- public static <T> Builder<T> builder(Class<T> type, String name) {
- return new Builder<T>().type(type).name(name);
- }
-
- public static <T> Builder<T> builder(ConfigKey<T> key) {
- return new Builder<T>()
- .name(checkNotNull(key.getName(), "name"))
- .type(checkNotNull(key.getTypeToken(), "type"))
- .description(key.getDescription())
- .defaultValue(key.getDefaultValue())
- .reconfigurable(key.isReconfigurable())
- .inheritance(key.getInheritance())
- .constraint(key.getConstraint());
- }
-
- public static class Builder<T> {
- private String name;
- private TypeToken<T> type;
- private String description;
- private T defaultValue;
- private boolean reconfigurable;
- private Predicate<? super T> constraint = Predicates.alwaysTrue();
- private ConfigInheritance inheritance;
-
- public Builder<T> name(String val) {
- this.name = val; return this;
- }
- public Builder<T> type(Class<T> val) {
- this.type = TypeToken.of(val); return this;
- }
- public Builder<T> type(TypeToken<T> val) {
- this.type = val; return this;
- }
- public Builder<T> description(String val) {
- this.description = val; return this;
- }
- public Builder<T> defaultValue(T val) {
- this.defaultValue = val; return this;
- }
- public Builder<T> reconfigurable(boolean val) {
- this.reconfigurable = val; return this;
- }
- public Builder<T> inheritance(ConfigInheritance val) {
- this.inheritance = val; return this;
- }
- @Beta
- public Builder<T> constraint(Predicate<? super T> constraint) {
- this.constraint = checkNotNull(constraint, "constraint"); return this;
- }
- public BasicConfigKey<T> build() {
- return new BasicConfigKey<T>(this);
- }
-
- public String getName() {
- return name;
- }
- public String getDescription() {
- return description;
- }
- }
-
- private String name;
- private TypeToken<T> typeToken;
- private Class<? super T> type;
- private String description;
- private T defaultValue;
- private boolean reconfigurable;
- private ConfigInheritance inheritance;
- private Predicate<? super T> constraint;
-
- // FIXME In groovy, fields were `public final` with a default constructor; do we need the gson?
- public BasicConfigKey() { /* for gson */ }
-
- public BasicConfigKey(Class<T> type, String name) {
- this(TypeToken.of(type), name);
- }
-
- public BasicConfigKey(Class<T> type, String name, String description) {
- this(TypeToken.of(type), name, description);
- }
-
- public BasicConfigKey(Class<T> type, String name, String description, T defaultValue) {
- this(TypeToken.of(type), name, description, defaultValue);
- }
-
- public BasicConfigKey(TypeToken<T> type, String name) {
- this(type, name, name, null);
- }
-
- public BasicConfigKey(TypeToken<T> type, String name, String description) {
- this(type, name, description, null);
- }
-
- public BasicConfigKey(TypeToken<T> type, String name, String description, T defaultValue) {
- this.description = description;
- this.name = checkNotNull(name, "name");
-
- this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(type, "type"));
- this.typeToken = TypeTokens.getTypeTokenIfNotRaw(type);
-
- this.defaultValue = defaultValue;
- this.reconfigurable = false;
- this.constraint = Predicates.alwaysTrue();
- }
-
- public BasicConfigKey(Builder<T> builder) {
- this.name = checkNotNull(builder.name, "name");
- this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(builder.type, "type"));
- this.typeToken = TypeTokens.getTypeTokenIfNotRaw(builder.type);
- this.description = builder.description;
- this.defaultValue = builder.defaultValue;
- this.reconfigurable = builder.reconfigurable;
- this.inheritance = builder.inheritance;
- // Note: it's intentionally possible to have default values that are not valid
- // per the configured constraint. If validity were checked here any class that
- // contained a weirdly-defined config key would fail to initialise.
- this.constraint = checkNotNull(builder.constraint, "constraint");
- }
-
- /** @see ConfigKey#getName() */
- @Override public String getName() { return name; }
-
- /** @see ConfigKey#getTypeName() */
- @Override public String getTypeName() { return getType().getName(); }
-
- /** @see ConfigKey#getType() */
- @Override public Class<? super T> getType() { return TypeTokens.getRawType(typeToken, type); }
-
- /** @see ConfigKey#getTypeToken() */
- @Override public TypeToken<T> getTypeToken() { return TypeTokens.getTypeToken(typeToken, type); }
-
- /** @see ConfigKey#getDescription() */
- @Override public String getDescription() { return description; }
-
- /** @see ConfigKey#getDefaultValue() */
- @Override public T getDefaultValue() { return defaultValue; }
-
- /** @see ConfigKey#hasDefaultValue() */
- @Override public boolean hasDefaultValue() {
- return defaultValue != null;
- }
-
- /** @see ConfigKey#isReconfigurable() */
- @Override
- public boolean isReconfigurable() {
- return reconfigurable;
- }
-
- /** @see ConfigKey#getInheritance() */
- @Override @Nullable
- public ConfigInheritance getInheritance() {
- return inheritance;
- }
-
- /** @see ConfigKey#getConstraint() */
- @Override @Nonnull
- public Predicate<? super T> getConstraint() {
- // Could be null after rebinding
- if (constraint != null) {
- return constraint;
- } else {
- return Predicates.alwaysTrue();
- }
- }
-
- /** @see ConfigKey#isValueValid(T) */
- @Override
- public boolean isValueValid(T value) {
- // The likeliest source of an exception is a constraint from Guava that expects a non-null input.
- try {
- return getConstraint().apply(value);
- } catch (Exception e) {
- log.debug("Suppressing exception when testing validity of " + this, e);
- return false;
- }
- }
-
- /** @see ConfigKey#getNameParts() */
- @Override public Collection<String> getNameParts() {
- return Lists.newArrayList(dots.split(name));
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) return true;
- if (!(obj instanceof BasicConfigKey)) return false;
- BasicConfigKey<?> o = (BasicConfigKey<?>) obj;
-
- return Objects.equal(name, o.name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(name);
- }
-
- @Override
- public String toString() {
- return String.format("%s[ConfigKey:%s]", name, getTypeName());
- }
-
- /**
- * Retrieves the value corresponding to this config key from the given map.
- * Could be overridden by more sophisticated config keys, such as MapConfigKey etc.
- */
- @SuppressWarnings("unchecked")
- @Override
- public T extractValue(Map<?,?> vals, ExecutionContext exec) {
- Object v = vals.get(this);
- try {
- return (T) resolveValue(v, exec);
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
- @Override
- public boolean isSet(Map<?,?> vals) {
- return vals.containsKey(this);
- }
-
- protected Object resolveValue(Object v, ExecutionContext exec) throws ExecutionException, InterruptedException {
- if (v instanceof Collection || v instanceof Map) {
- return Tasks.resolveDeepValue(v, Object.class, exec, "config "+name);
- } else {
- return Tasks.resolveValue(v, getType(), exec, "config "+name);
- }
- }
-
- /** used to record a key which overwrites another; only needed at disambiguation time
- * if a class declares a key and an equivalent one (often inherited) which overwrites it.
- * See org.apache.brooklyn.core.entity.ConfigEntityInheritanceTest, and uses of this class, for more explanation.
- */
- public static class BasicConfigKeyOverwriting<T> extends BasicConfigKey<T> {
- private static final long serialVersionUID = -3458116971918128018L;
-
- private final ConfigKey<T> parentKey;
-
- /** builder here should be based on the same key passed in as parent */
- @Beta
- public BasicConfigKeyOverwriting(Builder<T> builder, ConfigKey<T> parent) {
- super(builder);
- parentKey = parent;
- Preconditions.checkArgument(Objects.equal(builder.name, parent.getName()), "Builder must use key of the same name.");
- }
-
- public BasicConfigKeyOverwriting(ConfigKey<T> key, T defaultValue) {
- this(builder(key).defaultValue(defaultValue), key);
- }
-
- public BasicConfigKeyOverwriting(ConfigKey<T> key, String newDescription, T defaultValue) {
- this(builder(key).description(newDescription).defaultValue(defaultValue), key);
- }
-
- public ConfigKey<T> getParentKey() {
- return parentKey;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
deleted file mode 100644
index c508349..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * 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.core.config;
-
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.objs.BrooklynObject;
-import org.apache.brooklyn.api.objs.EntityAdjunct;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.objs.AbstractEntityAdjunct;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
-import org.apache.brooklyn.core.objs.BrooklynObjectPredicate;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-/**
- * Checks configuration constraints on entities and their adjuncts.
- *
- * @since 0.9.0
- */
-public abstract class ConfigConstraints<T extends BrooklynObject> {
-
- public static final Logger LOG = LoggerFactory.getLogger(ConfigConstraints.class);
-
- private final T brooklynObject;
-
- /**
- * Checks all constraints of all config keys available to an entity.
- * <p>
- * If a constraint is a {@link BrooklynObjectPredicate} then
- * {@link BrooklynObjectPredicate#apply(Object, BrooklynObject)} will be used.
- */
- public static void assertValid(Entity entity) {
- Iterable<ConfigKey<?>> violations = new EntityConfigConstraints(entity).getViolations();
- if (!Iterables.isEmpty(violations)) {
- throw new ConstraintViolationException(errorMessage(entity, violations));
- }
- }
-
- /**
- * Checks all constraints of all config keys available to an entity adjunct.
- * <p>
- * If a constraint is a {@link BrooklynObjectPredicate} then
- * {@link BrooklynObjectPredicate#apply(Object, BrooklynObject)} will be used.
- */
- public static void assertValid(EntityAdjunct adjunct) {
- Iterable<ConfigKey<?>> violations = new EntityAdjunctConstraints(adjunct).getViolations();
- if (!Iterables.isEmpty(violations)) {
- throw new ConstraintViolationException(errorMessage(adjunct, violations));
- }
- }
-
- public static <T> void assertValid(Entity entity, ConfigKey<T> key, T value) {
- if (!new EntityConfigConstraints(entity).isValueValid(key, value)) {
- throw new ConstraintViolationException("Invalid value for " + key + " on " + entity + ": " + value);
- }
- }
-
- public static <T> void assertValid(Location location, ConfigKey<T> key, T value) {
- if (!new LocationConfigConstraints(location).isValueValid(key, value)) {
- throw new ConstraintViolationException("Invalid value for " + key + " on " + location + ": " + value);
- }
- }
-
- private static String errorMessage(BrooklynObject object, Iterable<ConfigKey<?>> violations) {
- StringBuilder message = new StringBuilder("Error configuring ")
- .append(object.getDisplayName())
- .append(": [");
- Iterator<ConfigKey<?>> it = violations.iterator();
- while (it.hasNext()) {
- ConfigKey<?> config = it.next();
- message.append(config.getName())
- .append(":")
- .append(config.getConstraint());
- if (it.hasNext()) {
- message.append(", ");
- }
- }
- return message.append("]").toString();
- }
-
- public ConfigConstraints(T brooklynObject) {
- this.brooklynObject = brooklynObject;
- }
-
- abstract Iterable<ConfigKey<?>> getBrooklynObjectTypeConfigKeys();
-
- public Iterable<ConfigKey<?>> getViolations() {
- return validateAll();
- }
-
- @SuppressWarnings("unchecked")
- private Iterable<ConfigKey<?>> validateAll() {
- List<ConfigKey<?>> violating = Lists.newLinkedList();
- Iterable<ConfigKey<?>> configKeys = getBrooklynObjectTypeConfigKeys();
- LOG.trace("Checking config keys on {}: {}", getBrooklynObject(), configKeys);
- for (ConfigKey<?> configKey : configKeys) {
- BrooklynObjectInternal.ConfigurationSupportInternal configInternal = getConfigurationSupportInternal();
- // getNonBlocking method coerces the value to the config key's type.
- Maybe<?> maybeValue = configInternal.getNonBlocking(configKey);
- if (maybeValue.isPresent()) {
- // Cast is safe because the author of the constraint on the config key had to
- // keep its type to Predicte<? super T>, where T is ConfigKey<T>.
- ConfigKey<Object> ck = (ConfigKey<Object>) configKey;
- if (!isValueValid(ck, maybeValue.get())) {
- violating.add(configKey);
- }
- }
- }
- return violating;
- }
-
- @SuppressWarnings("unchecked")
- <V> boolean isValueValid(ConfigKey<V> configKey, V value) {
- try {
- Predicate<? super V> po = configKey.getConstraint();
- if (po instanceof BrooklynObjectPredicate) {
- return BrooklynObjectPredicate.class.cast(po).apply(value, brooklynObject);
- } else {
- return po.apply(value);
- }
- } catch (Exception e) {
- LOG.debug("Error checking constraint on " + configKey.getName(), e);
- }
- return true;
- }
-
- private BrooklynObjectInternal.ConfigurationSupportInternal getConfigurationSupportInternal() {
- return ((BrooklynObjectInternal) brooklynObject).config();
- }
-
- protected T getBrooklynObject() {
- return brooklynObject;
- }
-
- private static class EntityConfigConstraints extends ConfigConstraints<Entity> {
- public EntityConfigConstraints(Entity brooklynObject) {
- super(brooklynObject);
- }
-
- @Override
- Iterable<ConfigKey<?>> getBrooklynObjectTypeConfigKeys() {
- return getBrooklynObject().getEntityType().getConfigKeys();
- }
- }
-
- private static class EntityAdjunctConstraints extends ConfigConstraints<EntityAdjunct> {
- public EntityAdjunctConstraints(EntityAdjunct brooklynObject) {
- super(brooklynObject);
- }
-
- @Override
- Iterable<ConfigKey<?>> getBrooklynObjectTypeConfigKeys() {
- return ((AbstractEntityAdjunct) getBrooklynObject()).getAdjunctType().getConfigKeys();
- }
- }
-
- private static class LocationConfigConstraints extends ConfigConstraints<Location> {
- public LocationConfigConstraints(Location brooklynObject) {
- super(brooklynObject);
- }
-
- @Override
- Iterable<ConfigKey<?>> getBrooklynObjectTypeConfigKeys() {
- return Collections.emptyList();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigKeys.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigKeys.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigKeys.java
deleted file mode 100644
index ecc1ec0..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigKeys.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * 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.core.config;
-
-import java.util.Map;
-
-import javax.annotation.Nonnull;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.config.BasicConfigKey.BasicConfigKeyOverwriting;
-import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey;
-import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
-import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
-import org.apache.brooklyn.core.sensor.TemplatedStringAttributeSensorAndConfigKey;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.text.Strings;
-import org.apache.brooklyn.util.time.Duration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.CaseFormat;
-import com.google.common.base.Preconditions;
-import com.google.common.reflect.TypeToken;
-
-
-/**
- * Dictionary of {@link ConfigKey} entries.
- */
-public class ConfigKeys {
-
- private static final Logger log = LoggerFactory.getLogger(ConfigKeys.class);
-
- public static <T> ConfigKey<T> newConfigKey(Class<T> type, String name) {
- return new BasicConfigKey<T>(type, name);
- }
-
- public static <T> ConfigKey<T> newConfigKey(Class<T> type, String name, String description) {
- return new BasicConfigKey<T>(type, name, description);
- }
-
- public static <T> ConfigKey<T> newConfigKey(TypeToken<T> type, String name) {
- return new BasicConfigKey<T>(type, name);
- }
-
- public static <T> ConfigKey<T> newConfigKey(TypeToken<T> type, String name, String description) {
- return new BasicConfigKey<T>(type, name, description);
- }
-
- public static <T> ConfigKey<T> newConfigKey(Class<T> type, String name, String description, T defaultValue) {
- return new BasicConfigKey<T>(type, name, description, defaultValue);
- }
-
- public static <T> ConfigKey<T> newConfigKey(TypeToken<T> type, String name, String description, T defaultValue) {
- return new BasicConfigKey<T>(type, name, description, defaultValue);
- }
-
- public static <T> AttributeSensorAndConfigKey<T,T> newSensorAndConfigKey(Class<T> type, String name, String description) {
- return new BasicAttributeSensorAndConfigKey<T>(type, name, description);
- }
-
- public static <T> AttributeSensorAndConfigKey<T,T> newSensorAndConfigKey(Class<T> type, String name, String description, T defaultValue) {
- return new BasicAttributeSensorAndConfigKey<T>(type, name, description, defaultValue);
- }
-
- public static <T> AttributeSensorAndConfigKey<T,T> newSensorAndConfigKey(TypeToken<T> type, String name, String description) {
- return new BasicAttributeSensorAndConfigKey<T>(type, name, description);
- }
-
- public static <T> AttributeSensorAndConfigKey<T,T> newSensorAndConfigKey(TypeToken<T> type, String name, String description, T defaultValue) {
- return new BasicAttributeSensorAndConfigKey<T>(type, name, description, defaultValue);
- }
-
- public static AttributeSensorAndConfigKey<String,String> newStringSensorAndConfigKey(String name, String description) {
- return new BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey(name, description);
- }
-
- public static AttributeSensorAndConfigKey<String,String> newStringSensorAndConfigKey(String name, String description, String defaultValue) {
- return new BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey(name, description, defaultValue);
- }
-
- public static AttributeSensorAndConfigKey<String,String> newTemplateSensorAndConfigKey(String name, String description) {
- return new TemplatedStringAttributeSensorAndConfigKey(name, description);
- }
-
- public static AttributeSensorAndConfigKey<String,String> newTemplateSensorAndConfigKey(String name, String description, String defaultValue) {
- return new TemplatedStringAttributeSensorAndConfigKey(name, description, defaultValue);
- }
-
- public static AttributeSensorAndConfigKey<Integer,Integer> newIntegerSensorAndConfigKey(String name, String description) {
- return new BasicAttributeSensorAndConfigKey.IntegerAttributeSensorAndConfigKey(name, description);
- }
-
- public static AttributeSensorAndConfigKey<Integer,Integer> newIntegerSensorAndConfigKey(String name, String description, Integer defaultValue) {
- return new BasicAttributeSensorAndConfigKey.IntegerAttributeSensorAndConfigKey(name, description, defaultValue);
- }
-
- public static PortAttributeSensorAndConfigKey newPortSensorAndConfigKey(String name, String description) {
- return new PortAttributeSensorAndConfigKey(name, description);
- }
-
- public static PortAttributeSensorAndConfigKey newPortSensorAndConfigKey(String name, String description, Object defaultValue) {
- return new PortAttributeSensorAndConfigKey(name, description, defaultValue);
- }
-
- /** Infers the type from the default value */
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static <T> ConfigKey<T> newConfigKey(String name, String description, @Nonnull T defaultValue) {
- return new BasicConfigKey<T>((Class)Preconditions.checkNotNull(defaultValue,
- "Type must be exlicit for ConfigKey if defaultValue is null").getClass(),
- name, description, defaultValue);
- }
-
- public static <T> BasicConfigKey.Builder<T> builder(Class<T> type) {
- return BasicConfigKey.builder(type);
- }
- public static <T> BasicConfigKey.Builder<T> builder(TypeToken<T> type) {
- return BasicConfigKey.builder(type);
- }
- public static <T> BasicConfigKey.Builder<T> builder(Class<T> type, String name) {
- return BasicConfigKey.builder(type, name);
- }
- public static <T> BasicConfigKey.Builder<T> builder(TypeToken<T> type, String name) {
- return BasicConfigKey.builder(type, name);
- }
-
- // ---- extensions to keys
-
- public static <T> ConfigKey<T> newConfigKeyWithDefault(ConfigKey<T> parent, T defaultValue) {
- return new BasicConfigKeyOverwriting<T>(parent, defaultValue);
- }
-
- public static <T> ConfigKey<T> newConfigKeyWithDefault(ConfigKey<T> parent, String newDescription, T defaultValue) {
- return new BasicConfigKeyOverwriting<T>(parent, newDescription, defaultValue);
- }
-
- public static <T> ConfigKey<T> newConfigKeyRenamed(String newName, ConfigKey<T> key) {
- return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
- }
-
- public static <T> ConfigKey<T> newConfigKeyWithPrefix(String prefix, ConfigKey<T> key) {
- return newConfigKeyRenamed(prefix+key.getName(), key);
- }
-
- public static <T> ConfigKey<T> newConfigKeyWithPrefixRemoved(String prefix, ConfigKey<T> key) {
- if (key.getName().startsWith(prefix)) {
- return newConfigKeyRenamed(key.getName().substring(prefix.length()), key);
- } else {
- throw new IllegalArgumentException("key "+key+" does not start with prefix "+prefix);
- }
- }
-
- /** converts the name of the key from one case-strategy (e.g. lowerCamel) to andother (e.g. lower-hyphen) */
- public static <T> ConfigKey<T> convert(ConfigKey<T> key, CaseFormat inputCaseStrategy, CaseFormat outputCaseStrategy) {
- return newConfigKeyRenamed(inputCaseStrategy.to(outputCaseStrategy, key.getName()), key);
- }
-
- // ---- typed keys
-
- public static ConfigKey<String> newStringConfigKey(String name) {
- return newConfigKey(String.class, name);
- }
- public static ConfigKey<String> newStringConfigKey(String name, String description) {
- return newConfigKey(String.class, name, description);
- }
- public static ConfigKey<String> newStringConfigKey(String name, String description, String defaultValue) {
- return newConfigKey(String.class, name, description, defaultValue);
- }
-
- public static ConfigKey<Integer> newIntegerConfigKey(String name) {
- return newConfigKey(Integer.class, name);
- }
- public static ConfigKey<Integer> newIntegerConfigKey(String name, String description) {
- return newConfigKey(Integer.class, name, description);
- }
- public static ConfigKey<Integer> newIntegerConfigKey(String name, String description, Integer defaultValue) {
- return newConfigKey(Integer.class, name, description, defaultValue);
- }
-
- public static ConfigKey<Long> newLongConfigKey(String name) {
- return newConfigKey(Long.class, name);
- }
- public static ConfigKey<Long> newLongConfigKey(String name, String description) {
- return newConfigKey(Long.class, name, description);
- }
- public static ConfigKey<Long> newLongConfigKey(String name, String description, Long defaultValue) {
- return newConfigKey(Long.class, name, description, defaultValue);
- }
-
- public static ConfigKey<Double> newDoubleConfigKey(String name) {
- return newConfigKey(Double.class, name);
- }
- public static ConfigKey<Double> newDoubleConfigKey(String name, String description) {
- return newConfigKey(Double.class, name, description);
- }
- public static ConfigKey<Double> newDoubleConfigKey(String name, String description, Double defaultValue) {
- return newConfigKey(Double.class, name, description, defaultValue);
- }
-
- public static ConfigKey<Boolean> newBooleanConfigKey(String name) {
- return newConfigKey(Boolean.class, name);
- }
- public static ConfigKey<Boolean> newBooleanConfigKey(String name, String description) {
- return newConfigKey(Boolean.class, name, description);
- }
- public static ConfigKey<Boolean> newBooleanConfigKey(String name, String description, Boolean defaultValue) {
- return newConfigKey(Boolean.class, name, description, defaultValue);
- }
-
- public static ConfigKey<Duration> newDurationConfigKey(String name) {
- return newConfigKey(Duration.class, name);
- }
- public static ConfigKey<Duration> newDurationConfigKey(String name, String description) {
- return newConfigKey(Duration.class, name, description);
- }
- public static ConfigKey<Duration> newDurationConfigKey(String name, String description, Duration defaultValue) {
- return newConfigKey(Duration.class, name, description, defaultValue);
- }
-
- public static class DynamicKeys {
-
- // TODO see below
-// public static final ConfigKey<String> TYPE = ConfigKeys.newStringConfigKey("type");
- public static final ConfigKey<String> NAME = ConfigKeys.newStringConfigKey("name");
- public static final ConfigKey<String> DESCRIPTION = ConfigKeys.newStringConfigKey("description");
- public static final ConfigKey<Object> DEFAULT_VALUE = ConfigKeys.newConfigKey(Object.class, "defaultValue");
-
- public static ConfigKey<?> newInstance(ConfigBag keyDefs) {
- String typeName = Strings.toString(keyDefs.getStringKey("type"));
- if (Strings.isNonBlank(typeName)) {
- // TODO dynamic typing - see TYPE key commented out above; also see AddSensor.getType for type lookup
- log.warn("Setting 'type' is not currently supported for dynamic config keys; ignoring in definition of "+keyDefs);
- }
-
- Class<Object> type = Object.class;
- String name = keyDefs.get(NAME);
- String description = keyDefs.get(DESCRIPTION);
- Object defaultValue = keyDefs.get(DEFAULT_VALUE);
- return newConfigKey(type, name, description, defaultValue);
- }
-
- /** creates a new {@link ConfigKey} given a map describing it */
- public static ConfigKey<?> newInstance(Map<?,?> keyDefs) {
- return newInstance(ConfigBag.newInstance(keyDefs));
- }
-
- /** creates a new {@link ConfigKey} given a name (e.g. as a key in a larger map) and a map of other definition attributes */
- public static ConfigKey<?> newNamedInstance(String name, Map<?,?> keyDefs) {
- ConfigBag defs = ConfigBag.newInstance(keyDefs);
- String oldName = defs.put(NAME, name);
- if (oldName!=null && !oldName.equals(name))
- log.warn("Dynamic key '"+oldName+"' being overridden as key '"+name+"' in "+keyDefs);
- return newInstance(defs);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigPredicates.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigPredicates.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigPredicates.java
deleted file mode 100644
index a2f5bec..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigPredicates.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.core.config;
-
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.util.guava.SerializablePredicate;
-import org.apache.brooklyn.util.text.StringPredicates;
-import org.apache.brooklyn.util.text.WildcardGlobs;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-
-@SuppressWarnings("serial")
-public class ConfigPredicates {
-
- /** @deprecated since 0.9.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static Predicate<ConfigKey<?>> startingWithOld(final String prefix) {
- // TODO PERSISTENCE WORKAROUND
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && input.getName().startsWith(prefix);
- }
- };
- }
-
- /** @deprecated since 0.9.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static Predicate<ConfigKey<?>> matchingGlobOld(final String glob) {
- // TODO PERSISTENCE WORKAROUND
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && WildcardGlobs.isGlobMatched(glob, input.getName());
- }
- };
- }
-
- /** @deprecated since 0.9.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static Predicate<ConfigKey<?>> matchingRegexOld(final String regex) {
- // TODO PERSISTENCE WORKAROUND
- final Pattern p = Pattern.compile(regex);
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && p.matcher(input.getName()).matches();
- }
- };
- }
-
- /** @deprecated since 0.9.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static Predicate<ConfigKey<?>> nameMatchingOld(final Predicate<String> filter) {
- // TODO PERSISTENCE WORKAROUND
- return new Predicate<ConfigKey<?>>() {
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && filter.apply(input.getName());
- }
- };
- }
-
- /** @deprecated since 0.9.0; use {@link #nameStartsWith(String)} */
- public static Predicate<ConfigKey<?>> startingWith(final String prefix) {
- return nameStartsWith(prefix);
- }
-
- /** @deprecated since 0.9.0; use {@link #nameMatchesGlob(String)} */
- public static Predicate<ConfigKey<?>> matchingGlob(final String glob) {
- return nameMatchesGlob(glob);
- }
-
- /** @deprecated since 0.9.0; use {@link #nameMatchesRegex(String)} */
- public static Predicate<ConfigKey<?>> matchingRegex(final String regex) {
- return nameMatchesRegex(regex);
- }
-
- /** @deprecated since 0.9.0; use {@link #nameSatisfies(Predicate)} */
- public static Predicate<ConfigKey<?>> nameMatching(final Predicate<String> filter) {
- return nameSatisfies(filter);
- }
-
- /**
- * @since 0.9.0
- */
- public static Predicate<ConfigKey<?>> nameStartsWith(final String prefix) {
- return nameSatisfies(StringPredicates.startsWith(prefix));
- }
-
- /**
- * @since 0.9.0
- */
- public static Predicate<ConfigKey<?>> nameMatchesGlob(final String glob) {
- return nameSatisfies(StringPredicates.matchesGlob(glob));
- }
-
- /**
- * @since 0.9.0
- */
- public static Predicate<ConfigKey<?>> nameMatchesRegex(final String regex) {
- return nameSatisfies(StringPredicates.matchesRegex(regex));
- }
-
- /**
- * @since 0.9.0
- */
- public static Predicate<ConfigKey<?>> nameEqualTo(final String val) {
- return nameSatisfies(Predicates.equalTo(val));
- }
-
- /**
- * @since 0.9.0
- */
- public static Predicate<ConfigKey<?>> nameSatisfies(final Predicate<? super String> condition) {
- return new NameSatisfies(condition);
- }
-
- /**
- * @since 0.9.0
- */
- protected static class NameSatisfies implements SerializablePredicate<ConfigKey<?>> {
- protected final Predicate<? super String> condition;
- protected NameSatisfies(Predicate<? super String> condition) {
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable ConfigKey<?> input) {
- return (input != null) && condition.apply(input.getName());
- }
- @Override
- public String toString() {
- return "displayNameSatisfies("+condition+")";
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
deleted file mode 100644
index 80d06b9..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigUtils.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 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.core.config;
-
-import java.io.File;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.core.config.ConfigUtils;
-import org.apache.brooklyn.core.config.WrappedConfigKey;
-import org.apache.brooklyn.core.internal.BrooklynProperties;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Predicate;
-
-@SuppressWarnings({"unchecked"})
-public class ConfigUtils {
-
- private static final Logger log = LoggerFactory.getLogger(ConfigUtils.class);
-
- public static <T> T getRequiredConfig(Entity entity, ConfigKey<T> key) {
- T result = entity.getConfig(key);
- if (result==null) throw new IllegalStateException("Configuration "+key+" is required");
- return result;
- }
-
- /** prepends the given prefix to the key. prefix will typically end with a ".".
- * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user")
- * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"),
- * and we wish to convert from the shorter names to the longer names. */
- public static <T> ConfigKey<T> prefixedKey(String prefix, ConfigKey<T> key) {
- return ConfigKeys.newConfigKeyWithPrefix(prefix, key);
- }
-
- /** removes the given prefix from the key for configuration purposes; logs warning and does nothing if there is no such prefix.
- * prefix will typically end with a ".".
- * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user")
- * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"),
- * and we wish to convert from the longer names to the short-name. */
- public static <T> ConfigKey<T> unprefixedKey(String prefix, ConfigKey<T> key) {
- String newName = key.getName();
- if (newName.startsWith(prefix)) newName = newName.substring(prefix.length());
- else log.warn("Cannot remove prefix "+prefix+" from key "+key+" (ignoring)");
- return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
- }
-
-
- public static BrooklynProperties loadFromFile(String file) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- if (file!=null) result.addFrom(new File(file));
- return result;
- }
-
- public static BrooklynProperties filterFor(BrooklynProperties properties, Predicate<? super String> filter) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (filter.apply(k)) {
- result.put(k, properties.get(k));
- }
- }
- return result;
- }
-
- public static BrooklynProperties filterForPrefix(BrooklynProperties properties, String prefix) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: (Collection<String>)properties.keySet()) {
- if (k.startsWith(prefix)) {
- result.put(k, properties.get(k));
- }
- }
- return result;
- }
-
- /** prefix generally ends with a full stop */
- public static BrooklynProperties filterForPrefixAndStrip(Map<String,?> properties, String prefix) {
- BrooklynProperties result = BrooklynProperties.Factory.newEmpty();
- for (String k: properties.keySet()) {
- if (k.startsWith(prefix)) {
- result.put(k.substring(prefix.length()), properties.get(k));
- }
- }
- return result;
- }
-
- @SuppressWarnings("rawtypes")
- public static Set<HasConfigKey<?>> getStaticKeysOnClass(Class<?> type) {
- Set<HasConfigKey<?>> result = new LinkedHashSet<ConfigKey.HasConfigKey<?>>();
- for (Field f: type.getFields()) {
- try {
- if ((f.getModifiers() & Modifier.STATIC)==0)
- continue;
- if (ConfigKey.class.isAssignableFrom(f.getType()))
- result.add(new WrappedConfigKey((ConfigKey<?>) f.get(null)));
- else if (HasConfigKey.class.isAssignableFrom(f.getType()))
- result.add((HasConfigKey<?>) f.get(null));
- } catch (Exception e) {
- log.error("Error retrieving config key for field "+f+" on class "+type+"; rethrowing", e);
- throw Exceptions.propagate(e);
- }
- }
- return Collections.unmodifiableSet(result);
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConstraintViolationException.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConstraintViolationException.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConstraintViolationException.java
deleted file mode 100644
index 55c7f07..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConstraintViolationException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.core.config;
-
-/**
- * A {@link ConstraintViolationException} indicates one or more problems applying
- * values for {@link org.apache.brooklyn.config.ConfigKey ConfigKeys} when creating
- * a {@link org.apache.brooklyn.api.objs.BrooklynObject}.
- */
-public class ConstraintViolationException extends RuntimeException {
- private static final long serialVersionUID = -6719912119648996815L;
-
- public ConstraintViolationException(String message) {
- super(message);
- }
-
- public ConstraintViolationException(String message, Throwable cause) {
- super(message, cause);
- }
-
-}