Skip to content

Commit

Permalink
Merged PR 868491: Fix module lifecycle and use agent base image
Browse files Browse the repository at this point in the history
Fix module lifecycle and use agent base image
  • Loading branch information
ancaantochi authored and myagley committed May 31, 2018
1 parent cfeb7f0 commit 2d2d074
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
15 changes: 1 addition & 14 deletions edge-agent/docker/linux/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
ARG base_tag=2.1.0-rc1-runtime-alpine3.7
ARG num_procs=4

FROM alpine:3.7 as builder

# Build RocksDB for alpine
RUN apk update && \
apk add build-base bash perl linux-headers coreutils git snappy-dev

RUN git clone -b v5.4.6 --depth 1 https://github.com/facebook/rocksdb.git && \
cd rocksdb && \
CFLAGS="-static-libstdc++ -Wno-psabi -DSNAPPY" PORTABLE=1 make -j ${num_procs} shared_lib && \
strip librocksdb.so && \
mkdir -p ../publish && \
cp -vL librocksdb.so ../publish/
FROM azureiotedge/azureiotedge-agent-base:1.0.0-linux-amd64 as builder

FROM microsoft/dotnet:${base_tag}

Expand Down
15 changes: 15 additions & 0 deletions edge-agent/docker/linux/amd64/base/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG base_tag=2.1.0-rc1-runtime-alpine3.7
ARG num_procs=4

FROM alpine:3.7 as builder

# Build RocksDB for alpine
RUN apk update && \
apk add build-base bash perl linux-headers coreutils git snappy-dev

RUN git clone -b v5.4.6 --depth 1 https://github.com/facebook/rocksdb.git && \
cd rocksdb && \
CFLAGS="-static-libstdc++ -Wno-psabi -DSNAPPY" PORTABLE=1 make -j ${num_procs} shared_lib && \
strip librocksdb.so && \
mkdir -p ../publish && \
cp -vL librocksdb.so ../publish/
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public Diff Diff(ModuleSet other)
// be "updated"
IEnumerable<IModule> updated = this.Modules.Keys
.Intersect(other.Modules.Keys)
.Where(key =>
{
return !this.Modules[key].Equals(other.Modules[key]);
})
.Where(key => !this.Modules[key].Equals(other.Modules[key]))
.Select(key => this.Modules[key]);

return new Diff(created.Concat(updated).ToList(), removed.ToList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,15 @@ public async Task<IImmutableDictionary<string, IModuleIdentity>> GetModuleIdenti
// Create/update identities.
IEnumerable<Task<Identity>> createTasks = createIdentities.Select(i => this.identityManager.CreateIdentityAsync(i));
IEnumerable<Task<Identity>> updateTasks = updateIdentities.Select(i => this.identityManager.UpdateIdentityAsync(i.ModuleId, i.GenerationId));
Identity[] createdIdentities = await Task.WhenAll(createTasks.Concat(updateTasks));
Identity[] upsertedIdentities = await Task.WhenAll(createTasks.Concat(updateTasks));

IEnumerable<IModuleIdentity> moduleIdentities = createdIdentities.Concat(identities.Values)
.Select(m => this.GetModuleIdentity(m));
List<IModuleIdentity> moduleIdentities = upsertedIdentities.Select(m => this.GetModuleIdentity(m)).ToList();
// Add the module identity for Edge Agent in the returned dictionary
// because is was excluded from the update call.
if (identities.ContainsKey(Constants.EdgeAgentModuleIdentityName))
{
moduleIdentities.Add(this.GetModuleIdentity(identities[Constants.EdgeAgentModuleIdentityName]));
}
return moduleIdentities.ToImmutableDictionary(m => ModuleIdentityHelper.GetModuleName(m.ModuleId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public TestModule(string name, string version, string type, ModuleStatus desired
: base(name, version, type, desiredStatus, config, restartPolicy, configuration, env)
{
}

public TestModule CloneWithImage(string image)
{
return new TestModule(this.Name, this.Version, this.Type, this.DesiredStatus, new TestConfig(image), this.RestartPolicy, this.ConfigurationInfo, this.Env);
}
}

public class TestAgentModule : TestModule, IEdgeAgentModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ public async Task TestGetModulesIdentity_WithUpdatedModules_ShouldUpdateIdentiti
var module3 = new TestModule(Module3, "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
var module4 = new TestModule(Module4, "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
var module5 = new TestModule(Module5, "v1", "test", ModuleStatus.Running, new TestConfig("image"), RestartPolicy.OnUnhealthy, DefaultConfigurationInfo, envVar);
ModuleSet desired = ModuleSet.Create(new IModule[] { module1, module2, module3, module4, module5 });
ModuleSet desired = ModuleSet.Create(new IModule[] { module1, module2.CloneWithImage("image2"), module3.CloneWithImage("image2"), module4.CloneWithImage("image2"), module5.CloneWithImage("image2") });
ModuleSet current = ModuleSet.Create(new IModule[] { module2, module3, module4, module5 });

// Act
IImmutableDictionary<string, IModuleIdentity> modulesIdentities = await moduleIdentityLifecycleManager.GetModuleIdentitiesAsync(desired, current);

// Assert
Assert.True(modulesIdentities.Count() == 5);
Assert.Equal(5, modulesIdentities.Count);
Assert.True(modulesIdentities.TryGetValue(Module1, out IModuleIdentity moduleIdentity1));
Assert.Equal(Module1, moduleIdentity1.ModuleId);
Assert.True(modulesIdentities.TryGetValue(Module2, out IModuleIdentity moduleIdentity2));
Expand Down

0 comments on commit 2d2d074

Please sign in to comment.