Skip to content
Snippets Groups Projects
Commit 52c1e542 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Merge branch 'Hotfix/xxxx-fastDeployment' into 'master'

New: Fast Deployment

See merge request !16
parents ca1f39ce 0c763c58
Branches
Tags
1 merge request!16New: Fast Deployment
using System.Security.Cryptography;
namespace Coscine.GraphDeployer
{
public static class HashUtil
{
public static string GetFileHash(string path)
{
using (SHA256 sha256 = SHA256.Create())
{
using (FileStream fileStream = File.OpenRead(path))
{
return BitConverter.ToString(sha256.ComputeHash(fileStream));
}
}
}
}
}
...@@ -3,6 +3,7 @@ using Coscine.GraphDeployer.Logging; ...@@ -3,6 +3,7 @@ using Coscine.GraphDeployer.Logging;
using Coscine.Metadata; using Coscine.Metadata;
using LibGit2Sharp; using LibGit2Sharp;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NLog.Config; using NLog.Config;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
using System.Diagnostics; using System.Diagnostics;
...@@ -41,6 +42,10 @@ public class Program ...@@ -41,6 +42,10 @@ public class Program
private static void Run() private static void Run()
{ {
var currentRun = new Dictionary<string, string>();
var lastRun = JsonConvert.DeserializeObject<Dictionary<string, string>>(Configuration.GetString("coscine/local/graph_deployer/last_run", "{}"));
lastRun ??= new Dictionary<string, string>();
var virtuosoServer = Configuration.GetString("coscine/local/virtuoso/additional/url"); var virtuosoServer = Configuration.GetString("coscine/local/virtuoso/additional/url");
var virtuosoHost = new Uri(virtuosoServer).Host; var virtuosoHost = new Uri(virtuosoServer).Host;
var virtuosoUser = Configuration.GetString("coscine/global/virtuoso_db_user"); var virtuosoUser = Configuration.GetString("coscine/global/virtuoso_db_user");
...@@ -111,6 +116,15 @@ public class Program ...@@ -111,6 +116,15 @@ public class Program
{ {
var graph = kv.Value.Item1; var graph = kv.Value.Item1;
var graphName = kv.Key.ToString(); var graphName = kv.Key.ToString();
kv.Value.Item2.ForEach((path) => currentRun.TryAdd(graphName + path, HashUtil.GetFileHash(path)));
var changed = kv.Value.Item2.Any((path) =>
!lastRun.ContainsKey(graphName + path) || lastRun[graphName + path] != currentRun[graphName + path]);
if (!changed)
{
_logger.LogInformation("Skipping {graphName}", graphName);
continue;
}
var currentGraph = Helpers.WrapRequest(() => _rdfStoreConnector.GetGraph(graphName)); var currentGraph = Helpers.WrapRequest(() => _rdfStoreConnector.GetGraph(graphName));
...@@ -121,8 +135,12 @@ public class Program ...@@ -121,8 +135,12 @@ public class Program
var graphWasChanged = graph.Triples.Count != currentGraph.Triples.Count var graphWasChanged = graph.Triples.Count != currentGraph.Triples.Count
|| projectedGraph.Except(projectedCurrentGraph).Any(); || projectedGraph.Except(projectedCurrentGraph).Any();
if (graphWasChanged) if (!graphWasChanged)
{ {
_logger.LogInformation("Skipping {graphName}", graphName);
continue;
}
if (!currentGraph.IsEmpty) if (!currentGraph.IsEmpty)
{ {
Helpers.WrapRequest(() => _rdfStoreConnector.ClearGraph(graphName)); Helpers.WrapRequest(() => _rdfStoreConnector.ClearGraph(graphName));
...@@ -139,11 +157,6 @@ public class Program ...@@ -139,11 +157,6 @@ public class Program
queries.Add($"ld_dir('{fileInfo.DirectoryName[2..].Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');"); queries.Add($"ld_dir('{fileInfo.DirectoryName[2..].Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');");
} }
} }
else
{
_logger.LogInformation("Skipping {graphName}", graphName);
}
}
queries.Add($"rdf_loader_run ();"); queries.Add($"rdf_loader_run ();");
queries.Add($"DELETE from DB.DBA.load_list where 1=1;"); queries.Add($"DELETE from DB.DBA.load_list where 1=1;");
...@@ -159,6 +172,7 @@ public class Program ...@@ -159,6 +172,7 @@ public class Program
} }
} }
Configuration.Put("coscine/local/graph_deployer/last_run", JsonConvert.SerializeObject(currentRun));
_logger.LogInformation("Done"); _logger.LogInformation("Done");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment