Skip to content
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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

grkvlt
Copy link
Member

@grkvlt grkvlt commented Jun 29, 2017

Adds CreateLocationPolicywhich 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.

@drigodwin
Copy link
Member

This looks really useful but it could probably do with some tests if that's possible @grkvlt?

@grkvlt
Copy link
Member Author

grkvlt commented Jun 29, 2017

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);
Copy link
Contributor

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?

@andreaturli
Copy link
Contributor

I agree with @drigodwin about the tests :)

FYI I've tested the CreateLocationPolicy and it works fine in some scenarios, only a minor comment.

@andreaturli
Copy link
Contributor

@grkvlt any updates on this?

Copy link
Contributor

@aledsage aledsage left a 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());
Copy link
Contributor

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'")
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

@grkvlt
Copy link
Member Author

grkvlt commented Sep 13, 2017

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 KubernetesLocation or similar.

@tbouron
Copy link
Member

tbouron commented Nov 22, 2017

@grkvlt Did you had the time to look at @aledsage's comments for this PR?

@tbouron
Copy link
Member

tbouron commented Aug 30, 2018

@grkvlt Could you look at @aledsage comments please? Would be great to merge this PR 👍

@nakomis
Copy link
Contributor

nakomis commented Nov 26, 2019

@grkvlt Could you take a look at this to see if it's still relevant, and address the comments please

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants