Exemplo n.º 1
0
        public List <RubyHash> WithGearRotation(RubyHash options, GearRotationCallback action)
        {
            dynamic       localGearEnv = Environ.ForGear(this.ContainerDir);
            Manifest      proxyCart    = this.Cartridge.WebProxy();
            List <object> gears        = new List <object>();

            // TODO: vladi: verify if this is needed for scalable apps
            //if (options.ContainsKey("all") && proxyCart != null)
            //{
            //    if ((bool)options["all"])
            //    {
            //        gears = this.GearRegist.Entries["web"].Keys.ToList<object>();
            //    }
            //    else if (options.ContainsKey("gears"))
            //    {
            //        List<string> g = (List<string>)options["gears"];
            //        gears = this.GearRegist.Entries["web"].Keys.Where(e => g.Contains(e)).ToList<object>();
            //    }
            //    else
            //    {
            //        try
            //        {
            //            gears.Add(this.GearRegist.Entries["web"][this.Uuid]);
            //        }
            //        catch
            //        {
            //            gears.Add(this.Uuid);
            //        }
            //    }
            //}
            //else
            {
                gears.Add(this.Uuid);
            }

            double parallelConcurrentRatio = PARALLEL_CONCURRENCY_RATIO;

            if (options.ContainsKey("parallel_concurrency_ratio"))
            {
                parallelConcurrentRatio = (double)options["parallel_concurrency_ratio"];
            }

            int batchSize = CalculateBatchSize(gears.Count, parallelConcurrentRatio);

            int threads = Math.Max(batchSize, MAX_THREADS);

            List <RubyHash> result = new List <RubyHash>();

            // need to parallelize
            foreach (var targetGear in gears)
            {
                result.Add(RotateAndYield(targetGear, localGearEnv, options, action));
            }

            return(result);
        }
Exemplo n.º 2
0
        public void TestFacterOK()
        {
            // Arrange

            // Act
            RubyHash facts = Uhuru.Openshift.Runtime.Utils.Facter.GetFacterFacts();

            // Assert
            Assert.IsTrue(facts.ContainsKey("operatingsystem"));
            Assert.AreEqual(facts["operatingsystem"], "windows");
        }
Exemplo n.º 3
0
        public string Deploy(RubyHash options)
        {
            StringBuilder output = new StringBuilder();

            if (!options.ContainsKey("artifact_url"))
            {
                output.AppendLine(PreReceive(options));
                PostReceive(options);
            }
            else
            {
                output.AppendLine(DeployBinaryArtifact(options));
            }
            return(output.ToString());
        }
Exemplo n.º 4
0
        public void Test_FacterOpenshift()
        {
            RubyHash facts = Uhuru.Openshift.Runtime.Utils.Facter.GetOpenshiftFacts();

            Assert.IsTrue(facts.ContainsKey("node_profile"));
        }
