Allow to link contexts and views together, so one provider can inject and call
another. This adds the `linkedContexts`and `linkedViews` methods to the
`ContextBuilder`.
An example usage to link an existing compute context with a blob store one
would be something like:
```java
BlobStoreContext blobstore = ContextBuilder.newBuilder("azureblob")
.credentials("identity", "credential")
...
.buildView(BlobStoreContext.class);
ComputeServiceContext compute = ContextBuilder.newBuilder("azurecompute-arm")
.credentials("identity", "credential")
.linkedViews(blobstore)
...
.buildView(BlobStoreContext.class);
```
Providing a link to a context or view during context creation, makes the linked
entities injectable by "provider id". An example code in the compute provider
could be:
```java
public class DependsOnTheExternalBlob {
private final BlobStoreContext blobstore;
@Inject DependsOnTheExternalBlob(@Named("azureblob") View blobstoreView) {
checkArgument(blobstoreView instanceof BlobStoreContext);
blobstore = (BlobStoreContext) blobstoreView;
}
}
```
Note a couple things:
* Linked contexts and views are bound using the provider id. This allows to
link more than one provider and inject the right one where needed.
* Injection has to use the base `View` and `Context` types. The jclouds-core
project does not have teh BlobStoreContext or ComputeService views; they're
defined in downstream projects, so we can't create a binding for that type when
adding the linked views to the injector.
And finally, specifics for the Azure ARM ImageExtension:
* Since the extension is optional, one could consider to mark the injection as
optional, to avoid failing to create the context if users don't provide the
linked context.
* This PR also provides a commit to allow providers to override the binding for
the image extension. This way the Azure provider will be able to return an
absent extension if there is no linked azure blob context.
@jtjk Could you try building this branch and see if it helps you build the
Azure ARM ImageExtension?
@demobox Could you have a look and give your opinion about this approach to
allowing to call external contexts?
@andreaturli @zack-shoylev This will potentially help calling Neutron from the
nova compute service (although first we need to promote Neutron to this repo).
WDYT about this?
You can view, comment on, or merge this pull request online at:
https://github.com/jclouds/jclouds/pull/960
-- Commit Summary --
* Allow to link contexts and views together
* Allow to override the Image and Security extension bindings
-- File Changes --
M
compute/src/main/java/org/jclouds/compute/config/BaseComputeServiceContextModule.java
(14)
M core/src/main/java/org/jclouds/ContextBuilder.java (24)
A core/src/main/java/org/jclouds/config/BindLinkedContextsAndViews.java (90)
M core/src/test/java/org/jclouds/ContextBuilderTest.java (59)
-- Patch Links --
https://github.com/jclouds/jclouds/pull/960.patch
https://github.com/jclouds/jclouds/pull/960.diff
---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/960