Esempio n. 1
0
        public MainForm(DecoderJob job, bool startJob)
        {
            InitializeComponent();

            _logBuffer = new List <LogMessage>(100);

            _dispatcher = new JobDispatcher(job);
            _dispatcher.Logger.MessagesChanged += new EventHandler(Log_MessagesChanged);

#if DEBUG
            _dispatcher.Logger.LogLevel = LogLevel.Debug0;
#endif

            _dispatcher.OnJobProgressChanged += new EventHandler(Dispatcher_OnJobProgressChanged);
            _dispatcher.AfterJobCompleted    += new EventHandler(Dispatcher_AfterJobCompleted);

            _autorun = startJob;

            statusBindingSource.DataSource = _dispatcher.Status;

            jobPropertyGrid.SelectedObject = job;
            jobPropertyGrid.ExpandAllGridItems();

            _executionTime  = new TimeSpan();
            _timer          = new Timer();
            _timer.Tick    += new EventHandler(TimerTick);
            _timer.Interval = 1000;

            this.Log_MessagesChanged(this, EventArgs.Empty);
        }
Esempio n. 2
0
        public async void DispatcherRenewJobRequestRecoverFromExceptions()
        {
            //Arrange
            using (var hc = new TestHostContext(this))
            {
                int   poolId    = 1;
                Int64 requestId = 1000;
                int   count     = 0;

                var trace = hc.GetTrace(nameof(DispatcherRenewJobRequestRecoverFromExceptions));
                TaskCompletionSource <int> firstJobRequestRenewed  = new TaskCompletionSource <int>();
                CancellationTokenSource    cancellationTokenSource = new CancellationTokenSource();

                TaskAgentJobRequest request           = new TaskAgentJobRequest();
                PropertyInfo        lockUntilProperty = request.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                Assert.NotNull(lockUntilProperty);
                lockUntilProperty.SetValue(request, DateTime.UtcNow.AddMinutes(5));

                hc.SetSingleton <IRunnerServer>(_runnerServer.Object);
                hc.SetSingleton <IConfigurationStore>(_configurationStore.Object);
                _configurationStore.Setup(x => x.GetSettings()).Returns(new RunnerSettings()
                {
                    PoolId = 1
                });
                _runnerServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>()))
                .Returns(() =>
                {
                    count++;
                    if (!firstJobRequestRenewed.Task.IsCompletedSuccessfully)
                    {
                        trace.Info("First renew happens.");
                    }

                    if (count < 5)
                    {
                        return(Task.FromResult <TaskAgentJobRequest>(request));
                    }
                    else if (count == 5 || count == 6 || count == 7)
                    {
                        throw new TimeoutException("");
                    }
                    else
                    {
                        cancellationTokenSource.Cancel();
                        return(Task.FromResult <TaskAgentJobRequest>(request));
                    }
                });

                var jobDispatcher = new JobDispatcher();
                jobDispatcher.Initialize(hc);

                await jobDispatcher.RenewJobRequestAsync(poolId, requestId, Guid.Empty, firstJobRequestRenewed, cancellationTokenSource.Token);

                Assert.True(firstJobRequestRenewed.Task.IsCompletedSuccessfully, "First renew should succeed.");
                Assert.True(cancellationTokenSource.IsCancellationRequested);
                _runnerServer.Verify(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>()), Times.Exactly(8));
                _runnerServer.Verify(x => x.RefreshConnectionAsync(RunnerConnectionType.JobRequest, It.IsAny <TimeSpan>()), Times.Exactly(3));
                _runnerServer.Verify(x => x.SetConnectionTimeout(RunnerConnectionType.JobRequest, It.IsAny <TimeSpan>()), Times.Once);
            }
        }
