履歴の未加工および集約された時系列コンテキスト情報の移行

STH コンポーネントは、過去の未加工および集約された時系列のコンテキスト情報をデータベースに格納するときに、3つの代替データモデルをサポートします :

  1. サービスパスごとに1つのコレクション
  2. エンティティごとに1つのコレクション
  3. 属性ごとに1つのコレクション

名前が示すように、サポートされているデータモデルのそれぞれは、サービスパス、エンティティ、または属性ごとに1つのコレクションに未加工と集約された時系列コンテキスト情報をそれぞれ格納します。

デフォルトのデータモデルは、エンティティごとのコレクションですが、未加工と集約された時系列コンテキスト情報が格納されている MongoDB データベースから最高のパフォーマンスを得るために、代替データモデルが必要です。これがデータモデル移行ツールを導入した理由です。

使用するデータモデルを設定するには、以下の STH サーバの実行をご覧ください。

データ移行ツールを実行するには、次のコマンドを実行してください :

./bin/sthDatabaseModelTool

これはコマンドのヘルプ情報を表示します :

Usage: sthDatabaseModelTool [options]

  Options:

    -h, --help                         output usage information
    -V, --version                      output the version number
    -a, --analysis                     prints the results of the data model analysis including the databases and collections which need to be migrated to the currently configured data model (mandatory if not -m or --migrate)
    -m, --migrate                      migrates to the currently configured data model all the databases and collections which has been created using a distinct data model (mandatory if not -a or --analysis)
    -v, --verbose [documents]          shows migration progress information if the number of documents to migrate in the collection is bigger or equal to the optional value passed (1 if no value passed)
    -r, --remove-collection            the original data model collection will be removed to avoid conflict if migrating back to that data model in the future
    -u, --update-collection            the migration will take place even if the target collections already exist combining the data of the original and target collections (use this option with special care since the migration operation is not idempotent for the aggregated data collections)
    -f, --full                         the migration will continue with the pending collections in case a previous collection throws an error and cannot be migrated (it is recommended to be used with the -r option to avoid subsequent  migrations of the same aggregated data collections)
    -d, --database <databaseName>      only this database will be taken into consideration for the analysis and/or migration process
    -c, --collection <collectionName>  only this collection will be taken info consideration, a database is mandatory if a collection is set
    -x, --dictionary <dictionary>      the path to a file including a dictionary to resolve the names of the collections to be migrated to their associated data (i.e., service path, entity id, entity type, attribute name and attribute type) (it is expected as a CSV file with lines including the following info: <collection-name>,<service-path>,<entity-id>,<entity-type>,<attribute-name>,<attribute-type>, some of which may not apply and can be left as blank)

ターゲット・データ・モデル・コレクションがすでに存在する場合、集約された時系列コンテキスト情報のマイグレーションは偶発的な操作ではないため、データ・モデルのマイグレーションを要求するときには特別な注意が必要です。この場合、これらのコレクションに格納されている既存のデータは、移行が保留されている元のデータモデルコレクションに格納されているデータと結合されます。この事実に基づいて、データモデルの移行を検討する際に次の手順を提案します :

  1. 以下の STH サーバの実行で説明されているオプションに基づいて、STH コンポーネントが使用する現在の構成済みデータモデルを確認します。通常は、エンティティ・データモデルごとのデフォルト・コレクションになります。
  2. 次のコマンドを実行して、新しい希望するデータ・モデル (DATA_MODEL 環境変数で設定)に移行する必要があるデータベースおよびコレクションに関するデータ・モデル分析レポートを取得します :
    LOGOPS_FORMAT=dev DATA_MODEL=collection-per-service-path ./bin/sthDatabaseModelTool -a
  3. 次のコマンドを実行しているターゲット・データ・モデル・コレクションの更新を強制することなく、目的のデータ・モデルのマイグレーション (DATA_MODEL 環境変数で設定)を要求します :
    LOGOPS_FORMAT=dev DATA_MODEL=collection-per-service-path ./bin/sthDatabaseModelTool -a -m
    ターゲット・コレクションのいずれかがすでに存在する場合、データ・モデルのマイグレーションは停止し、それ以降の収集のために既存のターゲット・データ・モデルの最初のコレクションに対しては行われません。ターゲットコレクションがすでに存在しない場合、データモデルの移行は正常に完了します。
    1. データモデルの移行が正常に完了した場合は、元のデータモデルに戻すことを決定した場合、問題を回避するために既に移行した元のデータモデルコレクションを削除します。 正常に移行されたコレクションに関する情報は、ログに提供されます。 ポイント3で説明したコマンドを実行するときに -r オプションを設定すると、この削除が自動的に行われます。これでデータモデルの移行は正常に終了しました。
    2. ターゲット・データ・モデル・コレクションのいずれかがすでに存在するため、データ・モデルのマイグレーションが正常に完了しなかった場合は :
      1. 正常にマイグレーションされた元のデータ・モデル・コレクションがあれば削除して、将来マイグレーションされないようにします。マイグレーションされたコレクションについての詳細はログに含まれています。-r オプションは、ポイント3で述べたコマンドを実行するときに自動的にこの削除を行います。
      2. 競合の原因となるターゲット・データモデル・コレクションに貴重なデータが含まれているかどうかを判断する必要があります。 もしそうなら、ただそれを保ってください。 そうでない場合は、削除してください。
      3. 貴重なデータが含まれているため、ターゲット・データモデル・コレクションに競合が発生した場合は、次のコマンドを使用してデータ・モデルの移行を強制してください :
        LOGOPS_FORMAT=dev DATA_MODEL=collection-per-service-path ./bin/sthDatabaseModelTool -a -m -d <database_name> -c <original_data_model_collection_to_be_migrated> -u
        元のデータモデル・コレクションは、ターゲット・データモデル・コレクションに格納されている既存のデータと結合されます
      4. 強制移行したばかりの <original_data_model_collection_to_be_migrated> コレクションを削除して、後で再度移行されないようにするか、-r を使用して移行ツールでこの削除を実行させます
  4. ポイント3から戻り繰り返します

現在サポートされている唯一のデータモデル・マイグレーションは、エンティティ・データモデルごとのデフォルト・コレクションと、サービスパス・データモデルごとのコレクションです。