Exemplo n.º 5
0
        public RubyHash UpdateRemoteProxyStatus(RubyHash args)
        {
            RubyHash result      = new RubyHash();
            string   currentGear = args["current_gear"];

            GearRegistry.Entry proxyGear  = args["proxy_gear"];
            object             targetGear = args["target_gear"];
            Manifest           cartridge  = args["cartridge"];
            string             action     = args["action"];
            bool   persist = args["persist"] != null && args["persist"] == true;
            object gearEnv = args["gear_env"];

            if (currentGear == proxyGear.Uuid)
            {
                // self, no need to ssh
                return(this.UpdateLocalProxyStatus(new RubyHash()
                {
                    { "cartridge", cartridge },
                    { "action", action },
                    { "target_gear", targetGear },
                    { "persist", persist }
                }));
            }

            string direction     = action == "enable" ? "in" : "out";
            string persistOption = persist ? "--persist" : "";

            string url = string.Format("{0}@{1}", proxyGear.Uuid, proxyGear.ProxyHostname);

            string ooSSH      = @"/cygpath/c/openshift/oo-bin/oo-ssh";
            string bashBinary = Path.Combine(NodeConfig.Values["SSHD_BASE_DIR"], "bin\bash.exe");

            string sshCommand = string.Format("{0} {1} gear rotate-{2} --gear {3} {4} --cart {5}-{6} --as-json",
                                              ooSSH, url, direction, targetGear, persistOption, cartridge.Name, cartridge.Version);

            string bashArgs = string.Format("--norc --login -c '{0}'", sshCommand);

            string command = string.Format("{0} {1}", bashBinary, bashArgs);

            try
            {
                ProcessResult processResult = this.RunProcessInContainerContext(this.ContainerDir, command, 0);

                if (string.IsNullOrEmpty(processResult.StdOut))
                {
                    throw new Exception("No result JSON was received from the remote proxy update call");
                }

                result = JsonConvert.DeserializeObject <RubyHash>(processResult.StdOut);

                if (!result.ContainsKey("status"))
                {
                    throw new Exception(string.Format("Invalid result JSON received from remote proxy update call: {0}", processResult.StdOut));
                }
            }
            catch (Exception ex)
            {
                result = new RubyHash()
                {
                    { "status", RESULT_FAILURE },
                    { "proxy_gear_uuid", proxyGear.Uuid },
                    { "messages", new List <string>() },
                    { "errors", new List <string> {
                          string.Format("An exception occured updating the proxy status: {0}\n{1}", ex.Message, ex.StackTrace)
                      } }
                };
            }

            return(result);
        }
        public RubyHash UpdateRemoteProxyStatus(RubyHash args)
        {
            RubyHash result = new RubyHash();
            string currentGear = args["current_gear"];
            GearRegistry.Entry proxyGear = args["proxy_gear"];
            object targetGear = args["target_gear"];
            Manifest cartridge = args["cartridge"];
            string action = args["action"];
            bool persist = args["persist"] != null && args["persist"] == true;
            object gearEnv = args["gear_env"];

            if (currentGear == proxyGear.Uuid)
            {
                // self, no need to ssh
                return this.UpdateLocalProxyStatus(new RubyHash()
                {
                    { "cartridge", cartridge }, 
                    { "action", action }, 
                    { "target_gear", targetGear }, 
                    { "persist", persist }
                });
            }

            string direction = action == "enable" ? "in" : "out";
            string persistOption = persist ? "--persist" : "";

            string url = string.Format("{0}@{1}", proxyGear.Uuid, proxyGear.ProxyHostname);

            string ooSSH = @"/cygpath/c/openshift/oo-bin/oo-ssh";
            string bashBinary = Path.Combine(NodeConfig.Values["SSHD_BASE_DIR"], "bin\bash.exe");

            string sshCommand = string.Format("{0} {1} gear rotate-{2} --gear {3} {4} --cart {5}-{6} --as-json", 
                ooSSH, url, direction, targetGear, persistOption, cartridge.Name, cartridge.Version);

            string bashArgs = string.Format("--norc --login -c '{0}'", sshCommand);

            string command = string.Format("{0} {1}", bashBinary, bashArgs);

            try
            {
                ProcessResult processResult = this.RunProcessInContainerContext(this.ContainerDir, command, 0);

                if (string.IsNullOrEmpty(processResult.StdOut))
                {
                    throw new Exception("No result JSON was received from the remote proxy update call");
                }

                result = JsonConvert.DeserializeObject<RubyHash>(processResult.StdOut);

                if (!result.ContainsKey("status"))
                {
                    throw new Exception(string.Format("Invalid result JSON received from remote proxy update call: {0}", processResult.StdOut));
                }
            }
            catch (Exception ex)
            {
                result = new RubyHash()
                {
                    { "status", RESULT_FAILURE },
                    { "proxy_gear_uuid", proxyGear.Uuid },
                    { "messages", new List<string>() },
                    { "errors", new List<string> { string.Format("An exception occured updating the proxy status: {0}\n{1}", ex.Message, ex.StackTrace) } }
                };
            }

            return result;
        }
        public List<RubyHash> WithGearRotation(RubyHash options, GearRotationCallback action)
        {
            dynamic localGearEnv = Environ.ForGear(this.ContainerDir);
            Manifest proxyCart = this.Cartridge.WebProxy();
            List<object> gears = new List<object>();

            // TODO: vladi: verify if this is needed for scalable apps
            //if (options.ContainsKey("all") && proxyCart != null)
            //{
            //    if ((bool)options["all"])
            //    {
            //        gears = this.GearRegist.Entries["web"].Keys.ToList<object>();
            //    }
            //    else if (options.ContainsKey("gears"))
            //    {
            //        List<string> g = (List<string>)options["gears"];
            //        gears = this.GearRegist.Entries["web"].Keys.Where(e => g.Contains(e)).ToList<object>();
            //    }
            //    else
            //    {
            //        try
            //        {
            //            gears.Add(this.GearRegist.Entries["web"][this.Uuid]);
            //        }
            //        catch
            //        {
            //            gears.Add(this.Uuid);
            //        }
            //    }
            //}
            //else
            {
                gears.Add(this.Uuid);
            }

            double parallelConcurrentRatio = PARALLEL_CONCURRENCY_RATIO;
            if (options.ContainsKey("parallel_concurrency_ratio"))
            {
                parallelConcurrentRatio = (double)options["parallel_concurrency_ratio"];
            }

            int batchSize = CalculateBatchSize(gears.Count, parallelConcurrentRatio);

            int threads = Math.Max(batchSize, MAX_THREADS);

            List<RubyHash> result = new List<RubyHash>();

            // need to parallelize
            foreach (var targetGear in gears)
            {
                result.Add(RotateAndYield(targetGear, localGearEnv, options, action));
            }

            return result;
        }
