Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
97b50e4
add routine to create new temp bundle
ahgittin Jun 26, 2017
d7975d1
implicitly wrap yaml in bundles when uploading to catalog
ahgittin Jun 23, 2017
2165778
fix bundles set on scanning, and aborted work to scan osgi bundles
ahgittin Jun 27, 2017
e7dc875
Add checksum to managed bundle so we can tell if it changes and fail …
ahgittin Jun 27, 2017
f16bda9
support force when wrapping a BOM
ahgittin Jun 27, 2017
8385f13
repair tests where semantics changed, new tests
ahgittin Jun 28, 2017
e32d74d
comments on BOM scanning
ahgittin Jun 28, 2017
dc43f03
add library bundles directly, without munging yaml, and only if not w…
ahgittin Jun 28, 2017
480a0c7
Delete wrapper bundles who have no types installed.
ahgittin Jun 28, 2017
21e93d2
restore test bundle counts, and resolve library URLs on install
ahgittin Jun 28, 2017
12ea23b
Merge branch 'version-new-rules' into osgi-auto-wrap-yaml
ahgittin Jun 28, 2017
41b9894
Merge branch 'catalog-internal-references' into osgi-auto-wrap-yaml
ahgittin Jun 28, 2017
4318237
Merge branch 'catalog-internal-references' into 2
ahgittin Jun 29, 2017
9885cff
catalog.bom parsing can result in RegisteredType instances instead of…
ahgittin Jun 29, 2017
d2e6a53
big work in catalog to add unresolved items to type registry
ahgittin Jun 29, 2017
bf31100
roughly working to validate types in a separate pass, fixing the big …
ahgittin Jun 30, 2017
02cfe50
misc fixes related to type-reg / osgi, making the tests work
ahgittin Jun 30, 2017
580c00d
remove osgi deprecation, disable, and transform tests
ahgittin Jun 30, 2017
915e3bf
Merge branch 'master' into osgi-auto-wrap-yaml
ahgittin Jun 30, 2017
ce85007
Merge branch 'master' into osgi-auto-wrap-yaml
ahgittin Jun 30, 2017
520fb6a
tidy tests, add more OSGi-variants of existing tests, weaken same-blu…
ahgittin Jul 3, 2017
b016e67
fix more tests, pointing at type registry instead of catalog
ahgittin Jul 3, 2017
c5af549
make LocationRegistry be a facade to TypeRegistry for most things
ahgittin Jul 3, 2017
7a42cf8
support templates for RegisteredType instances, using tags
ahgittin Jul 3, 2017
694ac1d
use more forgiving checksum routine, ignoring dates and order in zip …
ahgittin Jul 4, 2017
d7ebb6b
switch REST API to use TypeRegistry methods (but not yet changing API)
ahgittin Jul 4, 2017
f344430
better error messages and warnings around catalog item failures
ahgittin Jun 7, 2017
bf7d292
address two edge cases where osgi bundles out of sync with brooklyn-m…
ahgittin Jul 7, 2017
ab75195
suppress some warnings
ahgittin Jul 7, 2017
d0183c2
address PR comments
ahgittin Jul 12, 2017
5868124
remove CatalogBomScanner
ahgittin Jul 12, 2017
a9e770f
remove more of the legacy bom-scanning support
ahgittin Jul 17, 2017
d6fd2ae
remove BomScanner reference in blueprint.xml
ahgittin Jul 17, 2017
c39eb71
address misc PR comments
ahgittin Jul 17, 2017
98d9b0a
tests for deletion of empty wrapper bundles
ahgittin Jul 18, 2017
c2d9bff
tidy warnings
ahgittin Jul 18, 2017
c7034e6
fix broken tests by reverting the increased flexibility to the java c…
ahgittin Jul 18, 2017
97f2524
address review comments
ahgittin Jul 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
package org.apache.brooklyn.api.catalog;

import java.util.Collection;
import java.util.Map;
import java.util.NoSuchElementException;

import javax.annotation.Nullable;

import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.api.typereg.RegisteredType;

import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;

