Skip to content

Commit 179c0ba

Browse files
authored
Allow user to select between Edge Runtime 1.0 or 1.1 (#569)
* Allow user to select between Edge Runtime 1.0 or 1.1 * Update per PR feedback * Fix lint issues * Update a stale link in readme * Update based on PR feedback
1 parent d1011ef commit 179c0ba

10 files changed

+153
-37
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Change Log
2+
## 1.24.0 - 2021-3-26
3+
### Changed
4+
* Allow user to select Edge Runtime version between 1.0 and 1.1
25

36
## 1.23.0 - 2020-9-23
47
### Fixed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ You can also trigger following frequently-used commands in context menu.
156156
- [Develop and deploy a Python module](https://docs.microsoft.com/azure/iot-edge/tutorial-python-module)
157157
- [Develop and deploy a Node.js module](https://docs.microsoft.com/azure/iot-edge/tutorial-node-module)
158158
- [Develop and deploy a C module](https://docs.microsoft.com/azure/iot-edge/tutorial-c-module)
159-
- [Register a new Azure IoT Edge device](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-register-device-vscode)
159+
- [Register a new Azure IoT Edge device](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-register-device)
160160
- [Deploy Azure IoT Edge modules](https://docs.microsoft.com/azure/iot-edge/how-to-deploy-modules-vscode)
161161
- [Debug C# module](https://docs.microsoft.com/azure/iot-edge/how-to-develop-csharp-module)
162162
- [Debug Node.js module](https://docs.microsoft.com/azure/iot-edge/how-to-develop-node-module)

package-lock.json

+30-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "azure-iot-edge",
33
"displayName": "Azure IoT Edge",
44
"description": "This extension is now a part of Azure IoT Tools extension pack. We highly recommend installing Azure IoT Tools to get full capabilities for Azure IoT development. Develop, deploy, debug, and manage your IoT Edge solution.",
5-
"version": "1.23.0",
5+
"version": "1.24.0-rc1",
66
"publisher": "vsciot-vscode",
77
"aiKey": "95b20d64-f54f-4de3-8ad5-165a75a6c6fe",
88
"icon": "logo.png",
@@ -43,6 +43,7 @@
4343
"onCommand:azure-iot-edge.addModule",
4444
"onCommand:azure-iot-edge.stopSolution",
4545
"onCommand:azure-iot-edge.setupIotedgehubdev",
46+
"onCommand:azure-iot-edge.setDefaultEdgeRuntimeVersion",
4647
"onCommand:azure-iot-edge.startEdgeHubSingle",
4748
"onCommand:azure-iot-edge.setModuleCred",
4849
"onCommand:azure-iot-edge.setDefaultPlatform",
@@ -166,6 +167,11 @@
166167
"title": "Setup IoT Edge Simulator",
167168
"category": "Azure IoT Edge"
168169
},
170+
{
171+
"command": "azure-iot-edge.setDefaultEdgeRuntimeVersion",
172+
"title": "Set Default IoT Edge Runtime Version",
173+
"category": "Azure IoT Edge"
174+
},
169175
{
170176
"command": "azure-iot-edge.startEdgeHubSingle",
171177
"title": "Start IoT Edge Hub Simulator for Single Module",
@@ -191,16 +197,6 @@
191197
"type": "object",
192198
"title": "Azure IoT Edge configuration",
193199
"properties": {
194-
"azure-iot-edge.version.edgeHub": {
195-
"type": "string",
196-
"default": "1.0",
197-
"description": "Set the edgeHub image version, which will be referenced in deployment manifest."
198-
},
199-
"azure-iot-edge.version.edgeAgent": {
200-
"type": "string",
201-
"default": "1.0",
202-
"description": "Set the edgeAgent image version, which will be referenced in deployment manifest."
203-
},
204200
"azure-iot-edge.version.tempSensor": {
205201
"type": "string",
206202
"default": "1.0",
@@ -284,6 +280,19 @@
284280
},
285281
"description": "Current default target platform for Edge Module"
286282
},
283+
"azure-iot-edge.version.supported.edgeRuntime": {
284+
"type": "array",
285+
"default": [
286+
"1.0",
287+
"1.1"
288+
],
289+
"description": "List of supported Edge Runtime images versions"
290+
},
291+
"azure-iot-edge.version.default.edgeRuntime": {
292+
"type": "string",
293+
"default": "1.0",
294+
"description": "Set the edgeAgent and edgeHub images version, which will be referenced in deployment manifest."
295+
},
287296
"azure-iot-edge.3rdPartyModuleTemplates": {
288297
"type": "object",
289298
"default": {},

src/common/constants.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class Constants {
1414
public static deploymentTemplatePattern = "**/deployment.template.json";
1515
public static debugDeploymentTemplatePattern = "**/deployment.debug.template.json";
1616
public static tsonPattern = "**/*.template.json";
17-
public static deploymentTsonPattern = "**/deployment.*.template.json,**/deployment.template.json";
17+
public static deploymentJsonPattern = "**/deployment.*.template.json,**/deployment.template.json";
1818
public static tson = ".template.json";
1919
public static deploymentTemplateDesc = "Deployment Template file";
2020
public static deploymentFilePattern = "**/deployment.json";
@@ -89,6 +89,7 @@ export class Constants {
8989
public static moduleName = "Module Name";
9090
public static moduleNamePrompt = "Provide a Module Name";
9191
public static moduleNameDft = "SampleModule";
92+
public static edgeRuntimeVersionPrompt = "Select Azure IoT Edge Runtime (Edge Hub and Edge Agent images) version";
9293
public static registryPlaceholder = "<registry>";
9394
public static repoNamePlaceholder = "<repo-name>";
9495
public static tagPlaceholder = "<tag>";
@@ -108,6 +109,7 @@ export class Constants {
108109
public static runSolutionEvent = "runSolution";
109110
public static generateDeploymentEvent = "generateDeployment";
110111
public static addModuleEvent = "addModule";
112+
public static selectEdgeRuntimeVerEvent = "selectEdgeVer";
111113
public static launchCSharp = "launch_csharp.json";
112114
public static launchNode = "launch_node.json";
113115
public static launchC = "launch_c.json";
@@ -159,6 +161,8 @@ export class Constants {
159161

160162
public static versionEdgeAgent = "version.edgeAgent";
161163
public static versionEdgeHub = "version.edgeHub";
164+
public static versionEdgeRuntime = "version.supported.edgeRuntime";
165+
public static versionDefaultEdgeRuntime = "version.default.edgeRuntime";
162166
public static versionTempSensor = "version.tempSensor";
163167
public static versionCModule = "version.cmodule";
164168
public static versionPythonModule = "version.pythonmodule";

src/common/version.ts

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Configuration } from "./configuration";
22
import { Constants } from "./constants";
33

4+
type ImageJson = "${string}:${string}";
5+
46
export class Versions {
57
public static getRunTimeVersionMap(): Map<string, string> {
68
const verMap: Map<string, string> = new Map();
@@ -9,6 +11,10 @@ export class Versions {
911
return verMap;
1012
}
1113

14+
public static getSupportedEdgeRuntimeVersions(): string[] {
15+
return Versions.getValue(Constants.versionEdgeRuntime, []) as string[];
16+
}
17+
1218
public static installCSharpTemplate(): boolean {
1319
return Versions.getValue(Constants.installCSharpModule, true) as boolean;
1420
}
@@ -49,15 +55,42 @@ export class Versions {
4955
return Versions.getValue(Constants.versionTempSensor, "1.0") as string;
5056
}
5157

58+
public static updateSystemModuleImageVersion(templateJson: any, moduleName: string, versionMap: Map<string, string>) {
59+
if (templateJson !== undefined) {
60+
const sysModuleImage =
61+
templateJson.modulesContent.$edgeAgent["properties.desired"].systemModules[moduleName].settings.image;
62+
templateJson.modulesContent.$edgeAgent["properties.desired"].systemModules[moduleName].settings.image =
63+
Versions.getNewImageVersionJson(sysModuleImage, versionMap);
64+
}
65+
}
66+
67+
public static edgeHubVersion(): string {
68+
return Versions.getDefaultEdgeRuntimeVersion();
69+
}
70+
5271
private static edgeAgentVersion(): string {
53-
return Versions.getValue(Constants.versionEdgeAgent) as string;
72+
return Versions.getDefaultEdgeRuntimeVersion();
5473
}
5574

56-
private static edgeHubVersion(): string {
57-
return Versions.getValue(Constants.versionEdgeHub, "1.0") as string;
75+
private static getDefaultEdgeRuntimeVersion(): string {
76+
return Versions.getValue(Constants.versionDefaultEdgeRuntime, "1.0") as string;
77+
}
78+
79+
private static getNewImageVersionJson(input: ImageJson, versionMap: Map<string, string>): string {
80+
if (input !== undefined) {
81+
const imageName: string = input.split(":")[0];
82+
switch (imageName) {
83+
case "mcr.microsoft.com/azureiotedge-agent":
84+
return imageName + ":" + versionMap.get(Constants.edgeAgentVerPlaceHolder);
85+
case "mcr.microsoft.com/azureiotedge-hub":
86+
return imageName + ":" + versionMap.get(Constants.edgeHubVerPlaceHolder);
87+
default:
88+
return input;
89+
}
90+
}
5891
}
5992

60-
private static getValue(key: string, defaultVal: string|boolean = null): string | boolean {
93+
private static getValue(key: string, defaultVal: string|string[]|boolean = null): string | string[] | boolean {
6194
const value = Configuration.getConfigurationProperty(key);
6295
if (value === undefined || value === null) {
6396
return defaultVal;

src/container/containerManager.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class ContainerManager {
4343
}
4444

4545
public async buildSolution(outputChannel: vscode.OutputChannel, templateUri?: vscode.Uri, push: boolean = true, run: boolean = false): Promise<void> {
46-
const pattern = `{${Constants.deploymentTsonPattern}}`;
46+
const pattern = `{${Constants.deploymentJsonPattern}}`;
4747
const templateFile: string = await Utility.getInputFilePath(templateUri,
4848
pattern,
4949
Constants.deploymentTemplateDesc,
@@ -56,7 +56,7 @@ export class ContainerManager {
5656
}
5757

5858
public async generateDeployment(outputChannel: vscode.OutputChannel, templateUri?: vscode.Uri): Promise<void> {
59-
const pattern = `{${Constants.deploymentTsonPattern}}`;
59+
const pattern = `{${Constants.deploymentJsonPattern}}`;
6060
const templateFile: string = await Utility.getInputFilePath(templateUri,
6161
pattern,
6262
Constants.deploymentTemplateDesc,

src/edge/edgeManager.ts

+44-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class EdgeManager {
5959
}
6060

6161
public async addModuleForSolution(outputChannel: vscode.OutputChannel, templateUri?: vscode.Uri): Promise<void> {
62-
const pattern = `{${Constants.deploymentTsonPattern}}`;
62+
const pattern = `{${Constants.deploymentJsonPattern}}`;
6363
let templateFile: string = await Utility.getInputFilePath(templateUri,
6464
pattern,
6565
Constants.deploymentTemplateDesc,
@@ -156,6 +156,27 @@ export class EdgeManager {
156156
}
157157
}
158158

159+
public async selectDefaultEdgeRuntimeVersion(outputChannel: vscode.OutputChannel) {
160+
const edgeRuntimeVersions: string[] = Versions.getSupportedEdgeRuntimeVersions();
161+
const edgeVersionPick = await vscode.window.showQuickPick(edgeRuntimeVersions, { placeHolder: Constants.edgeRuntimeVersionPrompt, ignoreFocusOut: true });
162+
if (!edgeVersionPick) {
163+
throw new UserCancelledError();
164+
}
165+
166+
TelemetryClient.sendEvent(`${Constants.selectEdgeRuntimeVerEvent}`, {
167+
template: edgeVersionPick,
168+
});
169+
170+
await Configuration.setWorkspaceConfigurationProperty(Constants.versionDefaultEdgeRuntime, edgeVersionPick);
171+
outputChannel.appendLine(`Default Azure IoT Edge Runtime is ${edgeVersionPick} now.`);
172+
173+
// If there is an active workspace, update the deployment templates
174+
// with the desired runtime version
175+
if (Utility.checkWorkspace() !== undefined) {
176+
await this.updateRuntimeVersionInDeploymentTemplate();
177+
}
178+
}
179+
159180
public async selectDefaultPlatform(outputChannel: vscode.OutputChannel) {
160181
if (!Utility.checkWorkspace(Constants.noWorkspaceSetDefaultPlatformMsg)) {
161182
return;
@@ -372,6 +393,28 @@ export class EdgeManager {
372393
}
373394
}
374395

396+
private async updateRuntimeVersionInDeploymentTemplate() {
397+
const pattern = `{${Constants.deploymentJsonPattern}}`;
398+
const description = `${Constants.deploymentTemplateDesc}`;
399+
400+
const fileList: vscode.Uri[] = await vscode.workspace.findFiles(pattern);
401+
if (!fileList || fileList.length === 0) {
402+
vscode.window.showErrorMessage(`No ${description} can be found under this workspace.`);
403+
return;
404+
}
405+
406+
const versionMap = Versions.getRunTimeVersionMap();
407+
for (const deploymentTemplateFile of fileList) {
408+
const deploymentTemplateFilePath: string = deploymentTemplateFile.fsPath;
409+
const templateJson = await fse.readJson(deploymentTemplateFilePath);
410+
411+
Versions.updateSystemModuleImageVersion(templateJson, "edgeAgent", versionMap);
412+
Versions.updateSystemModuleImageVersion(templateJson, "edgeHub", versionMap);
413+
414+
await fse.writeFile(deploymentTemplateFilePath, JSON.stringify(templateJson, null, 2), { encoding: "utf8" });
415+
}
416+
}
417+
375418
private async addModuleToDeploymentTemplate(templateJson: any, templateFile: string, envFilePath: string,
376419
moduleInfo: ModuleInfo, isTempsensorNeeded: boolean, isDebug: boolean = false): Promise<{ usernameEnv: string, passwordEnv: string }> {
377420
const modules = templateJson.modulesContent.$edgeAgent["properties.desired"].modules;

src/edge/simulator.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { SimulatorInfo } from "../common/SimulatorInfo";
2020
import { TelemetryClient } from "../common/telemetryClient";
2121
import { UserCancelledError } from "../common/UserCancelledError";
2222
import { Utility } from "../common/utility";
23+
import { Versions } from "../common/version";
2324
import { IDeviceItem } from "../typings/IDeviceItem";
2425
import { InstallResult, InstallReturn } from "./InstallResult";
2526

@@ -156,8 +157,9 @@ export class Simulator {
156157
return await this.callWithInstallationCheck(outputChannel, async () => {
157158
await this.checkIoTedgehubdevConnectionString(outputChannel);
158159
const inputs = await this.inputInputNames();
160+
const imgVersion = Versions.edgeHubVersion();
159161
await this.setModuleCred(outputChannel);
160-
await Executor.runInTerminal(Simulator.adjustTerminalCommand(this.getAdjustedSimulatorExecutorPath() + ` start -i "${inputs}"`));
162+
await Executor.runInTerminal(Simulator.adjustTerminalCommand(this.getAdjustedSimulatorExecutorPath() + ` start -er "${imgVersion}" -i "${inputs}"`));
161163
});
162164
}
163165

src/extension.ts

+8
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,14 @@ export function activate(context: vscode.ExtensionContext) {
176176
return configDiagnosticProvider.updateDiagnostics(document, diagCollection);
177177
});
178178

179+
initCommandAsync(context, outputChannel,
180+
"azure-iot-edge.setDefaultEdgeRuntimeVersion",
181+
async (): Promise<void> => {
182+
await edgeManager.selectDefaultEdgeRuntimeVersion(outputChannel);
183+
const document = vscode.window && vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document : null;
184+
return configDiagnosticProvider.updateDiagnostics(document, diagCollection);
185+
});
186+
179187
initCommandAsync(context, outputChannel,
180188
"azure-iot-edge.showGallery",
181189
async (): Promise<void> => {

0 commit comments

Comments
 (0)