Search in sources :

Example 26 with Tuple

use of edu.iu.dsc.tws.api.comms.structs.Tuple in project twister2 by DSC-SPIDAL.

the class TSetAllGatherExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    super.execute(workerEnv);
    BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
    // set the parallelism of source to task stage 0
    List<Integer> taskStages = jobParameters.getTaskStages();
    int sourceParallelism = taskStages.get(0);
    int sinkParallelism = taskStages.get(1);
    SourceTSet<int[]> source = env.createSource(new TestBaseSource(), sourceParallelism).setName("Source");
    AllGatherTLink<int[]> gather = source.allGather();
    SinkTSet<Iterator<Tuple<Integer, int[]>>> sink = gather.sink(new SinkFunc<Iterator<Tuple<Integer, int[]>>>() {

        private TSetContext context;

        @Override
        public boolean add(Iterator<Tuple<Integer, int[]>> value) {
            // todo: check this!
            int[] result = new int[0];
            while (value.hasNext()) {
                Tuple<Integer, int[]> t = value.next();
                if (t.getKey().equals(context.getIndex())) {
                    result = t.getValue();
                    break;
                }
            }
            LOG.info("Task Id : " + context.getIndex() + " Results " + Arrays.toString(result));
            experimentData.setOutput(value);
            try {
                verify(OperationNames.ALLGATHER);
            } catch (VerificationException e) {
                LOG.info("Exception Message : " + e.getMessage());
            }
            return true;
        }

        @Override
        public void prepare(TSetContext ctx) {
            this.context = ctx;
        }
    });
    env.run(sink);
}
Also used : BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) TSetContext(edu.iu.dsc.tws.api.tset.TSetContext) Iterator(java.util.Iterator) VerificationException(edu.iu.dsc.tws.examples.verification.VerificationException) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Example 27 with Tuple

use of edu.iu.dsc.tws.api.comms.structs.Tuple in project twister2 by DSC-SPIDAL.

the class SDirectExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    StreamingEnvironment env = TSetEnvironment.initStreaming(workerEnv);
    SSourceTSet<Integer> src = dummySource(env, COUNT, PARALLELISM).setName("src");
    SDirectTLink<Integer> link = src.direct().setName("dir");
    link.map(i -> i * 2).setName("map").direct().forEach(i -> LOG.info("m" + i.toString()));
    link.flatmap((i, c) -> c.collect("fm" + i)).setName("flatmap").direct().forEach(i -> LOG.info(i.toString()));
    link.compute(i -> i + "C").setName("compute").direct().forEach(i -> LOG.info(i));
    link.mapToTuple(i -> new Tuple<>(i, i.toString())).keyedDirect().forEach(i -> LOG.info("mapToTuple: " + i.toString()));
    link.compute((input, output) -> output.collect(input + "DD")).setName("computec").direct().forEach(s -> LOG.info(s.toString()));
    // Runs the entire TSet graph
    env.run();
}
Also used : SSourceTSet(edu.iu.dsc.tws.tset.sets.streaming.SSourceTSet) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) TSetEnvironment(edu.iu.dsc.tws.tset.env.TSetEnvironment) SDirectTLink(edu.iu.dsc.tws.tset.links.streaming.SDirectTLink) ResourceAllocator(edu.iu.dsc.tws.rsched.core.ResourceAllocator) HashMap(java.util.HashMap) Config(edu.iu.dsc.tws.api.config.Config) Logger(java.util.logging.Logger) JobConfig(edu.iu.dsc.tws.api.JobConfig) BatchTsetExample(edu.iu.dsc.tws.examples.tset.batch.BatchTsetExample) StreamingEnvironment(edu.iu.dsc.tws.tset.env.StreamingEnvironment) StreamingEnvironment(edu.iu.dsc.tws.tset.env.StreamingEnvironment)

Example 28 with Tuple

use of edu.iu.dsc.tws.api.comms.structs.Tuple in project twister2 by DSC-SPIDAL.

