Search in sources :

Example 1 with InMemoryState

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

the class AbstractSchedulerTest method cleanState.

protected void cleanState(final String mesosRole) {
    // start with clean state
    state = new InMemoryState();
    configuration = new PersistedCassandraFrameworkConfiguration(state, "test-cluster", // health-check
    0, // bootstrap-grace-time
    0, "2.1.4", 2, 4096, 4096, 0, 3, 2, mesosRole, "./backup", ".", true, false, "RACK0", "DC0", Lists.<CassandraFrameworkProtos.ExternalDc>newArrayList(), "test-cluster");
    healthCheckHistory = new PersistedCassandraClusterHealthCheckHistory(state);
    cluster = new CassandraCluster(new SystemClock(), "http://127.0.0.1:65535", new ExecutorCounter(state, 0L), new PersistedCassandraClusterState(state), healthCheckHistory, new PersistedCassandraClusterJobs(state), configuration, new SeedManager(configuration, new ObjectMapper(), new SystemClock()));
    clusterState = cluster.getClusterState();
}
Also used : SystemClock(io.mesosphere.mesos.util.SystemClock) InMemoryState(org.apache.mesos.state.InMemoryState) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with InMemoryState

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

the class CassandraClusterTest method removeExecutor_cleansAllTasksAndExecutorInfo.

@Test
public void removeExecutor_cleansAllTasksAndExecutorInfo() throws Exception {
    final InMemoryState state = new InMemoryState();
    final Clock clock = new SystemClock();
    final ExecutorCounter execCounter = new ExecutorCounter(state, 0);
    final PersistedCassandraClusterState clusterState = new PersistedCassandraClusterState(state);
    final PersistedCassandraClusterHealthCheckHistory healthCheckHistory = new PersistedCassandraClusterHealthCheckHistory(state);
    final PersistedCassandraClusterJobs jobsState = new PersistedCassandraClusterJobs(state);
    final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(state, "cassandra.unit-test", 15, 15, "2.1.4", 1.0, 64, 64, 32, 1, 1, "*", "./backup", ".", true, false, "rack0", "dc0", Collections.<CassandraFrameworkProtos.ExternalDc>emptyList(), "cassandra.unit-test");
    final CassandraCluster cluster1 = new CassandraCluster(clock, "http://localhost:1234/", execCounter, clusterState, healthCheckHistory, jobsState, configuration, new SeedManager(configuration, new ObjectMapper(), clock));
    final Offer offer1 = Offer.newBuilder().setId(OfferID.newBuilder().setValue("1")).setFrameworkId(FrameworkID.newBuilder().setValue("fw1")).setSlaveId(SlaveID.newBuilder().setValue("slave1")).setHostname("localhost").addAllResources(newArrayList(cpu(4, "*"), mem(4096, "*"), disk(20 * 1024, "*"), ports(newArrayList(7000L, 7001L, 7199L, 9042L, 9160L, 10000L), "*"))).build();
    final TasksForOffer tasksForOffer = cluster1.getTasksForOffer(offer1);
    assertThat(tasksForOffer).isNotNull();
    // noinspection ConstantConditions
    assertThat(tasksForOffer.getExecutor()).isNotNull();
    final List<CassandraNode> nodes1 = clusterState.nodes();
    assertThat(nodes1).hasSize(1);
    final CassandraNode node1 = nodes1.get(0);
    assertThat(node1.getTasksList()).hasSize(1);
    assertThat(node1.hasCassandraNodeExecutor()).isTrue();
    final CassandraNodeExecutor executor1 = node1.getCassandraNodeExecutor();
    assertThat(executor1.getDownloadList()).hasSize(3);
    final List<FileDownload> from1 = newArrayList(from(executor1.getDownloadList()).filter(new Predicate<FileDownload>() {

        @Override
        public boolean apply(final FileDownload input) {
            return input.getDownloadUrl().startsWith("http://localhost:1234/");
        }
    }));
    assertThat(from1).hasSize(3);
    cluster1.removeExecutor("cassandra.unit-test.node.0.executor");
    final List<CassandraNode> afterRemove1 = clusterState.nodes();
    assertThat(afterRemove1).hasSize(1);
    final CassandraNode nodeAfterRemove1 = clusterState.nodes().get(0);
    assertThat(nodeAfterRemove1.getTasksList()).isEmpty();
    assertThat(nodeAfterRemove1.hasCassandraNodeExecutor()).isFalse();
    final CassandraCluster cluster2 = new CassandraCluster(clock, "http://localhost:4321/", execCounter, clusterState, healthCheckHistory, jobsState, configuration, new SeedManager(configuration, new ObjectMapper(), clock));
    final Offer offer2 = Offer.newBuilder(offer1).setId(OfferID.newBuilder().setValue("2")).build();
    final TasksForOffer tasksForOffer2 = cluster2.getTasksForOffer(offer2);
    assertThat(tasksForOffer2).isNotNull();
    // noinspection ConstantConditions
    assertThat(tasksForOffer2.getExecutor()).isNotNull();
    final List<CassandraNode> nodes2 = clusterState.nodes();
    assertThat(nodes2).hasSize(1);
    final CassandraNode node2 = nodes2.get(0);
    assertThat(node2.getTasksList()).hasSize(1);
    assertThat(node2.hasCassandraNodeExecutor()).isTrue();
    final CassandraNodeExecutor executor2 = node2.getCassandraNodeExecutor();
    assertThat(executor2.getDownloadList()).hasSize(3);
    final List<FileDownload> from2 = newArrayList(from(executor2.getDownloadList()).filter(new Predicate<FileDownload>() {

        @Override
        public boolean apply(final FileDownload input) {
            return input.getDownloadUrl().startsWith("http://localhost:4321/");
        }
    }));
    assertThat(from2).hasSize(3);
}
Also used : CassandraFrameworkProtos(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos) SystemClock(io.mesosphere.mesos.util.SystemClock) InMemoryState(org.apache.mesos.state.InMemoryState) Clock(io.mesosphere.mesos.util.Clock) SystemClock(io.mesosphere.mesos.util.SystemClock) CassandraNodeExecutor(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNodeExecutor) Predicate(com.google.common.base.Predicate) FileDownload(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.FileDownload) CassandraNode(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with InMemoryState

use of org.apache.mesos.state.InMemoryState 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 4 with InMemoryState

use of org.apache.mesos.state.InMemoryState 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 5 with InMemoryState

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

the class SeedManagerTest method before.

@Before
public void before() {
    InMemoryState state = new InMemoryState();
    PersistedCassandraFrameworkConfiguration config = new PersistedCassandraFrameworkConfiguration(state, "name", 60, 30, "2.1", 0.5, 1024, 1024, 512, 1, 1, "role", "./backup", ".", false, true, "RACK1", "DC1", Arrays.asList(ExternalDc.newBuilder().setName("dc").setUrl("http://dc").build()), "name");
    seedManager = new SeedManager(config, new ObjectMapper(), new SystemClock()) {

        @Override
        @Nullable
        protected JsonNode fetchJson(@NotNull final String url) {
            try {
                return new ObjectMapper().readTree(jsonResponse);
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    };
}
Also used : SystemClock(io.mesosphere.mesos.util.SystemClock) InMemoryState(org.apache.mesos.state.InMemoryState) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Nullable(org.jetbrains.annotations.Nullable) Before(org.junit.Before)

Aggregations

InMemoryState (org.apache.mesos.state.InMemoryState)8 Test (org.junit.Test)5 CassandraFrameworkProtos (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos)4 State (org.apache.mesos.state.State)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SystemClock (io.mesosphere.mesos.util.SystemClock)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Predicate (com.google.common.base.Predicate)1 CassandraFrameworkConfiguration (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraFrameworkConfiguration)1 CassandraNode (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNode)1 CassandraNodeExecutor (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNodeExecutor)1 FileDownload (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.FileDownload)1 Clock (io.mesosphere.mesos.util.Clock)1 IOException (java.io.IOException)1 NotNull (javax.validation.constraints.NotNull)1 Variable (org.apache.mesos.state.Variable)1 Nullable (org.jetbrains.annotations.Nullable)1 Before (org.junit.Before)1