From 0bf0f8a05db346e6b06aed1d47d3fc2f4cf5c3d4 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Tue, 23 Apr 2019 16:16:58 +0200 Subject: [PATCH] small changes and fixes for jobrunner --- Jobs/JobConfigParser.vb | 21 ++++++++++++------- .../ActiveDirectoryInterface.vb | 14 ++++++++----- .../SyncUsers.Firebird.vb | 4 ++-- .../SyncUsers.MSSQL.vb | 2 +- Service.JobRunner/JobRunner.vb | 11 +++++----- 5 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Jobs/JobConfigParser.vb b/Jobs/JobConfigParser.vb index ad089da0..e1f9c0c3 100644 --- a/Jobs/JobConfigParser.vb +++ b/Jobs/JobConfigParser.vb @@ -2,22 +2,28 @@ Imports System.Text.RegularExpressions Public Class JobConfigParser - Private Shared JobOptionsRegex As New Regex("(?True|False)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::\w*,?)*))?") - Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::\w+,?)?)+") + Private Shared JobOptionsRegex As New Regex("(?True|False)\|(?[\w\d\s,\?*-/]*)(?:\|(?(?:\w*::[^,\n]+,?)*))?") + Private Shared JobArgumentsRegex As New Regex("(?:(?:\w+::[^,\n]+,?)?)+") Private Const ARGS_ITEM_DELIMITER As String = "," Private Const ARGS_KEYVALUE_DELIMITER As String = "::" + Private Const ARGS_LIST_DELIMITER As String = "|" + Public Shared Function ParseConfig(ConfigString As String) As JobConfig If JobOptionsRegex.IsMatch(ConfigString) Then Dim oMatches = JobOptionsRegex.Matches(ConfigString) Dim oOptions As New JobConfig - If oMatches.Count = 1 Then - Dim oMatch = oMatches.Item(0) + Dim oSplitOptions As String() = ConfigString.Split(ARGS_LIST_DELIMITER) - oOptions.Enabled = CBool(oMatch.Groups("enabled").Value) - oOptions.CronExpression = oMatch.Groups("cron").Value - oOptions.Arguments = ParseOptionalArguments(oMatch.Groups("args").Value) + If oSplitOptions.Length = 3 Then + oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions.CronExpression = oSplitOptions(1) + oOptions.Arguments = New Dictionary(Of String, String) + ElseIf oSplitOptions.Length = 2 Then + oOptions.Enabled = CBool(oSplitOptions(0)) + oOptions.CronExpression = oSplitOptions(1) + oOptions.Arguments = ParseOptionalArguments(oSplitOptions(2)) Else Throw New ArgumentException("Config Malformed") End If @@ -37,6 +43,7 @@ Public Class JobConfigParser For Each oArg In oArgs Dim oDelimiter As String() = New String() {ARGS_KEYVALUE_DELIMITER} Dim oArgSplit = oArg.Split(oDelimiter, StringSplitOptions.RemoveEmptyEntries) + Regex.Split(oArg, "::") If oArgSplit.Length = 2 Then oArgsDictionary.Add(oArgSplit(0), oArgSplit(1)) diff --git a/Modules.Interfaces/ActiveDirectoryInterface.vb b/Modules.Interfaces/ActiveDirectoryInterface.vb index 49e81a03..ac057edb 100644 --- a/Modules.Interfaces/ActiveDirectoryInterface.vb +++ b/Modules.Interfaces/ActiveDirectoryInterface.vb @@ -52,8 +52,8 @@ Public Class ActiveDirectoryInterface Dim oSyncedUsers As New List(Of ADUser) Dim oGroupId As Int64 = Nothing - Dim oFirebirdSync As New SyncUsers.Firebird(_logConfig, _firebird) - Dim oSQLSync As New SyncUsers.MSSQL(_logConfig, _mssql) + Dim oFirebirdSync As New SyncUsers.FirebirdSync(_logConfig, _firebird) + Dim oSQLSync As New SyncUsers.MSSQLSync(_logConfig, _mssql) Dim oSyncedUsersFirebird, oSyncedUsersMSSQL As List(Of ADUser) Try @@ -73,13 +73,17 @@ Public Class ActiveDirectoryInterface ' Do the actual sync into firebird If _firebird IsNot Nothing Then oSyncedUsersFirebird = oFirebirdSync.SyncUsers(GroupName, oUsers, AttributeMappings) - _logger.Info("Synced {0} users to Firebird", oSyncedUsersFirebird.Count) + If oSyncedUsersFirebird.Count > 0 Then + _logger.Info("Synced {0} users to Firebird", oSyncedUsersFirebird.Count) + End If End If ' Do the actual sync into MSSQL If _mssql IsNot Nothing Then oSyncedUsersMSSQL = oSQLSync.SyncUsers(GroupName, oUsers, AttributeMappings) - _logger.Info("Synced {0} users to MSSQLServer", oSyncedUsersMSSQL.Count) + If oSyncedUsersMSSQL.Count > 0 Then + _logger.Info("Synced {0} users to MSSQLServer", oSyncedUsersMSSQL.Count) + End If End If Return oUsers @@ -180,7 +184,7 @@ Public Class ActiveDirectoryInterface _logger.Warn("Could not fetch CustomAttributes for user {0}", oUser) End If - _logger.Info("Trying to add User {0} to user list", oUser) + _logger.Debug("Trying to add User {0} to user list", oUser) Dim oNewUser As New ADUser With { .SId = oUser.Sid, diff --git a/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.Firebird.vb b/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.Firebird.vb index 00d842d0..b15e9d4d 100644 --- a/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.Firebird.vb +++ b/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.Firebird.vb @@ -3,7 +3,7 @@ Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Logging Namespace SyncUsers - Public Class Firebird + Public Class FirebirdSync Implements ISyncUsers Private ReadOnly _logConfig As LogConfig @@ -25,7 +25,7 @@ Namespace SyncUsers oGroupId = GetGroupId(GroupName) If oGroupId = 0 Then - _logger.Warn("Group {0} does not exist in database. Exiting", GroupName) + _logger.Debug("Group {0} does not exist in database or is not enabled for sync.", GroupName) Return oSyncedUsers End If diff --git a/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.MSSQL.vb b/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.MSSQL.vb index 0ec04d2e..15e75b18 100644 --- a/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.MSSQL.vb +++ b/Modules.Interfaces/ActiveDirectoryInterface/SyncUsers.MSSQL.vb @@ -2,7 +2,7 @@ Imports DigitalData.Modules.Logging Namespace SyncUsers - Public Class MSSQL + Public Class MSSQLSync Implements ISyncUsers Private _logConfig As LogConfig diff --git a/Service.JobRunner/JobRunner.vb b/Service.JobRunner/JobRunner.vb index 29d17192..e11eeecb 100644 --- a/Service.JobRunner/JobRunner.vb +++ b/Service.JobRunner/JobRunner.vb @@ -14,7 +14,8 @@ Public Class JobRunner Private _mssql As MSSQLServer Private _Props As New NameValueCollection From { - {"quartz.serializer.type", "binary"} + {"quartz.serializer.type", "binary"}, + {"quartz.threadPool.threadCount", 1} } Private _factory As StdSchedulerFactory Private _scheduler As IScheduler @@ -98,11 +99,11 @@ Public Class JobRunner Dim oFirebird As Firebird = oJobData.Item("Firebird") Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL") Dim oArgs As Dictionary(Of String, String) = oJobData.Item("Args") - Dim oRootPath As String = oArgs.Item("RootPath") + Dim oADJobArgs = New ADSyncArgs() - Dim oADJobArgs = New ADSyncArgs() With { - .RootPath = oRootPath - } + If oArgs.ContainsKey("RootPath") Then + oADJobArgs.RootPath = oArgs.Item("RootPath") + End If Dim oADSyncJob As New ADSyncJob(oLogConfig, oFirebird, oMSSQL) oADSyncJob.Start(oADJobArgs)