Exemplo n.º 1
0
        public EndpointJob(IServiceProvider provider, Model.Endpoint endpoint)
        {
            _provider = provider;
            _endpoint = endpoint;

            ConfigureJob();
        }
Exemplo n.º 2
0
        public void PublishHealthReport(Model.Endpoint endpoint, HealthReport report)
        {
            if (!endpoint.PublishStats)
            {
                return;
            }

            var gauge1 = Metrics.CreateGauge($"epmon_healthcheck", "Shows health check status (0 = Unhealthy, 1 = Healthy)", new GaugeConfiguration
            {
                SuppressInitialValue = true,
                LabelNames           = GetLabelNames()
            });

            gauge1.WithLabels(GetLabelValues(endpoint)).Set(Convert.ToDouble(report.IsHealthy));

            var gauge2 = Metrics.CreateGauge($"epmon_healthcheck_duration", "Shows duration of the health check execution in miliseconds", new GaugeConfiguration
            {
                SuppressInitialValue = true,
                LabelNames           = GetLabelNames()
            });

            gauge2.WithLabels(GetLabelValues(endpoint)).Set(report.ResponseTime);
        }
Exemplo n.º 3
0
        private void CreateSingle(Model.Endpoint endpoint, EndpointCreatorSettings settings)
        {
            DirectoryPath targetRootPath = new DirectoryPath(settings?.TargetRootPath ?? "./").MakeAbsolute(environment);

            string targetEndpointPathName = endpoint.Id + settings?.TargetPathPostFix;

            DirectoryPath targetEndpointPath = targetRootPath.Combine(targetEndpointPathName);

            if (endpoint.Files != null)
            {
                foreach (File file in endpoint.Files)
                {
                    string fileSourcePath = file.SourcePath;
                    if (!string.IsNullOrWhiteSpace(settings?.BuildConfiguration))
                    {
                        fileSourcePath = fileSourcePath.Replace("[BuildConfiguration]", settings.BuildConfiguration);
                    }

                    if (file.IsFilePath)
                    {
                        FilePath targetPath = targetEndpointPath.CombineWithFilePath(file.TargetPath);
                        context.EnsureDirectoryExists(targetPath.GetDirectory());
                        context.CopyFile(file.SourcePath, targetPath);
                    }
                    else
                    {
                        DirectoryPath targetPath = targetEndpointPath.Combine(file.TargetPath);
                        context.EnsureDirectoryExists(targetPath);
                        context.CopyFileToDirectory(fileSourcePath, targetPath);
                    }
                }
            }

            if (endpoint.Directories != null)
            {
                foreach (Directory directory in endpoint.Directories)
                {
                    DirectoryPath targetDirectoryPath = targetEndpointPath.Combine(directory.TargetPath);
                    context.EnsureDirectoryExists(targetDirectoryPath);

                    string directorySourcePath = directory.SourcePath;
                    if (!string.IsNullOrWhiteSpace(settings?.BuildConfiguration))
                    {
                        directorySourcePath = directorySourcePath.Replace("[BuildConfiguration]", settings.BuildConfiguration);
                    }

                    if (context.DirectoryExists(directorySourcePath))
                    {
                        context.CopyDirectory(directorySourcePath, targetDirectoryPath);
                    }
                    else
                    {
                        log.Warning($"Skipped copying {directorySourcePath} because it does not exist.");
                    }
                }
            }

            log.Information($"Created endpoint at {targetEndpointPath.FullPath}");

            if (settings != null && settings.ZipTargetPath)
            {
                FilePath zipFilePath = targetRootPath.CombineWithFilePath(new FilePath(targetEndpointPathName + ".zip"));
                new Zipper(fileSystem, environment, log).Zip(targetEndpointPath,
                                                             zipFilePath,
                                                             context.GetFiles(string.Concat(targetEndpointPath, "/**/*")));

                log.Information($"Zipped endpoint at {zipFilePath.FullPath}");
            }
        }