Beispiel #1
0
        private static AdxDbTestHelper CreateSingleton()
        {
            var dbPrefix               = Environment.GetEnvironmentVariable("deltaKustoDbPrefix");
            var clusterUri             = Environment.GetEnvironmentVariable("deltaKustoClusterUri");
            var tenantId               = Environment.GetEnvironmentVariable("deltaKustoTenantId");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("deltaKustoSpId");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("deltaKustoSpSecret");

            if (string.IsNullOrWhiteSpace(tenantId))
            {
                throw new ArgumentNullException(nameof(tenantId));
            }
            if (string.IsNullOrWhiteSpace(servicePrincipalId))
            {
                throw new ArgumentNullException(nameof(servicePrincipalId));
            }
            if (string.IsNullOrWhiteSpace(servicePrincipalSecret))
            {
                throw new ArgumentNullException(nameof(servicePrincipalSecret));
            }
            if (string.IsNullOrWhiteSpace(clusterUri))
            {
                throw new ArgumentNullException(nameof(clusterUri));
            }
            if (string.IsNullOrWhiteSpace(dbPrefix))
            {
                throw new ArgumentNullException(nameof(dbPrefix));
            }

            var tracer                = new ConsoleTracer(false);
            var httpClientFactory     = new SimpleHttpClientFactory(tracer);
            var tokenParameterization = new TokenProviderParameterization
            {
                Login = new ServicePrincipalLoginParameterization
                {
                    TenantId = tenantId,
                    ClientId = servicePrincipalId,
                    Secret   = servicePrincipalSecret
                }
            };
            var kustoGatewayFactory = new KustoManagementGatewayFactory(tokenParameterization, tracer);
            var helper = new AdxDbTestHelper(
                dbPrefix,
                db => kustoGatewayFactory.CreateGateway(new Uri(clusterUri), db));

            return(helper);
        }
Beispiel #2
0
        protected AdxIntegrationTestBase(bool overrideLoginTokenProvider = true)
        {
            var clusterUri             = Environment.GetEnvironmentVariable("deltaKustoClusterUri");
            var tenantId               = Environment.GetEnvironmentVariable("deltaKustoTenantId");
            var servicePrincipalId     = Environment.GetEnvironmentVariable("deltaKustoSpId");
            var servicePrincipalSecret = Environment.GetEnvironmentVariable("deltaKustoSpSecret");

            if (string.IsNullOrWhiteSpace(clusterUri))
            {
                throw new ArgumentNullException(nameof(clusterUri));
            }
            if (string.IsNullOrWhiteSpace(tenantId))
            {
                throw new ArgumentNullException(nameof(tenantId));
            }
            if (string.IsNullOrWhiteSpace(servicePrincipalId))
            {
                throw new ArgumentNullException(nameof(servicePrincipalId));
            }
            if (string.IsNullOrWhiteSpace(servicePrincipalSecret))
            {
                throw new ArgumentNullException(nameof(servicePrincipalSecret));
            }

            _overrideLoginTokenProvider = overrideLoginTokenProvider;
            ClusterUri             = new Uri(clusterUri);
            TenantId               = tenantId;
            ServicePrincipalId     = servicePrincipalId;
            ServicePrincipalSecret = servicePrincipalSecret;
            KustoGatewayFactory    = new KustoManagementGatewayFactory(
                new TokenProviderParameterization
            {
                Login = new ServicePrincipalLoginParameterization
                {
                    TenantId = TenantId,
                    ClientId = ServicePrincipalId,
                    Secret   = ServicePrincipalSecret
                }
            },
                Tracer);
        }
        public async Task <bool> ComputeDeltaAsync(
            string parameterFilePath,
            IEnumerable <string> pathOverrides)
        {
            _tracer.WriteLine(false, "Activating Client...");

            var availableClientVersions = await _apiClient.ActivateAsync();

            if (availableClientVersions == null)
            {
                _tracer.WriteLine(false, "Activating Client (skipped)");
            }
            else
            {
                _tracer.WriteLine(false, "Client Activated");
                if (availableClientVersions.Any())
                {
                    _tracer.WriteLine(
                        false,
                        "Newer clients available:  "
                        + string.Join(", ", availableClientVersions));
                }
            }

            _tracer.WriteLine(false, $"Loading parameters at '{parameterFilePath}'");

            var parameters =
                await LoadParameterizationAsync(parameterFilePath, pathOverrides);

            var parameterTelemetryTask = _apiClient.LogParameterTelemetryAsync(parameters);
            var parameterFolderPath    = Path.GetDirectoryName(parameterFilePath);

            try
            {
                var localFileGateway = _fileGateway.ChangeFolder(parameterFolderPath !);
                var kustoManagementGatewayFactory = new KustoManagementGatewayFactory(
                    parameters.TokenProvider,
                    _tracer);
                var orderedJobs = parameters.Jobs.OrderBy(p => p.Value.Priority);
                var success     = true;

                _tracer.WriteLine(false, $"{orderedJobs.Count()} jobs");
                foreach (var jobPair in orderedJobs)
                {
                    var(jobName, job) = jobPair;
                    var jobSuccess = await ProcessJobAsync(
                        parameters,
                        kustoManagementGatewayFactory,
                        localFileGateway,
                        jobName,
                        job);

                    success = success && jobSuccess;
                }

                await _apiClient.EndSessionAsync(success);

                return(success);
            }
            catch (Exception ex)
            {
                if (parameters.SendErrorOptIn)
                {
                    var sessionID = await _apiClient.RegisterExceptionAsync(ex);

                    _tracer.WriteLine(
                        false,
                        $"Exception registered with Session ID '{sessionID}'");
                }
                throw;
            }
            finally
            {
                await parameterTelemetryTask;
            }
        }