You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wf...@apache.org on 2014/07/22 02:52:57 UTC
git commit: Remove IsolatedSchedulerModule and surrounding code.
Repository: incubator-aurora
Updated Branches:
refs/heads/master ab5254023 -> bceac4ecd
Remove IsolatedSchedulerModule and surrounding code.
Bugs closed: AURORA-340
Reviewed at https://reviews.apache.org/r/20648/
Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/bceac4ec
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/bceac4ec
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/bceac4ec
Branch: refs/heads/master
Commit: bceac4ecd2b5bf078367938397e56cab1e728bd1
Parents: ab52540
Author: Bill Farner <wf...@apache.org>
Authored: Mon Jul 21 17:33:03 2014 -0700
Committer: Bill Farner <wf...@apache.org>
Committed: Mon Jul 21 17:33:03 2014 -0700
----------------------------------------------------------------------
build.gradle | 23 --
.../aurora/scheduler/app/SchedulerMain.java | 40 +--
.../scheduler/local/FakeDriverFactory.java | 167 ---------
.../local/IsolatedSchedulerModule.java | 358 -------------------
.../aurora/scheduler/log/testing/FileLog.java | 161 ---------
.../log/testing/FileLogStreamModule.java | 46 ---
.../scheduler/log/testing/FileLogTest.java | 56 ---
7 files changed, 13 insertions(+), 838 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 751bde2..32a31e6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -452,29 +452,6 @@ idea {
applicationName = 'aurora-scheduler'
mainClassName = 'org.apache.aurora.scheduler.app.SchedulerMain'
-// Run a local scheduler with a local log file and fake jobs
-run {
- classpath += sourceSets.generated.output
- args = [
- '-thermos_executor_path=/dev/null',
- '-gc_executor_path=/dev/null',
- '-http_port=8081',
- '-zk_in_proc=true',
- '-zk_endpoints=localhost:0',
- '-serverset_path=/twitter/service/mesos/local/scheduler',
- '-mesos_master_address=local',
- '-cluster_name=local',
- '-log_dir=/tmp',
- '-backup_dir=/tmp',
- '-logtostderr',
- '-vlog=INFO',
- '-testing_isolated_scheduler=true',
- '-testing_log_file_path=/tmp/testing_log_file',
- '-viz_job_url_prefix=http://fake_viz_domain.com/stats?',
- '-enable_cors_support'
- ]
-}
-
tasks.withType(nl.javadude.gradle.plugins.license.License).each { licenseTask ->
licenseTask.setSource files("$projectDir/src/main/java", "$projectDir/src/test/java")
}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
index 6d18695..f429eda 100644
--- a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
+++ b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
@@ -20,6 +20,7 @@ import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
@@ -53,7 +54,6 @@ import org.apache.aurora.scheduler.DriverFactory.DriverFactoryImpl;
import org.apache.aurora.scheduler.MesosTaskFactory.ExecutorConfig;
import org.apache.aurora.scheduler.SchedulerLifecycle;
import org.apache.aurora.scheduler.cron.quartz.CronModule;
-import org.apache.aurora.scheduler.local.IsolatedSchedulerModule;
import org.apache.aurora.scheduler.log.mesos.MesosLogStreamModule;
import org.apache.aurora.scheduler.storage.backup.BackupModule;
import org.apache.aurora.scheduler.storage.db.DbModule;
@@ -73,10 +73,6 @@ public class SchedulerMain extends AbstractApplication {
private static final Logger LOG = Logger.getLogger(SchedulerMain.class.getName());
- @CmdLine(name = "testing_isolated_scheduler",
- help = "If true, run in a testing mode with the scheduler isolated from other components.")
- private static final Arg<Boolean> ISOLATED_SCHEDULER = Arg.create(false);
-
@NotNull
@CmdLine(name = "cluster_name", help = "Name to identify the cluster being served.")
private static final Arg<String> CLUSTER_NAME = Arg.create();
@@ -116,14 +112,6 @@ public class SchedulerMain extends AbstractApplication {
@Inject private Lifecycle appLifecycle;
@Inject private Optional<RootLogConfig.Configuration> glogConfig;
- private static Iterable<? extends Module> getSystemModules() {
- return ImmutableList.of(
- new LogModule(),
- new HttpModule(),
- new StatsModule()
- );
- }
-
private static Iterable<? extends Module> getExtraModules() {
Builder<Module> modules = ImmutableList.builder();
modules.add(Modules.wrapInPrivateModule(AUTH_MODULE.get(), AUTH_MODULE_CLASSES));
@@ -135,6 +123,7 @@ public class SchedulerMain extends AbstractApplication {
return modules.build();
}
+ @VisibleForTesting
static Iterable<? extends Module> getModules(
String clusterName,
String serverSetPath,
@@ -142,7 +131,9 @@ public class SchedulerMain extends AbstractApplication {
String statsURLPrefix) {
return ImmutableList.<Module>builder()
- .addAll(getSystemModules())
+ .add(new LogModule())
+ .add(new HttpModule())
+ .add(new StatsModule())
.add(new AppModule(clusterName, serverSetPath, zkClientConfig, statsURLPrefix))
.addAll(getExtraModules())
.add(new LogStorageModule())
@@ -160,21 +151,16 @@ public class SchedulerMain extends AbstractApplication {
@Override
public Iterable<? extends Module> getModules() {
- Module additional;
final ClientConfig zkClientConfig = FlaggedClientConfig.create();
- if (ISOLATED_SCHEDULER.get()) {
- additional = new IsolatedSchedulerModule();
- } else {
// TODO(Kevin Sweeney): Push these bindings down into a "production" module.
- additional = new AbstractModule() {
- @Override
- protected void configure() {
- bind(DriverFactory.class).to(DriverFactoryImpl.class);
- bind(DriverFactoryImpl.class).in(Singleton.class);
- install(new MesosLogStreamModule(zkClientConfig));
- }
- };
- }
+ Module additional = new AbstractModule() {
+ @Override
+ protected void configure() {
+ bind(DriverFactory.class).to(DriverFactoryImpl.class);
+ bind(DriverFactoryImpl.class).in(Singleton.class);
+ install(new MesosLogStreamModule(zkClientConfig));
+ }
+ };
Module configModule = new AbstractModule() {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/main/java/org/apache/aurora/scheduler/local/FakeDriverFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/local/FakeDriverFactory.java b/src/main/java/org/apache/aurora/scheduler/local/FakeDriverFactory.java
deleted file mode 100644
index 92cf442..0000000
--- a/src/main/java/org/apache/aurora/scheduler/local/FakeDriverFactory.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.local;
-
-import java.util.Collection;
-import java.util.Objects;
-
-import javax.annotation.Nullable;
-import javax.inject.Inject;
-import javax.inject.Provider;
-
-import com.google.common.base.Optional;
-import com.twitter.common.application.Lifecycle;
-
-import org.apache.aurora.scheduler.DriverFactory;
-import org.apache.mesos.Protos.ExecutorID;
-import org.apache.mesos.Protos.Filters;
-import org.apache.mesos.Protos.FrameworkID;
-import org.apache.mesos.Protos.MasterInfo;
-import org.apache.mesos.Protos.OfferID;
-import org.apache.mesos.Protos.Request;
-import org.apache.mesos.Protos.SlaveID;
-import org.apache.mesos.Protos.Status;
-import org.apache.mesos.Protos.TaskID;
-import org.apache.mesos.Protos.TaskInfo;
-import org.apache.mesos.Protos.TaskStatus;
-import org.apache.mesos.Scheduler;
-import org.apache.mesos.SchedulerDriver;
-
-/**
- * A factory for fake scheduler driver instances.
- */
-@SuppressWarnings("deprecation")
-class FakeDriverFactory implements DriverFactory {
-
- private final Provider<Scheduler> scheduler;
- private final Lifecycle lifecycle;
-
- @Inject
- FakeDriverFactory(Provider<Scheduler> scheduler, Lifecycle lifecycle) {
- this.scheduler = Objects.requireNonNull(scheduler);
- this.lifecycle = Objects.requireNonNull(lifecycle);
- }
-
- @Override
- public SchedulerDriver apply(@Nullable final String frameworkId) {
- return new FakeSchedulerDriver() {
- @Override
- public Status start() {
- scheduler.get().registered(
- this,
- FrameworkID.newBuilder().setValue(
- Optional.fromNullable(frameworkId).or("new-framework-id")).build(),
- MasterInfo.newBuilder().setId("master-id").setIp(100).setPort(200).build());
- return null;
- }
-
- @Override
- public Status join() {
- lifecycle.awaitShutdown();
- return null;
- }
- };
- }
-
- static class FakeSchedulerDriver implements SchedulerDriver {
- @Override
- public Status start() {
- return null;
- }
-
- @Override
- public Status stop(boolean b) {
- return null;
- }
-
- @Override
- public Status stop() {
- return null;
- }
-
- @Override
- public Status abort() {
- return null;
- }
-
- @Override
- public Status join() {
- return run();
- }
-
- @Override
- public Status run() {
- return null;
- }
-
- @Override
- public Status requestResources(Collection<Request> requests) {
- return null;
- }
-
- @Override
- public Status launchTasks(
- Collection<OfferID> offerIds,
- Collection<TaskInfo> tasks,
- Filters filters) {
-
- return null;
- }
-
- @Override
- public Status launchTasks(Collection<OfferID> offerIds, Collection<TaskInfo> tasks) {
- return null;
- }
-
- @Override
- public Status launchTasks(OfferID offerID, Collection<TaskInfo> taskInfos, Filters filters) {
- return null;
- }
-
- @Override
- public Status launchTasks(OfferID offerID, Collection<TaskInfo> taskInfos) {
- return null;
- }
-
- @Override
- public Status killTask(TaskID taskID) {
- return null;
- }
-
- @Override
- public Status declineOffer(OfferID offerID, Filters filters) {
- return null;
- }
-
- @Override
- public Status declineOffer(OfferID offerID) {
- return null;
- }
-
- @Override
- public Status reviveOffers() {
- return null;
- }
-
- @Override
- public Status sendFrameworkMessage(ExecutorID executorID, SlaveID slaveID, byte[] bytes) {
- return null;
- }
-
- @Override
- public Status reconcileTasks(Collection<TaskStatus> statuses) {
- return null;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/main/java/org/apache/aurora/scheduler/local/IsolatedSchedulerModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/local/IsolatedSchedulerModule.java b/src/main/java/org/apache/aurora/scheduler/local/IsolatedSchedulerModule.java
deleted file mode 100644
index 2c06e24..0000000
--- a/src/main/java/org/apache/aurora/scheduler/local/IsolatedSchedulerModule.java
+++ /dev/null
@@ -1,358 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.local;
-
-import java.util.List;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ScheduledThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.logging.Logger;
-
-import javax.inject.Inject;
-import javax.inject.Provider;
-import javax.inject.Singleton;
-
-import com.google.common.base.Function;
-import com.google.common.base.Throwables;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.eventbus.Subscribe;
-import com.google.inject.AbstractModule;
-import com.twitter.common.application.ShutdownRegistry;
-import com.twitter.common.base.Command;
-import com.twitter.common.quantity.Amount;
-import com.twitter.common.quantity.Time;
-import com.twitter.common.stats.Stats;
-import com.twitter.common.util.concurrent.ExecutorServiceShutdown;
-
-import org.apache.aurora.codec.ThriftBinaryCodec;
-import org.apache.aurora.gen.AuroraAdmin;
-import org.apache.aurora.gen.ExecutorConfig;
-import org.apache.aurora.gen.Identity;
-import org.apache.aurora.gen.JobConfiguration;
-import org.apache.aurora.gen.Metadata;
-import org.apache.aurora.gen.ResourceAggregate;
-import org.apache.aurora.gen.Response;
-import org.apache.aurora.gen.SessionKey;
-import org.apache.aurora.gen.TaskConfig;
-import org.apache.aurora.gen.comm.DeletedTasks;
-import org.apache.aurora.gen.comm.SchedulerMessage;
-import org.apache.aurora.scheduler.DriverFactory;
-import org.apache.aurora.scheduler.base.AsyncUtil;
-import org.apache.aurora.scheduler.base.JobKeys;
-import org.apache.aurora.scheduler.configuration.ConfigurationManager;
-import org.apache.aurora.scheduler.configuration.Resources;
-import org.apache.aurora.scheduler.events.PubsubEvent.DriverRegistered;
-import org.apache.aurora.scheduler.events.PubsubEvent.EventSubscriber;
-import org.apache.aurora.scheduler.events.PubsubEvent.TaskStateChange;
-import org.apache.aurora.scheduler.events.PubsubEventModule;
-import org.apache.aurora.scheduler.local.FakeDriverFactory.FakeSchedulerDriver;
-import org.apache.aurora.scheduler.log.testing.FileLogStreamModule;
-import org.apache.commons.lang.RandomStringUtils;
-import org.apache.mesos.Protos;
-import org.apache.mesos.Protos.Attribute;
-import org.apache.mesos.Protos.FrameworkID;
-import org.apache.mesos.Protos.Offer;
-import org.apache.mesos.Protos.OfferID;
-import org.apache.mesos.Protos.Resource;
-import org.apache.mesos.Protos.SlaveID;
-import org.apache.mesos.Protos.TaskID;
-import org.apache.mesos.Protos.TaskState;
-import org.apache.mesos.Protos.TaskStatus;
-import org.apache.mesos.Protos.Value.Scalar;
-import org.apache.mesos.Protos.Value.Text;
-import org.apache.mesos.Protos.Value.Type;
-import org.apache.mesos.Scheduler;
-import org.apache.mesos.SchedulerDriver;
-import org.apache.thrift.TException;
-
-/**
- * A module that binds a fake mesos driver factory and a local (non-replicated) storage system.
- * <p/>
- * The easiest way to run the scheduler in local/isolated mode is by executing:
- * <pre>
- * $ ./pants goal bundle aurora:scheduler-local && ./aurora/scripts/scheduler.sh -c local
- * </pre>
- */
-public class IsolatedSchedulerModule extends AbstractModule {
-
- private static final Logger LOG = Logger.getLogger(IsolatedSchedulerModule.class.getName());
-
- @Override
- protected void configure() {
- bind(DriverFactory.class).to(FakeDriverFactory.class);
- bind(FakeDriverFactory.class).in(Singleton.class);
- PubsubEventModule.bindSubscriber(binder(), FakeClusterRunner.class);
- install(new FileLogStreamModule());
- }
-
- static class FakeClusterRunner implements EventSubscriber {
- private final FrameworkID frameworkId =
- FrameworkID.newBuilder().setValue("framework-id").build();
- private final List<FakeSlave> cluster = ImmutableList.of(
- new FakeSlave(frameworkId, "fake-host1", "rack1", "slave-id1"),
- new FakeSlave(frameworkId, "fake-host2", "rack2", "slave-id2")
- );
-
- private final AtomicLong offerId = new AtomicLong();
- private final Function<FakeSlave, Offer> slaveToOffer = new Function<FakeSlave, Offer>() {
- @Override
- public Offer apply(FakeSlave slave) {
- return slave.makeOffer(offerId.incrementAndGet());
- }
- };
-
- private final Provider<Scheduler> scheduler;
- private final AuroraAdmin.Iface thrift;
- private final ScheduledExecutorService executor;
- private final SchedulerDriver driver;
-
- @Inject
- FakeClusterRunner(
- Provider<Scheduler> scheduler,
- AuroraAdmin.Iface thrift,
- ShutdownRegistry shutdownRegistry) {
-
- this.scheduler = scheduler;
- this.thrift = thrift;
- this.executor = createThreadPool(shutdownRegistry);
- this.driver = new FakeSchedulerDriver();
- }
-
- private static ScheduledExecutorService createThreadPool(ShutdownRegistry shutdownRegistry) {
- final ScheduledThreadPoolExecutor executor =
- AsyncUtil.loggingScheduledExecutor(1, "TaskScheduler-%d", LOG);
- Stats.exportSize("schedule_queue_size", executor.getQueue());
- shutdownRegistry.addAction(new Command() {
- @Override
- public void execute() {
- new ExecutorServiceShutdown(executor, Amount.of(1L, Time.SECONDS)).execute();
- }
- });
- return executor;
- }
-
- private void offerClusterResources() {
- executor.submit(new Runnable() {
- @Override
- public void run() {
- scheduler.get().resourceOffers(
- driver,
- FluentIterable.from(cluster).transform(slaveToOffer).toList());
- }
- });
- }
-
- private void setQuotas() {
- executor.submit(new Runnable() {
- @Override
- public void run() {
- try {
- thrift.setQuota(
- "mesos",
- new ResourceAggregate(2.0 * 1000000, 100000000, 100000000),
- new SessionKey());
- } catch (TException e) {
- throw Throwables.propagate(e);
- }
- }
- });
- }
-
- @Subscribe
- public void registered(DriverRegistered event) {
- executor.submit(new Runnable() {
- @Override
- public void run() {
- Identity mesosUser = new Identity("mesos", "mesos");
- for (int i = 0; i < 20; i++) {
- JobConfiguration service = createJob("serviceJob" + i, mesosUser);
- service.getTaskConfig().setProduction(i % 2 == 0);
- service.getTaskConfig().setIsService(true);
- submitJob(service);
- }
-
- for (int i = 0; i < 20; i++) {
- JobConfiguration adhocJob = createJob("adhocJob" + i, mesosUser);
- adhocJob.getTaskConfig().setProduction(i % 2 == 0);
- adhocJob.getTaskConfig();
- submitJob(adhocJob);
- }
-
- for (int i = 0; i < 20; i++) {
- JobConfiguration cron = createJob("cronJob" + i, mesosUser);
- cron.getTaskConfig().setProduction(i % 2 == 0);
- cron.setCronSchedule("* * * * *");
- submitJob(cron);
- }
-
- JobConfiguration bigService = createJob("bigJob",
- mesosUser,
- 2000,
- RandomStringUtils.random(300));
-
- bigService.getTaskConfig().setProduction(true);
- bigService.getTaskConfig().setIsService(true);
- submitJob(bigService);
- }
- });
-
- setQuotas();
- offerClusterResources();
- // Send the offers again, since the first batch of offers will be consumed by GC executors.
- offerClusterResources();
- }
-
- private void moveTaskToState(final String taskId, final TaskState state, long delaySeconds) {
- Runnable changeState = new Runnable() {
- @Override
- public void run() {
- scheduler.get().statusUpdate(
- driver,
- TaskStatus.newBuilder()
- .setTaskId(TaskID.newBuilder().setValue(taskId))
- .setState(state)
- .build());
- }
- };
- executor.schedule(changeState, delaySeconds, TimeUnit.SECONDS);
-
- if (state == TaskState.TASK_FINISHED) {
- Runnable deleteSandBox = new Runnable() {
- @Override
- public void run() {
- try {
- scheduler.get().frameworkMessage(
- driver,
- Protos.ExecutorID.newBuilder().setValue("executor-id").build(),
- SlaveID.newBuilder().setValue("slave-id").build(),
- ThriftBinaryCodec.encode(
- SchedulerMessage.deletedTasks(new DeletedTasks(ImmutableSet.of(taskId)))));
- } catch (Exception e) {
- LOG.info("Error deleting tasks " + e);
- }
- }
- };
- executor.schedule(deleteSandBox, delaySeconds + 100, TimeUnit.SECONDS);
- }
- }
-
- @Subscribe
- public void stateChanged(TaskStateChange stateChange) {
- String taskId = stateChange.getTaskId();
- switch (stateChange.getNewState()) {
- case ASSIGNED:
- moveTaskToState(taskId, TaskState.TASK_STARTING, 1);
- break;
-
- case STARTING:
- moveTaskToState(taskId, TaskState.TASK_RUNNING, 1);
- break;
-
- case RUNNING:
- // Let the task finish some time randomly in the next 5 minutes.
- moveTaskToState(taskId, TaskState.TASK_FINISHED, (long) (Math.random() * 300));
- break;
-
- case FINISHED:
- offerClusterResources();
- break;
-
- default:
- break;
- }
- }
-
- private JobConfiguration createJob(String jobName, Identity owner) {
- return createJob(jobName, owner, 5, "opaque");
- }
-
- private JobConfiguration createJob(
- String jobName,
- Identity owner,
- int instanceCount,
- String executorConfig) {
-
- return new JobConfiguration()
- .setKey(JobKeys.from(owner.getRole(), "test", jobName).newBuilder())
- .setOwner(owner)
- .setInstanceCount(instanceCount)
- .setTaskConfig(new TaskConfig()
- .setOwner(owner)
- .setJobName(jobName)
- .setEnvironment("test")
- .setNumCpus(1.0)
- .setDiskMb(1024)
- .setRamMb(1024)
- .setMetadata(ImmutableSet.of(
- new Metadata("role", owner.getRole()),
- new Metadata("package", "15")))
- .setExecutorConfig(new ExecutorConfig("aurora", executorConfig)));
- }
-
- private void submitJob(JobConfiguration job) {
- Response response;
- try {
- response = thrift.createJob(job, null, new SessionKey());
- } catch (TException e) {
- throw Throwables.propagate(e);
- }
- LOG.info("Create job response: " + response);
- }
- }
-
- private static class FakeSlave {
- private final FrameworkID framework;
- private final String host;
- private final String rack;
- private final String slaveId;
-
- FakeSlave(FrameworkID framework, String host, String rack, String slaveId) {
- this.framework = framework;
- this.host = host;
- this.rack = rack;
- this.slaveId = slaveId;
- }
-
- private static Resource.Builder scalar(String name, double value) {
- return Resource.newBuilder()
- .setName(name)
- .setType(Type.SCALAR)
- .setScalar(Scalar.newBuilder().setValue(value));
- }
-
- private static Attribute.Builder attribute(String name, String value) {
- return Attribute.newBuilder()
- .setName(name)
- .setType(Type.TEXT)
- .setText(Text.newBuilder().setValue(value));
- }
-
- Offer makeOffer(long offerId) {
- return Offer.newBuilder()
- .setId(OfferID.newBuilder().setValue("offer" + offerId))
- .setFrameworkId(framework)
- .setSlaveId(SlaveID.newBuilder().setValue(slaveId))
- .setHostname(host)
- .addResources(scalar(Resources.CPUS, 16))
- .addResources(scalar(Resources.RAM_MB, 24576))
- .addResources(scalar(Resources.DISK_MB, 102400))
- .addAttributes(attribute(ConfigurationManager.RACK_CONSTRAINT, rack))
- .addAttributes(attribute(ConfigurationManager.HOST_CONSTRAINT, host))
- .build();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/main/java/org/apache/aurora/scheduler/log/testing/FileLog.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/log/testing/FileLog.java b/src/main/java/org/apache/aurora/scheduler/log/testing/FileLog.java
deleted file mode 100644
index c6672fb..0000000
--- a/src/main/java/org/apache/aurora/scheduler/log/testing/FileLog.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.log.testing;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.util.Iterator;
-import java.util.Objects;
-
-import javax.inject.Inject;
-
-import com.google.common.base.Function;
-import com.google.common.base.Functions;
-import com.google.common.base.Predicate;
-import com.google.common.base.Throwables;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
-import com.google.common.io.Files;
-import com.google.common.primitives.Longs;
-import com.twitter.common.base.Closure;
-
-import org.apache.aurora.codec.ThriftBinaryCodec;
-import org.apache.aurora.codec.ThriftBinaryCodec.CodingException;
-import org.apache.aurora.gen.test.FileLogContents;
-import org.apache.aurora.gen.test.LogRecord;
-import org.apache.aurora.scheduler.log.Log;
-
-/**
- * A log implementation that reads from and writes to a local file.
- * <p>
- * This should never be used in a production setting, it is only intended for local testing.
- * TODO(wfarner): Bind/inject a settable flag that indicates we are running with test settings.
- * Surface this in a banner on the web UI.
- */
-class FileLog implements Log {
-
- private final File logFile;
-
- @Inject
- FileLog(File logFile) {
- this.logFile = Objects.requireNonNull(logFile);
- }
-
- @Override
- public Stream open() throws IOException {
- try {
- FileLogContents logContents;
- // Treat an empty file as a new file.
- // NOTE: we can't use logFile.length == 0 to test for an empty file, since empty unicode files
- // contain a byte order mark (BOM) header that is 255 bytes in length.
- if (logFile.createNewFile()
- || Files.readFirstLine(logFile, Charset.defaultCharset()) == null) {
- logContents = new FileLogContents(Maps.<Long, LogRecord>newHashMap());
- } else {
- logContents = ThriftBinaryCodec.decode(FileLogContents.class, Files.toByteArray(logFile));
- }
- Closure<FileLogContents> logWriter = new Closure<FileLogContents>() {
- @Override
- public void execute(FileLogContents logContents) {
- try {
- Files.write(ThriftBinaryCodec.encode(logContents), logFile);
- } catch (IOException | CodingException e) {
- throw Throwables.propagate(e);
- }
- }
- };
- return new FileStream(logContents, logWriter);
- } catch (CodingException e) {
- throw new IOException("Failed to interpret log contents: " + e, e);
- }
- }
-
- private static class FileStream implements Stream {
- private final FileLogContents logContents;
- private final Closure<FileLogContents> logWriter;
- private long nextPosition;
-
- FileStream(FileLogContents logContents, Closure<FileLogContents> logWriter) {
- this.logContents = logContents;
- this.logWriter = logWriter;
- nextPosition = logContents.getRecords().isEmpty()
- ? 1
- : Ordering.natural().max(logContents.getRecords().keySet()) + 1;
- }
-
- @Override
- public Position append(byte[] contents) throws StreamAccessException {
- logContents.getRecords().put(nextPosition, new LogRecord(ByteBuffer.wrap(contents)));
- Position position = new CounterPosition(nextPosition);
- logWriter.execute(logContents);
- nextPosition++;
- return position;
- }
-
- private static final Function<LogRecord, Entry> TO_ENTRY = new Function<LogRecord, Entry>() {
- @Override
- public Entry apply(final LogRecord record) {
- return new Entry() {
- @Override
- public byte[] contents() {
- return record.getContents();
- }
- };
- }
- };
-
- @Override
- public Iterator<Entry> readAll() throws InvalidPositionException, StreamAccessException {
- return FluentIterable.from(Ordering.natural().sortedCopy(logContents.getRecords().keySet()))
- .transform(Functions.forMap(logContents.getRecords()))
- .transform(TO_ENTRY)
- .iterator();
- }
-
- @Override
- public void truncateBefore(Position position)
- throws InvalidPositionException, StreamAccessException {
-
- if (!(position instanceof CounterPosition)) {
- throw new InvalidPositionException("Unrecognized position " + position);
- }
-
- final long truncateBefore = ((CounterPosition) position).value;
- Iterables.removeIf(logContents.getRecords().keySet(), new Predicate<Long>() {
- @Override
- public boolean apply(Long recordPosition) {
- return recordPosition < truncateBefore;
- }
- });
- logWriter.execute(logContents);
- }
-
- private static class CounterPosition implements Position {
- private final long value;
-
- CounterPosition(long value) {
- this.value = value;
- }
-
- @Override
- public int compareTo(Position position) {
- return Longs.compare(value, ((CounterPosition) position).value);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/main/java/org/apache/aurora/scheduler/log/testing/FileLogStreamModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/log/testing/FileLogStreamModule.java b/src/main/java/org/apache/aurora/scheduler/log/testing/FileLogStreamModule.java
deleted file mode 100644
index 781414c..0000000
--- a/src/main/java/org/apache/aurora/scheduler/log/testing/FileLogStreamModule.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.log.testing;
-
-import java.io.File;
-import java.util.Objects;
-
-import javax.inject.Singleton;
-
-import com.google.inject.PrivateModule;
-import com.twitter.common.args.Arg;
-import com.twitter.common.args.CmdLine;
-
-import org.apache.aurora.scheduler.log.Log;
-
-/**
- * Binding module that uses a local log file, intended for testing.
- */
-public class FileLogStreamModule extends PrivateModule {
-
- // TODO(William Farner): Make this a required argument and ensure it is not included in production
- // builds (MESOS-471).
- //@NotNull
- @CmdLine(name = "testing_log_file_path", help = "Path to a file to store local log file data in.")
- private static final Arg<File> LOG_PATH = Arg.create(null);
-
- @Override
- protected void configure() {
- Objects.requireNonNull(LOG_PATH.get());
- bind(File.class).toInstance(LOG_PATH.get());
- bind(Log.class).to(FileLog.class);
- bind(FileLog.class).in(Singleton.class);
- expose(Log.class);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/bceac4ec/src/test/java/org/apache/aurora/scheduler/log/testing/FileLogTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/log/testing/FileLogTest.java b/src/test/java/org/apache/aurora/scheduler/log/testing/FileLogTest.java
deleted file mode 100644
index ef8c08c..0000000
--- a/src/test/java/org/apache/aurora/scheduler/log/testing/FileLogTest.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.scheduler.log.testing;
-
-import java.io.File;
-import java.io.IOException;
-
-import com.google.common.io.Files;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertNotNull;
-
-public class FileLogTest {
-
- private File tempDir;
- private File testingLogFile;
-
- @Before
- public void setUp() {
- tempDir = Files.createTempDir();
- testingLogFile = new File(tempDir.getAbsolutePath(), "/log_file");
- }
-
- @After
- public void tearDown() {
- testingLogFile.delete();
- tempDir.delete();
- }
-
- @Test
- public void testNewFile() throws IOException {
- FileLog log = new FileLog(testingLogFile);
- assertNotNull(log.open());
- }
-
- @Test
- public void testEmptyFile() throws IOException {
- testingLogFile.createNewFile();
- FileLog log = new FileLog(testingLogFile);
- assertNotNull(log.open());
- }
-}