Exemplo n.º 1
0
		public static void UseStardustManager(this IAppBuilder appBuilder,
		                                      ManagerConfiguration managerConfiguration,
		                                      ILifetimeScope lifetimeScope)
		{
			appBuilder.Map(
				managerConfiguration.Route,
				inner =>
				{
					var config = new HttpConfiguration
					{
						DependencyResolver = new AutofacWebApiDependencyResolver(lifetimeScope)
					};

					config.MapHttpAttributeRoutes();

					config.Services.Add(typeof (IExceptionLogger),
					                    new GlobalExceptionLogger());

					inner.UseAutofacWebApi(config);
					inner.UseWebApi(config);
				});

			var builder = new ContainerBuilder();
			builder.RegisterModule(new ManagerModule(managerConfiguration));
			builder.Update(lifetimeScope.ComponentRegistry);

			//to start the timers etc
			lifetimeScope.Resolve<ManagerController>();
		}
Exemplo n.º 2
0
        //private static readonly ILog ManagerLogger = LogManager.GetLogger("Stardust.ManagerLog");

        public JobManager(IJobRepository jobRepository,
                          IWorkerNodeRepository workerNodeRepository,
                          ManagerConfiguration managerConfiguration,
                          JobPurgeTimer jobPurgeTimer,
                          NodePurgeTimer nodePurgeTimer,
                          NodeManager nodeManager,
                          ILog logger)
        {
            _jobRepository        = jobRepository;
            _workerNodeRepository = workerNodeRepository;
            _managerConfiguration = managerConfiguration;
            _nodeManager          = nodeManager;
            ManagerLogger         = logger;

            _checkAndAssignJob.Elapsed += AssignJobToWorkerNodes_Elapsed;
            _checkAndAssignJob.Interval = _managerConfiguration.CheckNewJobIntervalSeconds * 1000;
            _checkAndAssignJob.Start();

            _checkHeartbeatsTimer.Elapsed += CheckHeartbeats_Elapsed;
            _checkHeartbeatsTimer.Interval = _managerConfiguration.AllowedNodeDownTimeSeconds * 1000;
            _checkHeartbeatsTimer.Start();

            jobPurgeTimer.Start();
            nodePurgeTimer.Start();
        }
Exemplo n.º 3
0
        public static void UseStardustManager(this IAppBuilder appBuilder,
                                              ManagerConfiguration managerConfiguration,
                                              ILifetimeScope lifetimeScope)
        {
            appBuilder.Map(
                managerConfiguration.Route,
                inner =>
            {
                var config = new HttpConfiguration
                {
                    DependencyResolver = new AutofacWebApiDependencyResolver(lifetimeScope)
                };

                config.MapHttpAttributeRoutes();

                config.Services.Add(typeof(IExceptionLogger),
                                    new GlobalExceptionLogger());

                inner.UseAutofacWebApi(config);
                inner.UseWebApi(config);
            });

            var builder = new ContainerBuilder();

            builder.RegisterModule(new ManagerModule(managerConfiguration));
            builder.Update(lifetimeScope.ComponentRegistry);

            //to start the timers etc
            lifetimeScope.Resolve <ManagerController>();
        }
Exemplo n.º 4
0
		public void SetUp()
		{
			ContainerBuilder containerBuilder = new ContainerBuilder();

			ManagerConfiguration config = new ManagerConfiguration(
				ConfigurationManager.ConnectionStrings["ManagerConnectionString"].ConnectionString, "Route", 60, 20, 1, 1, 1,1);

			containerBuilder.RegisterModule(new ManagerModule(config));
			_container = containerBuilder.Build();
		}
		protected override void SetUp(ContainerBuilder builder)
		{
			ManagerConfiguration managerConfiguration = new ManagerConfiguration("connectionstring", "route", 60, 20, 1, 1, 1,1);
			builder.RegisterInstance(managerConfiguration).As<ManagerConfiguration>().SingleInstance();
			builder.RegisterType<Validator>().SingleInstance();
			builder.RegisterType<FakeHttpSender>().As<IHttpSender>().SingleInstance().AsSelf();
			builder.Register(c => new FakeJobRepository()).As<IJobRepository>();
			builder.Register(c => new FakeWorkerNodeRepository()).As<IWorkerNodeRepository>();
			builder.RegisterApiControllers(typeof(ManagerController).Assembly);
			builder.RegisterType<JobManager>().SingleInstance();
			builder.RegisterType<NodeManager>().SingleInstance();
			builder.RegisterType<RetryPolicyProvider>().SingleInstance();
			builder.RegisterType<JobPurgeTimerFake>().As<JobPurgeTimer>().SingleInstance();
			builder.RegisterType<NodePurgeTimerFake>().As<NodePurgeTimer>().SingleInstance();
		}
