Ejemplo n.º 1
0
        public override void Load()
        {
            DashboardAccountContext context = TryCreateAccount();

            Bind <DashboardAccountContext>().ToConstant(context);

            this.BindFilter <AccountContextAttribute>(FilterScope.Global, 0);

            CloudStorageAccount account = context.StorageAccount;

            if (account == null)
            {
                return;
            }

            CloudBlobClient  blobClient  = account.CreateCloudBlobClient();
            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            Bind <CloudStorageAccount>().ToConstant(account);
            Bind <CloudBlobClient>().ToConstant(blobClient);
            Bind <CloudQueueClient>().ToConstant(queueClient);

            Bind <IHostVersionReader>().To <HostVersionReader>();
            Bind <IDashboardVersionManager>().To <DashboardVersionManager>();
            Bind <IFunctionInstanceLookup>().To <FunctionInstanceLookup>();
            Bind <IFunctionInstanceLogger>().To <FunctionInstanceLogger>();
            Bind <IHostIndexManager>().To <HostIndexManager>();
            Bind <IFunctionIndexVersionManager>().To <FunctionIndexVersionManager>();
            Bind <IFunctionIndexManager>().To <FunctionIndexManager>();
            Bind <IFunctionLookup>().To <FunctionLookup>();
            Bind <IFunctionIndexReader>().To <FunctionIndexReader>();
            Bind <IHeartbeatValidityMonitor>().To <HeartbeatValidityMonitor>();
            Bind <IHeartbeatMonitor>().To <HeartbeatMonitor>();
            Bind <Cache>().ToConstant(HttpRuntime.Cache);
            Bind <IFunctionStatisticsReader>().To <FunctionStatisticsReader>();
            Bind <IFunctionStatisticsWriter>().To <FunctionStatisticsWriter>();
            Bind <IRecentInvocationIndexReader>().To <RecentInvocationIndexReader>();
            Bind <IRecentInvocationIndexWriter>().To <RecentInvocationIndexWriter>();
            Bind <IRecentInvocationIndexByFunctionReader>().To <RecentInvocationIndexByFunctionReader>();
            Bind <IRecentInvocationIndexByFunctionWriter>().To <RecentInvocationIndexByFunctionWriter>();
            Bind <IRecentInvocationIndexByJobRunReader>().To <RecentInvocationIndexByJobRunReader>();
            Bind <IRecentInvocationIndexByJobRunWriter>().To <RecentInvocationIndexByJobRunWriter>();
            Bind <IRecentInvocationIndexByParentReader>().To <RecentInvocationIndexByParentReader>();
            Bind <IRecentInvocationIndexByParentWriter>().To <RecentInvocationIndexByParentWriter>();
            Bind <IHostMessageSender>().To <HostMessageSender>();
            Bind <IPersistentQueueReader <PersistentQueueMessage> >().To <PersistentQueueReader <PersistentQueueMessage> >();
            Bind <IFunctionQueuedLogger>().To <FunctionInstanceLogger>();
            Bind <IHostIndexer>().To <HostIndexer>();
            Bind <IFunctionIndexer>().To <FunctionIndexer>();
            Bind <IIndexer>().To <UpgradeIndexer>();
            Bind <IInvoker>().To <Invoker>();
            Bind <IAbortRequestLogger>().To <AbortRequestLogger>();
            Bind <IAborter>().To <Aborter>();

            Bind <IIndexerLogWriter>().To <IndexerBlobLogWriter>();
            Bind <IIndexerLogReader>().To <IndexerBlobLogReader>();
        }
Ejemplo n.º 2
0
        protected void Application_Start()
        {
            var kernel = NinjectWebCommon.Kernel;

            DashboardAccountContext context = kernel.Get <DashboardAccountContext>();

            AreaRegistration.RegisterAllAreas();

            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            if (!context.HasSetupError)
            {
                RouteConfig.RegisterRoutes(RouteTable.Routes);
            }
            else
            {
                RouteConfig.RegisterNoAccountRoutes(RouteTable.Routes);
            }

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            if (!context.HasSetupError)
            {
                ModelBinderConfig.Register(kernel);
                HostVersionConfig.RegisterWarnings(kernel.Get <IHostVersionReader>());
            }

            _indexer = kernel.TryGet <IIndexer>();

            if (_indexer != null)
            {
                // Using private threads for now. If indexing switches to async storage calls we need to
                // either use the CLR threadpool or figure out how to schedule the async callbacks on the
                // private threads.
                for (int i = 0; i < Environment.ProcessorCount; i++)
                {
                    new Thread(IndexerWorkerLoop).Start();
                }
            }
        }
