IM-BPM for Accel Platform IM-BPM 仕様書 第17版 2023-10-01

4.12. Elasticsearch連携機能

Elasticsearchとの連携について説明します。

4.12.1. Elasticsearch連携について

Elasticsearchは、Elastic社が提供するオープンソース全文検索エンジンです。

Elasticsearchは、データをJSON形式で格納できます。
Elasticsearch連携では、プロセスインスタンスに関する情報をElasticsearchに保存する為の機能です。
保存されたデータは、Elastic社が提供するKibanaを利用することにより可視化する事ができます。
Elasticsearch連携ではプロセスインスタンスに含まれる変数情報も含めて全てElasticsearchに保存するため
業務プロセスで利用されている任意のデータを可視化できます。

4.12.2. Elasticsearch連携方式

Elasticsearchでは、TCP TransportとHTTPによる連携方式があります。
Elasticsearch連携は全てHTTPによるデータの登録を行います。

連携のタイミングは、プロセスの実行が完了する直前です。
Elasticsearchに対し、httpによるバルクリクエストを行います。
連携に失敗した場合、プロセスインスタンスの処理は継続します。

4.12.3. 登録されるデータ

登録されるデータ例:

{
  "_index": "im_bpm-default-20160725",
  "_type": "im_bpm",
  "_id": "AVYfNl7gDFByk9GXT5rc",
  "_score": null,
  "_source": {
    "source_activity_id": "servicetask1",
    "sequence_flow_id": "flow2",
    "type_activiti": "SEQUENCEFLOW_TAKEN",
    "target_activity_type": "endEvent",
    "source_activity_type": "serviceTask",
    "target_activity_id": "endevent1",
    "user_cd": "master",
    "process_definition_id": "service:1:8e28em7kuuyr2m7",
    "source_activity_name": "Service Task",
    "execution_id": "8e2ao18qwuztbm7",
    "process_instance_id": "8e2ao18qwuztbm7",
    "target_activity_behavior_class": "jp.co.intra_mart.activiti.engine.impl.bpmn.behavior.NoneEndEventActivityBehavior",
    "source_activity_behavior_class": "jp.co.intra_mart.activiti.engine.impl.bpmn.helper.ClassDelegate",
    "target_activity_name": "End",
    "time": "2016-07-25T08:21:12+0900",
    "variables": {
      "foo": "FOO",
      "bar": "BAR"
    }
  },
  "fields": {
    "time": [
      1469402472000
    ]
  },
  "sort": [
    1469402472000
  ]
}

4.12.4. 連携イベント

Elasticsearchに登録されるプロセス内のイベントデータは以下の種類が存在します。
  • アクティビティの開始: activity_started
  • アクティビティの完了: activity_completed
  • アクティビティのキャンセル: activity_cancelled
  • アクティビティに対するシグナルの受信: activity_signaled
  • アクティビティに対するメッセージの受信: activity_message_received
  • アクティビティに対するエラーの受信: activity_error_received
  • シーケンスフローによる遷移: sequenceflow_taken
  • ユーザタスクの作成: task_created
  • ユーザタスクに対する担当者の割当: task_assigned
  • ユーザタスクの完了: task_completed
  • プロセスインスタンスの開始: process_started
  • プロセスインスタンスの終了: process_completed
  • プロセスインスタンスのエラー終了: process_completed_with_error_end_event
  • プロセスインスタンスのキャンセル: process_cancelled
上記のイベントは設定ファイルによりそれぞれデータの登録の制御が可能です。
詳細は設定ファイルリファレンスを御覧ください。

以下のイベントは、プロセスインスタンスに含まれる変数情報も含めてElasticsearchに登録されます。
  • ユーザタスクの完了: taks_completed
  • プロセスインスタンスの開始: process_started
  • プロセスインスタンスの終了: process_completed
  • プロセスインスタンスのエラー終了: process_completed_with_error_end_event

4.12.5. インデックスのパターン

Elasticsearchに対してデータを登録する際、index, typeの指定が行えます。
設定ファイルに含めるindex, typeはプレースホルダを埋め込む事により動的に変更することが可能です。

例: im_bpm-${yyyyMMdd}

利用可能な置換文字は以下の通りです。
  • yyyyMMdd: 年月日
  • yyyyMM: 年月
  • yyyy: 年
  • MM: 月
  • dd: 日
  • tenantId: テナントID

4.12.6. インデックステンプレート例

Elasticsearchは、事前にindex templateを登録する必要があります。

index template例:

