use of edu.iu.dsc.tws.tset.env.BatchEnvironment in project twister2 by DSC-SPIDAL.
the class HadoopTSet method execute.
@Override
public void execute(Config config, JobAPI.Job job, IWorkerController workerController, IPersistentVolume persistentVolume, IVolatileVolume volatileVolume) {
int workerId = workerController.getWorkerInfo().getWorkerID();
WorkerEnvironment workerEnv = WorkerEnvironment.init(config, job, workerController, persistentVolume, volatileVolume);
BatchEnvironment tSetEnv = TSetEnvironment.initBatch(workerEnv);
Configuration configuration = new Configuration();
configuration.addResource(new Path(HdfsDataContext.getHdfsConfigDirectory(config)));
configuration.set(TextInputFormat.INPUT_DIR, "/input4");
SourceTSet<String> source = tSetEnv.createHadoopSource(configuration, TextInputFormat.class, 4, new MapFunc<Tuple<LongWritable, Text>, String>() {
@Override
public String map(Tuple<LongWritable, Text> input) {
return input.getKey().toString() + " : " + input.getValue().toString();
}
});
SinkTSet<Iterator<String>> sink = source.direct().sink((SinkFunc<Iterator<String>>) value -> {
while (value.hasNext()) {
String next = value.next();
LOG.info("Received value: " + next);
}
return true;
});
tSetEnv.run(sink);
}
use of edu.iu.dsc.tws.tset.env.BatchEnvironment in project twister2 by DSC-SPIDAL.
the class AddInputsExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
// source with 25..29
SourceTSet<Integer> baseSrc = dummySourceOther(env, COUNT, PARALLELISM);
// source with 0..4
SourceTSet<Integer> src = dummySource(env, COUNT, PARALLELISM);
CachedTSet<Integer> srcCache = src.direct().cache().setName("src");
// make src an input of baseSrc
CachedTSet<Integer> baseSrcCache = baseSrc.direct().cache().setName("baseSrc");
CachedTSet<Integer> out = baseSrcCache.direct().compute(new BaseComputeCollectorFunc<Iterator<Integer>, Integer>() {
@Override
public void compute(Iterator<Integer> input, RecordCollector<Integer> collector) {
DataPartitionConsumer<Integer> c1 = (DataPartitionConsumer<Integer>) getInput("src-input").getConsumer();
while (input.hasNext() && c1.hasNext()) {
collector.collect(input.next() + c1.next());
}
}
}).addInput("src-input", srcCache).lazyCache();
for (int i = 0; i < 4; i++) {
LOG.info("iter: " + i);
env.evalAndUpdate(out, baseSrcCache);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
baseSrcCache.direct().forEach(l -> LOG.info(l.toString()));
}
use of edu.iu.dsc.tws.tset.env.BatchEnvironment in project twister2 by DSC-SPIDAL.
the class BranchingExample method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
int para = 2;
SourceTSet<Integer> src = dummySource(env, COUNT, para).setName("src0");
KeyedTSet<Integer, Integer> left = src.mapToTuple(i -> new Tuple<>(i % 2, i)).setName("left");
KeyedTSet<Integer, Integer> right = src.mapToTuple(i -> new Tuple<>(i % 2, i + 1)).setName("right");
JoinTLink<Integer, Integer, Integer> join = left.join(right, CommunicationContext.JoinType.INNER, Integer::compareTo).setName("join");
ComputeTSet<String> map = join.map(t -> "(" + t.getKey() + " " + t.getLeftValue() + " " + t.getRightValue() + ")").setName("map***");
ComputeTSet<String> map1 = map.direct().map(s -> "###" + s).setName("map@@");
ComputeTSet<String> union = map.union(map1).setName("union");
union.direct().forEach(s -> LOG.info(s));
}
use of edu.iu.dsc.tws.tset.env.BatchEnvironment in project twister2 by DSC-SPIDAL.
the class BaseTSetBatchWorker method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
jobParameters = JobParameters.build(env.getConfig());
experimentData = new ExperimentData();
experimentData.setTaskStages(jobParameters.getTaskStages());
if (jobParameters.isStream()) {
throw new IllegalStateException("This worker does not support streaming, Please use" + "TSetStreamingWorker instead");
} else {
experimentData.setOperationMode(OperationMode.BATCH);
experimentData.setIterations(jobParameters.getIterations());
}
}
use of edu.iu.dsc.tws.tset.env.BatchEnvironment in project twister2 by DSC-SPIDAL.
the class HelloTSet method execute.
@Override
public void execute(WorkerEnvironment workerEnv) {
BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
LOG.info("Strating Hello TSet Example");
int para = env.getConfig().getIntegerValue("para", 4);
SourceTSet<int[]> source = env.createSource(new SourceFunc<int[]>() {
private int count = 0;
@Override
public boolean hasNext() {
return count < para;
}
@Override
public int[] next() {
count++;
return new int[] { 1, 1, 1 };
}
}, para).setName("source");
PartitionTLink<int[]> partitioned = source.partition(new LoadBalancePartitioner<>());
ComputeTSet<int[]> mapedPartition = partitioned.map((MapFunc<int[], int[]>) input -> Arrays.stream(input).map(a -> a * 2).toArray());
ReduceTLink<int[]> reduce = mapedPartition.reduce((t1, t2) -> {
int[] ret = new int[t1.length];
for (int i = 0; i < t1.length; i++) {
ret[i] = t1[i] + t2[i];
}
return ret;
});
SinkTSet<int[]> sink = reduce.sink(value -> {
LOG.info("Results " + Arrays.toString(value));
return false;
});
env.run(sink);
LOG.info("Ending Hello TSet Example");
}
Aggregations