Ejemplo n.º 3
0
        private static DashboardAccountContext TryCreateAccount()
        {
            DashboardAccountContext context = new DashboardAccountContext();

            string connectionString = ConnectionStringProvider.GetConnectionString(
                DashboardAccountContext.ConnectionStringName);

            if (String.IsNullOrEmpty(connectionString))
            {
                context.ConnectionStringState = ConnectionStringState.Missing;
                return(context);
            }

            CloudStorageAccount account;

            if (!CloudStorageAccount.TryParse(connectionString, out account))
            {
                context.ConnectionStringState = ConnectionStringState.Unparsable;
                return(context);
            }

            context.SdkStorageAccountName = account.Credentials.AccountName;

            if (!StorageAccountValidator.ValidateEndpointsSecure(account))
            {
                context.ConnectionStringState = ConnectionStringState.Insecure;
                return(context);
            }

            if (!StorageAccountValidator.ValidateAccountAccessible(account))
            {
                context.ConnectionStringState = ConnectionStringState.Inaccessible;
                return(context);
            }

            context.ConnectionStringState = ConnectionStringState.Valid;
            context.StorageAccount        = account;
            return(context);
        }
Ejemplo n.º 4
0
        private static DashboardAccountContext TryCreateAccount()
        {
            DashboardAccountContext context = new DashboardAccountContext();

            string connectionString = ConnectionStringProvider.GetConnectionString(
                DashboardAccountContext.ConnectionStringName);
            if (String.IsNullOrEmpty(connectionString))
            {
                context.ConnectionStringState = ConnectionStringState.Missing;
                return context;
            }

            CloudStorageAccount account;
            if (!CloudStorageAccount.TryParse(connectionString, out account))
            {
                context.ConnectionStringState = ConnectionStringState.Unparsable;
                return context;
            }

            context.SdkStorageAccountName = account.Credentials.AccountName;

            if (!StorageAccountValidator.ValidateEndpointsSecure(account))
            {
                context.ConnectionStringState = ConnectionStringState.Insecure;
                return context;
            }

            if (!StorageAccountValidator.ValidateAccountAccessible(account))
            {
                context.ConnectionStringState = ConnectionStringState.Inaccessible;
                return context;
            }

            context.ConnectionStringState = ConnectionStringState.Valid;
            context.StorageAccount = account;
            return context;
        }
