Exemplo n.º 1
0
        /// <summary>
        /// Creates a new Influx DB Continuous Query.
        /// </summary>
        /// <param name="cqParams">The parameters used to create the CQ.</param>
        /// <returns>The API response.</returns>
        public async override Task<InfluxDbApiResponse> CreateContinuousQueryAsync(InfluxDbCqParams cqParams)
        {
            if (cqParams == null) throw new ArgumentNullException("cqParams");

            // Validate
            if (string.IsNullOrWhiteSpace(cqParams.Name)) throw new ArgumentNullException("cqParams.Name");
            if (string.IsNullOrWhiteSpace(cqParams.Database)) throw new ArgumentNullException("cqParams.Database");
            if (string.IsNullOrWhiteSpace(cqParams.Destination)) throw new ArgumentNullException("cqParams.Destination");
            if (string.IsNullOrWhiteSpace(cqParams.Source)) throw new ArgumentNullException("cqParams.Source");
            if (string.IsNullOrWhiteSpace(cqParams.Interval)) throw new ArgumentNullException("cqParams.Interval");

            if (cqParams.SubQueries == null || cqParams.SubQueries.Count() == 0 || string.IsNullOrWhiteSpace(cqParams.SubQueries.First()))
                throw new ArgumentException("cqParams.SubQueries needs at least one query.");

            if (!InfluxDbHelper.IsTimeIntervalValid(cqParams.Interval))
                throw new ArgumentException("cqParams.Interval is invalid: " + cqParams.Interval);

            if (!string.IsNullOrWhiteSpace(cqParams.ResampleEveryInterval) 
                && !InfluxDbHelper.IsTimeIntervalValid(cqParams.ResampleEveryInterval))
            {
                throw new ArgumentException("cqParams.ResampleEveryInterval is invalid: " + cqParams.ResampleEveryInterval);
            }

            if (!string.IsNullOrWhiteSpace(cqParams.ResampleForInterval)
                && !InfluxDbHelper.IsTimeIntervalValid(cqParams.ResampleForInterval))
            {
                throw new ArgumentException("cqParams.ResampleForInterval is invalid: " + cqParams.ResampleForInterval);
            }

            // Copy values to InfluxData.Net equivalent
            var _cqParams = new CqParams()
            {
                CqName = cqParams.Name,
                DbName = cqParams.Database,
                DsSerieName = cqParams.Destination,
                SourceSerieName = cqParams.Source,
                Downsamplers = cqParams.SubQueries.ToList(),
                Interval = cqParams.Interval,
                FillType = (FillType)Enum.Parse(typeof(FillType), cqParams.FillType.ToString(), true),
                Tags = cqParams.Tags != null ? cqParams.Tags.ToList() : null,
            };

            // Add resample values if they exist
            if (!string.IsNullOrWhiteSpace(cqParams.ResampleEveryInterval)
                || !string.IsNullOrWhiteSpace(cqParams.ResampleForInterval))
            {
                _cqParams.Resample = new CqResampleParam()
                {
                    Every = cqParams.ResampleEveryInterval,
                    For = cqParams.ResampleForInterval
                };
            }

            // Execute the request and return response
            var response = await influx.ContinuousQuery.CreateContinuousQueryAsync(_cqParams).ConfigureAwait(false);
            return new InfluxDbApiResponse(response.Body, response.StatusCode, response.Success);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new Influx DB Continuous Query.
 /// </summary>
 /// <param name="cqParams">The parameters used to create the CQ.</param>
 /// <returns>The API response.</returns>
 public abstract Task <InfluxDbApiResponse> CreateContinuousQueryAsync(InfluxDbCqParams cqParams);