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

Bundle type endpoint #927

Merged
merged 2 commits into from
Jan 8, 2018
Merged

Bundle type endpoint #927

merged 2 commits into from
Jan 8, 2018

Conversation

ahgittin
Copy link
Contributor

@ahgittin ahgittin commented Jan 5, 2018

It was noted that if the same type is defined in two different bundles, the API does not let you distinguish between the two. This adds /catalog/bundles/{symbolicName}/{version}/types/{typeSymbolicName}/{typeVersion} to resolve that. (It also adds the two immediate ancestor paths, with ../types listing types in the bundle and ../types/{typeSymbolicName} giving TypeDetail assuming typeVersion==version).

It also adds a bunch of tests for behaviour when adding the same type ID:

testAddSameTypeTwiceInSameBundle_SilentlyDeduped()
testAddSameTypeTwiceInSameBundleDifferentDisplayName_LastOneWins()
testAddSameTypeTwiceInSameBundleDifferentDefinition_Disallowed()
testAddSameTypeTwiceInDifferentBundleDifferentDefinition_Disallowed()
testAddSameTypeTwiceInDifferentBundleSameDefinition_AllowedAndApiMakesTheDifferentOnesClear()

the final test above fails after the first commit but is fixed by the second commit here, by changing the type's self link to use the unambiguous bundles/.../types/... endpoint.

and fixes test for self link distinguishing between same type id in different bundles
Copy link
Member

@tbouron tbouron left a comment

Choose a reason for hiding this comment

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

This LGTM @ahgittin, we were definitely missing those endpoints!

I just have a few comments/questions (see below) + one request: we can request the latest type by passing latest as the type's version (it also works like that for the all old catalog endpoints) Could you also add that to the lookup method for bundles?

String version,
@ApiParam(name = "typeSymbolicName", value = "Type name to query", required = true)
@PathParam("typeSymbolicName")
String typeSymbolicName);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure to understand the difference between this endpoint and the one below (i.e. /{symbolicName}/{version}/types/{typeSymbolicName}/{typeVersion}).

It seems to that that it will be the same as "/{symbolicName}/{version}/types/{typeSymbolicName}/latest so probably not needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it isn't latest - it is for case where type version = bundle version. i think as that should be the normal case we should have an endpoint which doesn't require repeating version.

Copy link
Member

Choose a reason for hiding this comment

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

Hum I get your PoV. I believe it's better to specify everything but why not, and it's using the same codepath so I'm fine with that

@Override
public List<TypeSummary> getTypes(String symbolicName, String version) {
ManagedBundle b = lookup(symbolicName, version);
return TypeTransformer.bundleDetails(brooklyn(), b, ui.getBaseUriBuilder(), mgmt()).getTypes();
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need an entitlement check on the bundle here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lookup does the bundle entitlement check doesn't it?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I did check that but forgot about it, ignore me then.

private final static boolean DISALLOW_DIFFERENCES_IN_SAME_TYPE_ID_FROM_DIFFERENT_BUNDLES = true;

@Test
public void testAddSameTypeTwiceInDifferentBundleDifferentDefinition_Disallowed() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this case is not allowed. Could you elaborate on this please @ahgittin ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it might be allowed in future, it certainly can be behind the scenes, but it can cause oddness as it is then ambiguous what type:version would mean if there are two different implementations. so there is strong argument to discourage/prevent it.

however in a multi-tenant world different users might not be allowed to see other bundles, so user 1 and user 2 might add the same type:version where they aren't allowed to see the other (and in fact shouldn't be allowed to know that someone else has defined that type:version), so in that case we would allow this. (we'd weaken restrictions to allow it, maybe e.g. user 2 can add type:version so long as he can't see any differing type:version.) but it might mean that a user 3 who is allowed to see bundles from both user 1 and user 2 is then able to see differing definition, which is not ideal and potentially confusing but i think least bad option. cc @aledsage ?

(NB longer term discussion, not part of this PR which just clarifies and tests current behaviour in this regard)

Copy link
Member

Choose a reason for hiding this comment

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

Ah got it, makes sense

@ahgittin
Copy link
Contributor Author

ahgittin commented Jan 8, 2018

+1 to supporting latest on bundle version -- i'll add that. i think all other comments addressed. latest bundle support could be new PR if you're happy to merge this now @tbouron .

@tbouron
Copy link
Member

tbouron commented Jan 8, 2018

Yep, the latest for bundles is not in the scope of this PR so I'm happy if there is another one for this.

Merging

@asfgit asfgit merged commit 93b2b99 into apache:master Jan 8, 2018
asfgit pushed a commit that referenced this pull request Jan 8, 2018
@tbouron
Copy link
Member

tbouron commented Jan 8, 2018

Actually @ahgittin, it seems the new endpoint is not available: I get a 404 and it does not appear on the swagger page. Not sure what's going on here

@ahgittin
Copy link
Contributor Author

ahgittin commented Jan 8, 2018

v strange. are you sure it was built correctly @tbouron ? it maybe had a mvn clean install pull down a slightly-old snapshot jar? adding a new *Resource class needs updates in a few places but adding methods to the *Api classes is usually straightforward.

@tbouron
Copy link
Member

tbouron commented Jan 8, 2018

I did but looks like I messed up my env somehow. Everything is fine now, sorry for the noise @ahgittin

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