public EndpointHealth(DateTime checkTimeUtc, TimeSpan responseTime, EndpointStatus status, IReadOnlyDictionary<string, string> details = null) { CheckTimeUtc = checkTimeUtc; ResponseTime = responseTime; Status = status; Details = details ?? new Dictionary<string, string>(); }
private void Then_monitor_should_observe_endpoint_status_being_STATUS_with_error(EndpointStatus status, string error) { Wait.Until(Timeouts.Default, () => _client.GetEndpointDetails(_identifier), e => e.Status == status && e.Details["reason"] == error, "Endpoint status did not changed to " + status + " with error: " + error); }
public virtual void AddEndpointCheckResult(int endpointId, EndpointCheckResult result, bool isFinal) { var status = _endpointStates.AddOrUpdate(endpointId, (id) => { var es = new EndpointStatus(); es.InProgressResults = new List <EndpointCheckResult> { result }; return(es); }, (id, oldStatus) => { var es = oldStatus.DeepClone(); if (es.InProgressResults == null) { es.InProgressResults = new List <EndpointCheckResult>(); } es.InProgressResults.Add(result); return(es); }); PostProcessStatus(endpointId, status, isFinal); }
private void Then_monitor_should_observe_endpoint_status_being_STATUS(EndpointStatus status) { Wait.Until(Timeouts.Default, () => _client.GetEndpointDetails(_identifier), e => e.Status == status, "Endpoint status did not changed"); }
public ServiceResponse(T response, EndpointStatus status) { Response = response; Headers = new ServiceHeaders { Status = status }; }
public EndpointHealth(DateTime checkTimeUtc, TimeSpan responseTime, EndpointStatus status, IReadOnlyDictionary <string, string> details = null) { CheckTimeUtc = checkTimeUtc; ResponseTime = responseTime; Status = status; Details = details ?? new Dictionary <string, string>(); }
private void NotifyUpDown(Endpoint endpoint, EndpointStatus status) { if (status.InProgressResults == null || !status.InProgressResults.Any()) { return; } if (status.InProgressResults.Last().Success) { if (status.IsUp == false || status.IsUp == null) { // Endpoint has just come up _notifier.NotifyUp(endpoint, status.DownAsOf); } // If old status is true, don't notify that it's up } else { if (status.IsUp == null || status.IsUp == true) { // Endpoint has just gone down _notifier.NotifyDown(endpoint, status.DownAsOf ?? status.InProgressResults.Last().Start, status.InProgressResults.Last().Error); } else if (status.LastFinishedResults?.Last().Error?.ToString() != status.InProgressResults.Last().Error?.ToString()) { // Endpoint is down, but with a different error _notifier.NotifyDown(endpoint, status.DownAsOf ?? status.InProgressResults.Last().Start, status.InProgressResults.Last().Error); } } }
public static void TimestampMonitoring(IMemoryCache cache, EndpointStatus endpoint, TelemetryClient telemetry) { if (!cache.TryGetValue(CacheKeys.HitmanTimestampKey, out dynamic _)) { cache.Set(CacheKeys.HitmanTimestampKey, string.Empty, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromSeconds(60))); var json = JObject.Parse(endpoint.Status); if (DateTime.TryParse((string)json["timestamp"], out DateTime timestamp)) { if (timestamp <= DateTime.UtcNow.Add(new TimeSpan(0, -10, 0))) { if (!cache.TryGetValue(CacheKeys.TimestampNotUpdatedBurnout, out dynamic _)) { try { telemetry.TrackEvent("HitmanTimestampNotUpdated"); cache.Set(CacheKeys.TimestampNotUpdatedBurnout, string.Empty, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromMinutes(30))); } catch { } } } } } }
public static void EnsureStatusChanged(this RestClient client, Guid endpointId, EndpointStatus expectedStatus) { Wait.Until(Timeouts.Default, () => client.GetEndpointDetails(endpointId), e => e.Status == expectedStatus, "Endpoint status did not changed to " + expectedStatus); }
private EndpointHealth(DateTime checkTimeUtc, TimeSpan responseTime, EndpointStatus status, IReadOnlyDictionary<string, string> details) { CheckTimeUtc = checkTimeUtc; ResponseTime = responseTime; Status = status; Details = details; }
private void PostProcessStatus(int endpointId, EndpointStatus status, bool finalizeResults) { var endpoint = GetEndpointById(endpointId); if (endpoint == null) { return; } NotifyNewestCheckResult(endpoint, status.InProgressResults?.LastOrDefault()); if (finalizeResults) { NotifyUpDown(endpoint, status); status.LastFinishedResults = status.InProgressResults; status.InProgressResults = null; } if (status.IsUp == null || status.IsUp == true) { status.DownAsOf = null; } else { status.DownAsOf ??= status.LastFinishedResults?.FirstOrDefault(r => !r.Success)?.Start; } }
public void GetEndpoint_should_return_endpoint_information_with_details(EndpointStatus status) { Guid id = Guid.NewGuid(); var healthSampler = new Mock <IHealthSampler>(); var endpoint = new Endpoint(id, MonitorMock.GetMock("monitor").Object, "address", "name", "group"); var token = new CancellationToken(); var endpointHealth = new EndpointHealth(DateTime.UtcNow, TimeSpan.FromSeconds(1), status, new Dictionary <string, string> { { "a", "b" }, { "c", "d" } }); healthSampler.Setup(s => s.CheckHealth(endpoint, token)).Returns(Task.FromResult(endpointHealth)); endpoint.CheckHealth(healthSampler.Object, token).Wait(); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult <EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(status, result.Content.Status); Assert.Equal(endpointHealth.CheckTimeUtc, result.Content.LastCheckUtc); Assert.Equal(endpointHealth.ResponseTime, result.Content.LastResponseTime); Assert.Equal(endpointHealth.Details, result.Content.Details); }
/// <summary> /// Verifies that the service is alive. If the service is not alive, then an issue is logged /// that will be reported back to the user. /// </summary> private void CheckEndpointStatus(EndpointStatus status) { if (status == EndpointStatus.Deprecated) { _progressReport.ReportIssue(LocalizedStrings.ServerEndpointDeprecated); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogDebug("HitmanForumStatusSeekerHostedService is starting"); stoppingToken.Register(() => _logger.LogDebug("HitmanForumStatusSeekerHostedService has been canceled")); using var scope = _scopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService <DatabaseContext>(); var manager = new EventManager(db, _logger, _cache); while (!stoppingToken.IsCancellationRequested) { _logger.LogDebug("HitmanForumStatusSeekerHostedService is running"); var endpointException = new EndpointStatusException(EndpointName.HitmanForum); try { EndpointStatus endpoint = await _client.GetStatusAsync(); if (endpoint.State == EndpointState.Up) { _cache.Set(CacheKeys.HitmanForumKey, endpoint, new MemoryCacheEntryOptions() .SetPriority(CacheItemPriority.NeverRemove)); manager.RemoveCache(new List <string> { CacheKeys.HitmanForumErrorCountKey, CacheKeys.HitmanForumErrorEventKey }); } else { endpointException.Status = endpoint.Status; } } catch (Exception e) { _logger.LogError(e, "Exception in the HitmanForumStatusSeekerHostedService"); endpointException.Status = "Unhandled error"; endpointException.Message = e.Message; } finally { if (!string.IsNullOrEmpty(endpointException.Status)) { _cache.Set(CacheKeys.HitmanForumExceptionKey, endpointException, new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromSeconds(45))); await manager.InsertEndpointExceptionAsync(endpointException); } } await Task.Delay(TimeSpan.FromSeconds(30), stoppingToken); } _logger.LogDebug("HitmanForumStatusSeekerHostedService has been stopped"); }
public EndpointEntry(Endpoint endpoint) { this.endpoint = endpoint; this.lastPing = DateTime.UtcNow; this.pingDelay = 32; this.status = EndpointStatus.Waiting; }
public void Report( Endpoint endpoint, EndpointStatus status ) { var message = BuildMessage( endpoint, status ); using ( var client = BuildSmtpClient() ) { client.Send( message ); } }
public void Report(Endpoint endpoint, EndpointStatus status) { var message = BuildMessage(endpoint, status); using (var client = BuildSmtpClient()) { client.Send(message); } }
/// <summary> /// Initializes a new instance of the /// DefinitionEndpointCreateParameters class with required arguments. /// </summary> public DefinitionEndpointCreateParameters(string domainName, EndpointStatus status) : this() { if (domainName == null) { throw new ArgumentNullException("domainName"); } this.DomainName = domainName; this.Status = status; }
public async Task ApiPortService_GetAvailableFormatsAsync(ApiPortService apiPortService, EndpointStatus expectedStatus) { var expected = new List<string> { "Json", "HTML", "Excel" }; var serviceResponse = await apiPortService.GetResultFormatsAsync(); var headers = serviceResponse.Headers; var result = serviceResponse.Response; Assert.Equal(expectedStatus, headers.Status); Assert.Equal(expected.Count(), result.Count()); Assert.Equal(0, expected.Except(result.Select(r => r.DisplayName)).Count()); }
public async Task DetailsShouldDisplayEndpointInfo() { var state = new EndpointStatus(); _stateService.GetStatus(2).Returns(state); var result = await _controller.Details(2) as ViewResult; Assert.IsNotNull(result); Assert.AreSame(state, result.ViewData["State"]); Assert.AreEqual("C", (result.Model as EndpointViewModel).Name); }
private MailMessage BuildMessage( Endpoint endpoint, EndpointStatus status ) { var message = new MailMessage(); if ( !String.IsNullOrEmpty( FromAddress ) ) { message.From = new MailAddress( FromAddress ); } message.To.Add( ToAddress ); message.Subject = String.Format( "Endpoint is {0}: {1}", status.Status, endpoint.Description ); var template = GetTemplate(); template = template.Replace( "##Description##", endpoint.Description ); template = template.Replace( "##Url##", endpoint.Url ); template = template.Replace( "##Status##", status.Status.ToString() ); template = template.Replace( "##Timestamp##", status.Timestamp.ToString() ); message.Body = template; return message; }
private MailMessage BuildMessage(Endpoint endpoint, EndpointStatus status) { var message = new MailMessage(); if (!String.IsNullOrEmpty(FromAddress)) { message.From = new MailAddress(FromAddress); } message.To.Add(ToAddress); message.Subject = String.Format("Endpoint is {0}: {1}", status.Status, endpoint.Description); var template = GetTemplate(); template = template.Replace("##Description##", endpoint.Description); template = template.Replace("##Url##", endpoint.Url); template = template.Replace("##Status##", status.Status.ToString()); template = template.Replace("##Timestamp##", status.Timestamp.ToString()); message.Body = template; return(message); }
public void GetEndpoint_should_return_endpoint_information_with_details(EndpointStatus status) { var id = Guid.NewGuid(); var endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(id, "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); var endpointHealth = new EndpointHealth(_utcNow, TimeSpan.FromSeconds(5), status, new Dictionary <string, string> { { "abc", "def" } }); endpoint.UpdateHealth(endpointHealth); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult <EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(status, result.Content.Status); Assert.Equal(endpointHealth.CheckTimeUtc, result.Content.LastCheckUtc); Assert.Equal(endpointHealth.ResponseTime, result.Content.LastResponseTime); Assert.Equal(endpointHealth.Details, result.Content.Details); }
public async Task ApiPortService_GetDocIdsWithValidDocIdAsync(ApiPortService apiPortService, EndpointStatus expectedStatus) { var docIds = new List<string> { "T:System.Console", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Object,System.Xml.Serialization.XmlSerializationWriter)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces,System.String)" }; var serviceResponse = await apiPortService.QueryDocIdsAsync(docIds); var headers = serviceResponse.Headers; var result = serviceResponse.Response; Assert.Equal(expectedStatus, headers.Status); Assert.Equal(docIds.Count(), result.Count()); Assert.Equal(0, docIds.Except(result.Select(r => r.Definition.DocId)).Count()); }
public EndpointStats(DateTime checkTimeUtc, EndpointStatus status, TimeSpan responseTime) { CheckTimeUtc = checkTimeUtc; Status = status; ResponseTime = responseTime; }
private void When_client_request_endpoint_health_update_with_credentials(Guid endpointId, EndpointStatus status, Credentials credentials) { var updates = new [] { new EndpointHealthUpdate { EndpointId = endpointId, Status = status, CheckTimeUtc = DateTime.UtcNow, ResponseTime = TimeSpan.FromSeconds(5) } }; PostHealth(updates, credentials); }
public void GetEndpoint_should_return_endpoint_information_with_details(EndpointStatus status) { Guid id = Guid.NewGuid(); var healthSampler = new Mock<IHealthSampler>(); var endpoint = new Endpoint(id, MonitorMock.GetMock("monitor").Object, "address", "name", "group"); var token = new CancellationToken(); var endpointHealth = new EndpointHealth(DateTime.UtcNow, TimeSpan.FromSeconds(1), status, new Dictionary<string, string> { { "a", "b" }, { "c", "d" } }); healthSampler.Setup(s => s.CheckHealth(endpoint, token)).Returns(Task.FromResult(endpointHealth)); endpoint.CheckHealth(healthSampler.Object, token).Wait(); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult<EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(status, result.Content.Status); Assert.Equal(endpointHealth.CheckTimeUtc, result.Content.LastCheckUtc); Assert.Equal(endpointHealth.ResponseTime, result.Content.LastResponseTime); Assert.Equal(endpointHealth.Details, result.Content.Details); }
private void Then_monitor_should_observe_endpoint_status_being_STATUS(EndpointStatus status) { _client.EnsureStatusChanged(_identifier, status); }
private void Then_the_endpoint_status_should_be_provided(EndpointStatus status) { Assert.Equal(status, _details.Status); }
public async Task <EndpointStatus> GetStatusAsync() { HttpResponseMessage response = null; var endpoint = new EndpointStatus(); try { response = await HttpClient.GetAsync("/status"); response.EnsureSuccessStatusCode(); if (!Utilities.IsJsonResponse(response.Content.Headers)) { endpoint.Status = "Bad data returned by authentication server"; } else { endpoint.State = EndpointState.Up; } } catch (TimeoutRejectedException) { endpoint.Status = "Authentication server connection timeout"; } catch (BrokenCircuitException) { endpoint.Status = "Authentication server is down"; } catch (HttpRequestException e) { if (response != null) { switch (response.StatusCode) { case HttpStatusCode.InternalServerError: endpoint.Status = "Authentication server critical error"; break; case HttpStatusCode.BadGateway: case HttpStatusCode.ServiceUnavailable: case HttpStatusCode.GatewayTimeout: endpoint.State = EndpointState.Maintenance; endpoint.Status = "Authentication server unavailable"; break; default: endpoint.Status = string.Format( "Error code returned by authentication server - error HTTP {0}", response.StatusCode); break; } } else { endpoint.Status = e.Message; } } catch (OperationCanceledException) { endpoint.Status = "Authentication server connection canceled"; } finally { if (endpoint.State == EndpointState.Up) { endpoint.Status = await response.Content.ReadAsStringAsync(); } else { TelemetryClient.TrackEvent("HitmanTransientHTTPError"); } } return(endpoint); }
private static extern int QISRAudioWrite(string sessionID, byte[] waveData, uint waveLen, SampleStatus audioStatus, ref EndpointStatus epStatus, ref RecognitionStatus recogStatus);
public void Report(Endpoint endpoint, EndpointStatus status) { Console.WriteLine("{0} ({1}) is {2} as of {3}", endpoint.Description, endpoint.Url, status.Status, status.Timestamp); }
private void AssertStateEquality(bool?expectedIsUp, string expectedMessage, EndpointStatus actualStatus) { Assert.AreEqual(expectedIsUp, actualStatus?.IsUp); Assert.AreEqual(expectedMessage, actualStatus?.Error?.Message); }
public void Report( Endpoint endpoint, EndpointStatus status ) { Console.WriteLine( "{0} ({1}) is {2} as of {3}", endpoint.Description, endpoint.Url, status.Status, status.Timestamp ); }
private void SetupHttpEndpoint(HttpStatusCode httpStatusCode, string name, string group, string[] tags, EndpointStatus expectedStatus) { var endpoint = MockWebEndpointFactory.CreateNew(); _endpoints.Add(endpoint); endpoint.SetupStatusResponse(httpStatusCode); var identifier = _client.RegisterEndpoint(MonitorTypes.Http, endpoint.StatusAddress, group, name, tags); _client.EnsureStatusChanged(identifier, expectedStatus); }
public async Task ApiPortService_GetAvailableFormatsAsync(ApiPortService apiPortService, EndpointStatus expectedStatus) { var expected = new List <string> { "Json", "HTML", "Excel" }; var serviceResponse = await apiPortService.GetResultFormatsAsync(); var headers = serviceResponse.Headers; var result = serviceResponse.Response; Assert.Equal(expectedStatus, headers.Status); Assert.Equal(expected.Count(), result.Count()); Assert.Equal(0, expected.Except(result.Select(r => r.DisplayName)).Count()); }
public void GetEndpoint_should_return_endpoint_information_with_details(EndpointStatus status) { var id = Guid.NewGuid(); var endpoint = new Endpoint(TimeCoordinatorMock.Get().Object, new EndpointIdentity(id, "monitor", "address"), new EndpointMetadata("name", "group", new[] { "t1", "t2" }, EndpointMetadata.DefaultMonitorTag, DateTime.UtcNow, DateTime.UtcNow)); var endpointHealth = new EndpointHealth(_utcNow, TimeSpan.FromSeconds(5), status, new Dictionary<string, string> { { "abc", "def" } }); endpoint.UpdateHealth(endpointHealth); _endpointRegistry.Setup(r => r.GetById(id)).Returns(endpoint); var result = _controller.GetEndpoint(id) as OkNegotiatedContentResult<EndpointDetails>; Assert.NotNull(result); AssertEndpoint(endpoint, result.Content); Assert.Equal(status, result.Content.Status); Assert.Equal(endpointHealth.CheckTimeUtc, result.Content.LastCheckUtc); Assert.Equal(endpointHealth.ResponseTime, result.Content.LastResponseTime); Assert.Equal(endpointHealth.Details, result.Content.Details); }
public async Task ApiPortService_GetDocIdsWithValidDocIdAsync(ApiPortService apiPortService, EndpointStatus expectedStatus) { var docIds = new List <string> { "T:System.Console", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Object,System.Xml.Serialization.XmlSerializationWriter)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.Stream,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.IO.TextWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces)", "M:System.Xml.Serialization.XmlSerializer.Serialize(System.Xml.XmlWriter,System.Object,System.Xml.Serialization.XmlSerializerNamespaces,System.String)" }; var serviceResponse = await apiPortService.QueryDocIdsAsync(docIds); var headers = serviceResponse.Headers; var result = serviceResponse.Response; Assert.Equal(expectedStatus, headers.Status); Assert.Equal(docIds.Count(), result.Count()); Assert.Equal(0, docIds.Except(result.Select(r => r.Definition.DocId)).Count()); }
static void Main(string[] args) { string accesKeyId = ""; string accessKeySecret = ""; string trainingImage = ""; string roleArn = ""; string trainingJobName = $"ontology-training-job-{DateTime.UtcNow.Ticks}"; string endpointName = $"ontology-endpoint-{DateTime.UtcNow.Ticks}"; using (AmazonS3Client client = new AmazonS3Client(accesKeyId, accessKeySecret, Amazon.RegionEndpoint.EUCentral1)) { TransferUtility fileTransferUtility = new TransferUtility(client); // upload our csv training\test files using (AmazonSageMakerClient awsSageMakerClient = new AmazonSageMakerClient(accesKeyId, accessKeySecret, Amazon.RegionEndpoint.EUCentral1)) { CreateTrainingJobResponse response = awsSageMakerClient.CreateTrainingJobAsync(new CreateTrainingJobRequest() { AlgorithmSpecification = new AlgorithmSpecification() { TrainingInputMode = TrainingInputMode.File, TrainingImage = trainingImage }, OutputDataConfig = new OutputDataConfig() { S3OutputPath = "https://s3.eu-central-1.amazonaws.com/sagemaker-ovechko/sagemaker/test-csv/output" }, ResourceConfig = new ResourceConfig() { InstanceCount = 1, InstanceType = TrainingInstanceType.MlM4Xlarge, VolumeSizeInGB = 5 }, TrainingJobName = trainingJobName, HyperParameters = new Dictionary <string, string>() { { "eta", "0.1" }, { "objective", "multi:softmax" }, { "num_round", "5" }, { "num_class", "3" } }, StoppingCondition = new StoppingCondition() { MaxRuntimeInSeconds = 3600 }, RoleArn = roleArn, InputDataConfig = new List <Channel>() { new Channel() { ChannelName = "train", DataSource = new DataSource() { S3DataSource = new S3DataSource() { S3DataType = S3DataType.S3Prefix, S3Uri = "https://s3.eu-central-1.amazonaws.com/sagemaker-ovechko/sagemaker/test-csv/train/", S3DataDistributionType = S3DataDistribution.FullyReplicated } }, ContentType = "csv", CompressionType = Amazon.SageMaker.CompressionType.None }, new Channel() { ChannelName = "validation", DataSource = new DataSource() { S3DataSource = new S3DataSource() { S3DataType = S3DataType.S3Prefix, S3Uri = "https://s3.eu-central-1.amazonaws.com/sagemaker-ovechko/sagemaker/test-csv/validation/", S3DataDistributionType = S3DataDistribution.FullyReplicated } }, ContentType = "csv", CompressionType = Amazon.SageMaker.CompressionType.None } } }).Result; string modelName = $"{trainingJobName}-model"; DescribeTrainingJobResponse info = new DescribeTrainingJobResponse() { TrainingJobStatus = TrainingJobStatus.InProgress }; while (info.TrainingJobStatus == TrainingJobStatus.InProgress) { info = awsSageMakerClient.DescribeTrainingJobAsync(new DescribeTrainingJobRequest() { TrainingJobName = trainingJobName }).Result; if (info.TrainingJobStatus == TrainingJobStatus.InProgress) { Logger.Info("Training job creation is in progress..."); Thread.Sleep(10000); } } Logger.Info($"Training job creation has been finished. With status {info.TrainingJobStatus.ToString()}. {info.FailureReason}"); if (info.TrainingJobStatus == TrainingJobStatus.Completed) { CreateModelResponse modelCreationInfo = awsSageMakerClient.CreateModelAsync(new CreateModelRequest() { ModelName = modelName, ExecutionRoleArn = roleArn, PrimaryContainer = new ContainerDefinition() { ModelDataUrl = info.ModelArtifacts.S3ModelArtifacts, Image = trainingImage } }).Result; string endpointConfigName = $"{endpointName}-config"; awsSageMakerClient.CreateEndpointConfigAsync(new CreateEndpointConfigRequest() { EndpointConfigName = endpointConfigName, ProductionVariants = new List <ProductionVariant>() { new ProductionVariant() { InstanceType = ProductionVariantInstanceType.MlM4Xlarge, InitialVariantWeight = 1, InitialInstanceCount = 1, ModelName = modelName, VariantName = "AllTraffic" } } }); CreateEndpointResponse endpointCreationInfo = awsSageMakerClient.CreateEndpointAsync(new CreateEndpointRequest() { EndpointConfigName = endpointConfigName, EndpointName = endpointName }).Result; EndpointStatus currentStatus = EndpointStatus.Creating; while (currentStatus == EndpointStatus.Creating) { currentStatus = awsSageMakerClient.DescribeEndpointAsync(new DescribeEndpointRequest() { EndpointName = endpointName }).Result.EndpointStatus; if (currentStatus == EndpointStatus.Creating) { Logger.Info("Endpoint creation is in progress..."); Thread.Sleep(10000); } } Logger.Info("Endpoint creation has been finished."); if (currentStatus == EndpointStatus.InService) { using (AmazonSageMakerRuntimeClient sageMakerRuntimeClient = new AmazonSageMakerRuntimeClient(accesKeyId, accessKeySecret, Amazon.RegionEndpoint.EUCentral1)) { using (MemoryStream ms = new MemoryStream()) { GetObjectResponse s3Response = client.GetObjectAsync("sagemaker-ovechko", "sagemaker/test-csv/test/test.csv").Result; s3Response.ResponseStream.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(ms)) { string csv = sr.ReadToEnd(); csv = csv.Replace("", string.Empty); using (MemoryStream ms2 = new MemoryStream(Encoding.ASCII.GetBytes(csv))) { InvokeEndpointResponse endpointResponseInfo = sageMakerRuntimeClient.InvokeEndpointAsync(new InvokeEndpointRequest() { ContentType = "text/csv", EndpointName = endpointName, Body = ms2, }).Result; using (StreamReader sr2 = new StreamReader(endpointResponseInfo.Body)) { string endpointResponseBody = sr2.ReadToEnd(); Logger.Info(endpointResponseBody); } } } } Logger.Info("Performing clean up..."); awsSageMakerClient.DeleteEndpointAsync(new DeleteEndpointRequest() { EndpointName = endpointName }); awsSageMakerClient.DeleteEndpointConfigAsync(new DeleteEndpointConfigRequest() { EndpointConfigName = endpointConfigName }); awsSageMakerClient.DeleteModelAsync(new DeleteModelRequest() { ModelName = modelName }); Logger.Info("Clean up finished."); } } } } } Console.ReadLine(); }