/// <summary>
        /// 开始执行处理
        /// </summary>
        /// <param name="setting"></param>
        public async Task StartByPS(CancellationTokenSource _source)
        {
            if (BeforeTaskStart.Invoke(this))
            {
                source = _source;
                var poltCommend = $"{chiaSetting.setupPath} plots create -k {poltConfig.stripeSize} -b {poltConfig.memorySize} -t {poltConfig.tempPath} -d {poltConfig.finalPath} -f {chiaSetting.farmerPublicKey} -p {chiaSetting.poolPublicKey}";
                if (poltConfig.isBitfieldPlotting)
                {
                    poltCommend = poltCommend + " -e";
                }
                if (poltConfig.stripeSize < 32)
                {
                    poltCommend = poltCommend + " --override-k";
                }
                using (var helper = new PowershellHelper(LogerHelper.loggerFactory).WithOptions(o => { o.CleanupMethod = CleanupType.Recursive; }))
                {
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    this.currentStartTime = DateTime.Now;
                    helper.AddCommand(poltCommend);
                    this.status = TaskStatusEnum.Runing;
                    ChiaPoltTaskFactory.CallStatusChangeEvent(this);
                    LogerHelper.logger.Info($"任务编号【{this.id}】指令开始执行Powershell指令【{poltCommend}】!!");
                    var result = await Task.Run(() => helper.RunAsync(source.Token));

                    this.status = TaskStatusEnum.Wait;
                    if (result == PowershellStatus.Exited)
                    {
                        stopwatch.Stop();
                        var useTime = TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds);
                        this.lastUseTime = useTime.TotalHours.ToString("0.00");
                        this.completeNumber++;
                        LogerHelper.logger.Info($"任务编号【{this.id}】指令执行完成!");
                    }
                    else
                    {
                        LogerHelper.logger.Error($"任务编号【{this.id}】指令异常终止退出码【{helper.ExitCode}】");
                    }
                    helper.WaitOnCleanup();
                }
                ChiaPoltTaskFactory.CallStatusChangeEvent(this);
                if (poltConfig.isKeepWorking && !source.IsCancellationRequested)
                {
                    await StartByPS(source);
                }
                else
                {
                    this.status = TaskStatusEnum.Stop;
                    ChiaPoltTaskFactory.CallStatusChangeEvent(this);
                }
            }
            else
            {
                this.status = TaskStatusEnum.Stop;
                ChiaPoltTaskFactory.CallStatusChangeEvent(this);
            }
        }
Beispiel #2
0
    public static FirewallPort OpenWinPort(int port, ITestOutputHelper output)
    {
        string ruleName  = $"TraceAgent-{port}";
        string psCommand = $"New-NetFirewallRule -DisplayName '{ruleName}' -Direction Inbound -LocalPort {port} -Protocol TCP -Action Allow -Profile Any";

        PowershellHelper.RunCommand(psCommand, output);

        return(new FirewallPort(port, ruleName, output));
    }
    public async Task <Container> StartContainerAsync(int traceAgentPort, int webPort)
    {
        // get path to test application that the profiler will attach to
        string testApplicationName = $"testapplication-{EnvironmentHelper.TestApplicationName.ToLowerInvariant()}";

        string agentBaseUrl    = $"http://{DockerNetworkHelper.IntegrationTestsGateway}:{traceAgentPort}";
        string agentHealthzUrl = $"{agentBaseUrl}/healthz";
        string zipkinEndpoint  = $"{agentBaseUrl}/api/v2/spans";
        string networkName     = DockerNetworkHelper.IntegrationTestsNetworkName;
        string networkId       = DockerNetworkHelper.SetupIntegrationTestsNetwork();

        Output.WriteLine($"Zipkin Endpoint: {zipkinEndpoint}");

        string logPath = EnvironmentHelper.IsRunningOnCI()
            ? Path.Combine(Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"), "build_data", "profiler-logs")
            : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"OpenTelemetry .NET AutoInstrumentation", "logs");

        Directory.CreateDirectory(logPath);

        Output.WriteLine("Collecting docker logs to: " + logPath);

        var builder = new TestcontainersBuilder <TestcontainersContainer>()
                      .WithImage(testApplicationName)
                      .WithCleanUp(cleanUp: true)
                      .WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole())
                      .WithName($"{testApplicationName}-{traceAgentPort}-{webPort}")
                      .WithNetwork(networkId, networkName)
                      .WithPortBinding(webPort, 80)
                      .WithEnvironment("OTEL_EXPORTER_ZIPKIN_ENDPOINT", zipkinEndpoint)
                      .WithBindMount(logPath, "c:/inetpub/wwwroot/logs")
                      .WithBindMount(EnvironmentHelper.GetNukeBuildOutput(), "c:/opentelemetry");

        var container  = builder.Build();
        var wasStarted = container.StartAsync().Wait(TimeSpan.FromMinutes(5));

        wasStarted.Should().BeTrue($"Container based on {testApplicationName} has to be operational for the test.");

        Output.WriteLine($"Container was started successfully.");

        PowershellHelper.RunCommand($"docker exec {container.Name} curl -v {agentHealthzUrl}", Output);

        var webAppHealthzUrl    = $"http://localhost:{webPort}/healthz";
        var webAppHealthzResult = await HealthzHelper.TestHealtzAsync(webAppHealthzUrl, "IIS WebApp", Output);

        webAppHealthzResult.Should().BeTrue("IIS WebApp health check never returned OK.");

        Output.WriteLine($"IIS WebApp was started successfully.");

        return(new Container(container));
    }
Beispiel #4
0
    public static void CloseWinPort(string ruleName, ITestOutputHelper output)
    {
        string psCommand = $"Remove-NetFirewallRule -DisplayName {ruleName}";

        PowershellHelper.RunCommand(psCommand, output);
    }