Ejemplo n.º 5
0
        public static void Load(ContainerBuilder builder)
        {
            DashboardAccountContext context = TryCreateAccount();

            builder.RegisterInstance(context);

            // http://stackoverflow.com/a/21535799/534514
            builder.RegisterType <AccountContextAttribute>().AsResultFilterFor <Controller>().InstancePerRequest();
            builder.RegisterType <HandleErrorAttribute>().AsExceptionFilterFor <Controller>();
            builder.RegisterFilterProvider();

            CloudStorageAccount account = context.StorageAccount;

            if (account == null)
            {
                return;
            }

            builder.RegisterInstance(account).As <CloudStorageAccount>();
            builder.RegisterInstance(account.CreateCloudBlobClient()).As <CloudBlobClient>();

            CloudTableClient tableClient = account.CreateCloudTableClient();

            var tableProvider = GetNewLoggerTableProvider(tableClient);

            if (tableProvider != null)
            {
                context.DisableInvoke = true;

                // fast table reader.
                var reader = LogFactory.NewReader(tableProvider);
                builder.RegisterInstance(reader).As <ILogReader>();

                var s = new FastTableReader(reader);

                builder.RegisterInstance(s)
                .As <IRecentInvocationIndexReader>()
                .As <IRecentInvocationIndexByFunctionReader>()
                .As <IFunctionIndexReader>()
                .As <IFunctionStatisticsReader>()
                .As <IFunctionInstanceLookup>()
                .As <IFunctionLookup>().SingleInstance();

                builder.RegisterType <NullHostVersionReader>().As <IHostVersionReader>().SingleInstance();

                // See services used by FunctionsController
                builder.RegisterType <NullInvocationIndexReader>().As <IRecentInvocationIndexByJobRunReader>().SingleInstance();
                builder.RegisterType <NullInvocationIndexReader>().As <IRecentInvocationIndexByParentReader>().SingleInstance();

                builder.RegisterType <NullHeartbeatValidityMonitor>().As <IHeartbeatValidityMonitor>().SingleInstance();
                builder.RegisterType <NullAborter>().As <IAborter>().SingleInstance();
                builder.RegisterType <NullInvoker>().As <IInvoker>().SingleInstance();

                // for diagnostics
                builder.RegisterType <NullIIndexerLogReader>().As <IIndexerLogReader>().SingleInstance();
                builder.RegisterType <NullLogReader>().As <IPersistentQueueReader <PersistentQueueMessage> >().SingleInstance();
                builder.RegisterType <NullIDashboardVersionManager>().As <IDashboardVersionManager>().SingleInstance();
            }
            else
            {
                builder.RegisterInstance(new NullFastReader()).As <ILogReader>();

                // Traditional SDK reader.

                CloudQueueClient queueClient = account.CreateCloudQueueClient();

                builder.RegisterInstance(queueClient).As <CloudQueueClient>();
                builder.RegisterType <HostVersionReader>().As <IHostVersionReader>().SingleInstance();
                builder.RegisterType <DashboardVersionManager>().As <IDashboardVersionManager>().SingleInstance();
                builder.RegisterType <FunctionInstanceLookup>().As <IFunctionInstanceLookup>().SingleInstance();
                builder.RegisterType <FunctionInstanceLogger>().As <IFunctionInstanceLogger>().SingleInstance();
                builder.RegisterType <HostIndexManager>().As <IHostIndexManager>().SingleInstance();
                builder.RegisterType <FunctionIndexVersionManager>().As <IFunctionIndexVersionManager>().SingleInstance();
                builder.RegisterType <FunctionIndexManager>().As <IFunctionIndexManager>().SingleInstance();
                builder.RegisterType <FunctionLookup>().As <IFunctionLookup>().SingleInstance();
                builder.RegisterType <FunctionIndexReader>().As <IFunctionIndexReader>().SingleInstance();
                builder.RegisterType <HeartbeatValidityMonitor>().As <IHeartbeatValidityMonitor>().SingleInstance();
                builder.RegisterType <HeartbeatMonitor>().As <IHeartbeatMonitor>().SingleInstance();
                builder.RegisterInstance(HttpRuntime.Cache).As <Cache>();
                builder.RegisterType <FunctionStatisticsReader>().As <IFunctionStatisticsReader>().SingleInstance();
                builder.RegisterType <FunctionStatisticsWriter>().As <IFunctionStatisticsWriter>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexReader>().As <IRecentInvocationIndexReader>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexWriter>().As <IRecentInvocationIndexWriter>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByFunctionReader>().As <IRecentInvocationIndexByFunctionReader>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByFunctionWriter>().As <IRecentInvocationIndexByFunctionWriter>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByJobRunReader>().As <IRecentInvocationIndexByJobRunReader>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByJobRunWriter>().As <IRecentInvocationIndexByJobRunWriter>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByParentReader>().As <IRecentInvocationIndexByParentReader>().SingleInstance();
                builder.RegisterType <RecentInvocationIndexByParentWriter>().As <IRecentInvocationIndexByParentWriter>().SingleInstance();
                builder.RegisterType <HostMessageSender>().As <IHostMessageSender>().SingleInstance();
                builder.RegisterType <PersistentQueueReader <PersistentQueueMessage> >().As <IPersistentQueueReader <PersistentQueueMessage> >().SingleInstance();
                builder.RegisterType <FunctionInstanceLogger>().As <IFunctionQueuedLogger>().SingleInstance();
                builder.RegisterType <HostIndexer>().As <IHostIndexer>().SingleInstance();
                builder.RegisterType <FunctionIndexer>().As <IFunctionIndexer>().SingleInstance();
                builder.RegisterType <UpgradeIndexer>().As <IIndexer>().SingleInstance();
                builder.RegisterType <Invoker>().As <IInvoker>().SingleInstance();
                builder.RegisterType <AbortRequestLogger>().As <IAbortRequestLogger>().SingleInstance();
                builder.RegisterType <Aborter>().As <IAborter>().SingleInstance();

                builder.RegisterType <IndexerBlobLogWriter>().As <IIndexerLogWriter>().SingleInstance();
                builder.RegisterType <IndexerBlobLogReader>().As <IIndexerLogReader>().SingleInstance();
            }
        }
