Skip to content

Commit

Permalink
adding few changes to documentation and maven fix
Browse files Browse the repository at this point in the history
  • Loading branch information
supunkamburugamuve committed Aug 30, 2019
1 parent 87c6c66 commit 8432fb3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 57 deletions.
83 changes: 42 additions & 41 deletions docs/docs/guides/first-twister2-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ vi src/main/java/helloworld/HelloWorld.java
```java
package helloworld;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import edu.iu.dsc.tws.api.JobConfig;

import edu.iu.dsc.tws.api.Twister2Job;
import edu.iu.dsc.tws.api.config.Config;
import edu.iu.dsc.tws.api.resource.IPersistentVolume;
Expand All @@ -116,54 +121,50 @@ import edu.iu.dsc.tws.api.resource.IWorkerController;
import edu.iu.dsc.tws.rsched.core.ResourceAllocator;
import edu.iu.dsc.tws.rsched.job.Twister2Submitter;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This is a Hello World example of Twister2. This is the most basic functionality of Twister2,
* where it spawns set of parallel workers.
*/
public class HelloWorld implements IWorker {

private static final Logger LOG = Logger.getLogger(HelloWorld.class.getName());

@Override
public void execute(Config config, int workerID,
IWorkerController workerController,
IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
// lets retrieve the configuration set in the job config
String helloKeyValue = config.getStringValue("hello-key");

// lets do a log to indicate we are running
LOG.log(Level.INFO, String.format("Hello World from Worker %d; there are %d total workers "
+ "and I got a message: %s", workerID,
workerController.getNumberOfWorkers(), helloKeyValue));
private static final Logger LOG = Logger.getLogger(HelloWorld.class.getName());

@Override
public void execute(Config config, int workerID,
IWorkerController workerController,
IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
// lets retrieve the configuration set in the job config
String helloKeyValue = config.getStringValue("hello-key");

// lets do a log to indicate we are running
LOG.log(Level.INFO, String.format("Hello World from Worker %d; there are %d total workers "
+ "and I got a message: %s", workerID,
workerController.getNumberOfWorkers(), helloKeyValue));
}

public static void main(String[] args) {
// lets take number of workers as an command line argument
int numberOfWorkers = 4;
if (args.length == 1) {
numberOfWorkers = Integer.valueOf(args[0]);
}

public static void main(String[] args) {
// lets take number of workers as an command line argument
int numberOfWorkers = 4;
if (args.length == 1) {
numberOfWorkers = Integer.valueOf(args[0]);
}

// first load the configurations from command line and config files
Config config = ResourceAllocator.loadConfig(new HashMap<>());

// lets put a configuration here
JobConfig jobConfig = new JobConfig();
jobConfig.put("hello-key", "Twister2-Hello");

Twister2Job twister2Job = Twister2Job.newBuilder()
.setJobName("hello-world-job")
.setWorkerClass(HelloWorld.class)
.addComputeResource(2, 1024, numberOfWorkers)
.setConfig(jobConfig)
.build();
// now submit the job
Twister2Submitter.submitJob(twister2Job, config);
}
// first load the configurations from command line and config files
Config config = ResourceAllocator.loadConfig(new HashMap<>());

// lets put a configuration here
JobConfig jobConfig = new JobConfig();
jobConfig.put("hello-key", "Twister2-Hello");

Twister2Job twister2Job = Twister2Job.newBuilder()
.setJobName("hello-world-job")
.setWorkerClass(HelloWorld.class)
.addComputeResource(2, 1024, numberOfWorkers)
.setConfig(jobConfig)
.build();
// now submit the job
Twister2Submitter.submitJob(twister2Job, config);
}
}
```

Expand All @@ -178,7 +179,7 @@ mvn install
After this we can run this code from the Twister2 installation directory

```bash
./bin/twister2 submit standalone jar [PATH TO JAR FILE] HelloWorld 4
./bin/twister2 submit standalone jar [PATH TO JAR FILE] helloworld.HelloWorld 4

```

Expand Down
30 changes: 17 additions & 13 deletions docs/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,41 @@ There is an example called HelloWorld.java included with Twister2 examples packa
package edu.iu.dsc.tws.examples.basic;

