public void CollectionConfigurationAccumulatorPreparesMetricAccumulatorsTest()
        {
            // ARRANGE
            CollectionConfigurationError[] error;
            var metricInfo = new CalculatedMetricInfo()
            {
                Id            = "Metric1",
                TelemetryType = TelemetryType.Request,
                Projection    = "Name",
                Aggregation   = AggregationType.Min,
                FilterGroups  = new FilterConjunctionGroupInfo[0]
            };

            var collectionConfigurationInfo = new CollectionConfigurationInfo()
            {
                Metrics = new[] { metricInfo }
            };
            var collectionConfiguration = new CollectionConfiguration(collectionConfigurationInfo, out error, new ClockMock());

            // ACT
            var accumulator = new CollectionConfigurationAccumulator(collectionConfiguration);

            // ASSERT
            Assert.AreSame(collectionConfiguration, accumulator.CollectionConfiguration);
            Assert.AreEqual("Metric1", accumulator.MetricAccumulators.Single().Key);
        }
Example #2
0
            public static async Task <CollectionConfiguration> LoadConfig(string path)
            {
                if (!File.Exists(path))
                {
                    return(null);
                }

                string text;

                using (System.IO.StreamReader reader = new System.IO.StreamReader(path))
                {
                    text = await reader.ReadToEndAsync();
                }

                var root = XElement.Parse(text);

                var config = new CollectionConfiguration();

                config.MsBuildPath   = root.Element(nameof(config.MsBuildPath)).Value;
                config.RootDirectory = root.Element(nameof(config.RootDirectory)).Value;

                string collectionStringValue = root.Element(nameof(config.CollectionMethod)).Value;

                config.CollectionMethod = (CollectionMethod)Enum.Parse(typeof(CollectionMethod), collectionStringValue);

                return(config);
            }
Example #3
0
        public bool Initialize(DatabaseContext _dbContext, CollectionConfiguration config)
        {
            //eviction is always enabled for now and can not be turned off.
            _isEvictionEnabled = true;
            if (_parent.CollectionConfiguration.EvictionConfiguration != null)  //TODO this check is added if eviction configuration is not available at collection level in db.config
            {
                //_isEvictionEnabled = _parent.CollectionConfiguration.EvictionConfiguration.EnabledEviction;
                if (_parent.CollectionConfiguration.EvictionConfiguration.Policy.ToLower() == "lru")
                {
                    _evictionPolicy = new LRUEvictionPolicy(_parent.DbContext.StatsIdentity);
                }
            }
            else
            {
                _evictionPolicy = new LRUEvictionPolicy(_parent.DbContext.StatsIdentity);
            }

            _persistenceManager = _parent.DbContext.PersistenceManager;
            _persistenceManager.AddMetadataIndex(_parent.Name, _parent.MetadataIndex);

            _indexManager = new CollectionIndexManager(_dbContext, _dbContext.IndexPersistanceManager, this, config.CollectionName);
            if (!_indexManager.Initialize(config.Indices))
            {
                return(false);
            }
            //if (_statsCollector != null)
            //    _statsCollector.SetStatsValue(StatisticsType.PendingPersistentDocuments, _dirtyDocuments.Count);

            if (_persistenceManager == null)
            {
                return(false);
            }
            return(true);
        }
Example #4
0
 public CreateCollectionOperation()
 {
     _createCollectionCommand = new Alachisoft.NosDB.Common.Protobuf.CreateCollectionCommand.Builder();
     _collectionConfiguration = new CollectionConfiguration();
     _distribution            = null;
     base.Message             = this;
 }
Example #5
0
        private async Task <ICollectionFacade> FindOrCreateCollectionAsync(
            ICosmosAccountFacade cosmosFacade,
            CollectionConfiguration targetCollection)
        {
            var dbs = await cosmosFacade.GetDatabasesAsync();

            var db = dbs.Where(d => d.DatabaseName == targetCollection.Db).FirstOrDefault();

            if (db == null)
            {
                throw new CosbakException($"Can't find database {targetCollection.Db}");
            }
            else
            {
                var collections = await db.GetCollectionsAsync();

                var collection = collections
                                 .Where(c => c.CollectionName == targetCollection.Collection)
                                 .FirstOrDefault();

                if (collection == null)
                {
                    throw new CosbakException($"Can't find collection {targetCollection.Collection}");
                }
                else
                {
                    return(collection);
                }
            }
        }
Example #6
0
 public static async Task SaveConfigToFile(CollectionConfiguration config, string path)
 {
     using (System.IO.StreamWriter file = new System.IO.StreamWriter(path))
     {
         var text = WriteXml(config);
         await file.WriteLineAsync(text);
     }
 }
        public void CollectionConfigurationReportsPerformanceCountersWithDuplicateIds()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var filter1 = new FilterInfo()
            {
                FieldName = "Name", Predicate = Predicate.Equal, Comparand = "Request1"
            };
            var filter2 = new FilterInfo()
            {
                FieldName = "Name", Predicate = Predicate.Equal, Comparand = "Request1"
            };
            var metrics = new[]
            {
                new CalculatedMetricInfo()
                {
                    Id            = "PerformanceCounter1",
                    TelemetryType = TelemetryType.PerformanceCounter,
                    Projection    = @"\SomeObject\SomeCounter",
                    Aggregation   = AggregationType.Avg,
                    FilterGroups  = new[] { new FilterConjunctionGroupInfo()
                                            {
                                                Filters = new[] { filter1 }
                                            } }
                },
                new CalculatedMetricInfo()
                {
                    Id            = "PerformanceCounter1",
                    TelemetryType = TelemetryType.PerformanceCounter,
                    Projection    = @"\SomeObject(SomeInstance)\SomeCounter",
                    Aggregation   = AggregationType.Avg,
                    FilterGroups  = new[] { new FilterConjunctionGroupInfo()
                                            {
                                                Filters = new[] { filter2 }
                                            } }
                }
            };

            // ACT
            var collectionConfiguration = new CollectionConfiguration(
                new CollectionConfigurationInfo()
            {
                ETag = "ETag1", Metrics = metrics
            },
                out errors,
                new ClockMock());

            // ASSERT
            Assert.AreEqual("PerformanceCounter1", collectionConfiguration.PerformanceCounters.Single().Item1);
            Assert.AreEqual(@"\SomeObject\SomeCounter", collectionConfiguration.PerformanceCounters.Single().Item2);

            Assert.AreEqual(CollectionConfigurationErrorType.PerformanceCounterDuplicateIds, errors.Single().ErrorType);
            Assert.AreEqual("Duplicate performance counter id 'PerformanceCounter1'", errors.Single().Message);
            Assert.AreEqual(string.Empty, errors.Single().FullException);
            Assert.AreEqual(2, errors.Single().Data.Count);
            Assert.AreEqual("PerformanceCounter1", errors.Single().Data["MetricId"]);
            Assert.AreEqual("ETag1", errors.Single().Data["ETag"]);
        }
Example #8
0
        /// <summary>
        /// Initialize method is called after all configuration properties have been loaded from the configuration.
        /// </summary>
        /// <param name="configuration">TelemetryConfiguration passed to the module.</param>
        public void Initialize(TelemetryConfiguration configuration)
        {
            if (!this.IsInitialized)
            {
                lock (this.moduleInitializationLock)
                {
                    if (!this.IsInitialized)
                    {
                        QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent(
                            this.QuickPulseServiceEndpoint,
                            this.DisableFullTelemetryItems,
                            this.DisableTopCpuProcesses,
                            this.AuthenticationApiKey);

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration...");
                        ValidateConfiguration(configuration);
                        this.config = configuration;

                        QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members...");
                        this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager();

                        this.performanceCollector = this.performanceCollector ?? PerformanceCounterUtility.GetPerformanceCollector();

                        this.timeProvider    = this.timeProvider ?? new Clock();
                        this.topCpuCollector = this.topCpuCollector
                                               ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib()));
                        this.timings = this.timings ?? QuickPulseTimings.Default;

                        CollectionConfigurationError[] errors;
                        this.collectionConfiguration = new CollectionConfiguration(
                            new CollectionConfigurationInfo()
                        {
                            ETag = string.Empty
                        },
                            out errors,
                            this.timeProvider);
                        this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(this.collectionConfiguration);

                        this.InitializeServiceClient(configuration);

                        this.stateManager = new QuickPulseCollectionStateManager(
                            this.ServiceClient,
                            this.timeProvider,
                            this.timings,
                            this.OnStartCollection,
                            this.OnStopCollection,
                            this.OnSubmitSamples,
                            this.OnReturnFailedSamples,
                            this.OnUpdatedConfiguration,
                            this.OnUpdatedServiceEndpoint);

                        this.CreateStateThread();

                        this.IsInitialized = true;
                    }
                }
            }
        }
        public DocumentCollection(CollectionConfiguration configuration)
        {
            Configuration = configuration;

            //todo: передавать снаружи
            ConfigurationTyped = (configuration as CollectionConfigurationTyped <T>) ?? new CollectionConfigurationTyped <T>();
            _keyGetter         = ConfigurationTyped.KeyGetter;
            _keySetter         = ConfigurationTyped.KeySetter;
        }
