Search in sources :

Example 1 with Clock

use of io.mesosphere.mesos.util.Clock 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 2 with Clock

use of io.mesosphere.mesos.util.Clock in project cassandra-mesos-deprecated by mesosphere.

the class Main method _main.

private static int _main() throws UnknownHostException {
    final Optional<String> portOption = Env.option("PORT0");
    if (!portOption.isPresent()) {
        throw new SystemExitException("Environment variable PORT0 must be defined", 5);
    }
    final int port0 = Integer.parseInt(portOption.get());
    final String host = Env.option("HOST").or("localhost");
    final Optional<String> clusterNameOpt = Env.option("CASSANDRA_CLUSTER_NAME");
    final int executorCount = Integer.parseInt(Env.option("CASSANDRA_NODE_COUNT").or("3"));
    final int seedCount = Integer.parseInt(Env.option("CASSANDRA_SEED_COUNT").or("2"));
    final double resourceCpuCores = Double.parseDouble(Env.option("CASSANDRA_RESOURCE_CPU_CORES").or("2.0"));
    final long resourceMemoryMegabytes = Long.parseLong(Env.option("CASSANDRA_RESOURCE_MEM_MB").or("2048"));
    final long resourceDiskMegabytes = Long.parseLong(Env.option("CASSANDRA_RESOURCE_DISK_MB").or("2048"));
    final long javaHeapMb = Long.parseLong(Env.option("CASSANDRA_RESOURCE_HEAP_MB").or("0"));
    final long healthCheckIntervalSec = Long.parseLong(Env.option("CASSANDRA_HEALTH_CHECK_INTERVAL_SECONDS").or("60"));
    final long bootstrapGraceTimeSec = Long.parseLong(Env.option("CASSANDRA_BOOTSTRAP_GRACE_TIME_SECONDS").or("120"));
    final String cassandraVersion = "2.1.4";
    final String clusterName = clusterNameOpt.or("cassandra");
    final String frameworkName = frameworkName(clusterNameOpt);
    final String zkUrl = Env.option("CASSANDRA_ZK").or("zk://localhost:2181/cassandra-mesos");
    final long zkTimeoutMs = Long.parseLong(Env.option("CASSANDRA_ZK_TIMEOUT_MS").or("10000"));
    final String mesosMasterZkUrl = Env.option("MESOS_ZK").or("zk://localhost:2181/mesos");
    final String mesosUser = Env.option("MESOS_USER").or("");
    final long failoverTimeout = Long.parseLong(Env.option("CASSANDRA_FAILOVER_TIMEOUT_SECONDS").or(String.valueOf(Period.days(7).toStandardSeconds().getSeconds())));
    final String mesosRole = Env.option("CASSANDRA_FRAMEWORK_MESOS_ROLE").or("*");
    // TODO: Temporary. Will be removed when MESOS-1554 is released
    final String dataDirectory = Env.option("CASSANDRA_DATA_DIRECTORY").or(DEFAULT_DATA_DIRECTORY);
    final String backupDirectory = Env.option("CASSANDRA_BACKUP_DIRECTORY").or(DEFAULT_BACKUP_DIRECTORY);
    final boolean jmxLocal = Boolean.parseBoolean(Env.option("CASSANDRA_JMX_LOCAL").or("true"));
    final boolean jmxNoAuthentication = Boolean.parseBoolean(Env.option("CASSANDRA_JMX_NO_AUTHENTICATION").or("false"));
    final String defaultRack = Env.option("CASSANDRA_DEFAULT_RACK").or("RAC1");
    final String defaultDc = Env.option("CASSANDRA_DEFAULT_DC").or("DC1");
    final List<ExternalDc> externalDcs = getExternalDcs(Env.filterStartsWith("CASSANDRA_EXTERNAL_DC_", true));
    final Matcher matcher = validateZkUrl(zkUrl);
    final State state = new ZooKeeperState(matcher.group(1), zkTimeoutMs, TimeUnit.MILLISECONDS, matcher.group(2));
    if (seedCount > executorCount || seedCount <= 0 || executorCount <= 0) {
        throw new IllegalArgumentException("number of nodes (" + executorCount + ") and/or number of seeds (" + seedCount + ") invalid");
    }
    final PersistedCassandraFrameworkConfiguration configuration = new PersistedCassandraFrameworkConfiguration(state, frameworkName, healthCheckIntervalSec, bootstrapGraceTimeSec, cassandraVersion, resourceCpuCores, resourceDiskMegabytes, resourceMemoryMegabytes, javaHeapMb, executorCount, seedCount, mesosRole, backupDirectory, dataDirectory, jmxLocal, jmxNoAuthentication, defaultRack, defaultDc, externalDcs, clusterName);
    final FrameworkInfo.Builder frameworkBuilder = FrameworkInfo.newBuilder().setFailoverTimeout(failoverTimeout).setUser(mesosUser).setName(frameworkName).setRole(mesosRole).setCheckpoint(true);
    final Optional<String> frameworkId = configuration.frameworkId();
    if (frameworkId.isPresent()) {
        frameworkBuilder.setId(frameworkId(frameworkId.get()));
    }
    final URI httpServerBaseUri = URI.create("http://" + host + ":" + port0 + "/");
    final Clock clock = new SystemClock();
    final PersistedCassandraClusterHealthCheckHistory healthCheckHistory = new PersistedCassandraClusterHealthCheckHistory(state);
    final PersistedCassandraClusterState clusterState = new PersistedCassandraClusterState(state);
    final SeedManager seedManager = new SeedManager(configuration, new ObjectMapper(), new SystemClock());
    final CassandraCluster cassandraCluster = new CassandraCluster(clock, httpServerBaseUri.toString(), new ExecutorCounter(state, 0L), clusterState, healthCheckHistory, new PersistedCassandraClusterJobs(state), configuration, seedManager);
    final HealthReportService healthReportService = new HealthReportService(clusterState, configuration, healthCheckHistory, clock);
    final Scheduler scheduler = new CassandraScheduler(configuration, cassandraCluster, clock);
    final JsonFactory factory = new JsonFactory();
    final ObjectMapper objectMapper = new ObjectMapper(factory);
    objectMapper.registerModule(new GuavaModule());
    // create JsonProvider to provide custom ObjectMapper
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(objectMapper);
    final ResourceConfig rc = new ResourceConfig().registerInstances(new FileResourceController(cassandraVersion), new ApiController(factory), new ClusterCleanupController(cassandraCluster, factory), new ClusterRepairController(cassandraCluster, factory), new ClusterRollingRestartController(cassandraCluster, factory), new ClusterBackupController(cassandraCluster, factory), new ClusterRestoreController(cassandraCluster, factory), new ConfigController(cassandraCluster, factory), new LiveEndpointsController(cassandraCluster, factory), new NodeController(cassandraCluster, factory), new HealthCheckController(healthReportService), new QaReportController(cassandraCluster, factory), new ScaleOutController(cassandraCluster, factory), provider);
    final HttpServer httpServer = GrizzlyHttpServerFactory.createHttpServer(httpServerBaseUri, rc);
    final MesosSchedulerDriver driver;
    final Optional<Credential> credentials = getCredential();
    if (credentials.isPresent()) {
        frameworkBuilder.setPrincipal(credentials.get().getPrincipal());
        driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMasterZkUrl, credentials.get());
    } else {
        frameworkBuilder.setPrincipal("cassandra-framework");
        driver = new MesosSchedulerDriver(scheduler, frameworkBuilder.build(), mesosMasterZkUrl);
    }
    seedManager.startSyncingSeeds(60);
    final int status;
    switch(driver.run()) {
        case DRIVER_STOPPED:
            status = 0;
            break;
        case DRIVER_ABORTED:
            status = 1;
            break;
        case DRIVER_NOT_STARTED:
            status = 2;
            break;
        default:
            status = 3;
            break;
    }
    httpServer.shutdownNow();
    // Ensure that the driver process terminates.
    driver.stop(true);
    return status;
}
Also used : Clock(io.mesosphere.mesos.util.Clock) SystemClock(io.mesosphere.mesos.util.SystemClock) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) HealthReportService(io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService) MesosSchedulerDriver(org.apache.mesos.MesosSchedulerDriver) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SystemClock(io.mesosphere.mesos.util.SystemClock) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) State(org.apache.mesos.state.State) ZooKeeperState(org.apache.mesos.state.ZooKeeperState) Matcher(java.util.regex.Matcher) FrameworkInfo(org.apache.mesos.Protos.FrameworkInfo) Scheduler(org.apache.mesos.Scheduler) JsonFactory(com.fasterxml.jackson.core.JsonFactory) ExternalDc(io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.ExternalDc) URI(java.net.URI) ZooKeeperState(org.apache.mesos.state.ZooKeeperState) HttpServer(org.glassfish.grizzly.http.server.HttpServer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Credential(org.apache.mesos.Protos.Credential)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Clock (io.mesosphere.mesos.util.Clock)2 SystemClock (io.mesosphere.mesos.util.SystemClock)2 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)1 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 Predicate (com.google.common.base.Predicate)1 CassandraFrameworkProtos (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos)1 CassandraNode (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNode)1 CassandraNodeExecutor (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.CassandraNodeExecutor)1 ExternalDc (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.ExternalDc)1 FileDownload (io.mesosphere.mesos.frameworks.cassandra.CassandraFrameworkProtos.FileDownload)1 HealthReportService (io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService)1 URI (java.net.URI)1 Matcher (java.util.regex.Matcher)1 MesosSchedulerDriver (org.apache.mesos.MesosSchedulerDriver)1 Credential (org.apache.mesos.Protos.Credential)1 FrameworkInfo (org.apache.mesos.Protos.FrameworkInfo)1 Scheduler (org.apache.mesos.Scheduler)1 InMemoryState (org.apache.mesos.state.InMemoryState)1