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:06 UTC
[24/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/CatalogDo.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDo.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDo.java
deleted file mode 100644
index f30803e..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDo.java
+++ /dev/null
@@ -1,364 +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.Collections;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.javalang.AggregateClassLoader;
-import org.apache.brooklyn.util.net.Urls;
-import org.apache.brooklyn.util.time.CountdownTimer;
-import org.apache.brooklyn.util.time.Duration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-public class CatalogDo {
-
- private static final Logger log = LoggerFactory.getLogger(CatalogDo.class);
-
- volatile boolean isLoaded = false;
- final CatalogDto dto;
- ManagementContext mgmt = null;
- CatalogDo parent = null;
-
- List<CatalogDo> childrenCatalogs = new ArrayList<CatalogDo>();
- CatalogClasspathDo classpath;
- private Map<String, CatalogItemDo<?,?>> cacheById;
-
- AggregateClassLoader childrenClassLoader = AggregateClassLoader.newInstanceWithNoLoaders();
- ClassLoader recursiveClassLoader;
-
- protected CatalogDo(CatalogDto dto) {
- this.dto = Preconditions.checkNotNull(dto);
- }
-
- public CatalogDo(ManagementContext mgmt, CatalogDto dto) {
- this(dto);
- this.mgmt = mgmt;
- }
-
- boolean isLoaded() {
- return isLoaded;
- }
-
- /** Calls {@link #load(CatalogDo)} with a null parent. */
- public CatalogDo load() {
- return load(null);
- }
-
- /** Calls {@link #load(ManagementContext, CatalogDo)} with the catalog's existing management context. */
- public CatalogDo load(CatalogDo parent) {
- return load(mgmt, parent);
- }
-
- /** Calls {@link #load(ManagementContext, CatalogDo, boolean)} failing on load errors. */
- public synchronized CatalogDo load(ManagementContext mgmt, CatalogDo parent) {
- return load(mgmt, parent, true);
- }
-
- /** causes all URL-based catalogs to have their manifests loaded,
- * and all scanning-based classpaths to scan the classpaths
- * (but does not load all JARs)
- */
- public synchronized CatalogDo load(ManagementContext mgmt, CatalogDo parent, boolean failOnLoadError) {
- if (isLoaded()) {
- if (mgmt!=null && !Objects.equal(mgmt, this.mgmt)) {
- throw new IllegalStateException("Cannot set mgmt "+mgmt+" on "+this+" after catalog is loaded");
- }
- log.debug("Catalog "+this+" is already loaded");
- return this;
- }
- loadThisCatalog(mgmt, parent, failOnLoadError);
- loadChildrenCatalogs(failOnLoadError);
- buildCaches();
- return this;
- }
-
- protected synchronized void loadThisCatalog(ManagementContext mgmt, CatalogDo parent, boolean failOnLoadError) {
- if (isLoaded()) return;
- CatalogUtils.logDebugOrTraceIfRebinding(log, "Loading catalog {} into {}", this, parent);
- if (this.parent!=null && !this.parent.equals(parent))
- log.warn("Catalog "+this+" being initialised with different parent "+parent+" when already parented by "+this.parent, new Throwable("source of reparented "+this));
- if (this.mgmt!=null && !this.mgmt.equals(mgmt))
- log.warn("Catalog "+this+" being initialised with different mgmt "+mgmt+" when already managed by "+this.mgmt, new Throwable("source of reparented "+this));
- this.parent = parent;
- this.mgmt = mgmt;
- dto.populate();
- loadCatalogClasspath();
- loadCatalogItems(failOnLoadError);
- isLoaded = true;
- synchronized (this) {
- notifyAll();
- }
- }
-
- private void loadCatalogClasspath() {
- try {
- classpath = new CatalogClasspathDo(this);
- classpath.load();
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- log.error("Unable to load catalog "+this+" (ignoring): "+e);
- log.info("Trace for failure to load "+this+": "+e, e);
- }
- }
-
- private void loadCatalogItems(boolean failOnLoadError) {
- Iterable<CatalogItemDtoAbstract<?, ?>> entries = dto.getUniqueEntries();
- if (entries!=null) {
- for (CatalogItemDtoAbstract<?,?> entry : entries) {
- try {
- CatalogUtils.installLibraries(mgmt, entry.getLibraries());
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- if (failOnLoadError) {
- Exceptions.propagate(e);
- } else {
- log.error("Loading bundles for catalog item " + entry + " failed: " + e.getMessage(), e);
- }
- }
- }
- }
- }
-
- public boolean blockIfNotLoaded(Duration timeout) throws InterruptedException {
- if (isLoaded()) return true;
- synchronized (this) {
- if (isLoaded()) return true;
- CountdownTimer timer = CountdownTimer.newInstanceStarted(timeout);
- while (!isLoaded())
- if (!timer.waitOnForExpiry(this))
- return false;
- return true;
- }
- }
-
- protected void loadChildrenCatalogs(boolean failOnLoadError) {
- if (dto.catalogs!=null) {
- for (CatalogDto child: dto.catalogs) {
- loadCatalog(child, failOnLoadError);
- }
- }
- }
-
- CatalogDo loadCatalog(CatalogDto child, boolean failOnLoadError) {
- CatalogDo childL = new CatalogDo(child);
- childrenCatalogs.add(childL);
- childL.load(mgmt, this, failOnLoadError);
- childrenClassLoader.addFirst(childL.getRecursiveClassLoader());
- clearCache(false);
- return childL;
- }
-
- protected Map<String, CatalogItemDo<?,?>> getIdCache() {
- Map<String, CatalogItemDo<?,?>> cache = this.cacheById;
- if (cache==null) cache = buildCaches();
- return cache;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- protected synchronized Map<String, CatalogItemDo<?,?>> buildCaches() {
- if (cacheById != null) return cacheById;
- CatalogUtils.logDebugOrTraceIfRebinding(log, "Building cache for {}", this);
- if (!isLoaded())
- log.debug("Catalog not fully loaded when loading cache of "+this);
-
- Map<String, CatalogItemDo<?,?>> cache = new LinkedHashMap<String, CatalogItemDo<?,?>>();
-
- // build the cache; first from children catalogs, then from local entities
- // so that root and near-root takes precedence over deeper items;
- // and go through in reverse order so that things at the top of the file take precedence
- // (both in the cache and in the aggregate class loader);
- // however anything added _subsequently_ will take precedence (again in both)
- if (dto.catalogs!=null) {
- List<CatalogDo> catalogsReversed = new ArrayList<CatalogDo>(childrenCatalogs);
- Collections.reverse(catalogsReversed);
- for (CatalogDo child: catalogsReversed) {
- cache.putAll(child.getIdCache());
- }
- }
- if (dto.getUniqueEntries()!=null) {
- List<CatalogItemDtoAbstract<?,?>> entriesReversed = MutableList.copyOf(dto.getUniqueEntries());
- Collections.reverse(entriesReversed);
- for (CatalogItemDtoAbstract<?,?> entry: entriesReversed)
- cache.put(entry.getId(), new CatalogItemDo(this, entry));
- }
- this.cacheById = cache;
- return cache;
- }
-
- protected synchronized void clearCache(boolean deep) {
- this.cacheById = null;
- if (deep) {
- for (CatalogDo child : childrenCatalogs) {
- child.clearCache(true);
- }
- }
- clearParentCache();
- }
- protected void clearParentCache() {
- if (this.parent!=null)
- this.parent.clearCache(false);
- }
-
- /**
- * Adds the given entry to the catalog, with no enrichment.
- * Callers may prefer {@link CatalogClasspathDo#addCatalogEntry(CatalogItemDtoAbstract, Class)}
- */
- public synchronized void addEntry(CatalogItemDtoAbstract<?,?> entry) {
- dto.addEntry(entry);
-
- // could do clearCache(false); but this is slightly more efficient...
- if (cacheById != null) {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- CatalogItemDo<?, ?> cdo = new CatalogItemDo(this, entry);
- cacheById.put(entry.getId(), cdo);
- }
- clearParentCache();
-
- if (mgmt != null) {
- mgmt.getRebindManager().getChangeListener().onManaged(entry);
- }
- }
-
- /**
- * Removes the given entry from the catalog.
- */
- public synchronized void deleteEntry(CatalogItemDtoAbstract<?, ?> entry) {
- dto.removeEntry(entry);
-
- // could do clearCache(false); but this is slightly more efficient...
- if (cacheById != null) {
- cacheById.remove(entry.getId());
- }
- clearParentCache();
-
- if (mgmt != null) {
- // TODO: Can the entry be in more than one catalogue? The management context has no notion of
- // catalogue hierarchy so this will effectively remove it from all catalogues.
- // (YES- we're assuming ID's are unique across all catalogues; if not, things get out of sync;
- // however see note at top of BasicBrooklynCatalog --
- // manualCatalog and OSGi is used for everything now except legacy XML trees)
- mgmt.getRebindManager().getChangeListener().onUnmanaged(entry);
- }
- }
-
- /** returns loaded catalog, if this has been loaded */
- CatalogDo addCatalog(CatalogDto child) {
- if (dto.catalogs == null)
- dto.catalogs = new ArrayList<CatalogDto>();
- dto.catalogs.add(child);
- if (!isLoaded())
- return null;
- return loadCatalog(child, true);
- }
-
- /** adds the given urls; filters out any nulls supplied */
- public synchronized void addToClasspath(String ...urls) {
- if (dto.classpath == null)
- dto.classpath = new CatalogClasspathDto();
- for (String url: urls) {
- if (url!=null)
- dto.classpath.addEntry(url);
- }
- if (isLoaded())
- throw new IllegalStateException("dynamic classpath entry value update not supported");
- // easy enough to add, just support unload+reload (and can also allow dynamic setScan below)
- // but more predictable if we don't; the one exception is in the manualAdditionsCatalog
- // where BasicBrooklynCatalog reaches in and updates the DTO and/or CompositeClassLoader directly, if necessary
-// for (String url: urls)
-// loadedClasspath.addEntry(url);
- }
-
- public synchronized void setClasspathScanForEntities(CatalogScanningModes value) {
- if (dto.classpath == null)
- dto.classpath = new CatalogClasspathDto();
- dto.classpath.scan = value;
- if (isLoaded())
- throw new IllegalStateException("dynamic classpath scan value update not supported");
- // easy enough to add, see above
- }
-
- @Override
- public String toString() {
- String size = cacheById == null ? "not yet loaded" : "size " + cacheById.size();
- return "Loaded:" + dto + "(" + size + ")";
- }
-
- /** is "local" if it and all ancestors are not based on any remote urls */
- public boolean isLocal() {
- if (dto.url != null) {
- String proto = Urls.getProtocol(dto.url);
- if (proto != null) {
- // 'file' is the only protocol accepted as "local"
- if (!"file".equals(proto)) return false;
- }
- }
- return parent == null || parent.isLocal();
- }
-
- /** classloader for only the entries in this catalog's classpath */
- public ClassLoader getLocalClassLoader() {
- if (classpath != null) return classpath.getLocalClassLoader();
- return null;
- }
-
- /** recursive classloader is the local classloader plus all children catalog's classloader */
- public ClassLoader getRecursiveClassLoader() {
- if (recursiveClassLoader == null) loadRecursiveClassLoader();
- return recursiveClassLoader;
- }
-
- protected synchronized void loadRecursiveClassLoader() {
- if (recursiveClassLoader!=null) return;
- AggregateClassLoader cl = AggregateClassLoader.newInstanceWithNoLoaders();
- cl.addFirst(childrenClassLoader);
- ClassLoader local = getLocalClassLoader();
- if (local != null) cl.addFirst(local);
- if (parent == null) {
- // we are root. include the mgmt base classloader and/or standard class loaders
- ClassLoader base = mgmt != null ? ((ManagementContextInternal)mgmt).getBaseClassLoader() : null;
- if (base != null) cl.addFirst(base);
- else {
- cl.addFirst(getClass().getClassLoader());
- cl.addFirst(Object.class.getClassLoader());
- }
- }
- recursiveClassLoader = cl;
- }
-
- /** the root classloader is the recursive CL from the outermost catalog
- * (which includes the base classloader from the mgmt context, if set) */
- public ClassLoader getRootClassLoader() {
- if (parent != null) return parent.getRootClassLoader();
- return getRecursiveClassLoader();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDto.java
deleted file mode 100644
index 1bd2236..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDto.java
+++ /dev/null
@@ -1,229 +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.io.InputStream;
-import java.io.StringReader;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.ResourceUtils;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.exceptions.PropagatedRuntimeException;
-import org.apache.brooklyn.util.stream.Streams;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Objects;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Lists;
-
-@Beta
-public class CatalogDto {
-
- private static final Logger LOG = LoggerFactory.getLogger(CatalogDto.class);
-
- String id;
- String url;
- String contents;
- String contentsDescription;
- String name;
- String description;
- CatalogClasspathDto classpath;
- private List<CatalogItemDtoAbstract<?,?>> entries = null;
-
- // for thread-safety, any dynamic additions to this should be handled by a method
- // in this class which does copy-on-write
- List<CatalogDto> catalogs = null;
-
- public static CatalogDto newDefaultLocalScanningDto(CatalogClasspathDo.CatalogScanningModes scanMode) {
- CatalogDo result = new CatalogDo(
- newNamedInstance("Local Scanned Catalog", "All annotated Brooklyn entities detected in the default classpath", "scanning-local-classpath") );
- result.setClasspathScanForEntities(scanMode);
- return result.dto;
- }
-
- /** @deprecated since 0.7.0 use {@link #newDtoFromXmlUrl(String)} if you must, but note the xml format itself is deprecated */
- @Deprecated
- public static CatalogDto newDtoFromUrl(String url) {
- return newDtoFromXmlUrl(url);
- }
-
- /** @deprecated since 0.7.0 the xml format is deprecated; use YAML parse routines on BasicBrooklynCatalog */
- @Deprecated
- public static CatalogDto newDtoFromXmlUrl(String url) {
- if (LOG.isDebugEnabled()) LOG.debug("Retrieving catalog from: {}", url);
- try {
- InputStream source = ResourceUtils.create().getResourceFromUrl(url);
- String contents = Streams.readFullyString(source);
- return newDtoFromXmlContents(contents, url);
- } catch (Throwable t) {
- Exceptions.propagateIfFatal(t);
- throw new PropagatedRuntimeException("Unable to retrieve catalog from " + url + ": " + t, t);
- }
- }
-
- /** @deprecated since 0.7.0 the xml format is deprecated; use YAML parse routines on BasicBrooklynCatalog */
- @Deprecated
- public static CatalogDto newDtoFromXmlContents(String xmlContents, String originDescription) {
- CatalogDto result = (CatalogDto) new CatalogXmlSerializer().deserialize(new StringReader(xmlContents));
- result.contentsDescription = originDescription;
-
- if (LOG.isDebugEnabled()) LOG.debug("Retrieved catalog from: {}", originDescription);
- return result;
- }
-
- /**
- * Creates a DTO.
- * <p>
- * The way contents is treated may change; thus this (and much of catalog) should be treated as beta.
- *
- * @param name
- * @param description
- * @param optionalContentsDescription optional description of contents; if null, we normally expect source 'contents' to be set later;
- * if the DTO has no 'contents' (ie XML source) then a description should be supplied so we know who is populating it
- * (e.g. manual additions); without this, warnings may be generated
- *
- * @return a new Catalog DTO
- */
- public static CatalogDto newNamedInstance(String name, String description, String optionalContentsDescription) {
- CatalogDto result = new CatalogDto();
- result.name = name;
- result.description = description;
- if (optionalContentsDescription!=null) result.contentsDescription = optionalContentsDescription;
- return result;
- }
-
- /** Used when caller wishes to create an explicitly empty catalog */
- public static CatalogDto newEmptyInstance(String optionalContentsDescription) {
- CatalogDto result = new CatalogDto();
- if (optionalContentsDescription!=null) result.contentsDescription = optionalContentsDescription;
- return result;
- }
-
- public static CatalogDto newLinkedInstance(String url) {
- CatalogDto result = new CatalogDto();
- result.contentsDescription = url;
- result.contents = ResourceUtils.create().getResourceAsString(url);
- return result;
- }
-
- /** @deprecated since 0.7.0 use {@link #newDtoFromCatalogItems(Collection, String)}, supplying a description for tracking */
- @Deprecated
- public static CatalogDto newDtoFromCatalogItems(Collection<CatalogItem<?, ?>> entries) {
- return newDtoFromCatalogItems(entries, null);
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static CatalogDto newDtoFromCatalogItems(Collection<CatalogItem<?, ?>> entries, String description) {
- CatalogDto result = new CatalogDto();
- result.contentsDescription = description;
- // Weird casts because compiler does not seem to like
- // .copyInto(Lists.<CatalogItemDtoAbstract<?, ?>>newArrayListWithExpectedSize(entries.size()));
- result.entries = (List<CatalogItemDtoAbstract<?, ?>>) (List) FluentIterable.from(entries)
- .filter(CatalogItemDtoAbstract.class)
- .copyInto(Lists.newArrayListWithExpectedSize(entries.size()));
- return result;
- }
-
- void populate() {
- if (contents==null) {
- if (url != null) {
- contents = ResourceUtils.create().getResourceAsString(url);
- contentsDescription = url;
- } else if (contentsDescription==null) {
- LOG.debug("Catalog DTO has no contents and no description; ignoring call to populate it. Description should be set to suppress this message.");
- return;
- } else {
- LOG.trace("Nothing needs doing (no contents or URL) for catalog with contents described as "+contentsDescription+".");
- return;
- }
- }
-
- CatalogDto remoteDto = newDtoFromXmlContents(contents, contentsDescription);
- try {
- copyFrom(remoteDto, true);
- } catch (Exception e) {
- Exceptions.propagate(e);
- }
- }
-
- /**
- * @throws NullPointerException If source is null (and !skipNulls)
- */
- void copyFrom(CatalogDto source, boolean skipNulls) throws IllegalAccessException {
- if (source==null) {
- if (skipNulls) return;
- throw new NullPointerException("source DTO is null, when copying to "+this);
- }
-
- if (!skipNulls || source.id != null) id = source.id;
- if (!skipNulls || source.contentsDescription != null) contentsDescription = source.contentsDescription;
- if (!skipNulls || source.contents != null) contents = source.contents;
- if (!skipNulls || source.name != null) name = source.name;
- if (!skipNulls || source.description != null) description = source.description;
- if (!skipNulls || source.classpath != null) classpath = source.classpath;
- if (!skipNulls || source.entries != null) entries = source.entries;
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(this)
- .omitNullValues()
- .add("name", name)
- .add("id", id)
- .add("contentsDescription", contentsDescription)
- .toString();
- }
-
- // temporary fix for issue where entries might not be unique
- Iterable<CatalogItemDtoAbstract<?, ?>> getUniqueEntries() {
- if (entries==null) return null;
- Map<String, CatalogItemDtoAbstract<?, ?>> result = getEntriesMap();
- return result.values();
- }
-
- private Map<String, CatalogItemDtoAbstract<?, ?>> getEntriesMap() {
- if (entries==null) return null;
- Map<String,CatalogItemDtoAbstract<?, ?>> result = MutableMap.of();
- for (CatalogItemDtoAbstract<?,?> entry: entries) {
- result.put(entry.getId(), entry);
- }
- return result;
- }
-
- void removeEntry(CatalogItemDtoAbstract<?, ?> entry) {
- if (entries!=null)
- entries.remove(entry);
- }
-
- void addEntry(CatalogItemDtoAbstract<?, ?> entry) {
- if (entries == null) entries = MutableList.of();
- CatalogItemDtoAbstract<?, ?> oldEntry = getEntriesMap().get(entry.getId());
- entries.add(entry);
- if (oldEntry!=null)
- removeEntry(oldEntry);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDtoUtils.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDtoUtils.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDtoUtils.java
deleted file mode 100644
index 93a5cc1..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogDtoUtils.java
+++ /dev/null
@@ -1,66 +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.io.InputStream;
-import java.io.InputStreamReader;
-
-import org.apache.brooklyn.core.catalog.internal.CatalogClasspathDo.CatalogScanningModes;
-import org.apache.brooklyn.util.core.ResourceUtils;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CatalogDtoUtils {
-
- private static final Logger log = LoggerFactory.getLogger(CatalogDtoUtils.class);
-
- public static CatalogDto newDefaultLocalScanningDto(CatalogScanningModes scanMode) {
- return CatalogDto.newDefaultLocalScanningDto(scanMode);
- }
-
- /** throws if there are any problems in retrieving or copying */
- public static void populateFromUrl(CatalogDto dto, String url) {
- CatalogDto remoteDto = newDtoFromUrl(url);
- try {
- copyDto(remoteDto, dto, true);
- } catch (Exception e) {
- Exceptions.propagate(e);
- }
- }
-
- /** does a shallow copy.
- * "skipNulls" means not to copy any fields from the source which are null */
- static void copyDto(CatalogDto source, CatalogDto target, boolean skipNulls) throws IllegalArgumentException, IllegalAccessException {
- target.copyFrom(source, skipNulls);
- }
-
- public static CatalogDto newDtoFromUrl(String url) {
- if (log.isDebugEnabled()) log.debug("Retrieving catalog from: {}", url);
- try {
- InputStream source = ResourceUtils.create().getResourceFromUrl(url);
- CatalogDto result = (CatalogDto) new CatalogXmlSerializer().deserialize(new InputStreamReader(source));
- if (log.isDebugEnabled()) log.debug("Retrieved catalog from: {}", url);
- return result;
- } catch (Throwable t) {
- log.debug("Unable to retrieve catalog from: "+url+" ("+t+")");
- throw Exceptions.propagate(t);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogEntityItemDto.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogEntityItemDto.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogEntityItemDto.java
deleted file mode 100644
index 851287a..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogEntityItemDto.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.entity.Entity;
-import org.apache.brooklyn.api.entity.EntitySpec;
-
-
-public class CatalogEntityItemDto extends CatalogItemDtoAbstract<Entity,EntitySpec<?>> {
-
- @Override
- public CatalogItemType getCatalogItemType() {
- return CatalogItemType.ENTITY;
- }
-
- @Override
- public Class<Entity> getCatalogItemJavaType() {
- return Entity.class;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- @Override
- public Class<EntitySpec<?>> 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/CatalogInitialization.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
deleted file mode 100644
index 37783cd..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ /dev/null
@@ -1,453 +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.io.File;
-import java.util.Collection;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.ha.ManagementNodeState;
-import org.apache.brooklyn.core.catalog.CatalogLoadMode;
-import org.apache.brooklyn.core.mgmt.ManagementContextInjectable;
-import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.core.server.BrooklynServerConfig;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.core.ResourceUtils;
-import org.apache.brooklyn.util.core.flags.TypeCoercions;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.exceptions.FatalRuntimeException;
-import org.apache.brooklyn.util.exceptions.RuntimeInterruptedException;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.apache.brooklyn.util.javalang.JavaClassNames;
-import org.apache.brooklyn.util.os.Os;
-import org.apache.brooklyn.util.text.Strings;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-@Beta
-public class CatalogInitialization implements ManagementContextInjectable {
-
- /*
-
- A1) if not persisting, go to B1
- A2) if --catalog-reset, delete persisted catalog items
- A3) if there is a persisted catalog (and it wasn't not deleted by A2), read it and go to C1
- A4) go to B1
-
- B1) look for --catalog-initial, if so read it, then go to C1
- B2) look for BrooklynServerConfig.BROOKLYN_CATALOG_URL, if so, read it, supporting YAML or XML (warning if XML), then go to C1
- B3) look for ~/.brooklyn/catalog.bom, if exists, read it then go to C1
- B4) look for ~/.brooklyn/brooklyn.xml, if exists, warn, read it then go to C1
- B5) read all classpath://brooklyn/default.catalog.bom items, if they exist (and for now they will)
- B6) go to C1
-
- C1) if --catalog-add, read and add those items
-
- D1) if persisting, read the rest of the persisted items (entities etc)
-
- */
-
- private static final Logger log = LoggerFactory.getLogger(CatalogInitialization.class);
-
- private String initialUri;
- private boolean reset;
- private String additionsUri;
- private boolean force;
-
- private boolean disallowLocal = false;
- private List<Function<CatalogInitialization, Void>> callbacks = MutableList.of();
- private boolean
- /** has run an unofficial initialization (i.e. an early load, triggered by an early read of the catalog) */
- hasRunUnofficialInitialization = false,
- /** has run an official initialization, but it is not a permanent one (e.g. during a hot standby mode, or a run failed) */
- hasRunTransientOfficialInitialization = false,
- /** has run an official initialization which is permanent (node is master, and the new catalog is now set) */
- hasRunFinalInitialization = false;
- /** is running a populate method; used to prevent recursive loops */
- private boolean isPopulating = false;
-
- private ManagementContext managementContext;
- private boolean isStartingUp = false;
- private boolean failOnStartupErrors = false;
-
- private Object populatingCatalogMutex = new Object();
-
- public CatalogInitialization(String initialUri, boolean reset, String additionUri, boolean force) {
- this.initialUri = initialUri;
- this.reset = reset;
- this.additionsUri = additionUri;
- this.force = force;
- }
-
- public CatalogInitialization() {
- this(null, false, null, false);
- }
-
- @Override
- public void setManagementContext(ManagementContext managementContext) {
- Preconditions.checkNotNull(managementContext, "management context");
- if (this.managementContext!=null && managementContext!=this.managementContext)
- throw new IllegalStateException("Cannot switch management context, from "+this.managementContext+" to "+managementContext);
- this.managementContext = managementContext;
- }
-
- /** Called by the framework to set true while starting up, and false afterwards,
- * in order to assist in appropriate logging and error handling. */
- public void setStartingUp(boolean isStartingUp) {
- this.isStartingUp = isStartingUp;
- }
-
- public void setFailOnStartupErrors(boolean startupFailOnCatalogErrors) {
- this.failOnStartupErrors = startupFailOnCatalogErrors;
- }
-
- public CatalogInitialization addPopulationCallback(Function<CatalogInitialization, Void> callback) {
- callbacks.add(callback);
- return this;
- }
-
- public ManagementContext getManagementContext() {
- return Preconditions.checkNotNull(managementContext, "management context has not been injected into "+this);
- }
-
- public boolean isInitialResetRequested() {
- return reset;
- }
-
- /** Returns true if the canonical initialization has completed,
- * that is, an initialization which is done when a node is rebinded as master
- * (or an initialization done by the startup routines when not running persistence);
- * see also {@link #hasRunAnyInitialization()}. */
- public boolean hasRunFinalInitialization() { return hasRunFinalInitialization; }
- /** Returns true if an official initialization has run,
- * even if it was a transient run, e.g. so that the launch sequence can tell whether rebind has triggered initialization */
- public boolean hasRunOfficialInitialization() { return hasRunFinalInitialization || hasRunTransientOfficialInitialization; }
- /** Returns true if the initializer has run at all,
- * including transient initializations which might be needed before a canonical becoming-master rebind,
- * for instance because the catalog is being accessed before loading rebind information
- * (done by {@link #populateUnofficial(BasicBrooklynCatalog)}) */
- public boolean hasRunAnyInitialization() { return hasRunFinalInitialization || hasRunTransientOfficialInitialization || hasRunUnofficialInitialization; }
-
- /** makes or updates the mgmt catalog, based on the settings in this class
- * @param nodeState the management node for which this is being read; if master, then we expect this run to be the last one,
- * and so subsequent applications should ignore any initialization data (e.g. on a subsequent promotion to master,
- * after a master -> standby -> master cycle)
- * @param needsInitialItemsLoaded whether the catalog needs the initial items loaded
- * @param needsAdditionalItemsLoaded whether the catalog needs the additions loaded
- * @param optionalExcplicitItemsForResettingCatalog
- * if supplied, the catalog is reset to contain only these items, before calling any other initialization
- * for use primarily when rebinding
- */
- public void populateCatalog(ManagementNodeState nodeState, boolean needsInitialItemsLoaded, boolean needsAdditionsLoaded, Collection<CatalogItem<?, ?>> optionalExcplicitItemsForResettingCatalog) {
- if (log.isDebugEnabled()) {
- String message = "Populating catalog for "+nodeState+", needsInitial="+needsInitialItemsLoaded+", needsAdditional="+needsAdditionsLoaded+", explicitItems="+(optionalExcplicitItemsForResettingCatalog==null ? "null" : optionalExcplicitItemsForResettingCatalog.size())+"; from "+JavaClassNames.callerNiceClassAndMethod(1);
- if (!ManagementNodeState.isHotProxy(nodeState)) {
- log.debug(message);
- } else {
- // in hot modes, make this message trace so we don't get too much output then
- log.trace(message);
- }
- }
- synchronized (populatingCatalogMutex) {
- try {
- if (hasRunFinalInitialization() && (needsInitialItemsLoaded || needsAdditionsLoaded)) {
- // if we have already run "final" then we should only ever be used to reset the catalog,
- // not to initialize or add; e.g. we are being given a fixed list on a subsequent master rebind after the initial master rebind
- log.warn("Catalog initialization called to populate initial, even though it has already run the final official initialization");
- }
- isPopulating = true;
- BasicBrooklynCatalog catalog = (BasicBrooklynCatalog) managementContext.getCatalog();
- if (!catalog.getCatalog().isLoaded()) {
- catalog.load();
- } else {
- if (needsInitialItemsLoaded && hasRunAnyInitialization()) {
- // an indication that something caused it to load early; not severe, but unusual
- if (hasRunTransientOfficialInitialization) {
- log.debug("Catalog initialization now populating, but has noted a previous official run which was not final (probalby loaded while in a standby mode, or a previous run failed); overwriting any items installed earlier");
- } else {
- log.warn("Catalog initialization now populating, but has noted a previous unofficial run (it may have been an early web request); overwriting any items installed earlier");
- }
- catalog.reset(ImmutableList.<CatalogItem<?,?>>of());
- }
- }
-
- populateCatalogImpl(catalog, needsInitialItemsLoaded, needsAdditionsLoaded, optionalExcplicitItemsForResettingCatalog);
- if (nodeState == ManagementNodeState.MASTER) {
- // TODO ideally this would remain false until it has *persisted* the changed catalog;
- // if there is a subsequent startup failure the forced additions will not be persisted,
- // but nor will they be loaded on a subsequent run.
- // callers will have to restart a brooklyn, or reach into this class to change this field,
- // or (recommended) manually adjust the catalog.
- // TODO also, if a node comes up in standby, the addition might not take effector for a while
- //
- // however since these options are mainly for use on the very first brooklyn run, it's not such a big deal;
- // once up and running the typical way to add items is via the REST API
- hasRunFinalInitialization = true;
- }
- } catch (Throwable e) {
- log.warn("Error populating catalog (rethrowing): "+e, e);
- throw Exceptions.propagate(e);
- } finally {
- if (!hasRunFinalInitialization) {
- hasRunTransientOfficialInitialization = true;
- }
- isPopulating = false;
- }
- }
- }
-
- private void populateCatalogImpl(BasicBrooklynCatalog catalog, boolean needsInitialItemsLoaded, boolean needsAdditionsLoaded, Collection<CatalogItem<?, ?>> optionalItemsForResettingCatalog) {
- applyCatalogLoadMode();
-
- if (optionalItemsForResettingCatalog!=null) {
- catalog.reset(optionalItemsForResettingCatalog);
- }
-
- if (needsInitialItemsLoaded) {
- populateInitial(catalog);
- }
-
- if (needsAdditionsLoaded) {
- populateAdditions(catalog);
- populateViaCallbacks(catalog);
- }
- }
-
- private enum PopulateMode { YAML, XML, AUTODETECT }
-
- protected void populateInitial(BasicBrooklynCatalog catalog) {
- if (disallowLocal) {
- if (!hasRunFinalInitialization()) {
- log.debug("CLI initial catalog not being read when local catalog load mode is disallowed.");
- }
- return;
- }
-
-// B1) look for --catalog-initial, if so read it, then go to C1
-// B2) look for BrooklynServerConfig.BROOKLYN_CATALOG_URL, if so, read it, supporting YAML or XML (warning if XML), then go to C1
-// B3) look for ~/.brooklyn/catalog.bom, if exists, read it then go to C1
-// B4) look for ~/.brooklyn/brooklyn.xml, if exists, warn, read it then go to C1
-// B5) read all classpath://brooklyn/default.catalog.bom items, if they exist (and for now they will)
-// B6) go to C1
-
- if (initialUri!=null) {
- populateInitialFromUri(catalog, initialUri, PopulateMode.AUTODETECT);
- return;
- }
-
- String catalogUrl = managementContext.getConfig().getConfig(BrooklynServerConfig.BROOKLYN_CATALOG_URL);
- if (Strings.isNonBlank(catalogUrl)) {
- populateInitialFromUri(catalog, catalogUrl, PopulateMode.AUTODETECT);
- return;
- }
-
- catalogUrl = Os.mergePaths(BrooklynServerConfig.getMgmtBaseDir( managementContext.getConfig() ), "catalog.bom");
- if (new File(catalogUrl).exists()) {
- populateInitialFromUri(catalog, new File(catalogUrl).toURI().toString(), PopulateMode.YAML);
- return;
- }
-
- catalogUrl = Os.mergePaths(BrooklynServerConfig.getMgmtBaseDir( managementContext.getConfig() ), "catalog.xml");
- if (new File(catalogUrl).exists()) {
- populateInitialFromUri(catalog, new File(catalogUrl).toURI().toString(), PopulateMode.XML);
- return;
- }
-
- // otherwise look for for classpath:/brooklyn/default.catalog.bom --
- // there is one on the classpath which says to scan, and provides a few templates;
- // if one is supplied by user in the conf/ dir that will override the item from the classpath
- // (TBD - we might want to scan for all such bom's?)
-
- catalogUrl = "classpath:/brooklyn/default.catalog.bom";
- if (new ResourceUtils(this).doesUrlExist(catalogUrl)) {
- populateInitialFromUri(catalog, catalogUrl, PopulateMode.YAML);
- return;
- }
-
- log.info("No catalog found on classpath or specified; catalog will not be initialized.");
- return;
- }
-
- private void populateInitialFromUri(BasicBrooklynCatalog catalog, String catalogUrl, PopulateMode mode) {
- log.debug("Loading initial catalog from {}", catalogUrl);
-
- Exception problem = null;
- Object result = null;
-
- String contents = null;
- try {
- contents = new ResourceUtils(this).getResourceAsString(catalogUrl);
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- if (problem==null) problem = e;
- }
-
- if (contents!=null && (mode==PopulateMode.YAML || mode==PopulateMode.AUTODETECT)) {
- // try YAML first
- try {
- catalog.reset(MutableList.<CatalogItem<?,?>>of());
- result = catalog.addItems(contents);
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- if (problem==null) problem = e;
- }
- }
-
- if (result==null && contents!=null && (mode==PopulateMode.XML || mode==PopulateMode.AUTODETECT)) {
- // then try XML
- try {
- populateInitialFromUriXml(catalog, catalogUrl, contents);
- // clear YAML problem
- problem = null;
- } catch (Exception e) {
- Exceptions.propagateIfFatal(e);
- if (problem==null) problem = e;
- }
- }
-
- if (result!=null) {
- log.debug("Loaded initial catalog from {}: {}", catalogUrl, result);
- }
- if (problem!=null) {
- log.warn("Error importing catalog from " + catalogUrl + ": " + problem, problem);
- // TODO inform mgmt of error
- }
-
- }
-
- // deprecated XML format
- @SuppressWarnings("deprecation")
- private void populateInitialFromUriXml(BasicBrooklynCatalog catalog, String catalogUrl, String contents) {
- CatalogDto dto = CatalogDto.newDtoFromXmlContents(contents, catalogUrl);
- if (dto!=null) {
- catalog.reset(dto);
- }
- }
-
- boolean hasRunAdditions = false;
- protected void populateAdditions(BasicBrooklynCatalog catalog) {
- if (Strings.isNonBlank(additionsUri)) {
- if (disallowLocal) {
- if (!hasRunAdditions) {
- log.warn("CLI additions supplied but not supported when catalog load mode disallows local loads; ignoring.");
- }
- return;
- }
- if (!hasRunAdditions) {
- log.debug("Adding to catalog from CLI: "+additionsUri+" (force: "+force+")");
- }
- Iterable<? extends CatalogItem<?, ?>> items = catalog.addItems(
- new ResourceUtils(this).getResourceAsString(additionsUri), force);
-
- if (!hasRunAdditions)
- log.debug("Added to catalog from CLI: "+items);
- else
- log.debug("Added to catalog from CLI: count "+Iterables.size(items));
-
- hasRunAdditions = true;
- }
- }
-
- protected void populateViaCallbacks(BasicBrooklynCatalog catalog) {
- for (Function<CatalogInitialization, Void> callback: callbacks)
- callback.apply(this);
- }
-
- private Object setFromCLMMutex = new Object();
- private boolean setFromCatalogLoadMode = false;
-
- /** @deprecated since introduced in 0.7.0, only for legacy compatibility with
- * {@link CatalogLoadMode} {@link BrooklynServerConfig#CATALOG_LOAD_MODE},
- * allowing control of catalog loading from a brooklyn property */
- @Deprecated
- public void applyCatalogLoadMode() {
- synchronized (setFromCLMMutex) {
- if (setFromCatalogLoadMode) return;
- setFromCatalogLoadMode = true;
- Maybe<Object> clmm = ((ManagementContextInternal)managementContext).getConfig().getConfigRaw(BrooklynServerConfig.CATALOG_LOAD_MODE, false);
- if (clmm.isAbsent()) return;
- org.apache.brooklyn.core.catalog.CatalogLoadMode clm = TypeCoercions.coerce(clmm.get(), org.apache.brooklyn.core.catalog.CatalogLoadMode.class);
- log.warn("Legacy CatalogLoadMode "+clm+" set: applying, but this should be changed to use new CLI --catalogXxx commands");
- switch (clm) {
- case LOAD_BROOKLYN_CATALOG_URL:
- reset = true;
- break;
- case LOAD_BROOKLYN_CATALOG_URL_IF_NO_PERSISTED_STATE:
- // now the default
- break;
- case LOAD_PERSISTED_STATE:
- disallowLocal = true;
- break;
- }
- }
- }
-
- /** Creates the catalog based on parameters set here, if not yet loaded,
- * but ignoring persisted state and warning if persistence is on and we are starting up
- * (because the official persistence is preferred and the catalog will be subsequently replaced);
- * for use when the catalog is accessed before persistence is completed.
- * <p>
- * This method is primarily used during testing, which in many cases does not enforce the full startup order
- * and which wants a local catalog in any case. It may also be invoked if a client requests the catalog
- * while the server is starting up. */
- public void populateUnofficial(BasicBrooklynCatalog catalog) {
- synchronized (populatingCatalogMutex) {
- // check isPopulating in case this method gets called from inside another populate call
- if (hasRunAnyInitialization() || isPopulating) return;
- log.debug("Populating catalog unofficially ("+catalog+")");
- isPopulating = true;
- try {
- if (isStartingUp) {
- log.warn("Catalog access requested when not yet initialized; populating best effort rather than through recommended pathway. Catalog data may be replaced subsequently.");
- }
- populateCatalogImpl(catalog, true, true, null);
- } finally {
- hasRunUnofficialInitialization = true;
- isPopulating = false;
- }
- }
- }
-
- public void handleException(Throwable throwable, Object details) {
- if (throwable instanceof InterruptedException)
- throw new RuntimeInterruptedException((InterruptedException) throwable);
- if (throwable instanceof RuntimeInterruptedException)
- throw (RuntimeInterruptedException) throwable;
-
- String throwableText = Exceptions.collapseText(throwable);
- log.error("Error loading catalog item '"+details+"': "+throwableText);
- log.debug("Trace for error loading catalog item '"+details+"': "+throwableText, throwable);
-
- // TODO give more detail when adding
- ((ManagementContextInternal)getManagementContext()).errors().add(throwable);
-
- if (isStartingUp && failOnStartupErrors) {
- throw new FatalRuntimeException("Unable to load catalog item '"+details+"': "+throwableText, throwable);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemBuilder.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemBuilder.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemBuilder.java
deleted file mode 100644
index 299abdb..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemBuilder.java
+++ /dev/null
@@ -1,150 +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.CatalogBundle;
-import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
-
-import com.google.common.base.Preconditions;
-
-public class CatalogItemBuilder<CIConcreteType extends CatalogItemDtoAbstract<?, ?>> {
- private CIConcreteType dto;
-
- public static CatalogItemBuilder<?> newItem(CatalogItemType itemType, String symbolicName, String version) {
- Preconditions.checkNotNull(itemType, "itemType required");
- switch (itemType) {
- case ENTITY: return newEntity(symbolicName, version);
- case TEMPLATE: return newTemplate(symbolicName, version);
- case POLICY: return newPolicy(symbolicName, version);
- case LOCATION: return newLocation(symbolicName, version);
- }
- throw new IllegalStateException("Unexpected itemType: "+itemType);
- }
-
- public static CatalogItemBuilder<CatalogEntityItemDto> newEntity(String symbolicName, String version) {
- return new CatalogItemBuilder<CatalogEntityItemDto>(new CatalogEntityItemDto())
- .symbolicName(symbolicName)
- .version(version);
- }
-
- public static CatalogItemBuilder<CatalogTemplateItemDto> newTemplate(String symbolicName, String version) {
- return new CatalogItemBuilder<CatalogTemplateItemDto>(new CatalogTemplateItemDto())
- .symbolicName(symbolicName)
- .version(version);
- }
-
- public static CatalogItemBuilder<CatalogPolicyItemDto> newPolicy(String symbolicName, String version) {
- return new CatalogItemBuilder<CatalogPolicyItemDto>(new CatalogPolicyItemDto())
- .symbolicName(symbolicName)
- .version(version);
- }
-
- public static CatalogItemBuilder<CatalogLocationItemDto> newLocation(String symbolicName, String version) {
- return new CatalogItemBuilder<CatalogLocationItemDto>(new CatalogLocationItemDto())
- .symbolicName(symbolicName)
- .version(version);
- }
-
- public CatalogItemBuilder(CIConcreteType dto) {
- this.dto = dto;
- this.dto.setLibraries(Collections.<CatalogBundle>emptyList());
- }
-
- public CatalogItemBuilder<CIConcreteType> symbolicName(String symbolicName) {
- dto.setSymbolicName(symbolicName);
- return this;
- }
-
- @Deprecated
- public CatalogItemBuilder<CIConcreteType> javaType(String javaType) {
- dto.setJavaType(javaType);
- return this;
- }
-
- /** @deprecated since 0.7.0 use {@link #displayName}*/
- @Deprecated
- public CatalogItemBuilder<CIConcreteType> name(String name) {
- return displayName(name);
- }
-
- public CatalogItemBuilder<CIConcreteType> displayName(String displayName) {
- dto.setDisplayName(displayName);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> description(String description) {
- dto.setDescription(description);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> iconUrl(String iconUrl) {
- dto.setIconUrl(iconUrl);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> version(String version) {
- dto.setVersion(version);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> deprecated(boolean deprecated) {
- dto.setDeprecated(deprecated);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> disabled(boolean disabled) {
- dto.setDisabled(disabled);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> libraries(Collection<CatalogBundle> libraries) {
- dto.setLibraries(libraries);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> plan(String yaml) {
- dto.setPlanYaml(yaml);
- return this;
- }
-
- public CatalogItemBuilder<CIConcreteType> tag(Object tag) {
- dto.tags().addTag(tag);
- return this;
- }
-
- public CIConcreteType build() {
- Preconditions.checkNotNull(dto.getSymbolicName());
- Preconditions.checkNotNull(dto.getVersion());
-
- if (dto.getLibraries() == null) {
- dto.setLibraries(Collections.<CatalogBundle>emptyList());
- }
-
- CIConcreteType ret = dto;
-
- //prevent mutations through the builder
- dto = null;
-
- return ret;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemComparator.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemComparator.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemComparator.java
deleted file mode 100644
index abd4d08..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemComparator.java
+++ /dev/null
@@ -1,52 +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.Collections;
-import java.util.Comparator;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.util.text.VersionComparator;
-
-/**
- * Largest version first order.
- *
- * When using the comparator to sort - first using symbolicName
- * and if equal puts larger versions first, snapshots at the back.
- */
-public class CatalogItemComparator<T,SpecT> implements Comparator<CatalogItem<T, SpecT>> {
-
- public static final CatalogItemComparator<?, ?> INSTANCE = new CatalogItemComparator<Object, Object>();
-
- @SuppressWarnings("unchecked")
- public static <T,SpecT> CatalogItemComparator<T,SpecT> getInstance() {
- return (CatalogItemComparator<T, SpecT>) INSTANCE;
- }
-
- @Override
- public int compare(CatalogItem<T, SpecT> o1, CatalogItem<T, SpecT> o2) {
- int symbolicNameComparison = o1.getSymbolicName().compareTo(o2.getSymbolicName());
- if (symbolicNameComparison != 0) {
- return symbolicNameComparison;
- } else {
- return Collections.reverseOrder(VersionComparator.INSTANCE).compare(o1.getVersion(), o2.getVersion());
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
deleted file mode 100644
index 1766ad7..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDo.java
+++ /dev/null
@@ -1,226 +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.Nonnull;
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
-import org.apache.brooklyn.core.relations.EmptyRelationSupport;
-
-import com.google.common.base.Preconditions;
-
-public class CatalogItemDo<T,SpecT> implements CatalogItem<T,SpecT>, BrooklynObjectInternal {
-
- protected final CatalogDo catalog;
- protected final CatalogItemDtoAbstract<T,SpecT> itemDto;
-
- protected volatile Class<T> javaClass;
-
- public CatalogItemDo(CatalogDo catalog, CatalogItem<T,SpecT> itemDto) {
- this.catalog = Preconditions.checkNotNull(catalog, "catalog");
- this.itemDto = (CatalogItemDtoAbstract<T, SpecT>) Preconditions.checkNotNull(itemDto, "itemDto");
- }
-
- public CatalogItem<T,SpecT> getDto() {
- return itemDto;
- }
-
- /**
- * @throws UnsupportedOperationException; Config not supported for catalog item. See {@link #getPlanYaml()}.
- */
- @Override
- public ConfigurationSupportInternal config() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @throws UnsupportedOperationException; subscriptions are not supported for catalog items
- */
- @Override
- public SubscriptionSupportInternal subscriptions() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Overrides the parent so that relations are not visible.
- * @return an immutable empty relation support object; relations are not supported,
- * but we do not throw on access to enable reads in a consistent manner
- */
- @Override
- public RelationSupportInternal<CatalogItem<T,SpecT>> relations() {
- return new EmptyRelationSupport<CatalogItem<T,SpecT>>(this);
- }
-
- @Override
- public <U> U getConfig(ConfigKey<U> key) {
- return config().get(key);
- }
-
- @Override
- public <U> U setConfig(ConfigKey<U> key, U val) {
- return config().set(key, val);
- }
-
- @Override
- public CatalogItemType getCatalogItemType() {
- return itemDto.getCatalogItemType();
- }
-
- @Override
- public Class<T> getCatalogItemJavaType() {
- return itemDto.getCatalogItemJavaType();
- }
-
- @Override
- public String getId() {
- return itemDto.getId();
- }
-
- @Override
- public String getCatalogItemId() {
- return itemDto.getCatalogItemId();
- }
-
- @Override
- public void setDeprecated(boolean deprecated) {
- itemDto.setDeprecated(deprecated);
- }
-
- @Override
- public boolean isDeprecated() {
- return itemDto.isDeprecated();
- }
-
- @Override
- public void setDisabled(boolean diabled) {
- itemDto.setDisabled(diabled);
- }
-
- @Override
- public boolean isDisabled() {
- return itemDto.isDisabled();
- }
-
- @Override
- public void setCatalogItemId(String id) {
- itemDto.setCatalogItemId(id);
- }
-
- @Override
- public String getJavaType() {
- return itemDto.getJavaType();
- }
-
- @Deprecated
- @Override
- public String getName() {
- return getDisplayName();
- }
-
- @Deprecated
- @Override
- public String getRegisteredTypeName() {
- return getSymbolicName();
- }
-
- @Override
- public String getDisplayName() {
- return itemDto.getDisplayName();
- }
-
- @Override
- public TagSupport tags() {
- return itemDto.tags();
- }
-
- @Override
- public String getDescription() {
- return itemDto.getDescription();
- }
-
- @Override
- public String getIconUrl() {
- return itemDto.getIconUrl();
- }
-
- @Override
- public String getSymbolicName() {
- return itemDto.getSymbolicName();
- }
-
- @Override
- public String getVersion() {
- return itemDto.getVersion();
- }
-
- @Nonnull // but it is still null sometimes, see in CatalogDo.loadJavaClass
- @Override
- public Collection<CatalogBundle> getLibraries() {
- return itemDto.getLibraries();
- }
-
- /** @deprecated since 0.7.0 this is the legacy mechanism; still needed for policies and apps, but being phased out.
- * new items should use {@link #getPlanYaml} and {@link #newClassLoadingContext} */
- @Deprecated
- public Class<T> getJavaClass() {
- if (javaClass==null) loadJavaClass(null);
- return javaClass;
- }
-
- @SuppressWarnings("unchecked")
- @Deprecated
- Class<? extends T> loadJavaClass(final ManagementContext mgmt) {
- if (javaClass!=null) return javaClass;
- javaClass = (Class<T>)CatalogUtils.newClassLoadingContext(mgmt, getId(), getLibraries(), catalog.getRootClassLoader()).loadClass(getJavaType());
- return javaClass;
- }
-
- @Override
- public String toString() {
- return getClass().getCanonicalName()+"["+itemDto+"]";
- }
-
- @Override
- public String toXmlString() {
- return itemDto.toXmlString();
- }
-
- @Override
- public Class<SpecT> getSpecType() {
- return itemDto.getSpecType();
- }
-
- @Nullable @Override
- public String getPlanYaml() {
- return itemDto.getPlanYaml();
- }
-
- @Override
- public RebindSupport<CatalogItemMemento> getRebindSupport() {
- return itemDto.getRebindSupport();
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
deleted file mode 100644
index df0d2e4..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogItemDtoAbstract.java
+++ /dev/null
@@ -1,439 +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 java.util.Map;
-import java.util.Set;
-
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.CatalogItemMemento;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.mgmt.rebind.BasicCatalogItemRebindSupport;
-import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
-import org.apache.brooklyn.core.relations.EmptyRelationSupport;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.core.flags.FlagUtils;
-import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-public abstract class CatalogItemDtoAbstract<T, SpecT> extends AbstractBrooklynObject implements CatalogItem<T, SpecT> {
-
- private static Logger LOG = LoggerFactory.getLogger(CatalogItemDtoAbstract.class);
-
- private @SetFromFlag String symbolicName;
- private @SetFromFlag String version = BasicBrooklynCatalog.NO_VERSION;
-
- private @SetFromFlag String displayName;
- private @SetFromFlag String description;
- private @SetFromFlag String iconUrl;
-
- private @SetFromFlag String javaType;
- /**@deprecated since 0.7.0, left for deserialization backwards compatibility (including xml based catalog format) */
- private @Deprecated @SetFromFlag String type;
- private @SetFromFlag String planYaml;
-
- private @SetFromFlag Collection<CatalogBundle> libraries;
- private @SetFromFlag Set<Object> tags = Sets.newLinkedHashSet();
- private @SetFromFlag boolean deprecated;
- private @SetFromFlag boolean disabled;
-
- /**
- * @throws UnsupportedOperationException; Config not supported for catalog item. See {@link #getPlanYaml()}.
- */
- @Override
- public ConfigurationSupportInternal config() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * @throws UnsupportedOperationException; subscriptions are not supported for catalog items
- */
- @Override
- public SubscriptionSupportInternal subscriptions() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public <U> U getConfig(ConfigKey<U> key) {
- return config().get(key);
- }
-
- @Override
- public <U> U setConfig(ConfigKey<U> key, U val) {
- return config().set(key, val);
- }
-
- @Override
- public String getId() {
- return getCatalogItemId();
- }
-
- @Override
- public String getCatalogItemId() {
- return CatalogUtils.getVersionedId(getSymbolicName(), getVersion());
- }
-
- @Override
- public String getJavaType() {
- if (javaType != null) return javaType;
- return type;
- }
-
- @Override
- @Deprecated
- public String getName() {
- return getDisplayName();
- }
-
- @Override
- @Deprecated
- public String getRegisteredTypeName() {
- return getSymbolicName();
- }
-
- @Override
- public String getDisplayName() {
- return displayName;
- }
-
- @Override
- public String getDescription() {
- return description;
- }
-
- @Override
- public String getIconUrl() {
- return iconUrl;
- }
-
- @Override
- public String getSymbolicName() {
- if (symbolicName != null) return symbolicName;
- return getJavaType();
- }
-
- @Override
- public String getVersion() {
- // The property is set to NO_VERSION when the object is initialized so it's not supposed to be null ever.
- // But xstream doesn't call constructors when reading from the catalog.xml file which results in null value
- // for the version property. That's why we have to fix it in the getter.
- if (version != null) {
- return version;
- } else {
- return BasicBrooklynCatalog.NO_VERSION;
- }
- }
-
- @Override
- public boolean isDeprecated() {
- return deprecated;
- }
-
- @Override
- public void setDeprecated(boolean deprecated) {
- this.deprecated = deprecated;
- }
-
- @Override
- public boolean isDisabled() {
- return disabled;
- }
-
- @Override
- public void setDisabled(boolean disabled) {
- this.disabled = disabled;
- }
-
- @Nonnull
- @Override
- public Collection<CatalogBundle> getLibraries() {
- if (libraries != null) {
- return ImmutableList.copyOf(libraries);
- } else {
- return Collections.emptyList();
- }
- }
-
- @Nullable @Override
- public String getPlanYaml() {
- return planYaml;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(symbolicName, planYaml, javaType, nullIfEmpty(libraries), version, getCatalogItemId());
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
- CatalogItemDtoAbstract<?,?> other = (CatalogItemDtoAbstract<?,?>) obj;
- if (!Objects.equal(symbolicName, other.symbolicName)) return false;
- if (!Objects.equal(planYaml, other.planYaml)) return false;
- if (!Objects.equal(javaType, other.javaType)) return false;
- if (!Objects.equal(nullIfEmpty(libraries), nullIfEmpty(other.libraries))) return false;
- if (!Objects.equal(getCatalogItemId(), other.getCatalogItemId())) return false;
- if (!Objects.equal(version, other.version)) return false;
- if (!Objects.equal(deprecated, other.deprecated)) return false;
- if (!Objects.equal(description, other.description)) return false;
- if (!Objects.equal(displayName, other.displayName)) return false;
- if (!Objects.equal(iconUrl, other.iconUrl)) return false;
- if (!Objects.equal(tags, other.tags)) return false;
- // 'type' not checked, because deprecated,
- // and in future we might want to allow it to be removed/blanked in some impls without affecting equality
- // (in most cases it is the same as symbolicName so doesn't matter)
- return true;
- }
-
- private static <T> Collection<T> nullIfEmpty(Collection<T> coll) {
- if (coll==null || coll.isEmpty()) return null;
- return coll;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName()+"["+getId()+"/"+getDisplayName()+"]";
- }
-
- @Override
- public abstract Class<SpecT> getSpecType();
-
- transient CatalogXmlSerializer serializer;
-
- @Override
- public String toXmlString() {
- if (serializer==null) loadSerializer();
- return serializer.toString(this);
- }
-
- private synchronized void loadSerializer() {
- if (serializer == null) {
- serializer = new CatalogXmlSerializer();
- }
- }
-
- @Override
- public RebindSupport<CatalogItemMemento> getRebindSupport() {
- return new BasicCatalogItemRebindSupport(this);
- }
-
- /**
- * Overrides the parent so that relations are not visible.
- * @return an immutable empty relation support object; relations are not supported,
- * but we do not throw on access to enable reads in a consistent manner
- */
- @Override
- public RelationSupportInternal<CatalogItem<T,SpecT>> relations() {
- return new EmptyRelationSupport<CatalogItem<T,SpecT>>(this);
- }
-
- @Override
- public void setDisplayName(String newName) {
- this.displayName = newName;
- }
-
- @Override
- protected CatalogItemDtoAbstract<T, SpecT> configure(Map<?, ?> flags) {
- FlagUtils.setFieldsFromFlags(flags, this);
- return this;
- }
-
- @Override
- public TagSupport tags() {
- return new BasicTagSupport();
- }
-
- /*
- * Using a custom tag support class rather than the one in AbstractBrooklynObject because
- * when XStream unmarshals a catalog item with no tags (e.g. from any catalog.xml file)
- * super.tags will be null, and any call to getTags throws a NullPointerException on the
- * synchronized (tags) statement. It can't just be initialised here because super.tags is
- * final.
- */
- private class BasicTagSupport implements TagSupport {
-
- private void setTagsIfNull() {
- // Possible if the class was unmarshalled by Xstream with no tags
- synchronized (CatalogItemDtoAbstract.this) {
- if (tags == null) {
- tags = Sets.newLinkedHashSet();
- }
- }
- }
-
- @Nonnull
- @Override
- public Set<Object> getTags() {
- synchronized (CatalogItemDtoAbstract.this) {
- setTagsIfNull();
- return ImmutableSet.copyOf(tags);
- }
- }
-
- @Override
- public boolean containsTag(Object tag) {
- synchronized (CatalogItemDtoAbstract.this) {
- setTagsIfNull();
- return tags.contains(tag);
- }
- }
-
- @Override
- public boolean addTag(Object tag) {
- boolean result;
- synchronized (CatalogItemDtoAbstract.this) {
- setTagsIfNull();
- result = tags.add(tag);
- }
- onTagsChanged();
- return result;
- }
-
- @Override
- public boolean addTags(Iterable<?> newTags) {
- boolean result;
- synchronized (CatalogItemDtoAbstract.this) {
- setTagsIfNull();
- result = Iterables.addAll(tags, newTags);
- }
- onTagsChanged();
- return result;
- }
-
- @Override
- public boolean removeTag(Object tag) {
- boolean result;
- synchronized (CatalogItemDtoAbstract.this) {
- setTagsIfNull();
- result = tags.remove(tag);
- }
- onTagsChanged();
- return result;
- }
- }
-
- @Override
- @Deprecated
- public void setCatalogItemId(String id) {
- //no op, should be used by rebind code only
- }
-
- protected void setSymbolicName(String symbolicName) {
- this.symbolicName = symbolicName;
- }
-
- protected void setVersion(String version) {
- this.version = version;
- }
-
- protected void setDescription(String description) {
- this.description = description;
- }
-
- protected void setIconUrl(String iconUrl) {
- this.iconUrl = iconUrl;
- }
-
- protected void setJavaType(String javaType) {
- this.javaType = javaType;
- this.type = null;
- }
-
- protected void setPlanYaml(String planYaml) {
- this.planYaml = planYaml;
- }
-
- protected void setLibraries(Collection<CatalogBundle> libraries) {
- this.libraries = libraries;
- }
-
- protected void setTags(Set<Object> tags) {
- this.tags = tags;
- }
-
- protected void setSerializer(CatalogXmlSerializer serializer) {
- this.serializer = serializer;
- }
-
- /**
- * Parses an instance of CatalogLibrariesDto from the given List. Expects the list entries
- * to be either Strings or Maps of String -> String. Will skip items that are not.
- */
- public static Collection<CatalogBundle> parseLibraries(Collection<?> possibleLibraries) {
- Collection<CatalogBundle> dto = MutableList.of();
- for (Object object : possibleLibraries) {
- if (object instanceof Map) {
- Map<?, ?> entry = (Map<?, ?>) object;
- String name = stringValOrNull(entry, "name");
- String version = stringValOrNull(entry, "version");
- String url = stringValOrNull(entry, "url");
- dto.add(new CatalogBundleDto(name, version, url));
- } else if (object instanceof String) {
- String inlineRef = (String) object;
-
- final String name;
- final String version;
- final String url;
-
- //Infer reference type (heuristically)
- if (inlineRef.contains("/") || inlineRef.contains("\\")) {
- //looks like an url/file path
- name = null;
- version = null;
- url = inlineRef;
- } else if (CatalogUtils.looksLikeVersionedId(inlineRef)) {
- //looks like a name+version ref
- name = CatalogUtils.getSymbolicNameFromVersionedId(inlineRef);
- version = CatalogUtils.getVersionFromVersionedId(inlineRef);
- url = null;
- } else {
- //assume it to be relative url
- name = null;
- version = null;
- url = inlineRef;
- }
-
- dto.add(new CatalogBundleDto(name, version, url));
- } else {
- LOG.debug("Unexpected entry in libraries list neither string nor map: " + object);
- }
- }
- return dto;
- }
-
- private static String stringValOrNull(Map<?, ?> map, String key) {
- Object val = map.get(key);
- return val != null ? String.valueOf(val) : null;
- }
-}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.java
deleted file mode 100644
index 99041d2..0000000
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogLibrariesDo.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 java.util.Collection;
-
-import org.apache.brooklyn.api.catalog.CatalogItem;
-
-import com.google.common.base.Preconditions;
-
-@Deprecated
-public class CatalogLibrariesDo implements CatalogItem.CatalogItemLibraries {
-
- private final CatalogLibrariesDto librariesDto;
-
-
- public CatalogLibrariesDo(CatalogLibrariesDto librariesDto) {
- this.librariesDto = Preconditions.checkNotNull(librariesDto, "librariesDto");
- }
-
- @Override
- public Collection<String> getBundles() {
- return librariesDto.getBundles();
- }
-
-}