コード例 #1
0
        public void GetFunctionMetadata()
        {
            var mockFunctionIndexProvider = new Mock <IFunctionIndexProvider>();

            var functionDescriptor = new FunctionDescriptor()
            {
                IsDisabled = true
            };
            var mockFunctionIndex = new Mock <IFunctionIndex>();

            mockFunctionIndex.Setup(i => i.LookupByName("testMethod")).Returns(new FunctionDefinition(functionDescriptor, null, null));
            var token = new CancellationToken();

            mockFunctionIndexProvider.Setup(p => p.GetAsync(token)).Returns(Task.FromResult(mockFunctionIndex.Object));

            Func <IFunctionIndexProvider> getter = (() =>
            {
                return(mockFunctionIndexProvider.Object);
            });

            IJobHostMetadataProvider provider = new JobHostMetadataProvider(mockFunctionIndexProvider.Object, null, null, null);

            var functionMetadata = provider.GetFunctionMetadata("testNotExists");

            Assert.Equal(functionMetadata, null);

            functionMetadata = provider.GetFunctionMetadata("testMethod");
            Assert.Equal(functionMetadata.IsDisabled, true);
        }
コード例 #2
0
        public override void Initialize(AnalysisContext context)
        {
            VerifyWebJobsLoaded();

            // Analyze method signatures,
            context.RegisterSyntaxNodeAction(AnalyzeMethodDeclarationNode, SyntaxKind.MethodDeclaration);

            // Hook compilation to get the assemblies references and build the WebJob tooling interfaces.
            context.RegisterCompilationStartAction(compilationAnalysisContext =>
            {
                var compilation = compilationAnalysisContext.Compilation;

                AssemblyCache.Instance.Build(compilation);
                this._tooling = AssemblyCache.Instance.Tooling;

                // cast to PortableExecutableReference which has a file path
                var x1          = compilation.References.OfType <PortableExecutableReference>().ToArray();
                var webJobsPath = (from reference in x1
                                   where IsWebJobsSdk(reference)
                                   select reference.FilePath).SingleOrDefault();

                if (webJobsPath == null)
                {
                    return; // Not a WebJobs project.
                }
            });
        }
