Search in sources :

Example 1 with RejectedThread

use of com.sequenceiq.periscope.model.RejectedThread in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method testCreateWhenClusterId.

@Test
public void testCreateWhenClusterId() {
    Long data = 1L;
    EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(data));
    underTest.create(task);
    List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertFalse(allRejectedCluster.isEmpty());
    Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor) Test(org.junit.Test)

Example 2 with RejectedThread

use of com.sequenceiq.periscope.model.RejectedThread in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method testCreateWhenClusterIdCountEqualsTwo.

@Test
public void testCreateWhenClusterIdCountEqualsTwo() {
    Long data = 1L;
    EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(data));
    underTest.create(task);
    underTest.create(task);
    List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertFalse(allRejectedCluster.isEmpty());
    Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
    Assert.assertEquals(2L, allRejectedCluster.get(0).getRejectedCount());
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor) Test(org.junit.Test)

Example 3 with RejectedThread

use of com.sequenceiq.periscope.model.RejectedThread in project cloudbreak by hortonworks.

the class RejectedThreadServiceTest method testCreateWhenAutoscaleStackResponse.

@Test
public void testCreateWhenAutoscaleStackResponse() {
    AutoscaleStackV4Response response = new AutoscaleStackV4Response();
    response.setStackId(1L);
    EvaluatorExecutor task = new TestEvaluatorExecutor(getContext(response));
    underTest.create(task);
    List<RejectedThread> allRejectedCluster = underTest.getAllRejectedCluster();
    Assert.assertFalse(allRejectedCluster.isEmpty());
    Assert.assertEquals(1L, allRejectedCluster.get(0).getId());
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response) EvaluatorExecutor(com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor) Test(org.junit.Test)

Example 4 with RejectedThread

use of com.sequenceiq.periscope.model.RejectedThread in project cloudbreak by hortonworks.

the class RejectedThreadService method createOrUpdateRejectedThread.

private RejectedThread createOrUpdateRejectedThread(Object data, Long id) {
    RejectedThread rejectedThread = findById(id);
    if (rejectedThread == null) {
        rejectedThread = new RejectedThread();
        rejectedThread.setRejectedCount(1L);
        rejectedThread.setId(id);
        rejectedThread.setJson(writeValueAsStringSilent(data));
    } else {
        rejectedThread.setRejectedCount(rejectedThread.getRejectedCount() + 1L);
    }
    return rejectedThread;
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread)

Example 5 with RejectedThread

use of com.sequenceiq.periscope.model.RejectedThread in project cloudbreak by hortonworks.

the class RejectedThreadService method create.

public void create(EvaluatorExecutor task) {
    Object data = task.getContext().getData();
    RejectedThread rejectedThread;
    if (data instanceof AutoscaleStackV4Response) {
        Long stackId = ((AutoscaleStackV4Response) data).getStackId();
        rejectedThread = createOrUpdateRejectedThread(data, stackId);
    } else if (data instanceof Long) {
        rejectedThread = createOrUpdateRejectedThread(Collections.singletonMap("id", data), (Long) data);
    } else {
        throw new IllegalArgumentException("The given data is not match to AutoscaleStackResponse or Long, not possible to create");
    }
    LOGGER.debug("Rejected task: {}, count: {}", rejectedThread.getJson(), rejectedThread.getRejectedCount());
    rejectedThread.setType(task.getClass().getName());
    save(rejectedThread);
}
Also used : RejectedThread(com.sequenceiq.periscope.model.RejectedThread) AutoscaleStackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)

Aggregations

RejectedThread (com.sequenceiq.periscope.model.RejectedThread)9 EvaluatorExecutor (com.sequenceiq.periscope.monitor.evaluator.EvaluatorExecutor)6 Test (org.junit.Test)6 AutoscaleStackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.AutoscaleStackV4Response)4