public IAppInitializedDetector create(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            //if( string.IsNullOrEmpty(definitionString) )
            //{
            //    throw new UnknownAppInitDetectorType( appDef.AppIdTuple + " <Init condition not defined>" );
            //}

            //string name="";
            //string args="";
            //parseDefinitionString(definitionString, ref name, ref args);

            //if( !creators.ContainsKey(name) )
            //{
            //    throw new UnknownAppInitDetectorType( definitionString );
            //}

            //CreateDeleg cd = creators[name];
            //return cd(appDef, appState, processId, args);

            string name = xml.Name.LocalName;

            CreateDeleg cd = Find(name);
            if( cd == null )
            {
                throw new UnknownAppInitDetectorType( name );
            }

            return cd(appDef, appState, processId, xml);
        }
Exemplo n.º 2
0
        string getAppStatusCode( AppIdTuple appIdTuple, AppState st, bool isPartOfPlan )
        {
            string stCode = "Not running";

            var currPlan = ctrl.GetCurrentPlan();
            bool planRunning = (currPlan != null) && currPlan.Running && isPartOfPlan;
            bool connected = callbacks.isConnectedDeleg();
            var currTime = DateTime.UtcNow;
            bool isRemoteApp = appIdTuple.MachineId != this.machineId;

            if( isRemoteApp && !connected )
            {
                stCode = "??? (discon.)";
                return stCode;
            }

            if( planRunning && !st.PlanApplied )
            {
                stCode = "Planned";
            }

            if (st.Started)
            {
                if (st.Running && !st.Initialized)
                {
                    stCode = "Initializing";
                }
                if (st.Running && st.Initialized)
                {
                    stCode = "Running";
                }
                if (!st.Running)
                {
                    if (st.Killed)
                    {
                        stCode = "Killed";
                    }
                    else
                    {
                        stCode = string.Format("Terminated ({0})", st.ExitCode);
                    }
                }
            }
            else
            if (st.StartFailed)
            {
                stCode = "Failed to start";
            }

            var statusInfoAge = currTime - st.LastChange;
            if( isRemoteApp && statusInfoAge > TimeSpan.FromSeconds(3) )
            {
                stCode += string.Format(" (no info for {0:0} sec)", statusInfoAge.TotalSeconds);
            }

            return stCode;
        }
Exemplo n.º 3
0
        public void testFactoryFailsForUnknownType()
        {
            AppDef appDef = new AppDef();
            AppState appState = new AppState();

            var f = new AppInitializedDetectorFactory();

            var d = f.create( appDef, appState, 0, XElement.Parse("<unknown>any-params</unknown>") );
        }
Exemplo n.º 4
0
        public ExitCodeInitDetector(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            this.appState = appState;

            try
            {
                string args = xml.Value;

                // " -1, 1, 2,3, 6-8 "
                foreach(var token in args.Split(','))
                {
                    // fill the exitCodes
                    var trimmed = token.Trim();
                    Match m;
                    m = Regex.Match( trimmed, "(-?\\d+)-(-?\\d+)" ); // "1-6" or "-4-8" or "-4--1"
                    if (m.Success)
                    {
                        var lo = int.Parse(m.Groups[1].Value);
                        var hi = int.Parse(m.Groups[2].Value);
                        if( lo <= hi )
                        {
                            for( var i = lo; i <= hi; i++ )
                            {
                                exitCodes.Add(i);
                            }
                        }
                    }
                    else
                    {
                        m = Regex.Match( trimmed, "(-?\\d+)" );
                        if (m.Success)
                        {
                            var i = int.Parse(m.Groups[0].Value);
                            exitCodes.Add(i);
                        }
                    }
                }

                // no exit codes specified??
                if (exitCodes.Count == 0)
                {
                    throw new InvalidAppInitDetectorArguments(Name, args);
                }

                appState.Initialized = false; // will be set to true as soon as the exit code condition is met

            }
            catch( Exception ex )
            {
                if (ex is FormatException || ex is OverflowException)
                {
                    throw new InvalidAppInitDetectorArguments(Name, xml.ToString());
                }
                throw;
            }
        }
Exemplo n.º 5
0
        public void testFactoryCreatesTimeOut()
        {
            AppDef appDef = new AppDef();
            AppState appState = new AppState();

            var f = new AppInitializedDetectorFactory();

            IAppInitializedDetector d = f.create( appDef, appState, 0, XElement.Parse("<timeout> 0.1</timeout>") );

            Assert.AreEqual(typeof(TimeOutInitDetector), d.GetType(), "correct detector type created");
        }
