Exemple #1
0
 public void Deserialize(Serialization.IO.CompactReader reader)
 {
     _jobIdentifier  = reader.ReadString();
     rootFolderName  = reader.ReadString();
     _creationTime   = reader.ReadDateTime();
     _activeConfig   = reader.ReadObject() as RecoveryConfiguration;
     _executionState = reader.ReadObject() as ClusteredRecoveryJobState;
 }
        private void PopulateRestoreConfiguration(Dictionary <string, object> configValues,
                                                  out ICloneable configuration)
        {
            RecoveryConfiguration recoveryConfig = new RecoveryConfiguration();
            string databaseName = "";

            if (configValues.ContainsKey(ConfigType.Name.ToString()))
            {
                databaseName = configValues[ConfigType.Name.ToString()] as string;
            }
            if (configValues.ContainsKey(ConfigType.SourceDatabase.ToString()))
            {
                recoveryConfig.DatabaseMap.Add(configValues[ConfigType.SourceDatabase.ToString()] as string, databaseName.ToLower());
            }
            else
            {
                recoveryConfig.DatabaseMap.Add(databaseName.ToLower(), string.Empty);
            }
            if (configValues.ContainsKey(ConfigType.RestoreType.ToString()))
            {
                string jobType = configValues[ConfigType.RestoreType.ToString()] as string;
                if ("Full".Equals(jobType, StringComparison.OrdinalIgnoreCase))
                {
                    recoveryConfig.JobType = RecoveryJobType.Restore;
                }
                else
                {
                    throw new QuerySystemException(ErrorCodes.Query.INVALID_DDL_CONFIGURATION_JSON);
                }
            }
            if (configValues.ContainsKey(ConfigType.Path.ToString()))
            {
                string path = (string)configValues[ConfigType.Path.ToString()];
                //validate
                recoveryConfig.RecoveryPath = path;
            }
            if (configValues.ContainsKey(ConfigType.UserName.ToString()))
            {
                string userName = (string)configValues[ConfigType.UserName.ToString()];
                //validate
                recoveryConfig.UserName = userName;
            }

            if (configValues.ContainsKey(ConfigType.Password.ToString()))
            {
                string password = (string)configValues[ConfigType.Password.ToString()];
                //validate
                recoveryConfig.Password = password;
            }

            configuration = recoveryConfig;
        }
        public RecoveryOperationStatus StartRecoveryJob(string databaseName, string destinationDatabase, string backUpType, string path)
        {
            RecoveryConfiguration recoveryConfiguration = new RecoveryConfiguration();

            recoveryConfiguration.DatabaseMap = new Dictionary <string, string>();
            recoveryConfiguration.DatabaseMap.Add(databaseName,
                                                  string.IsNullOrEmpty(destinationDatabase) ? string.Empty : destinationDatabase);

            recoveryConfiguration.Cluster = ConfigurationConnection.ClusterConfiguration.Name;


            recoveryConfiguration.JobType      = (RecoveryJobType)Enum.Parse(typeof(RecoveryJobType), backUpType);
            recoveryConfiguration.RecoveryPath = path;
            return(ConfigurationConnection.Current.SubmitRecoveryJob(recoveryConfiguration));
        }
Exemple #4
0
        public RecoveryConfiguration GetJobConfiguration(string identifier)
        {
            RecoveryConfiguration config = new RecoveryConfiguration();

            config.Identifier = identifier;

            if (_runningClusteredJobMap.ContainsKey(identifier))
            {
                config = ((ClusterRecoveryJob)_runningClusteredJobMap[identifier]).ActiveConfig;
            }
            else
            {
                ClusterJobInfoObject jobInfo = _configurationStore.GetRecoveryJobData(identifier);
                if (jobInfo != null)
                {
                    config = jobInfo.ActiveConfig;
                }
            }
            return(config);
        }
