Use Jclouds with Openstack

326 views
Skip to first unread message

Lahiru Sandaruwan

unread,
May 30, 2012, 2:31:10 AM5/30/12
to jcl...@googlegroups.com
Hi all,

I'm using Jclouds and managed the operations with AWS. I used quick start guides and then the Minecraft sample(from Jclouds-example git source code) which is matching our requirement a lot.

But i'm little bit struggling with setup Openstack with Jclouds and also the Openstack setup.  Our main requirement is to setup LXCs using Openstack.

Any guide to setup those with versions (fro Jclouds, Openstack, and OSes) to be used will be highly appreciated.

Thank you.

--
--
Regards,
--
--
Lahiru Sandaruwan
Software Engineer,
Cloud Team,
WSO2 Inc., http://wso2.com
lean.enterprise.middleware

email: lahi...@gmail.com cell: (+94) 773 325 954
blog: http://lahiruwrites.blogspot.com/
twitter: http://twitter.com/lahirus
linked-in: http://lk.linkedin.com/pub/lahiru-sandaruwan/16/153/146




Adrian Cole

unread,
May 31, 2012, 1:40:51 PM5/31/12
to jcl...@googlegroups.com
Hi, Lahiru.

I suspect the best course is to sort out your OpenStack (hopefully
essex) install w/LXC independently, then try jclouds against it. WRT
doing that, the forums and wikis from OpenStack are a good start.

Once that is working, then it is a good time to ping about any
connection issues.

Good luck!
-A
> --
> You received this message because you are subscribed to the Google Groups
> "jclouds" group.
> To post to this group, send email to jcl...@googlegroups.com.
> To unsubscribe from this group, send email to
> jclouds+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/jclouds?hl=en.

Lahiru Sandaruwan

unread,
May 31, 2012, 1:51:55 PM5/31/12
to jcl...@googlegroups.com
Thanks Adrian,

We were able to setup Openstack and some LXCs in a virtual box environment. We are on hold to check with Jclouds to Openstack since we are sorting out some network level problem. Will ask if any issues futher.
Thanks again for the reply.

On Thu, May 31, 2012 at 11:10 PM, Adrian Cole <adrian...@gmail.com> wrote:han

Lahiru Sandaruwan

unread,
Jun 4, 2012, 5:02:19 AM6/4/12
to jcl...@googlegroups.com
Hi, 
Since i was able to setup Openstack successfully, trying to communicate with an OpenStack endpoint via Jclouds APIs.

OpenStack version : 2012.1 (2012.1-LOCALBRANCH:LOCALREVISION)  Essex
JClouds version : 1.5.0-beta.1

I'm getting an exception (java.lang.NullPointerException: X-Auth-Token) when trying to build the template using TemplateBuilder. Any help would be highly appreciated. 

Exception logs, sample code (MainApp.java) and novarc file is also listed below

================================================================
Exception log