Example #10
0
        public QuickPulseDataAccumulatorManager(CollectionConfiguration collectionConfiguration)
        {
            if (collectionConfiguration == null)
            {
                throw new ArgumentNullException(nameof(collectionConfiguration));
            }

            this.currentDataAccumulator = new QuickPulseDataAccumulator(collectionConfiguration);
        }
Example #11
0
            public static string WriteXml(CollectionConfiguration config)
            {
                var xmlConfig = new XElement("Config",
                                             new XElement(nameof(config.CollectionMethod), config.CollectionMethod.ToString()),
                                             new XElement(nameof(config.MsBuildPath), config.MsBuildPath),
                                             new XElement(nameof(config.RootDirectory), config.RootDirectory)
                                             );

                return(xmlConfig.ToString());
            }
        public bool CreateCollection(string cluster, string shard, string database, CollectionConfiguration configuration)
        {
            ManagementCommand command = GetManagementCommand(ConfigurationCommandUtil.MethodName.CreateCollection);

            command.Parameters.AddParameter(cluster);
            command.Parameters.AddParameter(shard.ToLower());
            command.Parameters.AddParameter(database);
            command.Parameters.AddParameter(configuration);
            return((bool)ExecuteCommandOnMgtServer(command, true));
        }
        public IActionResult UpdateConfiguration([FromBody] CollectionConfiguration newConfig)
        {
            if (_userProvider.IsCurrentUserInRole("Administrator") == false)
            {
                return(Forbid());
            }

            _configurationProvider.MaxCollectionsPerUser   = newConfig.MaxCollectionsPerUser;
            _configurationProvider.MaxElementsInCollection = newConfig.MaxElementsInCollection;
            return(Ok());
        }
Example #14
0
        public void When_DCSweepResistorParameter_Expect_Reference()
        {
            // Create the circuit
            var ckt = new Circuit(
                new VoltageSource("V1", "in", "0", 0),
                new Resistor("R1", "in", "out", 1.0e4),
                new Resistor("R2", "out", "0", 1.0e4)
                );

            // Do a DC sweep where one of the sweeps is a parameter
            var cconfig = new CollectionConfiguration()
            {
                CloneParameters = true
            };
            var dcSimulations = new List <DC>();
            var n             = 4;

            for (var i = 0; i < n; i++)
            {
                var dc = new DC("DC " + i);
                dc.Configurations.Add(cconfig);
                var config = dc.Configurations.Get <DCConfiguration>();
                config.Sweeps.Add(new SweepConfiguration("R2", 0.0, 1e4, 1e3)); // Sweep R2 from 0 to 10k per 1k
                config.Sweeps.Add(new SweepConfiguration("V1", 1, 5, 0.1));     // Sweep V1 from 1V to 5V per 100mV
                dc.OnParameterSearch += (sender, args) =>
                {
                    if (args.Name.Equals("R2"))
                    {
                        args.Result            = dc.EntityParameters["R2"].GetParameter <Parameter <double> >("resistance");
                        args.TemperatureNeeded = true;
                    }
                };
                dc.ExportSimulationData += (sender, args) =>
                {
                    var resistance = dc.Sweeps[0].CurrentValue;
                    var voltage    = dc.Sweeps[1].CurrentValue;
                    var expected   = voltage * resistance / (resistance + 1.0e4);
                    Assert.AreEqual(expected, args.GetVoltage("out"), 1e-12);
                };

                dcSimulations.Add(dc);
            }
            var maxConcurrentSimulations = 2;

            Parallel.ForEach(
                dcSimulations,
                new ParallelOptions()
            {
                MaxDegreeOfParallelism = maxConcurrentSimulations
            },
                (simulation) => simulation.Run(ckt));
        }
