in src/iotEdgeExplorer.ts [255:353]
private async deployAtScale(iotHubConnectionString: string, deploymentJson: string) {
const deploymentJsonObject = JSON.parse(deploymentJson);
let modulesContent;
if (deploymentJsonObject.modulesContent) {
modulesContent = deploymentJsonObject.modulesContent;
} else if (deploymentJsonObject.content && deploymentJsonObject.content.modulesContent) {
modulesContent = deploymentJsonObject.content.modulesContent;
}
if (!modulesContent) {
vscode.window.showWarningMessage("Deployment manifest is invalid.");
return;
}
const deploymentId = await vscode.window.showInputBox({
prompt: "Deployment id",
placeHolder: "The name of the deployment",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (!value) {
return "The value should not be empty.";
}
if (value.length > 128) {
return "Up to 128 characters are allowed.";
}
if (!/^[a-z0-9-:+%_#*?!(),=@;']+$/.test(value)) {
return "Lowercase letters, numbers and the following characters are allowed [ -:+%_#*?!(),=@;' ].";
}
return undefined;
},
});
if (!deploymentId) {
return;
}
const targetCondition = await vscode.window.showInputBox({
prompt: "A target condition to determine which devices will be targeted with this deployment",
placeHolder: "e.g. tags.environment='test', properties.reported.devicemodel='4000x', or deviceId='{id}'",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (!value) {
return "The value should not be empty.";
}
if (!Utility.isValidTargetCondition(value)) {
return "Valid conditions specify a either a deviceId (e.g. deviceId='{id}'), \
one or more device twin tag criteria (e.g. tags.environment = 'prod' AND tags.location = 'westus'), \
or reported property criteria (e.g. properties.reported.lastStatus='200').";
}
return undefined;
},
});
if (!targetCondition) {
return;
}
const priority = await vscode.window.showInputBox({
prompt: "Deployment priority (Higher values indicate higher priority)",
value: "10",
ignoreFocusOut: true,
validateInput: (value: string) => {
if (!value) {
return "The value should not be empty.";
}
const floatValue = parseFloat(value);
if (!Number.isInteger(floatValue) || floatValue < 0) {
return "Deployment priority should be a positive integer";
}
return undefined;
},
});
if (!priority) {
return;
}
const deploymentConfiguration = {
id: deploymentId,
content: {
modulesContent,
},
schemaVersion: "1.0",
targetCondition,
priority: parseInt(priority, 10),
};
const label = Constants.IoTHubEdgeLabel;
this._outputChannel.show();
this.outputLine(label, `Start deployment with deployment id [${deploymentId}] and target condition [${targetCondition}]`);
const registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
registry.addConfiguration(deploymentConfiguration, (err) => {
if (err) {
this.outputLine(label, `Deployment with deployment id [${deploymentId}] failed. ${err}`);
TelemetryClient.sendEvent(Constants.IoTHubAIEdgeDeployAtScaleDoneEvent, { Result: "Fail", [Constants.errorProperties.Message]: err.message });
} else {
this.outputLine(label, `Deployment with deployment id [${deploymentId}] succeeded.`);
TelemetryClient.sendEvent(Constants.IoTHubAIEdgeDeployAtScaleDoneEvent, { Result: "Success" });
}
});
}