Esempio n. 3
0
        public void Badger_AssignExperiments5()
        {
            //create herd agents
            List <HerdAgentInfo> herdAgents = new List <HerdAgentInfo>
            {
                new HerdAgentInfo("Agent-1", 4, PropValues.Linux64, PropValues.None, "1.1.0"),
                new HerdAgentInfo("Agent-2", 2, PropValues.Win32, "8.1.2", "1.1.0"),
                new HerdAgentInfo("Agent-3", 2, PropValues.Win64, "8.1.2", "1.1.0")
            };

            //create app versions
            AppVersionRequirements win64Reqs      = new AppVersionRequirements(PropValues.Win64);
            AppVersionRequirements win32Reqs      = new AppVersionRequirements(PropValues.Win32);
            AppVersionRequirements linux64Reqs    = new AppVersionRequirements(PropValues.Linux64);
            AppVersion             win32Version   = new AppVersion("win-x32", "RLSimion.exe", win32Reqs);
            AppVersion             win64Version   = new AppVersion("win-x64", "RLSimion-linux-x64.exe", win64Reqs);
            AppVersion             linux64Version = new AppVersion("linux-x64", "RLSimion-x64.exe", linux64Reqs);
            List <AppVersion>      appVersions    = new List <AppVersion>()
            {
                win32Version, win64Version, linux64Version
            };

            //create run-time requirements
            RunTimeRequirements cores_2_win32   = new RunTimeRequirements(0, PropValues.Win32);
            RunTimeRequirements cores_2_linux64 = new RunTimeRequirements(2, PropValues.Linux64);
            RunTimeRequirements cores_1         = new RunTimeRequirements(1, PropValues.Linux64);
            //create experiments
            List <ExperimentalUnit> pendingExperiments = new List <ExperimentalUnit>()
            {
                new ExperimentalUnit("Experiment-1", appVersions, cores_2_win32),
                new ExperimentalUnit("Experiment-2", appVersions, cores_2_linux64),
                new ExperimentalUnit("Experiment-3", appVersions, cores_2_linux64),
            };

            //create output list to receive assigned jobs
            List <Job> assignedJobs = new List <Job>();

            //Assign experiments
            JobDispatcher.AssignExperiments(ref pendingExperiments, ref herdAgents, ref assignedJobs);

            //Check everything went as expected
            Assert.IsTrue(assignedJobs.Count == 2);
            //  -assigned experimental units and agents
            Assert.IsTrue(assignedJobs[0].HerdAgent.ProcessorId == "Agent-1");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits.Count == 2);
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].Name == "Experiment-2");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].SelectedVersion.Requirements.Architecture == PropValues.Linux64);
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[1].Name == "Experiment-3");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[1].SelectedVersion.Requirements.Architecture == PropValues.Linux64);
            Assert.IsTrue(assignedJobs[1].HerdAgent.ProcessorId == "Agent-2");
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits.Count == 1);
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits[0].Name == "Experiment-1");
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits[0].SelectedVersion.Requirements.Architecture == PropValues.Win32);

            //  -used agents are removed
            Assert.IsTrue(herdAgents.Count == 1);
            //  -assigned experiments are removed
            Assert.IsTrue(pendingExperiments.Count == 0);
        }
Esempio n. 4
0
 void Awake()
 {
     Jobs = gameObject.AddComponent <JobDispatcher>();
     if (AudioSourcePlayer == null)
     {
         AudioSourcePlayer = GetComponent <AudioSource>();
     }
     listOfAssociatedWorkers = new List <GameObject>();
 }
Esempio n. 5
0
        public async void RenewJobRequestNewAgentNameUpdatesSettings()
        {
            //Arrange
            using (var hc = new TestHostContext(this))
            {
                var count       = 0;
                var oldName     = "OldName";
                var newName     = "NewName";
                var oldSettings = new RunnerSettings {
                    AgentName = oldName
                };
                var reservedAgent = new TaskAgentReference {
                    Name = newName
                };

                var trace = hc.GetTrace(nameof(DispatcherRenewJobRequestStopOnJobTokenExpiredExceptions));
                TaskCompletionSource <int> firstJobRequestRenewed  = new TaskCompletionSource <int>();
                CancellationTokenSource    cancellationTokenSource = new CancellationTokenSource();

                var request = new Mock <TaskAgentJobRequest>();
                request.Object.ReservedAgent = reservedAgent;
                PropertyInfo lockUntilProperty = request.Object.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                Assert.NotNull(lockUntilProperty);
                lockUntilProperty.SetValue(request.Object, DateTime.UtcNow.AddMinutes(5));
                hc.SetSingleton <IRunnerServer>(_runnerServer.Object);
                hc.SetSingleton <IConfigurationStore>(_configurationStore.Object);
                _configurationStore.Setup(x => x.GetSettings()).Returns(oldSettings);
                _runnerServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
                .Returns(() =>
                {
                    count++;
                    if (count < 5)
                    {
                        return(Task.FromResult <TaskAgentJobRequest>(request.Object));
                    }
                    else if (count == 5 || count == 6 || count == 7)
                    {
                        throw new TimeoutException("");
                    }
                    else
                    {
                        cancellationTokenSource.Cancel();
                        return(Task.FromResult <TaskAgentJobRequest>(request.Object));
                    }
                });

                var jobDispatcher = new JobDispatcher();
                jobDispatcher.Initialize(hc);

                // Act
                await jobDispatcher.RenewJobRequestAsync(0, 0, Guid.Empty, Guid.NewGuid().ToString(), firstJobRequestRenewed, cancellationTokenSource.Token);

                // Assert
                _configurationStore.Verify(x => x.SaveSettings(It.Is <RunnerSettings>(settings => settings.AgentName == newName)), Times.Once);
            }
        }