the class KeyedAddInputsExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
    KeyedSourceTSet<String, Integer> src0 = dummyKeyedSource(env, COUNT, PARALLELISM);
    KeyedSourceTSet<String, Integer> src1 = dummyKeyedSourceOther(env, COUNT, PARALLELISM);
    KeyedCachedTSet<String, Integer> cache0 = src0.cache();
    KeyedCachedTSet<String, Integer> cache1 = src1.cache();
    ComputeTSet<String> comp = cache0.keyedDirect().compute(new BaseComputeCollectorFunc<Iterator<Tuple<String, Integer>>, String>() {

        private Map<String, Integer> input1 = new HashMap<>();

        @Override
        public void prepare(TSetContext ctx) {
            super.prepare(ctx);
            // populate the hashmap with values from the input
            DataPartitionConsumer<Tuple<String, Integer>> part = (DataPartitionConsumer<Tuple<String, Integer>>) getInput("input").getConsumer();
            while (part.hasNext()) {
                Tuple<String, Integer> next = part.next();
                input1.put(next.getKey(), next.getValue());
            }
        }

        @Override
        public void compute(Iterator<Tuple<String, Integer>> input, RecordCollector<String> output) {
            while (input.hasNext()) {
                Tuple<String, Integer> next = input.next();
                output.collect(next.getKey() + " -> " + next.getValue() + ", " + input1.get(next.getKey()));
            }
        }
    }).addInput("input", cache1);
    comp.direct().forEach(i -> LOG.info("comp: " + i));
    LOG.info("Test lazy cache!");
    ComputeTSet<Object> forEach = comp.direct().lazyForEach(i -> LOG.info("comp-lazy: " + i));
    for (int i = 0; i < 4; i++) {
        LOG.info("iter: " + i);
        env.eval(forEach);
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    env.finishEval(forEach);
}
Also used : RecordCollector(edu.iu.dsc.tws.api.tset.fn.RecordCollector) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) BaseComputeCollectorFunc(edu.iu.dsc.tws.api.tset.fn.BaseComputeCollectorFunc) TSetContext(edu.iu.dsc.tws.api.tset.TSetContext) Iterator(java.util.Iterator) DataPartitionConsumer(edu.iu.dsc.tws.api.dataset.DataPartitionConsumer) HashMap(java.util.HashMap) Map(java.util.Map) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Example 29 with Tuple

use of edu.iu.dsc.tws.api.comms.structs.Tuple in project twister2 by DSC-SPIDAL.

the class TSetGatherExample method execute.

@Override
public void execute(WorkerEnvironment workerEnv) {
    super.execute(workerEnv);
    BatchEnvironment env = TSetEnvironment.initBatch(workerEnv);
    // set the parallelism of source to task stage 0
    int srcPara = jobParameters.getTaskStages().get(0);
    int sinkPara = jobParameters.getTaskStages().get(1);
    SourceTSet<int[]> source = env.createSource(new TestBaseSource(), srcPara).setName("Source");
    GatherTLink<int[]> gather = source.gather();
    SinkTSet<Iterator<Tuple<Integer, int[]>>> sink = gather.sink((SinkFunc<Iterator<Tuple<Integer, int[]>>>) val -> {
        int[] value = null;
        while (val.hasNext()) {
            value = val.next().getValue();
        }
        experimentData.setOutput(value);
        LOG.info("Results " + Arrays.toString(value));
        try {
            verify(OperationNames.GATHER);
        } catch (VerificationException e) {
            LOG.info("Exception Message : " + e.getMessage());
        }
        return true;
    });
    env.run(sink);
}
Also used : Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Arrays(java.util.Arrays) Iterator(java.util.Iterator) SourceTSet(edu.iu.dsc.tws.tset.sets.batch.SourceTSet) VerificationException(edu.iu.dsc.tws.examples.verification.VerificationException) GatherTLink(edu.iu.dsc.tws.tset.links.batch.GatherTLink) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) SinkTSet(edu.iu.dsc.tws.tset.sets.batch.SinkTSet) OperationNames(edu.iu.dsc.tws.api.compute.OperationNames) BaseTSetBatchWorker(edu.iu.dsc.tws.examples.tset.BaseTSetBatchWorker) Logger(java.util.logging.Logger) SinkFunc(edu.iu.dsc.tws.api.tset.fn.SinkFunc) WorkerEnvironment(edu.iu.dsc.tws.api.resource.WorkerEnvironment) TSetEnvironment(edu.iu.dsc.tws.tset.env.TSetEnvironment) BatchEnvironment(edu.iu.dsc.tws.tset.env.BatchEnvironment) Iterator(java.util.Iterator) VerificationException(edu.iu.dsc.tws.examples.verification.VerificationException)

