public async Task <int> RegisterRequestedAsync([FromBody] ComputeClusterRegistrationInformation registerInfo, CancellationToken token) { try { var nodeName = registerInfo.NodeName.ToLowerInvariant(); this.logger.LogInformation("RegisterRequested, NodeName {0}, Distro {1} ", nodeName, registerInfo.DistroInfo); var nodeTable = this.utilities.GetNodesTable(); var jsonTableEntity = new JsonTableEntity(this.utilities.NodesPartitionKey, this.utilities.GetRegistrationKey(nodeName), registerInfo); var result = await nodeTable.ExecuteAsync(TableOperation.InsertOrReplace(jsonTableEntity), null, null, token); using (HttpResponseMessage r = new HttpResponseMessage((HttpStatusCode)result.HttpStatusCode)) { r.EnsureSuccessStatusCode(); } // 5 minutes return(this.utilities.Option.RegistrationIntervalSeconds * 1000); } catch (Exception ex) { this.logger.LogError(ex, "RegisterRequested. NodeName {0}, Distro {1}", registerInfo.NodeName, registerInfo.DistroInfo); } return(this.utilities.Option.RetryOnFailureSeconds * 1000); }
public async T.Task RegisterNodeAsync(ComputeClusterRegistrationInformation info, CancellationToken token) { var nodeName = info.NodeName.ToLowerInvariant(); this.Logger.Information("RegisterRequested, NodeName {0}, Distro {1} ", nodeName, info.DistroInfo); var nodeTable = this.Utilities.GetNodesTable(); var jsonTableEntity = new JsonTableEntity(this.Utilities.NodesPartitionKey, this.Utilities.GetRegistrationKey(nodeName), info); var result = await nodeTable.ExecuteAsync(TableOperation.InsertOrReplace(jsonTableEntity), null, null, token); using (HttpResponseMessage r = new HttpResponseMessage((HttpStatusCode)result.HttpStatusCode)) { r.EnsureSuccessStatusCode(); } }
public async T.Task <int> RegisterRequestedAsync([FromBody] ComputeClusterRegistrationInformation registerInfo, CancellationToken token) { try { await this.register.RegisterNodeAsync(registerInfo, token); // 5 minutes return(this.utilities.Option.RegistrationIntervalSeconds * 1000); } catch (Exception ex) { this.logger.Error(ex, "RegisterRequested. NodeName {0}, Distro {1}", registerInfo.NodeName, registerInfo.DistroInfo); } return(this.utilities.Option.RetryOnFailureSeconds * 1000); }
public async Task <IActionResult> GetAsync(string name, CancellationToken token) { name = name.ToLowerInvariant(); var registrationKey = this.utilities.GetRegistrationKey(name); var nodes = this.utilities.GetNodesTable(); var result = await nodes.ExecuteAsync(TableOperation.Retrieve <JsonTableEntity>(this.utilities.NodesPartitionKey, registrationKey), null, null, token); if (!result.IsSuccessfulStatusCode()) { return(new StatusCodeResult(result.HttpStatusCode)); } ComputeClusterRegistrationInformation registerInfo = (result.Result as JsonTableEntity)?.GetObject <ComputeClusterRegistrationInformation>(); var heartbeatKey = this.utilities.GetHeartbeatKey(name); result = await nodes.ExecuteAsync(TableOperation.Retrieve <JsonTableEntity>(this.utilities.NodesPartitionKey, heartbeatKey), null, null, token); if (!result.IsSuccessfulStatusCode()) { return(new StatusCodeResult(result.HttpStatusCode)); } var entity = result.Result as JsonTableEntity; ComputeClusterNodeInformation nodeInfo = entity?.GetObject <ComputeClusterNodeInformation>(); var node = new Node() { NodeRegistrationInfo = registerInfo, Name = name, }; if (entity?.Timestamp.AddSeconds(this.utilities.Option.MaxMissedHeartbeats * this.utilities.Option.HeartbeatIntervalSeconds) > DateTimeOffset.UtcNow) { node.Health = NodeHealth.OK; node.RunningJobCount = nodeInfo.Jobs.Count; node.EventCount = 5; } else { node.Health = NodeHealth.Error; } node.State = NodeState.Online; var nodeDetails = new NodeDetails() { NodeInfo = node, Jobs = nodeInfo?.Jobs, }; var metricsKey = this.utilities.GetMinuteHistoryKey(); result = await nodes.ExecuteAsync(TableOperation.Retrieve <JsonTableEntity>(this.utilities.GetNodePartitionKey(name), metricsKey), null, null, token); if (!result.IsSuccessfulStatusCode()) { return(new StatusCodeResult(result.HttpStatusCode)); } var historyEntity = result.Result as JsonTableEntity; nodeDetails.History = historyEntity.GetObject <MetricHistory>(); return(new OkObjectResult(nodeDetails)); }