use of com.continuuity.weave.api.WeaveSpecification in project weave by continuuity.
the class WeaveContainerMain method main.
/**
* Main method for launching a {@link WeaveContainerService} which runs
* a {@link com.continuuity.weave.api.WeaveRunnable}.
*/
public static void main(final String[] args) throws Exception {
// Try to load the secure store from localized file, which AM requested RM to localize it for this container.
loadSecureStore();
String zkConnectStr = System.getenv(EnvKeys.WEAVE_ZK_CONNECT);
File weaveSpecFile = new File(Constants.Files.WEAVE_SPEC);
RunId appRunId = RunIds.fromString(System.getenv(EnvKeys.WEAVE_APP_RUN_ID));
RunId runId = RunIds.fromString(System.getenv(EnvKeys.WEAVE_RUN_ID));
String runnableName = System.getenv(EnvKeys.WEAVE_RUNNABLE_NAME);
int instanceId = Integer.parseInt(System.getenv(EnvKeys.WEAVE_INSTANCE_ID));
int instanceCount = Integer.parseInt(System.getenv(EnvKeys.WEAVE_INSTANCE_COUNT));
ZKClientService zkClientService = ZKClientServices.delegate(ZKClients.reWatchOnExpire(ZKClients.retryOnFailure(ZKClientService.Builder.of(zkConnectStr).build(), RetryStrategies.fixDelay(1, TimeUnit.SECONDS))));
DiscoveryService discoveryService = new ZKDiscoveryService(zkClientService);
WeaveSpecification weaveSpec = loadWeaveSpec(weaveSpecFile);
renameLocalFiles(weaveSpec.getRunnables().get(runnableName));
WeaveRunnableSpecification runnableSpec = weaveSpec.getRunnables().get(runnableName).getRunnableSpecification();
ContainerInfo containerInfo = new EnvContainerInfo();
Arguments arguments = decodeArgs();
BasicWeaveContext context = new BasicWeaveContext(runId, appRunId, containerInfo.getHost(), arguments.getRunnableArguments().get(runnableName).toArray(new String[0]), arguments.getArguments().toArray(new String[0]), runnableSpec, instanceId, discoveryService, instanceCount, containerInfo.getMemoryMB(), containerInfo.getVirtualCores());
Configuration conf = new YarnConfiguration(new HdfsConfiguration(new Configuration()));
Service service = new WeaveContainerService(context, containerInfo, getContainerZKClient(zkClientService, appRunId, runnableName), runId, runnableSpec, getClassLoader(), createAppLocation(conf));
new WeaveContainerMain().doMain(zkClientService, service);
}
use of com.continuuity.weave.api.WeaveSpecification in project weave by continuuity.
the class WeaveSpecificationTest method testAnyOrder.
@Test
public void testAnyOrder() {
WeaveSpecification spec = WeaveSpecification.Builder.with().setName("Testing").withRunnable().add("r1", new DummyRunnable()).noLocalFiles().add("r2", new DummyRunnable()).noLocalFiles().add("r3", new DummyRunnable()).noLocalFiles().anyOrder().build();
Assert.assertEquals(3, spec.getRunnables().size());
List<WeaveSpecification.Order> orders = spec.getOrders();
Assert.assertEquals(1, orders.size());
Assert.assertEquals(ImmutableSet.of("r1", "r2", "r3"), orders.get(0).getNames());
}
use of com.continuuity.weave.api.WeaveSpecification in project weave by continuuity.
the class WeaveSpecificationCodec method serialize.
@Override
public JsonElement serialize(WeaveSpecification src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("name", src.getName());
json.add("runnables", context.serialize(src.getRunnables(), new TypeToken<Map<String, RuntimeSpecification>>() {
}.getType()));
json.add("orders", context.serialize(src.getOrders(), new TypeToken<List<WeaveSpecification.Order>>() {
}.getType()));
EventHandlerSpecification eventHandler = src.getEventHandler();
if (eventHandler != null) {
json.add("handler", context.serialize(eventHandler, EventHandlerSpecification.class));
}
return json;
}
use of com.continuuity.weave.api.WeaveSpecification in project weave by continuuity.
the class YarnWeaveRunnerService method prepare.
@Override
public WeavePreparer prepare(WeaveApplication application) {
Preconditions.checkState(isRunning(), "Service not start. Please call start() first.");
final WeaveSpecification weaveSpec = application.configure();
final String appName = weaveSpec.getName();
return new YarnWeavePreparer(yarnConfig, weaveSpec, yarnAppClient, zkClientService, locationFactory, Suppliers.ofInstance(jvmOptions), new YarnWeaveControllerFactory() {
@Override
public YarnWeaveController create(RunId runId, Iterable<LogHandler> logHandlers, Callable<ProcessController<YarnApplicationReport>> startUp) {
ZKClient zkClient = ZKClients.namespace(zkClientService, "/" + appName);
YarnWeaveController controller = listenController(new YarnWeaveController(runId, zkClient, logHandlers, startUp));
synchronized (YarnWeaveRunnerService.this) {
Preconditions.checkArgument(!controllers.contains(appName, runId), "Application %s with runId %s is already running.", appName, runId);
controllers.put(appName, runId, controller);
}
return controller;
}
});
}
use of com.continuuity.weave.api.WeaveSpecification in project weave by continuuity.
the class WeaveSpecificationTest method testOrder.
@Test
public void testOrder() {
WeaveSpecification spec = WeaveSpecification.Builder.with().setName("Testing").withRunnable().add("r1", new DummyRunnable()).noLocalFiles().add("r2", new DummyRunnable()).noLocalFiles().add("r3", new DummyRunnable()).noLocalFiles().add("r4", new DummyRunnable()).noLocalFiles().withOrder().begin("r1", "r2").nextWhenStarted("r3").build();
Assert.assertEquals(4, spec.getRunnables().size());
List<WeaveSpecification.Order> orders = spec.getOrders();
Assert.assertEquals(3, orders.size());
Assert.assertEquals(ImmutableSet.of("r1", "r2"), orders.get(0).getNames());
Assert.assertEquals(ImmutableSet.of("r3"), orders.get(1).getNames());
Assert.assertEquals(ImmutableSet.of("r4"), orders.get(2).getNames());
}
Aggregations