Search in sources :

Example 1 with JarUploadResult

use of edu.snu.mist.formats.avro.JarUploadResult in project mist by snuspl.

the class MistClient method main.

public static void main(final String[] args) throws IOException {
    if (args.length < 4) {
        System.out.println("Please enter the command-line parameters: ");
        System.out.println("submit-jar $jar_path$ $driver_address$ $driver_port$");
        return;
    }
    final String type = args[0];
    if (type.compareToIgnoreCase("submit-jar") == 0) {
        final String jarPath = args[1];
        final File file = new File(jarPath);
        if (!file.exists()) {
            System.out.println("File " + jarPath + " does not exist");
            return;
        }
        final String address = args[2];
        final int port = Integer.valueOf(args[3]);
        try (final MISTExecutionEnvironment ee = new MISTDefaultExecutionEnvironmentImpl(address, port)) {
            final JarUploadResult result = ee.submitJar(Arrays.asList(jarPath));
            if (result.getIsSuccess()) {
                System.out.println("App identifier: " + result.getIdentifier());
                return;
            } else {
                System.out.println("Submission failed: " + result.getMsg());
            }
        } catch (final Exception e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Not supported operation");
        return;
    }
}
Also used : File(java.io.File) JarUploadResult(edu.snu.mist.formats.avro.JarUploadResult) IOException(java.io.IOException)

Example 2 with JarUploadResult

use of edu.snu.mist.formats.avro.JarUploadResult in project mist by snuspl.

the class MISTDefaultExecutionEnvironmentImplTest method testMISTDefaultExecutionEnvironment.

/**
 * This unit test creates mock jar file, mocking driver, and mocking task and tests
 * whether a test query can be serialized and sent via MISTDefaultExecutionEnvironmentImpl.
 */
@Test
public void testMISTDefaultExecutionEnvironment() throws IOException {
    // Step 1: Launch mock RPC Server
    final Server masterServer = new NettyServer(new SpecificResponder(ClientToMasterMessage.class, new MockMasterServer(host, taskPortNum)), new InetSocketAddress(masterPortNum));
    final Server taskServer = new NettyServer(new SpecificResponder(ClientToTaskMessage.class, new MockTaskServer(testQueryResult)), new InetSocketAddress(taskPortNum));
    // Step 2: Upload jar file
    final int suffixStartIndex = mockJarOutName.lastIndexOf(".");
    final String mockJarOutPrefix = mockJarOutName.substring(0, suffixStartIndex);
    final String mockJarOutSuffix = mockJarOutName.substring(suffixStartIndex);
    final List<String> jarPaths = new LinkedList<>();
    final Path tempJarFile = Files.createTempFile(mockJarOutPrefix, mockJarOutSuffix);
    jarPaths.add(tempJarFile.toString());
    final MISTExecutionEnvironment executionEnvironment = new MISTDefaultExecutionEnvironmentImpl(host, masterPortNum);
    final JarUploadResult jarUploadResult = executionEnvironment.submitJar(jarPaths);
    Assert.assertEquals("app_id", jarUploadResult.getIdentifier());
    // Step 3: Generate a new query
    final MISTQueryBuilder queryBuilder = new MISTQueryBuilder();
    queryBuilder.setApplicationId(jarUploadResult.getIdentifier()).socketTextStream(TestParameters.LOCAL_TEXT_SOCKET_SOURCE_CONF).flatMap(s -> Arrays.asList(s.split(" "))).map(s -> new Tuple2<>(s, 1)).reduceByKey(0, String.class, (Integer x, Integer y) -> x + y).textSocketOutput("localhost", 13667);
    final MISTQuery query = queryBuilder.build();
    System.err.println(mockJarOutPrefix);
    System.err.println(mockJarOutSuffix);
    // Step 4: Send a query and check whether the query comes to the task correctly
    final APIQueryControlResult result = executionEnvironment.submitQuery(query);
    Assert.assertEquals(result.getQueryId(), testQueryResult);
    masterServer.close();
    taskServer.close();
    Files.delete(tempJarFile);
}
Also used : SpecificResponder(org.apache.avro.ipc.specific.SpecificResponder) Path(java.nio.file.Path) Arrays(java.util.Arrays) Files(java.nio.file.Files) Tuple2(edu.snu.mist.common.types.Tuple2) Server(org.apache.avro.ipc.Server) Test(org.junit.Test) IOException(java.io.IOException) ClientToTaskMessage(edu.snu.mist.formats.avro.ClientToTaskMessage) JarUploadResult(edu.snu.mist.formats.avro.JarUploadResult) InetSocketAddress(java.net.InetSocketAddress) ClientToMasterMessage(edu.snu.mist.formats.avro.ClientToMasterMessage) SpecificResponder(org.apache.avro.ipc.specific.SpecificResponder) MockTaskServer(edu.snu.mist.client.utils.MockTaskServer) List(java.util.List) NettyServer(org.apache.avro.ipc.NettyServer) MockMasterServer(edu.snu.mist.client.utils.MockMasterServer) TestParameters(edu.snu.mist.client.utils.TestParameters) Assert(org.junit.Assert) LinkedList(java.util.LinkedList) Path(java.nio.file.Path) Server(org.apache.avro.ipc.Server) MockTaskServer(edu.snu.mist.client.utils.MockTaskServer) NettyServer(org.apache.avro.ipc.NettyServer) MockMasterServer(edu.snu.mist.client.utils.MockMasterServer) InetSocketAddress(java.net.InetSocketAddress) MockMasterServer(edu.snu.mist.client.utils.MockMasterServer) MockTaskServer(edu.snu.mist.client.utils.MockTaskServer) JarUploadResult(edu.snu.mist.formats.avro.JarUploadResult) NettyServer(org.apache.avro.ipc.NettyServer) LinkedList(java.util.LinkedList) ClientToTaskMessage(edu.snu.mist.formats.avro.ClientToTaskMessage) ClientToMasterMessage(edu.snu.mist.formats.avro.ClientToMasterMessage) Test(org.junit.Test)

Example 3 with JarUploadResult

use of edu.snu.mist.formats.avro.JarUploadResult in project mist by snuspl.

the class MISTExampleUtils method submit.

/**
 * Submit query to MIST driver.
 */
public static APIQueryControlResult submit(final MISTQueryBuilder queryBuilder, final Configuration configuration) throws IOException, URISyntaxException, InjectionException {
    final String[] masterSocket = Tang.Factory.getTang().newInjector(configuration).getNamedInstance(MasterAddress.class).split(":");
    final String masterHostname = masterSocket[0];
    final int masterPort = Integer.parseInt(masterSocket[1]);
    try (final MISTExecutionEnvironment executionEnvironment = new MISTDefaultExecutionEnvironmentImpl(masterHostname, masterPort)) {
        // Upload jar
        final String jarFilePath = getJarFilePath();
        final List<String> jarFilePaths = Arrays.asList(jarFilePath);
        final JarUploadResult result = executionEnvironment.submitJar(jarFilePaths);
        queryBuilder.setApplicationId(result.getIdentifier());
        return executionEnvironment.submitQuery(queryBuilder.build());
    } catch (final Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : MasterAddress(edu.snu.mist.examples.parameters.MasterAddress) MISTDefaultExecutionEnvironmentImpl(edu.snu.mist.client.MISTDefaultExecutionEnvironmentImpl) MISTExecutionEnvironment(edu.snu.mist.client.MISTExecutionEnvironment) JarUploadResult(edu.snu.mist.formats.avro.JarUploadResult) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) InjectionException(org.apache.reef.tang.exceptions.InjectionException)

Aggregations

JarUploadResult (edu.snu.mist.formats.avro.JarUploadResult)3 IOException (java.io.IOException)3 MISTDefaultExecutionEnvironmentImpl (edu.snu.mist.client.MISTDefaultExecutionEnvironmentImpl)1 MISTExecutionEnvironment (edu.snu.mist.client.MISTExecutionEnvironment)1 MockMasterServer (edu.snu.mist.client.utils.MockMasterServer)1 MockTaskServer (edu.snu.mist.client.utils.MockTaskServer)1 TestParameters (edu.snu.mist.client.utils.TestParameters)1 Tuple2 (edu.snu.mist.common.types.Tuple2)1 MasterAddress (edu.snu.mist.examples.parameters.MasterAddress)1 ClientToMasterMessage (edu.snu.mist.formats.avro.ClientToMasterMessage)1 ClientToTaskMessage (edu.snu.mist.formats.avro.ClientToTaskMessage)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NettyServer (org.apache.avro.ipc.NettyServer)1