Esempio n. 6
0
        public async void DispatcherRenewJobRequestFirstRenewRetrySixTimes()
        {
            //Arrange
            using (var hc = new TestHostContext(this))
            {
                int   poolId    = 1;
                Int64 requestId = 1000;
                int   count     = 0;

                var trace = hc.GetTrace(nameof(DispatcherRenewJobRequestFirstRenewRetrySixTimes));
                TaskCompletionSource <int> firstJobRequestRenewed  = new TaskCompletionSource <int>();
                CancellationTokenSource    cancellationTokenSource = new CancellationTokenSource();

                TaskAgentJobRequest request           = new TaskAgentJobRequest();
                PropertyInfo        lockUntilProperty = request.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                Assert.NotNull(lockUntilProperty);
                lockUntilProperty.SetValue(request, DateTime.UtcNow.AddMinutes(5));

                hc.SetSingleton <IRunnerServer>(_runnerServer.Object);
                hc.SetSingleton <IConfigurationStore>(_configurationStore.Object);
                _configurationStore.Setup(x => x.GetSettings()).Returns(new RunnerSettings()
                {
                    PoolId = 1
                });
                _runnerServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
                .Returns(() =>
                {
                    count++;
                    if (!firstJobRequestRenewed.Task.IsCompletedSuccessfully)
                    {
                        trace.Info("First renew happens.");
                    }

                    if (count <= 5)
                    {
                        throw new TimeoutException("");
                    }
                    else
                    {
                        cancellationTokenSource.CancelAfter(10000);
                        throw new InvalidOperationException("Should not reach here.");
                    }
                });

                var jobDispatcher = new JobDispatcher();
                jobDispatcher.Initialize(hc);

                await jobDispatcher.RenewJobRequestAsync(poolId, requestId, Guid.Empty, Guid.NewGuid().ToString(), firstJobRequestRenewed, cancellationTokenSource.Token);

                Assert.False(firstJobRequestRenewed.Task.IsCompletedSuccessfully, "First renew should failed.");
                Assert.False(cancellationTokenSource.IsCancellationRequested);
                _runnerServer.Verify(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <CancellationToken>()), Times.Exactly(6));
            }
        }
Esempio n. 7
0
        public WinService()
        {
            CanShutdown                 = false;
            CanPauseAndContinue         = false;
            CanHandleSessionChangeEvent = false;
            CanHandlePowerEvent         = false;

            JobProxy jobProxy = new JobProxy();

            jobProxy.AddProxy(new WinAutomation());
            m_jobDispatcher = new JobDispatcher(jobProxy);
        }
