public void ShouldThrowExceptionWhenConstructorArgumentIsStringEmpty() { NodeUriBuilderHelperToTest = new NodeUriBuilderHelper(string.Empty); }
public void ShouldThrowExceptionWhenConstructorArgumentStringIsIvalidUri() { NodeUriBuilderHelperToTest = new NodeUriBuilderHelper("invalid uri"); }
public void ShouldReturnCorrectJobTemplateUri() { NodeUriBuilderHelperToTest = new NodeUriBuilderHelper(UriToTest); Assert.IsTrue(NodeUriBuilderHelperToTest.GetJobTemplateUri() == JobTemplateUri); }
public void ShouldReturnCorrectCancelJobUri() { NodeUriBuilderHelperToTest = new NodeUriBuilderHelper(UriToTest); Assert.IsTrue(NodeUriBuilderHelperToTest.GetCancelJobUri(Guid) == CancelJobUri); }
public void ShouldInstantiateWhenConstructorArgumentStringIsIvalidUri() { NodeUriBuilderHelperToTest = new NodeUriBuilderHelper(UriToTest); Assert.IsNotNull(NodeUriBuilderHelperToTest); }
private void AssignJobToWorkerNodeWorker(Uri availableNode) { try { using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.OpenWithRetry(_retryPolicy); JobQueueItem jobQueueItem = null; using (var selectJobQueueItemCommand = new SqlCommand("[Stardust].[AcquireQueuedJob]", sqlConnection)) { selectJobQueueItemCommand.CommandType = CommandType.StoredProcedure; SqlParameter retVal = new SqlParameter("@idd", SqlDbType.UniqueIdentifier); retVal.Direction = ParameterDirection.ReturnValue; selectJobQueueItemCommand.Parameters.Add(retVal); using (var reader = selectJobQueueItemCommand.ExecuteReaderWithRetry(_retryPolicy)) { if (reader.HasRows) { reader.Read(); jobQueueItem = CreateJobQueueItemFromSqlDataReader(reader); } } } if (jobQueueItem == null) { sqlConnection.Close(); return; } var builderHelper = new NodeUriBuilderHelper(availableNode); var urijob = builderHelper.GetJobTemplateUri(); var response = _httpSender.PostAsync(urijob, jobQueueItem).Result; if (response != null && (response.IsSuccessStatusCode || response.StatusCode.Equals(HttpStatusCode.BadRequest))) { string sentToWorkerNodeUri = availableNode.ToString(); using (var sqlTransaction = sqlConnection.BeginTransaction()) { using (var insertIntoJobCommand = _createSqlCommandHelper.CreateInsertIntoJobCommand(jobQueueItem, sentToWorkerNodeUri, sqlConnection, sqlTransaction)) { if (response.IsSuccessStatusCode) { insertIntoJobCommand.Parameters.AddWithValue("@Result", DBNull.Value); } else { insertIntoJobCommand.Parameters.AddWithValue("@Result", response.ReasonPhrase); } insertIntoJobCommand.ExecuteNonQueryWithRetry(_retryPolicy); } using (var deleteJobQueueItemCommand = _createSqlCommandHelper.CreateDeleteFromJobQueueCommand(jobQueueItem.JobId, sqlConnection, sqlTransaction)) { deleteJobQueueItemCommand.ExecuteNonQueryWithRetry(_retryPolicy); } Retry(sqlTransaction.Commit); using (var insertIntoJobDetailsCommand = _createSqlCommandHelper.CreateInsertIntoJobDetailCommand(jobQueueItem.JobId, "Job Started", DateTime.UtcNow, sqlConnection)) { insertIntoJobDetailsCommand.ExecuteNonQueryWithRetry(_retryPolicy); } } urijob = builderHelper.GetUpdateJobUri(jobQueueItem.JobId); //what should happen if this response is not 200? var resp = _httpSender.PutAsync(urijob, null); } else { using (var sqlTransaction = sqlConnection.BeginTransaction()) { if (response == null) { var updateCommandText = @"UPDATE [Stardust].[WorkerNode] SET Alive = @Alive WHERE Url = @Url"; using (var command = new SqlCommand(updateCommandText, sqlConnection, sqlTransaction)) { command.Parameters.Add("@Alive", SqlDbType.Bit).Value = false; command.Parameters.Add("@Url", SqlDbType.NVarChar).Value = availableNode.ToString(); command.ExecuteNonQueryWithRetry(_retryPolicy); } } var commandText = "update [Stardust].[JobQueue] set Tagged = NULL where JobId = @Id"; using (var cmd = new SqlCommand(commandText, sqlConnection, sqlTransaction)) { cmd.Parameters.AddWithValue("@Id", jobQueueItem.JobId); cmd.ExecuteNonQuery(); } sqlTransaction.Commit(); } } } } catch (Exception exp) { this.Log().ErrorWithLineNumber(exp.Message, exp); throw; } }
private void CancelJobByJobIdWorker(Guid jobId) { try { using (var sqlConnection = new SqlConnection(_connectionString)) { sqlConnection.OpenWithRetry(_retryPolicy); using (var sqlTransaction = sqlConnection.BeginTransaction()) { string sentToWorkerNodeUri = null; using (var createSelectWorkerNodeUriCommand = _createSqlCommandHelper.CreateSelectWorkerNodeCommand(jobId, sqlConnection, sqlTransaction)) { using (var selectSqlReader = createSelectWorkerNodeUriCommand.ExecuteReaderWithRetry(_retryPolicy)) { if (selectSqlReader.HasRows) { selectSqlReader.Read(); sentToWorkerNodeUri = selectSqlReader.GetString(selectSqlReader.GetOrdinal("SentToWorkerNodeUri")); } } } if (sentToWorkerNodeUri != null) { var builderHelper = new NodeUriBuilderHelper(sentToWorkerNodeUri); var uriCancel = builderHelper.GetCancelJobUri(jobId); var response = _httpSender.DeleteAsync(uriCancel).Result; if (response != null && response.IsSuccessStatusCode) { using (var createUpdateCancellingResultCommand = _createSqlCommandHelper.CreateUpdateCancellingResultCommand(jobId, sqlConnection, sqlTransaction)) { createUpdateCancellingResultCommand.ExecuteNonQueryWithRetry(_retryPolicy); } using (var deleteFromJobDefinitionsCommand = _createSqlCommandHelper.CreateDeleteFromJobQueueCommand(jobId, sqlConnection, sqlTransaction)) { deleteFromJobDefinitionsCommand.ExecuteNonQueryWithRetry(_retryPolicy); } Retry(sqlTransaction.Commit); } else { this.Log().ErrorWithLineNumber("Could not send cancel to node. JobId: " + jobId); } } } } } catch (Exception exp) { this.Log().ErrorWithLineNumber(exp.Message, exp); throw; } }