use of com.continuuity.weave.api.ResourceSpecification in project weave by continuuity.
the class FailureRestartTestRun method testFailureRestart.
@Test
public void testFailureRestart() throws Exception {
WeaveRunner runner = YarnTestSuite.getWeaveRunner();
ResourceSpecification resource = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(512, ResourceSpecification.SizeUnit.MEGA).setInstances(2).build();
WeaveController controller = runner.prepare(new FailureRunnable(), resource).withApplicationArguments("failure").withArguments(FailureRunnable.class.getSimpleName(), "failure2").addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).start();
Iterable<Discoverable> discoverables = controller.discoverService("failure");
Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 2, 60));
// Make sure we see the right instance IDs
Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));
// Kill server with instanceId = 0
controller.sendCommand(FailureRunnable.class.getSimpleName(), Command.Builder.of("kill0").build());
// Do a shot sleep, make sure the runnable is killed.
TimeUnit.SECONDS.sleep(5);
Assert.assertTrue(YarnTestSuite.waitForSize(discoverables, 2, 60));
// Make sure we see the right instance IDs
Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));
controller.stopAndWait();
}
use of com.continuuity.weave.api.ResourceSpecification in project weave by continuuity.
the class RuntimeSpecificationCodec method deserialize.
@Override
public RuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
WeaveRunnableSpecification runnable = context.deserialize(jsonObj.get("runnable"), WeaveRunnableSpecification.class);
ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), ResourceSpecification.class);
Collection<LocalFile> files = context.deserialize(jsonObj.get("files"), new TypeToken<Collection<LocalFile>>() {
}.getType());
return new DefaultRuntimeSpecification(name, runnable, resources, files);
}
use of com.continuuity.weave.api.ResourceSpecification in project weave by continuuity.
the class ResourceReportTestRun method testResourceReportWithFailingContainers.
@Test
public void testResourceReportWithFailingContainers() throws InterruptedException, IOException, TimeoutException, ExecutionException {
WeaveRunner runner = YarnTestSuite.getWeaveRunner();
ResourceSpecification resourceSpec = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(128, ResourceSpecification.SizeUnit.MEGA).setInstances(2).build();
WeaveController controller = runner.prepare(new BuggyServer(), resourceSpec).addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).withApplicationArguments("echo").withArguments("BuggyServer", "echo2").start();
final CountDownLatch running = new CountDownLatch(1);
controller.addListener(new ServiceListenerAdapter() {
@Override
public void running() {
running.countDown();
}
}, Threads.SAME_THREAD_EXECUTOR);
Assert.assertTrue(running.await(30, TimeUnit.SECONDS));
Iterable<Discoverable> echoServices = controller.discoverService("echo");
Assert.assertTrue(YarnTestSuite.waitForSize(echoServices, 2, 60));
// check that we have 2 runnables.
ResourceReport report = controller.getResourceReport();
Assert.assertEquals(2, report.getRunnableResources("BuggyServer").size());
// cause a divide by 0 in one server
Discoverable discoverable = echoServices.iterator().next();
Socket socket = new Socket(discoverable.getSocketAddress().getAddress(), discoverable.getSocketAddress().getPort());
try {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
writer.println("0");
} finally {
socket.close();
}
// takes some time for app master to find out the container completed...
TimeUnit.SECONDS.sleep(5);
// check that we have 1 runnable, not 2.
report = controller.getResourceReport();
Assert.assertEquals(1, report.getRunnableResources("BuggyServer").size());
controller.stop().get(30, TimeUnit.SECONDS);
// Sleep a bit before exiting.
TimeUnit.SECONDS.sleep(2);
}
use of com.continuuity.weave.api.ResourceSpecification in project weave by continuuity.
the class ResourceReportTestRun method testRunnablesGetAllowedResourcesInEnv.
@Test
public void testRunnablesGetAllowedResourcesInEnv() throws InterruptedException, IOException, TimeoutException, ExecutionException {
WeaveRunner runner = YarnTestSuite.getWeaveRunner();
ResourceSpecification resourceSpec = ResourceSpecification.Builder.with().setVirtualCores(1).setMemory(2048, ResourceSpecification.SizeUnit.MEGA).setInstances(1).build();
WeaveController controller = runner.prepare(new EnvironmentEchoServer(), resourceSpec).addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))).withApplicationArguments("envecho").withArguments("EnvironmentEchoServer", "echo2").start();
final CountDownLatch running = new CountDownLatch(1);
controller.addListener(new ServiceListenerAdapter() {
@Override
public void running() {
running.countDown();
}
}, Threads.SAME_THREAD_EXECUTOR);
Assert.assertTrue(running.await(30, TimeUnit.SECONDS));
Iterable<Discoverable> envEchoServices = controller.discoverService("envecho");
Assert.assertTrue(YarnTestSuite.waitForSize(envEchoServices, 1, 30));
// TODO: check virtual cores once yarn adds the ability
Map<String, String> expectedValues = Maps.newHashMap();
expectedValues.put(EnvKeys.YARN_CONTAINER_MEMORY_MB, "2048");
expectedValues.put(EnvKeys.WEAVE_INSTANCE_COUNT, "1");
// check environment of the runnable.
Discoverable discoverable = envEchoServices.iterator().next();
for (Map.Entry<String, String> expected : expectedValues.entrySet()) {
Socket socket = new Socket(discoverable.getSocketAddress().getHostName(), discoverable.getSocketAddress().getPort());
try {
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
writer.println(expected.getKey());
Assert.assertEquals(expected.getValue(), reader.readLine());
} finally {
socket.close();
}
}
controller.stop().get(30, TimeUnit.SECONDS);
// Sleep a bit before exiting.
TimeUnit.SECONDS.sleep(2);
}
Aggregations