Example #15
0
        internal static CollectionConfiguration GetUserInformationCollection()
        {
            CollectionConfiguration collectionConfiguration = new CollectionConfiguration();

            collectionConfiguration.CollectionName = SystemCollection.UserInformationCollection;

            collectionConfiguration.Indices = new Indices();
            collectionConfiguration.EvictionConfiguration = new EvictionConfiguration();
            collectionConfiguration.EvictionConfiguration.EnabledEviction = true;
            collectionConfiguration.EvictionConfiguration.Policy          = "lru";

            return(collectionConfiguration);
        }
        private CollectionConfigurationError[] OnUpdatedConfiguration(CollectionConfigurationInfo configurationInfo)
        {
            // we need to preserve the current quota for each document stream that still exists in the new configuration
            CollectionConfigurationError[] errorsConfig;
            var newCollectionConfiguration = new CollectionConfiguration(configurationInfo, out errorsConfig, this.timeProvider, this.collectionConfiguration?.DocumentStreams);

            // the next accumulator that gets swapped in on the collection thread will be initialized with the new collection configuration
            Interlocked.Exchange(ref this.collectionConfiguration, newCollectionConfiguration);

            CollectionConfigurationError[] errorsPerformanceCounters;
            this.UpdatePerformanceCollector(newCollectionConfiguration.PerformanceCounters, out errorsPerformanceCounters);

            return(errorsConfig.Concat(errorsPerformanceCounters).ToArray());
        }
