-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Logs upload method request handler (#956)
* Blob uploader hookup * Add JsonConstructor attribute * Add tests * Add tests
- Loading branch information
1 parent
fe8457f
commit e064a59
Showing
9 changed files
with
228 additions
and
72 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Agent.Core.Requests | ||
{ | ||
using Microsoft.Azure.Devices.Edge.Agent.Core.Logs; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
using Newtonsoft.Json; | ||
|
||
public class LogsUploadRequest | ||
{ | ||
public LogsUploadRequest(string id, LogsContentEncoding encoding, LogsContentType contentType, string sasUrl) | ||
{ | ||
this.Id = Preconditions.CheckNonWhiteSpace(id, nameof(id)); | ||
this.Encoding = encoding; | ||
this.ContentType = contentType; | ||
this.SasUrl = sasUrl; | ||
} | ||
|
||
[JsonConstructor] | ||
LogsUploadRequest(string id, LogsContentEncoding? encoding, LogsContentType? contentType, string sasUrl) | ||
: this(id, encoding.HasValue ? encoding.Value : LogsContentEncoding.None, contentType.HasValue ? contentType.Value : LogsContentType.Json, sasUrl) | ||
{ | ||
} | ||
|
||
public string Id { get; } | ||
public LogsContentEncoding Encoding { get; } | ||
public LogsContentType ContentType { get; } | ||
public string SasUrl { get; } | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
edge-agent/src/Microsoft.Azure.Devices.Edge.Agent.Core/requests/LogsUploadRequestHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
namespace Microsoft.Azure.Devices.Edge.Agent.Core.Requests | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Devices.Edge.Agent.Core.Logs; | ||
using Microsoft.Azure.Devices.Edge.Util; | ||
|
||
public class LogsUploadRequestHandler : RequestHandlerBase<LogsUploadRequest, object> | ||
{ | ||
readonly ILogsUploader logsUploader; | ||
readonly ILogsProvider logsProvider; | ||
|
||
public LogsUploadRequestHandler(ILogsUploader logsUploader, ILogsProvider logsProvider) | ||
{ | ||
this.logsProvider = Preconditions.CheckNotNull(logsProvider, nameof(logsProvider)); | ||
this.logsUploader = Preconditions.CheckNotNull(logsUploader, nameof(logsUploader)); | ||
} | ||
|
||
public override string RequestName => "UploadLogs"; | ||
|
||
protected override async Task<Option<object>> HandleRequestInternal(Option<LogsUploadRequest> payloadOption) | ||
{ | ||
LogsUploadRequest payload = payloadOption.Expect(() => new ArgumentException("Request payload not found")); | ||
var moduleLogOptions = new ModuleLogOptions(payload.Id, payload.Encoding, payload.ContentType); | ||
byte[] logBytes = await this.logsProvider.GetLogs(moduleLogOptions, CancellationToken.None); | ||
await this.logsUploader.Upload(payload.SasUrl, payload.Id, logBytes, payload.Encoding, payload.ContentType); | ||
return Option.None<object>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.