Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions api/src/main/java/org/apache/brooklyn/api/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ public interface Entity extends BrooklynObject {

/**
* Adds the given feed to this entity. Also calls feed.setEntity if available.
*
* @deprecated since 0.13.0; see {@link FeedSupport#add(Feed)}
*/
@Deprecated
<T extends Feed> T addFeed(T feed);

SensorSupport sensors();
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/apache/brooklyn/api/sensor/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface Feed extends EntityAdjunct, Rebindable {

/**
* True if everything has been _started_ (or it is starting) but not stopped,
* even if it is suspended; see also {@link #isActive()}
* even if it is suspended; see also {@link #isRunning()}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Neither of isRunning or isActive methods are available in the class. Did you want to link to somewhere else?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isRunning is inherited from EntityAdjunct, so I think this javadoc link is ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

isRunning() is avail, inherited from EntityAdjunct

*/
boolean isActivated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,8 @@ public boolean removeAllEnrichers() {
*/
@Override
public <T extends Feed> T addFeed(T feed) {
return feeds().add(feed);
feeds().add(feed);
return feed;
}

@Override
Expand All @@ -1896,8 +1897,9 @@ public Collection<Feed> getFeeds() {
public <T extends Feed> T add(T feed) {
return addFeed(feed);
}

@Override

/** @deprecated since 0.13.0 use {@link #add(Feed)} */
@Deprecated
public <T extends Feed> T addFeed(T feed) {
Feed old = findApparentlyEqualAndWarnIfNotSameUniqueTag(feedsInternal, feed);
if (old != null) {
Expand All @@ -1921,7 +1923,7 @@ public <T extends Feed> T addFeed(T feed) {
getManagementContext().getRebindManager().getChangeListener().onManaged(feed);
getManagementSupport().getEntityChangeListener().onFeedAdded(feed);
// TODO Could add equivalent of AbstractEntity.POLICY_ADDED for feeds; no use-case for that yet

return feed;
}

Expand All @@ -1930,7 +1932,8 @@ public boolean remove(Feed feed) {
return removeFeed(feed);
}

@Override
/** @deprecated since 0.13.0 use {@link #remove(Feed)} */
@Deprecated
public boolean removeFeed(Feed feed) {
feed.stop();
boolean changed = feedsInternal.remove(feed);
Expand All @@ -1955,6 +1958,27 @@ public boolean removeAllFeeds() {
}
return changed;
}

@Override
public Iterator<Feed> iterator() {
return getFeeds().iterator();
}

// TODO add these back when we implement AdjunctSupport (after 0.13.0)
// @Override
// public int size() {
// return getFeeds().size();
// }
//
// @Override
// public boolean isEmpty() {
// return getFeeds().isEmpty();
// }
//
// @Override
// public List<Feed> asList() {
// return ImmutableList.copyOf(getFeeds());
// }
}

// -------- SENSORS --------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@

import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.objs.EntityAdjunct;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.sensor.Enricher;
import org.apache.brooklyn.api.sensor.Feed;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ComputeServiceState;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceNotUpLogic;
import org.apache.brooklyn.util.collections.MutableList;
import org.apache.brooklyn.util.guava.Maybe;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

Expand Down Expand Up @@ -66,5 +70,27 @@ public static boolean isSystemEnricher(Enricher enr) {
if (SYSTEM_ENRICHER_UNIQUE_TAGS.contains(enr.getUniqueTag())) return true;
return false;
}


@Beta
public static Lifecycle inferAdjunctStatus(EntityAdjunct a) {
if (a.isRunning()) return Lifecycle.RUNNING;
if (a.isDestroyed()) return Lifecycle.DESTROYED;

// adjuncts don't currently support an "error" state; though that would be useful!

if (a instanceof Policy) {
if (((Policy)a).isSuspended()) return Lifecycle.STOPPED;
return Lifecycle.CREATED;
}
if (a instanceof Feed) {
if (((Feed)a).isSuspended()) return Lifecycle.STOPPED;
if (((Feed)a).isActivated()) return Lifecycle.STARTING;
return Lifecycle.CREATED;
}

// Enricher doesn't support suspend so if not running or destroyed then
// it is just created
return Lifecycle.CREATED;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,27 @@ public interface SensorSupportInternal extends Entity.SensorSupport {
void remove(AttributeSensor<?> attribute);
}

public interface FeedSupport {
// TODO extend AdjunctSupport<Feed>, after 0.13.0
public interface FeedSupport extends Iterable<Feed> {

Collection<Feed> getFeeds();

/**
* Adds the given feed to this entity. The feed will automatically be re-added on brooklyn restart.
*
* @deprecated since 0.13.0 will change to return type 'void', for consistency with other {@link AdjunctSupport}
*/
<T extends Feed> T add(T feed);

/** @deprecated since 0.10.0; use {@link #add()} */
@Deprecated
<T extends Feed> T addFeed(T feed);
// @Override
<T extends Feed> T add(T feed);

/**
* Removes the given feed from this entity.
* @return True if the feed existed at this entity; false otherwise
*/
// @Override
boolean remove(Feed feed);

/** @deprecated since 0.10.0; use {@link #remove()} */
@Deprecated
boolean removeFeed(Feed feed);

/**
* Removes all feeds from this entity.
* Use with caution as some entities automatically register feeds; this will remove those feeds as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public AbstractFeed() {
public void setEntity(EntityLocal entity) {
super.setEntity(entity);
if (BrooklynFeatureEnablement.isEnabled(BrooklynFeatureEnablement.FEATURE_FEED_REGISTRATION_PROPERTY)) {
((EntityInternal)entity).feeds().addFeed(this);
((EntityInternal)entity).feeds().add(this);
}
}

Expand Down
66 changes: 5 additions & 61 deletions core/src/main/java/org/apache/brooklyn/core/policy/Policies.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,74 +18,18 @@
*/
package org.apache.brooklyn.core.policy;

import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.entity.EntityAdjuncts;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import groovy.lang.Closure;

@SuppressWarnings({"rawtypes","unchecked"})
/** @deprecated since 0.13.0 use {@link EntityAdjuncts} */
@Deprecated
public class Policies {

private static final Logger LOG = LoggerFactory.getLogger(Policies.class);

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static SensorEventListener listenerFromValueClosure(final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.listenerFromValueClosure()");
return new SensorEventListener() {
@Override
public void onEvent(SensorEvent event) {
code.call(event.getValue());
}
};
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
/** @deprecated since 0.13.0, use {@link EntityAdjuncts#inferAdjunctStatus(org.apache.brooklyn.api.objs.EntityAdjunct)} */
@Deprecated
public static <T> Policy newSingleSensorValuePolicy(final Sensor<T> sensor, final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.newSingleSensorValuePolicy()");
return new AbstractPolicy() {
@Override
public void setEntity(EntityLocal entity) {
super.setEntity(entity);
entity.subscriptions().subscribe(entity, sensor, listenerFromValueClosure(code));
}
};
}

/**
* @deprecated since 0.11.0; explicit groovy utilities/support will be deleted.
*/
@Deprecated
public static <S,T> Policy newSingleSensorValuePolicy(final Entity remoteEntity, final Sensor<T> remoteSensor,
final Closure code) {
LOG.warn("Use of groovy.lang.Closure is deprecated in Policies.newSingleSensorValuePolicy()");
return new AbstractPolicy() {
@Override
public void setEntity(EntityLocal entity) {
super.setEntity(entity);
entity.subscriptions().subscribe(remoteEntity, remoteSensor, listenerFromValueClosure(code));
}
};
}

public static Lifecycle getPolicyStatus(Policy p) {
if (p.isRunning()) return Lifecycle.RUNNING;
if (p.isDestroyed()) return Lifecycle.DESTROYED;
if (p.isSuspended()) return Lifecycle.STOPPED;
// TODO could policy be in an error state?
return Lifecycle.CREATED;
return EntityAdjuncts.inferAdjunctStatus(p);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public void testConcurrentAddFeed() throws Exception {
for (int i = 0; i < NUM_TASKS; i++) {
ListenableFuture<?> future = executor.submit(new Runnable() {
@Override public void run() {
entity.feeds().addFeed(new MyFeed());
entity.feeds().add(new MyFeed());
}});
futures.add(future);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void testDeletesOrphanedPolicies() throws Exception {
@Test
public void testDeletesOrphanedFeeds() throws Exception {
EntityInternal entity = origApp.addChild(EntitySpec.create(TestEntity.class).impl(MyEntity.class));
Feed feed = entity.feeds().add(new MyFeed());
Feed feed = new MyFeed();
entity.feeds().add(feed);
MementoTweaker tweaker = new MementoTweaker(new Deletions().entities(entity.getId()));
assertTransformDeletes(new Deletions().feeds(feed.getId()), tweaker);
}
Expand All @@ -63,7 +64,8 @@ public void testDeletesOrphanedFeeds() throws Exception {
public void testKeepsReachableAdjuncts() throws Exception {
MyPolicy policy = origApp.policies().add(PolicySpec.create(MyPolicy.class));
MyEnricher enricher = origApp.enrichers().add(EnricherSpec.create(MyEnricher.class));
Feed feed = origApp.feeds().add(new MyFeed());
Feed feed = new MyFeed();
origApp.feeds().add(feed);

// Double-check we have the state we expected for the assertions that it is unmodified!
BrooklynMementoRawData origData = getRawData();
Expand Down
Loading