Esempio n. 8
0
        public async void DispatchesOneTimeJobRequest()
        {
            //Arrange
            using (var hc = new TestHostContext(this))
            {
                var jobDispatcher = new JobDispatcher();
                hc.SetSingleton <IConfigurationStore>(_configurationStore.Object);
                hc.SetSingleton <IRunnerServer>(_runnerServer.Object);

                hc.EnqueueInstance <IProcessChannel>(_processChannel.Object);
                hc.EnqueueInstance <IProcessInvoker>(_processInvoker.Object);

                _configurationStore.Setup(x => x.GetSettings()).Returns(new RunnerSettings()
                {
                    PoolId = 1
                });
                jobDispatcher.Initialize(hc);

                var ts = new CancellationTokenSource();
                Pipelines.AgentJobRequestMessage message = CreateJobRequestMessage();
                string strMessage = JsonUtility.ToString(message);

                _processInvoker.Setup(x => x.ExecuteAsync(It.IsAny <String>(), It.IsAny <String>(), "spawnclient 1 2", null, It.IsAny <CancellationToken>()))
                .Returns(Task.FromResult <int>(56));

                _processChannel.Setup(x => x.StartServer(It.IsAny <StartProcessDelegate>()))
                .Callback((StartProcessDelegate startDel) => { startDel("1", "2"); });
                _processChannel.Setup(x => x.SendAsync(MessageType.NewJobRequest, It.Is <string>(s => s.Equals(strMessage)), It.IsAny <CancellationToken>()))
                .Returns(Task.CompletedTask);

                var          request           = new TaskAgentJobRequest();
                PropertyInfo sessionIdProperty = request.GetType().GetProperty("LockedUntil", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
                Assert.NotNull(sessionIdProperty);
                sessionIdProperty.SetValue(request, DateTime.UtcNow.AddMinutes(5));

                _runnerServer.Setup(x => x.RenewAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <TaskAgentJobRequest>(request));

                _runnerServer.Setup(x => x.FinishAgentRequestAsync(It.IsAny <int>(), It.IsAny <long>(), It.IsAny <Guid>(), It.IsAny <DateTime>(), It.IsAny <TaskResult>(), It.IsAny <CancellationToken>())).Returns(Task.FromResult <TaskAgentJobRequest>(new TaskAgentJobRequest()));

                //Act
                jobDispatcher.Run(message, true);

                //Assert
                await jobDispatcher.WaitAsync(CancellationToken.None);

                Assert.True(jobDispatcher.RunOnceJobCompleted.Task.IsCompleted, "JobDispatcher should set task complete token for one time agent.");
                Assert.True(jobDispatcher.RunOnceJobCompleted.Task.Result, "JobDispatcher should set task complete token to 'TRUE' for one time agent.");
            }
        }
Esempio n. 9
0
        public async void RunExperimentsAsync(List <HerdAgentInfo> freeHerdAgents)
        {
            SetRunning(true);

            m_cancelTokenSource = new CancellationTokenSource();

            Monitoring.MsgDispatcher dispatcher
                = new Monitoring.MsgDispatcher(OnJobAssigned, OnJobFinished
                                               , DispatchOnAllStatesChanged, DispatchOnStateChanged
                                               , DispatchOnMessageReceived, DispatchOnExperimentalUnitLaunched
                                               , MainWindowViewModel.Instance.LogToFile, m_cancelTokenSource.Token);

            int ret = await JobDispatcher.RunExperimentsAsync(m_pendingExperiments, freeHerdAgents, dispatcher, m_cancelTokenSource, ShepherdViewModel.DispatcherOptions);

            SetRunning(false);
        }
Esempio n. 10
0
        // Methods
        public Quax()
        {
            _jobDispatcher    = new JobDispatcher();
            _jobResultReciver = new JobResultReciver();
            _controlUnit      = new ControlUnit();

            // Default values
            MaxDispatcherThreads     = 5;
            DataChannelPortNumber    = 40000;
            ControlChannelPortNumber = 40001;

            // Event handlers
            _jobDispatcher.NewLogItem         += new NewLogItemEventHandler(_jobDispatcher_OnNewLogItem);
            _jobResultReciver.JobResultRecive += new JobResultReciveEventHandler(_jobResultReciver_OnJobResultRecive);
            _controlUnit.NewLogItem           += new NewLogItemEventHandler(_controlUnit_OnNewLogItem);

            //
            _controlUnit.JobDispatcher = _jobDispatcher;
        }
Esempio n. 11
0
        public void Badger_AssignExperiments2()
        {
            //Case: Cannot find match for x64 agents because only x32 version is defined
            //Agent 1: x64, 4 cores
            //Agent 2: x32, 2 cores
            //Agent 3: x64, 2 cores
            //Exp.Unit 1: 0 cores
            //Exp.Unit 2: 1 cores
            //Exp.Unit 3: 2 cores
            //Exp.Unit 4: 1 cores
            //Exp.Unit 5: 0 cores
            //Exp.Unit 6: 1 cores
            //Exp.Unit 7: 2 cores
            //Exp.Unit 8: 1 cores

            //create herd agents
            List <HerdAgentInfo> herdAgents = new List <HerdAgentInfo>
            {
                new HerdAgentInfo("Agent-1", 4, PropValues.Win64, PropValues.None, "1.1.0"),
                new HerdAgentInfo("Agent-2", 2, PropValues.Win32, "8.1.2", "1.1.0"),
                new HerdAgentInfo("Agent-3", 2, PropValues.Win64, "8.1.2", "1.1.0")
            };

            //create app versions
            AppVersionRequirements x64Reqs     = new AppVersionRequirements(PropValues.Win64);
            AppVersionRequirements x32Reqs     = new AppVersionRequirements(PropValues.Win32);
            AppVersion             x32Version  = new AppVersion("x32", "RLSimion.exe", x32Reqs);
            List <AppVersion>      appVersions = new List <AppVersion>()
            {
                x32Version
            };

            //create run-time requirements
            RunTimeRequirements cores_all = new RunTimeRequirements(0);
            RunTimeRequirements cores_2   = new RunTimeRequirements(2);
            RunTimeRequirements cores_1   = new RunTimeRequirements(1);
            //create experiments
            List <ExperimentalUnit> pendingExperiments = new List <ExperimentalUnit>()
            {
                new ExperimentalUnit("Experiment-1", appVersions, cores_all),
                new ExperimentalUnit("Experiment-2", appVersions, cores_1),
                new ExperimentalUnit("Experiment-3", appVersions, cores_2),
                new ExperimentalUnit("Experiment-4", appVersions, cores_1),
                new ExperimentalUnit("Experiment-5", appVersions, cores_all),
                new ExperimentalUnit("Experiment-6", appVersions, cores_1),
                new ExperimentalUnit("Experiment-7", appVersions, cores_1),
                new ExperimentalUnit("Experiment-8", appVersions, cores_1)
            };

            //create output list to receive assigned jobs
            List <Job> assignedJobs = new List <Job>();

            //Assign experiments
            JobDispatcher.AssignExperiments(ref pendingExperiments, ref herdAgents, ref assignedJobs);

            //Check everything went as expected
            Assert.IsTrue(assignedJobs.Count == 1);
            //  -assigned experimental units and agents
            Assert.IsTrue(assignedJobs[0].HerdAgent.ProcessorId == "Agent-2");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits.Count == 1);
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].Name == "Experiment-1");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].SelectedVersion.Requirements.Architecture == PropValues.Win32);


            //  -used agents are removed
            Assert.IsTrue(herdAgents.Count == 2);
            //  -assigned experiments are removed
            Assert.IsTrue(pendingExperiments.Count == 7);
        }
        public async Task RunExample(string[] args)
        {
            _configProvider = new ConfigProvider(Environment.GetCommandLineArgs());
            _bitmovinApi    = BitmovinApi.Builder
                              .WithApiKey(_configProvider.GetBitmovinApiKey())
                              .WithLogger(new ConsoleLogger())
                              .Build();

            var input = await CreateHttpInput(_configProvider.GetHttpInputHost());

            var output = await CreateS3Output(_configProvider.GetS3OutputBucketName(),
                                              _configProvider.GetS3OutputAccessKey(),
                                              _configProvider.GetS3OutputSecretKey());

            var codecConfigurations = new List <CodecConfiguration>()
            {
                await CreateH264VideoConfiguration(480, 800_000L),
                await CreateH264VideoConfiguration(720, 1_200_000L),
                await CreateH264VideoConfiguration(1080, 2_000_000L),
                await CreateAacAudioConfiguration()
            };

            var jobDispatcher = new JobDispatcher();

            do
            {
                var queuedEncodings = await CountQueuedEncodings();

                var freeSlots = TargetQueueSize - queuedEncodings;

                if (freeSlots > 0)
                {
                    var jobsToStart = jobDispatcher.GetJobsToStart(freeSlots);

                    if (jobsToStart.Count > 0)
                    {
                        Console.WriteLine($"There are currently {queuedEncodings} encodings queued. " +
                                          $"Starting {jobsToStart.Count} more to reach target queue size " +
                                          $"of {TargetQueueSize}");

                        await StartEncodings(jobsToStart, codecConfigurations, input, output);
                    }
                    else
                    {
                        Console.WriteLine("No more jobs to start. Waiting for " +
                                          $"{jobDispatcher.GetStartedJobs().Count} jobs to finish.");
                    }
                }
                else
                {
                    Console.WriteLine($"There are currently {queuedEncodings} encodings queued. " +
                                      "Waiting for free slots...");
                }

                await Task.Delay(10000);

                foreach (var job in jobDispatcher.GetStartedJobs())
                {
                    await UpdateEncodingJob(job);

                    await Task.Delay(300);
                }
            } while (!jobDispatcher.AllJobsFinished());

            Console.WriteLine("All encodings jobs are finished!");

            jobDispatcher.LogFailedJobs();
        }