Exemple #5
0
        public ClusterJobInfoObject(string identifier, RecoveryConfiguration config)
        {
            if (!string.IsNullOrEmpty(identifier))
            {
                _jobIdentifier  = identifier;
                _executionState = new ClusteredRecoveryJobState(identifier);
                _mutex          = new object();
                if (config != null)
                {
                    _activeConfig = config;
                    _creationTime = _activeConfig.CreationTime;
                    string databaseName = config.DatabaseMap.First().Key;
                    rootFolderName    = databaseName + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + RecoveryFolderStructure.INPROGRESS;
                    _shardResponseMap = new Dictionary <string, ShardDifState>();

                    if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                    {
                        LoggerManager.Instance.RecoveryLogger.Error("ClusterJobInfoObject.Submit()", config.ToString());
                    }
                }
            }
        }
Exemple #6
0
        public ClusteredRecoveryJobState GetJobState(string identifier)
        {
            ClusteredRecoveryJobState state = new ClusteredRecoveryJobState(identifier);

            try
            {
                RecoveryConfiguration config = new RecoveryConfiguration();
                config.Identifier = identifier;
                state.Identifier  = identifier;
                if (_runningClusteredJobMap.ContainsKey(identifier))
                {
                    IClusteredRecoveryJob _job = ((IClusteredRecoveryJob)_runningClusteredJobMap[identifier]);
                    state = _job.CurrentState(config) as ClusteredRecoveryJobState;
                }
                else
                {
                    ClusterJobInfoObject clusterJobs = _configurationStore.GetRecoveryJobData(identifier);
                    if (clusterJobs != null)// this should always be equyal
                    {
                        state = clusterJobs.ExecutionState;
                    }
                    else
                    {
                        state.Message = "Invalid identifier provided";
                    }
                    // query db for
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.GetState()", ex.ToString());
                }
                state.Message = ex.Message;
            }
            return(state);
        }
Exemple #7
0
        RecoveryOperationStatus IRecoveryManager.CancelRecoveryJob(string identifier)
        {
            RecoveryOperationStatus state = new RecoveryOperationStatus(RecoveryStatus.Failure);

            state.Message = "Failure during cancellation"; // change this default message

            try
            {
                RecoveryConfiguration config = new RecoveryConfiguration();
                config.Identifier   = identifier;
                state.JobIdentifier = identifier;
                if (_runningClusteredJobMap.ContainsKey(identifier))
                {
                    if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsInfoEnabled)
                    {
                        LoggerManager.Instance.RecoveryLogger.Info("RecoveryManager.CancelRecoveryJob()", "Explicit canceling initiated");
                    }
                    IClusteredRecoveryJob _job = ((IClusteredRecoveryJob)_runningClusteredJobMap[identifier]);
                    state = _job.Cancel(config, explicitCancel: true);
                    // remove job from active config
                    RemoveRunningJob(identifier);
                }
                else
                {
                    state.Message = "Invalid identifier provided";
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.Cancel()", ex.ToString());
                }
                state.Message = ex.Message;
            }
            return(state);
        }
Exemple #8
0
 public void Dispose()
 {
     _activeConfig     = null;
     _executionState   = null;
     _shardResponseMap = null;
 }
