diff --git a/.gitignore b/.gitignore index 009b6af790..c25140158f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ config.json *.log scratch/* config-amlexamples.json +node_modules \ No newline at end of file diff --git a/sdk/typescript/package.json b/sdk/typescript/package.json index 6b74fd2417..62295575d9 100644 --- a/sdk/typescript/package.json +++ b/sdk/typescript/package.json @@ -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" }, @@ -41,4 +41,4 @@ "typescript": "~4.8.0", "rimraf": "latest" } -} \ No newline at end of file +} diff --git a/sdk/typescript/src/resources/component/componentVersionsCreateOrUpdateSample.ts b/sdk/typescript/src/assets/component/componentVersionsCreateOrUpdateSample.ts similarity index 90% rename from sdk/typescript/src/resources/component/componentVersionsCreateOrUpdateSample.ts rename to sdk/typescript/src/assets/component/componentVersionsCreateOrUpdateSample.ts index 04129bd0ce..d9dabf0774 100644 --- a/sdk/typescript/src/resources/component/componentVersionsCreateOrUpdateSample.ts +++ b/sdk/typescript/src/assets/component/componentVersionsCreateOrUpdateSample.ts @@ -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 { +export async function createOrUpdateComponentVersion() : Promise { 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', @@ -37,7 +37,7 @@ async function createOrUpdateComponentVersion(): Promise { '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', diff --git a/sdk/typescript/src/resources/component/componentVersionsGetSample.ts b/sdk/typescript/src/assets/component/componentVersionsGetSample.ts similarity index 100% rename from sdk/typescript/src/resources/component/componentVersionsGetSample.ts rename to sdk/typescript/src/assets/component/componentVersionsGetSample.ts diff --git a/sdk/typescript/src/resources/component/componentVersionsListSample.ts b/sdk/typescript/src/assets/component/componentVersionsListSample.ts similarity index 100% rename from sdk/typescript/src/resources/component/componentVersionsListSample.ts rename to sdk/typescript/src/assets/component/componentVersionsListSample.ts diff --git a/sdk/typescript/src/jobs/pipelines/pipelineJobCreateOrUpdateSample.ts b/sdk/typescript/src/jobs/pipelines/pipelineJobCreateOrUpdateSample.ts new file mode 100644 index 0000000000..1145e13f73 --- /dev/null +++ b/sdk/typescript/src/jobs/pipelines/pipelineJobCreateOrUpdateSample.ts @@ -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 { + // 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 { + // 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); +}); \ No newline at end of file diff --git a/sdk/typescript/src/resources/component/componentVersionsDeleteSample.ts b/sdk/typescript/src/resources/component/componentVersionsDeleteSample.ts deleted file mode 100644 index 7ea026c10e..0000000000 --- a/sdk/typescript/src/resources/component/componentVersionsDeleteSample.ts +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { client, getEnvironmentVariable } from "../../utils"; - -// 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 Delete version. - * - * @summary Delete version. - * x-ms-original-file: specification/machinelearningservices/resource-manager/Microsoft.MachineLearningServices/stable/2022-10-01/examples/ComponentVersion/delete.json - */ -async function deleteComponentVersion(): Promise { - const name = "command_component_basic"; - const version = "0.0.1"; - try { - console.log("Delete component ...") - const componentVersionsDeleteResponse = await client.componentVersions.delete( - resourceGroupName, - workspaceName, - name, - version - ); - console.log(componentVersionsDeleteResponse); - console.log(`Delete component successfully`); - } catch (err: any) { - console.log( - `errorMessage - ${err.message}\n` - ) - } -} - -// deleteComponentVersion().catch(console.error); -export async function main(): Promise { - // 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 deleteComponentVersion(); -} - -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); -});