[
https://issues.apache.org/jira/browse/JCLOUDS-655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14090782#comment-14090782
]
Andrew Ruef edited comment on JCLOUDS-655 at 8/8/14 2:05 PM:
-------------------------------------------------------------
I created image by clicking "create snapshot" from a running instance in
the instance list. What is strange is the output of glance image-list:
{code}
$ glance image-list
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
| ID | Name | Disk Format |
Container Format | Size | Status |
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
| 224f4c31-052f-4e87-9f36-52c148358f60 | CentOS 6.5 | qcow2 | bare
| 344457216 | active |
| 7c35e28f-fee6-4f0a-a479-67ce8aa1e986 | Cirros 0.3.2 | qcow2 | bare
| 13167616 | active |
| cd9d57a9-0978-45f3-9cbc-edb99347be6b | t11 | |
| | active |
| cfefefc1-eba2-4b1e-9b07-a8c74a872d65 | Ubuntu LTS 14.04 | qcow2 | bare
| 254149120 | active |
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
{code}
because the t11 image has no format or size, but I can still start an instance
from it via the openstack web UI.
Here are the logs from debug:
{code}
>> initializing {id=openstack-nova, name=OpenStack Nova Diablo+ API,
>> views=[org.jclouds.compute.ComputeServiceContext], endpointName=Keystone
>> base url ending in /v2.0/, identityName=${tenantName}:${userName} or
>> ${userName}, if your keystone supports a default tenant,
>> credentialName=Optional.of(${password}),
>> documentation=http://api.openstack.org/, api=interface
>> org.jclouds.openstack.nova.v2_0.NovaApi}
>> adding node to group mygroup
- >> searching params({minDisk=20.0, osFamily=ubuntu})
- >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials
- Sending request -576421320: POST https://<redacted>:5000/v2.0/tokens HTTP/1.1
- >>
"{"auth":{"passwordCredentials":{"username":"<redacted>","password":"<redacted>"},"tenantName":"<redacted>"}}"
- >> POST https://stackadm00.umiacs.umd.edu:5000/v2.0/tokens HTTP/1.1
- >> Accept: application/json
- >> Content-Type: application/json
- >> Content-Length: 96
- Receiving response -576421320: HTTP/1.1 200 OK
- << HTTP/1.1 200 OK
- << Vary: X-Auth-Token,Accept-Encoding
- << Date: Fri, 08 Aug 2014 13:58:27 GMT
- << Connection: close
- << Server: Apache/2.2.15 (Red Hat)
- << Content-Type: application/json
- << Content-Length: 8625
- << "{"access": {"token": {"issued_at": "2014-08-08T13:58:27.350697",
"expires": "2014-08-08T14:58:27Z", "id": "<redacted>", "tenant":
{"description": "<redacted>", "enabled": true, "id":
"d312a9d1acee46499e04fc2c0cd7e540", "name": "<redacted>"}}, "serviceCatalog":
[{"endpoints": [{"adminURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540", "id":
"266bcf89093544c584b21ef7152e8a60", "publicURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:9696/", "region": "RegionOne",
"internalURL": "http://192.168.24.16:9696/", "id":
"34a3b8ec6c0845268811939ae00126d8", "publicURL":
"http://192.168.24.16:9696/"}], "endpoints_links": [], "type": "network",
"name": "neutron"}, {"endpoints": [{"adminURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540", "id":
"175f8094d5b94c3d99cc2a088119fdac", "publicURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "volumev2", "name": "cinder_v2"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:9292", "region": "RegionOne",
"internalURL": "http://192.168.24.16:9292", "id":
"0247e4da002646d9ac3be546022e54ae", "publicURL": "http://192.168.24.16:9292"}],
"endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8777", "region": "RegionOne",
"internalURL": "http://192.168.24.16:8777", "id":
"30e427c6f1b44acaab370dc6a8d5fb67", "publicURL": "http://192.168.24.16:8777"}],
"endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540",
"region": "RegionOne", "internalURL":
"http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540", "id":
"6a11da4559cb4ed6b53fed828a8c5ab0", "publicURL":
"http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8773/services/Admin", "region":
"RegionOne", "internalURL": "http://192.168.24.16:8773/services/Cloud", "id":
"4a32e2cec4154aa6a7f9679df8d4243a", "publicURL":
"http://192.168.24.16:8773/services/Cloud"}], "endpoints_links": [], "type":
"ec2", "name": "nova_ec2"}, {"endpoints": [{"adminURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540", "id":
"42d54eeabf29462da7ac7c9d5b8a198f", "publicURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "orchestration", "name": "heat"}, {"endpoints":
[{"adminURL": "https://stackadm00.umiacs.umd.edu:35357/v2.0", "region":
"regionOne", "internalURL": "https://stackadm00.umiacs.umd.edu:5000/v2.0",
"id": "496bbf5f41a746e092e5621ac1e92363", "publicURL":
"https://stackadm00.umiacs.umd.edu:5000/v2.0"}], "endpoints_links": [], "type":
"identity", "name": "keystone"}], "user": {"username": "awruef", "roles_links":
[], "id": "awruef", "roles": [{"name": "_member_"}], "name": "awruef"},
"metadata": {"is_admin": 0, "roles": ["9fe2ff9ee4384b1894a90878d3e92bab"]}}}"
- endpoints for apiType compute and version 2:
{RegionOne=[Endpoint{id=266bcf89093544c584b21ef7152e8a60, region=RegionOne,
publicURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540,
internalURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540,
adminURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540}]}
- no jclouds.zones configured for provider openstack-nova
- no jclouds.zones configured for provider openstack-nova
- >> invoking image:list
- Sending request 510492042: GET
http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/detail
HTTP/1.1
- >> GET
http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/detail
HTTP/1.1
- >> Accept: application/json
- >> X-Auth-Token: <redacted>
- Receiving response 510492042: HTTP/1.1 200 OK
- << HTTP/1.1 200 OK
- << Date: Fri, 08 Aug 2014 13:58:28 GMT
- << Connection: keep-alive
- << X-Compute-Request-Id: req-8a117f97-18ab-4323-841e-60ce4b029028
- << Content-Type: application/json
- << Content-Length: 3474
- << "{"images": [{"status": "ACTIVE", "updated": "2014-08-08T04:43:36Z",
"links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"cd9d57a9-0978-45f3-9cbc-edb99347be6b", "OS-EXT-IMG-SIZE:size": 0, "name":
"t11", "created": "2014-08-08T04:43:36Z", "minDisk": 0, "progress": 100,
"minRam": 0, "metadata": {"block_device_mapping": [{"guest_format": null,
"boot_index": 0, "no_device": null, "volume_id": null, "volume_size": null,
"disk_bus": null, "image_id": null, "source_type": "snapshot", "device_type":
null, "snapshot_id": "a900a56c-61b7-4438-9150-76312fa1aa10",
"destination_type": "volume", "delete_on_termination": null}], "checksum":
"32c08d302f9206668030d47789b77858", "min_ram": "1", "disk_format": "qcow2",
"image_name": "Ubuntu LTS 14.04", "bdm_v2": "True", "image_id":
"cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "root_device_name": "/dev/vda",
"container_format": "bare", "min_disk": "8", "size": "254149120"}}, {"status":
"ACTIVE", "updated": "2014-06-25T13:46:44Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"224f4c31-052f-4e87-9f36-52c148358f60", "OS-EXT-IMG-SIZE:size": 344457216,
"name": "CentOS 6.5", "created": "2014-06-25T13:45:19Z", "minDisk": 8,
"progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE", "updated":
"2014-06-25T13:41:29Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"7c35e28f-fee6-4f0a-a479-67ce8aa1e986", "OS-EXT-IMG-SIZE:size": 13167616,
"name": "Cirros 0.3.2", "created": "2014-06-25T13:41:25Z", "minDisk": 1,
"progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE", "updated":
"2014-06-25T13:38:57Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "OS-EXT-IMG-SIZE:size": 254149120,
"name": "Ubuntu LTS 14.04", "created": "2014-06-25T13:38:28Z", "minDisk": 8,
"progress": 100, "minRam": 1, "metadata": {}}]}"
- Error parsing input
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected
a string but was BEGIN_ARRAY at line 1 column 733
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:178)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:90)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:61)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$ParameterReader.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:260)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:172)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:803)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:768)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:717)
~[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
~[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:82)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:76)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.base.Functions$FunctionComposition.apply(Functions.java:216)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
[compute-basics-jar-with-dependencies.jar:na]
at com.sun.proxy.$Proxy67.listInDetail(Unknown Source) [na:na]
at
org.jclouds.openstack.nova.v2_0.compute.NovaComputeServiceAdapter.listImages(NovaComputeServiceAdapter.java:168)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:121)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:118)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier$SetAndThrowAuthorizationExceptionSupplierBackedLoader.load(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:73)
[compute-basics-jar-with-dependencies.jar:na
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier$SetAndThrowAuthorizationExceptionSupplierBackedLoader.load(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:57)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.get(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:119)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.suppliers.ImageCacheSupplier.get(ImageCacheSupplier.java:64)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.domain.internal.TemplateBuilderImpl.getImages(TemplateBuilderImpl.java:881)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.domain.internal.TemplateBuilderImpl.build(TemplateBuilderImpl.java:681)
[compute-basics-jar-with-dependencies.jar:na]
at edu.umd.umiacs.openstack.examples.MainApp.main(MainApp.java:177)
[compute-basics-jar-with-dependencies.jar:na]
Caused by: java.lang.IllegalStateException: Expected a string but was
BEGIN_ARRAY at line 1 column 733
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:821)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:358)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:346)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$MapTypeAdapter.read(NullFilteringTypeAdapterFactories.java:311)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$MapTypeAdapter.read(NullFilteringTypeAdapterFactories.java:281)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$ParameterReader.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:260)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:172)
~[compute-basics-jar-with-dependencies.jar:na]
... 37 common frames omitted
{code}
Here is the code:
{code}
package edu.umd.umiacs.openstack.examples;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.scriptbuilder.domain.Statements.createOrOverwriteFile;
import static org.jclouds.scriptbuilder.domain.Statements.rm;
import static
org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.blockUntilRunning;
import static
org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.keyPairName;
import static
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import static
org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials;
import static
org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginUser;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.ArrayList;
import java.util.Set;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import org.jclouds.ContextBuilder;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.Apis;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.RunScriptOnNodesException;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.Providers;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.ssh.SshClient;
import org.jclouds.io.Payloads;
import com.google.common.base.Charsets;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.inject.Module;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
public class MainApp {
public static final Map<String, ApiMetadata> allApis =
Maps.uniqueIndex(Apis.viewableAs(ComputeServiceContext.class),
Apis.idFunction());
public static final Map<String, ProviderMetadata> appProviders =
Maps.uniqueIndex(Providers.viewableAs(ComputeServiceContext.class),
Providers.idFunction());
public static final Set<String> allKeys =
ImmutableSet.copyOf(Iterables.concat(appProviders.keySet(), allApis.keySet()));
public static int PARAMETERS = 4;
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax
is: provider identity credential groupName";
private static void uploadResource(ComputeService compute, NodeMetadata node,
byte[] data, String fileName) {
//base64 encode 'data'
String b64data = Base64.encodeBase64String(data);
ArrayList<String> tmp = new ArrayList<String>();
tmp.add(b64data);
System.out.println("Uploading");
//upload it using the createOrOverwriteFile Statement
Statement upload = createOrOverwriteFile("/tmp/upld", tmp);
System.out.println("Decoding");
//use base64 to recreate the file on the far end
Statement decode = exec("base64 -d /tmp/upld > "+fileName);
System.out.println("Removing");
Statement stmts = newStatementList(upload, decode, rm("/tmp/upld"));
ExecResponse resp = compute.runScriptOnNode(node.getId(), stmts);
System.out.println("Done");
return;
}
public static void main(String[] args) {
if (args.length < PARAMETERS) {
throw new IllegalArgumentException(INVALID_SYNTAX);
}
String provider = args[0];
String identity = args[1];
String credential = args[2];
String groupName = args[3];
checkArgument(contains(allKeys, provider), "provider %s not in supported
list: %s", provider, allKeys);
LoginCredentials login = getLogin();
ComputeService compute = initComputeService(provider, identity,
credential);
NodeMetadata node = null;
try {
System.out.printf(">> adding node to group %s%n", groupName);
// Default template chooses the smallest size on an operating system
// that tested to work with java, which tends to be Ubuntu or CentOS
TemplateBuilder templateBuilder = compute.templateBuilder();
// note this will create a user with the same name as you on the
// node. ex. you can connect via ssh publicip
Statement bootInstructions = AdminAccess.standard();
// to run commands as root, we use the runScript option in the template.
templateBuilder.options(runScript(bootInstructions));
templateBuilder.osFamily(OsFamily.UBUNTU);
//templateBuilder.imageId("760153eb-75bf-4c14-94e6-cce36562ab45");
templateBuilder.minDisk(20);
//add openstack-specific options to set ssh key used in image
templateBuilder.options(keyPairName("dev").blockUntilRunning(true).overrideLoginCredentials(login));
//build the node
node = getOnlyElement(compute.createNodesInGroup(groupName, 1,
templateBuilder.build()));
System.out.printf("<< node %s: %s%n", node.getId(),
concat(node.getPrivateAddresses(), node.getPublicAddresses()));
} catch (RunNodesException e) {
System.err.println("<< error adding node to group " + groupName + ": " +
e.getMessage());
}
ListenableFuture<ExecResponse> r = null;
try {
if(node != null) {
System.out.printf(">> Submitting script to run %n");
Statement helloStmt = exec("echo hello");
r = compute.submitScriptOnNode(node.getId(), helloStmt,
runAsRoot(false).overrideLoginCredentials(login));
System.out.printf(">> Submitted script%n");
}
} catch (NoSuchElementException e) {
System.err.printf("<< submit NoSuchElementException%n");
} catch (IllegalStateException e) {
System.err.printf("<< submit IllegalStateException%n");
}
try {
if(r != null) {
System.out.printf("<< Getting response%n");
ExecResponse resp = r.get();
System.out.printf("<< response == %s%n", resp.getOutput());
}
} catch (InterruptedException e) {
System.err.printf("<< r.get() interrupted%n");
} catch (ExecutionException e) {
System.err.printf("<< r.get() execution exception%n");
}
//uploading new program and running it
try {
if(node != null) {
File f = new File("foo.py");
System.out.printf("Ssh put foo.py%n");
byte[] bytes = null;
try {
bytes = FileUtils.readFileToByteArray(f);
} catch (IOException e1) {
System.out.printf("Could not read file%n");
}
if(bytes != null) {
uploadResource(compute, node, bytes, "/home/ubuntu/foo.py");
System.out.printf("Put foo.py on host%n");
/*SshClient client =
compute.getContext().utils().sshForNode().apply(node);
client.put("/home/ubuntu/foo.py", Payloads.newFilePayload(new
File("foo.py")));*/
System.out.printf("Running foo.py on host%n");
Statement execStmt = exec("python /home/ubuntu/foo.py");
r = compute.submitScriptOnNode(node.getId(), execStmt,
runAsRoot(false).overrideLoginCredentials(login));
ExecResponse resp = r.get();
System.out.printf("Got response %s%n", resp.getOutput());
}
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
if(node != null) {
System.out.printf(">> Destroying node %s%n", node.getId());
compute.destroyNode(node.getId());
System.out.printf("<< Node destroyed%n");
}
System.out.printf("<< All done%n");
compute.getContext().close();
System.out.printf("<< Context closed %n");
return;
}
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 + "");
// example of injecting a ssh implementation
Iterable<Module> modules = ImmutableSet.<Module> of(
new JschSshClientModule(),
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();
}
private static LoginCredentials getLogin() {
try {
String user = System.getProperty("user.name");
String privateKey = Files.toString(
new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8);
return LoginCredentials.builder().
user(user).privateKey(privateKey).build();
} catch (Exception e) {
System.err.println("error reading ssh key " + e.getMessage());
System.exit(1);
return null;
}
}
}
{code}
was (Author: awruef):
I created image by clicking "create snapshot" from a running instance in
the instance list. What is strange is the output of glance image-list:
$ glance image-list
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
| ID | Name | Disk Format |
Container Format | Size | Status |
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
| 224f4c31-052f-4e87-9f36-52c148358f60 | CentOS 6.5 | qcow2 | bare
| 344457216 | active |
| 7c35e28f-fee6-4f0a-a479-67ce8aa1e986 | Cirros 0.3.2 | qcow2 | bare
| 13167616 | active |
| cd9d57a9-0978-45f3-9cbc-edb99347be6b | t11 | |
| | active |
| cfefefc1-eba2-4b1e-9b07-a8c74a872d65 | Ubuntu LTS 14.04 | qcow2 | bare
| 254149120 | active |
+--------------------------------------+------------------+-------------+------------------+-----------+--------+
because the t11 image has no format or size, but I can still start an instance
from it via the openstack web UI.
Here are the logs from debug:
{code}
>> initializing {id=openstack-nova, name=OpenStack Nova Diablo+ API,
>> views=[org.jclouds.compute.ComputeServiceContext], endpointName=Keystone
>> base url ending in /v2.0/, identityName=${tenantName}:${userName} or
>> ${userName}, if your keystone supports a default tenant,
>> credentialName=Optional.of(${password}),
>> documentation=http://api.openstack.org/, api=interface
>> org.jclouds.openstack.nova.v2_0.NovaApi}
>> adding node to group mygroup
- >> searching params({minDisk=20.0, osFamily=ubuntu})
- >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials
- Sending request -576421320: POST https://<redacted>:5000/v2.0/tokens HTTP/1.1
- >>
"{"auth":{"passwordCredentials":{"username":"<redacted>","password":"<redacted>"},"tenantName":"<redacted>"}}"
- >> POST https://stackadm00.umiacs.umd.edu:5000/v2.0/tokens HTTP/1.1
- >> Accept: application/json
- >> Content-Type: application/json
- >> Content-Length: 96
- Receiving response -576421320: HTTP/1.1 200 OK
- << HTTP/1.1 200 OK
- << Vary: X-Auth-Token,Accept-Encoding
- << Date: Fri, 08 Aug 2014 13:58:27 GMT
- << Connection: close
- << Server: Apache/2.2.15 (Red Hat)
- << Content-Type: application/json
- << Content-Length: 8625
- << "{"access": {"token": {"issued_at": "2014-08-08T13:58:27.350697",
"expires": "2014-08-08T14:58:27Z", "id": "<redacted>", "tenant":
{"description": "<redacted>", "enabled": true, "id":
"d312a9d1acee46499e04fc2c0cd7e540", "name": "<redacted>"}}, "serviceCatalog":
[{"endpoints": [{"adminURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540", "id":
"266bcf89093544c584b21ef7152e8a60", "publicURL":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:9696/", "region": "RegionOne",
"internalURL": "http://192.168.24.16:9696/", "id":
"34a3b8ec6c0845268811939ae00126d8", "publicURL":
"http://192.168.24.16:9696/"}], "endpoints_links": [], "type": "network",
"name": "neutron"}, {"endpoints": [{"adminURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540", "id":
"175f8094d5b94c3d99cc2a088119fdac", "publicURL":
"http://192.168.24.16:8776/v2/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "volumev2", "name": "cinder_v2"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:9292", "region": "RegionOne",
"internalURL": "http://192.168.24.16:9292", "id":
"0247e4da002646d9ac3be546022e54ae", "publicURL": "http://192.168.24.16:9292"}],
"endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8777", "region": "RegionOne",
"internalURL": "http://192.168.24.16:8777", "id":
"30e427c6f1b44acaab370dc6a8d5fb67", "publicURL": "http://192.168.24.16:8777"}],
"endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540",
"region": "RegionOne", "internalURL":
"http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540", "id":
"6a11da4559cb4ed6b53fed828a8c5ab0", "publicURL":
"http://192.168.24.16:8776/v1/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints":
[{"adminURL": "http://192.168.24.16:8773/services/Admin", "region":
"RegionOne", "internalURL": "http://192.168.24.16:8773/services/Cloud", "id":
"4a32e2cec4154aa6a7f9679df8d4243a", "publicURL":
"http://192.168.24.16:8773/services/Cloud"}], "endpoints_links": [], "type":
"ec2", "name": "nova_ec2"}, {"endpoints": [{"adminURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540", "region":
"RegionOne", "internalURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540", "id":
"42d54eeabf29462da7ac7c9d5b8a198f", "publicURL":
"http://192.168.24.16:8004/v1/d312a9d1acee46499e04fc2c0cd7e540"}],
"endpoints_links": [], "type": "orchestration", "name": "heat"}, {"endpoints":
[{"adminURL": "https://stackadm00.umiacs.umd.edu:35357/v2.0", "region":
"regionOne", "internalURL": "https://stackadm00.umiacs.umd.edu:5000/v2.0",
"id": "496bbf5f41a746e092e5621ac1e92363", "publicURL":
"https://stackadm00.umiacs.umd.edu:5000/v2.0"}], "endpoints_links": [], "type":
"identity", "name": "keystone"}], "user": {"username": "awruef", "roles_links":
[], "id": "awruef", "roles": [{"name": "_member_"}], "name": "awruef"},
"metadata": {"is_admin": 0, "roles": ["9fe2ff9ee4384b1894a90878d3e92bab"]}}}"
- endpoints for apiType compute and version 2:
{RegionOne=[Endpoint{id=266bcf89093544c584b21ef7152e8a60, region=RegionOne,
publicURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540,
internalURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540,
adminURL=http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540}]}
- no jclouds.zones configured for provider openstack-nova
- no jclouds.zones configured for provider openstack-nova
- >> invoking image:list
- Sending request 510492042: GET
http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/detail
HTTP/1.1
- >> GET
http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/detail
HTTP/1.1
- >> Accept: application/json
- >> X-Auth-Token: <redacted>
- Receiving response 510492042: HTTP/1.1 200 OK
- << HTTP/1.1 200 OK
- << Date: Fri, 08 Aug 2014 13:58:28 GMT
- << Connection: keep-alive
- << X-Compute-Request-Id: req-8a117f97-18ab-4323-841e-60ce4b029028
- << Content-Type: application/json
- << Content-Length: 3474
- << "{"images": [{"status": "ACTIVE", "updated": "2014-08-08T04:43:36Z",
"links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"cd9d57a9-0978-45f3-9cbc-edb99347be6b", "OS-EXT-IMG-SIZE:size": 0, "name":
"t11", "created": "2014-08-08T04:43:36Z", "minDisk": 0, "progress": 100,
"minRam": 0, "metadata": {"block_device_mapping": [{"guest_format": null,
"boot_index": 0, "no_device": null, "volume_id": null, "volume_size": null,
"disk_bus": null, "image_id": null, "source_type": "snapshot", "device_type":
null, "snapshot_id": "a900a56c-61b7-4438-9150-76312fa1aa10",
"destination_type": "volume", "delete_on_termination": null}], "checksum":
"32c08d302f9206668030d47789b77858", "min_ram": "1", "disk_format": "qcow2",
"image_name": "Ubuntu LTS 14.04", "bdm_v2": "True", "image_id":
"cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "root_device_name": "/dev/vda",
"container_format": "bare", "min_disk": "8", "size": "254149120"}}, {"status":
"ACTIVE", "updated": "2014-06-25T13:46:44Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"224f4c31-052f-4e87-9f36-52c148358f60", "OS-EXT-IMG-SIZE:size": 344457216,
"name": "CentOS 6.5", "created": "2014-06-25T13:45:19Z", "minDisk": 8,
"progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE", "updated":
"2014-06-25T13:41:29Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"7c35e28f-fee6-4f0a-a479-67ce8aa1e986", "OS-EXT-IMG-SIZE:size": 13167616,
"name": "Cirros 0.3.2", "created": "2014-06-25T13:41:25Z", "minDisk": 1,
"progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE", "updated":
"2014-06-25T13:38:57Z", "links": [{"href":
"http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"rel": "self"}, {"href":
"http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"rel": "bookmark"}, {"href":
"http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
"type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
"cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "OS-EXT-IMG-SIZE:size": 254149120,
"name": "Ubuntu LTS 14.04", "created": "2014-06-25T13:38:28Z", "minDisk": 8,
"progress": 100, "minRam": 1, "metadata": {}}]}"
- Error parsing input
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected
a string but was BEGIN_ARRAY at line 1 column 733
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:178)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:90)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:61)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$ParameterReader.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:260)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:172)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:803)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:768)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.Gson.fromJson(Gson.java:717)
~[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
~[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:82)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:76)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.base.Functions$FunctionComposition.apply(Functions.java:216)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
[compute-basics-jar-with-dependencies.jar:na]
at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
[compute-basics-jar-with-dependencies.jar:na]
at com.sun.proxy.$Proxy67.listInDetail(Unknown Source) [na:na]
at
org.jclouds.openstack.nova.v2_0.compute.NovaComputeServiceAdapter.listImages(NovaComputeServiceAdapter.java:168)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:121)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.config.ComputeServiceAdapterContextModule$2.get(ComputeServiceAdapterContextModule.java:118)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier$SetAndThrowAuthorizationExceptionSupplierBackedLoader.load(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:73)
[compute-basics-jar-with-dependencies.jar:na
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier$SetAndThrowAuthorizationExceptionSupplierBackedLoader.load(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:57)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache.get(LocalCache.java:3934)
[compute-basics-jar-with-dependencies.jar:na]
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938)
[compute-basics-jar-with-dependencies.jar:na]
at
com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.rest.suppliers.MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.get(MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.java:119)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.suppliers.ImageCacheSupplier.get(ImageCacheSupplier.java:64)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.domain.internal.TemplateBuilderImpl.getImages(TemplateBuilderImpl.java:881)
[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.compute.domain.internal.TemplateBuilderImpl.build(TemplateBuilderImpl.java:681)
[compute-basics-jar-with-dependencies.jar:na]
at edu.umd.umiacs.openstack.examples.MainApp.main(MainApp.java:177)
[compute-basics-jar-with-dependencies.jar:na]
Caused by: java.lang.IllegalStateException: Expected a string but was
BEGIN_ARRAY at line 1 column 733
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:821)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:358)
~[compute-basics-jar-with-dependencies.jar:na]
at com.google.gson.internal.bind.TypeAdapters$13.read(TypeAdapters.java:346)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$MapTypeAdapter.read(NullFilteringTypeAdapterFactories.java:311)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.NullFilteringTypeAdapterFactories$MapTypeAdapter.read(NullFilteringTypeAdapterFactories.java:281)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$ParameterReader.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:260)
~[compute-basics-jar-with-dependencies.jar:na]
at
org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory$DeserializeIntoParameterizedConstructor.read(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:172)
~[compute-basics-jar-with-dependencies.jar:na]
... 37 common frames omitted
{code}
Here is the code:
{code}
package edu.umd.umiacs.openstack.examples;
import static com.google.common.base.Charsets.UTF_8;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.contains;
import static com.google.common.collect.Iterables.getOnlyElement;
import static org.jclouds.scriptbuilder.domain.Statements.createOrOverwriteFile;
import static org.jclouds.scriptbuilder.domain.Statements.rm;
import static
org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.blockUntilRunning;
import static
org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.keyPairName;
import static
org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_SCRIPT_COMPLETE;
import static org.jclouds.compute.options.RunScriptOptions.Builder.runAsRoot;
import static
org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials;
import static
org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginUser;
import static org.jclouds.compute.options.TemplateOptions.Builder.runScript;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
import static org.jclouds.compute.predicates.NodePredicates.inGroup;
import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.scriptbuilder.domain.Statements.newStatementList;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.ArrayList;
import java.util.Set;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.ExecutionException;
import org.jclouds.ContextBuilder;
import org.jclouds.apis.ApiMetadata;
import org.jclouds.apis.Apis;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.RunScriptOnNodesException;
import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.enterprise.config.EnterpriseConfigurationModule;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.providers.Providers;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.statements.login.AdminAccess;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.ssh.SshClient;
import org.jclouds.io.Payloads;
import com.google.common.base.Charsets;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.io.Files;
import com.google.inject.Module;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.compute.domain.OsFamily;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.FileUtils;
public class MainApp {
public static final Map<String, ApiMetadata> allApis =
Maps.uniqueIndex(Apis.viewableAs(ComputeServiceContext.class),
Apis.idFunction());
public static final Map<String, ProviderMetadata> appProviders =
Maps.uniqueIndex(Providers.viewableAs(ComputeServiceContext.class),
Providers.idFunction());
public static final Set<String> allKeys =
ImmutableSet.copyOf(Iterables.concat(appProviders.keySet(), allApis.keySet()));
public static int PARAMETERS = 4;
public static String INVALID_SYNTAX = "Invalid number of parameters. Syntax
is: provider identity credential groupName";
private static void uploadResource(ComputeService compute, NodeMetadata node,
byte[] data, String fileName) {
//base64 encode 'data'
String b64data = Base64.encodeBase64String(data);
ArrayList<String> tmp = new ArrayList<String>();
tmp.add(b64data);
System.out.println("Uploading");
//upload it using the createOrOverwriteFile Statement
Statement upload = createOrOverwriteFile("/tmp/upld", tmp);
System.out.println("Decoding");
//use base64 to recreate the file on the far end
Statement decode = exec("base64 -d /tmp/upld > "+fileName);
System.out.println("Removing");
Statement stmts = newStatementList(upload, decode, rm("/tmp/upld"));
ExecResponse resp = compute.runScriptOnNode(node.getId(), stmts);
System.out.println("Done");
return;
}
public static void main(String[] args) {
if (args.length < PARAMETERS) {
throw new IllegalArgumentException(INVALID_SYNTAX);
}
String provider = args[0];
String identity = args[1];
String credential = args[2];
String groupName = args[3];
checkArgument(contains(allKeys, provider), "provider %s not in supported
list: %s", provider, allKeys);
LoginCredentials login = getLogin();
ComputeService compute = initComputeService(provider, identity,
credential);
NodeMetadata node = null;
try {
System.out.printf(">> adding node to group %s%n", groupName);
// Default template chooses the smallest size on an operating system
// that tested to work with java, which tends to be Ubuntu or CentOS
TemplateBuilder templateBuilder = compute.templateBuilder();
// note this will create a user with the same name as you on the
// node. ex. you can connect via ssh publicip
Statement bootInstructions = AdminAccess.standard();
// to run commands as root, we use the runScript option in the template.
templateBuilder.options(runScript(bootInstructions));
templateBuilder.osFamily(OsFamily.UBUNTU);
//templateBuilder.imageId("760153eb-75bf-4c14-94e6-cce36562ab45");
templateBuilder.minDisk(20);
//add openstack-specific options to set ssh key used in image
templateBuilder.options(keyPairName("dev").blockUntilRunning(true).overrideLoginCredentials(login));
//build the node
node = getOnlyElement(compute.createNodesInGroup(groupName, 1,
templateBuilder.build()));
System.out.printf("<< node %s: %s%n", node.getId(),
concat(node.getPrivateAddresses(), node.getPublicAddresses()));
} catch (RunNodesException e) {
System.err.println("<< error adding node to group " + groupName + ": " +
e.getMessage());
}
ListenableFuture<ExecResponse> r = null;
try {
if(node != null) {
System.out.printf(">> Submitting script to run %n");
Statement helloStmt = exec("echo hello");
r = compute.submitScriptOnNode(node.getId(), helloStmt,
runAsRoot(false).overrideLoginCredentials(login));
System.out.printf(">> Submitted script%n");
}
} catch (NoSuchElementException e) {
System.err.printf("<< submit NoSuchElementException%n");
} catch (IllegalStateException e) {
System.err.printf("<< submit IllegalStateException%n");
}
try {
if(r != null) {
System.out.printf("<< Getting response%n");
ExecResponse resp = r.get();
System.out.printf("<< response == %s%n", resp.getOutput());
}
} catch (InterruptedException e) {
System.err.printf("<< r.get() interrupted%n");
} catch (ExecutionException e) {
System.err.printf("<< r.get() execution exception%n");
}
//uploading new program and running it
try {
if(node != null) {
File f = new File("foo.py");
System.out.printf("Ssh put foo.py%n");
byte[] bytes = null;
try {
bytes = FileUtils.readFileToByteArray(f);
} catch (IOException e1) {
System.out.printf("Could not read file%n");
}
if(bytes != null) {
uploadResource(compute, node, bytes, "/home/ubuntu/foo.py");
System.out.printf("Put foo.py on host%n");
/*SshClient client =
compute.getContext().utils().sshForNode().apply(node);
client.put("/home/ubuntu/foo.py", Payloads.newFilePayload(new
File("foo.py")));*/
System.out.printf("Running foo.py on host%n");
Statement execStmt = exec("python /home/ubuntu/foo.py");
r = compute.submitScriptOnNode(node.getId(), execStmt,
runAsRoot(false).overrideLoginCredentials(login));
ExecResponse resp = r.get();
System.out.printf("Got response %s%n", resp.getOutput());
}
}
} catch (InterruptedException e) {
} catch (ExecutionException e) {
}
if(node != null) {
System.out.printf(">> Destroying node %s%n", node.getId());
compute.destroyNode(node.getId());
System.out.printf("<< Node destroyed%n");
}
System.out.printf("<< All done%n");
compute.getContext().close();
System.out.printf("<< Context closed %n");
return;
}
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 + "");
// example of injecting a ssh implementation
Iterable<Module> modules = ImmutableSet.<Module> of(
new JschSshClientModule(),
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();
}
private static LoginCredentials getLogin() {
try {
String user = System.getProperty("user.name");
String privateKey = Files.toString(
new File(System.getProperty("user.home") + "/.ssh/id_rsa"), UTF_8);
return LoginCredentials.builder().
user(user).privateKey(privateKey).build();
} catch (Exception e) {
System.err.println("error reading ssh key " + e.getMessage());
System.exit(1);
return null;
}
}
}
{code}
> com.google.gson.JsonSyntaxException on trying to start a new instance with
> openstack
> ------------------------------------------------------------------------------------
>
> Key: JCLOUDS-655
> URL: https://issues.apache.org/jira/browse/JCLOUDS-655
> Project: jclouds
> Issue Type: Bug
> Components: jclouds-compute
> Affects Versions: 1.8.0
> Environment: Openstack Havana, linux
> Reporter: Andrew Ruef
>
> this seems very similar to [JCLOUDS-558]:
> {code}
> "{"images": [{"status": "ACTIVE", "updated": "2014-08-08T04:43:36Z", "links":
> [{"href":
> "http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
> "rel": "self"}, {"href":
> "http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
> "rel": "bookmark"}, {"href":
> "http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cd9d57a9-0978-45f3-9cbc-edb99347be6b",
> "type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
> "cd9d57a9-0978-45f3-9cbc-edb99347be6b", "OS-EXT-IMG-SIZE:size": 0, "name":
> "t11", "created": "2014-08-08T04:43:36Z", "minDisk": 0, "progress": 100,
> "minRam": 0, "metadata": {"block_device_mapping": [{"guest_format": null,
> "boot_index": 0, "no_device": null, "volume_id": null, "volume_size": null,
> "disk_bus": null, "image_id": null, "source_type": "snapshot", "device_type":
> null, "snapshot_id": "a900a56c-61b7-4438-9150-76312fa1aa10",
> "destination_type": "volume", "delete_on_termination": null}], "checksum":
> "32c08d302f9206668030d47789b77858", "min_ram": "1", "disk_format": "qcow2",
> "image_name": "Ubuntu LTS 14.04", "bdm_v2": "True", "image_id":
> "cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "root_device_name": "/dev/vda",
> "container_format": "bare", "min_disk": "8", "size": "254149120"}},
> {"status": "ACTIVE", "updated": "2014-06-25T13:46:44Z", "links": [{"href":
> "http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
> "rel": "self"}, {"href":
> "http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
> "rel": "bookmark"}, {"href":
> "http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/224f4c31-052f-4e87-9f36-52c148358f60",
> "type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
> "224f4c31-052f-4e87-9f36-52c148358f60", "OS-EXT-IMG-SIZE:size": 344457216,
> "name": "CentOS 6.5", "created": "2014-06-25T13:45:19Z", "minDisk": 8,
> "progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE",
> "updated": "2014-06-25T13:41:29Z", "links": [{"href":
> "http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
> "rel": "self"}, {"href":
> "http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
> "rel": "bookmark"}, {"href":
> "http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/7c35e28f-fee6-4f0a-a479-67ce8aa1e986",
> "type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
> "7c35e28f-fee6-4f0a-a479-67ce8aa1e986", "OS-EXT-IMG-SIZE:size": 13167616,
> "name": "Cirros 0.3.2", "created": "2014-06-25T13:41:25Z", "minDisk": 1,
> "progress": 100, "minRam": 1, "metadata": {}}, {"status": "ACTIVE",
> "updated": "2014-06-25T13:38:57Z", "links": [{"href":
> "http://192.168.24.16:8774/v2/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
> "rel": "self"}, {"href":
> "http://192.168.24.16:8774/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
> "rel": "bookmark"}, {"href":
> "http://192.168.24.16:9292/d312a9d1acee46499e04fc2c0cd7e540/images/cfefefc1-eba2-4b1e-9b07-a8c74a872d65",
> "type": "application/vnd.openstack.image", "rel": "alternate"}], "id":
> "cfefefc1-eba2-4b1e-9b07-a8c74a872d65", "OS-EXT-IMG-SIZE:size": 254149120,
> "name": "Ubuntu LTS 14.04", "created": "2014-06-25T13:38:28Z", "minDisk": 8,
> "progress": 100, "minRam": 1, "metadata": {}}]}"
> - Error parsing input
> com.google.gson.JsonSyntaxException: java.lang.IllegalStateException:
> Expected a string but was BEGIN_ARRAY at line 1 column 733
> {code}
--
This message was sent by Atlassian JIRA
(v6.2#6252)