コード例 #3
0
        // $$$ This can get invoked multiple times concurrently
        // This will get called on every compilation.
        // So return early on subseuqnet initializations.
        internal void Build(Compilation compilation)
        {
            Register();

            int count;

            lock (this)
            {
                // If project references have changed, then reanalyze to pick up new dependencies.
                var refs = compilation.References.OfType <PortableExecutableReference>().ToArray();
                count = refs.Length;
                if ((count == _projectCount) && (_tooling != null))
                {
                    return; // already initialized.
                }

                // Even for netStandard/.core projects, this will still be a flattened list of the full transitive closure of dependencies.
                foreach (var asm in compilation.References.OfType <PortableExecutableReference>())
                {
                    var dispName = asm.Display; // For .net core, the displayname can be the full path
                    var path     = asm.FilePath;

                    _map[dispName] = path;
                }

                // Builtins
                _mapRef["mscorlib"]              = typeof(object).Assembly;
                _mapRef[WebJobsAssemblyName]     = typeof(Microsoft.Azure.WebJobs.BlobAttribute).Assembly;
                _mapRef[WebJobsHostAssemblyName] = typeof(Microsoft.Azure.WebJobs.JobHost).Assembly;

                // JSON.Net?
            }

            // Produce tooling object
            var hostConfig = Initialize();
            var jh2        = new JobHost(hostConfig);
            var tooling    = (JobHostMetadataProvider)jh2.Services.GetService(typeof(IJobHostMetadataProvider));

            lock (this)
            {
                this._projectCount = count;
                this._tooling      = tooling;
            }
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using the
        /// specified connection string for both reading and writing data as well as Dashboard logging.
        /// </summary>
        /// <param name="dashboardAndStorageConnectionString">The Azure Storage connection string to use.
        /// </param>
        public JobHostConfiguration(string dashboardAndStorageConnectionString)
        {
            if (!string.IsNullOrEmpty(dashboardAndStorageConnectionString))
            {
                _storageAccountProvider = new DefaultStorageAccountProvider(this, dashboardAndStorageConnectionString);
            }
            else
            {
                _storageAccountProvider = new DefaultStorageAccountProvider(this);
            }

            Singleton  = new SingletonConfiguration();
            Aggregator = new FunctionResultAggregatorConfiguration();

            // add our built in services here
            _tooling = new JobHostMetadataProvider(this);
            IExtensionRegistry       extensions       = new DefaultExtensionRegistry(_tooling);
            ITypeLocator             typeLocator      = new DefaultTypeLocator(ConsoleProvider.Out, extensions);
            IConverterManager        converterManager = new ConverterManager();
            IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler();

            AddService <IQueueConfiguration>(_queueConfiguration);
            AddService <IConsoleProvider>(ConsoleProvider);
            AddService <IStorageAccountProvider>(_storageAccountProvider);
            AddService <IExtensionRegistry>(extensions);
            AddService <StorageClientFactory>(new StorageClientFactory());
            AddService <INameResolver>(new DefaultNameResolver());
            AddService <IJobActivator>(DefaultJobActivator.Instance);
            AddService <ITypeLocator>(typeLocator);
            AddService <IConverterManager>(converterManager);
            AddService <IWebJobsExceptionHandler>(exceptionHandler);
            AddService <IFunctionResultAggregatorFactory>(new FunctionResultAggregatorFactory());

            string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(Host.Constants.EnvironmentSettingName);

            IsDevelopment = string.Compare(Host.Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0;
        }
コード例 #5
0
        // Static initialization. Returns a service provider with some new services initialized.
        // The new services:
        // - can retrieve static config like binders and converters; but the listeners haven't yet started.
        // - can be flowed into the runtime initialization to get a JobHost spun up and running.
        // This is just static initialization and should not need to make any network calls,
        // and so this method should not need to be async.
        // This can be called multiple times on a config, which is why it returns a new ServiceProviderWrapper
        // instead of modifying the config.
        public static ServiceProviderWrapper CreateStaticServices(this JobHostConfiguration config)
        {
            var services = new ServiceProviderWrapper(config);

            var consoleProvider = services.GetService <IConsoleProvider>();
            var nameResolver    = services.GetService <INameResolver>();
            IWebJobsExceptionHandler exceptionHandler   = services.GetService <IWebJobsExceptionHandler>();
            IQueueConfiguration      queueConfiguration = services.GetService <IQueueConfiguration>();
            var blobsConfiguration = config.Blobs;

            IStorageAccountProvider storageAccountProvider = services.GetService <IStorageAccountProvider>();
            IBindingProvider        bindingProvider        = services.GetService <IBindingProvider>();
            SingletonManager        singletonManager       = services.GetService <SingletonManager>();

            IHostIdProvider hostIdProvider = services.GetService <IHostIdProvider>();
            var             hostId         = config.HostId;

            if (hostId != null)
            {
                hostIdProvider = new FixedHostIdProvider(hostId);
            }

            // Need a deferred getter since the IFunctionIndexProvider service isn't created until later.
            Func <IFunctionIndexProvider> deferredGetter = () => services.GetService <IFunctionIndexProvider>();

            if (hostIdProvider == null)
            {
                hostIdProvider = new DynamicHostIdProvider(storageAccountProvider, deferredGetter);
            }
            services.AddService <IHostIdProvider>(hostIdProvider);

            AzureStorageDeploymentValidator.Validate();

            IExtensionTypeLocator extensionTypeLocator = services.GetService <IExtensionTypeLocator>();

            if (extensionTypeLocator == null)
            {
                extensionTypeLocator = new ExtensionTypeLocator(services.GetService <ITypeLocator>());
                services.AddService <IExtensionTypeLocator>(extensionTypeLocator);
            }

            ContextAccessor <IMessageEnqueuedWatcher> messageEnqueuedWatcherAccessor = new ContextAccessor <IMessageEnqueuedWatcher>();

            services.AddService(messageEnqueuedWatcherAccessor);
            ContextAccessor <IBlobWrittenWatcher> blobWrittenWatcherAccessor = new ContextAccessor <IBlobWrittenWatcher>();
            ISharedContextProvider sharedContextProvider = new SharedContextProvider();

            // Create a wrapper TraceWriter that delegates to both the user
            // TraceWriters specified via config (if present), as well as to Console
            TraceWriter trace = new ConsoleTraceWriter(config.Tracing, consoleProvider.Out);

            services.AddService <TraceWriter>(trace);

            // Add built-in extensions
            var metadataProvider = new JobHostMetadataProvider(deferredGetter);

            metadataProvider.AddAttributesFromAssembly(typeof(TableAttribute).Assembly);

            var  exts          = config.GetExtensions();
            bool builtinsAdded = exts.GetExtensions <IExtensionConfigProvider>().OfType <TableExtension>().Any();

            if (!builtinsAdded)
            {
                config.AddExtension(new TableExtension());
                config.AddExtension(new QueueExtension());
            }

            ExtensionConfigContext context = new ExtensionConfigContext
            {
                Config          = config,
                Trace           = trace,
                PerHostServices = services
            };

            InvokeExtensionConfigProviders(context);

            // After this point, all user configuration has been set.

            if (singletonManager == null)
            {
                var logger = config.LoggerFactory?.CreateLogger(LogCategories.Singleton);

                IDistributedLockManager lockManager = services.GetService <IDistributedLockManager>();
                if (lockManager == null)
                {
                    lockManager = new BlobLeaseDistributedLockManager(
                        storageAccountProvider,
                        trace,
                        logger);
                    services.AddService <IDistributedLockManager>(lockManager);
                }

                singletonManager = new SingletonManager(
                    lockManager,
                    config.Singleton,
                    trace,
                    exceptionHandler,
                    config.LoggerFactory,
                    hostIdProvider,
                    services.GetService <INameResolver>());
                services.AddService <SingletonManager>(singletonManager);
            }

            IExtensionRegistry      extensions             = services.GetExtensions();
            ITriggerBindingProvider triggerBindingProvider = DefaultTriggerBindingProvider.Create(nameResolver,
                                                                                                  storageAccountProvider, extensionTypeLocator, hostIdProvider, queueConfiguration, blobsConfiguration, exceptionHandler,
                                                                                                  messageEnqueuedWatcherAccessor, blobWrittenWatcherAccessor, sharedContextProvider, extensions, singletonManager, trace, config.LoggerFactory);

            services.AddService <ITriggerBindingProvider>(triggerBindingProvider);

            if (bindingProvider == null)
            {
                bindingProvider = DefaultBindingProvider.Create(nameResolver, config.LoggerFactory, storageAccountProvider, extensionTypeLocator, blobWrittenWatcherAccessor, extensions);
                services.AddService <IBindingProvider>(bindingProvider);
            }

            var converterManager = (ConverterManager)config.ConverterManager;

            metadataProvider.Initialize(bindingProvider, converterManager, exts);
            services.AddService <IJobHostMetadataProvider>(metadataProvider);

            return(services);
        }
コード例 #6
0
        internal void DebugDumpGraph(TextWriter output)
        {
            var binding = CreateBinding() as IBindingRuleProvider;

            JobHostMetadataProvider.DumpRule(binding, output);
        }
コード例 #7
0
 public DiagnosticHelper(JobHostMetadataProvider provider)
 {
     _provider = provider;
 }