コード例 #1
0
        private void ReloadLicense()
        {
            var license = _serverStore.LoadLicense();

            if (license == null)
            {
                _licenseStatus.Attributes = null;
                _licenseStatus.Error      = false;
                _licenseStatus.Message    = null;
                return;
            }

            try
            {
                _licenseStatus.Attributes = LicenseValidator.Validate(license, RSAParameters);
                _licenseStatus.Error      = false;
                _licenseStatus.Message    = null;
            }
            catch (Exception e)
            {
                _licenseStatus.Attributes = null;
                _licenseStatus.Error      = true;
                _licenseStatus.Message    = e.Message;
            }
        }
コード例 #2
0
        private static bool ValidateLicense(License oldLicense, RSAParameters rsaParameters, License newLicense)
        {
            try
            {
                LicenseValidator.Validate(oldLicense, rsaParameters);
            }
            catch (Exception e)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Failed to validate license: `{oldLicense}`", e);
                }

                return(true);
            }

            if (oldLicense.Id != newLicense.Id)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Can't update license because the new license ID is: {newLicense.Id} " +
                                $"while old license ID is: {oldLicense.Id}");
                }

                return(false);
            }

            return(true);
        }
コード例 #3
0
        public static void Activate(License license)
        {
            try
            {
                LicenseStatus.Attributes = LicenseValidator.Validate(license, RSAParameters);
                LicenseStatus.Error      = false;
                LicenseStatus.Message    = null;

                ServerStore.LicenseStorage.SaveLicense(license);
                Task.Run(() => LeaseLicense());
            }
            catch (Exception e)
            {
                LicenseStatus.Attributes = null;
                LicenseStatus.Error      = true;
                LicenseStatus.Message    = e.Message;

                var message = $"Could not validate the following license:{Environment.NewLine}" +
                              $"Id: {license.Id}{Environment.NewLine}" +
                              $"Name: {license.Name}{Environment.NewLine}" +
                              $"Keys: [{string.Join(", ", license.Keys)}]";

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info(message, e);
                }

                throw new InvalidDataException("Could not validate license!", e);
            }
        }
コード例 #4
0
        public async Task Activate(License license, bool skipLeaseLicense)
        {
            if (_serverStore.CurrentState == RachisConsensus.State.Passive)
            {
                throw new InvalidOperationException(
                          "Couldn't activate license because this node is passive" +
                          "Passive nodes aren't members of a cluster and require admin action (such as creating a db) " +
                          "to indicate that this node should create its own cluster");
            }

            try
            {
                _licenseStatus.Attributes = LicenseValidator.Validate(license, RSAParameters);
                var licenseExpiration = _licenseStatus.Expiration;

                if (licenseExpiration.HasValue == false)
                {
                    _licenseStatus.Attributes = null;
                    throw new LicenseExpiredException(@"License doesn't have an expirtaion date!");
                }

                if (licenseExpiration < DateTime.UtcNow)
                {
                    _licenseStatus.Attributes = null;
                    throw new LicenseExpiredException($"License already expired on: {licenseExpiration}");
                }

                _licenseStatus.Error   = false;
                _licenseStatus.Message = null;

                _lastSavedLicenseIndex = await _serverStore.PutLicense(license);

                if (skipLeaseLicense == false)
#pragma warning disable 4014
                {
                    Task.Run(LeaseLicense);
                }
#pragma warning restore 4014
            }
            catch (Exception e)
            {
                _licenseStatus.Attributes = null;
                _licenseStatus.Error      = true;
                _licenseStatus.Message    = e.Message;

                var message = $"Could not validate the following license:{Environment.NewLine}" +
                              $"Id: {license.Id}{Environment.NewLine}" +
                              $"Name: {license.Name}{Environment.NewLine}" +
                              $"Keys: [{(license.Keys != null ? string.Join(", ", license.Keys) : "N/A")}]";

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info(message, e);
                }

                throw new InvalidDataException("Could not validate license!", e);
            }
        }
コード例 #5
0
        public void Initialize(StorageEnvironment environment, TransactionContextPool contextPool)
        {
            try
            {
                _licenseStorage.Initialize(environment, contextPool);

                var firstServerStartDate = _licenseStorage.GetFirstServerStartDate();
                if (firstServerStartDate == null)
                {
                    firstServerStartDate = SystemTime.UtcNow;
                    _licenseStorage.SetFirstServerStartDate(firstServerStartDate.Value);
                }

                _licenseStatus.FirstServerStartDate = firstServerStartDate.Value;

                var license = _serverStore.LoadLicense();
                if (license == null)
                {
                    return;
                }

                _leaseLicenseTimer = new Timer(state =>
                                               AsyncHelpers.RunSync(LeaseLicense), null, 0, (int)TimeSpan.FromHours(24).TotalMilliseconds);

                _licenseStatus.Attributes = LicenseValidator.Validate(license, RSAParameters);
                _licenseStatus.Error      = false;
                _licenseStatus.Message    = null;
            }
            catch (Exception e)
            {
                _licenseStatus.Attributes = null;
                _licenseStatus.Error      = true;
                _licenseStatus.Message    = e.Message;

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Could not validate license", e);
                }

                var alert = AlertRaised.Create(
                    "License manager initialization error",
                    "Could not intitalize the license manager",
                    AlertType.LicenseManager_InitializationError,
                    NotificationSeverity.Warning,
                    details: new ExceptionDetails(e));

                _serverStore.NotificationCenter.Add(alert);
            }
        }
コード例 #6
0
        public static void Initialize()
        {
            var firstServerStartDate = ServerStore.LicenseStorage.GetFirstServerStartDate();

            if (firstServerStartDate == null)
            {
                firstServerStartDate = SystemTime.UtcNow;
                ServerStore.LicenseStorage.SetFirstServerStartDate(firstServerStartDate.Value);
            }

            LicenseStatus.FirstServerStartDate = firstServerStartDate.Value;

            var license = ServerStore.LicenseStorage.LoadLicense();

            if (license == null)
            {
                return;
            }

            try
            {
                LicenseStatus.Attributes = LicenseValidator.Validate(license, RSAParameters);
                LicenseStatus.Error      = false;
                LicenseStatus.Message    = null;
            }
            catch (Exception e)
            {
                LicenseStatus.Attributes = null;
                LicenseStatus.Error      = true;
                LicenseStatus.Message    = e.Message;

                if (Logger.IsInfoEnabled)
                {
                    Logger.Info("Could not validate license. License details", e);
                }

                throw new InvalidDataException("Could not validate license!");
            }
        }