Example 30 with Tuple

use of edu.iu.dsc.tws.api.comms.structs.Tuple in project twister2 by DSC-SPIDAL.

the class ExperimentVerification method isVerified.

@Override
public boolean isVerified() throws VerificationException {
    boolean isVerified = false;
    if (experimentData.getOperationMode() == OperationMode.STREAMING) {
        if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
            if (OperationNames.REDUCE.equals(this.operationNames)) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount < sinkCount && sinkCount == 1) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outString = Arrays.toString(output);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outString);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.ALLREDUCE.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount != sinkCount) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outString = Arrays.toString(output);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outString);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.GATHER.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount < sinkCount) && (sinkCount != 1)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.ALLGATHER.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount < sinkCount) && (sinkCount != 1)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.KEYED_REDUCE.equals(this.operationNames)) {
            Object keyedOutput = null;
            Object response = experimentData.getOutput();
            if (response instanceof Tuple) {
                keyedOutput = (Tuple) response;
            } else {
                keyedOutput = response;
            }
            if (experimentData.getInput() instanceof int[] && keyedOutput instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount < sinkCount && sinkCount != 1) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) keyedOutput;
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String resGen = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Results : " + resGen);
                    String outString = Arrays.toString(output);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.BROADCAST.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    String msg = String.format("Expected Result : %s Generated Result : %s", resString, outputRes);
                    if (isVerified) {
                        LOG.info(msg);
                    } else {
                        LOG.severe(msg);
                        throw new VerificationException(msg);
                    }
                }
            }
        }
        if (OperationNames.PARTITION.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    // isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    isVerified = resString.equals(outputRes);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.KEYED_PARTITION.equals(this.operationNames)) {
            Object response = experimentData.getOutput();
            Object outputMessage = null;
            if (response instanceof Tuple) {
                Tuple tuple = (Tuple) response;
                outputMessage = tuple.getValue();
            } else {
                outputMessage = response;
            }
            if (experimentData.getInput() instanceof int[] && outputMessage instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) outputMessage;
                    int[] res = input;
                    // isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    isVerified = resString.equals(outputRes);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
    }
    if (experimentData.getOperationMode() == OperationMode.BATCH) {
        if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
            if (OperationNames.REDUCE.equals(this.operationNames)) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount < sinkCount && sinkCount == 1) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outString = Arrays.toString(output);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outString);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.ALLREDUCE.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount != sinkCount) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outString = Arrays.toString(output);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outString);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.GATHER.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount < sinkCount) && (sinkCount != 1)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.KEYED_GATHER.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount < sinkCount) && (sinkCount != 1)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.ALLGATHER.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount < sinkCount) && (sinkCount != 1)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.KEYED_REDUCE.equals(this.operationNames)) {
            Object outputExp = experimentData.getOutput();
            Object keyedOutput = null;
            if (outputExp instanceof Tuple) {
                keyedOutput = ((Tuple) experimentData.getOutput()).getValue();
            } else {
                keyedOutput = outputExp;
            }
            if (experimentData.getInput() instanceof int[] && keyedOutput instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if (sourceCount < sinkCount && sinkCount != 1) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) keyedOutput;
                    Object[] res = Arrays.stream(input).map(i -> i * sourceCount * experimentData.getIterations()).boxed().collect(Collectors.toList()).toArray();
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String resGen = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Results : " + resGen);
                    String outString = Arrays.toString(output);
                    isVerified = resString.equals(outString);
                }
            }
        }
        if (OperationNames.BROADCAST.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    // isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    isVerified = resString.equals(outputRes);
                    String msg = String.format("Expected Result : %s Generated Result : %s", resString, outputRes);
                    if (isVerified) {
                        LOG.info(msg);
                    } else {
                        LOG.severe("Results Not Verified : " + msg);
                        throw new VerificationException(msg);
                    }
                }
            }
        }
        if (OperationNames.PARTITION.equals(this.operationNames)) {
            if (experimentData.getInput() instanceof int[] && experimentData.getOutput() instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    // isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    isVerified = resString.equals(outputRes);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
        if (OperationNames.KEYED_PARTITION.equals(this.operationNames)) {
            Object response = experimentData.getOutput();
            Object outputMessage = null;
            if (response instanceof Tuple) {
                Tuple tuple = (Tuple) response;
                outputMessage = tuple.getValue();
            } else {
                outputMessage = response;
            }
            if (experimentData.getInput() instanceof int[] && outputMessage instanceof int[]) {
                int sourceCount = experimentData.getTaskStages().get(0);
                int sinkCount = experimentData.getTaskStages().get(1);
                if ((sourceCount > sinkCount) && (sinkCount < 2)) {
                    throw new VerificationException("Invalid task stages : " + sourceCount + "," + sinkCount);
                } else {
                    LOG.info("Current Worker : " + experimentData.getWorkerId() + "/" + experimentData.getNumOfWorkers());
                    LOG.info("Task Id : " + experimentData.getTaskId());
                    int[] input = (int[]) experimentData.getInput();
                    int[] output = (int[]) experimentData.getOutput();
                    int[] res = input;
                    // isVerified = Arrays.equals(input, output);
                    String resString = Arrays.toString(Arrays.copyOfRange(res, 0, res.length));
                    String outputRes = Arrays.toString(Arrays.copyOfRange(output, 0, res.length));
                    isVerified = resString.equals(outputRes);
                    LOG.info("Expected Result : " + resString);
                    LOG.info("Generated Result : " + outputRes);
                }
            }
        }
    }
    return isVerified;
}
Also used : Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple) Arrays(java.util.Arrays) OperationMode(edu.iu.dsc.tws.api.compute.graph.OperationMode) OperationNames(edu.iu.dsc.tws.api.compute.OperationNames) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Tuple(edu.iu.dsc.tws.api.comms.structs.Tuple)

