public TSStatus createTrigger(TCreateTriggerReq req) {
    final boolean isStateful = TriggerType.construct(req.getTriggerType()) == TriggerType.STATEFUL;
    TDataNodeLocation dataNodeLocation = null;
    if (isStateful) {
      Optional<TDataNodeLocation> targetDataNode =
          configManager.getNodeManager().getLowestLoadDataNode();
      if (targetDataNode.isPresent()) {
        dataNodeLocation = targetDataNode.get();
      } else {
        return new TSStatus(TSStatusCode.NO_ENOUGH_DATANODE.getStatusCode());
      }
    }
    final String triggerName = req.getTriggerName();
    final boolean isUsingURI = req.isIsUsingURI();
    final boolean needToSaveJar = isUsingURI && triggerInfo.needToSaveJar(triggerName);
    TriggerInformation triggerInformation =
        new TriggerInformation(
            (PartialPath) PathDeserializeUtil.deserialize(req.pathPattern),
            triggerName,
            req.getClassName(),
            isUsingURI,
            req.getJarName(),
            req.getAttributes(),
            TriggerEvent.construct(req.triggerEvent),
            TTriggerState.INACTIVE,
            isStateful,
            dataNodeLocation,
            FailureStrategy.construct(req.getFailureStrategy()),
            req.getJarMD5());
    return configManager
        .getProcedureManager()
        .createTrigger(
            triggerInformation,
            needToSaveJar ? new Binary(req.getJarFile()) : null,
            req.isSetIsGeneratedByPipe() && req.isIsGeneratedByPipe());
  }
Create a trigger in cluster.

<p>If TriggerType is STATELESS, we should create TriggerInstance on all DataNodes, the
DataNodeLocation in TriggerInformation will be null.

<p>If TriggerType is STATEFUL, we should create TriggerInstance on the DataNode with the lowest
load, and DataNodeLocation of this DataNode will be saved.

<p>All DataNodes will add TriggerInformation of this trigger in local TriggerTable.

@param req the createTrigger request
@return status of create this trigger
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/TriggerManager.java