TIBCO Data Virtualization で WordPress のデータ にリアルタイムアクセスする方法
TIBCO Data Virtualization(TDV)は、複数の多様なデータソースへのアクセスを一元管理するエンタープライズデータ仮想化ソリューションです。CData TIBCO DV Adapter for WordPress と組み合わせることで、TIBCO Data Virtualization 内からWordPress のデータに直接フェデレーテッドアクセスが可能になります。この記事では、アダプターのデプロイと WordPress に基づく新しいデータソースの作成手順を解説します。
CData TIBCO DV Adapter は、最適化されたデータ処理機能が組み込まれており、WordPress のデータ とのインタラクションにおいて比類のないパフォーマンスを発揮します。WordPress に対して複雑な SQL クエリを発行すると、アダプターはフィルタや集計などサポートされている SQL 操作を直接 WordPress にプッシュします。組み込みの動的メタデータクエリにより、ネイティブのデータ型を使用してWordPress のデータを操作・分析できます。
WordPress TIBCO DV Adapter のデプロイ
コンソールで、TDV Server のインストールディレクトリ内の bin フォルダに移動します。現在のバージョンのアダプターがインストールされている場合は、先にアンデプロイする必要があります。
.\server_util.bat -server localhost -user admin -password ******** -undeploy -version 1 -name WordPress
CData TIBCO DV Adapter をローカルフォルダに解凍し、解凍した場所から JAR ファイル(tdv.wordpress.jar)をサーバーにデプロイします。
.\server_util.bat -server localhost -user admin -password ******** -deploy -package /PATH/TO/tdv.wordpress.jar
新しい JAR ファイルが正しくロードされるように、サーバーの再起動が必要な場合があります。再起動は、C:\Program Files\TIBCO\TDV Server <version>\bin にある composite.bat スクリプトを実行して行えます。サーバーを再起動した後は、TDV Studio への再認証が必要です。
再起動コマンドの例
.\composite.bat monitor restart
OAuth を使用して WordPress で認証する
WordPress は OAuth プロトコルを使用して認証を行いますが、TDV Studio は内部でブラウザベースの認証をサポートしていないため、OAuth トークンを取得するための簡単な Java アプリケーションを作成して実行する必要があります。取得したトークンは、アダプターから直接 WordPress に接続するために使用されます。
Create the Java Application
- Create a new Java file with preferred name for example GenOAuthSettings.java. This Java file leverages the WordPressOAuth class contained within the TDV Adapter JAR to initiate a test connection and perform the required OAuth authentication flow
- Copy and insert the following code into the .java file:
- Place the .java file in the same directory as the tdv.wordpress.jar file. This is required to prevent classpath resolution errors during compilation and execution
public class GenOAuthSettings {
public static void main(String[] args) {
try {
if (args.length != 2) {
throw new Exception("Input must have two arguments: 'data source', 'connection string'");
}
String source = args[0].replace(" ", "").toLowerCase();
String connectionString = args[1];
String prefix;
if (source.equals("wordpress")) {
prefix = "jdbc:wordpress:";
com.cdata.cis.wordpress.WordPressOAuth oauth = new com.cdata.cis.wordpress.WordPressOAuth();
if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
oauth.generateOAuthSettingsFile(connectionString);
}
// More sources can be added below using the same format. You must add the import statement and ensure the jar file resides in the classpath
// else if (source.equals("googlebigquery") || source.equals("bigquery")) {
// prefix = "jdbc:googlebigquery:";
//
// com.cdata.cis.googlebigquery.GoogleBigQueryOAuth oauth = new com.cdata.cis.googlebigquery.GoogleBigQueryOAuth();
//
// if (!connectionString.startsWith(prefix)) connectionString = prefix + connectionString;
// oauth.generateOAuthSettingsFile(connectionString);
// }
else {
throw new Exception("Data Source not supported. Available Data Sources: WordPress");
}
System.out.println("Test Connection Successful!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Build and run the Java Application
- Open Console and navigate to the directory containing the .java file and adapter jar
- Compile the Java file using the following command:
- Execute the application using one of the following commands:
javac -cp .;tdv.wordpress.jar GenOAuthSettings.java
java -cp .;tdv.wordpress.jar GenOAuthSettings "WordPress" "connection string"
This command initiates the OAuth authentication flow and generates the OAuth settings file at the location specified in the OAuthSettingsLocation parameter. Once you deploy the adapter and authenticate, you can create a new data source for WordPress in TDV Studio.
TDV Studio で WordPress データソースを作成する
CData TIBCO DV Adapter for WordPress を使用すると、WordPress 用のデータソースを簡単に作成し、データソースをイントロスペクトしてリソースを TDV に追加できます。
データソースの作成
- データソースを追加するフォルダを右クリックし、New -> New Data Source を選択します。
- アダプター(例:WordPress)が表示されるまでスクロールし、Next をクリックします。
- データソースに名前を付けます(例:CData WordPress Source)。
必要な接続プロパティを入力します。
WordPress 接続プロパティの取得・設定方法
現時点では、CData JDBC Driver for WordPress はセルフホスト型のWordPress インスタンスへの接続のみをサポートしています。データに接続するには、Url を自身のwordpress サイトに指定し、次に以下に説明するように認証を行います。URL を完全な形式で記入します。例えば、あなたのサイトが'http://localhost/wp/wordpress' でホストされている場合、URL は'http://localhost' ではなく、'http://localhost/wp/wordpress' となるべきです。 URL を完全な形式で入力しないと、'site not found' というエラーが発生します。
WordPress は2種類の認証をサポートします。
- Basic 認証は、テスト環境での使用が推奨されます。
- OAuth 2.0 認証は、デスクトップアプリケーション、Web アプリケーション、またはヘッドレスマシンからのブラウザベースのアクセスをサポートします。
Basic 認証
Basic 認証を使用するようにWordPress を設定する前に:
- WordPress ログインに管理者権限があることを確認してください。
- ローカルホストで実行されているWordPress のバージョンを確認します。(WordPress 4.7 以降はネイティブでWordPress REST API サポートしていますが、それより前のバージョンでは、REST API へのアクセスを安全に行うには、Basic 認証プラグインの使用が必要です。)
- WordPress ホストにログインします。
- 4.7より前のバージョンのWordPress を実行している場合は、REST API プラグインをインストールしてください。
- Basic Authentication プラグインをインストールします。
- カスタムタクソノミーを作成するには、Simple Taxonomy Refreshed をインストールします。プラグインを手動でインストールしたい場合は、圧縮されたフォルダをwp-content\plugins フォルダに展開してからWordPress 管理者インターフェース経由でプラグインを有効にします。
- 次の接続プロパティを設定します。
- AuthScheme:Basic。
- Url:WordPress URL。
- User:ユーザーネーム。
- Password:パスワード。
NOTE:DV Adapter の OAuthSettingsLocation プロパティには、OAuth 認証(上記参照)を実行したときと同じ値を設定してください。
- Create & Close をクリックします。
データソースのイントロスペクト
データソースを作成したら、右クリックして Open を選択することでデータソースをイントロスペクトできます。ダッシュボードで Add/Remove Resources をクリックし、データソースの一部として含めるテーブル、ビュー、ストアドプロシージャを選択します。Next をクリックし、Finish をクリックして、選択した WordPress のテーブル、ビュー、ストアドプロシージャをリソースとして追加します。
After creating and introspecting the data source, you are ready to work with WordPress のデータ in TIBCO Data Virtualization just like you would any other relational data source. You can create views, query using SQL, publish the data source, and more.
データソースを作成してイントロスペクトしたら、他のリレーショナルデータソースと同様に TIBCO Data Virtualization でWordPress のデータを操作できるようになります。ビューの作成、SQL によるクエリ、データソースの公開など、さまざまな操作が可能です。