Exemple #9
0
        RecoveryOperationStatus IRecoveryManager.SubmitRecoveryJob(RecoveryConfiguration config, object additionalParams)
        {
            RecoveryOperationStatus state = new RecoveryOperationStatus(RecoveryStatus.Failure);

            state.Message = "Failure during submission state";

            try
            {
                // Ensure the prereqs provided are valid
                RecoveryOperationStatus valid = this.EnsurePreRequisites(config, additionalParams);
                if (valid.Status == RecoveryStatus.Success)
                {
                    // 1. create and register clustered job
                    ClusterRecoveryJob _clusteredJob = new ClusterRecoveryJob(this.AssignJobUID(), config, this, _configurationStore);
                    _clusteredJob.RegisterRecoveryCommunicationHandler(this);
                    _runningClusteredJobMap.Add(_clusteredJob.JobIdentifier, _clusteredJob);

                    state.JobIdentifier = _clusteredJob.JobIdentifier;


                    // create rootfolder for recovery
                    switch (config.JobType)
                    {
                    case RecoveryJobType.ConfigBackup:
                    case RecoveryJobType.DataBackup:
                    case RecoveryJobType.FullBackup:

                        //
                        RecoveryOperationStatus folderStatus = _clusteredJob.CreateRecoveryFolder(config.RecoveryPath, config.UserName, config.Password);

                        if (folderStatus.Status == RecoveryStatus.Failure)
                        {
                            RemoveRunningJob(_clusteredJob.JobIdentifier);
                            _clusteredJob.Dispose();
                            return(folderStatus);
                        }
                        break;
                    }

                    //2. call prepare for this job
                    state = _clusteredJob.Initialize(config, additionalParams);

                    //3. verify status
                    if (state.Status == RecoveryStatus.Failure)
                    {
                        RemoveRunningJob(_clusteredJob.JobIdentifier);

                        return(state);
                    }

                    if (state.Status == RecoveryStatus.Failure)
                    {
                        // remove job from active config
                        RemoveRunningJob(_clusteredJob.JobIdentifier);
                        return(state);
                    }
                    else
                    {
                        state = _clusteredJob.Start(config);
                    }
                }
                else
                {
                    state = valid;
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.Submit()", ex.ToString());
                }
                state.Message = ex.Message;
                // log exception
            }

            return(state);
        }
Exemple #10
0
        private RecoveryOperationStatus EnsurePreRequisites(RecoveryConfiguration config, object additionalParams)
        {
            RecoveryOperationStatus state = new RecoveryOperationStatus(RecoveryStatus.Failure);

            state.JobIdentifier = config.Identifier;

            Impersonation impersonation = null;

            if (RecoveryFolderStructure.PathIsNetworkPath(config.RecoveryPath))
            {
                impersonation = new Impersonation(config.UserName, config.Password);
            }

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

            ClusterInfo clusterInfo = GetConfiguredClusters(config.Cluster);

            shardNameList.AddRange(clusterInfo.ShardInfo.Keys);

            state = RecoveryFolderStructure.ValidateFolderStructure(config.RecoveryPath, config.JobType, true,
                                                                    shardNameList);
            if (state.Status == RecoveryStatus.Failure)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.EnsurePreRequisites()", config.RecoveryPath + "  : " + state.Message);
                }
            }

            if (state.Status == RecoveryStatus.Success)
            {
                CsBackupableEntities entity = (CsBackupableEntities)additionalParams;

                #region validate db Name

                switch (config.JobType)
                {
                case RecoveryJobType.ConfigRestore:
                case RecoveryJobType.Restore:
                    state = DatabaseExists(config.DatabaseMap, entity, config.JobType);
                    if (state.Status == RecoveryStatus.Failure)
                    {
                        return(state);
                    }
                    break;

                case RecoveryJobType.ConfigBackup:
                case RecoveryJobType.DataBackup:
                case RecoveryJobType.FullBackup:

                    state = DatabaseExists(config.DatabaseMap, entity, config.JobType);
                    if (state.Status == RecoveryStatus.Failure)
                    {
                        return(state);
                    }

                    break;
                }
                state.Status = RecoveryStatus.Success;

                #endregion

                #region validate files

                if (config.JobType == RecoveryJobType.Restore)
                {
                    string configPath = Path.Combine(config.RecoveryPath, RecoveryFolderStructure.CONFIG_SERVER);
                    string filePath   = Path.Combine(configPath, RecoveryFolderStructure.CONFIG_SERVER);

                    if (File.Exists(filePath))
                    {
                        BackupFile file = new BackupFile(RecoveryFolderStructure.CONFIG_SERVER, configPath, config.UserName, config.Password);

                        Alachisoft.NosDB.Core.Recovery.Persistence.BackupFile.Header header = file.ReadFileHeader();
                        if (!header.Database.ToLower().Equals(config.DatabaseMap.First().Key))
                        {
                            state.Status  = RecoveryStatus.Failure;
                            state.Message = "Provided file does not contain the source database " +
                                            config.DatabaseMap.First().Key;
                        }
                        file.Close();
                    }
                    else
                    {
                        state.Status  = RecoveryStatus.Failure;
                        state.Message = "No file exists in the given folder";
                    }
                }

                #endregion
                if (impersonation != null)
                {
                    impersonation.Dispose();
                }
            }
            if (state.Status == RecoveryStatus.Failure)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.EnsurePreRequisites()", state.Message);
                }
            }

            return(state);
        }
