1

Apache JClouds 1.9.2 ライブラリを使用してOpenStack Swiftにアクセスしようとしています。Maven の依存関係:

<dependency>
    <groupId>org.apache.jclouds</groupId>
    <artifactId>jclouds-all</artifactId>
    <version>1.9.2</version>
</dependency>

入門ガイドとそのコード サンプルから始めました。一般に、ブロブを接続して保持するのに問題はありません。しかし、コンテナー (またはコンテナーの内容) のリストを一覧表示しようとすると、次のエラーが発生します。

SEVERE: Error parsing input: java.lang.IllegalStateException: 
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at com.google.gson.Gson.fromJson(Gson.java:770)
    at com.google.gson.Gson.fromJson(Gson.java:719)
    at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:83)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:77)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
    at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
    at org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
    at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
    at com.sun.proxy.$Proxy57.list(Unknown Source)
Caused by: java.lang.IllegalStateException: 
Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:88)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:239)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:225)
    at com.google.gson.Gson.fromJson(Gson.java:805)

以下のコードは、実行時に失敗するサンプルから取得したものcontainerApi.list()です。コメントされているように、メソッドcreateContaineruploadObjectFromString機能します。

Swift が JClouds が期待するものとは少し異なる JSON 形式で応答を返しているとしか思えませんが、これが正しいかどうか、またはそれを解決する方法はわかりません。また、私の OpenStack ダッシュボードを見ると、Object Store はhttp://xx.xx.xx.107:80/swift/v1 ですが、Identity はhttp://xx.xx.xx.101:5000/v2.0 ではありません。そのうちの 1 つが v1 で、もう 1 つが v2.0 である理由と、Java ライブラリを使用するときにこれを考慮に入れる必要があるかどうかを確認してください。使用する Java ライブラリに制限があるとは思わないので、JClouds の代わりに別のものを使用した方がよいのではないかと考えていますが、これが最も適しているように見えました。

