com.streamsets.pipeline.api.ErrorCode Java Examples

The following examples show how to use com.streamsets.pipeline.api.ErrorCode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultErrorRecordHandler.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void validateGetOnErrorRecord(Exception ex, ErrorCode errorCode, Object ... params) {
  if(onRecordError == null) {
    if(ex != null) {
      LOG.error("Can't propagate exception to error stream", ex);
    }
    if(errorCode != null) {
      LOG.error("Can't propagate error to error stream: {} with params {}", errorCode, params);
    }

    // We throw "nicer" exception when this stage is in place of an error stage, otherwise generally sounding error
    if(context.isErrorStage()) {
      throw new IllegalStateException(Utils.format("Error stage {} itself generated error record, shutting pipeline down to prevent data loss.", context.getStageInfo().getInstanceName()));
    } else {
      throw new IllegalStateException(Utils.format("Component {} doesn't have configured error record action.", context.getStageInfo().getInstanceName()));
    }
  }
}
 
Example #2
Source File: TestRemoteDownloadSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
private void assertExceptionMessageContainsOnlyRemoteError(Exception e, ErrorCode... expected) {
  String msg = e.getMessage();
  for (ErrorCode errror : expected) {
    Assert.assertTrue("Expected exception to contain " + errror.getCode() + " but did not: " + msg,
        msg.contains(errror.getCode()));
  }
  List<String> foundErrors = new ArrayList<>();
  for (Errors error : Errors.values()) {
    if (!ArrayUtils.contains(expected, error) && msg.contains(error.getCode())) {
      foundErrors.add(error.getCode());
    }
  }
  if (!foundErrors.isEmpty()) {
    Assert.fail("Expected exception NOT to contain " + Arrays.toString(foundErrors.toArray()) + " but it did: "
        + msg);
  }
}
 
Example #3
Source File: ErrorMessage.java    From datacollector-api with Apache License 2.0 6 votes vote down vote up
public ErrorMessage(List<AntennaDoctorMessage> antennaDoctorMessages, String resourceBundle, ErrorCode errorCode, Object... params) {
  this.errorCode = Utils.checkNotNull(errorCode, "errorCode").getCode();
  if ( params != null && params.length > 0 && params[params.length-1] instanceof Throwable){
    stackTrace = toStackTrace((Throwable)params[params.length-1]);
  } else {
    stackTrace = null;
  }

  localizableMessage = new LocalizableMessage(
      errorCode.getClass().getClassLoader(),
      resourceBundle,
      errorCode.getCode(),
      errorCode.getMessage(),
      (params != null) ? params : NULL_ONE_ARG
  );
  timestamp = System.currentTimeMillis();
  preppendErrorCode = true;
  this.antennaDoctorMessages = Collections.unmodifiableList(antennaDoctorMessages);
}
 
Example #4
Source File: ELUtils.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Deprecated
public static void validateExpression(
    ELEval elEvaluator,
    ELVars variables,
    String expression,
    Stage.Context context,
    String group,
    String config,
    ErrorCode err,
    Class<?> type,
    List<Stage.ConfigIssue> issues
) {
  validateExpression(expression, context, group, config, err, issues);
  try {
    context.parseEL(expression);
  } catch (Exception ex) {
    issues.add(context.createConfigIssue(group, config, err, expression, ex.toString(), ex));
  }
}
 
Example #5
Source File: TestBigQueryDelegate.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test(expected = StageException.class)
public void runQueryTimeout() throws Exception {
  QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder("SELECT * FROM [sample:table] LIMIT 1000")
      .setUseQueryCache(true)
      .setUseLegacySql(useLegacySql)
      .build();

  TableResult mockQueryResponse = mock(TableResult.class);
  Job mockJob = mock(Job.class);
  JobStatus mockJobStatus = mock(JobStatus.class);

  // First pretend we haven't finished running the query, second time around its completed.
  when(mockJob.isDone()).thenReturn(false).thenReturn(true);
  when(mockJob.getJobId()).thenReturn(jobId);
  when(mockJobStatus.getError()).thenReturn(null);
  when(mockJob.getStatus()).thenReturn(mockJobStatus);

  when(mockBigquery.create((JobInfo)any())).thenReturn(mockJob);
  when(mockBigquery.cancel(jobId)).thenReturn(true);
  when(mockJob.getQueryResults()).thenReturn(mockQueryResponse);

  BigQueryDelegate delegate = new BigQueryDelegate(
      mockBigquery,
      useLegacySql,
      Clock.offset(Clock.systemDefaultZone(), Duration.ofSeconds(2))
  );

  ErrorCode code = null;
  try {
    delegate.runQuery(queryConfig, 1000, 1000);
  } catch (StageException e) {
    code = e.getErrorCode();
    throw e;
  } finally {
    assertEquals(Errors.BIGQUERY_00, code);
  }
}
 
Example #6
Source File: BatchContextImpl.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void toError(Record record, ErrorCode errorCode, Object... args) {
  Preconditions.checkNotNull(record, "record cannot be null");
  Preconditions.checkNotNull(errorCode, "errorId cannot be null");
  // the last args needs to be Exception in order to show stack trace
  toError(record, new ErrorMessage(errorCode, args));
}
 
Example #7
Source File: TestWholeFileDataParserFactory.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void getParserWithInvalidMetadata(
    FileRef fileRef,
    Map<String, Object> metadata,
    DataParserFactory dataParserFactory,
    ErrorCode errorCode
) {
  try {
    dataParserFactory.getParser("id", metadata, fileRef);
    Assert.fail("getParser should fail for missing mandatory metadata");
  } catch (DataParserException e) {
    Assert.assertEquals(errorCode, e.getErrorCode());
  }
}
 
Example #8
Source File: JdbcBaseRunnable.java    From datacollector with Apache License 2.0 5 votes vote down vote up
/**
 * Handle Exception
 */
private void handleStageError(ErrorCode errorCode, Exception e) {
  String errorMessage = (e instanceof SQLException)? jdbcUtil.formatSqlException((SQLException)e) : "Failure Happened";
  LOG.error(errorMessage, e);

  try {
    errorRecordHandler.onError(errorCode, e);
  } catch (StageException se) {
    LOG.error("Error when routing to stage error", se);
    //Way to throw stage exception from runnable to main source thread
    Throwables.propagate(se);
  }
}
 
Example #9
Source File: CredentialStoresTaskImpl.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected CredentialStore.Context createContext(
    String storeId,
    Configuration storeConfig
) {
  return new CredentialStore.Context() {
    @Override
    public String getId() {
      return storeId;
    }

    @Override
    public CredentialStore.ConfigIssue createConfigIssue(
        ErrorCode errorCode, Object... args
    ) {
      return new CredentialStore.ConfigIssue() {
        @Override
        public String toString() {
          return Utils.format(
              "{} - Store ID '{}', ",
              errorCode.toString(),
              Utils.format(errorCode.getMessage(), args)
          );
        }
      };
    }

    @Override
    public String getConfig(String configName) {
      return storeConfig.get("credentialStore." + storeId + ".config." + configName, null);
    }

    @Override
    public String getStreamSetsConfigDir() {
      return runtimeInfo.getConfigDir();
    }
  };
}
 
Example #10
Source File: StageContext.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public ErrorMessage produceErrorMessage(ErrorCode errorCode, Object ...args) {
  List<AntennaDoctorMessage> messages = Collections.emptyList();
  if(antennaDoctor != null) {
    messages = antennaDoctor.onStage(antennaDoctorContext, errorCode, args);
  }

  return new ErrorMessage(messages, errorCode, args);
}
 
Example #11
Source File: HiveMetadataProcessor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void validateTemplate(String template, String configName, ErrorCode errorCode, List<ConfigIssue> issues){
  if (template == null || template.isEmpty()){
    issues.add(getContext().createConfigIssue(
        Groups.HIVE.name(),
        template,
        errorCode,
        configName
    ));
  }
}
 
Example #12
Source File: TestTCPServerSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private static void initSourceAndValidateIssues(TCPServerSourceConfig configBean, ErrorCode... errorCodes) throws
    StageException {

  List<Stage.ConfigIssue> issues = initSourceAndGetIssues(configBean);
  assertThat(issues, hasSize(errorCodes.length));
  for (int i = 0; i < errorCodes.length; i++) {
    assertThat(issues.get(i).toString(), containsString(errorCodes[i].getCode()));
  }
}
 
Example #13
Source File: StageContext.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void toError(Record record, ErrorCode errorCode, Object... args) {
  Preconditions.checkNotNull(record, "record cannot be null");
  Preconditions.checkNotNull(errorCode, "errorId cannot be null");

  if(statsCollector != null) {
    statsCollector.errorCode(errorCode);
  }

  // the last args needs to be Exception in order to show stack trace
  toError(record, new ErrorMessage(errorCode, args));
}
 
Example #14
Source File: BaseTableJdbcSourceIT.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected static void validateAndAssertConfigIssue(
    TableJdbcSource tableJdbcSource,
    ErrorCode expectedErrorCode,
    String expectedInErrorMessage
) throws StageException {

  PushSourceRunner runner = new PushSourceRunner.Builder(TableJdbcDSource.class, tableJdbcSource)
      .addOutputLane("a")
      .setOnRecordError(OnRecordError.TO_ERROR)
      .build();
  List<Stage.ConfigIssue> configIssues = runner.runValidateConfigs();
  if (expectedErrorCode == null) {
    assertThat(configIssues, hasSize(0));
  } else {
    assertThat(configIssues, hasSize(1));
    Stage.ConfigIssue issue = configIssues.get(0);

    final ErrorMessage errorMsg = (ErrorMessage) Whitebox.getInternalState(issue, "message");
    assertThat(errorMsg, notNullValue());
    Assert.assertEquals(
        expectedErrorCode.getCode(),
        errorMsg.getErrorCode()
    );

    if (expectedInErrorMessage != null) {
      assertThat(errorMsg.getLocalized(), containsString(expectedInErrorMessage));
    }
  }
}
 
Example #15
Source File: TestRemoteLocationExecutor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private void runWriteWithException(ExecutorRunner executor, List<Record> records, ErrorCode... expected) {
  try {
    executor.runWrite(records);
    Assert.fail("Expected a StageException");
  } catch (StageException e) {
    assertExceptionMessageContainsOnlyRemoteError(e, expected);
  }
}
 
Example #16
Source File: AntennaDoctor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public List<AntennaDoctorMessage> onValidation(AntennaDoctorStageContext context, String groupName, String configName, ErrorCode errorCode, Object... args) {
  AntennaDoctorEngine engine = this.engine;
  if(engine != null) {
    return engine.onValidation(context, groupName, configName, errorCode, args);
  }

  return Collections.emptyList();
}
 
Example #17
Source File: AntennaDoctor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public List<AntennaDoctorMessage> onRest(ErrorCode errorCode, Object... args) {
  AntennaDoctorEngine engine = this.engine;
  if(engine != null) {
    return engine.onRest(getContext(), errorCode, args);
  }

  return Collections.emptyList();
}
 
Example #18
Source File: StageContext.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void reportError(ErrorCode errorCode, Object... args) {
  Preconditions.checkNotNull(errorCode, "errorId cannot be null");
  if(statsCollector != null) {
    statsCollector.errorCode(errorCode);
  }
  reportErrorDelegate.reportError(stageInfo.getInstanceName(), produceErrorMessage(errorCode, args));
}
 
Example #19
Source File: TestBigQueryDelegate.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test(expected = StageException.class)
public void runQueryHasErrors() throws Exception {
  QueryJobConfiguration queryRequest = QueryJobConfiguration.newBuilder("SELECT * FROM [sample:table] LIMIT 1000")
      .setUseQueryCache(true)
      .setUseLegacySql(useLegacySql)
      .build();

  TableResult mockQueryResponse = mock(TableResult.class);
  Job mockJob = mock(Job.class);
  JobStatus mockJobStatus = mock(JobStatus.class);

  // First pretend we haven't finished running the query, second time around its completed.
  when(mockJob.isDone()).thenReturn(true);
  when(mockJob.getJobId()).thenReturn(jobId);

  when(mockJob.getQueryResults()).thenReturn(mockQueryResponse);
  when(mockJobStatus.getError()).thenReturn(new BigQueryError(
      "Some Error",
      "Some Location",
      "Some Error Message"
  ));
  when(mockJob.getStatus()).thenReturn(mockJobStatus);

  when(mockBigquery.create((JobInfo)any())).thenReturn(mockJob);
  when(mockBigquery.cancel(jobId)).thenReturn(true);

  BigQueryDelegate delegate = new BigQueryDelegate(mockBigquery, useLegacySql);

  ErrorCode code = null;
  try {
    delegate.runQuery(queryRequest, 1000, 1000);
  } catch (StageException e) {
    code = e.getErrorCode();
    throw e;
  } finally {
    assertEquals(Errors.BIGQUERY_02, code);
  }
}
 
Example #20
Source File: SolrTarget.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected ConfigIssue createSolrConfigIssue(String configName, ErrorCode errorMessage, Object... objects) {
  return getContext().createConfigIssue(
      Groups.SOLR.name(),
      configName,
      errorMessage,
      objects
  );
}
 
