Example #1
0
 public void LoadDriverImages(HardwareInteractionEnvironment hie)
 {
     if (Params.RUN_HIE)
     {
         Logger.Write(Logger.Tag.WARN, "Removing dangeling containers...");
         while (true)
         {
             try
             {
                 Docker.Instance.RemoveStoppedContainers().GetAwaiter().GetResult();
                 break;
             } catch
             {
                 Utils.Sleep(Utils.GetRandomInt(Params.ELECTION_TIMEOUT_START, Params.ELECTION_TIMEOUT_END));
             }
         }
         Logger.Write(Logger.Tag.INFO, "Preparing warm start...");
         foreach (string image in Get_Images)
         {
             Utils.Sleep(Utils.GetRandomInt(Params.ELECTION_TIMEOUT_START, Params.ELECTION_TIMEOUT_END));
             hie.PrepareWarmStart(image);
         }
     }
 }
Example #2
0
        ///<summary>
        ///<para>A tangible node is started with input params from standard-in to localize config.</para>
        ///<para>Ex. > dotnet run Program.cs filepath</para>
        ///</summary>
        public TangibleNode(string[] args)
        {
            // USED FOR DEBUGGING/EVALUATION
            // bool _enableStateLog = false;

            Settings settings = default(Settings);

            if (args.Length > 0)
            {
                try
                {
                    // load the configuration file by the specified filepath
                    settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(args[0]));

                    // OPTIONAL ARE ORGANISED EMPHASISING EVALUATION
                    if (settings.Optional == null)
                    {
                        settings.Optional = new Optional();
                    }
                    if (args.Length > 1)
                    {
                        settings.ID = args[1];
                    }

                    Logger.Instance._tags = new HashSet <Logger.Tag>(settings.LogLevel);
                    // DEBUGGING
                    Console.WriteLine(args[0] + " : " + JsonConvert.SerializeObject(settings, Formatting.Indented));

                    // write the header, so that when the log is piped, the columns are given
                    Logger.WriteHeader();
                    Logger.Write(Logger.Tag.INFO, "Loaded settings.");
                } catch
                {
                    // exit if there are no settings provided
                    Logger.Write(Logger.Tag.FATAL, "Failed to load settings.");
                }
            }
            else
            {
                Logger.Write(Logger.Tag.INFO, "No settings provided.");
            }

            // DEBUGGING/EVALUATION
            Utils.Sleep(settings.Optional.WaitBeforeStart_MS);

            // parse the settings
            Params.LoadEnvironment(settings);

            // // DEBUGGING/EVALUATION
            // if (args.Length > 1)
            // {
            //     _enableStateLog = bool.Parse(args[1]);
            //     if (_enableStateLog)
            //     {
            //         FileLogger.EnableFileLog();
            //     }
            // }

            // FileLogger.Instance.CreateLogFile();
            // FileLogger.Instance.WriteHeader();

            // initializing the listener
            _listener = new AsynchronousSocketListener();

            // initializing the HA and loading the RDF model
            HardwareAbstraction ha = new HardwareAbstraction(settings.RDFPath);

            HardwareInteractionEnvironment hie = new HardwareInteractionEnvironment();

            // prepare warm start
            ha.LoadDriverImages(hie);

            // initializing the consumer and providing the HA
            Consumer consumer = new Consumer(ha);

            // initializing the node itself [as a statemachine]
            StateMachine _stateMachine = new StateMachine(consumer, hie);

            _stateMachineThread = new Thread(() => {
                _stateMachine.Start(settings.Members);
            });
            _consumerThread = new Thread(() => {
                consumer.Start();
            });
        }
Example #3
0
 public StateMachine(Consumer consumer, HardwareInteractionEnvironment hie)
 {
     _consumer      = consumer;
     HIE            = hie;
     _sleepingTimer = new TTimer("sleepingTimer");
 }