Esempio n. 13
0
        public void Badger_AssignExperiments7()
        {
            //create herd agents
            List <HerdAgentInfo> herdAgents = new List <HerdAgentInfo>
            {
                new HerdAgentInfo("Agent-1", 4, PropValues.Linux64, PropValues.None, "1.1.0"),
                new HerdAgentInfo("Agent-2", 2, PropValues.Win32, "8.1.2", "1.1.0"),
                new HerdAgentInfo("Agent-3", 2, PropValues.Win64, "8.1.2", "1.1.0")
            };

            //create app versions
            AppVersionRequirements win64Reqs      = new AppVersionRequirements(PropValues.Win64);
            AppVersionRequirements win32Reqs      = new AppVersionRequirements(PropValues.Win32);
            AppVersionRequirements linux64Reqs    = new AppVersionRequirements(PropValues.Linux64);
            AppVersion             win32Version   = new AppVersion("win-x32", "RLSimion.exe", win32Reqs);
            AppVersion             win64Version   = new AppVersion("win-x64", "RLSimion-linux-x64.exe", win64Reqs);
            AppVersion             linux64Version = new AppVersion("linux-x64", "RLSimion-x64.exe", linux64Reqs);
            List <AppVersion>      appVersions    = new List <AppVersion>()
            {
                win32Version, win64Version, linux64Version
            };

            //create run-time requirements
            RunTimeRequirements cntkRequirements    = new RunTimeRequirements(0);
            Requirements        cntkLinuxInputFiles = new Requirements();

            cntkLinuxInputFiles.AddInputFile("cntk-linux.so");
            cntkRequirements.AddTargetPlatformRequirement(PropValues.Linux64, cntkLinuxInputFiles);
            Requirements cntkWindowsInputFiles = new Requirements();

            cntkWindowsInputFiles.AddInputFile("cntk-windows.dll");
            cntkRequirements.AddTargetPlatformRequirement(PropValues.Win64, cntkWindowsInputFiles);
            //create experiments
            List <ExperimentalUnit> pendingExperiments = new List <ExperimentalUnit>()
            {
                new ExperimentalUnit("Experiment-1", appVersions, cntkRequirements),
                new ExperimentalUnit("Experiment-2", appVersions, cntkRequirements),
                new ExperimentalUnit("Experiment-3", appVersions, cntkRequirements),
            };

            //create output list to receive assigned jobs
            List <Job> assignedJobs = new List <Job>();

            //Assign experiments
            JobDispatcherOptions options = new JobDispatcherOptions();

            options.LeaveOneFreeCore = true;

            JobDispatcher.AssignExperiments(ref pendingExperiments, ref herdAgents, ref assignedJobs, options);

            //Check everything went as expected
            Assert.IsTrue(assignedJobs.Count == 2);
            //  -assigned experimental units and agents
            Assert.IsTrue(assignedJobs[0].HerdAgent.ProcessorId == "Agent-1");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits.Count == 1);
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].Name == "Experiment-1");
            Assert.IsTrue(assignedJobs[0].ExperimentalUnits[0].SelectedVersion.Requirements.Architecture == PropValues.Linux64);
            Assert.IsTrue(assignedJobs[1].HerdAgent.ProcessorId == "Agent-3");
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits.Count == 1);
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits[0].Name == "Experiment-2");
            Assert.IsTrue(assignedJobs[1].ExperimentalUnits[0].SelectedVersion.Requirements.Architecture == PropValues.Win64);

            //  -used agents are removed
            Assert.IsTrue(herdAgents.Count == 1);
            //  -assigned experiments are removed
            Assert.IsTrue(pendingExperiments.Count == 1);
        }
Esempio n. 14
0
    // Update is called once per frame
    void Update()
    {
        if (isDead)
        {
            //despawnTimer += Time.deltaTime;
            //if (despawnTimer > Despawn)
            //{
            //    Destroy(gameObject);
            //}
            return;
        }
        // somehow check if you are at the jobsite and once done remove the job
        if (IsIdle)
        {
            JobDispatcher availableJobs = Fire.Jobs;
            if (availableJobs.HasJobs())
            {
                JobDispatcher.Job job = availableJobs.GetNearestJob(TilePosition());
                TakeJob(job);
                AtJobSite = false;
            }
            else
            {
                // TODO look for next fire
                pathFollowing.MoveToRandomLocationInSquare();
                Fire fire = World.Get().GetNearestFireWithJobs(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y));
                if (fire != null)
                {
                    if (Fire.NumAssociatedWorkers() > 5)
                    {
                        Fire.WorkerLeaving(gameObject);

                        Fire = fire;
                        Fire.WorkerComing(gameObject);
                    }
                }
            }
        }
        else
        {
            if (Job.Coordinates == TilePosition())
            {
                pathFollowing.CurrentPath.Cancel();
                if (Job.IsReady())
                {
                    JobProgress += Time.deltaTime;
                    gameObject.GetComponent <Animator>().SetBool("isChopping", true);
                }
                else if (!AtJobSite)
                {
                    AtJobSite = true;
                    Job.Arrived();
                }
                if (JobProgress >= Job.Duration())
                {
                    gameObject.GetComponent <Animator>().SetBool("isChopping", false);
                    Debug.Log("Changing Tile of Type " + World.Get().Tiles[Job.Coordinates].TileType.ToString());
                    if (Job.JobType == JobDispatcher.Job.Type.Chop)
                    {
                        World.Get().ChoppedTree(Job.Coordinates);
                    }
                    else
                    {
                        Fire fire = World.Get().SpawnCampFire(World.Get().GetWorldLocation(Job.Coordinates));
                        if (fire != null)
                        {
                            Fire = fire;
                        }
                    }
                    JobProgress = 0f;
                    Job         = null;
                    IsIdle      = true;
                }
            }
        }
        if (Fire.CurrentBurnRate == 0)
        {
            deathTimer += Time.deltaTime;
            if (deathTimer > SecondsToDeath)
            {
                gameObject.GetComponent <Animator>().SetBool("isDead", true);
                World.Get().RemoveWorker(gameObject);
                isDead = true;
            }
        }
        else
        {
            deathTimer = 0f;
        }
    }
Esempio n. 15
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
            return;
        }

        if (BlockGameplayInputs && Input.GetKeyDown(KeyCode.Space))
        {
            SceneManager.LoadScene("Game");
            return;
        }

        Vector2 mousePosInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        if (Input.GetButtonDown("PlaceCampFire"))
        {
            if (BlockGameplayInputs)
            {
                return;
            }

            World      w            = World.Get();
            Vector2Int gridLocation = w.GetGridLocation(mousePosInWorld);
            //w.Tiles[gridLocation].SetIsInSnow(false);

            if (w.Tiles[gridLocation].TileType == World.Tile.Type.Grass)
            {
                GameObject fire       = w.GetClosestFire(mousePosInWorld);
                Fire       fireScript = fire.GetComponent <Fire>();
                Vector2Int closestFireGridLocation = w.GetGridLocation(fire.transform.position);
                float      distance    = World.GetManhattanDistance(gridLocation, closestFireGridLocation);
                float      maxDistance = fireScript.CurrentRadiusOfInfluence + w.GetNewFireRadius() * 1.5f;
                if (distance > maxDistance)
                {
                    Debug.Log(distance.ToString() + " max reach " + maxDistance.ToString() + "(" + fireScript.CurrentRadiusOfInfluence.ToString() + " + " + w.GetNewFireRadius().ToString() + ")");
                    w.DisplayText("We cannot reach that far.", 2);
                    return;
                }
                int cost = Mathf.FloorToInt(w.GenerationParameters.resources.expeditionWoodCostPerTile * distance);

                if (w.GlobalInventory.CurrentWood > cost)
                {
                    w.SetTileType(gridLocation, World.Tile.Type.ExpeditionSite);
                    JobDispatcher jobScript = fire.GetComponent <JobDispatcher>();
                    jobScript.QueueJob(gridLocation, JobDispatcher.Job.Type.Expedition);
                    w.GlobalInventory.RemoveWood(cost);
                }
                else
                {
                    w.DisplayText("Not enough wood.", 2);
                }
            }
            else if (w.Tiles[w.GetGridLocation(mousePosInWorld)].TileType == World.Tile.Type.Hearth)
            {
                if (w.GlobalInventory.CurrentWood >= w.GenerationParameters.resources.hearthFeedingAmount)
                {
                    w.GlobalInventory.RemoveWood(w.GenerationParameters.resources.hearthFeedingAmount);
                    w.Hearth.GetComponent <Fire>().Feed();
                }
            }
        }

        if (Input.GetButtonDown("DragCamera"))
        {
            DragCameraInputLocation = Input.mousePosition;
            DragCameraStartLocation = Camera.main.transform.position;
        }

        if (DragCameraInputLocation != null)
        {
            Vector2 dragV = DragCameraInputLocation.Value - Input.mousePosition;
            dragV *= Camera.main.orthographicSize;
            float ratio = Camera.main.scaledPixelWidth / Camera.main.scaledPixelHeight;
            dragV.y *= ratio;
            dragV   /= 200.0f;

            float oldZ = Camera.main.transform.position.z;
            Camera.main.transform.position = new Vector3(dragV.x, dragV.y, 0) + DragCameraStartLocation.Value;
        }

        if (Input.GetButtonUp("DragCamera"))
        {
            DragCameraInputLocation = null;
            DragCameraStartLocation = null;
        }

        float scrollAmount = Input.GetAxis("Mouse ScrollWheel");

        if (Mathf.Abs(scrollAmount) > 0.0f)
        {
            Camera.main.orthographicSize -= scrollAmount;
            Camera.main.orthographicSize  = Mathf.Clamp(Camera.main.orthographicSize, 80, 700);
        }
    }
