Ejemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="hive">The hive being managed.</param>
 /// <param name="logFolder">
 /// The folder where log files are to be written, otherwise or <c>null</c> or
 /// empty if logging is disabled.
 /// </param>
 public XenServerHostingManager(HiveProxy hive, string logFolder = null)
 {
     this.hive = hive;
     this.hive.HostingManager = this;
     this.logFolder           = logFolder;
     this.maxVmNameWidth      = hive.Definition.Nodes.Max(n => n.Name.Length) + hive.Definition.Hosting.GetVmNamePrefix(hive.Definition).Length;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        internal HiveMQManager(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            this.hive     = hive;
            this.Internal = new InternalManager(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        internal DockerManager(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            this.hive   = hive;
            this.Config = new DockerConfigManager(hive);
            this.Secret = new DockerSecretManager(hive);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override void Run(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            var node = hive.GetNode(nodeName);

            node.SudoCommand("docker-volume-rm", volumeName);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        /// <param name="name">The traffic manager name (<b>public</b> or <b>private</b>).</param>
        /// <param name="useBootstrap">
        /// Optionally specifies that the instance should use the HiveMQ client
        /// to directly reference to the HiveMQ cluster nodes for broadcasting
        /// proxy update messages rather than routing traffic through the <b>private</b>
        /// traffic manager.  This is used internally to resolve chicken-and-the-egg
        /// dilemmas for the traffic manager and proxy implementations that rely on
        /// HiveMQ messaging.
        /// </param>
        internal TrafficManager(HiveProxy hive, string name, bool useBootstrap = false)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);
            Covenant.Requires <ArgumentException>(name == "public" || name == "private");

            this.hive         = hive;
            this.Name         = name;
            this.useBootstrap = useBootstrap;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the <see cref="HostingManager"/> for a specific environment.
        /// </summary>
        /// <param name="hive">The hive being managed.</param>
        /// <param name="logFolder">
        /// The folder where log files are to be written, otherwise or <c>null</c> or
        /// empty if logging is disabled.
        /// </param>
        /// <returns>
        /// The <see cref="HostingManager"/> or <c>null</c> if no hosting manager
        /// could be located for the specified hive environment.
        /// </returns>
        public HostingManager GetManager(HiveProxy hive, string logFolder = null)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);
            Covenant.Assert(environmentToHostingManager != null, $"[{nameof(HostingLoader)}] is not initialized.  You must call [{nameof(HostingLoader)}.{nameof(HostingLoader.Initialize)}()] first.");

            if (!environmentToHostingManager.TryGetValue(hive.Definition.Hosting.Environment, out var managerType))
            {
                return(null);
            }

            return((HostingManager)Activator.CreateInstance(managerType, hive, logFolder));
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        public override void Run(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            var node = hive.GetNode(nodeName);

            if (operationName != null)
            {
                node.InvokeIdempotentAction(operationName, () => action(node));
            }
            else
            {
                action(node);
            }
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        public override void Run(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            foreach (var node in hive.Nodes)
            {
                node.Status = $"pause {delay}";
            }

            Thread.Sleep(delay);

            foreach (var node in hive.Nodes)
            {
                node.Status = string.Empty;
            }
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public void Validate(HiveDefinition hiveDefinition)
        {
            CheckInitialized();

            Covenant.Requires <ArgumentNullException>(hiveDefinition != null);

            var hive    = new HiveProxy(hiveDefinition);
            var manager = GetManager(hive);

            if (manager == null)
            {
                throw new HiveException($"Cannot locate a [{nameof(IHostingManager)}] implementation for the [{hiveDefinition.Hosting.Environment}] hosting environment.");
            }

            manager.Validate(hiveDefinition);
        }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public override void Run(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            var node   = hive.GetNode(nodeName);
            var status = this.ToString();

            node.UploadText(path, text, tabStop, outputEncoding);

            if (!string.IsNullOrEmpty(permissions))
            {
                node.SudoCommand("chmod", permissions, path);
            }

            StatusPause();

            node.Status = string.Empty;
        }
Ejemplo n.º 11
0
        //---------------------------------------------------------------------
        // Static members

        /// <summary>
        /// Returns the summary from a hive proxy.
        /// </summary>
        /// <param name="hive">The target hive proxy.</param>
        /// <param name="definition">Optionally overrides the hive definition passed within <paramref name="hive"/>.</param>
        /// <returns>The <see cref="HiveSummary"/>.</returns>
        public static HiveSummary FromHive(HiveProxy hive, HiveDefinition definition = null)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            var summary = new HiveSummary();

            // Load the hive globals.

            var globals   = hive.Consul.Client.KV.DictionaryOrEmpty(HiveConst.GlobalKey).Result;
            var internals = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase)
            {
                // We don't include these internal globals in the summary.

                HiveGlobals.DefinitionDeflate,
                HiveGlobals.DefinitionHash,
                HiveGlobals.PetsDefinition
            };

            foreach (var item in globals.Where(i => !internals.Contains(i.Key)))
            {
                summary.Globals.Add(item.Key, Encoding.UTF8.GetString(item.Value));
            }

            // Summarize information from the hive definition.

            summary.NodeCount          = definition.Nodes.Count();
            summary.ManagerCount       = definition.Managers.Count();
            summary.WorkerCount        = definition.Workers.Count();
            summary.PetCount           = definition.Pets.Count();
            summary.OperatingSystem    = definition.HiveNode.OperatingSystem;
            summary.HostingEnvironment = definition.Hosting.Environment;
            summary.HiveFSEnabled      = definition.HiveFS.Enabled;
            summary.LogEnabled         = definition.Log.Enabled;
            summary.VpnEnabled         = definition.Vpn.Enabled;

            return(summary);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Called internally by <see cref="HiveHelper.OpenHiveRemote(DebugSecrets, DebugConfigs, string, bool)"/>
        /// to create any requested Vault and Consul credentials and add them to the dictionary.
        /// </summary>
        /// <param name="hive">The attached hive.</param>
        /// <param name="hiveLogin">The hive login.</param>
        internal void Realize(HiveProxy hive, HiveLogin hiveLogin)
        {
            this.hiveLogin = hiveLogin;

            HiveCredentials credentials;

            foreach (var request in credentialRequests)
            {
                switch (request.Type)
                {
                case CredentialType.VaultToken:

                    // Serialize the credentials as JSON and persist.

                    credentials = HiveCredentials.FromVaultToken(request.Token);

                    Add(request.SecretName, NeonHelper.JsonSerialize(credentials, Formatting.Indented));
                    break;

                case CredentialType.VaultAppRole:

                    // Serialize the credentials as JSON and persist.

                    credentials = VaultClient.GetAppRoleCredentialsAsync(request.RoleName).Result;

                    Add(request.SecretName, NeonHelper.JsonSerialize(credentials, Formatting.Indented));
                    break;

                case CredentialType.ConsulToken:

                    // $todo(jeff.lill): Implement this.

                    break;
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        internal RegistryManager(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            this.hive = hive;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        internal DockerConfigManager(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            this.hive = hive;
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Implements the configuration step.
 /// </summary>
 /// <param name="hive">The hive proxy instance.</param>
 public abstract void Run(HiveProxy hive);
Ejemplo n.º 16
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        /// <param name="hive">The parent <see cref="HiveProxy"/>.</param>
        internal CertificateManager(HiveProxy hive)
        {
            Covenant.Requires <ArgumentNullException>(hive != null);

            this.hive = hive;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="hive">The hive being managed.</param>
        /// <param name="logFolder">
        /// The folder where log files are to be written, otherwise or <c>null</c> or
        /// empty if logging is disabled.
        /// </param>
        public HyperVDevHostingManager(HiveProxy hive, string logFolder = null)
        {
            hive.HostingManager = this;

            this.hive = hive;
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Called internally by <see cref="HiveHelper.OpenHiveRemote(DebugSecrets, DebugConfigs, string, bool)"/>
 /// to create any requested configs and add them to the dictionary.
 /// </summary>
 /// <param name="hive">The attached hive.</param>
 /// <param name="hiveLogin">The hive login.</param>
 internal void Realize(HiveProxy hive, HiveLogin hiveLogin)
 {
     // This is a NOP because we already added all of the configs
     // to the base dictionary in the [Add()] methods.
 }
Ejemplo n.º 19
0
        /// <inheritdoc/>
        public HostingManager GetManager(HiveProxy hive, string logFolder = null)
        {
            CheckInitialized();

            return(Loader.GetManager(hive, logFolder));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="hive">The hive being managed.</param>
        /// <param name="logFolder">
        /// The folder where log files are to be written, otherwise or <c>null</c> or
        /// empty if logging is disabled.
        /// </param>
        public GoogleHostingManager(HiveProxy hive, string logFolder = null)
        {
            hive.HostingManager = this;

            this.hive = hive;
        }