public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();

            ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
             WithContainerName, WithNamespace, null, null, null);
            try
            {
                List<string> gears = null;
                List<string> keys = WithKeys.Split(' ').ToList();
                if (!string.IsNullOrEmpty(WithGears))
                {
                    gears = new List<string>();
                    JArray gearsObj = (JArray)JsonConvert.DeserializeObject(WithGears);
                    foreach (var gearObj in gearsObj)
                    {
                        gears.Add(gearObj.ToString());
                    }
                }

                status.Output = container.UserVarRemove(keys, gears);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-user-var-remove command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }

            return status;
        }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();

            ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                WithContainerName, WithNamespace, null, null, null, WithUid);
            try
            {
                string output = string.Empty;
                string[] keys = null;
                if (!string.IsNullOrEmpty(WithKeys))
                {
                    keys = WithKeys.Split(' ');
                }

                Dictionary<string, string> variables = container.UserVarList(keys);

                status.Output = string.Format("{0}CLIENT_RESULT: {1}{0}", Environment.NewLine, JsonConvert.SerializeObject(variables));
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-user-var-list command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName, WithContainerName,
             WithNamespace, null, null, null);
         List<SshKey> keys = new List<SshKey>();
         if (!string.IsNullOrWhiteSpace(WithSshKeys))
         {
             JArray varsArray = (JArray)JsonConvert.DeserializeObject(WithSshKeys);
             keys = varsArray.ToObject<List<SshKey>>();
         }
         container.ReplaceSshKeys(keys);
         status.ExitCode = 0;
         status.Output = string.Empty;
     }
     catch(Exception ex)
     {
         Logger.Error("Error running oo-authorized-ssh-keys-replace command: {0} - {1}", ex.Message, ex.StackTrace);
         status.ExitCode = 1;
         status.Output = ex.Message;
     }
     return status;
 }
Example #4
0
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                WithContainerName, WithNamespace, null, null, null, WithUid);
                RubyHash options = new RubyHash();
                options["all"] = All;
                if (ParallelConcurrencyRatio != 0.0)
                {
                    options["parallelConcurrencyRatio"] = ParallelConcurrencyRatio;
                }

                status.Output = container.Restart(CartName, options);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-restart command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;

            }
            return status;
        }        
 public CartridgeModel(ApplicationContainer container, ApplicationState state, Hourglass hourglass)
 {
     this.container = container;
     this.state = state;
     this.hourglass = hourglass;
     this.timeout = 30;
     this.cartridges = new Dictionary<string, Manifest>();
 }
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {               
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                 WithContainerName, WithNamespace, null, null, null);
         status.Output = string.Format("{0}CLIENT_RESULT: {1}{0}", Environment.NewLine, container.State.Value().ToLower());
         status.ExitCode = 0;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-app-state-show command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = 1;
     }
     return status;
 }
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName, WithContainerName,
            WithNamespace, null, null, new Hourglass(235));
         status.Output = container.PostConfigure(CartName, WithTemplateGitUrl);
         status.ExitCode = 0;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-post-configure command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = 1;
     }
     return status;
 }
Example #8
0
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
         WithContainerName, WithNamespace, null, null, null, WithUid);            
         status.Output = container.Reload(CartName);
         status.ExitCode = 0;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-reload command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = 1;
     }
     return status;
 }        
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName, WithContainerName,
             WithNamespace, null, null, null);
         status.Output = container.AddSshKey(WithSshKey, WithSshKeyType, WithSshKeyComment);
         status.ExitCode = 0;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-authorized-ssh-key-add command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = 1;
     }
     return status;
 }
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
             WithContainerName, WithNamespace, null, null, null);
         container.RemoveEnvVar(WithKey);
         status.Output = string.Empty;
         status.ExitCode = 0;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-env-var-remove command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = -1;
     }
     return status;
 }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                   WithContainerName, WithNamespace, null, null, null);

                status.Output = container.AddBrokerAuth(WithIv, WithToken);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-broker-auth-key-add command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
Example #12
0
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName, WithContainerName,
                                WithNamespace, null, null, null, WithUid);

                status.Output = container.Configure(CartName, WithTemplateGitUrl, WithCartridgeManifest, bool.Parse(WithExposePorts));
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-configure command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                    WithContainerName, WithNamespace, null, null, null);

                status.Output = container.ForceStop();
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-force-stop command: {0} - {1}", ex.Message, ex.StackTrace);
                status.ExitCode = 1;
                status.Output = ex.Message;
            }
            return status;
        }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName, WithContainerName,
                    WithNamespace, null, null, null);

                status.Output = container.ConnectorExecute(CartName, HookName, PublishingCartName, ConnectionType, InputArgs);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-connector-execute command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
Example #15
0
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();
            try
            {
            ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                                WithContainerName, WithNamespace, null, null, null, WithUid);

                RubyHash options = new RubyHash();
                options["deployment_id"] = WithDeploymentId;
                status.Output = container.Activate(options);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-activate command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
 public static ApplicationContainer CreateAppContainer()
 {
     string applicationUuid = Guid.NewGuid().ToString("N");
     string containerUuid = applicationUuid;
     NodeConfig config = new NodeConfig();
     // EtcUser etcUser = new Etc(config).GetPwanam(containerUuid);
     string userId = WindowsIdentity.GetCurrent().Name;
     string applicationName = "testApp";
     string containerName = applicationName;
     string namespaceName = "uhuru";
     object quotaBlocks = null;
     object quotaFiles = null;
     Hourglass hourglass = null;
     Node.LimitsFile = resourceLimitsFile;
     ApplicationContainer container = new ApplicationContainer(
         applicationUuid, containerUuid, null,
         applicationName, containerName, namespaceName,
         quotaBlocks, quotaFiles, hourglass);
     
     return container;
 }
 public ReturnStatus Execute()
 {
     ReturnStatus status = new ReturnStatus();
     try
     {
         ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
             WithContainerName, WithNamespace, null, null, null);
         container.SetAutoDeploy(AutoDeploy);
         container.SetDeploymentBranch(DeploymentBranch);
         container.SetKeepDeployments(KeepDeployments);
         container.SetDeploymentType(DeploymentType);
         status.ExitCode = 0;
         status.Output = string.Empty;
     }
     catch (Exception ex)
     {
         Logger.Error("Error running oo-update-configuration command: {0} - {1}", ex.Message, ex.StackTrace);
         status.Output = ex.ToString();
         status.ExitCode = 1;
     }
     return status;
 }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();

            try
            {
                string token = null;
                if (!string.IsNullOrEmpty(WithSecretToken))
                    token = WithSecretToken;
                ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
                    WithContainerName, WithNamespace, null, null, null);
                status.Output = container.Create(token);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-app-create command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
        public ReturnStatus Execute()
        {
            ReturnStatus status = new ReturnStatus();

            ApplicationContainer container = new ApplicationContainer(WithAppUuid, WithContainerUuid, null, WithAppName,
               WithContainerName, WithNamespace, null, null, null);

            try
            {
                Dictionary<string, string> variables = new Dictionary<string, string>();

                if (!string.IsNullOrWhiteSpace(WithVariables))
                {
                    foreach (string variable in WithVariables.Trim().Split(' '))
                    {
                        variables.Add(variable.Split('=')[0].Trim(), variable.Split('=')[1].Trim());
                    }

                }

                List<string> gears = new List<string>();

                if (!string.IsNullOrEmpty(WithGears))
                {
                    gears = this.WithGears.Split(';').ToList();
                }

                status.Output = container.AddUserVar(variables, gears);
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running oo-user-var-add command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = ex.ToString();
                status.ExitCode = 1;
            }
            return status;
        }
 public DeploymentMetadata(ApplicationContainer container, string deploymentDatetime)
 {
     this.file = Path.Combine(container.ContainerDir, "app-deployments", deploymentDatetime, "metadata.json");
     if(File.Exists(file))
     {
         Load();
     }
     else
     {
         using (File.Create(this.file)) { };
         container.SetRWPermissions(this.file);
         this.metadata = this.defaults;
         Save();
     }
 }
 public ApplicationRepository(ApplicationContainer container, string path)
 {
     this.Container = container;
     this.RepositoryPath = path ?? Path.Combine(container.ContainerDir, "git", string.Format("{0}.git", container.ApplicationName));
 }
 public ApplicationRepository(ApplicationContainer container) : this(container, null) { }
        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;
                }
            }
        }
Example #24
0
        public static RubyHash NodeUtilization()
        {
            RubyHash result = new RubyHash();

            Common.Config resource = Node.ResourceLimits;

            if (resource == null)
            {
                return(result);
            }

            result["node_profile"]         = resource.Get("node_profile", Node.DEFAULT_NODE_PROFILE);
            result["quota_blocks"]         = resource.Get("quota_blocks", Node.DEFAULT_QUOTA_BLOCKS);
            result["quota_files"]          = resource.Get("quota_files", Node.DEFAULT_QUOTA_FILES);
            result["no_overcommit_active"] = Boolean.Parse(resource.Get("no_overcommit_active", Node.DEFAULT_NO_OVERCOMMIT_ACTIVE));


            result["max_active_gears"] = Convert.ToInt32(resource.Get("max_active_gears", Node.DEFAULT_MAX_ACTIVE_GEARS));


            //
            // Count number of git repos and gear status counts
            //
            result["git_repos_count"]       = 0;
            result["gears_total_count"]     = 0;
            result["gears_idled_count"]     = 0;
            result["gears_stopped_count"]   = 0;
            result["gears_started_count"]   = 0;
            result["gears_deploying_count"] = 0;
            result["gears_unknown_count"]   = 0;


            foreach (ApplicationContainer app in ApplicationContainer.All(null, false))
            {
                result["gears_total_count"] += 1;

                switch (app.State.Value())
                {
                case "building":
                case "deploying":
                case "new":
                    result["gears_deploying_count"] += 1;
                    break;

                case "started":
                    result["gears_started_count"] += 1;
                    break;

                case "idle":
                    result["gears_idled_count"] += 1;
                    break;

                case "stopped":
                    result["gears_stopped_count"] += 1;
                    break;

                case "unknown":
                    result["gears_unknown_count"] += 1;
                    break;
                }
            }


            // consider a gear active unless explicitly not
            result["gears_active_count"]     = result["gears_total_count"] - result["gears_idled_count"] - result["gears_stopped_count"];
            result["gears_usage_pct"]        = result["max_active_gears"] == 0 ? 0.0f : (result["gears_total_count"] * 100.0f) / result["max_active_gears"];
            result["gears_active_usage_pct"] = result["max_active_gears"] == 0 ? 0.0f : (result["gears_active_count"] * 100.0f) / result["max_active_gears"];
            result["capacity"]        = result["gears_usage_pct"].ToString();
            result["active_capacity"] = result["gears_active_usage_pct"].ToString();
            return(result);
        }
 public ContainerPlugin(ApplicationContainer applicationContainer)
 {
     this.container = applicationContainer;
     this.config = NodeConfig.Values;
 }