Exemplo n.º 6
0
		protected override void SetUp(ContainerBuilder builder)
		{
			ManagerConfiguration config = new ManagerConfiguration(
				ConfigurationManager.ConnectionStrings["ManagerConnectionString"].ConnectionString, "Route", 60, 20, 10, 1, 24,1);

			builder.RegisterInstance(config).SingleInstance();
			builder.RegisterType<RetryPolicyProvider>().SingleInstance();
			builder.RegisterType<CreateSqlCommandHelper>().SingleInstance();
			builder.RegisterType<JobManager>().SingleInstance();

			builder.RegisterType<NodeManager>();

			builder.RegisterType<JobRepository>().As<IJobRepository>().SingleInstance();
			builder.RegisterType<WorkerNodeRepository>().As<IWorkerNodeRepository>().SingleInstance();

			builder.RegisterType<FakeHttpSender>().As<IHttpSender>().SingleInstance();
			builder.RegisterType<JobPurgeTimerFake>().As<JobPurgeTimer>().SingleInstance();
			builder.RegisterType<NodePurgeTimerFake>().As<NodePurgeTimer>().SingleInstance();
		}
Exemplo n.º 7
0
		public JobManager(IJobRepository jobRepository,
		                  IWorkerNodeRepository workerNodeRepository,
		                  ManagerConfiguration managerConfiguration,
						  JobPurgeTimer jobPurgeTimer,
						  NodePurgeTimer nodePurgeTimer)
		{
			_jobRepository = jobRepository;
			_workerNodeRepository = workerNodeRepository;
			_managerConfiguration = managerConfiguration;

			_checkAndAssignJob.Elapsed += AssignJobToWorkerNodes_Elapsed;
			_checkAndAssignJob.Interval = _managerConfiguration.CheckNewJobIntervalSeconds*1000;
			_checkAndAssignJob.Start();

			_checkHeartbeatsTimer.Elapsed += CheckHeartbeats_Elapsed;
			_checkHeartbeatsTimer.Interval = _managerConfiguration.AllowedNodeDownTimeSeconds*200;
			_checkHeartbeatsTimer.Start();

			jobPurgeTimer.Start();
			nodePurgeTimer.Start();
		}
Exemplo n.º 8
0
		public JobRepository(ManagerConfiguration managerConfiguration,
		                     RetryPolicyProvider retryPolicyProvider,
							 CreateSqlCommandHelper createSqlCommandHelper, 
							 IHttpSender httpSender)
		{
			if (retryPolicyProvider == null)
			{
				throw new ArgumentNullException("retryPolicyProvider");
			}

			if (retryPolicyProvider.GetPolicy() == null)
			{
				throw new ArgumentNullException("retryPolicyProvider.GetPolicy");
			}

			_connectionString = managerConfiguration.ConnectionString;
			_createSqlCommandHelper = createSqlCommandHelper;
			_httpSender = httpSender;

			_retryPolicy = retryPolicyProvider.GetPolicy();
		}
Exemplo n.º 9
0
        //private static readonly ILog ManagerLogger = LogManager.GetLogger("Stardust.ManagerLog");

        public JobRepository(ManagerConfiguration managerConfiguration,
                             RetryPolicyProvider retryPolicyProvider,
                             IHttpSender httpSender,
                             JobRepositoryCommandExecuter jobRepositoryCommandExecuter,
                             ILog managerLogger)
        {
            if (retryPolicyProvider == null)
            {
                throw new ArgumentNullException("retryPolicyProvider");
            }

            if (retryPolicyProvider.GetPolicy() == null)
            {
                throw new ArgumentNullException("retryPolicyProvider.GetPolicy");
            }

            _connectionString             = managerConfiguration.ConnectionString;
            _httpSender                   = httpSender;
            _jobRepositoryCommandExecuter = jobRepositoryCommandExecuter;
            ManagerLogger                 = managerLogger;

            _retryPolicy = retryPolicyProvider.GetPolicy();
        }
