Search in sources :

Example 1 with EvaluatorContext

use of com.sequenceiq.periscope.monitor.context.EvaluatorContext in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method getContext.

private EvaluatorContext getContext(Object data) {
    EvaluatorContext context = mock(EvaluatorContext.class);
    when(context.getData()).thenReturn(data);
    return context;
}
Also used : EvaluatorContext(com.sequenceiq.periscope.monitor.context.EvaluatorContext)

Example 2 with EvaluatorContext

use of com.sequenceiq.periscope.monitor.context.EvaluatorContext in project cloudbreak by hortonworks.

the class AbstractMonitorTest method getMonitor.

private AbstractMonitor getMonitor() {
    return new AbstractMonitor() {

        @Override
        protected List getMonitored() {
            return Arrays.asList(monitored);
        }

        @Override
        protected void save(Monitored monitored) {
        }

        @Override
        public String getIdentifier() {
            return null;
        }

        @Override
        public String getTriggerExpression() {
            return null;
        }

        @Override
        public Class<?> getEvaluatorType(Monitored monitored) {
            return TestExecutor.class;
        }

        @Override
        public EvaluatorContext getContext(Monitored monitored) {
            EvaluatorContext evaluatorContext = mock(EvaluatorContext.class);
            when(evaluatorContext.getItemId()).thenReturn(CLUSTER_ID);
            when(evaluatorContext.getData()).thenReturn(CLUSTER_ID);
            return evaluatorContext;
        }
    };
}
Also used : EvaluatorContext(com.sequenceiq.periscope.monitor.context.EvaluatorContext)

Example 3 with EvaluatorContext

use of com.sequenceiq.periscope.monitor.context.EvaluatorContext in project cloudbreak by hortonworks.

the class AbstractMonitor method execute.

@Override
public void execute(JobExecutionContext context) {
    MDCBuilder.buildMdcContext();
    evalContext(context);
    List<M> monitoredData = getMonitored();
    LOGGER.debug("Job started: {}, monitored: {}", context.getJobDetail().getKey(), monitoredData.size());
    for (M monitored : monitoredData) {
        try {
            EvaluatorExecutor evaluatorExecutor = getEvaluatorExecutorBean(monitored);
            EvaluatorContext evaluatorContext = getContext(monitored);
            evaluatorExecutor.setContext(evaluatorContext);
            executorServiceWithRegistry.submitIfAbsent(evaluatorExecutor, evaluatorContext.getItemId());
            // TODO CB-14972: The size of the queue needs to be logged occasionally.
            LOGGER.debug("Successfully submitted {} for cluster {}.", evaluatorExecutor.getName(), evaluatorContext.getData());
            rejectedThreadService.remove(evaluatorContext.getData());
            monitored.setLastEvaluated(System.currentTimeMillis());
            save(monitored);
        } catch (RejectedExecutionException ignore) {
            LOGGER.info("Error in processing monitor: {}", monitored, ignore);
        }
    }
}
Also used : EvaluatorContext(com.sequenceiq.periscope.monitor.context.EvaluatorContext) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor)

Aggregations

EvaluatorContext (com.sequenceiq.periscope.monitor.context.EvaluatorContext)3 EvaluatorExecutor (com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1