Skip to content

Commit

Permalink
Merge branch 'master' into yoml
Browse files Browse the repository at this point in the history
Conflicts: utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java = both added tests
  • Loading branch information
ahgittin committed Jun 5, 2017
2 parents cbe03dc + 97eaf5a commit 6869f7c
Show file tree
Hide file tree
Showing 240 changed files with 6,304 additions and 6,077 deletions.
2 changes: 1 addition & 1 deletion .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-Xmx1024m -Xms512m -XX:MaxPermSize=256m
-Xmx1024m -Xms512m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.apache.brooklyn.api.objs.BrooklynObject;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.Enricher;
import org.apache.brooklyn.api.sensor.EnricherSpec;
import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;

import com.google.common.annotations.Beta;
Expand All @@ -46,18 +48,21 @@ public static enum CatalogItemType {
TEMPLATE,
ENTITY,
POLICY,
ENRICHER,
LOCATION;

public static CatalogItemType ofSpecClass(Class<? extends AbstractBrooklynObjectSpec<?, ?>> type) {
if (type==null) return null;
if (PolicySpec.class.isAssignableFrom(type)) return POLICY;
if (EnricherSpec.class.isAssignableFrom(type)) return ENRICHER;
if (LocationSpec.class.isAssignableFrom(type)) return LOCATION;
if (EntitySpec.class.isAssignableFrom(type)) return ENTITY;
return null;
}
public static CatalogItemType ofTargetClass(Class<? extends BrooklynObject> type) {
if (type==null) return null;
if (Policy.class.isAssignableFrom(type)) return POLICY;
if (Enricher.class.isAssignableFrom(type)) return ENRICHER;
if (Location.class.isAssignableFrom(type)) return LOCATION;
if (Application.class.isAssignableFrom(type)) return TEMPLATE;
if (Entity.class.isAssignableFrom(type)) return ENTITY;
Expand Down Expand Up @@ -128,8 +133,6 @@ public static interface CatalogItemLibraries {

public Collection<CatalogBundle> getLibraries();

public String toXmlString();

/** @return The underlying YAML for this item, if known;
* currently including `services:` or `brooklyn.policies:` prefix (but this will likely be removed) */
@Nullable public String getPlanYaml();
Expand Down
12 changes: 0 additions & 12 deletions api/src/main/java/org/apache/brooklyn/api/entity/EntityType.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.brooklyn.api.entity;

import java.util.NoSuchElementException;
import java.util.Set;

import org.apache.brooklyn.api.effector.Effector;
Expand Down Expand Up @@ -50,17 +49,6 @@ public interface EntityType extends BrooklynType {
*/
public Maybe<Effector<?>> getEffectorByName(String name);

/**
* @return the matching effector on this entity
* @throws NoSuchElementException If there is no exact match for this signature
* <p>
* @deprecated since 0.7.0 use {@link #getEffectorByName(String)};
* use of multiple effectors with the same name is not supported by the EntityDynamicType implementation,
* so should be discouraged. overloading can be achieved by inspecting the parameters map.
*/
@Deprecated
Effector<?> getEffector(String name, Class<?>... parameterTypes);

/**
* The Sensor with the given name, or null if not found.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static <T extends Location> LocationSpec<T> create(LocationSpec<T> spec)
return create(exactType).copyFrom(spec);
}

private String id;
private Location parent;
private final Map<Class<?>, Object> extensions = Maps.newLinkedHashMap();

Expand All @@ -90,7 +89,6 @@ protected LocationSpec(Class<T> type) {
protected LocationSpec<T> copyFrom(LocationSpec<T> otherSpec) {
LocationSpec<T> result = super.copyFrom(otherSpec).extensions(otherSpec.getExtensions());
if (otherSpec.getParent() != null) result.parent(otherSpec.getParent());
if (otherSpec.getId() != null) result.id(otherSpec.getId());
return result;
}

Expand All @@ -100,15 +98,6 @@ protected void checkValidType(Class<? extends T> type) {
checkIsNewStyleImplementation(type);
}

/**
* @deprecated since 0.7.0; instead let the management context pick a random+unique id
*/
@Deprecated
public LocationSpec<T> id(String val) {
id = val;
return this;
}

public LocationSpec<T> parent(Location val) {
parent = checkNotNull(val, "parent");
return this;
Expand All @@ -127,16 +116,6 @@ public <E> LocationSpec<T> extensions(Map<Class<?>, ?> extensions) {
return this;
}

/**
* @return The id of the location to be created, or null if brooklyn can auto-generate an id
*
* @deprecated since 0.7.0; instead let the management context pick a random+unique id
*/
@Deprecated
public String getId() {
return id;
}

/**
* @return The location's parent
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static <T extends Enricher> EnricherSpec<T> create(Class<? extends T> typ
* @param config The spec's configuration (see {@link EnricherSpec#configure(Map)}).
* @param type An {@link Enricher} class
*/
public static <T extends Enricher> EnricherSpec<T> create(Map<?,?> config, Class<? extends T> type) {
public static <T extends Enricher> EnricherSpec<T> create(Map<?,?> config, Class<T> type) {
return EnricherSpec.create(type).configure(config);
}

Expand Down
5 changes: 3 additions & 2 deletions camp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The projects in this directory are designed so they could be used to build
other CAMP servers not based on Brooklyn, if desired.

These projects are part of the Apache Software Foundation Brooklyn project
(https://brooklyn.incubator.apache.org) and released under the Apache License 2.0.
(https://brooklyn.apache.org) and released under the Apache License 2.0.

----
Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -31,4 +31,5 @@ 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.
under the License.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class PlanInterpretationContext {

public PlanInterpretationContext(Map<String,?> originalDeploymentPlan, List<PlanInterpreter> interpreters) {
super();
this.originalDeploymentPlan = MutableMap.copyOf(originalDeploymentPlan).asUnmodifiable();
this.originalDeploymentPlan = MutableMap.<String, Object>copyOf(originalDeploymentPlan).asUnmodifiable();
this.interpreters = ImmutableList.copyOf(interpreters);
this.allInterpreter = new PlanInterpreter() {
@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.apache.brooklyn.api.objs.SpecParameter;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.policy.PolicySpec;
import org.apache.brooklyn.api.sensor.Enricher;
import org.apache.brooklyn.api.sensor.EnricherSpec;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
import org.apache.brooklyn.camp.CampPlatform;
Expand Down Expand Up @@ -144,6 +146,38 @@ static PolicySpec<?> createPolicySpec(BrooklynClassLoadingContext loader, Object
return spec;
}

static EnricherSpec<?> createEnricherSpec(String yamlPlan, BrooklynClassLoadingContext loader, Set<String> encounteredCatalogTypes) {
DeploymentPlan plan = makePlanFromYaml(loader.getManagementContext(), yamlPlan);

//Would ideally re-use the EnricherSpecResolver
//but it is CAMP specific and there is no easy way to get hold of it.
Object enrichers = checkNotNull(plan.getCustomAttributes().get(BasicBrooklynCatalog.ENRICHERS_KEY), "enricher config");
if (!(enrichers instanceof Iterable<?>)) {
throw new IllegalStateException("The value of " + BasicBrooklynCatalog.ENRICHERS_KEY + " must be an Iterable.");
}

Object policy = Iterables.getOnlyElement((Iterable<?>)enrichers);

return createEnricherSpec(loader, policy, encounteredCatalogTypes);
}

@SuppressWarnings("unchecked")
static EnricherSpec<?> createEnricherSpec(BrooklynClassLoadingContext loader, Object enricher, Set<String> encounteredCatalogTypes) {
Map<String, Object> itemMap;
if (enricher instanceof String) {
itemMap = ImmutableMap.<String, Object>of("type", enricher);
} else if (enricher instanceof Map) {
itemMap = (Map<String, Object>) enricher;
} else {
throw new IllegalStateException("Enricher expected to be string or map. Unsupported object type " + enricher.getClass().getName() + " (" + enricher.toString() + ")");
}

String versionedId = (String) checkNotNull(Yamls.getMultinameAttribute(itemMap, "enricher_type", "enricherType", "type"), "enricher type");
EnricherSpec<? extends Enricher> spec = resolveEnricherSpec(versionedId, loader, encounteredCatalogTypes);
initConfigAndParameters(spec, itemMap, loader);
return spec;
}

static LocationSpec<?> createLocationSpec(String yamlPlan, BrooklynClassLoadingContext loader, Set<String> encounteredTypes) {
DeploymentPlan plan = makePlanFromYaml(loader.getManagementContext(), yamlPlan);
Object locations = checkNotNull(plan.getCustomAttributes().get(BasicBrooklynCatalog.LOCATIONS_KEY), "location config");
Expand Down Expand Up @@ -217,6 +251,24 @@ private static PolicySpec<? extends Policy> resolvePolicySpec(
return spec;
}

@SuppressWarnings("unchecked")
private static EnricherSpec<? extends Enricher> resolveEnricherSpec(
String versionedId,
BrooklynClassLoadingContext loader,
Set<String> encounteredCatalogTypes) {

EnricherSpec<? extends Enricher> spec;
RegisteredType item = loader.getManagementContext().getTypeRegistry().get(versionedId);
if (item != null && !encounteredCatalogTypes.contains(item.getSymbolicName())) {
RegisteredTypeLoadingContext context = RegisteredTypeLoadingContexts.alreadyEncountered(encounteredCatalogTypes);
return loader.getManagementContext().getTypeRegistry().createSpec(item, context, EnricherSpec.class);
} else {
// TODO-type-registry pass the loader in to the above, and allow it to load with the loader
spec = EnricherSpec.create(loader.loadClass(versionedId, Enricher.class));
}
return spec;
}

private static LocationSpec<?> resolveLocationSpec(
String type,
Map<String, Object> brooklynConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.brooklyn.api.mgmt.ManagementContext;
import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.sensor.Enricher;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.api.typereg.RegisteredTypeLoadingContext;
import org.apache.brooklyn.camp.CampPlatform;
Expand Down Expand Up @@ -102,6 +103,8 @@ public CampResolver(ManagementContext mgmt, RegisteredType type, RegisteredTypeL
supers.addIfNotNull(expectedType);
if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Policy.class)) {
spec = CampInternalUtils.createPolicySpec(planYaml, loader, encounteredTypes);
} else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Enricher.class)) {
spec = CampInternalUtils.createEnricherSpec(planYaml, loader, encounteredTypes);
} else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Location.class)) {
spec = CampInternalUtils.createLocationSpec(planYaml, loader, encounteredTypes);
} else if (RegisteredTypes.isAnyTypeSubtypeOf(supers, Application.class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected double scoreForNullFormat(Object planData, RegisteredType type, Regist
// TODO these should become legacy
if (plan.get().containsKey("brooklyn.locations")) return 0.7;
if (plan.get().containsKey("brooklyn.policies")) return 0.7;
if (plan.get().containsKey("brooklyn.enrichers")) return 0.7;
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.brooklyn.core.mgmt.internal.EntityManagerInternal;
import org.apache.brooklyn.core.sensor.DependentConfiguration;
import org.apache.brooklyn.core.sensor.Sensors;
import org.apache.brooklyn.util.JavaGroovyEquivalents;
import org.apache.brooklyn.util.core.flags.TypeCoercions;
import org.apache.brooklyn.util.core.task.BasicExecutionContext;
import org.apache.brooklyn.util.core.task.DeferredSupplier;
Expand All @@ -52,7 +53,6 @@
import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.core.xstream.ObjectWithDefaultStringImplConverter;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.groovy.GroovyJavaMethods;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.text.Strings;

Expand Down Expand Up @@ -489,7 +489,7 @@ public final Maybe<Object> getImmediately() {
targetSensor = Sensors.newSensor(Object.class, sensorNameS);
}
Object result = targetEntity.sensors().get(targetSensor);
return GroovyJavaMethods.truth(result) ? Maybe.of(result) : ImmediateValueNotAvailableException.newAbsentWithExceptionSupplier();
return JavaGroovyEquivalents.groovyTruth(result) ? Maybe.of(result) : ImmediateValueNotAvailableException.newAbsentWithExceptionSupplier();
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ protected LocalManagementContext newMgmtContext() {
}

protected void addStubbedLocationToCatalog() {
String locationSpec = getLocationSpec();
String provider = getProvider();
String regionOrEndpoint = getRegion();

addCatalogItems(
"brooklyn.catalog:",
" id: " + LOCATION_CATALOG_ID,
" version: 1.0.0",
" itemType: location",
" item:",
" type: " + LOCATION_SPEC,
" type: " + locationSpec,
" brooklyn.config:",
" identity: myidentity",
" credential: mycredential",
Expand All @@ -124,6 +128,9 @@ protected void addStubbedLocationToCatalog() {
" $brooklyn:object:",
" type: "+JcloudsStubTemplateBuilder.class.getName(),
" factoryMethod.name: create",
" factoryMethod.args:",
" - " + provider,
" - " + regionOrEndpoint,
" " + JcloudsLocation.POLL_FOR_FIRST_REACHABLE_ADDRESS_PREDICATE.getName() + ":",
" $brooklyn:object:",
" type: "+Predicates.class.getName(),
Expand Down
Loading

0 comments on commit 6869f7c

Please sign in to comment.