http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/ApplicationBuilder.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/ApplicationBuilder.java b/core/src/main/java/org/apache/brooklyn/entity/factory/ApplicationBuilder.java deleted file mode 100644 index 6047159..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/ApplicationBuilder.java +++ /dev/null @@ -1,247 +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.entity.factory; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.mgmt.EntityManager; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.StartableApplication; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.annotations.Beta; - -/** - * Experimental mechanism for defining/building applications. In future releases, this - * API will change. Its concepts will most likely be merged with a TOSCA implementation - * and with {@link EntitySpec}. - * - * For building an application. Users can sub-class and override doBuild(), putting the logic for - * creating and wiring together entities in there. - * - * The builder is mutable; a given instance should be used to build only a single application. - * Once {@link #manage()} has been called, the application will be built and no additional configuration - * should be performed through this builder. - * - * Example (simplified) code for sub-classing is: - * <pre> - * {@code - * app = new ApplicationBuilder() { - * //@Override - * public void doBuild() { - * MySqlNode db = addChild(EntitySpec.create(MySqlNode.class))); - * JBoss7Server as = addChild(EntitySpec.create(JBoss7Server.class) - * .configure(HTTP_PORT, "8080+") - * .configure(javaSysProp("brooklyn.example.db.url"), attributeWhenReady(db, MySqlNode.MYSQL_URL)); - * } - * }.manage(); - * } - * </pre> - * - * @author aled - */ -@Beta -public abstract class ApplicationBuilder { - - @SuppressWarnings("unused") - private static final Logger LOG = LoggerFactory.getLogger(ApplicationBuilder.class); - - @SuppressWarnings("unchecked") - @Beta - /** @deprecated since 0.7.0 the management context should normally be passed in; - * for TestApplication also see TestApplication.Factory.newManagedInstanceForTests() */ - @Deprecated - public static <T extends StartableApplication> T newManagedApp(Class<T> type) { - if (type.isInterface()) { - return (T) newManagedApp(EntitySpec.create(type)); - } else { - return (T) newManagedApp(EntitySpec.create(StartableApplication.class, type)); - } - } - - @SuppressWarnings("unchecked") - @Beta - /** @deprecated since 0.7.0 the management context should normally be passed in; - * for TestApplication also see TestApplication.Factory.newManagedInstanceForTests() */ - @Deprecated - public static <T extends StartableApplication> T newManagedApp(EntitySpec<T> spec) { - return (T) new ApplicationBuilder(spec) { - @Override protected void doBuild() { - } - }.manage(); - } - - @SuppressWarnings("unchecked") - @Beta - public static <T extends StartableApplication> T newManagedApp(Class<T> type, ManagementContext managementContext) { - if (type.isInterface()) { - return (T) newManagedApp(EntitySpec.create(type), managementContext); - } else { - return (T) newManagedApp(EntitySpec.create(StartableApplication.class, type), managementContext); - } - } - - @SuppressWarnings("unchecked") - @Beta - public static <T extends StartableApplication> T newManagedApp(EntitySpec<T> spec, ManagementContext managementContext) { - return (T) new ApplicationBuilder(spec) { - @Override protected void doBuild() { - } - }.manage(managementContext); - } - - protected volatile boolean managed = false; - protected final AtomicBoolean inManage = new AtomicBoolean(false); - private EntitySpec<? extends StartableApplication> appSpec; - private ManagementContext managementContext; - private StartableApplication app; - - public ApplicationBuilder() { - this.appSpec = EntitySpec.create(BasicApplication.class); - } - - public ApplicationBuilder(EntitySpec<? extends StartableApplication> appSpec) { - this.appSpec = EntitySpec.create(appSpec); - } - - public final ApplicationBuilder appDisplayName(String val) { - checkPreManage(); - appSpec.displayName(val); - return this; - } - - protected final <T extends Entity> T createEntity(EntitySpec<T> spec) { - checkDuringManage(); - EntityManager entityManager = managementContext.getEntityManager(); - return entityManager.createEntity(spec); - } - - /** - * Adds the given entity as a child of the application being built. - * To be called during {@link #doBuild()}. - */ - protected final <T extends Entity> T addChild(T entity) { - checkDuringManage(); - return app.addChild(entity); - } - - /** - * Returns the type of the application being built. - */ - public final Class<? extends StartableApplication> getType() { - return appSpec.getType(); - } - - /** - * Configures the application instance. - */ - public final ApplicationBuilder configure(Map<?,?> config) { - checkPreManage(); - appSpec.configure(config); - return this; - } - - /** - * Adds the given entity as a child of the application being built. - */ - protected final <T extends Entity> T addChild(EntitySpec<T> spec) { - checkDuringManage(); - return addChild(createEntity(spec)); - } - - protected final <T extends Entity> T addChild(Map<?,?> config, Class<T> type) { - checkDuringManage(); - EntitySpec<T> spec = EntitySpec.create(type).configure(config); - return addChild(createEntity(spec)); - } - - protected final ManagementContext getManagementContext() { - return checkNotNull(managementContext, "must only be called after manage()"); - } - - protected final StartableApplication getApp() { - return checkNotNull(app, "must only be called after manage()"); - } - - /** - * For overriding, to create and wire together entities. - */ - protected abstract void doBuild(); - - /** - * Creates a new {@link ManagementContext}, and then builds and manages the application. - * - * @see #manage(ManagementContext) - */ - public final StartableApplication manage() { - return manage(Entities.newManagementContext()); - } - - /** - * Builds and manages the application, calling the user's {@link #doBuild()} method. - * - * @throws IllegalStateException If already managed, or if called during {@link #doBuild()}, or if - * multiple concurrent calls - */ - public final StartableApplication manage(ManagementContext managementContext) { - if (!inManage.compareAndSet(false, true)) { - throw new IllegalStateException("Concurrent and re-entrant calls to manage() forbidden on "+this); - } - try { - checkNotManaged(); - this.app = managementContext.getEntityManager().createEntity(appSpec); - this.managementContext = managementContext; - doBuild(); - Entities.startManagement(app, managementContext); - managed = true; - return app; - } finally { - inManage.set(false); - } - } - - protected void checkPreManage() { - if (inManage.get()) { - throw new IllegalStateException("Builder being managed; cannot perform operation during call to manage(), or in doBuild()"); - } - if (managed) { - throw new IllegalStateException("Builder already managed; cannot perform operation after call to manage()"); - } - } - - protected void checkNotManaged() { - if (managed) { - throw new IllegalStateException("Builder already managed; cannot perform operation after call to manage()"); - } - } - - protected void checkDuringManage() { - if (!inManage.get() || app == null) { - throw new IllegalStateException("Operation only permitted during manage, e.g. called from doBuild() of "+this); - } - } -}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/BasicConfigurableEntityFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/BasicConfigurableEntityFactory.java b/core/src/main/java/org/apache/brooklyn/entity/factory/BasicConfigurableEntityFactory.java deleted file mode 100644 index 64a9a42..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/BasicConfigurableEntityFactory.java +++ /dev/null @@ -1,75 +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.entity.factory; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; - -import com.google.common.base.Objects; -import com.google.common.base.Throwables; - -/** @deprecated since 0.7.0; use EntitySpec instead, as per {@link EntityFactory} javadoc */ -@Deprecated -public class BasicConfigurableEntityFactory<T extends Entity> extends AbstractConfigurableEntityFactory<T> { - private transient Class<? extends T> clazz; - private final String clazzName; - - public BasicConfigurableEntityFactory(Class<? extends T> clazz) { - this(new HashMap(), clazz); - } - - public BasicConfigurableEntityFactory(Map flags, Class<? extends T> clazz) { - super(flags); - this.clazz = checkNotNull(clazz, "clazz"); - this.clazzName = clazz.getName(); - } - - public T newEntity2(Map flags, Entity parent) { - try { - Constructor<? extends T> constructor = clazz.getConstructor(Map.class, Entity.class); - return constructor.newInstance(flags, parent); - } catch (InstantiationException e) { - throw Throwables.propagate(e); - } catch (IllegalAccessException e) { - throw Throwables.propagate(e); - } catch (InvocationTargetException e) { - throw Throwables.propagate(e); - } catch (NoSuchMethodException e) { - throw Throwables.propagate(e); - } - } - - private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); - clazz = (Class<T>) getClass().getClassLoader().loadClass(clazzName); - } - - @Override - public String toString() { - return Objects.toStringHelper(this).add("type", clazzName).toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/ClosureEntityFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/ClosureEntityFactory.java b/core/src/main/java/org/apache/brooklyn/entity/factory/ClosureEntityFactory.java deleted file mode 100644 index dcfdb8c..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/ClosureEntityFactory.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.entity.factory; - -import groovy.lang.Closure; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; - -public class ClosureEntityFactory<T extends Entity> extends AbstractConfigurableEntityFactory<T> { - private final Closure<T> closure; - - public ClosureEntityFactory(Closure<T> closure){ - this(new HashMap(),closure); - } - - public ClosureEntityFactory(Map flags, Closure<T> closure) { - super(flags); - this.closure = closure; - } - - public T newEntity2(Map flags, Entity parent) { - if (closure.getMaximumNumberOfParameters()>1) - return closure.call(flags, parent); - else { - //leaving out the parent is discouraged - T entity = closure.call(flags); - if(parent!=null && entity.getParent()==null){ - entity.setParent(parent); - } - - return entity; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactory.java b/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactory.java deleted file mode 100644 index df80300..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactory.java +++ /dev/null @@ -1,33 +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.entity.factory; - -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.config.ConfigKey; - -public interface ConfigurableEntityFactory<T extends Entity> extends EntityFactory<T> { - ConfigurableEntityFactory<T> configure(Map flags); - ConfigurableEntityFactory<T> configure(ConfigKey key, Object value); - ConfigurableEntityFactory<T> configure(ConfigKey.HasConfigKey key, Object value); - - ConfigurableEntityFactory<T> setConfig(ConfigKey key, Object value); - ConfigurableEntityFactory<T> setConfig(ConfigKey.HasConfigKey key, Object value); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactoryFromEntityFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactoryFromEntityFactory.java b/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactoryFromEntityFactory.java deleted file mode 100644 index 5849aa7..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/ConfigurableEntityFactoryFromEntityFactory.java +++ /dev/null @@ -1,45 +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.entity.factory; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; - -public class ConfigurableEntityFactoryFromEntityFactory<T extends Entity> extends AbstractConfigurableEntityFactory<T> { - - private final EntityFactory<? extends T> factory; - - public ConfigurableEntityFactoryFromEntityFactory(EntityFactory<? extends T> entityFactory){ - this(new HashMap(),entityFactory); - } - - public ConfigurableEntityFactoryFromEntityFactory(Map flags, EntityFactory<? extends T> factory) { - super(flags); - this.factory = checkNotNull(factory, "factory"); - } - - @Override - public T newEntity2(Map flags, Entity parent) { - return factory.newEntity(flags, parent); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactory.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactory.java b/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactory.java deleted file mode 100644 index 9d2ba6e..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactory.java +++ /dev/null @@ -1,32 +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.entity.factory; - -import java.util.Map; - -import org.apache.brooklyn.api.entity.Entity; - -/** - * A Factory for creating entities. - * - * @deprecated since 0.7.0; use EntitySpec instead, as the factory does not put the entity through the initialization process */ -@Deprecated -public interface EntityFactory<T extends Entity> { - T newEntity(Map flags, Entity parent); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactoryForLocation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactoryForLocation.java b/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactoryForLocation.java deleted file mode 100644 index 8dbdc0b..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/factory/EntityFactoryForLocation.java +++ /dev/null @@ -1,30 +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.entity.factory; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.location.Location; - -/** - * dispatch interface to allow an EntityFactory to indicate it might be able to discover - * other factories for specific locations (e.g. if the location implements a custom entity-aware interface) - */ -public interface EntityFactoryForLocation<T extends Entity> { - ConfigurableEntityFactory<T> newFactoryForLocation(Location l); -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroup.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroup.java b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroup.java index 440b7eb..00710ca 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroup.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroup.java @@ -25,8 +25,8 @@ import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers; -import org.apache.brooklyn.entity.trait.Changeable; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers; +import org.apache.brooklyn.core.entity.trait.Changeable; import org.apache.brooklyn.sensor.core.Sensors; import org.apache.brooklyn.util.collections.QuorumCheck; import org.apache.brooklyn.util.collections.QuorumCheck.QuorumChecks; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java index 6266d83..74f75f7 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractGroupImpl.java @@ -29,10 +29,10 @@ import org.apache.brooklyn.api.entity.EntityLocal; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.core.BrooklynFeatureEnablement; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; import org.apache.brooklyn.entity.stock.DelegateEntity; import org.apache.brooklyn.util.collections.SetFromLiveMap; import org.slf4j.Logger; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java index ed33ba9..a2ff5ac 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/AbstractMembershipTrackingPolicy.java @@ -32,7 +32,7 @@ import org.apache.brooklyn.api.sensor.SensorEventListener; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.BrooklynLogging; import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.entity.core.Attributes; +import org.apache.brooklyn.core.entity.Attributes; import org.apache.brooklyn.policy.core.AbstractPolicy; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.javalang.JavaClassNames; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/Cluster.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/Cluster.java b/core/src/main/java/org/apache/brooklyn/entity/group/Cluster.java index c498a12..62f5471 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/Cluster.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/Cluster.java @@ -20,8 +20,8 @@ package org.apache.brooklyn.entity.group; import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.core.config.BasicConfigKey; -import org.apache.brooklyn.entity.trait.Resizable; -import org.apache.brooklyn.entity.trait.Startable; +import org.apache.brooklyn.core.entity.trait.Resizable; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.util.core.flags.SetFromFlag; /** http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java index 2927fb2..1b16369 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java @@ -30,16 +30,16 @@ import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.annotation.Effector; +import org.apache.brooklyn.core.annotation.EffectorParam; import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.trait.MemberReplaceable; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.factory.EntityFactory; import org.apache.brooklyn.entity.group.zoneaware.BalancingNodePlacementStrategy; import org.apache.brooklyn.entity.group.zoneaware.ProportionalZoneFailureDetector; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.trait.MemberReplaceable; import org.apache.brooklyn.sensor.core.BasicAttributeSensor; import org.apache.brooklyn.sensor.core.BasicNotificationSensor; import org.apache.brooklyn.sensor.core.Sensors; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java index c1d3dbe..67b2b91 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java @@ -39,17 +39,17 @@ import org.apache.brooklyn.api.location.MachineProvisioningLocation; import org.apache.brooklyn.api.mgmt.Task; import org.apache.brooklyn.api.policy.Policy; import org.apache.brooklyn.core.config.render.RendererHints; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.factory.EntityFactoryForLocation; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; +import org.apache.brooklyn.core.entity.lifecycle.QuorumCheck.QuorumChecks; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic; +import org.apache.brooklyn.core.entity.trait.Startable; +import org.apache.brooklyn.core.entity.trait.StartableMethods; import org.apache.brooklyn.effector.core.Effectors; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.factory.EntityFactory; -import org.apache.brooklyn.entity.factory.EntityFactoryForLocation; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.entity.lifecycle.QuorumCheck.QuorumChecks; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic; import org.apache.brooklyn.entity.stock.DelegateEntity; -import org.apache.brooklyn.entity.trait.Startable; -import org.apache.brooklyn.entity.trait.StartableMethods; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.brooklyn.location.cloud.AvailabilityZoneExtension; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java index 1a5ed34..fc53c21 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java @@ -24,10 +24,10 @@ import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.config.ConfigKey; import org.apache.brooklyn.core.config.ConfigKeys; import org.apache.brooklyn.core.config.MapConfigKey; -import org.apache.brooklyn.entity.core.Attributes; -import org.apache.brooklyn.entity.factory.EntityFactory; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.trait.Startable; +import org.apache.brooklyn.core.entity.Attributes; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.sensor.core.Sensors; import org.apache.brooklyn.util.core.flags.SetFromFlag; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java index c5943f2..65b962a 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java @@ -32,15 +32,15 @@ import org.apache.brooklyn.api.entity.EntityLocal; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.factory.EntityFactory; +import org.apache.brooklyn.core.entity.factory.EntityFactoryForLocation; +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic; +import org.apache.brooklyn.core.entity.trait.Changeable; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.effector.core.Effectors; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.factory.EntityFactory; -import org.apache.brooklyn.entity.factory.EntityFactoryForLocation; -import org.apache.brooklyn.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic; -import org.apache.brooklyn.entity.trait.Changeable; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.sensor.enricher.Enrichers; import org.apache.brooklyn.util.GroovyJavaMethods; import org.apache.brooklyn.util.collections.MutableList; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java index 959731e..36ac0f9 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicGroup.java @@ -26,10 +26,10 @@ import org.apache.brooklyn.api.sensor.AttributeSensor; import org.apache.brooklyn.api.sensor.Sensor; import org.apache.brooklyn.api.sensor.SensorEvent; import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.annotation.Effector; import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.sensor.core.Sensors; import org.apache.brooklyn.util.core.flags.SetFromFlag; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java index 62e4668..a6880b7 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicMultiGroupImpl.java @@ -29,7 +29,7 @@ import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.entity.EntitySpec; import org.apache.brooklyn.api.entity.Group; import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.entity.core.Entities; +import org.apache.brooklyn.core.entity.Entities; import org.apache.brooklyn.sensor.feed.function.FunctionFeed; import org.apache.brooklyn.sensor.feed.function.FunctionPollConfig; import org.apache.brooklyn.util.collections.MutableMap; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabric.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabric.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabric.java index 359de23..fc11e9b 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabric.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabric.java @@ -19,9 +19,9 @@ package org.apache.brooklyn.entity.group; import org.apache.brooklyn.api.entity.ImplementedBy; +import org.apache.brooklyn.core.annotation.Effector; +import org.apache.brooklyn.core.annotation.EffectorParam; import org.apache.brooklyn.effector.core.MethodEffector; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; @ImplementedBy(DynamicRegionsFabricImpl.class) public interface DynamicRegionsFabric extends DynamicFabric { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricImpl.java index a00d801..427dd6c 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricImpl.java @@ -24,9 +24,9 @@ import java.util.Collection; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.Location; import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.core.EntityInternal; -import org.apache.brooklyn.entity.trait.Startable; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.EntityInternal; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.util.exceptions.Exceptions; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroup.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroup.java b/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroup.java index 38477d6..e6f2aab 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroup.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroup.java @@ -20,9 +20,9 @@ package org.apache.brooklyn.entity.group; import org.apache.brooklyn.api.entity.ImplementedBy; import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.annotation.Effector; +import org.apache.brooklyn.core.annotation.EffectorParam; import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.entity.annotation.Effector; -import org.apache.brooklyn.entity.annotation.EffectorParam; @ImplementedBy(QuarantineGroupImpl.class) public interface QuarantineGroup extends AbstractGroup { http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroupImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroupImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroupImpl.java index 749dcad..dfddf5f 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroupImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/QuarantineGroupImpl.java @@ -23,10 +23,10 @@ import java.util.Set; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.mgmt.Task; +import org.apache.brooklyn.core.entity.AbstractEntity; +import org.apache.brooklyn.core.entity.Entities; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.effector.core.Effectors; -import org.apache.brooklyn.entity.core.AbstractEntity; -import org.apache.brooklyn.entity.core.Entities; -import org.apache.brooklyn.entity.trait.Startable; import org.apache.brooklyn.util.core.task.DynamicTasks; import org.apache.brooklyn.util.core.task.Tasks; import org.apache.brooklyn.util.exceptions.Exceptions; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategy.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategy.java b/core/src/main/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategy.java index dcded71..d00784c 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategy.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/zoneaware/BalancingNodePlacementStrategy.java @@ -26,8 +26,8 @@ import java.util.Map; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.Location; +import org.apache.brooklyn.core.entity.trait.Startable; import org.apache.brooklyn.entity.group.DynamicCluster.NodePlacementStrategy; -import org.apache.brooklyn.entity.trait.Startable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/lifecycle/Lifecycle.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/Lifecycle.java b/core/src/main/java/org/apache/brooklyn/entity/lifecycle/Lifecycle.java deleted file mode 100644 index 31578d7..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/Lifecycle.java +++ /dev/null @@ -1,185 +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.entity.lifecycle; - -import java.io.Serializable; -import java.util.Date; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.config.render.RendererHints; -import org.apache.brooklyn.util.core.flags.TypeCoercions; -import org.apache.brooklyn.util.text.StringFunctions; - -import com.google.common.base.CaseFormat; -import com.google.common.base.Function; -import com.google.common.base.Objects; -import com.google.common.base.Preconditions; - -/** - * An enumeration representing the status of an {@link org.apache.brooklyn.api.entity.Entity}. - */ -public enum Lifecycle { - /** - * The entity has just been created. - * - * This stage encompasses the contruction. Once this stage is - * complete, the basic set of {@link brooklyn.event.Sensor}s will be available, apart from any that require the entity to be active or - * deployed to a {@link Location}. - */ - CREATED, - - /** - * The entity is starting. - * <p> - * This stage is typically entered when the {@link brooklyn.entity.trait.Startable#START} {@link brooklyn.entity.Effector} - * is called, to undertake the startup operations from the management plane. - * When this completes the entity will normally transition to - * {@link Lifecycle#RUNNING}. - */ - STARTING, - - /** - * The entity service is expected to be running. In healthy operation, {@link Attributes#SERVICE_UP} will be true, - * or will shortly be true if all service start actions have been completed and we are merely waiting for it to be running. - */ - RUNNING, - - /** - * The entity is stopping. - * - * This stage is activated when the {@link brooklyn.entity.trait.Startable#STOP} effector is called. The entity service is stopped. - * Sensors that provide data from the running entity may be cleared and subscriptions cancelled. - */ - STOPPING, - - /** - * The entity is not expected to be active. - * - * This stage is entered when an entity is stopped, or may be entered when an entity is - * fully created but not started. It may or may not be removed from the location(s) it was assigned, - * and it will typically not be providing new sensor data apart. - */ - STOPPED, - - /** - * The entity is destroyed. - * - * The entity will be unmanaged and removed from any groups and from its parent. - */ - DESTROYED, - - /** - * Entity error state. - * - * This stage is reachable from any other stage if an error occurs or an exception is thrown. - */ - ON_FIRE; - - /** - * The text representation of the {@link #name()}. - * - * This is formatted as lower case characters, with hyphens instead of spaces. - */ - public String value() { - return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); - } - - /** @see #value() */ - @Override - public String toString() { return value(); } - - /** - * Creates a {@link Lifecycle} from a text representation. - * - * This accepts the text representations output by the {@link #value()} method for each entry. - * - * @see #value() - */ - public static Lifecycle fromValue(String v) { - try { - return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, v)); - } catch (IllegalArgumentException iae) { - return ON_FIRE; - } - } - - public static class Transition implements Serializable { - private static final long serialVersionUID = 603419184398753502L; - - final Lifecycle state; - final long timestampUtc; - - public Transition(Lifecycle state, Date timestamp) { - this.state = Preconditions.checkNotNull(state, "state"); - this.timestampUtc = Preconditions.checkNotNull(timestamp, "timestamp").getTime(); - } - - public Lifecycle getState() { - return state; - } - public Date getTimestamp() { - return new Date(timestampUtc); - } - - @Override - public int hashCode() { - return Objects.hashCode(state, timestampUtc); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Transition)) return false; - if (!state.equals(((Transition)obj).getState())) return false; - if (timestampUtc != ((Transition)obj).timestampUtc) return false; - return true; - } - - @Override - public String toString() { - return state+" @ "+timestampUtc+" / "+new Date(timestampUtc); - } - } - - protected static class TransitionCoalesceFunction implements Function<String, Transition> { - private static final Pattern TRANSITION_PATTERN = Pattern.compile("^([\\w-]+)\\s+@\\s+(\\d+).*"); - - @Override - public Transition apply(final String input) { - if (input != null) { - Matcher m = TRANSITION_PATTERN.matcher(input); - if (m.matches()) { - Lifecycle state = Lifecycle.valueOf(m.group(1).toUpperCase().replace('-', '_')); - long time = Long.parseLong(m.group(2)); - return new Transition(state, new Date(time)); - } else { - throw new IllegalStateException("Serialized Lifecycle.Transition can't be parsed: " + input); - } - } else { - return null; - } - } - } - - static { - TypeCoercions.registerAdapter(String.class, Transition.class, new TransitionCoalesceFunction()); - RendererHints.register(Transition.class, RendererHints.displayValue(StringFunctions.toStringFunction())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/lifecycle/PolicyDescriptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/PolicyDescriptor.java b/core/src/main/java/org/apache/brooklyn/entity/lifecycle/PolicyDescriptor.java deleted file mode 100644 index ea737e5..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/PolicyDescriptor.java +++ /dev/null @@ -1,68 +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.entity.lifecycle; - -import org.apache.brooklyn.api.policy.Policy; -import org.apache.brooklyn.entity.core.AbstractEntity; - -import com.google.common.base.Objects; - -/** Emitted as part of {@link AbstractEntity#POLICY_ADDED} and {@link AbstractEntity#POLICY_REMOVED} */ -public class PolicyDescriptor { - - private final String id; - private final String type; - private final String name; - - public PolicyDescriptor(Policy policy) { - this.id = policy.getId(); - this.type = policy.getPolicyType().getName(); - this.name = policy.getDisplayName(); - } - public String getId() { - return id; - } - - public String getPolicyType() { - return type; - } - - public String getName() { - return name; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof PolicyDescriptor)) { - return false; - } - PolicyDescriptor o = (PolicyDescriptor) other; - return Objects.equal(id, o.id) && Objects.equal(type, o.type) && Objects.equal(name, o.name); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public String toString() { - return Objects.toStringHelper(this).add("id", id).add("type", type).add("name", name).omitNullValues().toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/lifecycle/QuorumCheck.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/QuorumCheck.java b/core/src/main/java/org/apache/brooklyn/entity/lifecycle/QuorumCheck.java deleted file mode 100644 index 9d38c36..0000000 --- a/core/src/main/java/org/apache/brooklyn/entity/lifecycle/QuorumCheck.java +++ /dev/null @@ -1,108 +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.entity.lifecycle; - -import java.io.Serializable; - -/** - * For checking if a group/cluster is quorate. That is, whether the group has sufficient - * healthy members. - * @deprecated since 0.7.0 use {@link org.apache.brooklyn.util.collections.QuorumCheck}. - * but keep this for a while as old quorum checks might be persisted. - */ -@Deprecated -public interface QuorumCheck extends org.apache.brooklyn.util.collections.QuorumCheck { - - /** - * @param sizeHealthy Number of healthy members - * @param totalSize Total number of members one would expect to be healthy (i.e. ignoring stopped members) - * @return Whether this group is healthy - */ - public boolean isQuorate(int sizeHealthy, int totalSize); - - public static class QuorumChecks { - /** - * Checks that all members that should be up are up (i.e. ignores stopped nodes). - */ - public static QuorumCheck all() { - return new NumericQuorumCheck(0, 1.0, false); - } - /** - * Checks all members that should be up are up, and that there is at least one such member. - */ - public static QuorumCheck allAndAtLeastOne() { - return new NumericQuorumCheck(1, 1.0, false); - } - /** - * Requires at least one member that should be up is up. - */ - public static QuorumCheck atLeastOne() { - return new NumericQuorumCheck(1, 0.0, false); - } - /** - * Requires at least one member to be up if the total size is non-zero. - * i.e. okay if empty, or if non-empty and something is healthy, but not okay if not-empty and nothing is healthy. - * "Empty" means that no members are supposed to be up (e.g. there may be stopped members). - */ - public static QuorumCheck atLeastOneUnlessEmpty() { - return new NumericQuorumCheck(1, 0.0, true); - } - /** - * Always "healthy" - */ - public static QuorumCheck alwaysTrue() { - return new NumericQuorumCheck(0, 0.0, true); - } - public static QuorumCheck newInstance(int minRequiredSize, double minRequiredRatio, boolean allowEmpty) { - return new NumericQuorumCheck(minRequiredSize, minRequiredRatio, allowEmpty); - } - } - - /** @deprecated since 0.7.0 use {@link org.apache.brooklyn.util.collections.QuorumCheck}. - * but keep this until we have a transition defined. - */ - @Deprecated - public static class NumericQuorumCheck implements QuorumCheck, Serializable { - private static final long serialVersionUID = -5090669237460159621L; - - protected final int minRequiredSize; - protected final double minRequiredRatio; - protected final boolean allowEmpty; - - public NumericQuorumCheck(int minRequiredSize, double minRequiredRatio, boolean allowEmpty) { - this.minRequiredSize = minRequiredSize; - this.minRequiredRatio = minRequiredRatio; - this.allowEmpty = allowEmpty; - } - - @Override - public boolean isQuorate(int sizeHealthy, int totalSize) { - if (allowEmpty && totalSize==0) return true; - if (sizeHealthy < minRequiredSize) return false; - if (sizeHealthy < totalSize*minRequiredRatio-0.000000001) return false; - return true; - } - - @Override - public String toString() { - return "QuorumCheck[require="+minRequiredSize+","+((int)100*minRequiredRatio)+"%"+(allowEmpty ? "|0" : "")+"]"; - } - } - -}
