Ejemplo n.º 1
0
        public Host(IStaticApplicationInfo applicationInfo, FunctionsHostConfiguration configuration, ILogger logger, uint processId, Stopwatch stopwatch, Guid invocationId)
        {
            this.processId       = processId;
            this.stopwatch       = stopwatch;
            this.applicationInfo = applicationInfo;
            this.configuration   = configuration;
            this.hostName        = Environment.MachineName;
            bool cloud = string.IsNullOrEmpty(Environment.GetEnvironmentVariable("REACTIVE_MACHINE_DIR"));

            CombinedLogger    = new CombinedLogger(logger, configuration, processId, cloud);
            HostLogger        = new LoggerWrapper(CombinedLogger, $"[p{processId:d3} host] ", configuration.HostLogLevel);
            ApplicationLogger = new LoggerWrapper(CombinedLogger, $"[p{processId:d3} application] ", configuration.ApplicationLogLevel);
            RuntimeLogger     = new LoggerWrapper(CombinedLogger, $"[p{processId:d3} runtime] ", configuration.RuntimeLogLevel);

            this.application = Compilation.Compile <TStaticApplicationInfo>(applicationInfo, configuration);

            this.invocationId              = invocationId;
            this.payloadSerializer         = new DataContractSerializer(typeof(List <KeyValuePair <long, IMessage> >), application.SerializableTypes);
            this.payloadSerializerLoopback = new DataContractSerializer(typeof(List <IMessage>), application.SerializableTypes);
            this.Connections = new EventHubsConnections(processId, HostLogger, configuration.ehConnectionString);

            if (application.TryGetConfiguration <ReactiveMachine.TelemetryBlobWriter.Configuration>(out var config))
            {
                this.collectHostEvents     = config.CollectHostEvents;
                this.blobTelemetryListener = new TelemetryCollector(config, application, processId, this.GetType());
            }
        }
Ejemplo n.º 2
0
 public BatchSender(uint destination, EventHubsConnections connections, ILogger logger,
                    DataContractSerializer payloadSerializer, FunctionsHostConfiguration configuration, PartitionSender sender)
 {
     this.destination       = destination;
     this.connections       = connections;
     this.payloadSerializer = payloadSerializer;
     this.configuration     = configuration;
     this.logger            = new LoggerWrapper(logger, $" [sender{destination:d3}] ");
     this.sender            = sender;
 }
Ejemplo n.º 3
0
        public CombinedLogger(ILogger logger, FunctionsHostConfiguration config, uint processId, bool cloud)
        {
            this.logger = logger;
            this.config = config;

            if (!cloud && config.LocalDevelopmentFileLogLevel != LogLevel.None)
            {
                try {
                    streamWriter = new StreamWriter(Path.Combine(config.LocalDevelopmentLogDirectory, $"p{processId:d3}-{DateTime.UtcNow:yyyy-MM-dd--hh-mm-ss}.log"));
                }
                catch (Exception e)
                {
                    logger.LogWarning($"could not create log file in {config.LocalDevelopmentLogDirectory}, caught {e}");
                }
            }
        }
Ejemplo n.º 4
0
 private Client(ILogger logger)
 {
     this.random             = new Random();
     this.applicationInfo    = new TStaticApplicationInfo();
     this.configuration      = applicationInfo.GetHostConfiguration();
     this.logger             = new LoggerWrapper(logger, $"[client] ", configuration.HostLogLevel);
     this.application        = Compilation.Compile <TStaticApplicationInfo>(applicationInfo, configuration);
     this.processId          = (uint)random.Next((int)application.NumberProcesses); // we connect to a randomly selected process
     this.responsePartition  = (uint)random.Next(ResponseSender.NumberPartitions);  // we receive on a randomly selected partition
     this.connections        = new EventHubsConnections(processId, logger, configuration.EventHubsConnectionString);
     this.requestSender      = new RequestSender(processId, connections, logger, new DataContractSerializer(typeof(List <IMessage>), application.SerializableTypes), configuration);
     this.responseSenders    = new Dictionary <uint, ResponseSender>();
     this.continuations      = new ConcurrentDictionary <Guid, object>();
     this.serializer         = new Serializer(application.SerializableTypes);
     this.responseSerializer = new DataContractSerializer(typeof(List <IResponseMessage>), application.SerializableTypes);
     var ignoredTask = ListenForResponses();
 }
