示例#1
0
        static async Task Main(string[] args)
        {
            using (var client = new HttpClient())
            {
                var healthClient = new HealthClient(client);

                var pingResult = await healthClient.PingAsync();
            }
        }
        public string Check(string id = "")
        {
            var channel = new Channel(Program.GrpcHost, Program.GrpcPort, ChannelCredentials.Insecure);

            channel.ConnectAsync();

            var healthClient = new HealthClient(channel);
            var request      = new HealthCheckRequest();

            request.Service = id;

            var responseText = string.Empty;

            try
            {
                var result = healthClient.Check(request);

                switch (result.Status)
                {
                case ServingStatus.NotServing:
                    Response.StatusCode = 503;
                    break;

                case ServingStatus.Unknown:
                    Response.StatusCode = 503;
                    break;

                case ServingStatus.Serving:
                    Response.StatusCode = 200;     //just to be clear
                    break;
                }

                responseText = result.Status.ToString();
            }
            catch (RpcException ex)
            {
                responseText        = ex.Status.StatusCode.ToString();
                Response.StatusCode = 404;
            }

            return(responseText
                   //adding http status code for POC
                   + " |  HttpStatusCode: " + Response.StatusCode);
        }
示例#3
0
        internal DCASettings(string applicationInstanceId, IDcaSettingsConfigReader dcaSettingsConfigReader)
        {
            this.applicationInstanceId = applicationInstanceId;
            this.configReader          = dcaSettingsConfigReader;

            Action <string> onError = error =>
            {
                // Trace immediately and aggregate for health.
                Utility.TraceSource.WriteError(TraceType, error);
                this.errors.Add(error);
            };

            this.producerInstances = new ReadOnlyDictionary <string, ProducerInstanceInfo>(this.GetProducers(onError));
            this.consumerInstances = new ReadOnlyDictionary <string, ConsumerInstanceInfo>(this.GetConsumers(onError));

            var pluginsEnabledBitFlags = this.producerInstances
                                         .Where(pair => StandardPluginTypes.PluginTypeMap.ContainsKey(pair.Value.TypeName))
                                         .Aggregate(StandardPluginTypes.PluginType.None, (agg, pair) => agg | StandardPluginTypes.PluginTypeMap[pair.Value.TypeName]);

            pluginsEnabledBitFlags = this.consumerInstances
                                     .Where(pair => StandardPluginTypes.PluginTypeMap.ContainsKey(pair.Value.TypeName))
                                     .Aggregate(pluginsEnabledBitFlags, (agg, pair) => agg | StandardPluginTypes.PluginTypeMap[pair.Value.TypeName]);

            if (Utility.IsSystemApplicationInstanceId(this.applicationInstanceId))
            {
                FabricEvents.Events.PluginConfigurationTelemetry((long)pluginsEnabledBitFlags);

                if (this.errors.Any())
                {
                    HealthClient.SendNodeHealthReport(string.Join("\n", this.errors), HealthState.Error, HealthSubProperty);
                }
                else
                {
                    HealthClient.ClearNodeHealthReport(HealthSubProperty);
                }
            }
            else
            {
                // ApplicationInstanceId will contain user app names, so we should hash value.
                var derivedApplicationInstanceId = string.Format("App{0}", this.applicationInstanceId.GetHashCode());
                FabricEvents.Events.AppPluginConfigurationTelemetry(derivedApplicationInstanceId, (long)pluginsEnabledBitFlags);
            }
        }