import java.io.Closeable;
import java.io.IOException;
import java.util.Set;
import org.jclouds.ContextBuilder;
import org.jclouds.openstack.swift.v1.SwiftApi;
import org.jclouds.openstack.swift.v1.domain.Container;
import org.jclouds.openstack.swift.v1.features.ContainerApi;
import com.google.common.io.Closeables;
public class JCloudsSwift implements Closeable {
    private SwiftApi swiftApi;
    public static void main(String[] args) {
        JCloudsSwift jcloudsSwift = new JCloudsSwift();

          try {
             jcloudsSwift.listContainers();
             jcloudsSwift.close();
          } catch (Exception e) {
             e.printStackTrace();
          } finally {
             try {
                jcloudsSwift.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
          }
    }
    public JCloudsSwift() {
          String provider = "openstack-swift";
          String identity = "tenantName:userName";
          String credential = "password";
          String endPoint = "http://xx.xx.xx.101:5000/v2.0/";
          swiftApi = ContextBuilder.newBuilder(provider)
                .endpoint(endPoint)
                .credentials(identity, credential)
                .buildApi(SwiftApi.class);
       }
       private void listContainers() {
          String region = "us-east-1a";
          ContainerApi containerApi = swiftApi.getContainerApi(region);
          Set<Container> containers = containerApi.list().toSet();
          for (Container container : containers) {
             System.out.println("  " + container);
          }
       }
       public void close() throws IOException {
          Closeables.close(swiftApi, true);
       }
}

zachsh の提案に従って、ワイヤー ログを有効にしました(以下を参照)。いくつかの詳細を隠しました(IP...)。うまくいけば、私はそこで何も妥協しませんでした。

最初に、 swift v1 のようなさまざまなエンドポイントを提供する有効な JSON 応答を取得するアイデンティティ v2 エンドポイントへの呼び出しがあるように見えます。リクエストとレスポンスの両方の content-type はapplication/json. 次に、この迅速なエンドポイントが呼び出されますが、応答はプレーン テキストでのみ返されます。つまり、リクエストのコンテンツ タイプは でapplication/jsonあり、レスポンスのコンテンツ タイプはtext/plainです。"Dev" と "dev2" は、オブジェクト ストア内の 2 つのコンテナーの名前です。

私の Java コードに何か問題があるのでしょうか (ほとんどの例をコピーしましたが、何かを誤って構成した可能性があります)、使用するライブラリーに何か問題があるのでしょうか、それとも Openstack のインストールに何か問題があるのでしょうか (私はそれを制御できませんが、私は詳細を尋ねることができます)。

以下のログを参照してください。

jclouds-wire.log

2016-02-17 09:31:04,562 DEBUG [jclouds.wire] [main] >> "Sensitive data in payload, use PROPERTY_LOGGER_WIRE_LOG_SENSITIVE_INFO override to enable logging this data."
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> POST http://xx.xx.xx.101:5000/v2.0/tokens HTTP/1.1
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Accept: application/json
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Content-Type: application/json
2016-02-17 09:31:04,562 DEBUG [jclouds.headers] [main] >> Content-Length: 103
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << HTTP/1.1 200 OK
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << X-Distribution: Ubuntu
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Connection: keep-alive
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Vary: X-Auth-Token
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Date: Wed, 17 Feb 2016 09:31:27 GMT
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Content-Type: application/json
2016-02-17 09:31:04,984 DEBUG [jclouds.headers] [main] << Content-Length: 4421
2016-02-17 09:31:04,999 DEBUG [jclouds.wire] [main] << "{"access": {"token": {"issued_at": "2016-02-17T09:31:27.785179", "expires": "2016-02-17T10:31:27Z", "id": "fb6b46bd674046ef87c3270f1fd9dafd", "tenant": {"description": "", "enabled": true, "id": "c2c919f7f89a4d8f913e4ce19a0e6ace", "name": "my_tenant_name"}, "audit_ids": ["nIjY-heVSV-cbTfVIpEY-Q"]}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "70c3eef4d3e242348c0e580f94414823", "publicURL": "http://xx.xx.xx.102:8774/v2/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.105:9696", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.105:9696", "id": "2a9328b17cc54538a38fb6ae13e5b3ac", "publicURL": "http://xx.xx.xx.105:9696"}], "endpoints_links": [], "type": "network", "name": "quantum"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "2eda4420ba0a49f9891ed9bd803b569c", "publicURL": "http://xx.xx.xx.104:8776/v2/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "volumev2", "name": "cinderv2"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.102:3333", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:3333", "id": "538aab805479410da21399abd012ceff", "publicURL": "http://xx.xx.xx.102:3333"}], "endpoints_links": [], "type": "s3", "name": "s3"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.103:9292", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.103:9292", "id": "80559923bf354541bdd9f56a45bedd7a", "publicURL": "http://xx.xx.xx.103:9292"}], "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.108:8777", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.108:8777", "id": "a777efdc724643ecb6e705ff2eb47004", "publicURL": "http://xx.xx.xx.108:8777"}], "endpoints_links": [], "type": "metering", "name": "ceilometer"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.220:8000/v1", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.220:8000/v1", "id": "253135e684c24e00bb7bea6feb7cf595", "publicURL": "http://xx.xx.xx.220:8000/v1"}], "endpoints_links": [], "type": "cloudformation", "name": "heat-cfn"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "38264ccfbb574fcd81ba345c9eb7d37b", "publicURL": "http://xx.xx.xx.104:8776/v1/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.102:8773/services/Cloud", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.102:8773/services/Cloud", "id": "4da43f1139c94d8aaf82564e16156ca5", "publicURL": "http://xx.xx.xx.102:8773/services/Cloud"}], "endpoints_links": [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace", "id": "1180dc51deea4523a088871a352d9f72", "publicURL": "http://xx.xx.xx.220:8004/v1/c2c919f7f89a4d8f913e4ce19a0e6ace"}], "endpoints_links": [], "type": "orchestration", "name": "heat"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.107:80/swift", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.107:80/swift/v1", "id": "0457cd31064243c9b548dfe2eb0c1bc8", "publicURL": "http://xx.xx.xx.107:80/swift/v1"}], "endpoints_links": [], "type": "object-store", "name": "swift"}, {"endpoints": [{"adminURL": "http://xx.xx.xx.101:35357/v2.0", "region": "us-east-1a", "internalURL": "http://xx.xx.xx.101:5000/v2.0", "id": "40d04c8899cc4ea083dc5ecac808a825", "publicURL": "http://xx.xx.xx.101:5000/v2.0"}], "endpoints_links": [], "type": "identity", "name": "keystone"}], "user": {"username": "my_user_name", "roles_links": [], "id": "e9312e8a3579404d91ba53894dcf72ea", "roles": [{"name": "Member"}, {"name": "_member_"}], "name": "my_user_name"}, "metadata": {"is_admin": 0, "roles": ["647df06e706f4d1f8a8810246e19bd26", "9fe2ff9ee4384b1894a90878d3e92bab"]}}}"
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> GET http://xx.xx.xx.107:80/swift/v1 HTTP/1.1
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> Accept: application/json
2016-02-17 09:31:05,062 DEBUG [jclouds.headers] [main] >> X-Auth-Token: fb6b46bd674046ef87c3270f1fd9dafd
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << HTTP/1.1 200 OK
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-type: text/plain; charset=utf-8
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Connection: Keep-Alive
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Date: Wed, 17 Feb 2016 09:31:28 GMT
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-Type: text/plain; charset=utf-8
2016-02-17 09:31:05,405 DEBUG [jclouds.headers] [main] << Content-Length: 9
2016-02-17 09:31:05,405 DEBUG [jclouds.wire] [main] << "dev[\n]"
2016-02-17 09:31:05,405 DEBUG [jclouds.wire] [main] << "dev2[\n]"

jclouds.log

2016-02-17 09:31:04,562 DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials
2016-02-17 09:31:04,562 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -1271935931: POST http://xx.xx.xx.101:5000/v2.0/tokens HTTP/1.1
2016-02-17 09:31:04,984 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Receiving response -1271935931: HTTP/1.1 200 OK
2016-02-17 09:31:05,046 DEBUG [org.jclouds.openstack.keystone.v2_0.suppliers.RegionIdToURIFromAccessForTypeAndVersion] [main] endpoints for apiType object-store and version 1: {us-east-1a=[Endpoint{id=0457cd31064243c9b548dfe2eb0c1bc8, region=us-east-1a, publicURL=http://xx.xx.xx.107:80/swift/v1, internalURL=http://xx.xx.xx.107:80/swift/v1, adminURL=http://xx.xx.xx.107:80/swift}]}
2016-02-17 09:31:05,062 DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking container:list
2016-02-17 09:31:05,062 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -629919459: GET http://xx.xx.xx.107:80/swift/v1 HTTP/1.1
2016-02-17 09:31:05,405 DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Receiving response -629919459: HTTP/1.1 200 OK
2016-02-17 09:31:05,420 ERROR [org.jclouds.http.functions.ParseJson] [main] Error parsing input: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.Gson.fromJson(Gson.java:817)
    at com.google.gson.Gson.fromJson(Gson.java:770)
    at com.google.gson.Gson.fromJson(Gson.java:719)
    at org.jclouds.json.internal.GsonWrapper.fromJson(GsonWrapper.java:42)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:83)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:77)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:62)
    at org.jclouds.http.functions.ParseJson.apply(ParseJson.java:42)
    at org.jclouds.rest.internal.InvokeHttpMethod.invoke(InvokeHttpMethod.java:90)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:73)
    at org.jclouds.rest.internal.InvokeHttpMethod.apply(InvokeHttpMethod.java:44)
    at org.jclouds.reflect.FunctionalReflection$FunctionalInvocationHandler.handleInvocation(FunctionalReflection.java:117)
    at com.google.common.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:87)
    at com.sun.proxy.$Proxy57.list(Unknown Source)
    at com.ceph.JCloudsSwift.listContainers(JCloudsSwift.java:58)
    at com.ceph.JCloudsSwift.main(JCloudsSwift.java:22)
Caused by: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING at line 1 column 1 path $
    at com.google.gson.stream.JsonReader.beginArray(JsonReader.java:351)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.readAndBuild(NullFilteringTypeAdapterFactories.java:88)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$IterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:82)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:239)
    at org.jclouds.json.internal.NullFilteringTypeAdapterFactories$FluentIterableTypeAdapter.read(NullFilteringTypeAdapterFactories.java:225)
    at com.google.gson.Gson.fromJson(Gson.java:805)
    ... 15 common frames omitted
4

1 に答える 1