Aggregations

Tuple (edu.iu.dsc.tws.api.comms.structs.Tuple)98 Iterator (java.util.Iterator)38 List (java.util.List)35 Logger (java.util.logging.Logger)34 ArrayList (java.util.ArrayList)29 Config (edu.iu.dsc.tws.api.config.Config)27 WorkerEnvironment (edu.iu.dsc.tws.api.resource.WorkerEnvironment)24 Test (org.junit.Test)24 BatchEnvironment (edu.iu.dsc.tws.tset.env.BatchEnvironment)18 InMessage (edu.iu.dsc.tws.comms.dfw.InMessage)17 HashMap (java.util.HashMap)16 TSetEnvironment (edu.iu.dsc.tws.tset.env.TSetEnvironment)15 JobConfig (edu.iu.dsc.tws.api.JobConfig)14 MessageTypes (edu.iu.dsc.tws.api.comms.messaging.types.MessageTypes)14 JoinedTuple (edu.iu.dsc.tws.api.comms.structs.JoinedTuple)14 ResourceAllocator (edu.iu.dsc.tws.rsched.core.ResourceAllocator)14 SourceTSet (edu.iu.dsc.tws.tset.sets.batch.SourceTSet)13 CommunicationContext (edu.iu.dsc.tws.api.comms.CommunicationContext)11 MessageType (edu.iu.dsc.tws.api.comms.messaging.types.MessageType)11 Comparator (java.util.Comparator)11