>> initializing {id=nova, name=OpenStack Nova Pre-Diablo API, views=[org.jclouds.compute.ComputeServiceContext], endpointName=https endpoint, identityName=accessKey, credentialName=Optional.of(secretKey), documentation=http://api.openstack.org/, api=interface org.jclouds.openstack.nova.NovaClient, asyncApi=interface org.jclouds.openstack.nova.NovaAsyncClient}
12:23:46.581 [main] DEBUG jclouds.compute - >> searching params([biggest=false, fastest=false, imageName=null, imageDescription=null, imageId=aki-00000002, imagePredicate=null,imageVersion=null, location=null, minCores=0.0, minRam=0, osFamily=null, osName=null, osDescription=null, osVersion=null,
osArch=null, os64Bit=null, hardwareId=null, hypervisor=null])
12:23:46.646 [main] DEBUG o.j.r.internal.AsyncRestClientProxy - Invoking OpenStackAuthAsyncClient.authenticate
12:23:46.661 [i/o thread 0] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request
2101758165: GET http://localhost:5000/v2.0/ HTTP/1.1 12:23:46.661 [i/o thread 0] DEBUG jclouds.headers - >> GET
http://localhost:5000/v2.0/ HTTP/1.1
12:23:46.662 [i/o thread 0] DEBUG jclouds.headers - >> X-Auth-User: demo
12:23:46.663 [i/o thread 0] DEBUG jclouds.headers - >> X-Auth-Key: openstack
12:23:46.663 [i/o thread 0] DEBUG jclouds.headers - >> Accept: */*
12:23:47.068 [i/o thread 0] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Receiving response
2101758165: HTTP/1.1 200 OK
12:23:47.068 [i/o thread 0] DEBUG jclouds.headers - << HTTP/1.1 200 OK
12:23:47.068 [i/o thread 0] DEBUG jclouds.headers - << Vary: X-Auth-Token
12:23:47.068 [i/o thread 0] DEBUG jclouds.headers - << Date: Mon, 04
Jun 2012 06:53:47 GMT
12:23:47.069 [i/o thread 0] DEBUG jclouds.headers - <<
Transfer-Encoding: chunked
12:23:47.069 [i/o thread 0] DEBUG jclouds.headers - << Connection: keep-alive
12:23:47.069 [i/o thread 0] DEBUG jclouds.headers - << Content-Type: application/json
12:23:47.076 [i/o thread 0] DEBUG jclouds.wire - << "{"version": {"status": "beta", "updated": "2011-11-19T00:00:00Z", "media-types":
[{"base": "application/json", "type":
"application/vnd.openstack.identity-v2.0+json"}, {"base":
"application/xml", "type":
"application/vnd.openstack.identity-v2.0+xml"}], "id": "v2.0",
"links": [{"href": "http://172.16.0.1:5000/v2.0/", "rel": "self"},
{"href": "http://docs.openstack.org/api/openstack-identity-service/2.0/content/",
"type": "text/html", "rel": "describedby"}, {"href":
"http://docs.openstack.org/api/openstack-identity-service/2.0/identity-dev-guide-2.0.pdf",
"type": "application/pdf", "rel": "describedby"}]}}"
Exception in thread "main"
com.google.common.util.concurrent.UncheckedExecutionException:
java.lang.NullPointerException: X-Auth-Token
       at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2256)
       at com.google.common.cache.LocalCache.get(LocalCache.java:3980)
       at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3984)
       at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4868)
       at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4874)
       at org.jclouds.openstack.config.OpenStackAuthenticationModule$3.get(OpenStackAuthenticationModule.java:125)
       at org.jclouds.openstack.config.OpenStackAuthenticationModule$3.get(OpenStackAuthenticationModule.java:122)
       at org.jclouds.openstack.functions.URIFromAuthenticationResponseForService.get(URIFromAuthenticationResponseForService.java:48)
       at org.jclouds.openstack.functions.URIFromAuthenticationResponseForService.get(URIFromAuthenticationResponseForService.java:31)
       at org.jclouds.rest.internal.RestAnnotationProcessor.getEndpointFor(RestAnnotationProcessor.java:781)
       at org.jclouds.rest.internal.RestAnnotationProcessor.createRequest(RestAnnotationProcessor.java:428)
       at org.jclouds.rest.internal.AsyncRestClientProxy.createListenableFutureForHttpRequestMappedToMethodAndArgs(AsyncRestClientProxy.java:237)
       at org.jclouds.rest.internal.AsyncRestClientProxy.invoke(AsyncRestClientProxy.java:148)
       at $Proxy76.listImages(Unknown Source)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at org.jclouds.concurrent.internal.SyncProxy.invoke(SyncProxy.java:159)
       at $Proxy77.listImages(Unknown Source)
       at org.jclouds.openstack.nova.compute.strategy.NovaComputeServiceAdapter.listImages(NovaComputeServiceAdapter.java:75)
       at org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:116)
       at org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:112)
       at org.jclouds.collect.TransformingSetSupplier.get(TransformingSetSupplier.java:47)
       at org.jclouds.collect.TransformingSetSupplier.get(TransformingSetSupplier.java:36)
       at org.jclouds.compute.config.BaseComputeServiceContextModule$9.get(BaseComputeServiceContextModule.java:251)
       at org.jclouds.compute.config.BaseComputeServiceContextModule$9.get(BaseComputeServiceContextModule.java:248)
       at org.jclouds.rest.suppliers.SetAndThrowAuthorizationExceptionSupplier.get(SetAndThrowAuthorizationExceptionSupplier.java:49)
       at org.jclouds.concurrent.RetryOnTimeOutExceptionSupplier.get(RetryOnTimeOutExceptionSupplier.java:47)
       at org.jclouds.util.Suppliers2$ExpiringMemoizingSupplier.get(Suppliers2.java:130)
       at org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.get(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:64)
       at org.jclouds.compute.domain.internal.TemplateBuilderImpl.getImages(TemplateBuilderImpl.java:739)
       at org.jclouds.compute.domain.internal.TemplateBuilderImpl.build(TemplateBuilderImpl.java:614)
       at org.jclouds.examples.compute.basics.MainApp.main(MainApp.java:98)
Caused by: java.lang.NullPointerException: X-Auth-Token
       at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:208)
       at org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders.apply(ParseAuthenticationResponseFromHeaders.java:74)
       at org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders.apply(ParseAuthenticationResponseFromHeaders.java:50)
       at com.google.common.util.concurrent.Futures$3.apply(Futures.java:380)
       at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:522)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
       at java.lang.Thread.run(Thread.java:662)

==============================================================================================================


---------------------------------------------------------------------------------------------------------
MainApp.java
-----------------------
package org.jclouds.examples.compute.basics;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.*;
import org.jclouds.compute.domain.internal.NodeMetadataImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.sshj.config.SshjSshClientModule;

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;


import org.jclouds.Constants;


public class MainApp {

   
   public static void main(String[] args) {

       MainApp jCloud = new MainApp();

       //ex. aws-ec2, gogrid
       String provider = "nova";

       // ex. access_key, username
       String identity = "demo";

       // ex. secret_key, password
       String credential = "openstack";

       ComputeService computeService = initComputeService(provider,identity, credential);

       TemplateBuilder templateBuilder =
computeService.templateBuilder().imageId("aki-00000002");
       Template template = templateBuilder.build();

        // TODO invoke later
        // jCloud.startInstance(computeService, template, "default", 1);

   }


   private static ComputeService initComputeService(String provider,
String identity, String credential) {

       Properties properties = new Properties();
      
       long scriptTimeout = TimeUnit.MILLISECONDS.convert(20,TimeUnit.MINUTES);

       properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");

       properties.setProperty(Constants.PROPERTY_ENDPOINT, "http://172.16.0.1:5000/");
       properties.setProperty(Constants.PROPERTY_API_VERSION, "2.0/");

       // example of injecting a ssh implementation
       Iterable<Module> modules = ImmutableSet.<Module>of(
               new SshjSshClientModule(),
               new SLF4JLoggingModule(),
               new EnterpriseConfigurationModule());

       ContextBuilder builder = ContextBuilder.newBuilder(provider)
               .credentials(identity, credential)
               .modules(modules)
               .overrides(properties);


       System.out.printf(">> initializing %s%n", builder.getApiMetadata());

       return builder.buildView(ComputeServiceContext.class).getComputeService();

   }    
}

==============================================================================



"novarc" file is as follows
=========================================================================
NOVA_API_HOST=172.16.0.1
GLANCE_API_HOST=172.16.0.1
KEYSTONE_API_HOST=172.16.0.1

NOVA_REGION="nova"

export NOVA_USERNAME=demo
export NOVA_PROJECT_ID=demo
export NOVA_PASSWORD=openstack
export NOVA_API_KEY=openstack
export NOVA_REGION_NAME=$NOVA_REGION
export NOVA_URL="http://$NOVA_API_HOST:5000/v2.0/"
export NOVA_VERSION="1.1"

export OS_USERNAME=demo
export OS_PASSWORD=openstack
export OS_TENANT_ID=6689a3d1caab4f7a8016f37c0a390adb
export OS_AUTH_URL="http://$KEYSTONE_API_HOST:5000/v2.0/"
export OS_AUTH_STRATEGY="keystone"

export EC2_URL="http://$NOVA_API_HOST:8773/services/Cloud"
export EC2_ACCESS_KEY="711066536be54d2b86ab15691f7557ee"
export EC2_SECRET_KEY="61bc9b2a6781490cb421493aa8c9cd30"
export S3_URL="http://$GLANCE_API_HOST:3333"
==============================================================

Adrian Cole

unread,
Jun 4, 2012, 11:19:04 AM6/4/12
to jcl...@googlegroups.com

Hi, Lahiru.

Use the provider 'openstack-nova' vs 'nova' and set the endpoint to your keystone url.

You can look at the readme on github/jclouds/jclouds-examples compute-basics as well.

-A

Lahiru Sandaruwan

unread,
Jun 4, 2012, 11:32:40 AM6/4/12
to jcl...@googlegroups.com
Hi Adrian,
I was able to start, list, and delete operations to Openstack - LXC instances :). Thanks for the help and guidance.

Thank you.

Adrian Cole

unread,
Jun 4, 2012, 11:51:09 AM6/4/12
to jcl...@googlegroups.com

Sweet!

Reply all
Reply to author
Forward
0 new messages