Skip to content
Snippets Groups Projects
Commit 04e99726 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Hotfix/790-orgDeploy' into 'Sprint/2020-11'

Hotfix/790 org deploy

See merge request coscine/cs/organizationdeployer!6
parents 3a70d789 d9d6404f
No related tags found
No related merge requests found
...@@ -14,26 +14,10 @@ namespace Coscine.OrganizationDeployer ...@@ -14,26 +14,10 @@ namespace Coscine.OrganizationDeployer
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
ProcessStartInfo startInfo = new ProcessStartInfo ExecuteCommand(
{ "powershell.exe",
FileName = @"powershell.exe", $@"& '{ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "getOrganizations.ps1") }'"
Arguments = $@"& '{ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "getOrganizations.ps1") }'", );
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
Process process = new Process
{
StartInfo = startInfo
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string errors = process.StandardError.ReadToEnd();
Console.WriteLine(errors);
var configuration = new ConsulConfiguration(); var configuration = new ConsulConfiguration();
...@@ -45,28 +29,68 @@ namespace Coscine.OrganizationDeployer ...@@ -45,28 +29,68 @@ namespace Coscine.OrganizationDeployer
VirtuosoManager virtuosoManager = new VirtuosoManager($"Server={virtuosoHost};Uid={virtuosoUser};pwd={virtuosoPassword}"); VirtuosoManager virtuosoManager = new VirtuosoManager($"Server={virtuosoHost};Uid={virtuosoUser};pwd={virtuosoPassword}");
var _util = new Util(virtuosoServer); var _util = new Util(virtuosoServer);
foreach (var file in GetFiles("organizations").Where((file) => file.Contains(".ttl"))) var folder = "/voc";
{ var virtuosoISQLLocation = configuration.GetString(
"coscine/local/virtuoso/isql",
"C:/Programs/Virtuoso/bin/isql.exe"
);
var queries = new List<string>();
foreach (var file in GetFiles(folder).Where((file) => file.Contains(".ttl")))
{
var fileInfo = new FileInfo(file);
var graph = new Graph(); var graph = new Graph();
graph.LoadFromFile(file); graph.LoadFromFile(file);
var graphName = graph.BaseUri.ToString(); var graphName = graph.BaseUri.ToString();
if (_util.HasGraph(graphName)) if (_util.HasGraph(graphName))
{ {
Console.WriteLine($"Clearing {graphName}"); Console.WriteLine($"Clearing {graphName}");
_util.ClearGraph(graphName); _util.ClearGraph(graphName);
} }
else
{ queries.Add($"ld_dir('{fileInfo.DirectoryName.Substring(2).Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');");
Console.WriteLine($"Creating {graphName}");
_util.CreateNamedGraph(graphName);
} }
queries.Add($"rdf_loader_run ();");
queries.Add($"DELETE from DB.DBA.load_list where 1=1;");
Console.WriteLine($"Adding to {graphName}"); foreach (var query in queries)
virtuosoManager.SaveGraph(graph); {
ExecuteCommand(
"powershell.exe",
$"\"\\\"{query}\\\" | {virtuosoISQLLocation}\""
);
} }
Console.WriteLine("Done"); Console.WriteLine("Done");
} }
private static void ExecuteCommand(string fileName, string arguments)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
};
using (var process = new Process
{
StartInfo = startInfo
})
{
process.Start();
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
string errors = process.StandardError.ReadToEnd();
Console.WriteLine(errors);
}
}
private static IEnumerable<string> GetFiles(string path) private static IEnumerable<string> GetFiles(string path)
{ {
Queue<string> queue = new Queue<string>(); Queue<string> queue = new Queue<string>();
......
...@@ -6,10 +6,32 @@ $gitlab_token = & $fullPath kv get "coscine/global/gitlabtoken" ...@@ -6,10 +6,32 @@ $gitlab_token = & $fullPath kv get "coscine/global/gitlabtoken"
Push-Location $PSScriptRoot Push-Location $PSScriptRoot
$organizationsPath = 'organizations'
# Twice remove, because of: https://stackoverflow.com/questions/7909167/how-to-quietly-remove-a-directory-with-content-in-powershell#comment10316056_7909195
If(Test-Path $organizationsPath) { Remove-Item -LiteralPath $organizationsPath -Force -Recurse }
If(Test-Path $organizationsPath) { Remove-Item -LiteralPath $organizationsPath -Force -Recurse }
git clone https://gitlab-ci-token:$gitlab_token@git.rwth-aachen.de/coscine/organizations.git git clone https://gitlab-ci-token:$gitlab_token@git.rwth-aachen.de/coscine/organizations.git
cd organizations cd organizations
git checkout Master $pagebranch = & $fullPath kv get 'coscine/local/organizationdeployer/branch'
if ($pagebranch -And $pagebranch -ne 'master' ) {
git checkout $pagebranch
git pull
}
cd ..
$path = '/voc'
# Twice remove, because of: https://stackoverflow.com/questions/7909167/how-to-quietly-remove-a-directory-with-content-in-powershell#comment10316056_7909195
If(Test-Path $path) { Remove-Item -LiteralPath $path -Force -Recurse }
If(Test-Path $path) { Remove-Item -LiteralPath $path -Force -Recurse }
New-Item -ItemType Directory -Force -Path $path
Copy-Item './organizations/*' $path -Recurse;
Pop-Location Pop-Location
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment