示例#1
0
        public void StartSimulation()
        {
            //Common Load Manager for Zhao (refactor to be a network resource)
            Global.CommonLoadManager = new CommonLoadManager(AccountingModuleObject);

            //Master Machine
            MasterMachine masterMachine = (MasterMachine)_masterFactory.GetMachine();

            MachineControllerObject.AddMachine(masterMachine);

            //Host Machines
            for (int i = 1; i <= (int)CurrentConfiguration.SimulationSize; i++)
            {
                MachineControllerObject.AddMachine(_hostFactory.GetMachine());
            }
            //Add registry when needed
            if (CurrentConfiguration.ContainersType == ContainersType.D)
            {
                Machine registry = _registryFactory.GetMachine();
                MachineControllerObject.AddMachine(registry);
            }

            var hosts = MachineTableObject.GetAllMachines();

            for (int i = 1; i <= (int)CurrentConfiguration.SimulationSize; i++)
            {
                List <Load> loads = LoadFactory.GenerateLoadList(CurrentConfiguration.StartPercent, CurrentConfiguration.SimulationSize);
                foreach (var load in loads)
                {
                    var container = _containerFactory.GetContainer(load);
                    if (container.ContainerType == ContainersType.D)
                    {
                        var          dockerregistry  = hosts.Last() as DockerRegistryMachine;
                        var          dockercontainer = container as DockerContainer;
                        List <Image> images          = dockerregistry.GetImagesList(dockercontainer.ImageId);
                        (hosts[i] as HostMachine).AddContainer(container, images);
                    }
                    else
                    {
                        (hosts[i] as HostMachine).AddContainer(container);
                    }
                }
            }

            MachineControllerObject.StartSimulation();

            var done = false;
            int c    = 0;

            for (int x = 0; x <= Global.GetSimulationTime; x += Global.AccountTime, c++)
            {
                Debug.WriteLine($"Time = {x}/{Global.GetSimulationTime}");
                AccountingModuleObject.ReadCurrentState();
                Thread.Sleep(Global.AccountTime);
                if (x >= Global.GetSimulationTime / 2 && !done)
                {
                    if (CurrentConfiguration.ChangeAction == LoadChangeAction.Opposite)
                    {
                        StartWaveSimmulationAction(LoadChangeAction.Burst, m => true, m => m.ContainerId % 2 == 0);
                        StartWaveSimmulationAction(LoadChangeAction.Drain, m => true, m => m.ContainerId % 2 == 1);
                    }
                    else if (CurrentConfiguration.ChangeAction == LoadChangeAction.None)
                    {
                    }
                    else
                    {
                        StartWaveSimmulationAction(CurrentConfiguration.ChangeAction, m => true, m => m.ContainerId % 2 == 0);
                    }
                    done = true;
                }
                //Add container to queue
                if (CurrentConfiguration.ChangeAction == LoadChangeAction.None)
                {
                    int             s           = 0;
                    Predicate <int> anotherTest = new Predicate <int>(n => true);
                    switch (CurrentConfiguration.SimulationSize)
                    {
                    case SimulationSize.Twenty:
                        s           = 3;
                        anotherTest = n => n % 4 == 0;
                        break;

                    case SimulationSize.Fifty:
                        s = 2;
                        break;

                    case SimulationSize.Hundred:
                        s           = 7;
                        anotherTest = n => n % 2 == 0;
                        break;

                    case SimulationSize.TwoHundred:
                        s = 7;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    for (int i = 0; i < s & anotherTest(c); i++)
                    {
                        masterMachine.AddContainer(_containerFactory.GetContainer(LoadFactory.GetRandomLoad()));
                    }
                }
            }
            EndSimulation();
        }
示例#2
0
 private void EndSimulation()
 {
     AccountingModuleObject.StopCounting();
     MachineControllerObject.EndSimulation();
     RandomNumberGenerator.ClearRandomNumber();
 }