Ejemplo n.º 6
0
        public override void Load()
        {
            DashboardAccountContext context = TryCreateAccount();

            Bind <DashboardAccountContext>().ToConstant(context);

            this.BindFilter <AccountContextAttribute>(FilterScope.Global, 0);

            CloudStorageAccount account = context.StorageAccount;

            if (account == null)
            {
                return;
            }

            CloudTableClient tableClient = account.CreateCloudTableClient();
            CloudBlobClient  blobClient  = account.CreateCloudBlobClient();

            Bind <CloudStorageAccount>().ToConstant(account);
            Bind <CloudBlobClient>().ToConstant(blobClient);

            CloudTable logTable = TryGetLogTable(tableClient);

            if (logTable != null)
            {
                context.DisableInvoke = true;

                // fast table reader.
                var reader = LogFactory.NewReader(logTable);
                Bind <ILogReader>().ToConstant(reader);

                var s = new FastTableReader(reader);

                Bind <IFunctionLookup>().ToConstant(s);
                Bind <IFunctionInstanceLookup>().ToConstant(s);
                Bind <IFunctionStatisticsReader>().ToConstant(s);
                Bind <IFunctionIndexReader>().ToConstant(s);
                Bind <IRecentInvocationIndexByFunctionReader>().ToConstant(s);
                Bind <IRecentInvocationIndexReader>().ToConstant(s);

                Bind <IHostVersionReader>().To <NullHostVersionReader>();

                // See services used by FunctionsController
                Bind <IRecentInvocationIndexByJobRunReader>().To <NullInvocationIndexReader>();
                Bind <IRecentInvocationIndexByParentReader>().To <NullInvocationIndexReader>();

                Bind <IHeartbeatValidityMonitor>().To <NullHeartbeatValidityMonitor>();

                Bind <IAborter>().To <NullAborter>();

                // for diagnostics
                Bind <IIndexerLogReader>().To <NullIIndexerLogReader>();
                Bind <IPersistentQueueReader <PersistentQueueMessage> >().To <NullLogReader>();
                Bind <IDashboardVersionManager>().To <NullIDashboardVersionManager>();
            }
            else
            {
                Bind <ILogReader>().ToConstant(new NullFastReader());

                // Traditional SDK reader.

                CloudQueueClient queueClient = account.CreateCloudQueueClient();

                Bind <CloudQueueClient>().ToConstant(queueClient);

                Bind <IHostVersionReader>().To <HostVersionReader>();
                Bind <IDashboardVersionManager>().To <DashboardVersionManager>();
                Bind <IFunctionInstanceLookup>().To <FunctionInstanceLookup>();
                Bind <IFunctionInstanceLogger>().To <FunctionInstanceLogger>();
                Bind <IHostIndexManager>().To <HostIndexManager>();
                Bind <IFunctionIndexVersionManager>().To <FunctionIndexVersionManager>();
                Bind <IFunctionIndexManager>().To <FunctionIndexManager>();
                Bind <IFunctionLookup>().To <FunctionLookup>();
                Bind <IFunctionIndexReader>().To <FunctionIndexReader>();
                Bind <IHeartbeatValidityMonitor>().To <HeartbeatValidityMonitor>();
                Bind <IHeartbeatMonitor>().To <HeartbeatMonitor>();
                Bind <Cache>().ToConstant(HttpRuntime.Cache);
                Bind <IFunctionStatisticsReader>().To <FunctionStatisticsReader>();
                Bind <IFunctionStatisticsWriter>().To <FunctionStatisticsWriter>();
                Bind <IRecentInvocationIndexReader>().To <RecentInvocationIndexReader>();
                Bind <IRecentInvocationIndexWriter>().To <RecentInvocationIndexWriter>();
                Bind <IRecentInvocationIndexByFunctionReader>().To <RecentInvocationIndexByFunctionReader>();
                Bind <IRecentInvocationIndexByFunctionWriter>().To <RecentInvocationIndexByFunctionWriter>();
                Bind <IRecentInvocationIndexByJobRunReader>().To <RecentInvocationIndexByJobRunReader>();
                Bind <IRecentInvocationIndexByJobRunWriter>().To <RecentInvocationIndexByJobRunWriter>();
                Bind <IRecentInvocationIndexByParentReader>().To <RecentInvocationIndexByParentReader>();
                Bind <IRecentInvocationIndexByParentWriter>().To <RecentInvocationIndexByParentWriter>();
                Bind <IHostMessageSender>().To <HostMessageSender>();
                Bind <IPersistentQueueReader <PersistentQueueMessage> >().To <PersistentQueueReader <PersistentQueueMessage> >();
                Bind <IFunctionQueuedLogger>().To <FunctionInstanceLogger>();
                Bind <IHostIndexer>().To <HostIndexer>();
                Bind <IFunctionIndexer>().To <FunctionIndexer>();
                Bind <IIndexer>().To <UpgradeIndexer>();
                Bind <IInvoker>().To <Invoker>();
                Bind <IAbortRequestLogger>().To <AbortRequestLogger>();
                Bind <IAborter>().To <Aborter>();

                Bind <IIndexerLogWriter>().To <IndexerBlobLogWriter>();
                Bind <IIndexerLogReader>().To <IndexerBlobLogReader>();
            }
        }