Ejemplo n.º 1
0
        public Manifest GetCartridgeFromDirectory(string cartDir)
        {
            if (string.IsNullOrEmpty(cartDir))
            {
                throw new ArgumentNullException("Directory name is required");
            }

            if (!this.cartridges.ContainsKey(cartDir))
            {
                string cartPath     = Path.Combine(container.ContainerDir, cartDir);
                string manifestPath = Path.Combine(cartPath, "metadata", "manifest.yml");
                string identPath    = Directory.GetFiles(Path.Combine(cartPath, "env"), "OPENSHIFT_*_IDENT").FirstOrDefault();

                if (!File.Exists(manifestPath))
                {
                    throw new Exception(string.Format("Cartridge manifest not found: {0} missing", manifestPath));
                }

                if (identPath == null)
                {
                    throw new Exception(string.Format("Cartridge Ident not found in {0}", cartPath));
                }

                string   version   = Manifest.ParseIdent(File.ReadAllText(identPath))[2];
                Manifest cartridge = new Manifest(manifestPath, version, "file", this.container.ContainerDir);
                this.cartridges[cartDir] = cartridge;
            }
            return(this.cartridges[cartDir]);
        }
Ejemplo n.º 2
0
        private RubyHash ActivateLocalGear(dynamic options)
        {
            string deploymentId = options["deployment_id"];

            Logger.Debug("Activating local gear with deployment id {0}", deploymentId);

            RubyHash result = new RubyHash();

            result["status"]        = RESULT_FAILURE;
            result["gear_uuid"]     = this.Uuid;
            result["deployment_id"] = deploymentId;
            result["messages"]      = new List <string>();
            result["errors"]        = new List <string>();

            if (!DeploymentExists(deploymentId))
            {
                Logger.Warning("No deployment with id {0} found on gear", deploymentId);
                result["errors"].Add(string.Format("No deployment with id {0} found on gear", deploymentId));
                return(result);
            }

            try
            {
                string deploymentDateTime = GetDeploymentDateTimeForDeploymentId(deploymentId);
                string deploymentDir      = Path.Combine(this.ContainerDir, "app-deployments", deploymentDateTime);

                Dictionary <string, string> gearEnv = Environ.ForGear(this.ContainerDir);

                string output = string.Empty;

                Logger.Debug("Current deployment state for deployment {0} is {1}", deploymentId, this.State.Value());

                if (Runtime.State.STARTED.EqualsString(State.Value()))
                {
                    options["exclude_web_proxy"] = true;
                    output = StopGear(options);
                    result["messages"].Add(output);
                }

                SyncDeploymentRepoDirToRuntime(deploymentDateTime);
                SyncDeploymentDependenciesDirToRuntime(deploymentDateTime);
                SyncDeploymentBuildDependenciesDirToRuntime(deploymentDateTime);

                UpdateCurrentDeploymentDateTimeSymlink(deploymentDateTime);

                Manifest primaryCartridge = this.Cartridge.GetPrimaryCartridge();

                this.Cartridge.DoControl("update-configuration", primaryCartridge);

                result["messages"].Add("Starting application " + ApplicationName);

                Dictionary <string, object> opts = new Dictionary <string, object>();
                opts["secondary_only"] = true;
                opts["user_initiated"] = true;
                opts["hot_deploy"]     = options["hot_deploy"];

                output = StartGear(opts);
                result["messages"].Add(output);

                this.State.Value(Runtime.State.DEPLOYING);

                opts = new Dictionary <string, object>();
                opts["pre_action_hooks_enabled"] = false;
                opts["prefix_action_hooks"]      = false;
                output = this.Cartridge.DoControl("deploy", primaryCartridge, opts);
                result["messages"].Add(output);

                opts = new Dictionary <string, object>();
                opts["primary_only"]   = true;
                opts["user_initiated"] = true;
                opts["hot_deploy"]     = options["hot_deploy"];
                output = StartGear(opts);
                result["messages"].Add(output);

                opts = new Dictionary <string, object>();
                opts["pre_action_hooks_enabled"] = false;
                opts["prefix_action_hooks"]      = false;
                output = this.Cartridge.DoControl("post-deploy", primaryCartridge, opts);
                result["messages"].Add(output);

                if (options.ContainsKey("post_install"))
                {
                    string primaryCartEnvDir = Path.Combine(this.ContainerDir, primaryCartridge.Dir, "env");
                    Dictionary <string, string> primaryCartEnv = Environ.Load(primaryCartEnvDir);
                    string ident = (from kvp in primaryCartEnv
                                    where Regex.Match(kvp.Key, "^OPENSHIFT_.*_IDENT").Success
                                    select kvp.Value).FirstOrDefault();
                    string version = Manifest.ParseIdent(ident)[2];
                    this.Cartridge.PostInstall(primaryCartridge, version);
                }

                DeploymentMetadata deploymentMetadata = DeploymentMetadataFor(deploymentDateTime);
                deploymentMetadata.RecordActivation();
                deploymentMetadata.Save();

                if (options.ContainsKey("report_deployments") && gearEnv["OPENSHIFT_APP_DNS"] == gearEnv["OPENSHIFT_GEAR_DNS"])
                {
                    ReportDeployments(gearEnv);
                }

                result["status"] = RESULT_SUCCESS;
            }
            catch (Exception e)
            {
                result["status"] = RESULT_FAILURE;
                result["errors"].Add(string.Format("Error activating gear: {0}", e.ToString()));
            }

            return(result);
        }