Skip to content
Snippets Groups Projects
Commit 49bd31bd authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

WIP

parent fb3f45e3
No related branches found
No related tags found
1 merge request!1New: KPI Generator Base Implementation
Pipeline #792565 passed
Showing
with 234 additions and 150 deletions
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.ApplicationProfile;
public class ApplicationProfileReporting : Kpi<ReturnObject, ApplicationProfileKpiOptions>
public class ApplicationProfileReporting : Reporting<ApplicationProfileReportingOptions>
{
public ApplicationProfileReporting(ApplicationProfileKpiOptions options) : base(options)
public ApplicationProfileReporting(ApplicationProfileReportingOptions options) : base(options)
{}
public override bool Run()
{
throw new NotImplementedException();
}
protected override ReturnObject GenerateReporting()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
......
......
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("applprofiles", HelpText = "Generate application profile KPIs")]
public class ApplicationProfileReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.KPIs.ApplicationProfile;
using KPIGenerator.KPIs.Project;
using KPIGenerator.KPIs.Resource;
using KPIGenerator.KPIs.System;
using KPIGenerator.KPIs.User;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.Complete;
public class CompleteReporting : Kpi<ReturnObject, CompleteKpiOptions>
public class CompleteReporting : Reporting<CompleteReportingOptions>
{
public CompleteReporting(CompleteKpiOptions options) : base(options)
public CompleteReporting(CompleteReportingOptions options) : base(options)
{}
public override bool Run()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
var result = new List<ReportingFileObject>();
// Project Reporting
result.AddRange(new ProjectReporting(new ProjectReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
// Resource Reporting
result.AddRange(new ResourceReporting(new ResourceReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
protected override ReturnObject GenerateReporting()
// User Reporting
result.AddRange(new UserReporting(new UserReportingOptions
{
throw new NotImplementedException();
DummyMode = Options.DummyMode
}).GenerateReporting());
// Application Profile Reporting
result.AddRange(new ApplicationProfileReporting(new ApplicationProfileReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
// System Status Reporting
result.AddRange(new SystemReporting(new SystemReportingOptions
{
DummyMode = Options.DummyMode
}).GenerateReporting());
return result;
}
}
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("all", HelpText = "Generate all KPIs")]
public class CompleteReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.Project;
public class ProjectReporting : Kpi<ReturnObject, ProjectKpiOptions>
public class ProjectReporting : Reporting<ProjectReportingOptions>
{
public ProjectReporting(ProjectKpiOptions options) : base(options)
public ProjectReporting(ProjectReportingOptions options) : base(options)
{}
public override bool Run()
{
throw new NotImplementedException();
}
protected override ReturnObject GenerateReporting()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
......
......
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("projects", HelpText = "Generate project KPIs")]
public class ProjectReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.Resource;
public class ResourceReporting : Kpi<ReturnObject, ResourceKpiOptions>
public class ResourceReporting : Reporting<ResourceReportingOptions>
{
public ResourceReporting(ResourceKpiOptions options) : base(options)
public ResourceReporting(ResourceReportingOptions options) : base(options)
{}
public override bool Run()
{
throw new NotImplementedException();
}
protected override ReturnObject GenerateReporting()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
......
......
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("resources", HelpText = "Generate resource KPIs")]
public class ResourceReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.System;
public class SystemReporting : Kpi<ReturnObject, SystemKpiOptions>
public class SystemReporting : Reporting<SystemReportingOptions>
{
public SystemReporting(SystemKpiOptions options) : base(options)
public SystemReporting(SystemReportingOptions options) : base(options)
{}
public override bool Run()
{
throw new NotImplementedException();
}
protected override ReturnObject GenerateReporting()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
......
......
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("system", HelpText = "Generate system status KPIs")]
public class SystemReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using static KPIGenerator.Utils.CommandLineOptions;
using KPIGenerator.Utils;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.KPIs.User;
public class UserReporting : Kpi<ReturnObject, UserKpiOptions>
public class UserReporting : Reporting<UserReportingOptions>
{
public UserReporting(UserKpiOptions options) : base(options)
public UserReporting(UserReportingOptions options) : base(options)
{}
public override bool Run()
{
throw new NotImplementedException();
}
protected override ReturnObject GenerateReporting()
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
throw new NotImplementedException();
}
......
......
using CommandLine;
namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("users", HelpText = "Generate user KPIs")]
public class UserReportingOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
using CommandLine;
using Coscine.Configuration;
using GitLabApiClient;
using KPIGenerator.KPIs.ApplicationProfile;
using KPIGenerator.KPIs.Complete;
using KPIGenerator.KPIs.Project;
......@@ -18,20 +16,20 @@ public static class Program
try
{
bool result = Parser.Default.ParseArguments<
CompleteKpiOptions,
ProjectKpiOptions,
ResourceKpiOptions,
UserKpiOptions,
ApplicationProfileKpiOptions,
SystemKpiOptions
CompleteReportingOptions,
ProjectReportingOptions,
ResourceReportingOptions,
UserReportingOptions,
ApplicationProfileReportingOptions,
SystemReportingOptions
>(args)
.MapResult(
(CompleteKpiOptions options) => new CompleteReporting(SanitizeOptions(options)).Run(),
(ProjectKpiOptions options) => new ProjectReporting(SanitizeOptions(options)).Run(),
(ResourceKpiOptions options) => new ResourceReporting(SanitizeOptions(options)).Run(),
(UserKpiOptions options) => new UserReporting(SanitizeOptions(options)).Run(),
(ApplicationProfileKpiOptions options) => new ApplicationProfileReporting(SanitizeOptions(options)).Run(),
(SystemKpiOptions options) => new SystemReporting(SanitizeOptions(options)).Run(),
(CompleteReportingOptions options) => new CompleteReporting(SanitizeOptions(options)).Run(),
(ProjectReportingOptions options) => new ProjectReporting(SanitizeOptions(options)).Run(),
(ResourceReportingOptions options) => new ResourceReporting(SanitizeOptions(options)).Run(),
(UserReportingOptions options) => new UserReporting(SanitizeOptions(options)).Run(),
(ApplicationProfileReportingOptions options) => new ApplicationProfileReporting(SanitizeOptions(options)).Run(),
(SystemReportingOptions options) => new SystemReporting(SanitizeOptions(options)).Run(),
_ => false);
if (result)
{
......@@ -54,43 +52,64 @@ public static class Program
public static TResult SanitizeOptions<TResult>(TResult unsanitizedOptions)
{
// Sanitize all input that accepts an array or is a list of inputs.
if (unsanitizedOptions is not null)
{
var type = unsanitizedOptions.GetType();
if (type == typeof(CompleteKpiOptions))
if (type == typeof(CompleteReportingOptions))
{
var options = unsanitizedOptions as CompleteReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as CompleteKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
else if (type == typeof(ProjectKpiOptions))
}
else if (type == typeof(ProjectReportingOptions))
{
var options = unsanitizedOptions as ProjectReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as ProjectKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
else if (type == typeof(ResourceKpiOptions))
}
else if (type == typeof(ResourceReportingOptions))
{
var options = unsanitizedOptions as ResourceReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as ResourceKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
else if (type == typeof(UserKpiOptions))
}
else if (type == typeof(UserReportingOptions))
{
var options = unsanitizedOptions as UserReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as UserKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
else if (type == typeof(ApplicationProfileKpiOptions))
}
else if (type == typeof(ApplicationProfileReportingOptions))
{
var options = unsanitizedOptions as ApplicationProfileReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as ApplicationProfileKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
else if (type == typeof(SystemKpiOptions))
}
else if (type == typeof(SystemReportingOptions))
{
var options = unsanitizedOptions as SystemReportingOptions;
if (options is not null)
{
var options = unsanitizedOptions as SystemKpiOptions;
// Sanitize options here
return (TResult)(object)options;
}
}
}
return unsanitizedOptions;
}
}
\ No newline at end of file
......@@ -7,14 +7,14 @@ using VDS.RDF.Query;
namespace KPIGenerator;
public abstract class Kpi<T, O> where T : class where O : class
public abstract class Reporting<O> where O : class
{
public O Options { get; set; }
public O Options { get; init; }
public RdfStoreConnector RdfStoreConnector { get; init; }
public readonly SparqlRemoteEndpoint QueryEndpoint;
public SparqlRemoteEndpoint QueryEndpoint { get; init; }
private static ConsulConfiguration Configuration { get; } = new ConsulConfiguration();
private const string HostUrl = "https://git.rwth-aachen.de/";
private static string HostUrl { get; } = "https://git.rwth-aachen.de/";
private static string InstanceName { get; set; } = null!;
/// <summary>
/// Reporting Database GitLab Project URL
......@@ -22,18 +22,30 @@ public abstract class Kpi<T, O> where T : class where O : class
/// <remarks>https://git.rwth-aachen.de/coscine/reporting/reporting-database</remarks>
private static readonly int ReportingDatabaseProjectId = 75304;
public Kpi(O options)
public Reporting(O options)
{
InstanceName = this.GetType().Name;
Options = options;
RdfStoreConnector = new RdfStoreConnector(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url"));
QueryEndpoint = new SparqlRemoteEndpoint(new Uri(Configuration.GetStringAndWait("coscine/local/virtuoso/additional/url")));
}
protected abstract T GenerateReporting();
public abstract IEnumerable<ReportingFileObject> GenerateReporting();
public bool Run()
{
Console.WriteLine($"{new string('-', 35)}\n{InstanceName}\n{new string('-', 35)}");
// Generate Reporting based on CLI input
var reportingFiles = GenerateReporting();
Console.WriteLine("Reporting generated successfully. Publishing...");
// Publish Report
var success = PublishAsync(reportingFiles).Result;
Console.WriteLine(success ? "Reporting published successfully." : "Reporting publishing FAILED!");
return success;
}
public abstract bool Run();
public static async Task<bool> PublishAsync(IEnumerable<ReportingFileObject> files)
private static async Task<bool> PublishAsync(IEnumerable<ReportingFileObject> files)
{
var token = Configuration.GetStringAndWait("coscine/global/gitlabtoken");
var gitLabClient = new GitLabClient(HostUrl, token);
......@@ -41,7 +53,7 @@ public abstract class Kpi<T, O> where T : class where O : class
{
// Retrieve Reporting Database project
var reportingDatabaseProject = await gitLabClient.Projects.GetAsync(ReportingDatabaseProjectId);
var commitMessage = $"Reporting Generated - {DateTime.Now:dd.MM.yyyy HH:mm}";
var commitMessage = $"{InstanceName} Generated - {DateTime.Now:dd.MM.yyyy HH:mm}"; // CompleteReporting Generated - 31.08.2022 10:25
// Define commit actions
var actions = new List<CreateCommitRequestAction>();
......
......
......@@ -2,47 +2,11 @@
namespace KPIGenerator.Utils;
public static class CommandLineOptions
public static partial class CommandLineOptions
{
public class BaseOptions
{
[Option("dummy", Required = false, Default = false, HelpText = "An argument that tells the program to execute in dummy mode.")]
public bool DummyMode { get; set; }
}
[Verb("all", HelpText = "Generate all KPIs")]
public class CompleteKpiOptions : BaseOptions
{
// Add verb specific options here
}
[Verb("projects", HelpText = "Generate project KPIs")]
public class ProjectKpiOptions : BaseOptions
{
// Add verb specific options here
}
[Verb("resources", HelpText = "Generate resource KPIs")]
public class ResourceKpiOptions : BaseOptions
{
// Add verb specific options here
}
[Verb("users", HelpText = "Generate user KPIs")]
public class UserKpiOptions : BaseOptions
{
// Add verb specific options here
}
[Verb("applprofiles", HelpText = "Generate application profile KPIs")]
public class ApplicationProfileKpiOptions : BaseOptions
{
// Add verb specific options here
}
[Verb("system", HelpText = "Generate system status KPIs")]
public class SystemKpiOptions : BaseOptions
{
// Add verb specific options here
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment