Esempio n. 1
0
        private void WarmUp()
        {
            InstallationProgress.Step = InstallationProgressStep.WarmUp;
            CacheHelper.SetInstallationProgress(UserId, InstallationProgress);

            SshHelper.WarmingUp(ConnectionInfo.Host);
        }
Esempio n. 2
0
        public JsonResult StartInstall(ConnectionSettingsModel connectionSettings, InstallationComponentsModel installationComponents)
        {
            try
            {
                var installedComponents = CacheHelper.GetInstalledComponents(UserId);

                if (installedComponents != null)
                {
                    return(Json(new
                    {
                        success = false,
                        message = OneClickHomePageResource.ExistVersionErrorText
                    }));
                }

                if (!installationComponents.CommunityServer || !installationComponents.DocumentServer)
                {
                    return(Json(new
                    {
                        success = false,
                        message = OneClickCommonResource.ErrorRequiredComponents
                    }));
                }

                if (installationComponents.MailServer && !ValidateDomainName(installationComponents.MailDomain))
                {
                    return(Json(new
                    {
                        success = false,
                        message = OneClickJsResource.ErrorInvalidDomainName
                    }));
                }

                CacheHelper.SetSelectedComponents(UserId, installationComponents);
                CacheHelper.SetInstallationProgress(UserId, new InstallationProgressModel());

                SshHelper.StartInstallation(UserId, connectionSettings, installationComponents);

                return(Json(new
                {
                    success = true,
                    message = string.Empty,
                    selectedComponents = GetJsonString(CacheHelper.GetSelectedComponents(UserId)),
                    installationProgress = GetJsonString(CacheHelper.GetInstallationProgress(UserId))
                }));
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ASC").Error(ex.Message, ex);

                CacheHelper.SetSelectedComponents(UserId, null);
                CacheHelper.SetInstallationProgress(UserId, null);

                return(Json(new
                {
                    success = false,
                    message = ex.Message
                }));
            }
        }
Esempio n. 3
0
 public DeploymentManager(DeploymentInfo deployment, string branch, string version)
 {
     Deployment         = deployment;
     Ssh                = new SshHelper(deployment.Ssh);
     Ssh.StartDirectory = "/usr/local/GrowSense/Index";
     Version            = version;
     Branch             = branch;
 }
Esempio n. 4
0
        public void Test_DeployUpgrade()
        {
            Console.WriteLine("Testing deploy upgrade...");

            var version = File.ReadAllText(ProjectDirectory + "/full-version.txt").Trim();

            var branch = new BranchDetector(ProjectDirectory).Branch;

            Console.WriteLine("  Version: " + version);
            Console.WriteLine("  Branch: " + branch);

            var deployment = GetDeploymentInfo(branch);

            Console.WriteLine("  Host: " + deployment.Ssh.Host);
            Console.WriteLine("  SSH Username: "******"  SSH Password: hidden (length " + (String.IsNullOrEmpty(deployment.Ssh.Password) ? deployment.Ssh.Password.Length : 0) + ")");
            Console.WriteLine("  SSH Port: " + deployment.Ssh.Port);

            Console.WriteLine("  MQTT Host: " + deployment.Mqtt.Host);
            Console.WriteLine("  MQTT Username: "******"  MQTT Password: hidden (length " + (String.IsNullOrEmpty(deployment.Mqtt.Password) ? deployment.Mqtt.Password.Length : 0) + ")");
            Console.WriteLine("  MQTT Port: " + deployment.Mqtt.Port);

            var ssh = new SshHelper(deployment.Ssh);

            ssh.UseSshPass = true;

            var manager = new DeploymentManager(deployment, branch, version);

            manager.CreateReleaseZipAndPushToHost(ProjectDirectory, deployment, ssh);

            if (!manager.IsInstalledOnTarget())
            {
                Assert.Fail("Can't upgrade when GrowSense is not currently installed.");
            }

            // TODO: Remove if not needed. Used for debugging
            //manager.Ssh.Execute("echo helloworld");
            //manager.Ssh.Execute("sudo echo hello > /usr/local/GrowSense/Installer/hello.txt");

            manager.DownloadAndLaunchUpgrade();

            manager.SetConfigValues();

            Console.WriteLine("Setting supervisor settings...");
            manager.Ssh.Execute("echo 10 > supervisor-status-check-frequency.txt && echo 10 > supervisor-docker-check-frequency.txt && echo 10 > supervisor-mqtt-check-frequency.txt");

            Console.WriteLine("Deploy upgrade successful.");
        }
Esempio n. 5
0
        public JsonResult Connect(ConnectionSettingsModel connectionSettings)
        {
            try
            {
                InstallationComponentsModel installedComponents  = null;
                InstallationComponentsModel selectedComponents   = null;
                InstallationProgressModel   installationProgress = null;

                if (connectionSettings != null)
                {
                    installedComponents  = SshHelper.Connect(UserId, connectionSettings);
                    installationProgress = CacheHelper.GetInstallationProgress(UserId);
                    selectedComponents   = CacheHelper.GetSelectedComponents(UserId);

                    CacheHelper.SetConnectionSettings(UserId, connectionSettings);
                    CacheHelper.SetInstalledComponents(UserId, installedComponents);
                }
                else
                {
                    CookieHelper.ClearCookie();
                    CacheHelper.ClearCache(UserId);
                }

                return(Json(new
                {
                    success = true,
                    message = string.Empty,
                    connectionSettings = GetJsonString(connectionSettings),
                    installedComponents = GetJsonString(installedComponents),
                    installationProgress = GetJsonString(installationProgress),
                    selectedComponents = GetJsonString(selectedComponents)
                }));
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ASC").Error(ex.Message, ex);

                return(Json(new
                {
                    success = false,
                    message = ex.Message,
                    errorCode = GetErrorCode(ex.Message)
                }));
            }
        }
Esempio n. 6
0
        /* Upload share.tar to /opt/omi/ and Uppack */
        private void UploadPythonPackages(string packageFolfer, string username, string pwd, string from)
        {
            SshHelper rootssh = new SshHelper(from, username, pwd);
            //Upload Provider to linux and run the script
            DirectoryInfo dir = new DirectoryInfo(Path.Combine(packageFolfer));

            try
            {
                string osname = GetOSName(rootssh);

                foreach (FileInfo f in dir.GetFiles("*"))
                {
                    string fileName     = f.Name;
                    string fullFileName = f.FullName;
                    switch (fileName)
                    {
                    case "share.tar":
                        ctx.Alw("Uploading and uppack the share.tar");
                        rootssh.Upload(fullFileName, "/root/share.tar");
                        rootssh.VerifyExecuteCommand("chmod +x /root/share.tar; tar xvf /root/share.tar -C /opt/omi/");
                        ctx.Alw(string.Format("Result:{0}", rootssh.Result));
                        break;

                    case "ProviderAndMofFiles.tar":
                        ctx.Alw("Uploading and uppack the ProviderAndMofFiles.tar");
                        rootssh.Upload(fullFileName, "/root/ProviderAndMofFiles.tar");
                        rootssh.VerifyExecuteCommand("chmod +x /root/ProviderAndMofFiles.tar; tar xvf /root/ProviderAndMofFiles.tar -C /opt/omi/lib");
                        ctx.Alw(string.Format("Result:{0}", rootssh.Result));
                        break;
                        //case "samples.tar":
                        //    ctx.Alw("Uploading and registering the libfilesys.so");
                        //    rootssh.Upload(fullFileName, "/root/libfilesys.so");
                        //    rootssh.VerifyExecuteCommand("chmod +x /root/libfilesys.so; /opt/omi/bin/omireg --hosting '@requestor@' -n root/cimv2 /root/libfilesys.so");
                        //    ctx.Alw(string.Format("Result:{0}", rootssh.Result));
                        //    break;
                    }
                }
            }
            catch (Exception ex)
            {
                ctx.Alw(string.Format("Failed to upload package files from Windows to remote Linux, error:{0}", ex.Message));
            }
        }
Esempio n. 7
0
        public JsonResult StartInstall(InstallationComponentsModel installationComponents)
        {
            try
            {
                var connectionSettings  = CacheHelper.GetConnectionSettings(UserId);
                var installedComponents = CacheHelper.GetInstalledComponents(UserId);

                if (connectionSettings.Enterprise && connectionSettings.LicenseKey == Settings.TrialFileName && !string.IsNullOrEmpty(Settings.LicenseUrl))
                {
                    if (installedComponents != null && installedComponents.LicenseFileExist)
                    {
                        throw new Exception(OneClickCommonResource.ErrorLicenseFileExist);
                    }

                    connectionSettings = RequestLicenseFile(connectionSettings, CacheHelper.GetRequestInfo(UserId));
                }

                var mailServerAlreadyInstalled = installedComponents != null &&
                                                 !string.IsNullOrEmpty(installedComponents.MailServerVersion);

                if (!mailServerAlreadyInstalled && !string.IsNullOrEmpty(installationComponents.MailServerVersion) &&
                    !ValidateDomainName(installationComponents.MailDomain))
                {
                    return(Json(new
                    {
                        success = false,
                        message = OneClickJsResource.ErrorInvalidDomainName
                    }));
                }

                CacheHelper.SetSelectedComponents(UserId, installationComponents);

                CacheHelper.SetInstallationProgress(UserId, new InstallationProgressModel());

                SshHelper.StartInstallation(UserId, connectionSettings, installationComponents);

                return(Json(new
                {
                    success = true,
                    message = string.Empty,
                    selectedComponents = GetJsonString(CacheHelper.GetSelectedComponents(UserId)),
                    installationProgress = GetJsonString(CacheHelper.GetInstallationProgress(UserId))
                }));
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ASC").Error(ex.Message, ex);

                CacheHelper.SetSelectedComponents(UserId, null);
                CacheHelper.SetInstallationProgress(UserId, null);

                var code = 0;

                if (ex is ExternalException)
                {
                    Int32.TryParse(Regex.Match(ex.Message, @"[\d+]").Value, out code);
                }

                return(Json(new
                {
                    success = false,
                    message = ex.Message,
                    errorCode = code > 0 ? "External" + code : "unknown"
                }));
            }
        }
Esempio n. 8
0
        public JsonResult Connect(ConnectionSettingsModel connectionSettings, RequestInfoModel requestInfo)
        {
            try
            {
                InstallationComponentsModel installedComponents  = null;
                InstallationComponentsModel selectedComponents   = null;
                InstallationProgressModel   installationProgress = null;
                OsInfo osInfo = null;

                if (connectionSettings != null)
                {
                    if (connectionSettings.Enterprise)
                    {
                        if (string.IsNullOrEmpty(connectionSettings.LicenseKey))
                        {
                            throw new ArgumentException("connectionSettings.licenseKey");
                        }

                        if (connectionSettings.LicenseKey == Settings.TrialFileName && requestInfo == null)
                        {
                            throw new ArgumentNullException("requestInfo");
                        }
                    }

                    var data = SshHelper.Connect(UserId, connectionSettings);

                    osInfo = data.Item1;
                    installedComponents  = data.Item2;
                    installationProgress = CacheHelper.GetInstallationProgress(UserId);
                    selectedComponents   = CacheHelper.GetSelectedComponents(UserId);

                    CacheHelper.SetConnectionSettings(UserId, connectionSettings);
                    CacheHelper.SetInstalledComponents(UserId, installedComponents);
                    CacheHelper.SetRequestInfo(UserId, requestInfo);
                }
                else
                {
                    CookieHelper.ClearCookie();
                    CacheHelper.ClearUserCache(UserId);
                }

                return(Json(new
                {
                    success = true,
                    message = string.Empty,
                    connectionSettings = GetJsonString(connectionSettings),
                    installedComponents = GetJsonString(installedComponents),
                    installationProgress = GetJsonString(installationProgress),
                    selectedComponents = GetJsonString(selectedComponents),
                    osInfo = GetJsonString(osInfo)
                }));
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("ASC").Error(ex.Message, ex);

                return(Json(new
                {
                    success = false,
                    message = ex.Message,
                    errorCode = GetErrorCode(ex.Message)
                }));
            }
        }
Esempio n. 9
0
        public void CreateReleaseZipAndPushToHost(string projectDirectory, DeploymentInfo deployment, SshHelper ssh)
        {
            Console.WriteLine("");
            Console.WriteLine("Creating release zip...");
            var starter = new ProcessStarter(projectDirectory);

            starter.StartBash("bash create-release-zip.sh");

            starter.OutputBuilder.Clear();


            var sourceReleaseFilePath = Directory.GetFiles(projectDirectory + "/releases/")[0];

            var destinationReleaseFilePath = "/usr/local/GrowSense/Installer/" + Path.GetFileName(sourceReleaseFilePath);

            ssh.CopyFileTo(sourceReleaseFilePath, destinationReleaseFilePath);
        }
Esempio n. 10
0
        /* Setup the ENV */
        public string UploadPackages(string packagesFolder, string userName, string password)
        {
            ctx.Alw(string.Format("Setup Linux OMI Environment"));
            string osPackageFilesPath = "BuildPlatform_PackageFiles.txt";
            string PackagesFolder     = GetValueByKey("PackagesFolder");
            string buildNumber        = GetValueByKey("BuildNumber");
            string providerFolder     = GetValueByKey("ProviderFolder");
            //string macMachine = GetValueByKey("macMachine");
            string errorMessage = string.Empty;


            string summaryResult = "<?xml version=\"1.0\" encoding=\"utf-16\"?><rootResult xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><LinuxResults>";

            foreach (string from in Linuxs)
            {
                SshHelper rootssh = new SshHelper(from, userName, password);

                //Upload GetOS.sh to linux and run the script
                string osname = GetOSName(rootssh);

                //Uninstall OMI
                ctx.Alw(string.Format("Uninstall OMI on {0}, osname:{1}", from, osname));
                UninstallOMIPackage(rootssh, osname);

                ctx.Alw(string.Format("Setup Negotiate and Kerberos authentication on Linux Server after install OMI on {0}, osname:{1}", from, osname));

                //Build Platform
                string buildPlatform = GetBuildPlatformByOSName(osname);
                ctx.Alw(string.Format("GetBuildPlatformByOSName OMI on {0}, osname:{1},buildPlatform:{2}", from, osname, buildPlatform));
                if (!File.Exists(osPackageFilesPath))
                {
                    this.Abort(ctx, "Need file:" + osPackageFilesPath);
                }

                rootssh.ExecuteCommand("openssl version");
                string opensslversion = rootssh.Result;

                //Upload Packages "share.tar"
                string linuxFile = UploadPythonPackage(rootssh, PackagesFolder, buildPlatform, osname, opensslversion, buildNumber);



                //Install OMI
                InstallOMIPackage(rootssh, osname, linuxFile);

                //Register OMI provider
                ctx.Alw(string.Format("Setup Linux OMI Providers"));
                string provierPath = Path.Combine(providerFolder, buildPlatform);
                UploadRegisterProvider(provierPath, buildPlatform, opensslversion, userName, password, from);
                summaryResult += "<LinuxResult><name>" + from + "</name><result><![CDATA[" + rootssh.Result + "]]></result></LinuxResult>";


                rootssh.VerifyExecuteCommand("/opt/omi/bin/service_control restart");
            }

            summaryResult += "</LinuxResults></rootResult>";

            if (!string.IsNullOrEmpty(errorMessage))
            {
                this.Fail(ctx, errorMessage);
            }

            return(summaryResult);
        }
Esempio n. 11
0
        public void Test_DeployInstall()
        {
            Console.WriteLine("Testing deploy install...");

            var version = File.ReadAllText(ProjectDirectory + "/full-version.txt").Trim();

            var branch = new BranchDetector(ProjectDirectory).Branch;


            Console.WriteLine("  Version: " + version);
            Console.WriteLine("  Branch: " + branch);

            var deployment = GetDeploymentInfo(branch);


            Console.WriteLine("  Username: "******"  Password: hidden (length " + (String.IsNullOrEmpty(deployment.Password) ? deployment.Password.Length : 0) + ")");

            Console.WriteLine("  SSH Host: " + deployment.Ssh.Host);
            Console.WriteLine("  SSH Username: "******"  SSH Password: hidden (length " + (String.IsNullOrEmpty(deployment.Ssh.Password) ? deployment.Ssh.Password.Length : 0) + ")");
            Console.WriteLine("  SSH Port: " + deployment.Ssh.Port);

            Console.WriteLine("  MQTT Host: " + deployment.Mqtt.Host);
            Console.WriteLine("  MQTT Username: "******"  MQTT Password: hidden (length " + (String.IsNullOrEmpty(deployment.Mqtt.Password) ? deployment.Mqtt.Password.Length : 0) + ")");
            Console.WriteLine("  MQTT Port: " + deployment.Mqtt.Port);

            var ssh = new SshHelper(deployment.Ssh);

            ssh.UseSshPass = true;

            var manager = new DeploymentManager(deployment, branch, version);

            manager.CreateReleaseZipAndPushToHost(ProjectDirectory, deployment, ssh);

            if (manager.IsInstalledOnTarget())
            {
                manager.WaitForUnlock();

                Console.WriteLine("Renaming GrowSense devices to ensure the name is set correctly after installation...");

                // TODO: Fix and reimplement
                //   manager.RenameDevice("irrigatorW1", "NewIrrigatorW");
                //   manager.RenameDevice("illuminator1", "NewIlluminator");
            }
            else
            {
                manager.Ssh.CreateDirectory("/usr/local/GrowSense/Index");
            }


            Console.WriteLine("");
            Console.WriteLine("Adding GrowSense remotes...");
            manager.AddRemotes();

            // TODO: Remove if not needed. Used for debugging
            //manager.Ssh.Execute("echo helloworld");
            //manager.Ssh.Execute("sudo echo hello > /usr/local/GrowSense/Installer/hello.txt");

            manager.DownloadAndLaunchInstall();

            manager.SetConfigValues();

            Console.WriteLine("Setting supervisor settings...");
            manager.Ssh.Execute("echo 10 > supervisor-status-check-frequency.txt && echo 10 > supervisor-docker-check-frequency.txt && echo 10 > supervisor-mqtt-check-frequency.txt");

            Console.WriteLine("Deploy installation successful.");
        }