Exemplo n.º 8
0
        private string Build(RubyHash options)
        {
            this.State.Value(Runtime.State.BUILDING);
            string             deploymentDateTime = options["deployment_datetime"] != null ? options["deployment_datetime"] : LatestDeploymentDateTime();
            DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDateTime);

            if (!options.ContainsKey("deployment_datetime"))
            {
                // this will execute if coming from a CI builder, since it doesn't
                // specify :deployment_datetime in the options hash
                throw new NotImplementedException();
            }

            StringBuilder buffer = new StringBuilder();

            if (deploymentMetadata.ForceCleanBuild)
            {
                buffer.AppendLine("Force clean build enabled - cleaning dependencies");

                CleanRuntimeDirs(new RubyHash()
                {
                    { "dependencies", true }, { "build_dependencies", true }
                });

                this.Cartridge.EachCartridge(delegate(Manifest cartridge) {
                    this.Cartridge.CreateDependencyDirectories(cartridge);
                });
            }

            buffer.AppendLine(string.Format("Building git ref {0}, commit {1}", deploymentMetadata.GitRef, deploymentMetadata.GitSha));

            Dictionary <string, string> env = Environ.ForGear(this.ContainerDir);
            int deploymentsToKeep           = DeploymentsToKeep(env);

            try
            {
                Manifest primaryCartridge = this.Cartridge.GetPrimaryCartridge();
                buffer.AppendLine(this.Cartridge.DoControl("update-configuration", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
                buffer.AppendLine(this.Cartridge.DoControl("pre-build", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
                buffer.AppendLine(this.Cartridge.DoControl("build", primaryCartridge, new RubyHash()
                {
                    { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false }
                }));
            }
            catch (Exception ex)
            {
                buffer.AppendLine("Encountered a failure during build: " + ex.ToString());
                if (deploymentsToKeep > 1)
                {
                    buffer.AppendLine("Restarting application");
                    buffer.AppendLine(StartGear(new RubyHash()
                    {
                        { "user_initiated", true }, { "hot_deploy", deploymentMetadata.HotDeploy }
                    }));
                }
                throw ex;
            }

            return(buffer.ToString());
        }
Exemplo n.º 9
0
 public string Deploy(RubyHash options)
 {
     StringBuilder output = new StringBuilder();
     if (!options.ContainsKey("artifact_url"))
     {
         output.AppendLine(PreReceive(options));
         PostReceive(options);
     }
     else
     {
         output.AppendLine(DeployBinaryArtifact(options));
     }
     return output.ToString();
 }
Exemplo n.º 10
0
        public string Build(RubyHash options)
        {
            this.State.Value(Runtime.State.BUILDING);
            string deploymentDateTime = options["deployment_datetime"] != null ? options["deployment_datetime"] : LatestDeploymentDateTime();
            DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDateTime);

            if (!options.ContainsKey("deployment_datetime"))
            {
                // this will execute if coming from a CI builder, since it doesn't
                // specify :deployment_datetime in the options hash
                ApplicationRepository applicationRepository = options["git_repo"];
                string gitRef = options["ref"];
                string gitSha1 = applicationRepository.GetSha1(gitRef);
                deploymentMetadata.GitSha = gitSha1;
                deploymentMetadata.GitRef = gitRef;
                deploymentMetadata.HotDeploy = options["hot_deploy"];
                deploymentMetadata.ForceCleanBuild = options["force_clean_build"];
                deploymentMetadata.Save();
            }

            StringBuilder buffer = new StringBuilder();

            if(deploymentMetadata.ForceCleanBuild)
            {
                buffer.AppendLine("Force clean build enabled - cleaning dependencies");

                CleanRuntimeDirs(new RubyHash() { { "dependencies", true }, { "build_dependencies", true } });

                this.Cartridge.EachCartridge(delegate(Manifest cartridge) {
                    this.Cartridge.CreateDependencyDirectories(cartridge);
                });
            }

            buffer.AppendLine(string.Format("Building git ref {0}, commit {1}", deploymentMetadata.GitRef, deploymentMetadata.GitSha));

            Dictionary<string, string> env = Environ.ForGear(this.ContainerDir);
            int deploymentsToKeep = DeploymentsToKeep(env);

            try
            {
                Manifest primaryCartridge = this.Cartridge.GetPrimaryCartridge();
                buffer.AppendLine(this.Cartridge.DoControl("update-configuration", primaryCartridge, new RubyHash() { { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false } }));
                buffer.AppendLine(this.Cartridge.DoControl("pre-build", primaryCartridge, new RubyHash() { { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false } }));
                buffer.AppendLine(this.Cartridge.DoControl("build", primaryCartridge, new RubyHash() { { "pre_action_hooks_enabled", false }, { "post_action_hooks_enabled", false } }));
            }
            catch(Exception ex)
            {
                buffer.AppendLine("Encountered a failure during build: " + ex.ToString());
                if(deploymentsToKeep > 1)
                {
                    buffer.AppendLine("Restarting application");
                    buffer.AppendLine(StartGear(new RubyHash() { { "user_initiated", true }, { "hot_deploy", deploymentMetadata.HotDeploy } }));
                }
                throw ex;
            }

            return buffer.ToString();
        }