Exemple #11
0
        public void SubmitConfigChanged(object changeConfig)
        {
            try
            {
                bool failed = true;;
                // get all clustered jobs working on given config
                foreach (ClusterRecoveryJob job in _runningClusteredJobMap.Values)
                {
                    if (job.ActiveConfig.JobType == RecoveryJobType.Restore || job.ActiveConfig.JobType == RecoveryJobType.ConfigRestore)
                    {
                        string db = string.Empty;
                        // check if exception or actual data
                        if (changeConfig is RecoveryOperationStatus)
                        {
                            RecoveryOperationStatus status = (RecoveryOperationStatus)changeConfig;
                            string[] splitString           = status.JobIdentifier.Split('_');
                            if (!string.IsNullOrEmpty(splitString[1]))
                            {
                                db = splitString[1];
                            }
                            else
                            {
                                db = splitString[0];
                            }
                        }

                        if (changeConfig is CsBackupableEntities)
                        {
                            CsBackupableEntities entity = (CsBackupableEntities)changeConfig;
                            db     = entity.Database.First().Key.ToLower();
                            failed = false;
                        }

                        KeyValuePair <string, string> dbMap = job.ActiveConfig.DatabaseMap.First();

                        bool valid = false;
                        if (!string.IsNullOrEmpty(dbMap.Value))
                        {
                            if (dbMap.Value.ToLower().Equals(db))
                            {
                                valid = true;
                            }
                        }
                        else
                        {
                            if (dbMap.Key.ToLower().Equals(db))
                            {
                                valid = true;
                            }
                        }

                        if (valid && !failed)
                        {
                            RecoveryConfiguration config = new RecoveryConfiguration();
                            config.Identifier = job.JobIdentifier;
                            RecoveryStatus state = (job.CurrentState(config) as ClusteredRecoveryJobState).Status;

                            if (state != RecoveryStatus.Failure || state != RecoveryStatus.Cancelled || state != RecoveryStatus.Completed)
                            {
                                if (changeConfig != null)
                                {
                                    job.SubmitConfigChanged(changeConfig);
                                }
                                else
                                {
                                    if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                                    {
                                        LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", "failing");
                                    }
                                    job.Cancel(config);// job has failed
                                    // remove job from active config
                                    RemoveRunningJob(config.Identifier);
                                    break;
                                }
                            }
                        }
                        else if (failed)
                        {
                            RecoveryConfiguration config = new RecoveryConfiguration();
                            config.Identifier = job.JobIdentifier;
                            if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                            {
                                LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", "overall failure");
                            }
                            job.Cancel(config);
                            // remove job from active config
                            RemoveRunningJob(config.Identifier);
                            break;
                        }
                        //job.
                    }
                }
            }
            catch (Exception ex)
            {
                if (LoggerManager.Instance.RecoveryLogger != null && LoggerManager.Instance.RecoveryLogger.IsErrorEnabled)
                {
                    LoggerManager.Instance.RecoveryLogger.Error("RecoveryManager.SubmitConfigChanged()", ex.ToString());
                }
            }
        }
Exemple #12
0
 public Common.Recovery.RecoveryOperationStatus SubmitRecoveryJob(RecoveryConfiguration config)
 {
     throw new NotImplementedException();
 }