Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PipelineJob]: Add Typescript/JavaScript samples for SDKv2 #2087

Merged
merged 12 commits into from
Feb 27, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ config.json
*.log
scratch/*
config-amlexamples.json
node_modules
6 changes: 3 additions & 3 deletions sdk/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
},
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/machinelearning/arm-machinelearning",
"dependencies": {
"@azure/arm-machinelearning": "^2.1.0",
"@azure/identity": "^2.1.0-beta.2",
"@azure/arm-machinelearning": "^2.1.1",
"@azure/identity": "^2.1.0",
"@azure/keyvault-secrets": "latest",
"dotenv": "latest"
},
Expand All @@ -41,4 +41,4 @@
"typescript": "~4.8.0",
"rimraf": "latest"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const workspaceName = getEnvironmentVariable("WORKSPACE_NAME");
* @summary Create or update version.
* x-ms-original-file: specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2022-10-01/examples/ComponentVersion/createOrUpdate.json
*/
async function createOrUpdateComponentVersion(): Promise<void> {
export async function createOrUpdateComponentVersion() : Promise<void> {
const name = "command_component_basic";
const version = "0.0.1";
const body: ComponentVersion = {
properties: {
description: "This is the basic command component",
componentSpec: {
'command': 'echo Hello World & echo $[[${{inputs.component_in_number}}]] & echo ${{inputs.component_in_path}} & echo ${{outputs.component_out_path}} > ${{outputs.component_out_path}}/component_in_number',
'command': 'echo Hello World & echo $[[${{inputs.component_in_number}}]] & echo $[[${{inputs.component_in_path}}]] & echo ${{outputs.component_out_path}} > ${{outputs.component_out_path}}/component_in_number',
'environment': 'azureml:AzureML-sklearn-0.24-ubuntu18.04-py37-cpu:1',
'name': 'command_component_basic',
'description': 'This is the basic command component',
Expand All @@ -37,7 +37,7 @@ async function createOrUpdateComponentVersion(): Promise<void> {
'is_deterministic': true,
'inputs': {
'component_in_number': { 'type': 'number', 'optional': true, 'default': '10.99', 'description': 'A number' },
'component_in_path': { 'type': 'uri_folder', 'description': 'A path' }
'component_in_path': { 'type': 'uri_folder', 'optional': true, 'description': 'A path' }
},
'outputs': { 'component_out_path': { 'type': 'uri_folder' } },
'type': 'command',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import {
JobBase,
} from "@azure/arm-machinelearning";
import { client, getEnvironmentVariable } from "../../utils";
import { createOrUpdateComponentVersion } from "../../assets/component/componentVersionsCreateOrUpdateSample";

// Load the .env file if it exists
import * as dotenv from "dotenv";
dotenv.config();

const resourceGroupName = getEnvironmentVariable("RESOURCEGROUP_NAME");
const workspaceName = getEnvironmentVariable("WORKSPACE_NAME");

/**
* This sample demonstrates how to Create or update pipeline job.
*
* @summary Create or update version.
*/
async function createOrUpdatePipelineJob(): Promise<void> {
// create a simple component
await createOrUpdateComponentVersion();
const name = "simple_pipeline_job";
const body: JobBase = {
properties: {
description: "This is the basic pipeline job",
computeId: "cpu-cluster",
jobType: "Pipeline",
jobs: {
"node1": {
"name": "node1",
"type": "command",
"componentId": "command_component_basic:0.0.1"
}
},
properties: {},
tags: { 'tag': 'tagvalue', 'owner': 'sdkteam' }
}
};
// const credential = new DefaultAzureCredential();
// const client = new AzureMachineLearningWorkspaces(credential, subscriptionId);
try {
console.log("Create or update pipeline job ...")
const pipelineJobCreateOrUpdateResponse = await client.jobs.createOrUpdate(
resourceGroupName,
workspaceName,
name,
body
);
console.log(pipelineJobCreateOrUpdateResponse);
console.log(`Created or update pipeline job ${pipelineJobCreateOrUpdateResponse.name} successfully`);
} catch (err: any) {
console.log(
`errorMessage - ${err.message}\n`
)
}
}

// createOrUpdateComponentVersion().catch(console.error);
export async function main(): Promise<void> {
// This sample uses DefaultAzureCredential, which supports a number of authentication mechanisms.
// See https://docs.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest for more information
// about DefaultAzureCredential and the other credentials that are available for use.
await createOrUpdatePipelineJob();
}

main().catch((error: any) => {
console.error("An error occurred:", error);
console.log("error code: ", error.code);
console.log("error message: ", error.message);
console.log("error stack: ", error.stack);
process.exit(1);
});

This file was deleted.