Example #17
0
 internal CollectionValueDetail(string databaseName, string nodeName, CollectionConfiguration configuration, string[] pathChunks)
 {
     _databaseName  = databaseName;
     NodeName       = nodeName;
     NodeType       = PathType.Collection;
     IsContainer    = true;
     IsValid        = true;
     Configuration  = configuration;
     PathChunks     = pathChunks;
     ChilderanTable = new PrintableTable();
     ChilderanName  = new List <string>();
     ChilderanTable.AddRow(ProviderUtil.INDICES);
     ChilderanName.Add(ProviderUtil.INDICES);
 }
        public void CollectionConfigurationReportsInvalidFilterForMetric()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var filterInfo = new FilterInfo()
            {
                FieldName = "NonExistentFieldName", Predicate = Predicate.Equal, Comparand = "Request"
            };
            var metrics = new[]
            {
                new CalculatedMetricInfo()
                {
                    Id            = "Metric1",
                    TelemetryType = TelemetryType.Request,
                    Projection    = "Name",
                    Aggregation   = AggregationType.Avg,
                    FilterGroups  = new[] { new FilterConjunctionGroupInfo()
                                            {
                                                Filters = new[] { filterInfo }
                                            } }
                }
            };

            // ACT
            var collectionConfiguration = new CollectionConfiguration(
                new CollectionConfigurationInfo()
            {
                Metrics = metrics
            },
                out errors,
                new ClockMock());

            // ASSERT
            Assert.AreEqual(1, collectionConfiguration.RequestMetrics.Count());
            Assert.AreEqual(1, collectionConfiguration.TelemetryMetadata.Count());

            Assert.AreEqual(CollectionConfigurationErrorType.FilterFailureToCreateUnexpected, errors.Single().ErrorType);
            Assert.AreEqual("Failed to create a filter NonExistentFieldName Equal Request.", errors.Single().Message);
            Assert.IsTrue(
                errors.Single()
                .FullException.Contains(
                    "Error finding property NonExistentFieldName in the type Microsoft.ApplicationInsights.DataContracts.RequestTelemetry"));
            Assert.AreEqual(5, errors.Single().Data.Count);
            Assert.AreEqual("Metric1", errors.Single().Data["MetricId"]);
            Assert.AreEqual(null, errors.Single().Data["ETag"]);
            Assert.AreEqual("NonExistentFieldName", errors.Single().Data["FilterFieldName"]);
            Assert.AreEqual(Predicate.Equal.ToString(), errors.Single().Data["FilterPredicate"]);
            Assert.AreEqual("Request", errors.Single().Data["FilterComparand"]);
        }
        public void CollectionConfigurationReportsInvalidFilterForDocumentStreams()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var documentStreamInfos = new[]
            {
                new DocumentStreamInfo()
                {
                    Id = "Stream1",
                    DocumentFilterGroups =
                        new[]
                    {
                        new DocumentFilterConjunctionGroupInfo()
                        {
                            TelemetryType = TelemetryType.Request,
                            Filters       = new FilterConjunctionGroupInfo()
                            {
                                Filters = new[] { new FilterInfo()
                                                  {
                                                      FieldName = "NonExistentFieldName"
                                                  } }
                            }
                        }
                    }
                }
            };

            var collectionConfigurationInfo = new CollectionConfigurationInfo()
            {
                DocumentStreams = documentStreamInfos, ETag = "ETag1"
            };

            // ACT
            var collectionConfiguration = new CollectionConfiguration(collectionConfigurationInfo, out errors, new ClockMock());

            // ASSERT
            Assert.AreEqual(1, collectionConfiguration.DocumentStreams.Count());

            Assert.AreEqual(CollectionConfigurationErrorType.FilterFailureToCreateUnexpected, errors.Single().ErrorType);
            Assert.AreEqual("Failed to create a filter NonExistentFieldName Equal .", errors.Single().Message);
            Assert.IsTrue(errors.Single().FullException.Contains("Comparand"));
            Assert.AreEqual(5, errors.Single().Data.Count);
            Assert.AreEqual("Stream1", errors.Single().Data["DocumentStreamId"]);
            Assert.AreEqual("ETag1", errors.Single().Data["ETag"]);
            Assert.AreEqual("NonExistentFieldName", errors.Single().Data["FilterFieldName"]);
            Assert.AreEqual(Predicate.Equal.ToString(), errors.Single().Data["FilterPredicate"]);
            Assert.AreEqual(null, errors.Single().Data["FilterComparand"]);
        }
        private async void CollectMetricsAsync(object sender, RoutedEventArgs e)
        {
            CollectionConfiguration config = new CollectionConfiguration();

            config.RootDirectory    = this.ViewModel.RootSearchDirectory;
            config.MsBuildPath      = this.ViewModel.MsBuildPath;
            config.CollectionMethod = this.ViewModel.CollectionMethod;

            await Parsing.Config.SaveConfigToFile(config, Parsing.Config.DefaultConfigFilename);

            var collector = new MetricsCollector.MetricsCollector(statusUpdater: value =>
            {
                this.ViewModel.ToolOutput += value;
            });

            await collector.Run(config);
        }
        public void CollectionConfigurationReportsInvalidMetric()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var filterInfo = new FilterInfo()
            {
                FieldName = "Name", Predicate = Predicate.Equal, Comparand = "Request"
            };
            var metrics = new[]
            {
                new CalculatedMetricInfo()
                {
                    Id            = "Metric1",
                    TelemetryType = TelemetryType.Request,
                    Projection    = "NonExistentFieldName",
                    Aggregation   = AggregationType.Avg,
                    FilterGroups  = new[] { new FilterConjunctionGroupInfo()
                                            {
                                                Filters = new[] { filterInfo }
                                            } }
                }
            };

            // ACT
            var collectionConfiguration = new CollectionConfiguration(
                new CollectionConfigurationInfo()
            {
                ETag = "ETag1", Metrics = metrics
            },
                out errors,
                new ClockMock());

            // ASSERT
            Assert.AreEqual(0, collectionConfiguration.RequestMetrics.Count());
            Assert.AreEqual(0, collectionConfiguration.TelemetryMetadata.Count());

            Assert.AreEqual(CollectionConfigurationErrorType.MetricFailureToCreate, errors.Single().ErrorType);
            Assert.AreEqual(
                "Failed to create metric Id: 'Metric1', TelemetryType: 'Request', Projection: 'NonExistentFieldName', Aggregation: 'Avg', FilterGroups: [Name Equal Request].",
                errors.Single().Message);
            Assert.IsTrue(errors.Single().FullException.Contains("Could not construct the projection"));
            Assert.AreEqual(2, errors.Single().Data.Count);
            Assert.AreEqual("Metric1", errors.Single().Data["MetricId"]);
            Assert.AreEqual("ETag1", errors.Single().Data["ETag"]);
        }
