public static ApplicationContainer GetFromUuid(string containerUuid, Hourglass hourglass = null) { EtcUser etcUser = GetPasswdFor(containerUuid); string nameSpace = null; Dictionary <string, string> env = Environ.Load(Path.Combine(etcUser.Dir, ".env")); if (!string.IsNullOrEmpty(env["OPENSHIFT_GEAR_DNS"])) { nameSpace = Regex.Replace(Regex.Replace("testing-uhu.openshift.local", @"\..*$", ""), @"^.*\-", ""); } if (string.IsNullOrEmpty(env["OPENSHIFT_APP_UUID"])) { //Maybe we should improve the exceptions we throw. throw new Exception("OPENSHIFT_APP_UUID is missing!"); } if (string.IsNullOrEmpty(env["OPENSHIFT_APP_NAME"])) { throw new Exception("OPENSHIFT_APP_NAME is missing!"); } if (string.IsNullOrEmpty(env["OPENSHIFT_GEAR_NAME"])) { throw new Exception("OPENSHIFT_GEAR_NAME is missing!"); } ApplicationContainer applicationContainer = new ApplicationContainer(env["OPENSHIFT_APP_UUID"], containerUuid, etcUser, env["OPENSHIFT_APP_NAME"], env["OPENSHIFT_GEAR_NAME"], nameSpace, null, null, hourglass); return(applicationContainer); }
public string CartridgeAction(Manifest cartridge, string action, string softwareVersion, bool renderErbs = false) { string cartridgeHome = Path.Combine(this.container.ContainerDir, cartridge.Dir); action = Path.Combine(cartridgeHome, "bin", action + ".ps1"); if (!File.Exists(action)) { return(string.Empty); } Dictionary <string, string> gearEnv = Environ.ForGear(this.container.ContainerDir); string cartridgeEnvHome = Path.Combine(cartridgeHome, "env"); Dictionary <string, string> cartridgeEnv = Environ.Load(cartridgeEnvHome); cartridgeEnv.Remove("PATH"); foreach (var kvp in gearEnv) { cartridgeEnv[kvp.Key] = kvp.Value; } if (renderErbs) { // TODO: render erb } // TODO: vladi: implement hourglass string cmd = string.Format("{0} -ExecutionPolicy Bypass -InputFormat None -noninteractive -file {1} --version {2}", ProcessExtensions.Get64BitPowershell(), action, softwareVersion); string output = this.container.RunProcessInContainerContext(cartridgeHome, cmd, 0).StdOut; // TODO: vladi: add logging return(output); }
public static IEnumerable <ApplicationContainer> All(Hourglass hourglass = null, bool loadenv = true) { EtcUser[] users = new Etc(NodeConfig.Values).GetAllUsers(); foreach (EtcUser user in users) { if (user.Gecos.StartsWith("openshift_service")) { RubyHash env = new RubyHash(); string gearNamespace = null; if (loadenv) { env = new RubyHash(Environ.Load(new string[] { Path.Combine(user.Dir, ".env") })); } if (env.ContainsKey("OPENSHIFT_GEAR_DNS")) { gearNamespace = env["OPENSHIFT_GEAR_DNS"]; } ApplicationContainer app = null; try { app = new ApplicationContainer(env["OPENSHIFT_APP_UUID"], user.Name, user, env["OPENSHIFT_APP_NAME"], env["OPENSHIFT_GEAR_NAME"], gearNamespace, null, null, hourglass); } catch (Exception ex) { Logger.Error("Failed to instantiate ApplicationContainer for uid {0}/uuid {1}: {2}", user.Uid, env["OPENSHIFT_APP_UUID"], ex.Message); Logger.Error("Stacktrace: {0}", ex.StackTrace); continue; } yield return(app); } } }
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); }