Search code examples
javaazurejclouds

jclouds-labs azurecompute getting a ComputeService object


Using Jclouds and jclouds-labs azurecompute I have the following code snip-it which is working as expected

ContextBuilder contextBuilder = ContextBuilder.newBuilder(cloudProvider);

AzureComputeApi api = contextBuilder
     .credentials(keyStoreLocation, keyStorePassword)
     .endpoint(uri + subscriptionId)
     .buildApi(AzureComputeApi.class);

List<Location> locations = api.getLocationApi().list();
for(Location l : locations)
     System.out.println(l);

AzureComputeApi is connecting and printing expected output

Location{name=West Europe, displayName=West Europe, availableServices=[Compute, Storage, PersistentVMRole, HighMemory]}
Location{name=North Europe, displayName=North Europe, availableServices=[Compute, Storage, PersistentVMRole, HighMemory]}
...

However my existing jclouds code base is working with an ComputeService type e.g. this approach is working of the cloudProvider's AWS and GCE

ContextBuilder contextBuilder = newContextBuilder(cloudProvider);

ComputeService cs =  contextBuilder
    .credentials(identity, credential)
    .buildView(ComputeServiceContext.class)
    .getComputeService();

How can i get AzureComputeApi to return a ComputeService (or some thing to this effect), so that I don't have to change my existing code base ?
is this is possible.

If I try this code snip-it, using cloudPprovider=azurecompute

ContextBuilder contextBuilder = ContextBuilder.newBuilder(cloudProvider);
ComputeService cs  = contextBuilder
    .credentials(keyStoreLocation, keyStorePassword)
    .endpoint(uri + subscriptionId)
    .buildView(ComputeServiceContext.class)
    .getComputeService();

I get this exception thrown

Exception in thread "main" java.lang.IllegalArgumentException: api {id=azurecompute, name=Microsoft Azure Service Management Service API, views=[], endpointName=Service Management Endpoint ending in your Subscription Id, identityName=Path to Management Certificate .p12 file, or PEM string, credentialName=Optional.of(Password to Management Certificate), documentation=http://msdn.microsoft.com/en-us/library/ee460799, api=interface org.jclouds.azurecompute.AzureComputeApi} not wrappable as org.jclouds.compute.ComputeServiceContext; context: org.jclouds.rest.ApiContext<org.jclouds.azurecompute.AzureComputeApi>, views: []
    at org.jclouds.ContextBuilder.buildView(ContextBuilder.java:604)
    at org.jclouds.ContextBuilder.buildView(ContextBuilder.java:588)
    at com.hazelcast.stabilizer.provisioner.ComputeServiceBuilder.main(ComputeServiceBuilder.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

I know all my keyStoreLocation, keyStorePassword, uri + subscriptionId variables are ok as they work If i am handle the AzureComputeApi direct


Solution

  • Azure compute is still under development and the ComputeService abstraction is still a work in progress, so you can't use it yet; you have to use directly the AzureComputeApi. You can track JCLOUDS-664 if you want to stay up to date.