Exemplo n.º 1
0
        /// <summary>
        /// Setups the runtimes.
        /// </summary>
        public void SetupRuntimes()
        {
            if (this.Runtimes == null || this.Runtimes.Count == 0)
            {
                Logger.Fatal(Strings.CannotDetermineApplicationRuntimes);
                throw new InvalidOperationException(Strings.CannotDetermineApplicationRuntimes);
            }

            Logger.Info(Strings.Checkingruntimes);

            foreach (KeyValuePair <string, DeaRuntime> kvp in this.Runtimes)
            {
                string     name    = kvp.Key;
                DeaRuntime runtime = kvp.Value;

                // Only enable when we succeed
                runtime.Enabled = false;

                // Check that we can get a version from the executable
                string version_flag = string.IsNullOrEmpty(runtime.VersionArgument) ? "-v" : runtime.VersionArgument;

                string expanded_exec = DEAUtilities.RunCommandAndGetOutputAndErrors("where", runtime.Executable).Trim();

                expanded_exec = expanded_exec.Split(new string[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)[0];

                if (!File.Exists(expanded_exec))
                {
                    Logger.Info(Strings.FailedExecutableNot, name, runtime.Executable, Directory.GetCurrentDirectory(), expanded_exec);
                    continue;
                }

                // java prints to stderr, so munch them both..
                string version_check = DEAUtilities.RunCommandAndGetOutputAndErrors(
                    expanded_exec,
                    string.Format(CultureInfo.InvariantCulture, "{0} {1}", expanded_exec, version_flag)).Trim();

                runtime.Executable = expanded_exec;

                if (string.IsNullOrEmpty(runtime.Version))
                {
                    continue;
                }

                // Check the version for a match
                if (new Regex(runtime.Version).IsMatch(version_check))
                {
                    // Additional checks should return true
                    if (!string.IsNullOrEmpty(runtime.AdditionalChecks))
                    {
                        string additional_check = DEAUtilities.RunCommandAndGetOutputAndErrors(
                            runtime.Executable,
                            string.Format(CultureInfo.InvariantCulture, "{0}", runtime.AdditionalChecks));
                        if (!new Regex("true").IsMatch(additional_check))
                        {
                            Logger.Info(Strings.FailedAdditionalChecks, name);
                        }
                    }

                    runtime.Enabled = true;
                    Logger.Info(Strings.RuntimeOk, name);
                }
                else
                {
                    Logger.Info(Strings.FailedVersionMismatch, name, version_check);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Agent"/> class. Loads the configuration and initializes the members.
        /// </summary>
        public Agent()
        {
            foreach (Configuration.DEA.RuntimeElement deaConf in UhuruSection.GetSection().DEA.Runtimes)
            {
                DeaRuntime dea = new DeaRuntime();

                dea.Executable = deaConf.Executable;
                dea.Version = deaConf.Version;
                dea.VersionArgument = deaConf.VersionArgument;
                dea.AdditionalChecks = deaConf.AdditionalChecks;
                dea.Enabled = true;

                foreach (Configuration.DEA.EnvironmentElement ienv in deaConf.Environment)
                {
                    dea.Environment.Add(ienv.Name, ienv.Value);
                }

                foreach (Configuration.DEA.DebugElement debugEnv in deaConf.Debug)
                {
                    dea.DebugEnvironmentVariables.Add(debugEnv.Name, new Dictionary<string, string>());
                    foreach (Configuration.DEA.EnvironmentElement ienv in debugEnv.Environment)
                    {
                        dea.DebugEnvironmentVariables[debugEnv.Name].Add(ienv.Name, ienv.Value);
                    }
                }

                this.stager.Runtimes.Add(deaConf.Name, dea);
            }

            string baseDir = UhuruSection.GetSection().DEA.BaseDir;
            this.stager.DropletDir = new DirectoryInfo(baseDir).FullName;

            this.stager.DisableDirCleanup = UhuruSection.GetSection().DEA.DisableDirCleanup;
            this.multiTenant = UhuruSection.GetSection().DEA.Multitenant;
            this.secure = UhuruSection.GetSection().DEA.Secure;
            this.enforceUlimit = UhuruSection.GetSection().DEA.EnforceUsageLimit;

            this.monitoring.MaxMemoryMbytes = UhuruSection.GetSection().DEA.MaxMemory;

            this.fileViewer.Port = UhuruSection.GetSection().DEA.FilerPort;

            // Replace the ephemeral monitoring port with the configured one
            if (UhuruSection.GetSection().DEA.StatusPort > 0)
            {
                this.Port = UhuruSection.GetSection().DEA.StatusPort;
            }

            this.stager.ForceHttpFileSharing = UhuruSection.GetSection().DEA.ForceHttpSharing;

            this.ComponentType = "DEA";

            // apps_dump_dir = ConfigurationManager.AppSettings["logFile"] ?? Path.GetTempPath();
            this.monitoring.AppsDumpDirectory = Path.GetTempPath();

            // heartbeat_interval = UhuruSection.GetSection().DEA.HeartBeatInterval;
            this.monitoring.MaxClients = this.multiTenant ? Monitoring.DefaultMaxClients : 1;

            this.stager.StagedDir = Path.Combine(this.stager.DropletDir, "staged");
            this.stager.AppsDir = Path.Combine(this.stager.DropletDir, "apps");
            this.stager.DBDir = Path.Combine(this.stager.DropletDir, "db");

            this.droplets.AppStateFile = Path.Combine(this.stager.DropletDir, "applications.json");

            this.deaReactor.UUID = UUID;

            this.helloMessage.Id = this.UUID;
            this.helloMessage.Host = this.Host;
            this.helloMessage.FileViewerPort = this.fileViewer.Port;
            this.helloMessage.Version = Version;
        }