Example #22
0
        protected async override Task <CollectionConfiguration> GetCollectionConfigurationAsync()
        {
            if (_collectionConfiguration == null)
            {
                var tenant = await _tenantStore.FindTenantByIdAsync(_scopedTenantRequestContext.Context.TenantName);

                _collectionConfiguration = new CollectionConfiguration
                {
                    Collection = new Collection
                    {
                        CollectionName = tenant.Properties[Constants.Cosmos.OperationalContainerName],
                        ReserveUnits   = 400
                    },
                    DatabaseName = tenant.Properties[Constants.Cosmos.OperationalDatabaseName]
                };
            }
            return(_collectionConfiguration);
        }
Example #23
0
        public QuickPulseDataAccumulator CompleteCurrentDataAccumulator(CollectionConfiguration collectionConfiguration)
        {
            /*
             *  Here we need to
             *      - promote currentDataAccumulator to completedDataAccumulator
             *      - reset (zero out) the new currentDataAccumulator
             *
             *  Certain telemetry items will be "sprayed" between two neighboring accumulators due to the fact that the snap might occur in the middle of a reader executing its Interlocked's.
             */

            this.completedDataAccumulator = Interlocked.Exchange(ref this.currentDataAccumulator, new QuickPulseDataAccumulator(collectionConfiguration));

            var timestamp = DateTimeOffset.UtcNow;

            this.completedDataAccumulator.EndTimestamp = timestamp;
            this.currentDataAccumulator.StartTimestamp = timestamp;

            return(this.completedDataAccumulator);
        }
        public void CollectionConfigurationReportsInvalidFilterGroupForDocumentStreams()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            var documentStreamInfos = new[]
            {
                new DocumentStreamInfo()
                {
                    Id = "Stream1",
                    DocumentFilterGroups =
                        new[]
                    {
                        new DocumentFilterConjunctionGroupInfo()
                        {
                            TelemetryType = (TelemetryType)505,
                            Filters       = new FilterConjunctionGroupInfo()
                            {
                                Filters = new FilterInfo[0]
                            }
                        }
                    }
                }
            };

            var collectionConfigurationInfo = new CollectionConfigurationInfo()
            {
                DocumentStreams = documentStreamInfos, ETag = "ETag1"
            };

            // ACT
            var collectionConfiguration = new CollectionConfiguration(collectionConfigurationInfo, out errors, new ClockMock());

            // ASSERT
            Assert.AreEqual(1, collectionConfiguration.DocumentStreams.Count());

            Assert.AreEqual(CollectionConfigurationErrorType.DocumentStreamFailureToCreateFilterUnexpected, errors.Single().ErrorType);
            Assert.AreEqual("Failed to create a document stream filter TelemetryType: '505', filters: ''.", errors.Single().Message);
            Assert.IsTrue(errors.Single().FullException.Contains("Unsupported TelemetryType: '505'"));
            Assert.AreEqual(2, errors.Single().Data.Count);
            Assert.AreEqual("Stream1", errors.Single().Data["DocumentStreamId"]);
            Assert.AreEqual("ETag1", errors.Single().Data["ETag"]);
        }
Example #25
0
        private static CollectionConfiguration GetQueryCollectionConfig(string shardName)
        {
            var queryConfig = new CollectionConfiguration
            {
                CollectionName       = SystemCollection.QueryResultCollection,
                Shard                = shardName,
                DistributionStrategy = new DistributionStrategyConfiguration
                {
                    Name = DistributionType.NonSharded.ToString(),
                },
                EvictionConfiguration = new EvictionConfiguration
                {
                    EnabledEviction = true,
                    Policy          = "lru"
                },
                Indices = new Indices(),
            };

            return(queryConfig);
        }
Example #26
0
        public static CollectionConfiguration GetConfigCollectionConfig(string shardName)
        {
            var configCol = new CollectionConfiguration
            {
                CollectionName       = SystemCollection.ConfigCollection,
                Shard                = shardName,
                DistributionStrategy = new DistributionStrategyConfiguration
                {
                    Name = DistributionType.NonSharded.ToString(),
                },
                EvictionConfiguration = new EvictionConfiguration
                {
                    EnabledEviction = true,
                    Policy          = "lru"
                },
                Indices = new Indices(),
            };

            return(configCol);
        }
Example #27
0
        public override bool TryGetNodeDetail(out NodeDetail nodeDetail)
        {
            NodeDetail thisNode = new EndNodeDetail();
            bool       sucess   = false;

            if (((CollectionConfigurations)Configuration).ContainsCollection(PathChunks[0].ToLower()))
            {
                string[] childPathChunks = new string[PathChunks.Length - 1];
                Array.Copy(PathChunks, 1, childPathChunks, 0, PathChunks.Length - 1);
                CollectionConfiguration cConfig = ((CollectionConfigurations)Configuration).GetCollection(PathChunks[0].ToLower());
                thisNode = new CollectionValueDetail(_databaseName, PathChunks[0], cConfig, childPathChunks);
                sucess   = true;
            }

            if (PathChunks.Length == 1)
            {
                nodeDetail = thisNode;
                return(sucess);
            }
            return(thisNode.TryGetNodeDetail(out nodeDetail));
        }
Example #28
0
        public static ISerializer DefaultResolveSerializer(CollectionConfiguration collectionConfiguration)
        {
            bool IsGoodFormat(string fmt) => !string.IsNullOrEmpty(fmt);

            var format = collectionConfiguration.Format;

            if (!IsGoodFormat(format) && collectionConfiguration.SourceFile != null)
            {
                format = Path.GetExtension(collectionConfiguration.SourceFile);
            }


            if (format == "json")
            {
                return(new JsonSerializer());
            }

            if (format == "csv")
            {
                return(new SimpleCsvSerializer());
            }

            return(GetDefaultSerializer());
        }
Example #29
0
        protected override bool CreateCollectionInternal(CollectionConfiguration configuration, NodeContext nodeContext, bool isNew)
        {
            if (_collections.ContainsKey(configuration.CollectionName))
            {
                return(false);
            }
            lock (Collections)
            {
                ICollectionStore collection;

                collection           = new BaseCollection(_dbContext, nodeContext);
                collection.ShardName = _nodeContext.LocalShardName;
                bool success = collection.Initialize(configuration, _queryResultManager, this, null);
                if (success)
                {
                    //    // set status running incase of internal collections
                    //   collection.Status.SetStatusBit(CollectionStatus.RUNNING, CollectionStatus.INITIALIZING);
                    _collections[collection.Name] = collection;
                    //    if (configuration.CollectionType.Equals(CollectionType.CappedCollection.ToString()))
                    //        ((CappedCollection) collection).PopulateData();
                }
                return(success);
            }

            /*if (_collections.ContainsKey(configuration.CollectionName))
             *  return false;
             * if (_dbContext.StorageManager.CreateCollection(configuration.CollectionName))
             * {
             *  ICollectionStore collection = new BaseCollection(_dbContext, nodeContext);
             *  bool success = collection.Initialize(configuration, _queryResultManager, this);
             *  if (success)
             *      _collections[collection.Name] = collection;
             *  return success;
             * }
             * return false;*/
        }
Example #30
0
        public void QuickPulseDataAccumulatorManagerLocksInSampleCorrectly()
        {
            // ARRANGE
            CollectionConfigurationError[] errors;
            CollectionConfiguration        collectionConfiguration =
                new CollectionConfiguration(
                    new CollectionConfigurationInfo()
            {
                ETag = string.Empty, Metrics = new CalculatedMetricInfo[0]
            },
                    out errors,
                    new ClockMock());
            var accumulatorManager = new QuickPulseDataAccumulatorManager(collectionConfiguration);

            accumulatorManager.CurrentDataAccumulator.AIRequestSuccessCount = 5;

            // ACT
            var completedSample = accumulatorManager.CompleteCurrentDataAccumulator(collectionConfiguration);

            // ASSERT
            Assert.AreEqual(5, completedSample.AIRequestSuccessCount);
            Assert.AreEqual(0, accumulatorManager.CurrentDataAccumulator.AIRequestSuccessCount);
            Assert.AreNotSame(completedSample, accumulatorManager.CurrentDataAccumulator);
        }