You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@reef.apache.org by we...@apache.org on 2015/01/23 00:47:05 UTC
[32/51] [partial] incubator-reef git commit: [REEF-93] Move java
sources to lang/java
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties b/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
new file mode 100644
index 0000000..a5ab8dc
--- /dev/null
+++ b/lang/java/reef-common/src/main/resources/org/apache/reef/logging.properties
@@ -0,0 +1,85 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+# Properties file which configures the operation of the JDK
+# logging facility.
+
+# The system will look for this config file, first using
+# a System property specified at startup:
+#
+# >java -Djava.utils.logging.config.file=myLoggingConfigFilePath
+#
+# If this property is not specified, then the config file is
+# retrieved from its default location at:
+#
+# JDK_HOME/jre/lib/logging.properties
+
+# Global logging properties.
+# ------------------------------------------
+# The set of handlers to be loaded upon startup.
+# Comma-separated list of class names.
+# (? LogManager docs say no comma here, but JDK example has comma.)
+# handlers=java.utils.logging.FileHandler, java.utils.logging.ConsoleHandler
+handlers=java.util.logging.ConsoleHandler
+
+# java.util.logging.SimpleFormatter.format=%1$tF %1$tT,%1$tL %4$s %2$s - %5$s%6$s%n
+
+org.apache.reef.util.logging.ThreadLogFormatter.format=%1$tF %1$tT,%1$tL %4$s %2$s %7$s | %5$s%6$s%n
+org.apache.reef.util.logging.ThreadLogFormatter.dropPrefix=com.microsoft.,org.apache.
+
+# Default global logging level.
+# Loggers and Handlers may override this level
+.level=ALL
+
+# Loggers
+# ------------------------------------------
+# Loggers are usually attached to packages.
+# Here, the level for each package is specified.
+# The global level is used by default, so levels
+# specified here simply act as an override.
+
+# org.apache.reef.examples.level=FINEST
+# org.apache.reef.tang.level=INFO
+
+# Handlers
+# -----------------------------------------
+
+# --- ConsoleHandler ---
+# Override of global logging level
+java.util.logging.ConsoleHandler.level=FINEST
+java.util.logging.ConsoleHandler.formatter=org.apache.reef.util.logging.ThreadLogFormatter
+
+# --- FileHandler ---
+# Override of global logging level
+java.util.logging.FileHandler.level=FINEST
+
+# Naming style for the output file:
+# (The output file is placed in the directory
+# defined by the "user.home" System property.)
+java.util.logging.FileHandler.pattern=%h/reef.%u.log
+
+# Limiting size of output file in bytes:
+java.util.logging.FileHandler.limit=512000
+
+# Number of output files to cycle through, by appending an
+# integer to the base file name:
+java.util.logging.FileHandler.count=100
+
+# Style of output (Simple or XML):
+java.util.logging.FileHandler.formatter=org.apache.reef.util.logging.ThreadLogFormatter
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/main/resources/version.properties
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/main/resources/version.properties b/lang/java/reef-common/src/main/resources/version.properties
new file mode 100644
index 0000000..846f2a0
--- /dev/null
+++ b/lang/java/reef-common/src/main/resources/version.properties
@@ -0,0 +1,18 @@
+ # Licensed to the Apache Software Foundation (ASF) under one
+ # or more contributor license agreements. See the NOTICE file
+ # distributed with this work for additional information
+ # regarding copyright ownership. The ASF licenses this file
+ # to you 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.
+
+version=${pom.version}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
new file mode 100644
index 0000000..ddbd83b
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/EvaluatorRequestorImplTest.java
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.runtime.common.driver;
+
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.apache.reef.runtime.common.driver.api.ResourceRequestHandler;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.logging.LoggingScopeFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Tests for EvaluatorRequestorImpl.
+ */
+public class EvaluatorRequestorImplTest {
+ private final ResourceCatalog resourceCatalog = mock(ResourceCatalog.class);
+ private LoggingScopeFactory loggingScopeFactory;
+
+ @Before
+ public void setUp() throws InjectionException {
+ loggingScopeFactory = Tang.Factory.getTang().newInjector().getInstance(LoggingScopeFactory.class);
+ }
+
+ /**
+ * If only memory, no count is given, 1 evaluator should be requested.
+ */
+ @Test
+ public void testMemoryOnly() {
+ final int memory = 777;
+ final DummyRequestHandler requestHandler = new DummyRequestHandler();
+ final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+ evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).build());
+ Assert.assertEquals("Memory request did not make it", requestHandler.get().getMemorySize(), memory);
+ Assert.assertEquals("Number of requests did not make it", requestHandler.get().getResourceCount(), 1);
+ }
+
+ /**
+ * Checks whether memory and count make it correctly.
+ */
+ @Test
+ public void testMemoryAndCount() {
+ final int memory = 777;
+ final int count = 9;
+ final DummyRequestHandler requestHandler = new DummyRequestHandler();
+ final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+ evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumber(count).build());
+ Assert.assertEquals("Memory request did not make it", requestHandler.get().getMemorySize(), memory);
+ Assert.assertEquals("Number of requests did not make it", requestHandler.get().getResourceCount(), count);
+ }
+
+ /**
+ * Expect an IllegalArgumentException when a non-positive memory amount is passed.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testIllegalMemory() {
+ final int memory = 0;
+ final int count = 1;
+ final DummyRequestHandler requestHandler = new DummyRequestHandler();
+ final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+ evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumberOfCores(1).setNumber(count).build());
+ }
+
+ /**
+ * Expect an IllegalArgumentException when a non-positive evaluator count is passed.
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testIllegalCount() {
+ final int memory = 128;
+ final int count = 0;
+ final DummyRequestHandler requestHandler = new DummyRequestHandler();
+ final EvaluatorRequestor evaluatorRequestor = new EvaluatorRequestorImpl(resourceCatalog, requestHandler, loggingScopeFactory);
+ evaluatorRequestor.submit(EvaluatorRequest.newBuilder().setMemory(memory).setNumberOfCores(1).setNumber(count).build());
+ }
+
+ private class DummyRequestHandler implements ResourceRequestHandler {
+ private DriverRuntimeProtocol.ResourceRequestProto request;
+
+ @Override
+ public void onNext(DriverRuntimeProtocol.ResourceRequestProto resourceRequestProto) {
+ this.request = resourceRequestProto;
+ }
+
+ public DriverRuntimeProtocol.ResourceRequestProto get() {
+ return this.request;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
new file mode 100644
index 0000000..66203b2
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/runtime/common/driver/catalog/CatalogTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.runtime.common.driver.catalog;
+
+import org.apache.reef.proto.DriverRuntimeProtocol;
+import org.junit.Assert;
+import org.junit.Test;
+
+public final class CatalogTest {
+
+
+ /**
+ * Basic catalog test that addes some nodes and checks
+ * that they exist.
+ */
+ @Test
+ public final void TestResourceCatalog() {
+ final int nodes = 10;
+ final ResourceCatalogImpl catalog = new ResourceCatalogImpl();
+
+ for (int i = 0; i < nodes; i++) {
+ catalog.handle(DriverRuntimeProtocol.NodeDescriptorProto.newBuilder()
+ .setRackName("test-rack")
+ .setHostName("test-" + i)
+ .setPort(0)
+ .setIdentifier("test-" + i)
+ .setMemorySize(512)
+ .build());
+ }
+
+ for (int i = 0; i < nodes; i++) {
+ Assert.assertNotNull(catalog.getNode("test-" + i));
+ }
+
+ Assert.assertTrue(catalog.getRacks().size() == 1);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
new file mode 100644
index 0000000..fdb2aa1
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/util/LoggingScopeTest.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.util;
+
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.ExternalConstructor;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.util.logging.*;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.inject.Inject;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Test LoggingScope
+ */
+public class LoggingScopeTest {
+
+ private LoggingScopeFactory logFactory;
+
+ @Before
+ public void setUp() throws InjectionException {
+ final ConfigurationBuilder b = Tang.Factory.getTang().newConfigurationBuilder()
+ .bindNamedParameter(LogLevelName.class, "INFO");
+
+ final Injector i = Tang.Factory.getTang().newInjector(b.build());
+ logFactory = i.getInstance(LoggingScopeFactory.class);
+ }
+
+ /**
+ * Test getNewLoggingScope() in LoggingScopeFactory that injects LoggingScope object
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testGetNewLoggingScope() throws InjectionException {
+ try (final LoggingScope ls = logFactory.getNewLoggingScope("test")) {
+ Assert.assertTrue(true);
+ }
+ }
+
+ /**
+ * Test getNewLoggingScope() in LoggingScopeFactory that injects LoggingScope object with param as a parameter
+ * @throws InjectionException
+ */
+ @Test
+ public void testGetNewLoggingScopeWithParam() throws InjectionException {
+ try (final LoggingScope ls = logFactory.getNewLoggingScope("test first string = {0}, second = {1}", new Object[] { "first", "second" })) {
+ Assert.assertTrue(true);
+ }
+ }
+
+ /**
+ * Test calling predefined method in LoggingScopeFactory
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testLoggingScopeFactory() {
+ try (final LoggingScope ls = logFactory.activeContextReceived("test")) {
+ Assert.assertTrue(true);
+ }
+ }
+
+ /**
+ * Use default log level in injecting LoggingScopeFactory constructor
+ * @throws InjectionException
+ */
+ @Test
+ public void testLoggingScopeFactoryWithDefaultLogLevel() throws InjectionException {
+ final Injector i = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
+ final LoggingScopeFactory logFactory = i.getInstance(LoggingScopeFactory.class);
+
+ try (final LoggingScope ls = logFactory.activeContextReceived("test")) {
+ Assert.assertTrue(true);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java b/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
new file mode 100644
index 0000000..5cecec6
--- /dev/null
+++ b/lang/java/reef-common/src/test/java/org/apache/reef/util/SingletonAsserterTest.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public final class SingletonAsserterTest {
+
+ @Test
+ public void testSingletonAsserter() {
+ Assert.assertTrue(SingletonAsserter.assertSingleton(SingletonAsserterTest.class));
+ Assert.assertTrue(SingletonAsserter.assertSingleton(List.class));
+ Assert.assertFalse(SingletonAsserter.assertSingleton(List.class));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/pom.xml b/lang/java/reef-examples-clr/pom.xml
new file mode 100644
index 0000000..94bda88
--- /dev/null
+++ b/lang/java/reef-examples-clr/pom.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>reef-examples-clr</artifactId>
+ <name>REEF Examples CLR</name>
+ <description>Examples that use the JVM/CLR interop of REEF.</description>
+
+ <parent>
+ <groupId>org.apache.reef</groupId>
+ <artifactId>reef-project</artifactId>
+ <version>0.11.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <dependencies>
+ <!-- REEF -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-runtime-local</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-runtime-yarn</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-io</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-checkpoint</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-webserver</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-examples</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- End of REEF -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <outputFile>
+ ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+ </outputFile>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>yarn-default.xml</exclude>
+ <exclude>yarn-version-info.properties</exclude>
+ <exclude>core-default.xml</exclude>
+ <exclude>LICENSE</exclude>
+ <exclude>META-INF/*</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+ <profiles>
+
+
+ <profile>
+ <id>RetainedEvalCLR</id>
+ <build>
+ <defaultGoal>exec:exec</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <configuration>
+ <executable>java</executable>
+ <arguments>
+ <argument>-classpath</argument>
+ <classpath/>
+ <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+ </argument>
+ <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+ </argument>
+ <argument>org.apache.reef.examples.retained_evalCLR.Launch</argument>
+ <argument>dotnetDistributedShell</argument>
+ <!-- <argument>-cmd</argument>
+ <argument>date</argument>
+ <argument>-num_runs</argument>
+ <argument>20</argument>
+ <argument>-local</argument>
+ <argument>true</argument> -->
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ <profile>
+ <id>HelloCLR</id>
+ <build>
+ <defaultGoal>exec:exec</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <configuration>
+ <executable>java</executable>
+ <arguments>
+ <argument>-classpath</argument>
+ <classpath/>
+ <argument>-Djava.util.logging.config.class=org.apache.reef.util.logging.Config
+ </argument>
+ <!-- <argument>-Dlog4j.debug=true</argument> -->
+ <argument>-Dcom.microsoft.reef.runtime.local.folder=${project.build.directory}
+ </argument>
+ <argument>org.apache.reef.examples.helloCLR.HelloCLR</argument>
+ <argument>dotnetHello</argument>
+ </arguments>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
new file mode 100644
index 0000000..f8ff247
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloCLR.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.helloCLR;
+
+import org.apache.reef.client.DriverConfiguration;
+import org.apache.reef.client.DriverLauncher;
+import org.apache.reef.client.LauncherStatus;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+import org.apache.reef.util.EnvironmentUtils;
+
+import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Client for Hello REEF example.
+ */
+public final class HelloCLR {
+
+ /**
+ * The name of the class hierarchy file.
+ */
+ // TODO: Make this a config option
+ public static final String CLASS_HIERARCHY_FILENAME = "HelloTask.bin";
+
+ private static final Logger LOG = Logger.getLogger(HelloCLR.class.getName());
+
+ /**
+ * Number of milliseconds to wait for the job to complete.
+ */
+ private static final int JOB_TIMEOUT = 1000000; // 1000 sec.
+
+ private static ConfigurationModule addAll(final ConfigurationModule conf, final OptionalParameter<String> param, final File folder) {
+ ConfigurationModule result = conf;
+ for (final File f : folder.listFiles()) {
+ if (f.canRead() && f.exists() && f.isFile()) {
+ result = result.set(param, f.getAbsolutePath());
+ }
+ }
+ return result;
+ }
+
+ public static LauncherStatus runHelloCLR(final Configuration runtimeConf, final int timeOut, final File clrFolder)
+ throws BindException, InjectionException {
+
+ ConfigurationModule driverConf =
+ addAll(DriverConfiguration.CONF, DriverConfiguration.GLOBAL_FILES, clrFolder)
+ .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(HelloDriver.class))
+ .set(DriverConfiguration.DRIVER_IDENTIFIER, "HelloCLR")
+ .set(DriverConfiguration.ON_DRIVER_STARTED, HelloDriver.StartHandler.class)
+ .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, HelloDriver.EvaluatorAllocatedHandler.class);
+
+ return DriverLauncher.getLauncher(runtimeConf).run(driverConf.build(), timeOut);
+ }
+
+ /**
+ * Start Hello REEF job. Runs method runHelloReef().
+ *
+ * @param args command line parameters.
+ * @throws org.apache.reef.tang.exceptions.BindException configuration error.
+ * @throws org.apache.reef.tang.exceptions.InjectionException configuration error.
+ */
+ public static void main(final String[] args) throws BindException, InjectionException {
+ final Configuration runtimeConfiguration = LocalRuntimeConfiguration.CONF
+ .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, 2)
+ .build();
+
+ final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+ final LauncherStatus status = runHelloCLR(runtimeConfiguration, JOB_TIMEOUT, dotNetFolder);
+ LOG.log(Level.INFO, "REEF job completed: {0}", status);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
new file mode 100644
index 0000000..74fb131
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/HelloDriver.java
@@ -0,0 +1,183 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.helloCLR;
+
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.evaluator.AllocatedEvaluator;
+import org.apache.reef.driver.evaluator.EvaluatorRequest;
+import org.apache.reef.driver.evaluator.EvaluatorRequestor;
+import org.apache.reef.driver.evaluator.EvaluatorType;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.hello.HelloTask;
+import org.apache.reef.tang.ClassHierarchy;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.ConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.time.event.StartTime;
+
+import javax.inject.Inject;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * The Driver code for the Hello REEF Application
+ */
+@Unit
+public final class HelloDriver {
+
+ private static final Logger LOG = Logger.getLogger(HelloDriver.class.getName());
+
+ private final EvaluatorRequestor requestor;
+
+ private int nJVMTasks = 1; // guarded by this
+ private int nCLRTasks = 1; // guarded by this
+
+
+ /**
+ * Job driver constructor - instantiated via TANG.
+ *
+ * @param requestor evaluator requestor object used to create new evaluator containers.
+ */
+ @Inject
+ public HelloDriver(final EvaluatorRequestor requestor) {
+ this.requestor = requestor;
+ }
+
+ /**
+ * Makes a task configuration for the CLR Task.
+ *
+ * @param taskId
+ * @return task configuration for the CLR Task.
+ * @throws BindException
+ */
+ private static final Configuration getCLRTaskConfiguration(final String taskId) throws BindException {
+ final ConfigurationBuilder taskConfigurationBuilder = Tang.Factory.getTang()
+ .newConfigurationBuilder(loadClassHierarchy());
+ taskConfigurationBuilder.bind("Microsoft.Reef.Tasks.TaskConfigurationOptions+Identifier, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", taskId);
+ taskConfigurationBuilder.bind("Microsoft.Reef.Tasks.ITask, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", "Microsoft.Reef.Tasks.HelloTask, Microsoft.Reef.Tasks.HelloTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+
+ return taskConfigurationBuilder.build();
+ }
+
+ /**
+ * Loads the class hierarchy.
+ *
+ * @return
+ */
+ private static ClassHierarchy loadClassHierarchy() {
+ try (final InputStream chin = new FileInputStream(HelloCLR.CLASS_HIERARCHY_FILENAME)) {
+ final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin); // A
+ final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+ return ch;
+ } catch (final IOException e) {
+ final String message = "Unable to load class hierarchy.";
+ LOG.log(Level.SEVERE, message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ /**
+ * Uses the AllocatedEvaluator to launch a CLR task.
+ *
+ * @param allocatedEvaluator
+ */
+ final void onNextCLR(final AllocatedEvaluator allocatedEvaluator) {
+ try {
+ allocatedEvaluator.setType(EvaluatorType.CLR);
+ final Configuration contextConfiguration = ContextConfiguration.CONF
+ .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
+ .build();
+
+ final Configuration taskConfiguration = getCLRTaskConfiguration("Hello_From_CLR");
+
+ allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
+ } catch (final BindException ex) {
+ final String message = "Unable to setup Task or Context configuration.";
+ LOG.log(Level.SEVERE, message, ex);
+ throw new RuntimeException(message, ex);
+ }
+ }
+
+ /**
+ * Uses the AllocatedEvaluator to launch a JVM task.
+ *
+ * @param allocatedEvaluator
+ */
+ final void onNextJVM(final AllocatedEvaluator allocatedEvaluator) {
+ try {
+ allocatedEvaluator.setType(EvaluatorType.JVM);
+ final Configuration contextConfiguration = ContextConfiguration.CONF
+ .set(ContextConfiguration.IDENTIFIER, "HelloREEFContext")
+ .build();
+
+ final Configuration taskConfiguration = TaskConfiguration.CONF
+ .set(TaskConfiguration.IDENTIFIER, "HelloREEFTask")
+ .set(TaskConfiguration.TASK, HelloTask.class)
+ .build();
+
+ allocatedEvaluator.submitContextAndTask(contextConfiguration, taskConfiguration);
+ } catch (final BindException ex) {
+ final String message = "Unable to setup Task or Context configuration.";
+ LOG.log(Level.SEVERE, message, ex);
+ throw new RuntimeException(message, ex);
+ }
+ }
+
+ /**
+ * Handles the StartTime event: Request as single Evaluator.
+ */
+ final class StartHandler implements EventHandler<StartTime> {
+ @Override
+ public void onNext(final StartTime startTime) {
+ LOG.log(Level.INFO, "StartTime: ", startTime);
+ HelloDriver.this.requestor.submit(EvaluatorRequest.newBuilder()
+ .setNumber(nCLRTasks + nJVMTasks)
+ .setMemory(128)
+ .setNumberOfCores(1)
+ .build());
+ }
+ }
+
+ /**
+ * Handles AllocatedEvaluator: Submit an empty context and the HelloTask
+ */
+ final class EvaluatorAllocatedHandler implements EventHandler<AllocatedEvaluator> {
+ @Override
+ public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+ synchronized (HelloDriver.this) {
+ if (HelloDriver.this.nJVMTasks > 0) {
+ HelloDriver.this.onNextJVM(allocatedEvaluator);
+ HelloDriver.this.nJVMTasks -= 1;
+ } else if (HelloDriver.this.nCLRTasks > 0) {
+ HelloDriver.this.onNextCLR(allocatedEvaluator);
+ HelloDriver.this.nCLRTasks -= 1;
+ }
+ }
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
new file mode 100644
index 0000000..bf381b1
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/helloCLR/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+/**
+ * The Hello REEF example for the CLR.
+ */
+package org.apache.reef.examples.helloCLR;
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
new file mode 100644
index 0000000..8823c87
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobClient.java
@@ -0,0 +1,317 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.client.*;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.annotations.Parameter;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.util.EnvironmentUtils;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+
+import javax.inject.Inject;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator Shell Client.
+ */
+@Unit
+public class JobClient {
+
+ /**
+ * Standard java logger.
+ */
+ private static final Logger LOG = Logger.getLogger(JobClient.class.getName());
+
+ /**
+ * Codec to translate messages to and from the job driver
+ */
+ private static final ObjectSerializableCodec<String> CODEC = new ObjectSerializableCodec<>();
+
+ /**
+ * Reference to the REEF framework.
+ * This variable is injected automatically in the constructor.
+ */
+ private final REEF reef;
+
+ /**
+ * Shell command to submitTask to the job driver.
+ */
+ private final String command;
+ /**
+ * If true, take commands from stdin; otherwise, use -cmd parameter in batch mode.
+ */
+ private final boolean isInteractive;
+ /**
+ * Total number of experiments to run.
+ */
+ private final int maxRuns;
+ /**
+ * Command prompt reader for the interactive mode (stdin).
+ */
+ private final BufferedReader prompt;
+ /**
+ * Job Driver configuration.
+ */
+ private Configuration driverConfiguration;
+ private ConfigurationModule driverConfigModule;
+ /**
+ * A reference to the running job that allows client to send messages back to the job driver
+ */
+ private RunningJob runningJob;
+
+ /**
+ * Start timestamp of the current task.
+ */
+ private long startTime = 0;
+
+ /**
+ * Total time spent performing tasks in Evaluators.
+ */
+ private long totalTime = 0;
+
+ /**
+ * Number of experiments ran so far.
+ */
+ private int numRuns = 0;
+
+ /**
+ * Set to false when job driver is done.
+ */
+ private boolean isBusy = true;
+
+ /**
+ * Retained Evaluator client.
+ * Parameters are injected automatically by TANG.
+ *
+ * @param command Shell command to run on each Evaluator.
+ * @param reef Reference to the REEF framework.
+ */
+ @Inject
+ JobClient(final REEF reef,
+ @Parameter(Launch.Command.class) final String command,
+ @Parameter(Launch.NumRuns.class) final Integer numRuns) throws BindException {
+
+ this.reef = reef;
+ this.command = command;
+ this.maxRuns = numRuns;
+
+ // If command is not set, switch to interactive mode. (Yes, we compare pointers here)
+ this.isInteractive = this.command ==
+ Launch.Command.class.getAnnotation(NamedParameter.class).default_value();
+
+ this.prompt = this.isInteractive ? new BufferedReader(new InputStreamReader(System.in)) : null;
+
+ this.driverConfigModule = DriverConfiguration.CONF
+ .set(DriverConfiguration.GLOBAL_LIBRARIES, EnvironmentUtils.getClassLocation(JobDriver.class))
+ .set(DriverConfiguration.DRIVER_IDENTIFIER, "eval-" + System.currentTimeMillis())
+ .set(DriverConfiguration.ON_EVALUATOR_ALLOCATED, JobDriver.AllocatedEvaluatorHandler.class)
+ .set(DriverConfiguration.ON_EVALUATOR_FAILED, JobDriver.FailedEvaluatorHandler.class)
+ .set(DriverConfiguration.ON_CONTEXT_ACTIVE, JobDriver.ActiveContextHandler.class)
+ .set(DriverConfiguration.ON_CONTEXT_CLOSED, JobDriver.ClosedContextHandler.class)
+ .set(DriverConfiguration.ON_CONTEXT_FAILED, JobDriver.FailedContextHandler.class)
+ .set(DriverConfiguration.ON_TASK_COMPLETED, JobDriver.CompletedTaskHandler.class)
+ .set(DriverConfiguration.ON_CLIENT_MESSAGE, JobDriver.ClientMessageHandler.class)
+ .set(DriverConfiguration.ON_DRIVER_STARTED, JobDriver.StartHandler.class)
+ .set(DriverConfiguration.ON_DRIVER_STOP, JobDriver.StopHandler.class);
+ }
+
+ private void addCLRFiles(final File folder) throws BindException {
+ ConfigurationModule result = this.driverConfigModule;
+ for (final File f : folder.listFiles()) {
+ if (f.canRead() && f.exists() && f.isFile()) {
+ result = result.set(DriverConfiguration.GLOBAL_FILES, f.getAbsolutePath());
+ }
+ }
+
+ this.driverConfigModule = result;
+ this.driverConfiguration = this.driverConfigModule.build();
+ }
+
+ /**
+ * Launch the job driver.
+ *
+ * @throws BindException configuration error.
+ */
+ public void submit(File clrFolder) {
+ try {
+ addCLRFiles(clrFolder);
+ } catch (final BindException e) {
+ LOG.log(Level.FINE, "Failed to bind", e);
+ }
+ this.reef.submit(this.driverConfiguration);
+ }
+
+ /**
+ * Send command to the job driver. Record timestamp when the command was sent.
+ * If this.command is set, use it; otherwise, ask user for the command.
+ */
+ private synchronized void submitTask() {
+ if (this.isInteractive) {
+ String cmd;
+ try {
+ do {
+ System.out.print("\nRE> ");
+ cmd = this.prompt.readLine();
+ } while (cmd != null && cmd.trim().isEmpty());
+ } catch (final IOException ex) {
+ LOG.log(Level.FINE, "Error reading from stdin: {0}", ex);
+ cmd = null;
+ }
+ if (cmd == null || cmd.equals("exit")) {
+ this.runningJob.close();
+ stopAndNotify();
+ } else {
+ this.submitTask(cmd);
+ }
+ } else {
+ // non-interactive batch mode:
+ this.submitTask(this.command);
+ }
+ }
+
+ /**
+ * Send command to the job driver. Record timestamp when the command was sent.
+ *
+ * @param cmd shell command to execute in all Evaluators.
+ */
+ private synchronized void submitTask(final String cmd) {
+ LOG.log(Level.INFO, "Submit task {0} \"{1}\" to {2}",
+ new Object[]{this.numRuns + 1, cmd, this.runningJob});
+ this.startTime = System.currentTimeMillis();
+ this.runningJob.send(CODEC.encode(cmd));
+ }
+
+ /**
+ * Notify the process in waitForCompletion() method that the main process has finished.
+ */
+ private synchronized void stopAndNotify() {
+ this.runningJob = null;
+ this.isBusy = false;
+ this.notify();
+ }
+
+ /**
+ * Wait for the job driver to complete. This method is called from Launcher.main()
+ */
+ public void waitForCompletion() {
+ while (this.isBusy) {
+ LOG.info("Waiting for the Job Driver to complete.");
+ try {
+ synchronized (this) {
+ this.wait();
+ }
+ } catch (final InterruptedException ex) {
+ LOG.log(Level.WARNING, "Waiting for result interrupted.", ex);
+ }
+ }
+ this.reef.close();
+ }
+
+ /**
+ * Receive notification from the job driver that the job is running.
+ */
+ final class RunningJobHandler implements EventHandler<RunningJob> {
+ @Override
+ public void onNext(final RunningJob job) {
+ LOG.log(Level.INFO, "Running job: {0}", job.getId());
+ synchronized (JobClient.this) {
+ JobClient.this.runningJob = job;
+ JobClient.this.submitTask();
+ }
+ }
+ }
+
+ /**
+ * Receive message from the job driver.
+ * There is only one message, which comes at the end of the driver execution
+ * and contains shell command output on each node.
+ */
+ final class JobMessageHandler implements EventHandler<JobMessage> {
+ @Override
+ public void onNext(final JobMessage message) {
+ synchronized (JobClient.this) {
+
+ final String result = CODEC.decode(message.get());
+ final long jobTime = System.currentTimeMillis() - startTime;
+ totalTime += jobTime;
+ ++numRuns;
+
+ LOG.log(Level.INFO, "Task {0} completed in {1} msec.:\n{2}",
+ new Object[]{numRuns, jobTime, result});
+
+ System.out.println(result);
+
+ if (runningJob != null) {
+ if (isInteractive || numRuns < maxRuns) {
+ submitTask();
+ } else {
+ LOG.log(Level.INFO,
+ "All {0} tasks complete; Average task time: {1}. Closing the job driver.",
+ new Object[]{maxRuns, totalTime / (double) maxRuns});
+ runningJob.close();
+ stopAndNotify();
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Receive notification from the job driver that the job had failed.
+ */
+ final class FailedJobHandler implements EventHandler<FailedJob> {
+ @Override
+ public void onNext(final FailedJob job) {
+ LOG.log(Level.SEVERE, "Failed job: " + job.getId(), job.getReason().orElse(null));
+ stopAndNotify();
+ }
+ }
+
+ /**
+ * Receive notification from the job driver that the job had completed successfully.
+ */
+ final class CompletedJobHandler implements EventHandler<CompletedJob> {
+ @Override
+ public void onNext(final CompletedJob job) {
+ LOG.log(Level.INFO, "Completed job: {0}", job.getId());
+ stopAndNotify();
+ }
+ }
+
+ /**
+ * Receive notification that there was an exception thrown from the job driver.
+ */
+ final class RuntimeErrorHandler implements EventHandler<FailedRuntime> {
+ @Override
+ public void onNext(final FailedRuntime error) {
+ LOG.log(Level.SEVERE, "Error in job driver: " + error, error.getReason().orElse(null));
+ stopAndNotify();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
new file mode 100644
index 0000000..8b798cd
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/JobDriver.java
@@ -0,0 +1,489 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.driver.catalog.ResourceCatalog;
+import org.apache.reef.driver.client.JobMessageObserver;
+import org.apache.reef.driver.context.ActiveContext;
+import org.apache.reef.driver.context.ClosedContext;
+import org.apache.reef.driver.context.ContextConfiguration;
+import org.apache.reef.driver.context.FailedContext;
+import org.apache.reef.driver.evaluator.*;
+import org.apache.reef.driver.task.CompletedTask;
+import org.apache.reef.driver.task.TaskConfiguration;
+import org.apache.reef.examples.library.Command;
+import org.apache.reef.examples.library.ShellTask;
+import org.apache.reef.tang.*;
+import org.apache.reef.tang.annotations.Unit;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.implementation.protobuf.ProtocolBufferClassHierarchy;
+import org.apache.reef.tang.proto.ClassHierarchyProto;
+import org.apache.reef.wake.EventHandler;
+import org.apache.reef.wake.remote.impl.ObjectSerializableCodec;
+import org.apache.reef.wake.time.Clock;
+import org.apache.reef.wake.time.event.Alarm;
+import org.apache.reef.wake.time.event.StartTime;
+import org.apache.reef.wake.time.event.StopTime;
+
+import javax.inject.Inject;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluator example job driver. Execute shell command on all evaluators,
+ * capture stdout, and return concatenated results back to the client.
+ */
+@Unit
+public final class JobDriver {
+ public static final String SHELL_TASK_CLASS_HIERARCHY_FILENAME = "ShellTask.bin";
+ /**
+ * Standard Java logger.
+ */
+ private static final Logger LOG = Logger.getLogger(JobDriver.class.getName());
+ /**
+ * Duration of one clock interval.
+ */
+ private static final int CHECK_UP_INTERVAL = 1000; // 1 sec.
+ private static final String JVM_CONTEXT_SUFFIX = "_JVMContext";
+ private static final String CLR_CONTEXT_SUFFIX = "_CLRContext";
+ /**
+ * String codec is used to encode the results
+ * before passing them back to the client.
+ */
+ private static final ObjectSerializableCodec<String> JVM_CODEC = new ObjectSerializableCodec<>();
+ public static int totalEvaluators = 2;
+ /**
+ * Wake clock is used to schedule periodical job check-ups.
+ */
+ private final Clock clock;
+ /**
+ * Job observer on the client.
+ * We use it to send results from the driver back to the client.
+ */
+ private final JobMessageObserver jobMessageObserver;
+ /**
+ * Job driver uses EvaluatorRequestor
+ * to request Evaluators that will run the Tasks.
+ */
+ private final EvaluatorRequestor evaluatorRequestor;
+ /**
+ * Static catalog of REEF resources.
+ * We use it to schedule Task on every available node.
+ */
+ private final ResourceCatalog catalog;
+ /**
+ * Shell execution results from each Evaluator.
+ */
+ private final List<String> results = new ArrayList<>();
+ /**
+ * Map from context ID to running evaluator context.
+ */
+ private final Map<String, ActiveContext> contexts = new HashMap<>();
+ private int nCLREvaluator = 1; // guarded by this
+ private int nJVMEvaluator = totalEvaluators - nCLREvaluator; // guarded by this
+ /**
+ * Job driver state.
+ */
+ private State state = State.INIT;
+ /**
+ * First command to execute. Sometimes client can send us the first command
+ * before Evaluators are available; we need to store this command here.
+ */
+ private String cmd;
+ /**
+ * Number of evaluators/tasks to complete.
+ */
+ private int expectCount = 0;
+
+ /**
+ * Job driver constructor.
+ * All parameters are injected from TANG automatically.
+ *
+ * @param clock Wake clock to schedule and check up running jobs.
+ * @param jobMessageObserver is used to send messages back to the client.
+ * @param evaluatorRequestor is used to request Evaluators.
+ */
+ @Inject
+ JobDriver(final Clock clock,
+ final JobMessageObserver jobMessageObserver,
+ final EvaluatorRequestor evaluatorRequestor,
+ final ResourceCatalog catalog) {
+ this.clock = clock;
+ this.jobMessageObserver = jobMessageObserver;
+ this.evaluatorRequestor = evaluatorRequestor;
+ this.catalog = catalog;
+ }
+
+ /**
+ * Makes a task configuration for the CLR ShellTask.
+ *
+ * @param taskId
+ * @return task configuration for the CLR Task.
+ * @throws BindException
+ */
+ private static final Configuration getCLRTaskConfiguration(
+ final String taskId, final String command) throws BindException {
+
+ final ConfigurationBuilder cb = Tang.Factory.getTang()
+ .newConfigurationBuilder(loadShellTaskClassHierarchy(SHELL_TASK_CLASS_HIERARCHY_FILENAME));
+
+ cb.bind("Microsoft.Reef.Tasks.ITask, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", "Microsoft.Reef.Tasks.ShellTask, Microsoft.Reef.Tasks.ShellTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
+ cb.bind("Microsoft.Reef.Tasks.TaskConfigurationOptions+Identifier, Microsoft.Reef.Tasks.ITask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=69c3241e6f0468ca", taskId);
+ cb.bind("Microsoft.Reef.Tasks.ShellTask+Command, Microsoft.Reef.Tasks.ShellTask, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", command);
+
+ return cb.build();
+ }
+
+ /**
+ * Makes a task configuration for the JVM ShellTask..
+ *
+ * @param taskId
+ * @return task configuration for the JVM Task.
+ * @throws BindException
+ */
+ private static final Configuration getJVMTaskConfiguration(
+ final String taskId, final String command) throws BindException {
+
+ final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+ cb.addConfiguration(
+ TaskConfiguration.CONF
+ .set(TaskConfiguration.IDENTIFIER, taskId)
+ .set(TaskConfiguration.TASK, ShellTask.class)
+ .build()
+ );
+ cb.bindNamedParameter(Command.class, command);
+ return cb.build();
+ }
+
+ /**
+ * Loads the class hierarchy.
+ *
+ * @return
+ */
+ private static ClassHierarchy loadShellTaskClassHierarchy(String binFile) {
+ try (final InputStream chin = new FileInputStream(binFile)) {
+ final ClassHierarchyProto.Node root = ClassHierarchyProto.Node.parseFrom(chin);
+ final ClassHierarchy ch = new ProtocolBufferClassHierarchy(root);
+ return ch;
+ } catch (final IOException e) {
+ final String message = "Unable to load class hierarchy " + binFile;
+ LOG.log(Level.SEVERE, message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ private void submitEvaluator(final AllocatedEvaluator eval, EvaluatorType type) {
+ synchronized (JobDriver.this) {
+
+ String contextIdSuffix = type.equals(EvaluatorType.JVM) ? JVM_CONTEXT_SUFFIX : CLR_CONTEXT_SUFFIX;
+ String contextId = eval.getId() + contextIdSuffix;
+
+ eval.setType(type);
+
+ LOG.log(Level.INFO, "Allocated Evaluator: {0} expect {1} running {2}",
+ new Object[]{eval.getId(), JobDriver.this.expectCount, JobDriver.this.contexts.size()});
+ assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+ try {
+ eval.submitContext(ContextConfiguration.CONF.set(ContextConfiguration.IDENTIFIER, contextId).build());
+ } catch (final BindException ex) {
+ LOG.log(Level.SEVERE, "Failed to submit context " + contextId, ex);
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+
+ /**
+ * Submit command to all available evaluators.
+ *
+ * @param command shell command to execute.
+ */
+ private void submit(final String command) {
+ LOG.log(Level.INFO, "Submit command {0} to {1} evaluators. state: {2}",
+ new Object[]{command, this.contexts.size(), this.state});
+ assert (this.state == State.READY);
+ this.expectCount = this.contexts.size();
+ this.state = State.WAIT_TASKS;
+ this.cmd = null;
+ for (final ActiveContext context : this.contexts.values()) {
+ this.submit(context, command);
+ }
+ }
+
+ /**
+ * Submit a Task that execute the command to a single Evaluator.
+ * This method is called from <code>submitTask(cmd)</code>.
+ */
+ private void submit(final ActiveContext context, final String command) {
+ try {
+ LOG.log(Level.INFO, "Sending command {0} to context: {1}", new Object[]{command, context});
+ String taskId = context.getId() + "_task";
+ final Configuration taskConfiguration;
+ if (context.getId().endsWith(JVM_CONTEXT_SUFFIX)) {
+ taskConfiguration = getJVMTaskConfiguration(taskId, command);
+ } else {
+ taskConfiguration = getCLRTaskConfiguration(taskId, command);
+ }
+ context.submitTask(taskConfiguration);
+ } catch (final BindException ex) {
+ LOG.log(Level.SEVERE, "Bad Task configuration for context: " + context.getId(), ex);
+ throw new RuntimeException(ex);
+ }
+ }
+
+ /**
+ * Construct the final result and forward it to the Client.
+ */
+ private void returnResults() {
+ final StringBuilder sb = new StringBuilder();
+ for (final String result : this.results) {
+ sb.append(result);
+ }
+ this.results.clear();
+ LOG.log(Level.INFO, "Return results to the client:\n{0}", sb);
+ this.jobMessageObserver.sendMessageToClient(JVM_CODEC.encode(sb.toString()));
+ }
+
+ /**
+ * Request evaluators on each node.
+ * If nodes are not available yet, schedule another request in CHECK_UP_INTERVAL.
+ * TODO: Ask for specific nodes. (This is not working in YARN... need to check again at some point.)
+ *
+ * @throws RuntimeException if any of the requests fails.
+ */
+ private synchronized void requestEvaluators() {
+ assert (this.state == State.INIT);
+ final int numNodes = totalEvaluators;
+ if (numNodes > 0) {
+ LOG.log(Level.INFO, "Schedule on {0} nodes.", numNodes);
+ this.evaluatorRequestor.submit(
+ EvaluatorRequest.newBuilder()
+ .setMemory(128)
+ .setNumberOfCores(1)
+ .setNumber(numNodes).build()
+ );
+ this.state = State.WAIT_EVALUATORS;
+ this.expectCount = numNodes;
+ } else {
+ // No nodes available yet - wait and ask again.
+ this.clock.scheduleAlarm(CHECK_UP_INTERVAL, new EventHandler<Alarm>() {
+ @Override
+ public void onNext(final Alarm time) {
+ synchronized (JobDriver.this) {
+ LOG.log(Level.INFO, "{0} Alarm: {1}", new Object[]{JobDriver.this.state, time});
+ if (JobDriver.this.state == State.INIT) {
+ JobDriver.this.requestEvaluators();
+ }
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Possible states of the job driver. Can be one of:
+ * <dl>
+ * <du><code>INIT</code></du><dd>initial state, ready to request the evaluators.</dd>
+ * <du><code>WAIT_EVALUATORS</code></du><dd>Wait for requested evaluators to initialize.</dd>
+ * <du><code>READY</code></du><dd>Ready to submitTask a new task.</dd>
+ * <du><code>WAIT_TASKS</code></du><dd>Wait for tasks to complete.</dd>
+ * </dl>
+ */
+ private enum State {
+ INIT, WAIT_EVALUATORS, READY, WAIT_TASKS
+ }
+
+ /**
+ * Handles AllocatedEvaluator: Submit an empty context
+ */
+ final class AllocatedEvaluatorHandler implements EventHandler<AllocatedEvaluator> {
+ @Override
+ public void onNext(final AllocatedEvaluator allocatedEvaluator) {
+ synchronized (JobDriver.this) {
+ if (JobDriver.this.nJVMEvaluator > 0) {
+ LOG.log(Level.INFO, "===== adding JVM evaluator =====");
+ JobDriver.this.submitEvaluator(allocatedEvaluator, EvaluatorType.JVM);
+ JobDriver.this.nJVMEvaluator -= 1;
+ } else if (JobDriver.this.nCLREvaluator > 0) {
+ LOG.log(Level.INFO, "===== adding CLR evaluator =====");
+ JobDriver.this.submitEvaluator(allocatedEvaluator, EvaluatorType.CLR);
+ JobDriver.this.nCLREvaluator -= 1;
+ }
+ }
+ }
+ }
+
+ /**
+ * Receive notification that a new Context is available.
+ * Submit a new Distributed Shell Task to that Context.
+ */
+ final class ActiveContextHandler implements EventHandler<ActiveContext> {
+ @Override
+ public void onNext(final ActiveContext context) {
+ synchronized (JobDriver.this) {
+ LOG.log(Level.INFO, "Context available: {0} expect {1} state {2}",
+ new Object[]{context.getId(), JobDriver.this.expectCount, JobDriver.this.state});
+ assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+ JobDriver.this.contexts.put(context.getId(), context);
+ if (--JobDriver.this.expectCount <= 0) {
+ JobDriver.this.state = State.READY;
+ if (JobDriver.this.cmd == null) {
+ LOG.log(Level.INFO, "All evaluators ready; waiting for command. State: {0}",
+ JobDriver.this.state);
+ } else {
+ JobDriver.this.submit(JobDriver.this.cmd);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Receive notification that the Context had completed.
+ * Remove context from the list of active context.
+ */
+ final class ClosedContextHandler implements EventHandler<ClosedContext> {
+ @Override
+ public void onNext(final ClosedContext context) {
+ LOG.log(Level.INFO, "Completed Context: {0}", context.getId());
+ synchronized (JobDriver.this) {
+ JobDriver.this.contexts.remove(context.getId());
+ }
+ }
+ }
+
+ /**
+ * Receive notification that the Context had failed.
+ * Remove context from the list of active context and notify the client.
+ */
+ final class FailedContextHandler implements EventHandler<FailedContext> {
+ @Override
+ public void onNext(final FailedContext context) {
+ LOG.log(Level.SEVERE, "FailedContext", context);
+ synchronized (JobDriver.this) {
+ JobDriver.this.contexts.remove(context.getId());
+ }
+ throw new RuntimeException("Failed context: ", context.asError());
+ }
+ }
+
+ /**
+ * Receive notification that the entire Evaluator had failed.
+ * Stop other jobs and pass this error to the job observer on the client.
+ */
+ final class FailedEvaluatorHandler implements EventHandler<FailedEvaluator> {
+ @Override
+ public void onNext(final FailedEvaluator eval) {
+ synchronized (JobDriver.this) {
+ LOG.log(Level.SEVERE, "FailedEvaluator", eval);
+ for (final FailedContext failedContext : eval.getFailedContextList()) {
+ JobDriver.this.contexts.remove(failedContext.getId());
+ }
+ throw new RuntimeException("Failed Evaluator: ", eval.getEvaluatorException());
+ }
+ }
+ }
+
+ /**
+ * Receive notification that the Task has completed successfully.
+ */
+ final class CompletedTaskHandler implements EventHandler<CompletedTask> {
+ @Override
+ public void onNext(final CompletedTask task) {
+ LOG.log(Level.INFO, "Completed task: {0}", task.getId());
+ // Take the message returned by the task and add it to the running result.
+ String result = "default result";
+ try {
+ if (task.getId().contains(CLR_CONTEXT_SUFFIX)) {
+ result = new String(task.get());
+ } else {
+ result = JVM_CODEC.decode(task.get());
+ }
+ } catch (final Exception e) {
+ LOG.log(Level.WARNING, "failed to decode task outcome");
+ }
+ synchronized (JobDriver.this) {
+ JobDriver.this.results.add(task.getId() + " :: " + result);
+ LOG.log(Level.INFO, "Task {0} result {1}: {2} state: {3}", new Object[]{
+ task.getId(), JobDriver.this.results.size(), result, JobDriver.this.state});
+ if (--JobDriver.this.expectCount <= 0) {
+ JobDriver.this.returnResults();
+ JobDriver.this.state = State.READY;
+ if (JobDriver.this.cmd != null) {
+ JobDriver.this.submit(JobDriver.this.cmd);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Receive notification from the client.
+ */
+ final class ClientMessageHandler implements EventHandler<byte[]> {
+ @Override
+ public void onNext(final byte[] message) {
+ synchronized (JobDriver.this) {
+ final String command = JVM_CODEC.decode(message);
+ LOG.log(Level.INFO, "Client message: {0} state: {1}",
+ new Object[]{command, JobDriver.this.state});
+ assert (JobDriver.this.cmd == null);
+ if (JobDriver.this.state == State.READY) {
+ JobDriver.this.submit(command);
+ } else {
+ // not ready yet - save the command for better times.
+ assert (JobDriver.this.state == State.WAIT_EVALUATORS);
+ JobDriver.this.cmd = command;
+ }
+ }
+ }
+ }
+
+ /**
+ * Job Driver is ready and the clock is set up: request the evaluators.
+ */
+ final class StartHandler implements EventHandler<StartTime> {
+ @Override
+ public void onNext(final StartTime startTime) {
+ LOG.log(Level.INFO, "{0} StartTime: {1}", new Object[]{state, startTime});
+ assert (state == State.INIT);
+ requestEvaluators();
+ }
+ }
+
+ /**
+ * Shutting down the job driver: close the evaluators.
+ */
+ final class StopHandler implements EventHandler<StopTime> {
+ @Override
+ public void onNext(final StopTime time) {
+ LOG.log(Level.INFO, "{0} StopTime: {1}", new Object[]{state, time});
+ for (final ActiveContext context : contexts.values()) {
+ context.close();
+ }
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
new file mode 100644
index 0000000..97c39c3
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/Launch.java
@@ -0,0 +1,189 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.retained_evalCLR;
+
+import org.apache.reef.client.ClientConfiguration;
+import org.apache.reef.runtime.local.client.LocalRuntimeConfiguration;
+import org.apache.reef.runtime.yarn.client.YarnClientConfiguration;
+import org.apache.reef.tang.Configuration;
+import org.apache.reef.tang.Injector;
+import org.apache.reef.tang.JavaConfigurationBuilder;
+import org.apache.reef.tang.Tang;
+import org.apache.reef.tang.annotations.Name;
+import org.apache.reef.tang.annotations.NamedParameter;
+import org.apache.reef.tang.exceptions.BindException;
+import org.apache.reef.tang.exceptions.InjectionException;
+import org.apache.reef.tang.formats.AvroConfigurationSerializer;
+import org.apache.reef.tang.formats.CommandLine;
+import org.apache.reef.tang.formats.ConfigurationModule;
+import org.apache.reef.tang.formats.OptionalParameter;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Retained Evaluators example - main class.
+ */
+public final class Launch {
+
+ /**
+ * Number of REEF worker threads in local mode.
+ */
+ private static final int NUM_LOCAL_THREADS = JobDriver.totalEvaluators;
+ /**
+ * Standard Java logger
+ */
+ private static final Logger LOG = Logger.getLogger(Launch.class.getName());
+
+ /**
+ * This class should not be instantiated.
+ */
+ private Launch() {
+ throw new RuntimeException("Do not instantiate this class!");
+ }
+
+ /**
+ * Parse the command line arguments.
+ *
+ * @param args command line arguments, as passed to main()
+ * @return Configuration object.
+ * @throws BindException configuration error.
+ * @throws IOException error reading the configuration.
+ */
+ private static Configuration parseCommandLine(final String[] args)
+ throws BindException, IOException {
+ final JavaConfigurationBuilder confBuilder = Tang.Factory.getTang().newConfigurationBuilder();
+ final CommandLine cl = new CommandLine(confBuilder);
+ cl.registerShortNameOfClass(Local.class);
+ cl.registerShortNameOfClass(Command.class);
+ cl.registerShortNameOfClass(NumRuns.class);
+ cl.processCommandLine(args);
+ return confBuilder.build();
+ }
+
+ private static Configuration cloneCommandLineConfiguration(final Configuration commandLineConf)
+ throws InjectionException, BindException {
+ final Injector injector = Tang.Factory.getTang().newInjector(commandLineConf);
+ final JavaConfigurationBuilder cb = Tang.Factory.getTang().newConfigurationBuilder();
+ cb.bindNamedParameter(Command.class, injector.getNamedInstance(Command.class));
+ cb.bindNamedParameter(NumRuns.class, String.valueOf(injector.getNamedInstance(NumRuns.class)));
+ return cb.build();
+ }
+
+ /**
+ * Parse command line arguments and create TANG configuration ready to be submitted to REEF.
+ *
+ * @param args Command line arguments, as passed into main().
+ * @return (immutable) TANG Configuration object.
+ * @throws BindException if configuration commandLineInjector fails.
+ * @throws InjectionException if configuration commandLineInjector fails.
+ * @throws IOException error reading the configuration.
+ */
+ private static Configuration getClientConfiguration(final String[] args)
+ throws BindException, InjectionException, IOException {
+
+ final Configuration commandLineConf = parseCommandLine(args);
+
+ final Configuration clientConfiguration = ClientConfiguration.CONF
+ .set(ClientConfiguration.ON_JOB_RUNNING, JobClient.RunningJobHandler.class)
+ .set(ClientConfiguration.ON_JOB_MESSAGE, JobClient.JobMessageHandler.class)
+ .set(ClientConfiguration.ON_JOB_COMPLETED, JobClient.CompletedJobHandler.class)
+ .set(ClientConfiguration.ON_JOB_FAILED, JobClient.FailedJobHandler.class)
+ .set(ClientConfiguration.ON_RUNTIME_ERROR, JobClient.RuntimeErrorHandler.class)
+ .build();
+
+ // TODO: Remove the injector, have stuff injected.
+ final Injector commandLineInjector = Tang.Factory.getTang().newInjector(commandLineConf);
+ final boolean isLocal = commandLineInjector.getNamedInstance(Local.class);
+ final Configuration runtimeConfiguration;
+ if (isLocal) {
+ LOG.log(Level.INFO, "Running on the local runtime");
+ runtimeConfiguration = LocalRuntimeConfiguration.CONF
+ .set(LocalRuntimeConfiguration.NUMBER_OF_THREADS, NUM_LOCAL_THREADS)
+ .build();
+ } else {
+ LOG.log(Level.INFO, "Running on YARN");
+ runtimeConfiguration = YarnClientConfiguration.CONF.build();
+ }
+
+ return Tang.Factory.getTang()
+ .newConfigurationBuilder(runtimeConfiguration, clientConfiguration,
+ cloneCommandLineConfiguration(commandLineConf))
+ .build();
+ }
+
+ private static ConfigurationModule addAll(final ConfigurationModule conf, final OptionalParameter<String> param, final File folder) {
+ ConfigurationModule result = conf;
+ for (final File f : folder.listFiles()) {
+ if (f.canRead() && f.exists() && f.isFile()) {
+ result = result.set(param, f.getAbsolutePath());
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Main method that starts the Retained Evaluators job.
+ *
+ * @param args command line parameters.
+ */
+ public static void main(final String[] args) {
+ try {
+ final File dotNetFolder = new File(args[0]).getAbsoluteFile();
+ String[] removedArgs = Arrays.copyOfRange(args, 1, args.length);
+
+ final Configuration config = getClientConfiguration(removedArgs);
+ LOG.log(Level.INFO, "Configuration:\n--\n{0}--",
+ new AvroConfigurationSerializer().toString(config));
+ final Injector injector = Tang.Factory.getTang().newInjector(config);
+ final JobClient client = injector.getInstance(JobClient.class);
+ client.submit(dotNetFolder);
+ client.waitForCompletion();
+ LOG.info("Done!");
+ } catch (final BindException | InjectionException | IOException ex) {
+ LOG.log(Level.SEVERE, "Job configuration error", ex);
+ }
+ }
+
+ /**
+ * Command line parameter: a command to run. e.g. "echo Hello REEF"
+ */
+ @NamedParameter(doc = "The shell command", short_name = "cmd", default_value = "*INTERACTIVE*")
+ public static final class Command implements Name<String> {
+ }
+
+ /**
+ * Command line parameter: number of experiments to run.
+ */
+ @NamedParameter(doc = "Number of times to run the command",
+ short_name = "num_runs", default_value = "1")
+ public static final class NumRuns implements Name<Integer> {
+ }
+
+ /**
+ * Command line parameter = true to run locally, or false to run on YARN.
+ */
+ @NamedParameter(doc = "Whether or not to run on the local runtime",
+ short_name = "local", default_value = "true")
+ public static final class Local implements Name<Boolean> {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
new file mode 100644
index 0000000..45455bb
--- /dev/null
+++ b/lang/java/reef-examples-clr/src/main/java/org/apache/reef/examples/retained_evalCLR/package-info.java
@@ -0,0 +1,22 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+/**
+ * The Retained Evaluators CLR example.
+ */
+package org.apache.reef.examples.retained_evalCLR;
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-hdinsight/pom.xml
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-hdinsight/pom.xml b/lang/java/reef-examples-hdinsight/pom.xml
new file mode 100644
index 0000000..ce52f92
--- /dev/null
+++ b/lang/java/reef-examples-hdinsight/pom.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>reef-examples-hdinsight</artifactId>
+ <name>REEF Examples on HDInsight</name>
+
+ <parent>
+ <groupId>org.apache.reef</groupId>
+ <artifactId>reef-project</artifactId>
+ <version>0.11.0-incubating-SNAPSHOT</version>
+ </parent>
+
+ <dependencies>
+ <!-- REEF -->
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-runtime-hdinsight</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>reef-examples</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- End of REEF -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!-- Hadoop -->
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-common</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-yarn-common</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-yarn-client</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.hadoop</groupId>
+ <artifactId>hadoop-yarn-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <!-- End of Hadoop -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <outputFile>
+ ${project.build.directory}/${project.artifactId}-${project.version}-shaded.jar
+ </outputFile>
+ <transformers>
+ <transformer
+ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+ <manifestEntries>
+ <Main-Class>
+ org.apache.reef.runtime.hdinsight.cli.HDICLI
+ </Main-Class>
+ </manifestEntries>
+ </transformer>
+ </transformers>
+ <filters>
+ <filter>
+ <artifact>*:*</artifact>
+ <excludes>
+ <exclude>yarn-default.xml</exclude>
+ <exclude>yarn-version-info.properties</exclude>
+ <exclude>core-default.xml</exclude>
+ <exclude>LICENSE</exclude>
+ <exclude>META-INF/*</exclude>
+ </excludes>
+ </filter>
+ </filters>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java b/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
new file mode 100644
index 0000000..2eacd7b
--- /dev/null
+++ b/lang/java/reef-examples-hdinsight/src/main/java/org/apache/reef/examples/hello/HelloHDInsight.java
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.reef.examples.hello;
+
+import org.apache.reef.runtime.hdinsight.client.UnsafeHDInsightRuntimeConfiguration;
+import org.apache.reef.tang.exceptions.InjectionException;
+
+import java.io.IOException;
+
+/**
+ * HelloREEF running on HDInsight
+ */
+public class HelloHDInsight {
+ public static void main(final String[] args) throws InjectionException, IOException {
+ HelloREEFNoClient.runHelloReefWithoutClient(UnsafeHDInsightRuntimeConfiguration.fromEnvironment());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/53ea32cc/lang/java/reef-examples/.gitignore
----------------------------------------------------------------------
diff --git a/lang/java/reef-examples/.gitignore b/lang/java/reef-examples/.gitignore
new file mode 100644
index 0000000..8ce3786
--- /dev/null
+++ b/lang/java/reef-examples/.gitignore
@@ -0,0 +1 @@
+dotnet*
\ No newline at end of file