Esempio n. 16
0
        public static void Run(string batchFilename, bool onlyUnfinished)
        {
            if (batchFilename == null)
            {
                Console.WriteLine("Error. Missing argument: -batch");
                return;
            }

            if (!File.Exists(batchFilename))
            {
                Console.WriteLine("Error. File doesn't exist: " + batchFilename);
                return;
            }

            //All the experimental units or only unfinished???
            LoadOptions loadOptions = new LoadOptions();

            if (onlyUnfinished)
            {
                loadOptions.Selection = LoadOptions.ExpUnitSelection.OnlyUnfinished;
            }
            else
            {
                loadOptions.Selection = LoadOptions.ExpUnitSelection.All;
            }

            Console.WriteLine("Running batch file: " + batchFilename);
            g_writer = System.IO.File.CreateText("log.txt");
            ExperimentBatch batch = new ExperimentBatch();

            batch.Load(batchFilename, loadOptions);

            NumUnfinishedExpUnits = batch.CountExperimentalUnits();
            NumTotalExpUnits      = NumUnfinishedExpUnits;
            if (NumUnfinishedExpUnits == 0)
            {
                Console.WriteLine("Finished: No experimental unit to be run");
                return;
            }
            else
            {
                Console.SetCursorPosition(0, experimentStatsLine);
                Console.WriteLine("Experimental units:");
                UpdateExperimentStats();
            }
            Console.SetCursorPosition(0, herdAgentsLine);
            Console.Write("Herd agents:");
            Shepherd shepherd = new Shepherd();

            shepherd.CallHerd();

            Thread.Sleep(2000);

            List <HerdAgentInfo> herdAgents = new List <HerdAgentInfo>();

            shepherd.GetHerdAgentList(ref herdAgents);

            Console.SetCursorPosition(herdAgentsRow, herdAgentsLine);
            Console.WriteLine("{0} available", herdAgents.Count);

            if (herdAgents.Count == 0)
            {
                Console.WriteLine("Error: no herd agents found to run the experiment batch");
            }

            Console.Write("Total progress: ");

            List <ExperimentalUnit> experiments = new List <ExperimentalUnit>();

            foreach (Experiment exp in batch.Experiments)
            {
                experiments.AddRange(exp.ExperimentalUnits);
            }
            CancellationTokenSource cancelSource = new CancellationTokenSource();

            Monitoring.MsgDispatcher dispatcher = new Monitoring.MsgDispatcher(OnJobAssigned, OnJobFinished
                                                                               , DispatchOnAllStatesChanged, DispatchOnStateChanged
                                                                               , DispatchOnMessageReceived, DispatchOnExperimentalUnitLaunched
                                                                               , Log, cancelSource.Token);

            int numExecutedExperimentalUnits =
                JobDispatcher.RunExperimentsAsync(experiments, herdAgents, dispatcher, cancelSource).Result;

            Console.SetCursorPosition(0, resultLine);
            Console.WriteLine("Badger finished: " + numExecutedExperimentalUnits + " experimental units were succesfully run");

            g_writer.Close();
        }