-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a policy to create locations from an entity #750
base: master
Are you sure you want to change the base?
Conversation
- add example to javadoc
This looks really useful but it could probably do with some tests if that's possible @grkvlt? |
Yes, that's true - I'll put something together |
|
||
for (Map.Entry<String, AttributeSensor<?>> entry : getLocationConfiguration().entrySet()) { | ||
AttributeSensor<?> sensor = getLocationConfiguration().get(entry.getKey()); | ||
Object value = entity.sensors().get(sensor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the sensor is not yet populated, wouldn't be safer to require directly value so we can use attributeWhenReady
in the blueprint? or maybe we can always assume that once LOCATION_STATUS
is true, brooklyn would have sensor data ready?
I agree with @drigodwin about the tests :) FYI I've tested the |
@grkvlt any updates on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires tests, and to think about what we should do on rebind.
Out of interest, what was the use-case that motivated you writing this?
this.tags = val; return this; | ||
} | ||
public CreateLocationPolicy build() { | ||
return new CreateLocationPolicy(toFlags()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this build
method - folk should always use the PolicySpec
. I'd probably go further and delete the builder entirely, relying on using the standard PolicySpec
as the way to build it.
|
||
public static final ConfigKey<String> LOCATION_TYPE = ConfigKeys.builder(String.class) | ||
.name("location.type") | ||
.description("The type of location to create, i.e. 'jclouds:aws-ec2'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"e.g." rather than "i.e."
this(MutableMap.<String,Object>of()); | ||
} | ||
|
||
public CreateLocationPolicy(Map<String,?> props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this constructor - rely on PolicySpec
for everything.
public void onEvent(SensorEvent<Boolean> event) { | ||
synchronized (mutex) { | ||
Boolean status = event.getValue(); | ||
if (status) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (Boolean.TRUE.equals(status))
catalogItem = Iterables.get(catalogItems, 0); | ||
} | ||
} else { | ||
if (created.compareAndSet(true, false) && catalogItem != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created
and catalogItem
fields won't survive rebind. Neither will the auto-incrementing version. Therefore this will likely misbehave on rebind.
Thanks for the review @aledsage, I will update appropriately. The use case is for blueprints like Kubernetes, which would be able to add a new |
@grkvlt Could you take a look at this to see if it's still relevant, and address the comments please Thanks |
Adds
CreateLocationPolicy
which configures a location using sensor data from an entity, once the entity is running. The location is added to the catalog for use by other blueprints.