Expand Down Expand Up @@ -57,6 +60,7 @@ public interface BrooklynCatalog {
<T,SpecT> Iterable<CatalogItem<T,SpecT>> getCatalogItems();

/** convenience for filtering items in the catalog; see CatalogPredicates for useful filters */
// XXX
<T,SpecT> Iterable<CatalogItem<T,SpecT>> getCatalogItems(Predicate<? super CatalogItem<T,SpecT>> filter);

/** persists the catalog item to the object store, if persistence is enabled */
Expand Down Expand Up @@ -92,6 +96,33 @@ public interface BrooklynCatalog {
*/
AbstractBrooklynObjectSpec<?, ?> peekSpec(CatalogItem<?, ?> item);

/** Adds the given registered types defined in a bundle's catalog BOM;
* no validation performed, so caller should do that subsequently after
* loading all potential inter-dependent types.
* <p>
* Nothing is returned but caller can retrieve the results by searching the
* type registry for types with the same containing bundle.
*/
@Beta // method may move elsewhere
public void addTypesFromBundleBom(String yaml, ManagedBundle bundle, boolean forceUpdate);

/** As {@link #validateType(RegisteredType)} but taking a set of types, returning a map whose keys are
* those types where validation failed, mapped to the collection of errors validating that type.
* An empty map result indicates no validation errors in the types passed in.
*/
@Beta // method may move elsewhere
public Map<RegisteredType,Collection<Throwable>> validateTypes(Iterable<RegisteredType> typesToValidate);

/** Performs YAML validation on the given type, returning a collection of errors.
* An empty result indicates no validation errors in the type passed in.
* <p>
* Validation may be side-effecting in that it sets metadata and refines supertypes
* for the given registered type.
*/
@Beta // method may move elsewhere
Collection<Throwable> validateType(RegisteredType typeToValidate);


/**
* Adds an item (represented in yaml) to the catalog.
* Fails if the same version exists in catalog.
Expand Down Expand Up @@ -137,6 +168,9 @@ public interface BrooklynCatalog {
*/
Iterable<? extends CatalogItem<?,?>> addItems(String yaml, boolean forceUpdate);

/** As {@link #addItems(String, ManagedBundle)} but exposing forcing option as per {@link #addItem(String, boolean)}. */
Iterable<? extends CatalogItem<?,?>> addItems(String yaml, ManagedBundle bundle, boolean forceUpdate);

/**
* adds an item to the 'manual' catalog;
* this does not update the classpath or have a record to the java Class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.mgmt.LocationManager;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
import org.apache.brooklyn.util.guava.Maybe;

/**
Expand All @@ -37,19 +38,32 @@
public interface LocationRegistry {

/** map of ID (possibly randomly generated) to the definition (spec, name, id, and props;
* where spec is the spec as defined, for instance possibly another named:xxx location) */
* where spec is the spec as defined, for instance possibly another named:xxx location).
* optionally will also return all things from other sources where this can look up. */
public Map<String,LocationDefinition> getDefinedLocations(boolean includeThingsWeAreFacadeFor);

/** @deprecated since 0.12.0 use {@link #getDefinedLocations(boolean)} passing <code>true</code>.
* some clients might only want the things actually defined here, which is cheaper. */
@Deprecated
public Map<String,LocationDefinition> getDefinedLocations();

/** returns a LocationDefinition given its ID (usually a random string), or null if none */
public LocationDefinition getDefinedLocationById(String id);

/** returns a LocationDefinition given its name (e.g. for named locations, supply the bit after the "named:" prefix),
* or null if none */
* looking inthe {@link BrooklynTypeRegistry} for registered items, then in this list, or null if none */
public LocationDefinition getDefinedLocationByName(String name);

/** adds or updates the given defined location */
/** as {@link #updateDefinedLocationNonPersisted(LocationDefinition)}
* @deprecated since 0.12.0 use {@link #updateDefinedLocationNonPersisted(LocationDefinition)};
* it's exactly the same, just the name makes it clear */
@Deprecated
public void updateDefinedLocation(LocationDefinition l);

/** adds or updates the given defined location in this registry; note it is not persisted;
* callers should consider adding to the {@link BrooklynTypeRegistry} instead */
public void updateDefinedLocationNonPersisted(LocationDefinition l);

/** removes the defined location from the registry (applications running there are unaffected) */
public void removeDefinedLocation(String id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.brooklyn.api.sensor.Enricher;
import org.apache.brooklyn.api.sensor.Feed;
import org.apache.brooklyn.api.typereg.ManagedBundle;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.util.time.Duration;

import com.google.common.annotations.Beta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public interface CatalogItemMemento extends Memento {

String getSymbolicName();

String getContainingBundle();

String getIconUrl();

String getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.brooklyn.api.objs;

import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
Expand Down Expand Up @@ -72,10 +73,37 @@ public Class<? extends BrooklynObject> getInterfaceType() {
}

public static BrooklynObjectType of(BrooklynObject instance) {
for (BrooklynObjectType t: values()) {
if (t.getInterfaceType()!=null && t.getInterfaceType().isInstance(instance))
return t;
if (instance!=null) {
for (BrooklynObjectType t: values()) {
if (t.getInterfaceType()!=null && t.getInterfaceType().isInstance(instance))
return t;
}
}
return UNKNOWN;
}

public static BrooklynObjectType of(Class<?> objectTypeOrSpecType) {
if (objectTypeOrSpecType!=null) {
for (BrooklynObjectType t: values()) {
if (t.getInterfaceType()!=null && t.getInterfaceType().isAssignableFrom(objectTypeOrSpecType))
return t;
if (t.getSpecType()!=null && t.getSpecType().isAssignableFrom(objectTypeOrSpecType))
return t;
}
}
return UNKNOWN;
}

public static BrooklynObjectType of(CatalogItemType t) {
if (t==null) return null;
switch (t) {
case ENRICHER: return BrooklynObjectType.ENRICHER;
case ENTITY: return BrooklynObjectType.ENTITY;
case LOCATION: return BrooklynObjectType.LOCATION;
case POLICY: return BrooklynObjectType.POLICY;
case TEMPLATE: return BrooklynObjectType.ENTITY;
default: return BrooklynObjectType.UNKNOWN;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ public enum RegisteredTypeKind {
* for the type registered (e.g. the {@link Entity} instance) */
SPEC,
/** a registered type which will create the java type described */
BEAN
BEAN,
/** a partially registered type which requires subsequent validation and changing the kind;
* until then, an item of this kind cannot be instantiated.
* items registered as templates (using a tag) may remain in this state
* if they do not resolve. */
UNRESOLVED
// note: additional kinds should have the visitor in core/RegisteredTypeKindVisitor updated
// to flush out all places which want to implement support for all kinds
}
Expand All @@ -47,7 +52,7 @@ public enum RegisteredTypeKind {
/** @return The item matching the given given
* {@link RegisteredType#getSymbolicName() symbolicName}
* and optionally {@link RegisteredType#getVersion()},
* taking the best version if the version is null or a default marker,
* taking the best version if the version is null, blank, or a default marker,
* returning null if no matches are found. */
RegisteredType get(String symbolicName, String version);
/** as {@link #get(String, String)} but the given string here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ public interface ManagedBundle extends BrooklynObject, Rebindable, OsgiBundleWit

/** A URL-like thing that we can register with the OSGi framework
* to uniquely identify this bundle-instance.
* This typically includes the unique {@link #getId()} of this item. */
* This typically includes the unique {@link #getId()} of this item.
* This will not normally be a URL that can be loaded. */
String getOsgiUniqueUrl();

VersionedName getVersionedName();

/** MD5 checksum of the contents of bundle as installed to OSGi */
String getChecksum();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd call this getMd5Checksum, if that's what it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it uses md5 but it has some opinions about what it uses for checksum so better to consider it its own checksum


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.apache.brooklyn.api.typereg;

import org.apache.brooklyn.util.osgi.VersionedName;

import com.google.common.annotations.Beta;

@Beta
Expand All @@ -36,5 +38,8 @@ public interface OsgiBundleWithUrl {
/** @return true if we have a name and version for this bundle;
* false if not, e.g. if we only know the URL and we haven't loaded it yet */
public boolean isNameResolved();

/** @return the {@link VersionedName} for this bundle, or null if not available */
public VersionedName getVersionedName();

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.brooklyn.api.objs.BrooklynObject;
import org.apache.brooklyn.api.objs.Identifiable;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
import org.apache.brooklyn.util.osgi.VersionedName;

import com.google.common.annotations.Beta;

Expand All @@ -37,6 +38,9 @@ public interface RegisteredType extends Identifiable {

String getSymbolicName();
String getVersion();

VersionedName getVersionedName();

/** Bundle in symbolicname:id format where this type is defined */
// TODO would prefer this to be VersionedName if/when everything comes from OSGi bundles
// unrevert 7260bf9cf3f3ebaaa790693e1b7217a81bef78a7 to start that, and adjust serialization
Expand Down Expand Up @@ -111,6 +115,11 @@ public interface TypeImplementationPlan {
String getPlanFormat();
/** data for the implementation; may be more specific */
Object getPlanData();

@Override boolean equals(Object obj);
@Override int hashCode();
}

@Override boolean equals(Object obj);
@Override int hashCode();
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ public boolean canResolve() {

public <T extends Entity> EntitySpec<T> resolveSpec(Set<String> encounteredRegisteredTypeSymbolicNames) {
if (alreadyBuilt.getAndSet(true))
throw new IllegalStateException("Spec can only be used once: "+this);
throw new IllegalStateException("Spec resolver can only be used once: "+this);

EntitySpec<?> spec = serviceSpecResolver.resolve(type, loader, encounteredRegisteredTypeSymbolicNames);

if (spec == null) {
// Try to provide some troubleshooting details
final String msgDetails;
RegisteredType item = mgmt.getTypeRegistry().get(Strings.removeFromStart(type, "catalog:"));
RegisteredType item = mgmt.getTypeRegistry().get(Strings.removeAllFromStart(type, "catalog:", "brooklyn:"));
String proto = Urls.getProtocol(type);
if (item != null && encounteredRegisteredTypeSymbolicNames.contains(item.getSymbolicName())) {
msgDetails = "Cycle between catalog items detected, starting from " + type +
". Other catalog items being resolved up the stack are " + encounteredRegisteredTypeSymbolicNames +
". Other catalog items being resolved recursively up the stack are " + encounteredRegisteredTypeSymbolicNames +
". Tried loading it as a Java class instead but failed.";
} else if (proto != null) {
if (BrooklynCampConstants.YAML_URL_PROTOCOL_WHITELIST.contains(proto)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.mgmt.EntityManagementUtils;
import org.apache.brooklyn.core.typereg.RegisteredTypes;
import org.apache.brooklyn.core.typereg.UnsupportedTypePlanException;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.text.Strings;

Expand Down Expand Up @@ -155,6 +156,9 @@ private static EntitySpec<?> createEntitySpecFromServicesBlock(String plan, Broo
return appSpec;

} else {
if (at.getPlatformComponentTemplates()==null || at.getPlatformComponentTemplates().isEmpty()) {
throw new UnsupportedTypePlanException("No 'services' declared");
}
throw new IllegalStateException("Unable to instantiate YAML; invalid type or parameters in plan:\n"+plan);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.api.typereg.RegisteredType.TypeImplementationPlan;
import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind;
import org.apache.brooklyn.core.typereg.AbstractFormatSpecificTypeImplementationPlan;
import org.apache.brooklyn.core.typereg.AbstractTypePlanTransformer;
import org.apache.brooklyn.core.typereg.BasicTypeImplementationPlan;
Expand All @@ -47,6 +48,8 @@ public CampTypePlanTransformer() {

@Override
protected double scoreForNullFormat(Object planData, RegisteredType type, RegisteredTypeLoadingContext context) {
if (type!=null && type.getKind()!=RegisteredTypeKind.SPEC) return 0;

Maybe<Map<?,?>> plan = RegisteredTypes.getAsYamlMap(planData);
if (plan.isAbsent()) return 0;
if (plan.get().containsKey("services")) return 0.8;
Expand All @@ -60,6 +63,8 @@ protected double scoreForNullFormat(Object planData, RegisteredType type, Regist

@Override
protected double scoreForNonmatchingNonnullFormat(String planFormat, Object planData, RegisteredType type, RegisteredTypeLoadingContext context) {
if (type!=null && type.getKind()!=RegisteredTypeKind.SPEC) return 0;

if (FORMATS.contains(planFormat.toLowerCase())) return 0.9;
return 0;
}
Expand All @@ -73,7 +78,7 @@ protected double scoreForNonmatchingNonnullFormat(String planFormat, Object plan
@Override
protected Object createBean(RegisteredType type, RegisteredTypeLoadingContext context) throws Exception {
// beans not supported by this?
return null;
throw new IllegalStateException("beans not supported here");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ protected LocalManagementContext newMgmtContext() {
};
launcher.launch();
platform = launcher.getCampPlatform();

forceUpdate = false;
}

@Override
Expand Down
Loading