import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import edu.iu.dsc.tws.api.JobConfig;
import edu.iu.dsc.tws.api.Twister2Submitter;
import edu.iu.dsc.tws.api.job.Twister2Job;
import edu.iu.dsc.tws.common.config.Config;
import edu.iu.dsc.tws.common.discovery.IWorkerController;
import edu.iu.dsc.tws.common.resource.AllocatedResources;
import edu.iu.dsc.tws.common.resource.WorkerComputeResource;
import edu.iu.dsc.tws.common.worker.IPersistentVolume;
import edu.iu.dsc.tws.common.worker.IVolatileVolume;
import edu.iu.dsc.tws.common.worker.IWorker;
import edu.iu.dsc.tws.api.Twister2Job;
import edu.iu.dsc.tws.api.config.Config;
import edu.iu.dsc.tws.api.exceptions.TimeoutException;
import edu.iu.dsc.tws.api.resource.IPersistentVolume;
import edu.iu.dsc.tws.api.resource.IVolatileVolume;
import edu.iu.dsc.tws.api.resource.IWorker;
import edu.iu.dsc.tws.api.resource.IWorkerController;
import edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI;
import edu.iu.dsc.tws.proto.utils.WorkerInfoUtils;
import edu.iu.dsc.tws.rsched.core.ResourceAllocator;
import edu.iu.dsc.tws.rsched.job.Twister2Submitter;

/**
* This is a Hello World example of Twister2. This is the most basic functionality of Twister2,
* where it spawns set of parallel workers.
*/
public class HelloWorld implements IWorker {

private static final Logger LOG = Logger.getLogger(HelloWorld.class.getName());

@Override
public void execute(Config config, int workerID,
AllocatedResources allocatedResources, IWorkerController workerController,
IWorkerController workerController,
IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
// lets retrieve the configuration set in the job config
String helloKeyValue = config.getStringValue("hello-key");

// lets do a log to indicate we are running
LOG.log(Level.INFO, String.format("Hello World from Worker %d; there are %d total workers "
+ "and I got a configuration value %s", workerID,
+ "and I got a message: %s", workerID,
workerController.getNumberOfWorkers(), helloKeyValue));

List<WorkerNetworkInfo> workerList = workerController.waitForAllWorkersToJoin(50000);
Expand All @@ -66,6 +69,7 @@ public class HelloWorld implements IWorker {
} catch (InterruptedException e) {
LOG.severe("Thread sleep interrupted.");
}

}

public static void main(String[] args) {
Expand All @@ -83,8 +87,8 @@ public class HelloWorld implements IWorker {
jobConfig.put("hello-key", "Twister2-Hello");

Twister2Job twister2Job = Twister2Job.newBuilder()
.setName("hello-world-job")
.setWorkerClass(HelloWorld.class.getName())
.setJobName("hello-world-job")
.setWorkerClass(HelloWorld.class)
.addComputeResource(2, 1024, numberOfWorkers)
.setConfig(jobConfig)
.build();
Expand Down
4 changes: 2 additions & 2 deletions tools/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def t2_java_lib(name, srcs = [], deps = [], artifact_name = "", generate_pom = T
name = name,
srcs = srcs,
deps = deps,
tags = mvn_tag("edu.iu.dsc.tws", name, T2_VERSION),
tags = mvn_tag("org.twister2", name, T2_VERSION),
)

if (generate_pom):
Expand All @@ -44,7 +44,7 @@ def t2_proto_java_lib(name, deps = [], artifact_name = "", generate_pom = True):
native.java_proto_library(
name = name,
deps = deps,
tags = mvn_tag("edu.iu.dsc.tws", name, T2_VERSION),
tags = mvn_tag("org.twister2", name, T2_VERSION),
)

if (generate_pom):
Expand Down
2 changes: 1 addition & 1 deletion util/mvn/install-local-snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu

echo -e "Installing maven snapshot locally...\n"

version=${1:-SNAPSHOT}
version=${1:-0.3.0}

bash $(dirname $0)/execute-deploy.sh \
"install:install-file" \
Expand Down

0 comments on commit 8432fb3

Please sign in to comment.