Skip to content

Commit

Permalink
Allow user to select between Edge Runtime 1.0 or 1.1 (#569)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
marianan authored Mar 29, 2021
1 parent d1011ef commit 179c0ba
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Change Log
## 1.24.0 - 2021-3-26
### Changed
* Allow user to select Edge Runtime version between 1.0 and 1.1

## 1.23.0 - 2020-9-23
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ You can also trigger following frequently-used commands in context menu.
- [Develop and deploy a Python module](https://docs.microsoft.com/azure/iot-edge/tutorial-python-module)
- [Develop and deploy a Node.js module](https://docs.microsoft.com/azure/iot-edge/tutorial-node-module)
- [Develop and deploy a C module](https://docs.microsoft.com/azure/iot-edge/tutorial-c-module)
- [Register a new Azure IoT Edge device](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-register-device-vscode)
- [Register a new Azure IoT Edge device](https://docs.microsoft.com/en-us/azure/iot-edge/how-to-register-device)
- [Deploy Azure IoT Edge modules](https://docs.microsoft.com/azure/iot-edge/how-to-deploy-modules-vscode)
- [Debug C# module](https://docs.microsoft.com/azure/iot-edge/how-to-develop-csharp-module)
- [Debug Node.js module](https://docs.microsoft.com/azure/iot-edge/how-to-develop-node-module)
Expand Down
46 changes: 30 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 20 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "azure-iot-edge",
"displayName": "Azure IoT Edge",
"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.",
"version": "1.23.0",
"version": "1.24.0-rc1",
"publisher": "vsciot-vscode",
"aiKey": "95b20d64-f54f-4de3-8ad5-165a75a6c6fe",
"icon": "logo.png",
Expand Down Expand Up @@ -43,6 +43,7 @@
"onCommand:azure-iot-edge.addModule",
"onCommand:azure-iot-edge.stopSolution",
"onCommand:azure-iot-edge.setupIotedgehubdev",
"onCommand:azure-iot-edge.setDefaultEdgeRuntimeVersion",
"onCommand:azure-iot-edge.startEdgeHubSingle",
"onCommand:azure-iot-edge.setModuleCred",
"onCommand:azure-iot-edge.setDefaultPlatform",
Expand Down Expand Up @@ -166,6 +167,11 @@
"title": "Setup IoT Edge Simulator",
"category": "Azure IoT Edge"
},
{
"command": "azure-iot-edge.setDefaultEdgeRuntimeVersion",
"title": "Set Default IoT Edge Runtime Version",
"category": "Azure IoT Edge"
},
{
"command": "azure-iot-edge.startEdgeHubSingle",
"title": "Start IoT Edge Hub Simulator for Single Module",
Expand All @@ -191,16 +197,6 @@
"type": "object",
"title": "Azure IoT Edge configuration",
"properties": {
"azure-iot-edge.version.edgeHub": {
"type": "string",
"default": "1.0",
"description": "Set the edgeHub image version, which will be referenced in deployment manifest."
},
"azure-iot-edge.version.edgeAgent": {
"type": "string",
"default": "1.0",
"description": "Set the edgeAgent image version, which will be referenced in deployment manifest."
},
"azure-iot-edge.version.tempSensor": {
"type": "string",
"default": "1.0",
Expand Down Expand Up @@ -284,6 +280,19 @@
},
"description": "Current default target platform for Edge Module"
},
"azure-iot-edge.version.supported.edgeRuntime": {
"type": "array",
"default": [
"1.0",
"1.1"
],
"description": "List of supported Edge Runtime images versions"
},
"azure-iot-edge.version.default.edgeRuntime": {
"type": "string",
"default": "1.0",
"description": "Set the edgeAgent and edgeHub images version, which will be referenced in deployment manifest."
},
"azure-iot-edge.3rdPartyModuleTemplates": {
"type": "object",
"default": {},
Expand Down
6 changes: 5 additions & 1 deletion src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Constants {
public static deploymentTemplatePattern = "**/deployment.template.json";
public static debugDeploymentTemplatePattern = "**/deployment.debug.template.json";
public static tsonPattern = "**/*.template.json";
public static deploymentTsonPattern = "**/deployment.*.template.json,**/deployment.template.json";
public static deploymentJsonPattern = "**/deployment.*.template.json,**/deployment.template.json";
public static tson = ".template.json";
public static deploymentTemplateDesc = "Deployment Template file";
public static deploymentFilePattern = "**/deployment.json";
Expand Down Expand Up @@ -89,6 +89,7 @@ export class Constants {
public static moduleName = "Module Name";
public static moduleNamePrompt = "Provide a Module Name";
public static moduleNameDft = "SampleModule";
public static edgeRuntimeVersionPrompt = "Select Azure IoT Edge Runtime (Edge Hub and Edge Agent images) version";
public static registryPlaceholder = "<registry>";
public static repoNamePlaceholder = "<repo-name>";
public static tagPlaceholder = "<tag>";
Expand All @@ -108,6 +109,7 @@ export class Constants {
public static runSolutionEvent = "runSolution";
public static generateDeploymentEvent = "generateDeployment";
public static addModuleEvent = "addModule";
public static selectEdgeRuntimeVerEvent = "selectEdgeVer";
public static launchCSharp = "launch_csharp.json";
public static launchNode = "launch_node.json";
public static launchC = "launch_c.json";
Expand Down Expand Up @@ -159,6 +161,8 @@ export class Constants {

public static versionEdgeAgent = "version.edgeAgent";
public static versionEdgeHub = "version.edgeHub";
public static versionEdgeRuntime = "version.supported.edgeRuntime";
public static versionDefaultEdgeRuntime = "version.default.edgeRuntime";
public static versionTempSensor = "version.tempSensor";
public static versionCModule = "version.cmodule";
public static versionPythonModule = "version.pythonmodule";
Expand Down
41 changes: 37 additions & 4 deletions src/common/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Configuration } from "./configuration";
import { Constants } from "./constants";

type ImageJson = "${string}:${string}";

export class Versions {
public static getRunTimeVersionMap(): Map<string, string> {
const verMap: Map<string, string> = new Map();
Expand All @@ -9,6 +11,10 @@ export class Versions {
return verMap;
}

public static getSupportedEdgeRuntimeVersions(): string[] {
return Versions.getValue(Constants.versionEdgeRuntime, []) as string[];
}

public static installCSharpTemplate(): boolean {
return Versions.getValue(Constants.installCSharpModule, true) as boolean;
}
Expand Down Expand Up @@ -49,15 +55,42 @@ export class Versions {
return Versions.getValue(Constants.versionTempSensor, "1.0") as string;
}

public static updateSystemModuleImageVersion(templateJson: any, moduleName: string, versionMap: Map<string, string>) {
if (templateJson !== undefined) {
const sysModuleImage =
templateJson.modulesContent.$edgeAgent["properties.desired"].systemModules[moduleName].settings.image;
templateJson.modulesContent.$edgeAgent["properties.desired"].systemModules[moduleName].settings.image =
Versions.getNewImageVersionJson(sysModuleImage, versionMap);
}
}

public static edgeHubVersion(): string {
return Versions.getDefaultEdgeRuntimeVersion();
}

private static edgeAgentVersion(): string {
return Versions.getValue(Constants.versionEdgeAgent) as string;
return Versions.getDefaultEdgeRuntimeVersion();
}

private static edgeHubVersion(): string {
return Versions.getValue(Constants.versionEdgeHub, "1.0") as string;
private static getDefaultEdgeRuntimeVersion(): string {
return Versions.getValue(Constants.versionDefaultEdgeRuntime, "1.0") as string;
}

private static getNewImageVersionJson(input: ImageJson, versionMap: Map<string, string>): string {
if (input !== undefined) {
const imageName: string = input.split(":")[0];
switch (imageName) {
case "mcr.microsoft.com/azureiotedge-agent":
return imageName + ":" + versionMap.get(Constants.edgeAgentVerPlaceHolder);
case "mcr.microsoft.com/azureiotedge-hub":
return imageName + ":" + versionMap.get(Constants.edgeHubVerPlaceHolder);
default:
return input;
}
}
}

private static getValue(key: string, defaultVal: string|boolean = null): string | boolean {
private static getValue(key: string, defaultVal: string|string[]|boolean = null): string | string[] | boolean {
const value = Configuration.getConfigurationProperty(key);
if (value === undefined || value === null) {
return defaultVal;
Expand Down
4 changes: 2 additions & 2 deletions src/container/containerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ContainerManager {
}

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

public async generateDeployment(outputChannel: vscode.OutputChannel, templateUri?: vscode.Uri): Promise<void> {
const pattern = `{${Constants.deploymentTsonPattern}}`;
const pattern = `{${Constants.deploymentJsonPattern}}`;
const templateFile: string = await Utility.getInputFilePath(templateUri,
pattern,
Constants.deploymentTemplateDesc,
Expand Down
45 changes: 44 additions & 1 deletion src/edge/edgeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class EdgeManager {
}

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

public async selectDefaultEdgeRuntimeVersion(outputChannel: vscode.OutputChannel) {
const edgeRuntimeVersions: string[] = Versions.getSupportedEdgeRuntimeVersions();
const edgeVersionPick = await vscode.window.showQuickPick(edgeRuntimeVersions, { placeHolder: Constants.edgeRuntimeVersionPrompt, ignoreFocusOut: true });
if (!edgeVersionPick) {
throw new UserCancelledError();
}

TelemetryClient.sendEvent(`${Constants.selectEdgeRuntimeVerEvent}`, {
template: edgeVersionPick,
});

await Configuration.setWorkspaceConfigurationProperty(Constants.versionDefaultEdgeRuntime, edgeVersionPick);
outputChannel.appendLine(`Default Azure IoT Edge Runtime is ${edgeVersionPick} now.`);

// If there is an active workspace, update the deployment templates
// with the desired runtime version
if (Utility.checkWorkspace() !== undefined) {
await this.updateRuntimeVersionInDeploymentTemplate();
}
}

public async selectDefaultPlatform(outputChannel: vscode.OutputChannel) {
if (!Utility.checkWorkspace(Constants.noWorkspaceSetDefaultPlatformMsg)) {
return;
Expand Down Expand Up @@ -372,6 +393,28 @@ export class EdgeManager {
}
}

private async updateRuntimeVersionInDeploymentTemplate() {
const pattern = `{${Constants.deploymentJsonPattern}}`;
const description = `${Constants.deploymentTemplateDesc}`;

const fileList: vscode.Uri[] = await vscode.workspace.findFiles(pattern);
if (!fileList || fileList.length === 0) {
vscode.window.showErrorMessage(`No ${description} can be found under this workspace.`);
return;
}

const versionMap = Versions.getRunTimeVersionMap();
for (const deploymentTemplateFile of fileList) {
const deploymentTemplateFilePath: string = deploymentTemplateFile.fsPath;
const templateJson = await fse.readJson(deploymentTemplateFilePath);

Versions.updateSystemModuleImageVersion(templateJson, "edgeAgent", versionMap);
Versions.updateSystemModuleImageVersion(templateJson, "edgeHub", versionMap);

await fse.writeFile(deploymentTemplateFilePath, JSON.stringify(templateJson, null, 2), { encoding: "utf8" });
}
}

private async addModuleToDeploymentTemplate(templateJson: any, templateFile: string, envFilePath: string,
moduleInfo: ModuleInfo, isTempsensorNeeded: boolean, isDebug: boolean = false): Promise<{ usernameEnv: string, passwordEnv: string }> {
const modules = templateJson.modulesContent.$edgeAgent["properties.desired"].modules;
Expand Down
4 changes: 3 additions & 1 deletion src/edge/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { SimulatorInfo } from "../common/SimulatorInfo";
import { TelemetryClient } from "../common/telemetryClient";
import { UserCancelledError } from "../common/UserCancelledError";
import { Utility } from "../common/utility";
import { Versions } from "../common/version";
import { IDeviceItem } from "../typings/IDeviceItem";
import { InstallResult, InstallReturn } from "./InstallResult";

Expand Down Expand Up @@ -156,8 +157,9 @@ export class Simulator {
return await this.callWithInstallationCheck(outputChannel, async () => {
await this.checkIoTedgehubdevConnectionString(outputChannel);
const inputs = await this.inputInputNames();
const imgVersion = Versions.edgeHubVersion();
await this.setModuleCred(outputChannel);
await Executor.runInTerminal(Simulator.adjustTerminalCommand(this.getAdjustedSimulatorExecutorPath() + ` start -i "${inputs}"`));
await Executor.runInTerminal(Simulator.adjustTerminalCommand(this.getAdjustedSimulatorExecutorPath() + ` start -er "${imgVersion}" -i "${inputs}"`));
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ export function activate(context: vscode.ExtensionContext) {
return configDiagnosticProvider.updateDiagnostics(document, diagCollection);
});

initCommandAsync(context, outputChannel,
"azure-iot-edge.setDefaultEdgeRuntimeVersion",
async (): Promise<void> => {
await edgeManager.selectDefaultEdgeRuntimeVersion(outputChannel);
const document = vscode.window && vscode.window.activeTextEditor ? vscode.window.activeTextEditor.document : null;
return configDiagnosticProvider.updateDiagnostics(document, diagCollection);
});

initCommandAsync(context, outputChannel,
"azure-iot-edge.showGallery",
async (): Promise<void> => {
Expand Down

0 comments on commit 179c0ba

Please sign in to comment.