/// <summary> /// The program entry point. /// </summary> /// <param name="args">The command line arguments.</param> /// <returns>The tracking <see cref="Task"/>.</returns> public static async Task Main(string[] args) { NeonService.Initialize(); try { //------------------------------------------------------------- // Intercept and handle KubeOps [generator] commands executed by the // KubeOps MSBUILD tasks. if (await OperatorHelper.HandleGeneratorCommand <Startup>(args)) { return; } //------------------------------------------------------------- // Start the operator service. Service = new Service(KubeService.NeonClusterOperator); Environment.Exit(await Service.RunAsync()); } catch (Exception e) { // We really shouldn't see exceptions here but let's log something // just in case. Note that logging may not be initialized yet so // we'll just output a string. Console.Error.WriteLine(NeonHelper.ExceptionError(e)); Environment.Exit(-1); } }
/* * Pushes the current operator token to the stack and pops Evaluatables from the stack */ private void FoundOperator(string token, List <string> result) { var op = Evaluatables[token]; if (Hold.Count != 0) { while (Hold.Count != 0) { var topOfStack = Hold.Peek(); if (!Evaluatables.OperatorExists(topOfStack)) { break; } var operatorTop = Evaluatables[topOfStack]; if ((OperatorHelper.CheckAssociativity(op, Associativity.L) && op.Precedence <= operatorTop.Precedence) || OperatorHelper.CheckAssociativity(op, Associativity.R) && op.Precedence < operatorTop.Precedence) { result.Add(Hold.Pop()); } else { break; } } } Hold.Push(token); }
public AphidObject NotEqualTest(AphidObject x, AphidObject y) { AphidObject result = OperatorHelper.NotEqual(x, y); return(result); // TODO: add assertions to method OperatorHelperTest.NotEqualTest(AphidObject, AphidObject) }
public OperatorHelper ConstructorTest(AphidInterpreter interpreter) { OperatorHelper target = new OperatorHelper(interpreter); return(target); // TODO: add assertions to method OperatorHelperTest.ConstructorTest(AphidInterpreter) }
public void ShouldManageBinaryOrOperator() { Assert.True(OperatorHelper.EvaluateBinary("||", true, true)); Assert.True(OperatorHelper.EvaluateBinary("||", true, false)); Assert.True(OperatorHelper.EvaluateBinary("||", false, true)); Assert.False(OperatorHelper.EvaluateBinary("||", false, false)); }
public bool EqualsCoreTest(AphidObject x, AphidObject y) { bool result = OperatorHelper.EqualsCore(x, y); return(result); // TODO: add assertions to method OperatorHelperTest.EqualsCoreTest(AphidObject, AphidObject) }
public AphidObject DivideTest( [PexAssumeUnderTest] OperatorHelper target, AphidObject x, AphidObject y ) { AphidObject result = target.Divide(x, y); return(result); // TODO: add assertions to method OperatorHelperTest.DivideTest(OperatorHelper, AphidObject, AphidObject) }
public AphidObject BinaryShiftRightTest( [PexAssumeUnderTest] OperatorHelper target, AphidObject x, AphidObject y ) { AphidObject result = target.BinaryShiftRight(x, y); return(result); // TODO: add assertions to method OperatorHelperTest.BinaryShiftRightTest(OperatorHelper, AphidObject, AphidObject) }
public bool EqualsTest01( AphidInterpreter instance, object left, object right ) { bool result = OperatorHelper.Equals(instance, left, right); return(result); // TODO: add assertions to method OperatorHelperTest.EqualsTest01(AphidInterpreter, Object, Object) }
void OnCalculate(System.Object sender, System.EventArgs e) { if (currentState == 2) { var result = OperatorHelper.Calculate(fisrtNumber, secondNumber, myOperator); this.resultText.Text = result.ToString(); fisrtNumber = result; currentState = -1; } }
public FilterRequestValidator() { RuleFor(x => x.Field).NotEmpty(); RuleFor(x => x).Must(x => OperatorHelper.OnlyOneTrue( !string.IsNullOrEmpty(x.ValueString), x.ValueGuid != null, x.ValueDateTimeFrom != null || x.ValueDateTimeTo != null, x.ValueNumberFrom != null || x.ValueNumberTo != null, x.ValueBool != null, x.ValueList != null )); }
public static void DeleteTableWithConditions(this SurlyDatabase database, string tableName, string line) { var tableResponse = database.GetTable(tableName); if (tableResponse.Table == null) { return; } string[] conditions = null; try { conditions = new Regex("where (.+);", RegexOptions.IgnoreCase) .Match(line) .Groups[1] .Captures[0] .ToString() .ToUpper() .Split(' '); } catch (Exception) { WriteLine("Invalid syntax, please see help.", Red); } if (conditions == null) { return; } var success = false; tableResponse.Table.Tuples.ToList().ForEach(tableRow => { var match = OperatorHelper.Chain(tableRow, true, conditions, 0); if (match) { tableResponse.Table.Tuples.Remove(tableRow); success = true; } }); if (success) { WriteLine("\n\tSuccess", Green); } else { WriteLine("No rows affected."); } }
/// <summary> /// Generate the employee query based on the query fields /// </summary> /// <param name="employeeRequest"></param> /// <returns>string</returns> public string CreateEmployeeQuery(QueryBuilderRequest employeeRequest) { //Parameters that used to read the data string query = string.Empty, tableJoin = string.Empty, selectQuery = string.Empty, whereQuery = string.Empty, currentUserId = string.Empty; List <string> fieldList = new List <string>(); try { if (employeeRequest.ColumnList.Length == 0) { throw new ArgumentException("ColumnList"); } if (employeeRequest.Fields.Count == 0) { throw new ArgumentException("Fields"); } //Select statement for the query selectQuery = "SELECT DISTINCT"; //getting column List query = string.Join("", (from column in columnList where employeeRequest.ColumnList.Any(x => x == column.Key) select column.Value)); query = query.TrimStart(','); query = selectQuery + query; //Append the user query with select statement query += " FROM dbo.[UserDetails_RB] u JOIN dbo.UserCompany uc on uc.UserId=u.User_Id AND uc.IsEnabled = 1 AND uc.Status = 1 AND uc.IsVisible = 1 AND uc.IsDefault=1"; //get table joins fieldList = employeeRequest.ColumnList.ToList(); fieldList.AddRange(employeeRequest.Fields.Select(x => x.Name.ToUpper()).ToArray()); tableJoin = string.Join("", from joins in tableJoins where fieldList.Any(x => joins.Value.Any(y => y == x)) select joins.Key); query += tableJoin; //Handles the smart parameter for the userName currentUserId = employeeRequest.Fields.Where(x => x.Name.ToUpper() == Constants.CURRENT_USER).Select(x => x.Value).FirstOrDefault(); if (employeeRequest.Fields.Where(x => x.Name == Constants.USERNAME).ToList().Count > 0 && employeeRequest.Fields.Where(x => x.Name == Constants.CURRENT_USER).ToList().Count > 0) { EmployeeModel userDetails = employeeRequest.Fields.Where(x => x.Name == Constants.CURRENT_USER).FirstOrDefault(); employeeRequest.Fields.Remove(userDetails); employeeRequest.Fields.Select(x => x.Name == Constants.USERNAME && UsernameSmartParameters.Contains(x.Value) ? x.Name = x.Value : x.Name).ToList(); employeeRequest.Fields.Select(x => (UsernameSmartParameters.Contains(x.Name) && x.Operator == "!=") ? x.Name = "NOT_" + x.Name : x.Name).ToList(); } //handles the Supervisor Id depends upon the Request if (employeeRequest.Fields.Where(x => x.Name == Constants.SUPERVISOR_ID).ToList().Count > 0) { employeeRequest.Fields.Select(x => x.Name == Constants.SUPERVISOR_ID ? x.Name = Constants.SUPERVISOR_ID_HANDLER : x.Name).ToList(); } //Remove student details from the List if (employeeRequest.Fields.Where(x => x.Name == Constants.STUDENT_DETAILS).ToList().Count > 0) { EmployeeModel userDetails = employeeRequest.Fields.Where(x => x.Name == Constants.STUDENT_DETAILS).FirstOrDefault(); employeeRequest.Fields.Remove(userDetails); } //getting where conditions whereQuery = string.Join("", from employee in employeeRequest.Fields select(!string.IsNullOrEmpty(employee.Bitwise) ? (" " + employee.Bitwise + " ") : string.Empty) + (!string.IsNullOrEmpty(employeeFields.Where(x => x.Key == employee.Name.ToUpper()).Select(x => x.Value).FirstOrDefault()) ? (employeeFields.Where(x => x.Key == employee.Name.ToUpper()).Select(x => x.Value).FirstOrDefault() + OperatorHelper.CheckOperator(employee.Operator, employee.Value.Trim(), employee.Name) + CheckValues(employee.Value, employee.Operator)) : string.Empty)); //Append the company query whereQuery = (!string.IsNullOrEmpty(whereQuery)) ? (" WHERE uc.CompanyId=" + employeeRequest.CompanyId + " AND uc.status=1 AND (" + whereQuery) : string.Empty; whereQuery = whereQuery.Replace("@currentuserId", currentUserId); //Create the final query that helps to retrieve the data query += whereQuery + " )"; return(query); } catch (Exception createEmployeeQueryException) { LambdaLogger.Log(createEmployeeQueryException.ToString()); return(string.Empty); } }
/// <inheritdoc/> public async Task <ResourceControllerResult> ReconcileAsync(V1NeonNodeTask resource) { // Ignore all events when the controller hasn't been started. if (resourceManager == null) { return(null); } var name = resource.Name(); log.LogInfo($"RECONCILED: {name}"); // We have a new node task targeting the host node: // // 1. Ensure that it's valid, delete if bad // 2. Add a status property as necessary // 3. Remove the task if it's been retained long enough // 4. Execute the task if it's pending var nodeTask = resource; // Verify that task is valid. try { nodeTask.Validate(); } catch (Exception e) { log.LogWarn($"Invalid NodeTask: [{name}]", e); log.LogWarn($"Deleting invalid NodeTask: [{name}]"); await k8s.DeleteClusterCustomObjectAsync(nodeTask); return(null); } // For new tasks, update the status to PENDING and also add the // node's owner reference to the object. if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.New) { var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status, new V1NeonNodeTask.TaskStatus()); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Pending); nodeTask = await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); var nodeOwnerReference = await Node.GetOwnerReferenceAsync(k8s); if (nodeOwnerReference != null) { if (nodeTask.Metadata.OwnerReferences == null) { nodeTask.Metadata.OwnerReferences = new List <V1OwnerReference>(); } nodeTask.Metadata.OwnerReferences.Add(await Node.GetOwnerReferenceAsync(k8s)); } nodeTask = await k8s.ReplaceClusterCustomObjectAsync <V1NeonNodeTask>(nodeTask, nodeTask.Name()); } if (nodeTask.Status.FinishTimestamp.HasValue) { var retentionTime = DateTime.UtcNow - nodeTask.Status.FinishTimestamp; if (retentionTime >= TimeSpan.FromSeconds(nodeTask.Spec.RetentionSeconds)) { log.LogInfo($"NodeTask [{name}] retained for [{retentionTime}] (deleting now)."); await k8s.DeleteClusterCustomObjectAsync(nodeTask); return(null); } } // Execute the task if it's pending and it hasn't missed the scheduling window. if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Pending) { var utcNow = DateTime.UtcNow; // Abort if we missed the end the scheduled window. if (nodeTask.Spec.StartBeforeTimestamp.HasValue && nodeTask.Spec.StartBeforeTimestamp < utcNow) { log.LogWarn($"Detected tardy [nodetask={nodeTask.Name()}]: task execution didn't start before [{nodeTask.Spec.StartBeforeTimestamp}]."); // Update the node task status to: TARDY var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Tardy); patch.Replace(path => path.Status.FinishTimestamp, utcNow); patch.Replace(path => path.Status.ExitCode, -1); await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); return(null); } // Don't start before a scheduled time. // $todo(jefflill): // // We should requeue the event for the remaining time here, instead of letting // the IDLE handler execute the delayed task. if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Pending) { if (nodeTask.Spec.StartAfterTimestamp.HasValue && nodeTask.Spec.StartAfterTimestamp.Value <= utcNow) { await ExecuteTaskAsync(nodeTask); return(null); } else { return(null); } } await ExecuteTaskAsync(nodeTask); } return(null); }
public void ShouldManageTheNotUnaryOperator() { Assert.True(OperatorHelper.EvaluateUnary("!", false)); Assert.False(OperatorHelper.EvaluateUnary("!", true)); }
public void ShouldRejectNotImplementedBinaryOperator() { Assert.Throws <NotImplementedException>(() => OperatorHelper.EvaluateBinary("+", false, true)); }
public static void Select(this SurlyDatabase database, string query) { _resultSet = new LinkedList <LinkedList <SurlyAttribute> >(); string tableName, conditions, projectionName = null; var printProjection = false; try { try { projectionName = new Regex("(\\w+) = select", RegexOptions.IgnoreCase) .Match(query) .Groups[1] .Captures[0] .ToString() .ToUpper(); } catch (Exception) { printProjection = true; } tableName = new Regex("select (\\w+) where", RegexOptions.IgnoreCase) .Match(query) .Groups[1] .Captures[0] .ToString() .ToUpper(); conditions = new Regex("where (.+);", RegexOptions.IgnoreCase) .Match(query) .Groups[1] .Captures[0] .ToString() .ToUpper(); } catch (Exception) { WriteLine("Invalid SELECT syntax, please see help", Red); return; } var tableResponse = database.GetTable(tableName); if (tableResponse.Table == null) { WriteLine($"{tableName.ToUpper()} not found.", Red); return; } if (!printProjection && SurlyProjections.GetInstance().Projections.Any(x => x.ProjectionName.ToUpper() == projectionName?.ToUpper())) { WriteLine($"\n\t{projectionName?.ToUpper()} already exists, please choose a different name", Red); return; } var conditionSteps = conditions.Split(' ').ToList(); tableResponse.Table.Tuples.ToList().ForEach(tableRow => { var valid = OperatorHelper.Chain(tableRow, true, conditionSteps.ToArray(), 0); if (valid) { var trimmedRow = new LinkedList <SurlyAttribute>(tableRow); var rowId = trimmedRow.SingleOrDefault(x => x.Name == "Id"); trimmedRow.Remove(rowId); _resultSet.AddLast(trimmedRow); } }); if (_resultSet.Count == 0) { WriteLine("\n\tQuery yielded no results.", Yellow); return; } var schema = new LinkedList <SurlyAttributeSchema>(tableResponse.Table.Schema); var id = schema.SingleOrDefault(x => x.Name == "Id"); schema.Remove(id); if (printProjection) { var response = new SurlyTableResponse { Table = new SurlyTable { Schema = schema, Name = "Results", Tuples = _resultSet }, //HideIndexes = true }; database.PrintTables(new List <SurlyTableResponse> { response }); return; } SurlyProjections.GetInstance().Projections.AddLast(new SurlyProjection { AttributeNames = schema, HideIndex = true, ProjectionName = projectionName, TableName = tableResponse.Table.Name, Tuples = _resultSet }); WriteLine($"\n\t{projectionName.ToUpper()} build successful.", Green); }
/// <summary> /// <para> /// Handles the cleanup of tasks targeting the current cluster node: /// </para> /// <list type="bullet"> /// <item> /// Tasks whose <see cref="V1NeonNodeTask.TaskStatus.AgentId"/> doesn't match /// the ID for the current agent will be marked as <see cref="V1NeonNodeTask.Phase.Orphaned"/> /// and the finish time will be set to now. This sets the task up for eventual /// deletion. /// </item> /// <item> /// Tasks with a finish time that is older than <see cref="V1NeonNodeTask.TaskSpec.RetentionTime"/> /// will be removed. /// </item> /// <item> /// Scheduled tasks that missed their scheduling window will be marked as TARDY and /// will be retained for a while before being deleted. /// </item> /// </list> /// </summary> /// <returns>The tracking <see cref="Task"/>.</returns> private async Task CleanupTasksAsync() { var utcNow = DateTime.UtcNow; var nodeTasks = (await k8s.ListClusterCustomObjectAsync <V1NeonNodeTask>()).Items .Where(tasks => NodeTaskFilter(tasks)) .ToArray(); foreach (var nodeTask in nodeTasks) { var taskName = nodeTask.Name(); //------------------------------------------------------------- // Remove invalid tasks. try { nodeTask.Validate(); } catch (Exception e) { log.LogWarn($"Invalid NodeTask: [{taskName}]", e); log.LogWarn($"Deleting invalid NodeTask: [{taskName}]"); await k8s.DeleteClusterCustomObjectAsync(nodeTask); continue; } if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Running) { //--------------------------------------------------------- // Detect and kill orphaned tasks. if (nodeTask.Status.AgentId != Node.AgentId) { log.LogWarn($"Detected orphaned [nodetask={taskName}]: task [agentID={nodeTask.Status.AgentId}] does not match operator [agentID={Node.AgentId}]"); // Update the node task status to: ORPHANED var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Orphaned); patch.Replace(path => path.Status.FinishTimestamp, utcNow); patch.Replace(path => path.Status.ExitCode, -1); await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); await KillTaskAsync(nodeTask); continue; } //--------------------------------------------------------- // Kill tasks that have been running for too long. if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Running && utcNow - nodeTask.Status.StartTimestamp >= TimeSpan.FromSeconds(nodeTask.Spec.TimeoutSeconds)) { log.LogWarn($"Execution timeout [nodetask={taskName}]: execution time exceeds [{nodeTask.Spec.TimeoutSeconds}]."); await KillTaskAsync(nodeTask); // Update the node task status to: TIMEOUT var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Timeout); patch.Replace(path => path.Status.FinishTimestamp, utcNow); patch.Replace(path => path.Status.RuntimeSeconds, (int)Math.Ceiling((utcNow - nodeTask.Status.StartTimestamp.Value).TotalSeconds)); patch.Replace(path => path.Status.ExitCode, -1); await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); continue; } //--------------------------------------------------------- // Detect that missed their scheduling window and mark them as tardy if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Pending && nodeTask.Spec.StartBeforeTimestamp.HasValue && nodeTask.Spec.StartBeforeTimestamp <= utcNow) { log.LogWarn($"Detected tardy [nodetask={taskName}]: task execution didn't start before [{nodeTask.Spec.StartBeforeTimestamp}]."); // Update the node task status to: TARDY var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Tardy); patch.Replace(path => path.Status.FinishTimestamp, utcNow); patch.Replace(path => path.Status.ExitCode, -1); await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); continue; } } } //----------------------------------------------------------------- // Remove tasks that have been retained long enough. foreach (var nodeTask in nodeTasks .Where(task => task.Status.Phase != V1NeonNodeTask.Phase.New && task.Status.Phase != V1NeonNodeTask.Phase.Running) .Where(task => (utcNow - task.Status.FinishTimestamp) >= TimeSpan.FromSeconds(task.Spec.RetentionSeconds))) { log.LogWarn($"[nodetask={nodeTask.Name()}]: has been retained for [{nodeTask.Spec.RetentionSeconds}] (deleting now)."); await k8s.DeleteClusterCustomObjectAsync(nodeTask); } //----------------------------------------------------------------- // Remove any script folders whose node task no longer exists. if (NeonHelper.IsLinux) { var nodeTaskExecuteIds = new HashSet <string>(); foreach (var nodeTask in nodeTasks.Where(task => !string.IsNullOrEmpty(task.Status.RunId))) { nodeTaskExecuteIds.Add(nodeTask.Status.RunId); } foreach (var scriptFolderPath in Directory.GetDirectories(hostNeonTasksFolder, "*", SearchOption.TopDirectoryOnly)) { var scriptFolderName = LinuxPath.GetFileName(scriptFolderPath); if (!nodeTaskExecuteIds.Contains(scriptFolderName)) { log.LogWarn($"Removing node task host script folder: {scriptFolderName}"); NeonHelper.DeleteFolder(scriptFolderPath); } } } }
/// <summary> /// Create SQL Query for the workbook based on the request /// </summary> /// <param name="queryBuilderRequest"></param> /// <returns>string</returns> public string CreateWorkbookQuery(QueryBuilderRequest queryBuilderRequest) { string query = string.Empty, tableJoin = string.Empty, selectQuery = string.Empty, whereQuery = string.Empty, companyQuery = string.Empty, supervisorId = string.Empty, currentUserId = string.Empty; List <string> fieldList = new List <string>(); try { //Select statement for the Query selectQuery = "SELECT DISTINCT "; //getting column List query = string.Join("", (from column in workbookColumnList where queryBuilderRequest.ColumnList.Any(x => x == column.Key) select column.Value)); query = query.TrimStart(','); query = selectQuery + query; //Append the workbook tables with select statement query += " FROM dbo.Workbook wb FULL OUTER JOIN dbo.UserWorkBook uwb ON uwb.workbookId=wb.Id FULL OUTER JOIN dbo.UserCompany uc ON uc.UserId=uwb.UserId AND uc.IsEnabled = 1 AND uc.Status = 1 AND uc.IsVisible = 1"; currentUserId = queryBuilderRequest.Fields.Where(x => x.Name.ToUpper() == Constants.CURRENT_USER).Select(x => x.Value).FirstOrDefault(); if (string.IsNullOrEmpty(currentUserId)) { currentUserId = "0"; } //get table joins fieldList = queryBuilderRequest.ColumnList.ToList(); fieldList.AddRange(queryBuilderRequest.Fields.Select(x => x.Name.ToUpper()).ToArray()); tableJoin = string.Join("", from joins in tableJoins where fieldList.Any(x => joins.Value.Any(y => y == x)) select joins.Key); query += tableJoin; //Read the supervisorId based on the request supervisorId = Convert.ToString(queryBuilderRequest.Fields.Where(x => x.Name.ToUpper() == Constants.SUPERVISOR_ID).Select(x => x.Value).FirstOrDefault()); //handles the Supervisor Id depends upon the Request if (queryBuilderRequest.ColumnList.Contains(Constants.TOTAL_EMPLOYEES) && !string.IsNullOrEmpty(supervisorId)) { queryBuilderRequest.Fields.Select(x => x.Name == Constants.SUPERVISOR_ID ? x.Name = Constants.SUPERVISOR_SUB : x.Name).ToList(); } else { if (!string.IsNullOrEmpty(supervisorId)) { queryBuilderRequest.Fields.Select(x => x.Name == Constants.SUPERVISOR_ID && x.Operator == "!=" ? x.Name = Constants.NOT_SUPERVISORID : x.Name).ToList(); } } //handles the Supervisor Id depends upon the Request if (queryBuilderRequest.Fields.Where(x => x.Name == Constants.SUPERVISOR_ID).ToList().Count > 0 && queryBuilderRequest.Fields.Where(x => x.Name == Constants.USERID).ToList().Count > 0) { EmployeeModel userDetails = queryBuilderRequest.Fields.Where(x => x.Name == Constants.USERID).FirstOrDefault(); queryBuilderRequest.Fields.Remove(userDetails); queryBuilderRequest.Fields.Select(x => x.Name == Constants.SUPERVISOR_ID ? x.Name = Constants.SUPERVISOR_USER : x.Name).ToList(); } if (queryBuilderRequest.Fields.Where(x => x.Name == Constants.CURRENT_USER).ToList().Count > 0) { EmployeeModel userDetails = queryBuilderRequest.Fields.Where(x => x.Name == Constants.CURRENT_USER).FirstOrDefault(); queryBuilderRequest.Fields.Remove(userDetails); } //Remove student details from the List if (queryBuilderRequest.Fields.Where(x => x.Name == Constants.STUDENT_DETAILS).ToList().Count > 0) { EmployeeModel userDetails = queryBuilderRequest.Fields.Where(x => x.Name == Constants.STUDENT_DETAILS).FirstOrDefault(); queryBuilderRequest.Fields.Remove(userDetails); } //getting where conditions whereQuery = string.Join("", from employee in queryBuilderRequest.Fields select(!string.IsNullOrEmpty(employee.Bitwise) ? (" " + employee.Bitwise + " ") : string.Empty) + (!string.IsNullOrEmpty(workbookFields.Where(x => x.Key == employee.Name.ToUpper()).Select(x => x.Value).FirstOrDefault()) ? (workbookFields.Where(x => x.Key == employee.Name.ToUpper()).Select(x => x.Value).FirstOrDefault() + OperatorHelper.CheckOperator(employee.Operator, employee.Value.Trim(), employee.Name)) : string.Empty)); //Add the where condition for the company companyQuery = (" WHERE uc.status=1 AND uc.CompanyId=" + queryBuilderRequest.CompanyId); if (queryBuilderRequest.ColumnList.Contains(Constants.WORKBOOK_NAME)) { whereQuery += "AND uwb.isEnabled=1"; } //Create the final query query += (!string.IsNullOrEmpty(whereQuery)) ? (companyQuery + " and (" + whereQuery) + ")" : string.Empty; query = query.Replace("@currentuserId", currentUserId); return(query); } catch (Exception createWorkbookQueryException) { LambdaLogger.Log(createWorkbookQueryException.ToString()); return(string.Empty); } }
public AltQueryComposer(AltQueryOptions options) { _comparisonOperators = OperatorHelper.GenerateComparisonOperatorDictionary(options.ComparisonOperatorOptions); _logicalOperators = OperatorHelper.GenerateLogicalOperatorDictionary(options.LogicalOperatorOptions); _notSymbol = OperatorHelper.GetNotSymbol(_logicalOperators); }
/// <summary> /// Initiates execution of a node task in the background when the task is still pending. /// </summary> /// <param name="nodeTask">The node task to be executed.</param> /// <param name="resources">The existing tasks.</param> /// <returns>The tracking <see cref="Task"/>.</returns> private async Task ExecuteTaskAsync(V1NeonNodeTask nodeTask) { Covenant.Requires <ArgumentNullException>(nodeTask != null, nameof(nodeTask)); var taskName = nodeTask.Name(); if (nodeTask.Status.Phase != V1NeonNodeTask.Phase.Pending) { return; } // Start and execute the command. The trick here is that we need the // ID of the process launched before we can update the status. int?processId = null; // Generate the execution UUID and determine where the script will be located. var executionId = Guid.NewGuid().ToString("d"); var taskFolder = LinuxPath.Combine(hostNeonTasksFolder, executionId); var scriptPath = LinuxPath.Combine(taskFolder, "task.sh"); // Prepend the script to be deployed with code that sets the special // environment variables. var deployedScript = $@" #------------------------------------------------------------------------------ # neon-node-task: Initialze special script variables export NODE_ROOT={Node.HostMount} export SCRIPT_DIR={taskFolder} #------------------------------------------------------------------------------ {nodeTask.Spec.BashScript} "; if (NeonHelper.IsLinux) { Directory.CreateDirectory(taskFolder); File.WriteAllText(scriptPath, NeonHelper.ToLinuxLineEndings(deployedScript)); } // Start the command process. var task = (Task <ExecuteResponse>)null; if (!NeonHelper.IsLinux) { processId = 1234; task = Task.Run <ExecuteResponse>( async() => { await Task.Delay(TimeSpan.FromSeconds(1)); return(new ExecuteResponse(0)); }); } else { try { // This callback will be executed once the [Node.ExecuteCaptureAsync()] // call has the process details. We'll save the details, update the node task // status and persist the status changes to the API server. var processCallback = (Process newProcess) => { processId = newProcess.Id; log.LogInfo($"Starting [nodetask={taskName}]: [command={Node.GetBashCommandLine(scriptPath)}] [processID={processId}]"); }; task = Node.BashExecuteCaptureAsync( path: scriptPath, timeout: TimeSpan.FromSeconds(nodeTask.Spec.TimeoutSeconds), processCallback: processCallback); } catch (Exception e) { // We shouldn't ever see an error here because [/bin/bash] should always // exist, but we'll log something just in case. log.LogWarn(e); var failedPatch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); failedPatch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Failed); failedPatch.Replace(path => path.Status.FinishTimestamp, DateTime.UtcNow); failedPatch.Replace(path => path.Status.ExitCode, -1); failedPatch.Replace(path => path.Status.Error, $"EXECUTE FAILED: {e.Message}"); await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(failedPatch), nodeTask.Name()); return; } } // We need to wait for the [Node.BashExecuteCaptureAsync()] call above to // report the process for the executed script. try { NeonHelper.WaitFor(() => processId != null, timeout: TimeSpan.FromSeconds(15), pollInterval: TimeSpan.FromMilliseconds(150)); } catch (TimeoutException e) { // It's possible but unlikely that the update above failed for some reason. // We'll log this and then hope for the best. log.LogWarn(e); } // Update the node task status to: RUNNING var patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Running); patch.Replace(path => path.Status.StartTimestamp, DateTime.UtcNow); patch.Replace(path => path.Status.AgentId, Node.AgentId); patch.Replace(path => path.Status.ProcessId, processId); patch.Replace(path => path.Status.CommandLine, Node.GetBashCommandLine(scriptPath).Trim()); patch.Replace(path => path.Status.RunId, executionId); nodeTask = await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); // Wait for the command to complete and then update the node task status. try { var result = (ExecuteResponse)null; var timeout = false; try { result = await task; log.LogInfo($"Finished [nodetask={taskName}]: [command={nodeTask.Status.CommandLine}] [exitcode={result.ExitCode}]"); } catch (TimeoutException) { timeout = true; log.LogWarn($"Timeout [nodetask={taskName}]"); } var utcNow = DateTime.UtcNow; if (nodeTask.Status.Phase == V1NeonNodeTask.Phase.Running) { patch = OperatorHelper.CreatePatch <V1NeonNodeTask>(); patch.Replace(path => path.Status.FinishTimestamp, utcNow); if (timeout) { patch.Replace(path => path.Status.Phase, V1NeonNodeTask.Phase.Timeout); patch.Replace(path => path.Status.RuntimeSeconds, (int)Math.Ceiling((utcNow - nodeTask.Status.StartTimestamp.Value).TotalSeconds)); patch.Replace(path => path.Status.ExitCode, -1); } else { patch.Replace(path => path.Status.Phase, result.ExitCode == 0 ? V1NeonNodeTask.Phase.Success : V1NeonNodeTask.Phase.Failed); patch.Replace(path => path.Status.RuntimeSeconds, (int)Math.Ceiling((utcNow - nodeTask.Status.StartTimestamp.Value).TotalSeconds)); patch.Replace(path => path.Status.ExitCode, result.ExitCode); if (nodeTask.Spec.CaptureOutput) { patch.Replace(path => path.Status.Output, result.OutputText); patch.Replace(path => path.Status.Error, result.ErrorText); } } nodeTask = await k8s.PatchClusterCustomObjectStatusAsync <V1NeonNodeTask>(OperatorHelper.ToV1Patch <V1NeonNodeTask>(patch), nodeTask.Name()); } } catch (Exception e) { log.LogWarn(e); } }