Example #21
Source File: AntennaDoctor.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public List<AntennaDoctorMessage> onStage(AntennaDoctorStageContext context, ErrorCode errorCode, Object... args) {
  AntennaDoctorEngine engine = this.engine;
  if(engine != null) {
    return engine.onStage(context, errorCode, args);
  }

  return Collections.emptyList();
}
 
Example #22
Source File: AntennaDoctorEngine.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public List<AntennaDoctorMessage> onValidation(AntennaDoctorStageContext context, String groupName, String configName, ErrorCode errorCode, Object... args) {
  JexlContext jexlContext = new MapContext();
  jexlContext.set("issue", new StageIssueJexl(groupName, configName, errorCode, args));
  jexlContext.set("stageDef", context.getStageDefinition());
  jexlContext.set("stageConf", context.getStageConfiguration());
  return evaluate(context, AntennaDoctorRuleBean.Entity.VALIDATION, jexlContext);
}
 
Example #23
Source File: AbstractCommand.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected CredentialStore.Context createContext(Configuration configuration, String confDir) {
  return new CredentialStore.Context() {
    @Override
    public String getId() {
      return storeId;
    }

    @Override
    public CredentialStore.ConfigIssue createConfigIssue(ErrorCode errorCode, Object... args) {
      return new CredentialStore.ConfigIssue() {
        @Override
        public String toString() {
          return errorCode.toString() + " - " + Utils.format(errorCode.getMessage(), args);
        }
      };
    }

    @Override
    public String getConfig(String configName) {
      return configuration.get("credentialStore." + storeId + ".config." + configName, null);
    }

    @Override
    public String getStreamSetsConfigDir() {
      return confDir;
    }
  };
}
 
Example #24
Source File: StageIssueJexl.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public StageIssueJexl(String groupName, String configName, ErrorCode errorCode, Object ...args) {
  this.exception = null;
  this.errorMessage = null;
  this.errorCode = errorCode;
  this.args = Arrays.asList(args);
  this.groupName = groupName;
  this.configName = configName;
}
 
Example #25
Source File: SpoolDirRunnable.java    From datacollector with Apache License 2.0 5 votes vote down vote up
/**
 * Handle Exception
 */
private void handleStageError(ErrorCode errorCode, Exception e) {
  final String errorMessage = "Failure Happened";
  LOG.error(errorMessage, e);
  try {
    errorRecordHandler.onError(errorCode, e);
  } catch (StageException se) {
    LOG.error("Error when routing to stage error", se);
    //Way to throw stage exception from runnable to main source thread
    Throwables.propagate(se);
  }
}
 
Example #26
Source File: StageIssueJexl.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public StageIssueJexl(ErrorCode errorCode, Object ...args) {
  this.exception = null;
  this.errorMessage = null;
  this.errorCode = errorCode;
  this.args = Arrays.asList(args);
  this.groupName = null;
  this.configName = null;
}
 
Example #27
Source File: Issue.java    From datacollector with Apache License 2.0 5 votes vote down vote up
protected Issue(String instanceName, String serviceName, String configGroup, String configName, ErrorCode error, Object... args) {
  this.instanceName = instanceName;
  this.serviceName = serviceName;
  this.configGroup = configGroup;
  this.configName = configName;
  this.count = 1;
  message = new ErrorMessage(error, args);
}
 
Example #28
Source File: AmazonS3Runnable.java    From datacollector with Apache License 2.0 5 votes vote down vote up
/**
 * Handle Exception
 */
private void handleStageError(ErrorCode errorCode, Exception e) {
  final String errorMessage = "A failure occurred";
  LOG.error(errorMessage, e);
  try {
    errorRecordHandler.onError(errorCode, e);
  } catch (StageException se) {
    LOG.error("Error when routing to stage error", se);
    //Way to throw stage exception from runnable to main source thread
    Throwables.propagate(se);
  }
}
 
Example #29
Source File: ProtoContext.java    From datacollector with Apache License 2.0 5 votes vote down vote up
public ConfigIssueImpl(
    String stageName,
    String serviceName,
    String configGroup,
    String configName,
    ErrorCode errorCode,
    Object... args
) {
  super(stageName, serviceName, configGroup, configName, errorCode, args);
}
 
Example #30
Source File: DataParserException.java    From datacollector with Apache License 2.0 4 votes vote down vote up
public DataParserException(ErrorCode errorCode, Object... params) {
  super(errorCode, params);
}