private object parse(String parseObject)
        {
            this.jreader.initialize(parseObject);
            this.jreader.readNextToken();
            TokenType type = this.jreader.getCurrentTokenType();
            bool      isOk = (type == TokenType.StartObject);

            if (isOk)
            {
                IExperimentSeries expSer = this.parseExperimentSeries(this.jreader);
                jreader.readNextToken();
                this.builder.setId(expSer.getId());
                this.builder.setName(expSer.getName());
                this.builder.setDescription(expSer.getDescription());
                this.builder.addRange(expSer.getExperiments());
                this.builder.setSoftwareName(expSer.getExperimentSoftware());
            }
            else
            {
                throw new ArgumentException("Argument 'type' must be a " +
                                            "TokenType with option of StartObject.");
            }
            object result = this.builder.build();

            this.builder.reset();
            return(result);
        }
        public async Task distributeExperimentSeries(IExperimentSeries eSeries,
                                                     String dockerImage,
                                                     String executionPath)
        {
            bool isOk = ((eSeries != null) && (dockerImage != null) && (executionPath != null));

            if (isOk)
            {
                IList <Task <KeyValuePair <String, String> > > tasks = new List <Task <KeyValuePair <String, String> > >();
                Console.WriteLine("Investigator: Start distributing experiment tasks of " +
                                  "series of experiment with id " + eSeries.getId());
                foreach (IExperiment experiment in eSeries.getExperiments())
                {
                    tasks.Add(this.distributeExperimentAsync(eSeries.getId(),
                                                             eSeries.getName(),
                                                             eSeries.getDescription(),
                                                             eSeries.getExperimentSoftware(),
                                                             experiment, dockerImage, executionPath));
                }
                await startRemovePolling(tasks.Select(x => x.Result).ToList());

                Console.WriteLine("Investigator: Experiment tasks of the series of experiment " +
                                  "with id " + eSeries.getId() + " were finished");
            }
            else
            {
                throw new ArgumentException("Arguments 'eSeries','dockerImage' and " +
                                            "'executionPath' must be not null.");
            }
        }
        // starts an task per given experiment, which create an experiment service in each case
        public async Task distributeExperimentSeries(IExperimentSeries eSeries,
                                                     String dockerImage,
                                                     String executionPath)
        {
            bool isOk = ((eSeries != null) && (dockerImage != null) && (executionPath != null));

            if (isOk)
            {
                IList <KeyValuePair <String, Task <KeyValuePair <String, String> > > > tasks = new List <KeyValuePair <String, Task <KeyValuePair <String, String> > > >();
                IList <IExperiment> experiments = eSeries.getExperiments().ToList();
                Console.WriteLine("Investigator: Start distributing experiment tasks of " +
                                  "series of experiment with id " + eSeries.getId());
                // create task per experiment
                foreach (IExperiment experiment in experiments)
                {
                    // wait 10 seconds until to the next task creation
                    Task.Delay(10000).Wait();
                    // create task
                    tasks.Add(new KeyValuePair <string, Task <KeyValuePair <string, string> > >(
                                  eSeries.getId() + ":::" + experiment.getId(),
                                  this.distributeExperimentAsync(eSeries.getId(),
                                                                 eSeries.getName(),
                                                                 eSeries.getDescription(),
                                                                 eSeries.getExperimentSoftware(),
                                                                 experiment, dockerImage, executionPath)));
                }
                // check if an created task faulted
                tasks.Where(x => x.Value.IsFaulted).ToList().ForEach(x =>
                {
                    String error = "Investigator: Task\n\t        " + x.Key +
                                   "\n\t      is faulted because:\n" +
                                   x.Value.Exception.Message;
                    Console.WriteLine(error);
                });
                // watch for state of experiment services:
                // remove, if faulted or finished successful - and display a message
                await startRemovePolling(tasks.Select(x => x.Value.Result).ToList());

                Console.WriteLine("Investigator: Experiment tasks of the series of experiment " +
                                  "with id " + eSeries.getId() + " were finished");
            }
            else
            {
                throw new ArgumentException("Arguments 'eSeries','dockerImage' and " +
                                            "'executionPath' must be not null.");
            }
        }
Beispiel #4
0
        public async Task distributeExperimentSeries(IExperimentSeries eSeries,
                                                     String dockerImage,
                                                     String executionPath)
        {
            bool isOk = ((eSeries != null) && (dockerImage != null) && (executionPath != null));

            if (isOk)
            {
                IList <KeyValuePair <String, Task <KeyValuePair <String, String> > > > tasks = new List <KeyValuePair <String, Task <KeyValuePair <String, String> > > >();
                IList <IExperiment> experiments = eSeries.getExperiments().ToList();
                Console.WriteLine("Investigator: Start distributing experiment tasks of " +
                                  "series of experiment with id " + eSeries.getId());
                //while(experiments.Count > 0)
                //{
                foreach (IExperiment experiment in experiments)
                {
                    tasks.Add(new KeyValuePair <string, Task <KeyValuePair <string, string> > >(
                                  eSeries.getId() + ":::" + experiment.getId(),
                                  this.distributeExperimentAsync(eSeries.getId(),
                                                                 eSeries.getName(),
                                                                 eSeries.getDescription(),
                                                                 eSeries.getExperimentSoftware(),
                                                                 experiment, dockerImage, executionPath)));
                }
                //Task.Delay(3000).Wait();
                tasks.Where(x => x.Value.IsFaulted).ToList().ForEach(x =>
                {
                    String error = "Investigator: Task\n\t        " + x.Key +
                                   "\n\t      is faulted because:\n" +
                                   x.Value.Exception.Message;
                    Console.WriteLine(error);
                });
                // IList<String> faultedTasks = tasks.Where(x => x.Value.IsFaulted)
                //                                   .Select(x => x.Key).ToList();
                // experiments = experiments.Where(x =>
                // {
                //     bool isSelected = false;
                //     String identifier = eSeries.getId() + ":::" + x.getId();
                //     foreach(String brokenIdentifier in faultedTasks) {
                //         if (String.Compare(identifier, brokenIdentifier) == 0)
                //             isSelected = true;
                //     }
                //     return isSelected;
                // }).ToList();
                //}
                // foreach(IExperiment experiment in eSeries.getExperiments())
                // {
                //     tasks.Add(this.distributeExperimentAsync(eSeries.getId(),
                //                                            eSeries.getName(),
                //                                            eSeries.getDescription(),
                //                                            eSeries.getExperimentSoftware(),
                //                                            experiment, dockerImage, executionPath));
                // }
                await startRemovePolling(tasks.Select(x => x.Value.Result).ToList());

                Console.WriteLine("Investigator: Experiment tasks of the series of experiment " +
                                  "with id " + eSeries.getId() + " were finished");
            }
            else
            {
                throw new ArgumentException("Arguments 'eSeries','dockerImage' and " +
                                            "'executionPath' must be not null.");
            }
        }