Search in sources :

Example 1 with State

use of org.apache.mesos.state.State in project cassandra-mesos-deprecated by mesosphere.

the class PersistedCassandraClusterHealthCheckHistoryTest method testRecord.

@Test
public void testRecord() throws Exception {
    final State state = new InMemoryState();
    final PersistedCassandraClusterHealthCheckHistory hcHistory = new PersistedCassandraClusterHealthCheckHistory(state);
    final String exec1 = "exec1";
    final CassandraFrameworkProtos.NodeInfo.Builder ni = CassandraFrameworkProtos.NodeInfo.newBuilder().setClusterName("cluster").setDataCenter("dc1").setUptimeMillis(1);
    final CassandraFrameworkProtos.HealthCheckDetails.Builder hc = CassandraFrameworkProtos.HealthCheckDetails.newBuilder().setHealthy(true).setInfo(ni.build());
    hcHistory.record(exec1, 1L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce1 = hcHistory.last(exec1);
    assertNotNull(hce1);
    assertThat(hcHistory.entries()).hasSize(1).contains(hce1);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(1).contains(hce1);
    assertEquals(1L, hce1.getTimestampStart());
    assertEquals(1L, hce1.getTimestampEnd());
    // just increase uptime
    hc.setInfo(ni.setUptimeMillis(2).build());
    hcHistory.record(exec1, 2L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce2 = hcHistory.last(exec1);
    assertNotNull(hce2);
    assertThat(hcHistory.entries()).hasSize(1).contains(hce2);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(1).contains(hce2);
    assertEquals(1L, hce2.getTimestampStart());
    assertEquals(2L, hce2.getTimestampEnd());
    // toggle a field
    hc.setInfo(ni.setNativeTransportRunning(true).build());
    hcHistory.record(exec1, 3L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce3 = hcHistory.last(exec1);
    assertNotNull(hce3);
    assertThat(hcHistory.entries()).hasSize(2).contains(hce2).contains(hce3);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(2).contains(hce2).contains(hce3);
    assertEquals(3L, hce3.getTimestampStart());
    assertEquals(3L, hce3.getTimestampEnd());
    // toggle more fields and record
    hc.setInfo(ni.setNativeTransportRunning(false).setRpcServerRunning(true).build());
    hcHistory.record(exec1, 4L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce4 = hcHistory.last(exec1);
    assertThat(hcHistory.entries()).hasSize(3);
    hc.setInfo(ni.setNativeTransportRunning(true).setRpcServerRunning(true).build());
    hcHistory.record(exec1, 5L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce5 = hcHistory.last(exec1);
    assertThat(hcHistory.entries()).hasSize(4);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(4).contains(hce2).contains(hce3).contains(hce4).contains(hce5);
    hc.setHealthy(true).setMsg("msg");
    hcHistory.record(exec1, 6L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce6 = hcHistory.last(exec1);
    assertThat(hcHistory.entries()).hasSize(5);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(5).contains(hce2).contains(hce3).contains(hce4).contains(hce5).contains(hce6);
    hc.setHealthy(false).setMsg("foo");
    hcHistory.record(exec1, 7L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce7 = hcHistory.last(exec1);
    assertThat(hcHistory.entries()).hasSize(5);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(5).doesNotContain(hce2).contains(hce3).contains(hce4).contains(hce5).contains(hce6).contains(hce7);
    hc.setHealthy(true).clearMsg();
    hcHistory.record(exec1, 8L, hc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry hce8 = hcHistory.last(exec1);
    assertThat(hcHistory.entries()).hasSize(5);
    assertThat(hcHistory.entriesForExecutor(exec1)).hasSize(5).doesNotContain(hce2).doesNotContain(hce3).contains(hce4).contains(hce5).contains(hce6).contains(hce7).contains(hce8);
    // 
    // similar for another executor
    // 
    final String exec2 = "exec2";
    final CassandraFrameworkProtos.NodeInfo.Builder otherNi = CassandraFrameworkProtos.NodeInfo.newBuilder().setClusterName("cluster").setDataCenter("dc1").setUptimeMillis(1);
    final CassandraFrameworkProtos.HealthCheckDetails.Builder otherHc = CassandraFrameworkProtos.HealthCheckDetails.newBuilder().setHealthy(true).setInfo(otherNi.build());
    hcHistory.record(exec2, 1L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce1 = hcHistory.last(exec2);
    assertNotNull(otherHce1);
    assertThat(hcHistory.entries()).hasSize(6).contains(otherHce1).doesNotContain(hce2).doesNotContain(hce3).contains(hce4).contains(hce5).contains(hce6).contains(hce7).contains(hce8);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(1).contains(otherHce1);
    assertEquals(1L, otherHce1.getTimestampStart());
    assertEquals(1L, otherHce1.getTimestampEnd());
    // just increase uptime
    otherHc.setInfo(otherNi.setUptimeMillis(2).build());
    hcHistory.record(exec2, 2L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce2 = hcHistory.last(exec2);
    assertNotNull(otherHce2);
    assertThat(hcHistory.entries()).hasSize(6).contains(otherHce2);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(1).contains(otherHce2);
    assertEquals(1L, otherHce2.getTimestampStart());
    assertEquals(2L, otherHce2.getTimestampEnd());
    // toggle a field
    otherHc.setInfo(otherNi.setNativeTransportRunning(true).build());
    hcHistory.record(exec2, 3L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce3 = hcHistory.last(exec2);
    assertNotNull(otherHce3);
    assertThat(hcHistory.entries()).hasSize(7).contains(otherHce2).contains(otherHce3);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(2).contains(otherHce2).contains(otherHce3);
    assertEquals(3L, otherHce3.getTimestampStart());
    assertEquals(3L, otherHce3.getTimestampEnd());
    // toggle more fields and record
    otherHc.setInfo(otherNi.setNativeTransportRunning(false).setRpcServerRunning(true).build());
    hcHistory.record(exec2, 4L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce4 = hcHistory.last(exec2);
    assertThat(hcHistory.entries()).hasSize(8);
    otherHc.setInfo(otherNi.setNativeTransportRunning(true).setRpcServerRunning(true).build());
    hcHistory.record(exec2, 5L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce5 = hcHistory.last(exec2);
    assertThat(hcHistory.entries()).hasSize(9);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(4).contains(otherHce2).contains(otherHce3).contains(otherHce4).contains(otherHce5);
    otherHc.setHealthy(true).setMsg("msg");
    hcHistory.record(exec2, 6L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce6 = hcHistory.last(exec2);
    assertThat(hcHistory.entries()).hasSize(10);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(5).contains(otherHce2).contains(otherHce3).contains(otherHce4).contains(otherHce5).contains(otherHce6);
    otherHc.setHealthy(false).setMsg("foo");
    hcHistory.record(exec2, 7L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce7 = hcHistory.last(exec2);
    assertThat(hcHistory.entries()).hasSize(10);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(5).doesNotContain(otherHce2).contains(otherHce3).contains(otherHce4).contains(otherHce5).contains(otherHce6).contains(otherHce7);
    otherHc.setHealthy(true).clearMsg();
    hcHistory.record(exec2, 8L, otherHc.build());
    final CassandraFrameworkProtos.HealthCheckHistoryEntry otherHce8 = hcHistory.last(exec2);
    assertThat(hcHistory.entries()).hasSize(10).doesNotContain(otherHce2).doesNotContain(otherHce3).contains(otherHce4).contains(otherHce5).contains(otherHce6).contains(otherHce7).contains(otherHce8).doesNotContain(hce2).doesNotContain(hce3).contains(hce4).contains(hce5).contains(hce6).contains(hce7).contains(hce8);
    assertThat(hcHistory.entriesForExecutor(exec2)).hasSize(5).doesNotContain(otherHce2).doesNotContain(otherHce3).contains(otherHce4).contains(otherHce5).contains(otherHce6).contains(otherHce7).contains(otherHce8);
}
Also used : CassandraFrameworkProtos(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos) State(org.apache.mesos.state.State) InMemoryState(org.apache.mesos.state.InMemoryState) InMemoryState(org.apache.mesos.state.InMemoryState) Test(org.junit.Test)

Example 2 with State

use of org.apache.mesos.state.State in project cassandra-mesos-deprecated by mesosphere.

the class PersistedCassandraClusterHealthCheckHistoryTest method testAllOscillatingOutOfOrder.

@Test
public void testAllOscillatingOutOfOrder() throws Exception {
    final State state = new InMemoryState();
    final PersistedCassandraClusterHealthCheckHistory hcHistory = new PersistedCassandraClusterHealthCheckHistory(state);
    hcHistory.record("abc", 10, unhealthy());
    hcHistory.record("abc", 11, healthy());
    hcHistory.record("abc", 13, unhealthy());
    hcHistory.record("abc", 16, unhealthy());
    hcHistory.record("abc", 14, healthy());
    hcHistory.record("abc", 19, unhealthy());
    hcHistory.record("abc", 15, healthy());
    hcHistory.record("abc", 12, healthy());
    hcHistory.record("abc", 25, unhealthy());
    hcHistory.record("abc", 17, healthy());
    hcHistory.record("abc", 20, healthy());
    hcHistory.record("abc", 21, healthy());
    hcHistory.record("abc", 22, unhealthy());
    hcHistory.record("abc", 24, healthy());
    hcHistory.record("abc", 18, healthy());
    hcHistory.record("abc", 23, healthy());
    final CassandraFrameworkProtos.CassandraClusterHealthCheckHistory history = hcHistory.get();
    final List<CassandraFrameworkProtos.HealthCheckHistoryEntry> list = history.getEntriesList();
    CassandraFrameworkProtos.HealthCheckHistoryEntry prev = null;
    for (final CassandraFrameworkProtos.HealthCheckHistoryEntry entry : list) {
        if (prev != null) {
            assertThat(entry.getTimestampStart()).isLessThanOrEqualTo(entry.getTimestampEnd());
            assertThat(prev.getTimestampEnd()).isLessThanOrEqualTo(entry.getTimestampStart());
        }
        prev = entry;
    }
}
Also used : CassandraFrameworkProtos(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos) State(org.apache.mesos.state.State) InMemoryState(org.apache.mesos.state.InMemoryState) InMemoryState(org.apache.mesos.state.InMemoryState) Test(org.junit.Test)

Example 3 with State

use of org.apache.mesos.state.State in project cassandra-mesos-deprecated by mesosphere.

the class PersistedCassandraFrameworkConfigurationTest method createInitializedState.

@NotNull
private State createInitializedState(@NotNull final String varName, @NotNull final String resourceName) throws IOException {
    final State state = new InMemoryState();
    final Variable var = await(state.fetch(varName));
    final Variable mut = var.mutate(readConfigurationFile(resourceName));
    await(state.store(mut));
    return state;
}
Also used : Variable(org.apache.mesos.state.Variable) InMemoryState(org.apache.mesos.state.InMemoryState) State(org.apache.mesos.state.State) InMemoryState(org.apache.mesos.state.InMemoryState) NotNull(javax.validation.constraints.NotNull)

Example 4 with State

use of org.apache.mesos.state.State in project cassandra-mesos-deprecated by mesosphere.

the class PersistedCassandraFrameworkConfigurationTest method separationOfFrameworkNameAndClusterNamePreservesOriginalClusterName.

@Test
public void separationOfFrameworkNameAndClusterNamePreservesOriginalClusterName() throws Exception {
    final State state = createInitializedState("CassandraFrameworkConfiguration", "/CassandraFrameworkConfiguration_v0.2.0.bin");
    final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(state, "frameworkName should be cassandra.cluster not this value", 15, 15, "2.1.4", 1.0, 2048, 2048, 1024, 1, 1, "*", "./backup", ".", true, true, "rack1", "dc1", Collections.<ExternalDc>emptyList(), "clusterName should be cassandra.cluster not this value");
    assertThat(configuration.frameworkName()).isEqualTo("cassandra.cluster");
    assertThat(configuration.clusterName()).isEqualTo("cassandra.cluster");
}
Also used : InMemoryState(org.apache.mesos.state.InMemoryState) State(org.apache.mesos.state.State) Test(org.junit.Test)

Example 5 with State

use of org.apache.mesos.state.State in project jesos by groupon.

the class AbstractTestState method testExpungeOk.

@Test
public void testExpungeOk() throws Exception {
    final State state = getState();
    final byte[] value = "The quick brown fox jumps over the lazy dog.".getBytes(StandardCharsets.UTF_8);
    final Variable var = state.fetch("someValue").get();
    assertTrue(var.value().length == 0);
    final JVariable storedVar = (JVariable) state.store(var.mutate(value)).get();
    final boolean expunged = state.expunge(storedVar).get();
    assertTrue(expunged);
    final JVariable retrievedVar = (JVariable) state.fetch("someValue").get();
    assertNotNull(retrievedVar);
    assertEquals(0, retrievedVar.value().length);
}
Also used : Variable(org.apache.mesos.state.Variable) State(org.apache.mesos.state.State) Test(org.junit.Test)

Aggregations

State (org.apache.mesos.state.State)16 Test (org.junit.Test)14 Variable (org.apache.mesos.state.Variable)11 InMemoryState (org.apache.mesos.state.InMemoryState)5 ImmutableList (com.google.common.collect.ImmutableList)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)2 CassandraFrameworkProtos (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos)2 Callable (java.util.concurrent.Callable)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ExternalDc (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.ExternalDc)1 HealthReportService (io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService)1 Clock (io.mesosphere.mesos.util.Clock)1 SystemClock (io.mesosphere.mesos.util.SystemClock)1 URI (java.net.URI)1