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

New: Fast Deployment

parent ca1f39ce
Branches Hotfix/xxxx-fastDeployment
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;
using Coscine.Metadata;
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NLog.Config;
using NLog.Extensions.Logging;
using System.Diagnostics;
......@@ -41,6 +42,10 @@ public class Program
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 virtuosoHost = new Uri(virtuosoServer).Host;
var virtuosoUser = Configuration.GetString("coscine/global/virtuoso_db_user");
......@@ -111,6 +116,15 @@ public class Program
{
var graph = kv.Value.Item1;
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));
......@@ -121,8 +135,12 @@ public class Program
var graphWasChanged = graph.Triples.Count != currentGraph.Triples.Count
|| projectedGraph.Except(projectedCurrentGraph).Any();
if (graphWasChanged)
if (!graphWasChanged)
{
_logger.LogInformation("Skipping {graphName}", graphName);
continue;
}
if (!currentGraph.IsEmpty)
{
Helpers.WrapRequest(() => _rdfStoreConnector.ClearGraph(graphName));
......@@ -139,11 +157,6 @@ public class Program
queries.Add($"ld_dir('{fileInfo.DirectoryName[2..].Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');");
}
}
else
{
_logger.LogInformation("Skipping {graphName}", graphName);
}
}
queries.Add($"rdf_loader_run ();");
queries.Add($"DELETE from DB.DBA.load_list where 1=1;");
......@@ -159,6 +172,7 @@ public class Program
}
}
Configuration.Put("coscine/local/graph_deployer/last_run", JsonConvert.SerializeObject(currentRun));
_logger.LogInformation("Done");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment