private void instrumentAlert(WorkflowExecutionContext context) {
    String clusterName = context.getClusterName();
    String entityName = context.getEntityName();
    String entityType = context.getEntityType();
    String operation = context.getOperation().name();
    String workflowId = context.getWorkflowId();
    String workflowUser = context.getWorkflowUser();
    String nominalTime = context.getNominalTimeAsISO8601();
    String runId = String.valueOf(context.getWorkflowRunId());
    Date now = new Date();
    // Start and/or End time may not be set in case of workflow suspend
    Date endTime;
    if (context.getWorkflowEndTime() == 0) {
      endTime = now;
    } else {
      endTime = new Date(context.getWorkflowEndTime());
    }

    Date startTime;
    if (context.getWorkflowStartTime() == 0) {
      startTime = now;
    } else {
      startTime = new Date(context.getWorkflowStartTime());
    }
    Long duration = (endTime.getTime() - startTime.getTime()) * 1000000;

    if (context.hasWorkflowFailed()) {
      GenericAlert.instrumentFailedInstance(
          clusterName,
          entityType,
          entityName,
          nominalTime,
          workflowId,
          workflowUser,
          runId,
          operation,
          SchemaHelper.formatDateUTC(startTime),
          "",
          "",
          duration);
    } else {
      GenericAlert.instrumentSucceededInstance(
          clusterName,
          entityType,
          entityName,
          nominalTime,
          workflowId,
          workflowUser,
          runId,
          operation,
          SchemaHelper.formatDateUTC(startTime),
          duration);
    }
  }
Beispiel #2
0
  @Override
  // SUSPEND CHECKSTYLE CHECK ParameterNumberCheck
  public void handleRerun(
      String clusterName,
      String entityType,
      String entityName,
      String nominalTime,
      String runId,
      String wfId,
      String workflowUser,
      long msgReceivedTime) {
    try {
      Entity entity = EntityUtil.getEntity(entityType, entityName);
      Retry retry = getRetry(entity);

      if (retry == null) {
        LOG.warn(
            "Retry not configured for entity: {} ({}), ignoring failed retried",
            entityType,
            entity.getName());
        return;
      }

      int attempts = retry.getAttempts();
      Frequency delay = retry.getDelay();
      PolicyType policy = retry.getPolicy();
      int intRunId = Integer.parseInt(runId);

      if (attempts > intRunId) {
        AbstractRerunPolicy rerunPolicy = RerunPolicyFactory.getRetryPolicy(policy);
        long delayTime = rerunPolicy.getDelay(delay, Integer.parseInt(runId));
        RetryEvent event =
            new RetryEvent(
                clusterName,
                wfId,
                msgReceivedTime,
                delayTime,
                entityType,
                entityName,
                nominalTime,
                intRunId,
                attempts,
                0,
                workflowUser);
        offerToQueue(event);
      } else {
        LOG.warn(
            "All retry attempt failed out of configured: {} attempt for entity instance: {}:{} "
                + "And WorkflowId: {}",
            attempts,
            entityName,
            nominalTime,
            wfId);

        GenericAlert.alertRetryFailed(
            entityType,
            entityName,
            nominalTime,
            wfId,
            workflowUser,
            runId,
            "All retry attempt failed out of configured: "
                + attempts
                + " attempt for entity instance::");
      }
    } catch (FalconException e) {
      LOG.error("Error during retry of entity instance {}:{}", entityName, nominalTime, e);
      GenericAlert.alertRetryFailed(
          entityType, entityName, nominalTime, wfId, workflowUser, runId, e.getMessage());
    }
  }