public static bool Create(string agentApplicationDirectory, bool useTestMode, out ServiceFabricLocalNodeManager serviceFabricLocalNodeManager) { serviceFabricLocalNodeManager = null; ServiceFabricLocalNodeManager localNodeManager = new ServiceFabricLocalNodeManager(agentApplicationDirectory, useTestMode); if (!localNodeManager.Initialize()) { return(false); } serviceFabricLocalNodeManager = localNodeManager; return(true); }
/* * Test mode allows testing of ServiceFabricAutopilotAgent outside an Autopilot hosting environment. * In test mode, all dependencies on AP Runtime are replaced by test environment equivalences: * Logging => text log * Configuration => default test configurations */ public void Start(bool useTestMode = false) { string agentApplicationDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); if (!useTestMode) { APRuntime.Initialize(StringConstants.ApplicationConfigurationFileName); } TextLogger.InitializeLogging(StringConstants.CustomLogIdName, useTestMode, StringConstants.TestModeLogFileNameTemplate, StringConstants.TestModeLogDirectoryName, StringConstants.TestModeTraceListenerName); TextLogger.LogInfo("Starting Service Fabric Autopilot Agent."); if (!ConfigurationManager.GetCurrentConfigurations(useTestMode)) { this.Exit(false); return; } TextLogger.SetLogLevel(ConfigurationManager.LogLevel); ConfigurationManager.LogCurrentConfigurations(); ServiceFabricLocalNodeManager localNodeManager; if (!ServiceFabricLocalNodeManager.Create(agentApplicationDirectory, useTestMode, out localNodeManager)) { this.Exit(false); return; } this.localNodeManager = localNodeManager; this.agentStatus.InitializeAgentStatus(); this.RegisterConsoleCancelEventNotifications(); this.backgroundStateMachineTask = Task.Factory.StartNew( () => this.RunBackgroundStateMachine(this.backgroundStateMachineCancellationTokenSource.Token), this.backgroundStateMachineCancellationTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }