Merge branch 'october-integration' into vertigo-davidb-unrecognized-command-behavior
This commit is contained in:
Коммит
f70614fcaf
|
@ -718,6 +718,27 @@ function InitializeEnvironment()
|
|||
}
|
||||
}
|
||||
|
||||
# Remove incorrectly duplicated files from the WebJob
|
||||
function FixWebJobZip()
|
||||
{
|
||||
Param(
|
||||
[Parameter(Mandatory=$true,Position=0)] [string] $filePath
|
||||
)
|
||||
$zipfile = get-item $filePath
|
||||
$zip = [System.IO.Compression.ZipFile]::Open($zipfile.FullName, "Update")
|
||||
|
||||
$entries = $zip.Entries.Where({$_.FullName.Contains("EventProcessor-WebJob/settings.job")})
|
||||
foreach ($entry in $entries) { $entry.Delete() }
|
||||
|
||||
$entries = $zip.Entries.Where({$_.FullName.Contains("EventProcessor-WebJob/Simulator")})
|
||||
foreach ($entry in $entries) { $entry.Delete() }
|
||||
|
||||
$entries = $zip.Entries.Where({$_.FullName.Contains("DeviceSimulator-WebJob/EventProcessor")})
|
||||
foreach ($entry in $entries) { $entry.Delete() }
|
||||
|
||||
$zip.Dispose()
|
||||
}
|
||||
|
||||
# Variable initialization
|
||||
[int]$global:envSettingsChanges = 0;
|
||||
$global:timeStampFormat = "o"
|
||||
|
@ -729,6 +750,9 @@ $global:version = "0.9"
|
|||
# Load System.Web
|
||||
Add-Type -AssemblyName System.Web
|
||||
|
||||
# Load System.IO.Compression.FileSystem
|
||||
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
||||
|
||||
# Make sure Azure PowerShell modules are loaded
|
||||
if ((Get-Module | where {$_.Name -match "Azure"}) -eq $Null)
|
||||
{
|
||||
|
|
|
@ -68,6 +68,7 @@ if ($cloudDeploy)
|
|||
$projectRoot = Join-Path $PSScriptRoot "..\.." -Resolve
|
||||
$webPackage = UploadFile ("$projectRoot\DeviceAdministration\Web\obj\{0}\Package\Web.zip" -f $configuration) $storageAccount.Name $resourceGroupName "WebDeploy"
|
||||
$params += @{packageUri=$webPackage}
|
||||
FixWebJobZip ("$projectRoot\WebJobHost\obj\{0}\Package\WebJobHost.zip" -f $configuration)
|
||||
$webJobPackage = UploadFile ("$projectRoot\WebJobHost\obj\{0}\Package\WebJobHost.zip" -f $configuration) $storageAccount.Name $resourceGroupName "WebDeploy"
|
||||
$params += @{webJobPackageUri=$webJobPackage}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,24 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
/// <param name="minTime">
|
||||
/// The cutoff time for Device Alert History items that should be returned.
|
||||
/// </param>
|
||||
/// <param name="minResults">
|
||||
/// The minimum number of items that should be returned, if possible,
|
||||
/// after <paramref name="minTime"/> or otherwise.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The latest Device Alert History items.
|
||||
/// </returns>
|
||||
public async Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime minTime)
|
||||
public async Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime minTime, int minResults)
|
||||
{
|
||||
if (minResults <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(
|
||||
"minResults",
|
||||
minResults,
|
||||
"minResults must be a positive integer.");
|
||||
}
|
||||
|
||||
return await this.alertsRepository.LoadLatestAlertHistoryAsync(minTime);
|
||||
return await this.alertsRepository.LoadLatestAlertHistoryAsync(minTime, minResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,6 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
{
|
||||
public interface IAlertsLogic
|
||||
{
|
||||
Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime cutoffTime);
|
||||
Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime cutoffTime, int minResults);
|
||||
}
|
||||
}
|
|
@ -56,13 +56,26 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
/// <param name="minTime">
|
||||
/// The cutoff time for Device Alert History items that should be returned.
|
||||
/// </param>
|
||||
/// <param name="minResults">
|
||||
/// The minimum number of items that should be returned, if possible,
|
||||
/// after <paramref name="minTime"/> or otherwise.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// The latest Device Alert History items.
|
||||
/// </returns>
|
||||
public async Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime minTime)
|
||||
public async Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(
|
||||
DateTime minTime,
|
||||
int minResults)
|
||||
{
|
||||
IEnumerable<IListBlobItem> blobs = await LoadApplicableListBlobItemsAsync(minTime);
|
||||
var result = new List<AlertHistoryItemModel>();
|
||||
if (minResults <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("minResults", minResults, "minResults must be a positive integer.");
|
||||
}
|
||||
|
||||
var filteredResult = new List<AlertHistoryItemModel>();
|
||||
var unfilteredResult = new List<AlertHistoryItemModel>();
|
||||
|
||||
IEnumerable<IListBlobItem> blobs = await LoadApplicableListBlobItemsAsync();
|
||||
|
||||
foreach (IListBlobItem blob in blobs)
|
||||
{
|
||||
|
@ -74,16 +87,38 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
|
||||
IEnumerable<AlertHistoryItemModel> segment = await ProduceAlertHistoryItemsAsync(blockBlob);
|
||||
|
||||
segment = segment.Where(
|
||||
t =>
|
||||
(t != null) &&
|
||||
t.Timestamp.HasValue &&
|
||||
(t.Timestamp.Value > minTime)).OrderByDescending(u => u.Timestamp);
|
||||
IEnumerable<AlertHistoryItemModel> filteredSegment = segment.Where(
|
||||
t => (t != null) && t.Timestamp.HasValue && (t.Timestamp.Value > minTime));
|
||||
|
||||
result.AddRange(segment);
|
||||
int unfilteredCount = segment.Count();
|
||||
int filteredCount = filteredSegment.Count();
|
||||
|
||||
unfilteredResult.AddRange(segment.OrderByDescending(t => t.Timestamp));
|
||||
filteredResult.AddRange(filteredSegment.OrderByDescending(t => t.Timestamp));
|
||||
|
||||
// Anything filtered and min entries?
|
||||
if ((filteredCount != unfilteredCount) && (filteredResult.Count >= minResults))
|
||||
{
|
||||
// already into items older than minTime
|
||||
break;
|
||||
}
|
||||
|
||||
// No more filtered entries and enough otherwise?
|
||||
if ((filteredCount == 0) && (unfilteredResult.Count >= minResults))
|
||||
{
|
||||
// we are past minTime and we have enough unfiltered results
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
if (filteredResult.Count >= minResults)
|
||||
{
|
||||
return filteredResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
return unfilteredResult.Take(minResults);
|
||||
}
|
||||
}
|
||||
|
||||
private static AlertHistoryItemModel ProduceAlertHistoryItem(ExpandoObject expandoObject)
|
||||
|
@ -190,7 +225,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
return models;
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<IListBlobItem>> LoadApplicableListBlobItemsAsync(DateTime cutoffTime)
|
||||
private async Task<IEnumerable<IListBlobItem>> LoadApplicableListBlobItemsAsync()
|
||||
{
|
||||
CloudBlobContainer container =
|
||||
await BlobStorageHelper.BuildBlobContainerAsync(
|
||||
|
@ -211,30 +246,12 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
null);
|
||||
});
|
||||
|
||||
var applicableBlobs = new List<IListBlobItem>();
|
||||
|
||||
if (blobs != null)
|
||||
{
|
||||
blobs = blobs.OrderByDescending(t => BlobStorageHelper.ExtractBlobItemDate(t));
|
||||
foreach (IListBlobItem blob in blobs)
|
||||
{
|
||||
if (blob == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
applicableBlobs.Add(blob);
|
||||
|
||||
// Allow 1 blob to be past the cutoff date.
|
||||
DateTime? timestamp = BlobStorageHelper.ExtractBlobItemDate(blob);
|
||||
if (timestamp.HasValue && timestamp.Value <= cutoffTime)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return applicableBlobs;
|
||||
return blobs;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,6 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Infr
|
|||
{
|
||||
public interface IAlertsRepository
|
||||
{
|
||||
Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime minTime);
|
||||
Task<IEnumerable<AlertHistoryItemModel>> LoadLatestAlertHistoryAsync(DateTime minTime, int minResults);
|
||||
}
|
||||
}
|
|
@ -23,13 +23,11 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
public class TelemetryApiController : WebApiControllerBase
|
||||
{
|
||||
private const double MAX_DEVICE_SUMMARY_AGE_MINUTES = 10.0;
|
||||
private const int MAX_HISTORY_ITEMS = 18;
|
||||
private const int DISPLAYED_HISTORY_ITEMS = 18;
|
||||
private const int MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD = 200;
|
||||
|
||||
private const double CautionAlertMaxMinutes = 91.0;
|
||||
private const double CriticalAlertMaxMinutes = 11.0;
|
||||
private const double MaxDeviceSummaryAgeMinutes = 10.0;
|
||||
private const int MaxHistoryItems = 18;
|
||||
private static readonly TimeSpan CautionAlertMaxDelta = TimeSpan.FromMinutes(91.0);
|
||||
private static readonly TimeSpan CriticalAlertMaxDelta = TimeSpan.FromMinutes(11.0);
|
||||
|
||||
private readonly IAlertsLogic _alertsLogic;
|
||||
private readonly IDeviceLogic _deviceLogic;
|
||||
|
@ -205,7 +203,9 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
var resultsModel = new AlertHistoryResultsModel();
|
||||
|
||||
IEnumerable<AlertHistoryItemModel> data =
|
||||
await _alertsLogic.LoadLatestAlertHistoryAsync(currentTime.AddMinutes(-CautionAlertMaxMinutes));
|
||||
await _alertsLogic.LoadLatestAlertHistoryAsync(
|
||||
currentTime.Subtract(CautionAlertMaxDelta),
|
||||
DISPLAYED_HISTORY_ITEMS);
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
|
@ -247,11 +247,11 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
{
|
||||
TimeSpan deltaTime = currentTime - lastStatusTime.Value;
|
||||
|
||||
if (deltaTime.TotalMinutes < CriticalAlertMaxMinutes)
|
||||
if (deltaTime < CriticalAlertMaxDelta)
|
||||
{
|
||||
deviceModel.Status = AlertHistoryDeviceStatus.Critical;
|
||||
}
|
||||
else if (deltaTime.TotalMinutes < CautionAlertMaxMinutes)
|
||||
else if (deltaTime < CautionAlertMaxDelta)
|
||||
{
|
||||
deviceModel.Status = AlertHistoryDeviceStatus.Caution;
|
||||
}
|
||||
|
@ -264,7 +264,7 @@ namespace Microsoft.Azure.Devices.Applications.RemoteMonitoring.DeviceAdmin.Web.
|
|||
}
|
||||
}
|
||||
|
||||
resultsModel.Data = historyItems.Take(MAX_DEVICES_TO_DISPLAY_ON_DASHBOARD).ToList();
|
||||
resultsModel.Data = historyItems.Take(DISPLAYED_HISTORY_ITEMS).ToList();
|
||||
resultsModel.Devices = deviceModels;
|
||||
resultsModel.TotalAlertCount = historyItems.Count;
|
||||
resultsModel.TotalFilteredCount = historyItems.Count;
|
||||
|
|
|
@ -168,10 +168,9 @@
|
|||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<None Include="Properties\webjob-publish-settings.json" />
|
||||
<None Include="run.cmd">
|
||||
<None Include="settings.job">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="settings.job" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SolutionDir)\Common\Common.csproj">
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
if /i %webjobs_name% == DeviceSimulator-WebJob ( Simulator.WebJob.exe ) else ( EventProcessor.WebJob.exe )
|
Загрузка…
Ссылка в новой задаче