Esempio n. 1
0
        private VostokMultiHostApplicationSettings UpdateAppSettings(VostokMultiHostApplicationSettings applicationSettings)
        {
            return(new VostokMultiHostApplicationSettings(
                       applicationSettings.Application,
                       applicationSettings.Identifier,
                       builder =>
            {
                settings.EnvironmentSetup(builder);

                builder.SetupLog(
                    logBuilder =>
                {
                    logBuilder.CustomizeLog(
                        logCustomization => logCustomization.ForContext($"{applicationSettings.Identifier.ApplicationName}-{applicationSettings.Identifier.InstanceName}"));
                });

                builder.SetupApplicationIdentity(
                    identityBuilder =>
                {
                    identityBuilder
                    .SetApplication(applicationSettings.Identifier.ApplicationName)
                    .SetInstance(applicationSettings.Identifier.InstanceName);
                });

                applicationSettings.EnvironmentSetup(builder);

                builder.SetupClusterConfigClient(clientBuilder => clientBuilder.UseInstance(commonEnvironment.ClusterConfigClient));

                builder.SetupHerculesSink(sinkBuilder => sinkBuilder.UseInstance(commonEnvironment.HerculesSink));

                if (commonEnvironment.HostExtensions.TryGet <IZooKeeperClient>(out var zooKeeperClient))
                {
                    builder.SetupZooKeeperClient(clientBuilder => clientBuilder.UseInstance(zooKeeperClient));
                }
            }
Esempio n. 2
0
        /// <summary>
        /// <para>Adds an application and returns created application.</para>
        /// </summary>
        public IVostokMultiHostApplication AddApplication(VostokMultiHostApplicationSettings applicationSettings)
        {
            if (initiateShutdown.Task.IsCompleted)
            {
                throw new InvalidOperationException($"Unable to add application {applicationSettings.Identifier} because VostokMultiHost is shutting down.");
            }

            if (applications.ContainsKey(applicationSettings.Identifier))
            {
                throw new ArgumentException($"{applicationSettings.Identifier} has already been added.");
            }

            var updatedSettings = UpdateAppSettings(applicationSettings);

            return(applications[applicationSettings.Identifier] =
                       new VostokMultiHostApplication(
                           updatedSettings,
                           () => commonEnvironment != null && !initiateShutdown.Task.IsCompleted));
        }
 /// <summary>
 /// Adds an application and returns <see cref="IVostokMultiHostApplication.StartAsync"/> task.
 /// May throw an exception if application with this identifier has already been added.
 /// <see cref="VostokMultiHost"/> should be running to perform this operation.
 /// </summary>
 public static Task StartApplicationAsync(this VostokMultiHost host, VostokMultiHostApplicationSettings settings)
 {
     return(host.AddApplication(settings).StartAsync());
 }
 /// <summary>
 /// Adds an application and returns <see cref="IVostokMultiHostApplication.RunAsync"/> task.
 /// May throw an exception if application with this identifier has already been added.
 /// <see cref="VostokMultiHost"/> should be running to perform this operation.
 /// </summary>
 public static Task <VostokApplicationRunResult> RunApplicationAsync(this VostokMultiHost host, VostokMultiHostApplicationSettings settings)
 {
     return(host.AddApplication(settings).RunAsync());
 }