Ejemplo n.º 5
0
        private static async Task RunHost(IStaticApplicationInfo applicationInfo, FunctionsHostConfiguration configuration, uint processId,
                                          ILogger hostlogger, ILogger logger, LeaseManager leaseManager, System.Diagnostics.Stopwatch stopwatch, Guid invocationId)
        {
            try
            {
                var host = new Host <TStaticApplicationInfo>(applicationInfo, configuration, logger, processId, stopwatch, invocationId);

                var done = await host.ResumeFromCheckpoint(leaseManager);

                // if we get here, there is no more work for this process
                await leaseManager.Release();

                hostlogger.LogInformation($"Lease released");

                if (!done)
                {
                    await host.RingMyself();
                }
                else
                {
                    await host.FinalRecheck();
                }

                await host.Cleanup(false);
            }
            catch (Exception e)
            {
                hostlogger.LogError($"RunHost Failed: {e}");

                // throw exception, so event hub delivers doorbell message again
                // TODO think about poison messages
                throw;
            }
            finally
            {
                hostlogger.LogDebug($"Control returned");
            }
        }
Ejemplo n.º 6
0
        internal static ICompiledApplication Compile <TApplicationInfo>(IStaticApplicationInfo info, FunctionsHostConfiguration configuration)
            where TApplicationInfo : IStaticApplicationInfo, new()
        {
            var compiler = new ReactiveMachine.ApplicationCompiler();

            compiler
            .SetConfiguration(configuration)
            .AddBuildStep(serviceBuilder =>
            {
                var m = typeof(Compilation).GetMethod(nameof(Compilation.DefineForResultType));
                foreach (var t in info.GetResultTypes())
                {
                    var mg = m.MakeGenericMethod(typeof(TApplicationInfo), t);
                    mg.Invoke(null, new object[] { serviceBuilder });
                }
            })
            ;
            return(info.Build(compiler));
        }
Ejemplo n.º 7
0
 public LoopbackSender(uint processId, EventHubsConnections connections,
                       ILogger logger, DataContractSerializer payloadSerializer, FunctionsHostConfiguration configuration, DateTime deploymentTimestamp)
     : base(processId, connections, logger, payloadSerializer, configuration,
            connections.GetProcessSender(processId))
 {
     this.deploymentTimestamp = deploymentTimestamp;
 }
Ejemplo n.º 8
0
 public RequestSender(uint processId, EventHubsConnections connections,
                      ILogger logger, DataContractSerializer payloadSerializer, FunctionsHostConfiguration configuration)
     : base(processId, connections, logger, payloadSerializer, configuration,
            connections.GetProcessSender(processId))
 {
     this.processId = processId;
     doorbell       = connections.GetDoorbellSender(processId);
 }
Ejemplo n.º 9
0
 public RemoteSender(uint processId, uint destination, EventHubsConnections connections,
                     ILogger logger, DataContractSerializer payloadSerializer, FunctionsHostConfiguration configuration, DateTime deploymentTimestamp)
     : base(destination, connections, logger, payloadSerializer, configuration,
            connections.GetProcessSender(destination))
 {
     this.processId           = processId;
     this.deploymentTimestamp = deploymentTimestamp;
     doorbell = connections.GetDoorbellSender(destination);
 }
Ejemplo n.º 10
0
        public static ICompiledApplication Compile <TStaticApplicationInfo>(TStaticApplicationInfo info, FunctionsHostConfiguration configuration)
            where TStaticApplicationInfo : IStaticApplicationInfo, new()
        {
            var compiler = new Compiler <TStaticApplicationInfo>();

            compiler.SetConfiguration(configuration);
            return(info.Build(compiler));
        }
Ejemplo n.º 11
0
 public ResponseSender(uint processId, uint partitionId, EventHubsConnections connections,
                       ILogger logger, DataContractSerializer payloadSerializer, FunctionsHostConfiguration configuration)
     : base(processId, connections, logger, payloadSerializer, configuration,
            connections.GetResponseSender(partitionId))
 {
 }