Exemplo n.º 6
0
        public AutoRestarter(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            this.appState = appState;

            parseXml( xml );

            state =  eState.WaitingForCrash;

            this.processId = processId;
            this.appDef = appDef;
        }
Exemplo n.º 7
0
        public void testTimeOutDetector()
        {
            AppDef appDef = new AppDef();
            AppState appState = new AppState();

            var initialTicks = DateTime.UtcNow.Ticks;
            IAppInitializedDetector d = new TimeOutInitDetector(appDef, appState, 0, XElement.Parse("<timeout>0.1</timeout>"));

            Assert.AreEqual(false, d.IsInitialized, "not initialized immediately");
            Thread.Sleep(100);
            Assert.AreEqual(true, d.IsInitialized, "initialized after time out");
        }
Exemplo n.º 8
0
        public WindowPositioner(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            this.appState = appState;
            //this.pos = pos;
            this.processId = processId;

            parseXml( xml );

            //if( pos.Rect == System.Drawing.Rectangle.Empty ) throw new InvalidAppConfig(appDef.AppIdTuple, "WindowPos: Missing Rectangle attribute");
            if( string.IsNullOrEmpty( pos.TitleRegExp ))  throw new InvalidAppConfig(appDef.AppIdTuple, "WindowPos: Missing TitleRegExp atribute");

            titleRegExp = new Regex( pos.TitleRegExp );
        }
Exemplo n.º 9
0
        public void testDetectorSingle()
        {
            AppDef appDef = new AppDef();
            AppState appState = new AppState();

            appState.Started = true;
            appState.Running = true;
            IAppInitializedDetector d = new ExitCodeInitDetector(appDef, appState, 0, XElement.Parse("<timeout>1</timeout>"));

            Assert.AreEqual(false, d.IsInitialized, "not initialized immediately");
            appState.Running = false;
            appState.ExitCode = 0;
            Assert.AreEqual(false, d.IsInitialized, "not initialized if wrong exit code");
            appState.ExitCode = 1;
            Assert.AreEqual(true, d.IsInitialized, "initialized if correct exit code");
        }
Exemplo n.º 10
0
        public WindowPoppedUpInitDetector(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            this.appState = appState;
            this.processId = processId;
            this.appDef = appDef;

            try
            {
                parseArgs( xml );
            }
            catch
            {
                throw new InvalidAppInitDetectorArguments(Name, xml.ToString());
            }

            appState.Initialized = false; // will be set to true as soon as the exit code condition is met

            log.DebugFormat("WindowPoppedUpInitDetector: Waiting for window with titleRegExp {0}, appid {1}, pid {2}", titleRegExpString, appDef.AppIdTuple, processId );
        }
Exemplo n.º 11
0
        //<TimeOut>2.0</TimeOut>
        public TimeOutInitDetector(AppDef appDef, AppState appState, int processId, XElement xml)
        {
            this.appState = appState;
            this.processId = processId;
            this.appDef = appDef;

            try
            {
                var timeString = xml.Value;

                TimeOut = Double.Parse( timeString, CultureInfo.InvariantCulture );
            }
            catch
            {
                throw new InvalidAppInitDetectorArguments(Name, xml.ToString());
            }

            appState.Initialized = false; // will be set to true as soon as the exit code condition is met

            InitialTicks = DateTime.UtcNow.Ticks;
            log.DebugFormat("TimeOutInitDetector: Waiting {0} sec, appid {1}, pid {2}", TimeOut, appDef.AppIdTuple, processId );
        }
Exemplo n.º 12
0
 public void testDetectorFailsOnInvalidParams()
 {
     AppDef appDef = new AppDef();
     AppState appState = new AppState();
     var d = new ExitCodeInitDetector(appDef, appState, 0, XElement.Parse("<timeout>abcd-not-a-double</timeout>"));
 }
Exemplo n.º 13
0
 public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state)
 {
     localOps.SetRemoteAppState(appIdTuple, state);
 }
 public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state)
 {
     impl.SetRemoteAppState(appIdTuple, state);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Sets new status info for given app.
 /// To be used for remote apps whose status gets received from master.
 /// </summary>
 /// <param name="appIdTuple"></param>
 /// <param name="appState"></param>
 public void SetRemoteAppState( AppIdTuple appIdTuple, AppState appState )
 {
     appsState[appIdTuple] = appState;
 }
Exemplo n.º 16
0
 public static IAppInitializedDetector create(AppDef appDef, AppState appState, int processId, XElement xml)
 {
     return new WindowPoppedUpInitDetector(appDef, appState, processId, xml);
 }
Exemplo n.º 17
0
 public void SetRemoteAppState(AppIdTuple appIdTuple, AppState state)
 {
     appsState[appIdTuple] = state;
 }