Example #26
0
 public ContainerPlugin(ApplicationContainer applicationContainer)
 {
     this.container = applicationContainer;
     this.config    = NodeConfig.Values;
 }
        public static ApplicationContainer GetFromUuid(string containerUuid, Hourglass hourglass = null)
        {
            EtcUser etcUser = GetPasswdFor(containerUuid);
            string nameSpace = null;
            Dictionary<string,string> env = Environ.Load(Path.Combine(LinuxFiles.Cygpath(etcUser.Dir, true), ".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;

        }
Example #28
0
        public ReturnStatus Execute()
        {
            Logger.Debug("Running gear command: '{0}'", Environment.CommandLine);

            ReturnStatus status = new ReturnStatus();
            try
            {
                string appUuid = Environment.GetEnvironmentVariable("OPENSHIFT_APP_UUID");
                string gearUuid = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_UUID");
                string appName = Environment.GetEnvironmentVariable("OPENSHIFT_APP_NAME");
                string gearName = Environment.GetEnvironmentVariable("OPENSHIFT_GEAR_NAME");
                string nmSpace = Environment.GetEnvironmentVariable("OPENSHIFT_NAMESPACE");

                NodeConfig config = new NodeConfig();
                EtcUser etcUser = new Etc(config).GetPwanam(gearUuid);

                container = new ApplicationContainer(appUuid, gearUuid, etcUser, appName, gearName, nmSpace, null, null, null);
                repo = new ApplicationRepository(container);

                if (Prereceive)
                {
                    Dictionary<string, object> options = new Dictionary<string, object>();
                    options["init"] = Init;
                    options["hotDeploy"] = true;
                    options["forceCleanBuild"] = true;
                    options["ref"] = container.DetermineDeploymentRef();
                    container.PreReceive(options);
                }
                else if (Postreceive)
                {
                    RubyHash options = new RubyHash();
                    options["init"] = Init;
                    options["all"] = true;
                    options["reportDeployment"] = true;
                    options["ref"] = container.DetermineDeploymentRef();
                    container.PostReceive(options);
                }
                else if (Build)
                {
                    string ciRepoPath = Path.Combine(Environment.GetEnvironmentVariable("OPENSHIFT_REPO_DIR"), ".git");
                    string repoDir = null;
                    if(Directory.Exists(ciRepoPath))
                    {
                        repoDir = ciRepoPath;
                    }
                    repo = new ApplicationRepository(this.container, repoDir);
                    string gitRef = null;
                    bool archive =false;
                    if(repoDir == null)
                    {
                        gitRef = this.container.DetermineDeploymentRef(this.RefId);
                        archive = true;
                    }
                    else
                    {
                        gitRef = Environment.GetEnvironmentVariable("GIT_BRANCH");
                    }
                    if(!ValidGitRef(gitRef))
                    {
                        throw new Exception(string.Format("Git ref {0} is invalid", gitRef));
                    }
                    if(archive)
                    {
                        repo.Archive(Environment.GetEnvironmentVariable("OPENSHIFT_REPO_DIR"), gitRef);
                    }

                    RubyHash options = new RubyHash();
                    options["ref"] = gitRef;
                    options["hot_deploy"] = repo.FileExists(HOT_DEPLOY_MARKER, gitRef);
                    options["force_clean_build"] = repo.FileExists(FORCE_CLEAN_BUILD_MARKER, gitRef);
                    options["git_repo"] = repo;

                    Console.WriteLine(container.Build(options));
                }
                else if (Prepare)
                {
                    throw new NotImplementedException();
                }
                else if (Deploy)
                {
                    if (Environment.GetEnvironmentVariable("OPENSHIFT_DEPLOYMENT_TYPE") == "binary")
                    {
                        throw new Exception("OPENSHIFT_DEPLOYMENT_TYPE is 'binary' - git-based deployments are disabled.");
                    }
                    string refToDeploy = container.DetermineDeploymentRef(this.DeployRefId);
                    if (!ValidGitRef(refToDeploy))
                    {
                        throw new Exception("Git ref " + refToDeploy + " is not valid");
                    }
                    RubyHash options = new RubyHash();
                    options["hot_deploy"] = this.HotDeploy;
                    options["force_clean_build"] = this.ForceCleanBuild;
                    options["ref"] = this.DeployRefId;
                    options["report_deployments"] = true;
                    options["all"] = true;
                    container.Deploy(options);
                }
                else if (Activate)
                {
                    status.Output = container.Activate(new RubyHash
                    {
                        {"deployment_id", this.DeploymentId},
                        {"post_install", this.PostInstall.ToBool()},
                        {"all", this.All.ToBool()},
                        {"rotate", this.Rotation && !this.NoRotation},
                        {"report_deployments", true},
                        {"out", !this.AsJson.ToBool()}
                    });
                }
                status.ExitCode = 0;
            }
            catch (Exception ex)
            {
                Logger.Error("Error running gear command: {0} - {1}", ex.Message, ex.StackTrace);
                status.Output = string.Format("{0}", ex.Message, ex.StackTrace);
                status.ExitCode = 255;
            }

            return status;
        }