{
  "index_patterns" : "im_bpm-default-*",
  "mappings" : {
    "im_bpm" : {
      "properties" : {
        "type_activiti" : {
          "type" : "keyword"
        },
        "time" : {
          "type" : "date",
          "format" : "dateOptionalTime"
        },
        "user_cd" : {
          "type" : "keyword"
        },
        "user_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_definition_id" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_instance_id" : {
          "type" : "keyword"
        },
        "execution_id" : {
          "type" : "keyword"
        },
        "activity_id" : {
          "type" : "keyword"
        },
        "activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_type" : {
          "type" : "keyword"
        },
        "behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_cause" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_cause_activity_impl" : {
          "properties" : {
            "id" : {
              "type" : "keyword"
            },
            "async" : {
              "type" : "boolean"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "height" : {
              "type" : "long"
            },
            "scope" : {
              "type" : "boolean"
            },
            "width" : {
              "type" : "long"
            },
            "x" : {
              "type" : "long"
            },
            "y" : {
              "type" : "long"
            }
          }
        },
        "activity_cause_event_subscription_entity" : {
          "properties" : {
            "activity" : {
              "properties" : {
                "id" : {
                  "type" : "keyword"
                },
                "async" : {
                  "type" : "boolean"
                },
                "exclusive" : {
                  "type" : "boolean"
                },
                "height" : {
                  "type" : "long"
                },
                "scope" : {
                  "type" : "boolean"
                },
                "width" : {
                  "type" : "long"
                },
                "x" : {
                  "type" : "long"
                },
                "y" : {
                  "type" : "long"
                }
              }
            },
            "activityId" : {
              "type" : "keyword"
            },
            "created" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "eventName" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "eventType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "activity_cause_job_entity" : {
          "properties" : {
            "duedate" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "jobHandlerConfiguration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobHandlerType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "retries" : {
              "type" : "long"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "error_code" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "message_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "message_data" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "signal_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "signal_data" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "activity_duration" : {
          "type" : "long"
        },
        "nested_process_definition_id" : {
          "type" : "keyword"
        },
        "nested_process_instance_id" : {
          "type" : "keyword"
        },
        "process_cause" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "process_cause_activity_impl" : {
          "properties" : {
            "id" : {
              "type" : "keyword"
            },
            "async" : {
              "type" : "boolean"
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "height" : {
              "type" : "long"
            },
            "scope" : {
              "type" : "boolean"
            },
            "width" : {
              "type" : "long"
            },
            "x" : {
              "type" : "long"
            },
            "y" : {
              "type" : "long"
            }
          }
        },
        "process_cause_event_subscription_entity" : {
          "properties" : {
            "activity" : {
              "properties" : {
                "id" : {
                  "type" : "keyword"
                },
                "async" : {
                  "type" : "boolean"
                },
                "exclusive" : {
                  "type" : "boolean"
                },
                "failedJobRetryTimeCycleValue" : {
                  "type" : "text",
                  "fields" : {
                    "raw" : {
                      "type" :  "keyword"
                    }
                  }
                },
                "height" : {
                  "type" : "long"
                },
                "scope" : {
                  "type" : "boolean"
                },
                "width" : {
                  "type" : "long"
                },
                "x" : {
                  "type" : "long"
                },
                "y" : {
                  "type" : "long"
                }
              }
            },
            "activityId" : {
              "type" : "keyword"
            },
            "configuration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "created" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "eventName" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "eventType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "processDefinitionId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "keyword"
            }
          }
        },
        "process_cause_job_entity" : {
          "properties" : {
            "duedate" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "exceptionMessage" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "exclusive" : {
              "type" : "boolean"
            },
            "executionId" : {
              "type" : "keyword"
            },
            "id" : {
              "type" : "keyword"
            },
            "jobHandlerConfiguration" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobHandlerType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "jobType" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "lockExpirationTime" : {
              "type" :   "date",
              "format" : "epoch_millis"
            },
            "lockOwner" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            },
            "processDefinitionId" : {
              "type" : "keyword"
            },
            "processInstanceId" : {
              "type" : "keyword"
            },
            "retries" : {
              "type" : "long"
            },
            "revision" : {
              "type" : "long"
            },
            "tenantId" : {
              "type" : "text",
              "fields" : {
                "raw" : {
                  "type" :  "keyword"
                }
              }
            }
          }
        },
        "process_duration" : {
          "type" : "long"
        },
        "sequence_flow_id" : {
          "type" : "text"
        },
        "source_activity_id" : {
          "type" : "keyword"
        },
        "source_activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "source_activity_type" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "source_activity_behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_id" : {
          "type" : "keyword"
        },
        "target_activity_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_type" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "target_activity_behavior_class" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_id" : {
          "type" : "keyword"
        },
        "task_name" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_definition_key" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "description" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "assignee" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "owner" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "category" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "due_date" : {
          "type" : "date",
          "format" : "dateOptionalTime"
        },
        "form_key" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "priority" : {
          "type" : "text",
          "fields" : {
            "raw" : {
              "type" :  "keyword"
            }
          }
        },
        "task_duration" : {
          "type" : "long"
        }
      }
    }
  }
}

コラム

上記テンプレートに加えて、プロセスインスタンスで利用される変数 (variables) 配下のプロパティを個別に指定する必要があります。
変数(variables)配下に日付型の変数が存在する場合、Long値(エポックミリ秒)としてElasticsearchに登録されます。
そのため、日付型の変数項目に対しては、必要に応じて下記の例のようにマッピング定義を登録してください。
・・・
"variables" : {
    "properties" : {
        "dateVariable" : {
            "type":   "date",
            "format": "epoch_millis"
        }
    }
},
・・・

4.12.7. HTTP Proxy

Elasticsearchに対してHTTP Proxyが必要となる場合には、Proxyの指定をシステムプロパティで行います。

例:
httpの場合
-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=9080
httpsの場合
-Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=9080

利用されているアプリケーションサーバに対して設定を行ってください。
Resinの場合には、{RESIN_HOME}/conf/resin.properties に含まれる jvm_args プロパティに追記します。