Skip to content

Commit

Permalink
Versioning for edgelet client and add prepare update command (#702)
Browse files Browse the repository at this point in the history
Versioning for edgelet client and add prepare update command
  • Loading branch information
ancaantochi authored Jan 29, 2019
1 parent 5bbcec0 commit 4992833
Show file tree
Hide file tree
Showing 53 changed files with 6,280 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ public static class Constants

public const string NetworkIdKey = "NetworkId";

public const string EdgeletWorkloadApiVersion = "2018-06-28";

public const string EdgeletManagementApiVersion = "2018-06-28";
public const string EdgeletClientApiVersion = "2019-01-30";

public const string EdgeletInitializationVectorFileName = "IOTEDGE_BACKUP_IV";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ public HealthRestartPlanner(
this.restartManager = Preconditions.CheckNotNull(restartManager, nameof(restartManager));
}

public async Task<Plan> CreateShutdownPlanAsync(ModuleSet current)
{
IEnumerable<Task<ICommand>> stopTasks = current.Modules.Values
.Where(c => !c.Name.Equals(Constants.EdgeAgentModuleName, StringComparison.OrdinalIgnoreCase))
.Select(m => this.commandFactory.StopAsync(m));
ICommand[] stopCommands = await Task.WhenAll(stopTasks);
ICommand parallelCommand = new ParallelGroupCommand(stopCommands);
Events.ShutdownPlanCreated(stopCommands);
return new Plan(new[] { parallelCommand });
}

public async Task<Plan> PlanAsync(
ModuleSet desired,
ModuleSet current,
Expand All @@ -113,9 +124,8 @@ public async Task<Plan> PlanAsync(

List<ICommand> updateRuntimeCommands = await this.GetUpdateRuntimeCommands(updateDeployed, moduleIdentities, runtimeInfo);

// create "stop" commands for modules that have been updated/removed
IEnumerable<Task<ICommand>> stopTasks = updateDeployed
.Concat(removed)
// create "stop" commands for modules that have been removed
IEnumerable<Task<ICommand>> stopTasks = removed
.Select(m => this.commandFactory.StopAsync(m));
IEnumerable<ICommand> stop = await Task.WhenAll(stopTasks);

Expand Down Expand Up @@ -170,17 +180,6 @@ public async Task<Plan> PlanAsync(
return new Plan(commands);
}

public async Task<Plan> CreateShutdownPlanAsync(ModuleSet current)
{
IEnumerable<Task<ICommand>> stopTasks = current.Modules.Values
.Where(c => !c.Name.Equals(Constants.EdgeAgentModuleName, StringComparison.OrdinalIgnoreCase))
.Select(m => this.commandFactory.StopAsync(m));
ICommand[] stopCommands = await Task.WhenAll(stopTasks);
ICommand parallelCommand = new ParallelGroupCommand(stopCommands);
Events.ShutdownPlanCreated(stopCommands);
return new Plan(new[] { parallelCommand });
}

IEnumerable<Task<ICommand>> ApplyRestartPolicy(IEnumerable<IRuntimeModule> modules)
{
IEnumerable<IRuntimeModule> modulesToBeRestarted = this.restartManager.ApplyRestartPolicy(modules);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ public async Task<ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo

public async Task<ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo)
{
if (current is DockerModule currentDockerModule && next.Module is DockerModule)
if (current is DockerModule currentDockerModule && next.Module is DockerModule nextDockerModule)
{
CombinedDockerConfig combinedDockerConfig = this.combinedConfigProvider.GetCombinedConfig(nextDockerModule, runtimeInfo);
return new GroupCommand(
new PullCommand(this.client, combinedDockerConfig),
new StopCommand(this.client, currentDockerModule),
new RemoveCommand(this.client, currentDockerModule),
await this.CreateAsync(next, runtimeInfo));
await CreateCommand.BuildAsync(this.client, nextDockerModule, next.ModuleIdentity, this.dockerLoggerConfig, this.configSource, next.Module is EdgeHubDockerModule));
}

return NullCommand.Instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft. All rights reserved.
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.Azure.Devices.Edge.Agent.Edgelet.Test")]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
{
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Agent.Core;
using Microsoft.Azure.Devices.Edge.Agent.Core.Commands;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Commands;
using Microsoft.Azure.Devices.Edge.Util;

Expand All @@ -29,10 +30,10 @@ public Task<ICommand> CreateAsync(IModuleWithIdentity module, IRuntimeInfo runti
this.combinedConfigProvider.GetCombinedConfig(module.Module, runtimeInfo)) as ICommand);

public Task<ICommand> UpdateAsync(IModule current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo) =>
this.UpdateAsync(next, runtimeInfo, false);
this.UpdateAsync(Option.Some(current), next, runtimeInfo, false);

public Task<ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo) =>
this.UpdateAsync(module, runtimeInfo, true);
this.UpdateAsync(Option.None<IModule>(), module, runtimeInfo, true);

public Task<ICommand> RemoveAsync(IModule module) => Task.FromResult(new RemoveCommand(this.moduleManager, module) as ICommand);

Expand All @@ -44,14 +45,19 @@ public Task<ICommand> UpdateEdgeAgentAsync(IModuleWithIdentity module, IRuntimeI

public Task<ICommand> WrapAsync(ICommand command) => Task.FromResult(command);

Task<ICommand> UpdateAsync(IModuleWithIdentity module, IRuntimeInfo runtimeInfo, bool start) =>
Task.FromResult(
async Task<ICommand> UpdateAsync(Option<IModule> current, IModuleWithIdentity next, IRuntimeInfo runtimeInfo, bool start)
{
T config = this.combinedConfigProvider.GetCombinedConfig(next.Module, runtimeInfo);
return new GroupCommand(
new PrepareUpdateCommand(this.moduleManager, next.Module, config),
await current.Match(c => this.StopAsync(c), () => Task.FromResult<ICommand>(NullCommand.Instance)),
CreateOrUpdateCommand.BuildUpdate(
this.moduleManager,
module.Module,
module.ModuleIdentity,
next.Module,
next.ModuleIdentity,
this.configSource,
this.combinedConfigProvider.GetCombinedConfig(module.Module, runtimeInfo),
config,
start) as ICommand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Models;

public interface IIdentityManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode;
using Microsoft.Azure.Devices.Edge.Agent.Core;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Models;

public interface IModuleManager
{
Expand All @@ -24,6 +25,8 @@ public interface IModuleManager

Task<SystemInfo> GetSystemInfoAsync();

Task<IEnumerable<ModuleDetails>> GetModules(CancellationToken token);
Task<IEnumerable<ModuleRuntimeInfo>> GetModules<T>(CancellationToken token);

Task PrepareUpdateAsync(ModuleSpec moduleSpec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Edgelet
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Agent.Core;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.GeneratedCode;
using Microsoft.Azure.Devices.Edge.Agent.Edgelet.Models;
using Microsoft.Azure.Devices.Edge.Util;
using Microsoft.Extensions.Logging;

Expand Down
Loading

0 comments on commit 4992833

Please sign in to comment.