Esempio n. 1
0
        internal void ResolvePartitions(ManagementAgent ma)
        {
            if (this.Partitions == null)
            {
                this.Partitions = new PartitionConfigurationCollection();
            }

            foreach (PartitionConfiguration c in this.Partitions)
            {
                bool found = false;

                foreach (Partition p in ma.Partitions.Values.Where(t => t.Selected))
                {
                    if (c.ID == p.ID || string.Equals(c.Name, p.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        c.UpdateConfiguration(p);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    c.IsMissing = true;
                }
            }

            foreach (Partition p in ma.Partitions.Values.Where(t => t.Selected && this.Partitions.GetItemOrNull(t.ID) == null))
            {
                PartitionConfiguration c = new PartitionConfiguration(p);
                MAConfigDiscovery.DoAutoRunProfileDiscovery(c, ma);
                this.Partitions.Add(c);
            }
        }
Esempio n. 2
0
        internal string GetRunProfileName(MARunProfileType type, Guid partitionID)
        {
            PartitionConfiguration p = this.Partitions.GetItemOrNull(partitionID);

            if (p == null)
            {
                logger.Warn($"Could not map run profile {type} for partition {partitionID} because the partition was not found");
                return(null);
            }

            if (!p.IsActive)
            {
                logger.Warn($"Could not map run profile {type} for partition {p.Name} ({partitionID}) because the partition is not active");
                return(null);
            }

            return(this.GetRunProfileName(type, p));
        }
Esempio n. 3
0
        internal void ResolvePartitions(ManagementAgent ma)
        {
            if (this.Partitions == null)
            {
                this.Partitions = new PartitionConfigurationCollection();
            }

            foreach (PartitionConfiguration c in this.Partitions)
            {
                bool found = false;

                foreach (Partition p in ma.Partitions.Values.Where(t => t.Selected))
                {
                    if (c.ID == p.ID || string.Equals(c.Name, p.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        logger.Trace($"Matched existing partition {c.ID}/{p.ID}/{c.Name}/{p.Name}");
                        c.UpdateConfiguration(p);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    logger.Trace($"Partition is missing from MA {c.ID}/{c.Name}");
                    c.IsMissing = true;
                }
            }

            foreach (Partition p in ma.Partitions.Values.Where(t => t.Selected && this.Partitions.GetItemOrNull(t.ID) == null))
            {
                logger.Trace($"New partition found in MA {p.ID}/{p.Name}");
                PartitionConfiguration c = new PartitionConfiguration(p);
                MAConfigDiscovery.DoAutoRunProfileDiscovery(c, ma);
                this.Partitions.Add(c);
            }

            logger.Trace($"{this.Partitions.Count} partitions are defined for the controller");
        }
Esempio n. 4
0
        internal string GetRunProfileName(MARunProfileType type, PartitionConfiguration partition)
        {
            switch (type)
            {
            case MARunProfileType.DeltaImport:
                return(partition.DeltaImportRunProfileName);

            case MARunProfileType.FullImport:
                return(partition.FullImportRunProfileName);

            case MARunProfileType.Export:
                return(partition.ExportRunProfileName);

            case MARunProfileType.DeltaSync:
                return(partition.DeltaSyncRunProfileName);

            case MARunProfileType.FullSync:
                return(partition.FullSyncRunProfileName);

            default:
            case MARunProfileType.None:
                throw new ArgumentException("Unknown run profile type");
            }
        }
        internal static void DoAutoRunProfileDiscovery(PartitionConfiguration config, ManagementAgent ma)
        {
            logger.Trace($"{ma.Name}: Performing run profile auto-discovery for partition {config.Name}");

            bool match = false;

            foreach (RunConfiguration profile in ma.RunProfiles.Values)
            {
                if (profile.RunSteps.Count == 0)
                {
                    continue;
                }

                if (profile.RunSteps.Count > 1)
                {
                    logger.Trace($"{ma.Name}: Ignoring multi-step run profile {profile.Name}");
                    continue;
                }

                if (profile.RunSteps.Any(t => t.IsTestRun))
                {
                    logger.Trace($"{ma.Name}: Ignoring test run profile {profile.Name}");
                    continue;
                }

                if (profile.RunSteps.Any(t => t.IsCombinedStep))
                {
                    logger.Trace($"{ma.Name}: Ignoring combined step profile {profile.Name}");
                    continue;
                }

                RunStep step = profile.RunSteps.First();

                if (step.ObjectLimit > 0)
                {
                    logger.Trace($"{ma.Name}: Ignoring limited step run profile {profile.Name}");
                    continue;
                }

                if (config.ID != step.Partition)
                {
                    logger.Trace($"{ma.Name}: Ignoring profile for other partition {profile.Name}");
                    continue;
                }

                switch (step.Type)
                {
                case RunStepType.Export:
                    config.ExportRunProfileName = profile.Name;
                    break;

                case RunStepType.FullImport:
                    config.FullImportRunProfileName = profile.Name;
                    break;

                case RunStepType.DeltaImport:
                    config.ScheduledImportRunProfileName = profile.Name;
                    config.DeltaImportRunProfileName     = profile.Name;
                    break;

                case RunStepType.DeltaSynchronization:
                    config.DeltaSyncRunProfileName = profile.Name;
                    break;

                case RunStepType.FullSynchronization:
                    config.FullSyncRunProfileName = profile.Name;
                    break;

                default:
                case RunStepType.Unknown:
                    continue;
                }

                logger.Trace($"{ma.Name}: Found {step.Type} profile {profile.Name}");
                match = true;
            }

            if (match)
            {
                if (!string.IsNullOrWhiteSpace(config.ScheduledImportRunProfileName))
                {
                    config.ConfirmingImportRunProfileName = config.ScheduledImportRunProfileName;
                }
                else
                {
                    config.ConfirmingImportRunProfileName = config.FullImportRunProfileName;
                    config.ScheduledImportRunProfileName  = config.FullImportRunProfileName;
                    config.DeltaImportRunProfileName      = config.FullImportRunProfileName;
                }
            }
        }
Esempio n. 6
0
        private bool DoSchemaUpdatev1(string file)
        {
            logger.Info("Configuration file upgrade in progress");

            XmlDocument d   = new XmlDocument();
            var         mgr = new XmlNamespaceManager(d.NameTable);

            mgr.AddNamespace("a", "http://schemas.datacontract.org/2004/07/Lithnet.Miiserver.AutoSync");
            d.Load(file);

            foreach (XmlNode node in d.SelectNodes("/a:lithnet-autosync/a:management-agents/a:management-agent", mgr))
            {
                string maName  = node.SelectSingleNode("a:name", mgr)?.InnerText;
                string maidstr = node.SelectSingleNode("a:id", mgr)?.InnerText;
                Guid   maID    = maidstr == null ? Guid.Empty : new Guid(maidstr);

                Guid?id = Global.FindManagementAgent(maName, maID);

                if (id == null)
                {
                    continue;
                }

                ManagementAgent ma = ManagementAgent.GetManagementAgent(id.Value);

                logger.Info($"Processing management agent controller {ma.Name}");

                MAControllerConfiguration c = this.ManagementAgents.GetItemOrDefault(id.Value);

                foreach (PartitionConfiguration p in c.Partitions.ActiveConfigurations)
                {
                    p.AutoImportEnabled         = node.SelectSingleNode("a:auto-import-scheduling", mgr)?.InnerText == "enabled";
                    p.AutoImportIntervalMinutes = int.Parse(node.SelectSingleNode("a:auto-import-interval", mgr)?.InnerText ?? "0");
                }

                string rpName = node.SelectSingleNode("a:run-profile-confirming-import", mgr)?.InnerText;
                Guid?  pid    = this.GetPartitionFromRunProfile(rpName, ma);

                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.ConfirmingImportRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.ConfirmingImportRunProfileName)}-{partition.ConfirmingImportRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-delta-import", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.DeltaImportRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.DeltaImportRunProfileName)}-{partition.DeltaImportRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-delta-sync", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.DeltaSyncRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.DeltaSyncRunProfileName)}-{partition.DeltaSyncRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-export", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.ExportRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.ExportRunProfileName)}-{partition.ExportRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-full-import", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.FullImportRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.FullImportRunProfileName)}-{partition.FullImportRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-full-sync", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.FullSyncRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.FullSyncRunProfileName)}-{partition.FullSyncRunProfileName} to partition {partition.Name}");
                    }
                }

                rpName = node.SelectSingleNode("a:run-profile-scheduled-import", mgr)?.InnerText;
                pid    = this.GetPartitionFromRunProfile(rpName, ma);
                if (pid != null)
                {
                    PartitionConfiguration partition = c.Partitions.GetItemOrNull(pid.Value);

                    if (partition != null)
                    {
                        partition.ScheduledImportRunProfileName = rpName;
                        logger.Trace($"Migrating run profile {nameof(partition.ScheduledImportRunProfileName)}-{partition.ScheduledImportRunProfileName} to partition {partition.Name}");
                    }
                }
            }

            this.SchemaVersion = 1;
            return(true);
        }