Exemplo n.º 10
0
 public ManagerModule(ManagerConfiguration managerConfiguration)
 {
     _managerConfiguration = managerConfiguration;
 }
Exemplo n.º 11
0
		public static void Main(string[] args)
		{
			var configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
			XmlConfigurator.ConfigureAndWatch(new FileInfo(configurationFile));

			SetConsoleCtrlHandler(ConsoleCtrlCheck,
			                      true);

			var managerName = ConfigurationManager.AppSettings["ManagerName"];
			var baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

			var managerAddress = baseAddress.Scheme + "://+:" +
			                     baseAddress.Port + "/";

			AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;


			WhoAmI =
				"[MANAGER CONSOLE HOST ( " + managerName + ", " + managerAddress + " )," + Environment.MachineName.ToUpper() + "]";

			Logger.InfoWithLineNumber(WhoAmI + " : started.");

			AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

			var managerConfiguration = new ManagerConfiguration(
				ConfigurationManager.ConnectionStrings["ManagerConnectionString"].ConnectionString,
				ConfigurationManager.AppSettings["route"],
				int.Parse(ConfigurationManager.AppSettings["AllowedNodeDownTimeSeconds"]),
				int.Parse(ConfigurationManager.AppSettings["CheckNewJobIntervalSeconds"]),
				int.Parse(ConfigurationManager.AppSettings["purgeJobsBatchSize"]),
				int.Parse(ConfigurationManager.AppSettings["purgeJobsIntervalHours"]),
				int.Parse(ConfigurationManager.AppSettings["PurgeJobsOlderThanHours"]),
				int.Parse(ConfigurationManager.AppSettings["PurgeNodesIntervalHours"]));
			
			var container = new ContainerBuilder().Build();
			var config = new HttpConfiguration();

			using (WebApp.Start(managerAddress,
			                    appBuilder =>
			                    {
				                    string owinListenerName = "Microsoft.Owin.Host.HttpListener.OwinHttpListener";
				                    OwinHttpListener owinListener = (OwinHttpListener) appBuilder.Properties[owinListenerName];

				                    int maxAccepts;
				                    int maxRequests;
				                    owinListener.GetRequestProcessingLimits(out maxAccepts, out maxRequests);

				                    owinListener.SetRequestQueueLimit(int.MaxValue);
				                    owinListener.SetRequestProcessingLimits(int.MaxValue, int.MaxValue);

				                    appBuilder.UseAutofacMiddleware(container);

				                    // Configure Web API for self-host. 
				                    appBuilder.UseStardustManager(managerConfiguration,
				                                                  container);

				                    appBuilder.UseAutofacWebApi(config);
				                    appBuilder.UseWebApi(config);

			                    }))
			{
				Logger.InfoWithLineNumber(WhoAmI + ": Started listening on port : ( " + baseAddress + " )");

				QuitEvent.WaitOne();
			}
		}
Exemplo n.º 12
0
		public ManagerModule(ManagerConfiguration managerConfiguration)
		{
			_managerConfiguration = managerConfiguration;
		}
Exemplo n.º 13
0
 public WorkerNodeRepository(ManagerConfiguration managerConfiguration,
                             RetryPolicyProvider retryPolicyProvider)
 {
     _connectionString = managerConfiguration.ConnectionString;
     _retryPolicy      = retryPolicyProvider.GetPolicy();
 }
Exemplo n.º 14
0
		public JobPurgeTimerFake(RetryPolicyProvider retryPolicyProvider, ManagerConfiguration managerConfiguration) : base(retryPolicyProvider, managerConfiguration)
		{
		}
Exemplo n.º 15
0
		public WorkerNodeRepository(ManagerConfiguration managerConfiguration,
		                            RetryPolicyProvider retryPolicyProvider)
		{
			_connectionString = managerConfiguration.ConnectionString;
			_retryPolicy = retryPolicyProvider.GetPolicy();
		}