Skip to content

Conversation

@aledsage
Copy link
Contributor

This replaces #396

See also neykov#4 (but I'll replay all the comments from that PR into this PR).

Bundle b = bundle.get();
Class<T> clazz;
Optional<String> strippedType = osgiClassPrefixer.stripMatchingPrefix(b, type);
String typeToLoad = strippedType.isPresent() ? strippedType.get() : type;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aledsage wrote 9 days ago:
Not sure if this is the right place for the fix! Arguably if it has the prefix, we should only look in one bundle (or multiple versions of the bundle), rather than iterating over all bundles.

@neykov responded 7 days ago:
If a class has bundle prefix obviously it's not relying on the libraries functionality to load it. Still could be useful to have this to avoid version mismatch (half of the blueprint is coming from libraries section the other half is using prefixes because of copy&paste).
I'd structure it a bit differently - if there's a prefix short-circuit and don't try to load it from non-matching bundles, but can't get away from iterating over them. And it's not all, just those in the libraries section so it's fine.
The prefix could include version as well - would be nice to support it here as well (by skipping non-matching versions) to avoid introducing subtle inconsistencies in the prefix behaviour.

@neykov responded 7 days ago:
This makes more sense now that I saw the commit comment. This is called by persistence, not only by yaml parsing code.
Another approach would be to skip writing the prefix if it the class comes from bundles in the memento's catalog item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points @neykov. I'll strip the version from the prefix as well.

I'll let it match by just comparing the symbolic name (even if wrong version number) because that will better support upgrades/rollback of bundles, where the symbolicName:version:className has been persisted (I'd hope we miss out the version number in persisted state for that reason though).

I'd prefer not to try skipping the prefix "if the class comes from the bundles in the memento's catalog item". It makes sense at a high level, but I worry about situations where there are nested catalog items or sub-types (where different levels declare their libraries). We should handle such cases, but it feels to me like belt-and-braces if we include the bundle id here as well. If we do want to skip writing the prefix in such cases, let's look at that in a separate PR.

public Optional<String> stripMatchingPrefix(Bundle bundle, String type) {
String symbolicName = bundle.getSymbolicName();
if (symbolicName != null && type.startsWith(symbolicName + ":")) {
return Optional.of(type.substring((symbolicName + ":").length()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neykov wrote: The prefix could include version identifier as well.


public Optional<String> getPrefix(Class<?> type) {
Optional<Bundle> bundle = Osgis.getBundleOf(type);
if (bundle.isPresent() && !whiteListRetriever.isBundleWhiteListed(bundle.get())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@neykov wrote 7 days:
Don't like how the white list is proliferating throughout the code base. It's supposed to go the other way :).
What do we gain by stripping the prefix for white listed bundles? I think not much because if classes move bundles then their package will change anyway. This can be handled by the renaming list.

Removing this will simplify the code and we don't lose much if anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the plus side, this is just moving the white list code (rather than proliferating). It is deleted from XmlMementoSerializer.OsgiClassnameMapper, which now delegates to this code. It does mean the white-list code is called slightly more often, but thus in a more consistent manner for handling prefixes.

Let's revisit the white list in a separate PR (potentially on the dev@brooklyn mailing list first).

@aledsage aledsage force-pushed the neykov-aled/test/osgi-prefix-rebind branch from 49b6535 to f4d3c18 Compare November 17, 2016 11:13
@aledsage
Copy link
Contributor Author

@neykov can you review this again please?

@aledsage aledsage force-pushed the neykov-aled/test/osgi-prefix-rebind branch from f4d3c18 to ea9084e Compare November 22, 2016 12:23
@aledsage aledsage force-pushed the neykov-aled/test/osgi-prefix-rebind branch from ea9084e to bad3280 Compare November 25, 2016 23:28
if (osgiClassPrefixer.hasPrefix(typeToLoad)) {
bundleProblems.put(osgiBundle, new UserFacingException("Bundle does not match prefix in type name '"+typeToLoad+"'"));
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

getResource(s) needs the same update. Turns out we can't load prefixed resources when combined with brooklyn.libraries.
Could be addressed as another PR.

@neykov
Copy link
Member

neykov commented Nov 29, 2016

LGTM, merging.
Resource handling can be added in another PR.

@asfgit asfgit merged commit bad3280 into apache:master Nov 29, 2016
asfgit pushed a commit that referenced this pull request Nov 29, 2016
BROOKLYN-379: Fix rebind when bundle prefixes are used to load classes

This replaces #396

See also neykov#4 (but I'll replay all the comments from that PR into this PR).
@aledsage aledsage deleted the neykov-aled/test/osgi-prefix-rebind branch December 5, 2016 16:27
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.

3 participants