14 グラフ・サーバー(PGX)のスタート・ガイド
グラフ・サーバー(PGX)をインストールしたら、起動してグラフ・サーバー・インスタンスに接続できます。
- グラフ・サーバーの起動(PGX)
このセクションでは、グラフ・サーバー(PGX)を起動および停止するコマンドについて説明します。 - グラフ・サーバー(PGX)への接続
リモート・モードで実行されているか、WebアプリケーションとしてApache TomcatまたはOracle WebLogic Serverにデプロイされているグラフ・サーバー(PGX)に接続する方法について説明します。
14.1 グラフ・サーバー(PGX)の起動
このセクションでは、グラフ・サーバー(PGX)を起動および停止するコマンドについて説明します。
Apache Tomcatの事前構成済バージョンがバンドルされているため、スクリプトを実行してグラフ・サーバー(PGX)を起動できます。
リモート・モードでグラフ・サーバーを起動するための前提条件として、システムにOracleグラフ・サーバーがインストールされていることを確認する必要があります。グラフ・サーバー(PGX)のインストール手順については、Oracle Graph Serverのインストールを参照してください。
ノート:
様々なグラフ・サーバーの実行モードの詳細は、グラフ・サーバー(PGX)の使用モードを参照してください。14.1.1 コマンドラインを使用したグラフ・サーバー(PGX)の起動と停止
PGXはsystemd
と統合され、バックグラウンドでLinuxサービスとして実行されます。
起動前にサーバーを構成する必要がある場合は、構成オプションの詳細について、グラフ・サーバー(PGX)の構成およびグラフ・サーバー(PGX)エンジンの構成パラメータを参照してください。
ノート:
rootユーザーの場合、次のコマンドをsudo
なしで実行できます。
PGXサーバーをデーモン・プロセスとして起動するには、次のコマンドを実行します。
sudo systemctl start pgx
サーバーを停止するには、次のコマンドを実行します。
sudo systemctl stop pgx
サーバーが起動しない場合は、次を実行してエラーがないかどうかを確認できます。
sudo journalctl -u pgx.service
Oracle Linuxでsystemd
を使用して対話する方法の詳細は、Oracle Linux管理者のドキュメントを参照してください。
親トピック: グラフ・サーバー(PGX)の起動
14.1.2 グラフ・サーバー(PGX)の構成
グラフ・サーバー(PGX)を構成するには、/etc/oracle/graph/server.conf
ファイルを変更します。次の表に、JSON形式で指定できる有効な構成オプションを示します。
表14-1 グラフ・サーバー(PGX)の構成パラメータ
パラメータ | 型 | 説明 | デフォルト |
---|---|---|---|
ca_certs |
文字列の配列 |
信頼できる証明書(PEM形式)を格納するファイルのリスト。enable_tls がfalse に設定されている場合、このフィールドは無効です。
|
[] |
ciphers |
文字列の配列 |
サーバーで使用される暗号スイートのリスト。たとえば、[cipher1, cipher2]。 | ["TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384", "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256", "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384", "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256", "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA", "TLS_DHE_RSA_WITH_AES_128_CBC_SHA", "TLS_DHE_DSS_WITH_AES_256_CBC_SHA", "TLS_DHE_RSA_WITH_AES_256_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256", "TLS_DH_DSS_WITH_AES_128_GCM_SHA256", "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_RSA_WITH_AES_256_GCM_SHA384", "TLS_DH_DSS_WITH_AES_256_GCM_SHA384", "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_RSA_WITH_AES_128_CBC_SHA256", "TLS_DH_DSS_WITH_AES_128_CBC_SHA256", "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256", "TLS_RSA_WITH_AES_256_CBC_SHA256", "TLS_DH_DSS_WITH_AES_256_CBC_SHA256", "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384", "TLS_RSA_WITH_AES_128_CBC_SHA", "TLS_DH_DSS_WITH_AES_128_CBC_SHA", "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_256_CBC_SHA", "TLS_DH_DSS_WITH_AES_256_CBC_SHA", "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA"] |
context_path |
string |
コンテキスト・パスの変更に使用できます。たとえば、port を7007 、context path を/pgx に指定すると、サーバーはhttps://localhost:7007/pgx でリスニングします |
/ |
enable_tls |
boolean |
true の場合、サーバーはトランスポート層セキュリティ(TLS)を有効にします。
|
true |
max_header_size |
integer |
有効なヘッダーの最大サイズ(バイト)。null の場合は、Tomcatのデフォルトを使用します。
|
null |
port |
integer |
グラフ・サーバー(PGX)サーバーがリスニングするポート。 | 7007 |
server_cert |
string |
TLSクライアントに提示されるサーバー証明書(PEM形式)へのパス。このファイルには1つの証明書のみが含まれている必要があります。証明書がチェーンで、ルート証明書が含まれている場合は、かわりにca_certs に追加します。enable_tls がfalse に設定されている場合、このフィールドは無効です
ノート:Graph Server and Clientリリース22.3以降、このフィールドは非推奨です。かわりに |
NULL |
server_keystore |
string |
サーバー接続に使用するキーストアへのパス。このフィールドがserver_cert またはserver_private_key とともに存在する場合は、エラーが発生します。
|
NULL |
server_keystore_alias |
string |
server_keystore のサーバー・キーストア別名。
|
NULL |
server_keystore_provider |
string |
server_keystore のサーバー・キーストア・プロバイダ。
|
SunJSSE |
server_keystore_type |
string |
server_keystore のサーバー・キーストア・タイプ。
|
JKS |
server_private_key |
string |
これは、サーバーの秘密キー(PEM形式)を格納するファイルへのパスです。セキュリティ上の理由から、このファイルには所有者のみに対する読取りおよび書込み権限(POSIXファイル・システムの600 権限)のみがある必要があります。そうでない場合はエラーがスローされます。enable_tls がfalse に設定されている場合、このフィールドは無効です。
ノート:Graph Server and Clientリリース22.3以降、このフィールドは非推奨です。かわりに |
NULL |
tls_version |
string |
サーバーで使用されるTLSバージョン。たとえば、TLSv1.2 です |
TLSv1.2 |
working_dir |
string |
サーバーによって一時ファイルの格納に使用される作業ディレクトリ。サーバーを起動したプロセスから書込み可能である必要があり、かつ、サーバーの実行中に他のプロセスからアクセスされない必要があります。 |
グラフ・サーバー(PGX)では、デフォルトで双方向のSSL/TLS (トランスポート層セキュリティ)が有効になります。サーバーはTLS 1.2を適用し、攻撃に対して脆弱であることがわかっている特定の暗号スイートを無効にします。TLSハンドシェイク時に、サーバーとクライアントの両方が証明書を相互に提示し、それを使用してお互いの正当性を検証します。クライアント証明書は、クライアント・アプリケーションの認可にも使用されます。
server.conf
ファイルの構成例
{
"port": 7007,
"enable_tls": true,
"server_cert": "server_cert.pem",
"server_private_key": "server_key.pem",
"ca_certs": [
"server_cert.pem"
]
}
キーストアを使用したserver.conf
ファイルの構成例
{
"port": 7007,
"enable_tls": true,
"enable_client_authentication": true,
"server_keystore": "/pgx/cert/server_keystore.rsa",
"server_keystore_alias": "pgx",
"server_keystore_provider": "JsafeJCE",
"server_keystore_type": "PKCS12"
}
親トピック: グラフ・サーバー(PGX)の起動
14.2 グラフ・サーバー(PGX)への接続
このセクションでは、リモート・モードで実行されているか、WebアプリケーションとしてApache TomcatまたはOracle WebLogic Serverにデプロイされているグラフ・サーバー(PGX)に接続する方法について説明します。
グラフ・サーバーに接続するための前提条件として、グラフ・サーバー(PGX)を起動および実行する必要があります。グラフ・サーバーを起動するコマンドの詳細は、コマンドラインを使用したグラフ・サーバー(PGX)の起動と停止を参照してください。
ノート:
グラフ・サーバー(PGX)をライブラリとして使用している場合は、ライブラリとしてのグラフ・サーバー(PGX)の使用を参照してください。14.2.1 グラフ・クライアントCLIによる接続
リモート・グラフ・サーバー(PGX)インスタンスに接続する最も簡単な方法は、次のように、サーバーのベースURLをグラフ・サーバー(PGX)認証に必要なデータベース・ユーザー名とともに指定することです。
cd /opt/oracle/graph
./bin/opg4j --base_url https://<host>:<port> --username <graphuser>
cd /opt/oracle/graph
./bin/opg4py --base_url https://<host>:<port> --username <graphuser>
<host>
: サーバー・ホスト名<port>
: サーバー・ポート<graphuser>
: データベース・ユーザーデータベース・パスワードの入力を要求されます。
関連項目:
- Java APIの詳細は、Java APIリファレンスを参照してください
- Python APIの詳細は、Python APIリファレンスを参照してください
HTTPリクエストのロギングについて
oracle.pgx
のログ・レベルをDEBUG
に設定します。
ノート:
これらのログを有効にすると、パスワードなどの機密情報が画面に出力されます。opg4j> loglevel("oracle.pgx","DEBUG")
===> Log level of oracle.pgx logger set to DEBUG
opg4j> session.readGraphWithProperties("bank_graph_analytics.json", "bank_graph");
06:29:03,702 DEBUG CommonsVfsProvider - resolve bank_graph_analytics.json
06:29:03,702 DEBUG AbstractConfigFactory - parse graph config from bank_graph_analytics.json (parent: file:///opt/oracle/graph)
06:29:03,709 DEBUG RemoteUtils - create session cookie (session ID = f5d029d7-2924-4cd4-86a9-6999c1ce5e3f)
06:29:03,713 DEBUG RemoteUtils - no value for the sticky cookie given
06:29:03,713 DEBUG RemoteUtils - create csrf token cookie (token = 36acbee2-6b78-4c13-b114-41040809833a)
06:29:03,713 DEBUG HttpRequestExecutor - Requesting POST https://localhost:7007/core/v1/loadGraph HTTP/1.1 with payload {"graphConfig":"HRcBVFVcO0dfXU9bUEhGEEYOdkMUElZYRFpcZgBeDxBYCxFcRGY2c21wIBUBEElAW11HQV5vVhpYAFRIFAMbeC5+NithRx9EEkwUVRADRlFBXVhGFlBpT0ZfSEFpAlZBQ1RXG1kTKiEXSREVCUAWU1dmElJfRlxKa11GDBJdSV1EQwMPd1paVhZfFxYXSREIB1gBEggbMEVMXEpUUV9HQUgWSV1FFVBDV01QVg1uAApZEF4IRA9GdHdqMGhkdhseFklREBBdQ1lCCFZDaU9cSxdUGzpFF1wQD1EBQhADRnZOUVZHWllHQUgWQVdXBVBDURsDQkFSEQBUEVY5DVAdb19YFEdEXF4QDktVDxdRUBQUBVhZV1tYSgZuFwRXCVY5CFQJVRADRnVsfHJtcWlzJjdrbHViQxUPXVxAZhdIEwAXXxEKCVsDEh4bAlhfX1hGFhcWEQBWQEsUHGQBFE9cSxdUGzpFF1wQD1EBQkEbXmxWEFJXTXJXDAhBQFYUWxtkchsVGw1QDgAXXxEnBVYLRVxNFxUBEFVdVUldDQMWF0MUAktIV01cZghUGjpYBEMWD1sDEghNFkJITxUQUExAAgZVXl1pFVhPWlxmVwJcBkcPR3EnKH47fn19IWQPHhtZUVRrFx1ESBoMQ1BDQlxeXBETT0dTCkELB0FGChBLAFVAQRtPaQEWDQVZSBoMQ1tMWFJmXhFQEw1qBF0HCkwQWVFKRkotMjkyAElr0w==","graphName":"bank_graph","_csrf_token":"36acbee2-6b78-4c13-b114-41040809833a"}
06:29:03,788 DEBUG HttpRequestExecutor - received HTTP status 202
06:29:03,789 DEBUG HttpRequestExecutor - {"futureId":"7f7a2206-8881-4c1e-909f-6e8778be617c"}
06:29:03,789 DEBUG PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/status HTTP/1.1
06:29:03,801 DEBUG PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/value HTTP/1.1
06:29:03,831 DEBUG RemoteUtils - received HTTP status 201
06:29:03,831 DEBUG RemoteUtils - {"id":"8B473228-0751-49A9-A945-9A0E4011AB69","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"canonical","method":"GET","interaction":["async-polling"]}],"graphName":"bank_graph","vertexTables":{"Accounts":{"name":"Accounts","metaData":{"name":"Accounts","idType":"integer","labels":["Accounts"],"properties":[],"edgeProviderNamesWhereSource":["Transfers"],"edgeProviderNamesWhereDestination":["Transfers"],"id":null,"links":null},"providerLabels":["Accounts"],"entityKeyType":"integer","isIdentityKeyMapping":false,"vertexProperties":{},"vertexLabels":{"id":"04156FFE-A3C1-4A6D-87E5-879A0895BBD4","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":-1,"propertyId":"04156FFE-A3C1-4A6D-87E5-879A0895BBD4","name":"__vertex_labels__","entityType":"vertex","type":"ro_string_set","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false},"transient":false}},"edgeTables":{"Transfers":{"name":"Transfers","metaData":{"name":"Transfers","idType":"long","directed":true,"labels":["Transfers"],"properties":[{"name":"AMOUNT","id":null,"propertyType":"float","dimension":0,"transient":true,"links":null,"propertyId":"AF2A2D0A-9C8C-478F-BD74-3444A7DD7339"}],"sourceVertexProviderName":"Accounts","destinationVertexProviderName":"Accounts","id":null,"links":null},"providerLabels":["Transfers"],"entityKeyType":"long","isIdentityKeyMapping":true,"sourceVertexTableName":"Accounts","destinationVertexTableName":"Accounts","edgeProperties":{"4046D845-D0C6-4231-A69B-F69D4963CD91":{"id":"4046D845-D0C6-4231-A69B-F69D4963CD91","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":0,"propertyId":"4046D845-D0C6-4231-A69B-F69D4963CD91","name":"AMOUNT","entityType":"edge","type":"float","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false}},"edgeLabel":{"id":"9763546A-1860-49A4-9292-77D2AA04F4BB","links
06:29:03,836 DEBUG PgxSession - engine reports latest snapshot is 621849 milli-seconds old. Max age is 0 milli-seconds
06:29:03,836 DEBUG PgxSession - ==> try to check out newer snapshot
06:29:03,836 DEBUG RemoteUtils - create session cookie (session ID = f5d029d7-2924-4cd4-86a9-6999c1ce5e3f)
06:29:03,836 DEBUG RemoteUtils - no value for the sticky cookie given
06:29:03,836 DEBUG RemoteUtils - create csrf token cookie (token = 36acbee2-6b78-4c13-b114-41040809833a)
06:29:03,836 DEBUG HttpRequestExecutor - Requesting POST https://localhost:7007/core/v1/graphs/x-graph-id/refresh HTTP/1.1 with payload {"blockIfFull":false,"_csrf_token":"36acbee2-6b78-4c13-b114-41040809833a"}
06:29:03,878 DEBUG HttpRequestExecutor - received HTTP status 202
06:29:03,878 DEBUG HttpRequestExecutor - {"futureId":"898d546e-583f-4d37-9ca9-d1e10134037f"}
06:29:04,135 DEBUG PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/status HTTP/1.1
06:29:04,828 DEBUG PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/value HTTP/1.1
06:29:04,858 DEBUG RemoteUtils - received HTTP status 201
06:29:04,859 DEBUG RemoteUtils - {"id":"BE960B34-E135-4CF8-AB2F-E1A6E2D7DB60","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"canonical","method":"GET","interaction":["async-polling"]}],"graphName":"bank_graph","vertexTables":{"Accounts":{"name":"Accounts","metaData":{"name":"Accounts","idType":"integer","labels":["Accounts"],"properties":[],"edgeProviderNamesWhereSource":["Transfers"],"edgeProviderNamesWhereDestination":["Transfers"],"id":null,"links":null},"providerLabels":["Accounts"],"entityKeyType":"integer","isIdentityKeyMapping":false,"vertexProperties":{},"vertexLabels":{"id":"19D95502-40D5-47F2-9F45-B1CD09ECB989","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":-1,"propertyId":"19D95502-40D5-47F2-9F45-B1CD09ECB989","name":"__vertex_labels__","entityType":"vertex","type":"ro_string_set","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false},"transient":false}},"edgeTables":{"Transfers":{"name":"Transfers","metaData":{"name":"Transfers","idType":"long","directed":true,"labels":["Transfers"],"properties":[{"name":"AMOUNT","id":null,"propertyType":"float","dimension":0,"transient":true,"links":null,"propertyId":"9A49BC0C-F8AA-465A-B8D6-CA5A92BAE2C9"}],"sourceVertexProviderName":"Accounts","destinationVertexProviderName":"Accounts","id":null,"links":null},"providerLabels":["Transfers"],"entityKeyType":"long","isIdentityKeyMapping":true,"sourceVertexTableName":"Accounts","destinationVertexTableName":"Accounts","edgeProperties":{"FED6FE43-D311-46B6-9A5A-E8DC0D7B56C6":{"id":"FED6FE43-D311-46B6-9A5A-E8DC0D7B56C6","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":0,"propertyId":"FED6FE43-D311-46B6-9A5A-E8DC0D7B56C6","name":"AMOUNT","entityType":"edge","type":"float","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false}},"edgeLabel":{"id":"371D2AC6-4EC5-45AD-8885-B3590F56D944","links
$5 ==> PgxGraph[name=bank_graph,N=1000,E=5001,created=1621160944599]
>>>setloglevel("oracle.pgx","DEBUG")
>>>session.read_graph_with_properties("/scratch/PG/data/bank_graph_analytics.json")
10:37:46.308 [main] DEBUG oracle.pgx.vfs.CommonsVfsProvider - resolve /scratch/PG/data/bank_graph_analytics.json
10:37:46.314 [main] DEBUG oracle.pgx.config.AbstractConfigFactory - parse graph config from /scratch/PG/data/bank_graph_analytics.json (parent: file:///scratch/PG/data)
10:37:46.464 [main] DEBUG oracle.pgx.client.RemoteUtils - create session cookie (session ID = 786242ef-a430-4964-8379-662079514d2e)
10:37:46.465 [main] DEBUG oracle.pgx.client.RemoteUtils - no value for the sticky cookie given
10:37:46.466 [main] DEBUG oracle.pgx.client.RemoteUtils - create csrf token cookie (token = f02ccd16-56e1-4e61-8d17-d6122f5ea48f)
10:37:46.565 [main] DEBUG oracle.pgx.client.HttpRequestExecutor - Requesting POST https://localhost:7007/core/v1/loadGraph HTTP/1.1 with payload {"graphConfig":"TBpAV0ZGAB5yEUZcRkRQXERHDwJoTBtGU09tU1hVQFxaRghHfnwUHhZcBAtIQw4RcU5XVkNaWUsRGxtGU09tRE5JUBMORlsLQ11RV0YQSURBDlVXWUNTGwxPD1tBUlhZU2lZVU5mWFBEFFsLUBoMRkZHABsBQ1BSRExWWEVRckxSVVVIaVhTXVIbDxN2JXwuaHl1cXtnKzJ+QxgRVkJGVFdADwIRRV1PW0UQHBVJR15EFxBfbEMURk1CAEQXQ11dREhTXEQWARpdVlRIFAwQeXMbSB1PRkYcR10UCBZBERRED1MRHA9aWFtRDwIReXhgcxRPbUpkGRNRAFUAaEhEXUJbAQNfEhYJa1YWUlNNcltcW0xAWBQIEl5dFx0WClMIUhoMEGBABAheB1FBQw8YG11RVGdHTklIFAwQXFhXUhMYRl4KVlxfXFMQXx0PAkZWUVlRZl1RVGdeVkldX1hVEg1fVF1HAU9JFVxTQUBbCwdZCFtdb1tRS0JRVWdDRVZbX1JXQhUDF3BXB10QWUxFEBgQAQNeFV1dUVldVlhrTldfQlRDFAwQZHhmdHJ3MG0scxoaEFBTEQdPAEdWb1lVW1pRclZSWlwPDBRwcXlyamVsKmFHGxpFXUFABgNyAltfRUBaGwwWa2p8emZsdXVmb359Fx0WAl0XWllCEA4QFwJPDEcRHA9ES1lEXhoJbEIPQk9CVRUDF1dYC1MRFRQUXFVfAEQXQ3V+f3h6bRRJAUMRQ0BdUxQIEkRNR1haAxBJFVZXX1EQX0RpJGdwYmRkbX97YxpOahUPRVlHQlRcakdRFkYAT2dGQFtEDAJIExYJEmxXWllBQ0xAFURwGhRcUVpcFwsWBlMLXGdRQFVCDTlMD1VfSVldWkUWUDgzNzmCqX+4","graphName":null,"_csrf_token":"f02ccd16-56e1-4e61-8d17-d6122f5ea48f"}
10:37:47.082 [main] DEBUG oracle.pgx.client.HttpRequestExecutor - received HTTP status 202
10:37:47.082 [main] DEBUG oracle.pgx.client.HttpRequestExecutor - {"futureId":"aeae66b7-e1d6-46f3-b78f-1c0d9642d308"}
10:37:47.086 [pgx-client-thread-2] DEBUG oracle.pgx.client.PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/status HTTP/1.1
10:37:50.434 [pgx-client-thread-2] DEBUG oracle.pgx.client.PgxRemoteFuture - Requesting GET https://localhost:7007/core/v1/futures/x-future-id/value HTTP/1.1
10:37:50.539 [pgx-client-thread-2] DEBUG oracle.pgx.client.RemoteUtils - received HTTP status 201
10:37:50.539 [pgx-client-thread-2] DEBUG oracle.pgx.client.RemoteUtils - {"id":"2EE6F933-5679-4387-B79B-A4AAD0814DC6","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id","rel":"canonical","method":"GET","interaction":["async-polling"]}],"graphName":"bank_graph_analytics","vertexTables":{"Accounts":{"name":"Accounts","metaData":{"name":"Accounts","idType":"integer","labels":["Accounts"],"properties":[{"name":"ID","id":null,"propertyType":"integer","dimension":0,"transient":true,"links":null,"propertyId":"C933AB01-358B-4553-974D-0C54845719F2"},{"name":"NAME","id":null,"propertyType":"string","dimension":0,"transient":true,"links":null,"propertyId":"E0EDF68C-5AFE-4886-B3A0-385CE56F1814"}],"edgeProviderNamesWhereSource":["Transfers"],"edgeProviderNamesWhereDestination":["Transfers"],"id":null,"links":null},"providerLabels":["Accounts"],"keyPropertyName":null,"entityKeyType":"integer","isIdentityKeyMapping":false,"vertexProperties":{"F5023C5A-5294-4383-BA4F-0109C67A020F":{"id":"F5023C5A-5294-4383-BA4F-0109C67A020F","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":0,"propertyId":"F5023C5A-5294-4383-BA4F-0109C67A020F","name":"ID","entityType":"vertex","type":"integer","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false},"C588F89E-53EB-46DD-A83D-1078138C42C7":{"id":"C588F89E-53EB-46DD-A83D-1078138C42C7","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET","interaction":["async-polling"]}],"dimension":0,"propertyId":"C588F89E-53EB-46DD-A83D-1078138C42C7","name":"NAME","entityType":"vertex","type":"string","namespace":"2C17C639-3771-3E30-88AE-34D6B380C5EC","transient":false}},"vertexLabels":{"id":"89FB1A38-BCDF-4FB0-9F8C-59471872BEA3","links":[{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"self","method":"GET","interaction":["async-polling"]},{"href":"https://localhost:7007/core/v1/graphs/x-graph-id/properties/x-property-name","rel":"canonical","method":"GET
10:37:50.655 [pgx-client-thread-2] DEBUG oracle.pgx.api.PgxSession - engine reports latest snapshot is 0 milli-seconds old. Max age is 0 milli-seconds
10:37:50.655 [pgx-client-thread-2] DEBUG oracle.pgx.api.PgxSession - ==> within range. Return snapshot
PgxGraph(name: bank_graph_analytics, v: 1000, e: 5001, directed: True, memory(Mb): 0)
親トピック: グラフ・サーバー(PGX)への接続
14.2.2 Javaによる接続
リモート・グラフ・サーバー(PGX)インスタンスへの接続を取得するには、単にリモートPGXインスタンスのベースURLをgetInstance()
メソッドに渡します。これにより、アプリケーションは自動的にPGXクライアント・ライブラリを使用してリモートに配置されたグラフ・サーバー(PGX)に接続します。
Javaを使用してグラフ・サーバー(PGX)インスタンスを初期化する場合、ベースURLを指定できます。この例は次のようになります。グラフ・サーバー(PGX)へのURLがgetInMemAnalyst
APIコールに提供されます。
import oracle.pgx.api.*;
import oracle.pg.rdbms.*;
ServerInstance instance = GraphServer.getInstance("https://<hostname>:<port>","<username>","<password>".toCharArray());
PgxSession session = instance.createSession("my-session");
ノート:
Java APIの詳細は、Java APIリファレンスを参照してください。親トピック: グラフ・サーバー(PGX)への接続
14.2.2.1 PGXエンジンの起動と停止
アプリケーションからグラフ・サーバー(PGX)を起動するには、PGX構成の引数としてJSONオブジェクトを使用するinstance.startEngine()
をコールします。
ノート:
- グラフ・サーバー(PGX)インスタンスへの接続および
ServerInstance
オブジェクトの取得の詳細は、Javaによる接続を参照してください。 - グラフ・サーバー(PGX)の様々な構成オプションは、グラフ・サーバー(PGX)エンジンの構成パラメータを参照してください。
PGXエンジンの停止
次のいずれかのAPIを使用して、PGXエンジンを停止できます。
instance.shutdownEngineNow(); // cancels pending tasks, throws exception if engine is not running
instance.shutdownEngineNowIfRunning(); // cancels pending tasks, only tries to shut down if engine is running
if (instance.shutdownEngine(30, TimeUnit.SECONDS) == false) {
// doesn't accept new tasks but finishes up remaining tasks
// pending tasks didn't finish after 30 seconds
}
ノート:
PGXエンジンをシャットダウンすると、Apache Tomcatサーバーは存続しますが、新しいセッションは作成できません。また、現在のすべてのセッションおよびタスクが取り消され、終了します。親トピック: Javaによる接続
14.2.3 Pythonによる接続
Pythonプログラムでリモート・グラフ・サーバー(PGX)インスタンスに接続できます。次の例に示すように、セッションを作成するには、まずリモート・サーバーで認証する必要があります。
import pypgx
import opg4py
import opg4py.graph_server as graph_server
pgql_conn = opg4py.pgql.get_connection("<username>","<password>", "<jdbc_url>")
pgql_statement = pgql_conn.create_statement()
pgql = """
CREATE PROPERTY GRAPH bank_graph
VERTEX TABLES (
bank_accounts
LABEL ACCOUNTS
PROPERTIES (ID, NAME)
)
EDGE TABLES (
bank_txns
SOURCE KEY (from_acct_id) REFERENCES bank_accounts (ID)
DESTINATION KEY (to_acct_id) REFERENCES bank_accounts (ID)
LABEL TRANSFERS
PROPERTIES (FROM_ACCT_ID, TO_ACCT_ID, AMOUNT, DESCRIPTION)
) OPTIONS(PG_VIEW)
"""
pgql_statement.execute(pgql)
instance = graph_server.get_instance("<base_url>", "<username>", "<password>")
session = instance.create_session("my_session")
graph = session.read_graph_by_name('BANK_GRAPH', 'pg_view')
analyst = session.create_analyst()
analyst.pagerank(graph)
rs = graph.query_pgql("SELECT id(x), x.pagerank FROM MATCH (x) LIMIT 5")
rs.print()
実行するには、前述のプログラムをprogram.py
という名前のファイルに保存し、次のコマンドを実行します。
python3 program.py
次の出力が表示されます。
+-------------------------------------------+
| id(x) | pagerank |
+-------------------------------------------+
| BANK_ACCOUNTS(2) | 9.749447313256548E-4 |
| BANK_ACCOUNTS(4) | 0.004584001759076056 |
| BANK_ACCOUNTS(6) | 5.358461393401424E-4 |
| BANK_ACCOUNTS(8) | 0.0013051552434930175 |
| BANK_ACCOUNTS(10) | 0.0015040122009364232 |
+-------------------------------------------+
PGQL結果セットからPandasデータフレームへの変換
to_pandas()
メソッドを使用して、PGQL結果セットをpandas.DataFrame
オブジェクトに変換することもできます。これによって、結果セットに対して様々なデータ・フィルタリング操作をより簡単に実行できるようになるとともに、それをラムダ関数で使用することもできます。たとえば、example_query = (
"SELECT n.name AS name, n.age AS age "
"WHERE (n)"
)
result_set = sample_graph.query_pgql(example_query)
result_df = result_set.to_pandas()
result_df['age_bin'] = result_df['age'].apply(lambda x: int(x)/20) # create age bins based on age ranges
ノート:
使用可能なPython APIの完全なセットを確認するには、OPG4PY Python API リファレンスを参照してください。親トピック: グラフ・サーバー(PGX)への接続