示例#4
0
        //public static ILogger Logger = new ConsoleLogger();

        public static void Main(string[] args)
        {
            var channel            = new Channel($"{Host}:{Port}", ChannelCredentials.Insecure);
            var interceptedChannel = channel.Intercept(new LogInterceptor());
            var client             = new Greeter.GreeterClient(interceptedChannel);

            Console.WriteLine($"Client connecting to server at {Host}:{Port}");

            var healthClient = new HealthClient(channel);
            var reply3       = healthClient.Check(new Grpc.Health.V1.HealthCheckRequest()
            {
                Service = "helloworld.Greeter"
            });

            var user    = "******";
            var request = new HelloRequest {
                Name = user
            };


            var reply = client.SayHello(request);
            // SayHelloAgain throws an error. reply2 will be null
            var reply2 = client.SayHelloAgain(request);

            Console.WriteLine("Press any key to continue after exception...");
            Console.ReadKey();

            // demonstrate that the server is still up when SayHelloAgain executed
            var reply4 = client.SayHello(request);

            Console.WriteLine("Press any key to shutdown channel...");
            Console.ReadKey();

            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
        public IBusService Create(IServiceBus bus)
        {
            var service = new HealthClient(_intervalInSeconds);

            return(service);
        }
		public IBusService Create(IServiceBus bus)
		{
			var service = new HealthClient(_intervalInSeconds);

			return service;
		}
        public IBusService Create(IServiceBus bus, IObjectBuilder builder)
        {
            var service = new HealthClient(_intervalInSeconds);

            return(service);
        }
示例#8
0
        public static int Main(string[] args)
        {
            Utility.TraceSource = null;

#if !DotNetCoreClr
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#endif

#if !DotNetCoreClrLinux && !DotNetCoreClrIOT
            // Register an unhandled exception event handler
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler.OnUnhandledException;
#endif

            // Initialize config store
            ConfigUpdateHandler configUpdateHandler = new ConfigUpdateHandler();
            Utility.InitializeConfigStore(configUpdateHandler);

            // Initialize the Fabric node Id
            Utility.InitializeFabricNodeInfo();

            // Read FabricHost's exit failure reset time from settings
            UnhandledExceptionHandler.ReadFabricHostExitFailureResetTime();

            // Set up tracing
            Utility.InitializeTracing();
            Utility.TraceSource = new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA);

            Utility.DcaProgramDirectory = Path.Combine(Path.GetDirectoryName(FabricEnvironment.GetCodePath()), "DCA.Code");

            // Initialize the work directory
            Utility.InitializeWorkDirectory();

            // Create the event that indicates when the main thread should
            // stop the DCA
            stopDCAEvent = new ManualResetEvent(false);
            UnhandledExceptionHandler.StopDcaEvent = stopDCAEvent;

            // Create the event that indicates that the main thread has
            // stopped the DCA.
            dcaHasStoppedEvent = new ManualResetEvent(false);

            // Register to be notified when we need to stop.
            Console.CancelKeyPress += CtrlCHandler;

            // The configuration update handler makes use of some members that we just
            // initialized above, e.g. the trace source and the event used to indicate
            // that the DCA should stop.
            //
            // Until we initialize these members, it is not safe for the the configuration
            // update handler to process any updates because it would end up trying to
            // access those uninitialized members. Therefore the configuration update
            // handler ignores these updates until this point. This is okay, because we
            // haven't attempted to read configurations until now. When we read the
            // configurations later, we will be reading the updated values anyway, so
            // ignoring the update notifications is not a problem.
            //
            // Now that we have initialized all the members needed by the configuration
            // update handler, we tell it to start processing configuration updates.
            configUpdateHandler.StartProcessingConfigUpdates();

            // Create and initialize the application instance manager object.
            AppInstanceManager appInstanceMgr = new AppInstanceManager();

            // Notify the application instance manager about the availability of the
            // Windows Fabric application.
            appInstanceMgr.CreateApplicationInstance(Utility.WindowsFabricApplicationInstanceId, null);

            // Let the config update handler know that the Windows Fabric
            // Application has been created, so that it can send configuration
            // updates if it needs to.
            configUpdateHandler.StartConfigUpdateDeliveryToAppInstanceMgr(appInstanceMgr);

            // Create and initialize the service package table manager object
            ServicePackageTableManager servicePackageTableManager = new ServicePackageTableManager(appInstanceMgr);

            // Create and initialize the container manager object if required.
            ContainerManager     containerManager     = null;
            ContainerEnvironment containerEnvironment = null;

            // FabricContainerAppsEnabled is set to true by default
            bool enableContainerManager = Utility.GetUnencryptedConfigValue <bool>(
                ConfigReader.HostingSectionName,
                ConfigReader.FabricContainerAppsEnabledParameterName,
                true);

            if (enableContainerManager)
            {
                containerEnvironment = new ContainerEnvironment();
                containerManager     = new ContainerManager(appInstanceMgr, containerEnvironment);
            }

            // DCA is running again.
            HealthClient.ClearNodeHealthReport();

            // Wait for the event that is signaled when the DCA needs to be
            // stopped.
            stopDCAEvent.WaitOne();

            // Stop the DCA's periodic activities
            Utility.TraceSource.WriteInfo(
                TraceType,
                "Stopping the DCA ...");

            servicePackageTableManager.Dispose();
            configUpdateHandler.Dispose();
            appInstanceMgr.Dispose();

            Utility.TraceSource.WriteInfo(
                TraceType,
                "DCA has stopped.");

            // Set event to indicate that the main thread has stopped the DCA
            bool result = dcaHasStoppedEvent.Set();
            System.Fabric.Interop.Utility.ReleaseAssert(
                result,
                StringResources.DCAError_SignalEventToStopFailed);

            return(0);
        }
		public IBusService Create(IServiceBus bus, IObjectBuilder builder)
		{
			var service = new HealthClient(_intervalInSeconds);

			return service;
		}
示例#10
0
        internal FabricDCA(string applicationInstanceId, DiskSpaceManager diskSpaceManager)
        {
            this.registeredAppConfigSections     = new HashSet <string>();
            this.registeredServiceConfigSections = new HashSet <string>();

            // Retrieve DCA settings
            this.settings = new DCASettings(applicationInstanceId);

            // Get the names of sections in settings.xml that contain DCA-related
            // configuration information
            this.registeredAppConfigSections.UnionWith(GetConfigurationSections(this.settings));

            // Dictionary that represents the mapping of producers and consumers
            // Key is the producer instance and value is the list of consumer instances
            // that are interested in receiving data from that producer instance.
            var producerConsumerMap = new Dictionary <string, List <object> >();

            var errorEvents = new List <string>();

            this.consumers = CreateConsumers(
                new ConsumerFactory(),
                producerConsumerMap,
                this.settings,
                diskSpaceManager,
                applicationInstanceId,
                errorEvents);

            // Create the Telemetry consumer and maps it to a etlfileproducer if it exists
            if (applicationInstanceId == Utility.WindowsFabricApplicationInstanceId)
            {
                CreateTelemetryConsumer(
                    this.consumers,
                    producerConsumerMap,
                    this.settings,
                    applicationInstanceId);
            }

            // Create the producers
            this.producers = CreateProducers(
                new ProducerFactory(diskSpaceManager),
                producerConsumerMap,
                this.settings,
                applicationInstanceId,
                errorEvents);

            // Send all errors found in initialization of plugins as single report.
            if (Utility.IsSystemApplicationInstanceId(applicationInstanceId))
            {
                if (errorEvents.Any())
                {
                    var message = string.Join(Environment.NewLine, errorEvents);
                    HealthClient.SendNodeHealthReport(message, HealthState.Error);
                }
                else
                {
                    HealthClient.ClearNodeHealthReport();
                }
            }

            // Get additional configuration sections that the producers are
            // interested in
            this.registeredAppConfigSections.UnionWith(GetAdditionalProducerAppSections(this.producers));
            this.RegisteredServiceConfigSections.UnionWith(GetAdditionalProducerServiceSections(this.producers));
        }