【问题标题】:Errors Creating Simple Azure HDInsight Spark Cluster with Pulumi使用 Pulumi 创建简单的 Azure HDInsight Spark 集群时出错
【发布时间】:2019-10-09 10:23:32
【问题描述】:

我正在尝试使用 Pulumi Javascript SDK 在 Azure 上创建 HDInsight Spark 集群。我遵循了 Pulumi 提供的关于创建“hello world”GCP Kubernetes 集群的教程,并浏览了 github 上 Pulumi 示例仓库中的 JavaScript 示例,但未能成功创建集群。

我已经尝试根据 Pulumi 存储库中的示例多次更改我的 export 语句,但是当我在我的 pulumi 项目根目录中运行 pulumi up 时,我总是得到一个“未处理的异常”错误,然后是堆栈跟踪。到目前为止,我已尝试使用以下导出语句。

    //attempt 1
    export const sparkClusterName = sparkCluster.name

    //attempt 2
    export const sparkClusterOutput = sparkCluster.output

    //attempt 3
    export const sparkEndpoint = sparkCluster.httpsEndpoint

我使用 Visual Studio Code 作为我的 IDE 使用 Mojave 在 MacBook Pro 上运行所有代码 使用 Pulumi 版本 0.17.11 使用节点版本 12.1.0 azure cli 和 pulumi cli 工具均已安装

我的index.js程序如下:

"use strict";
const pulumi = require("@pulumi/pulumi");
const azure = require("@pulumi/azure");

// Retrieve an Azure Resource Group
const resourceGroup = pulumi.output(azure.core.getResourceGroup({
    name: "MyResourceGroup",
}));
//Create Spark Cluster
const sparkCluster = new azure.hdinsight.SparkCluster("testSparkCluster", {
    clusterVersion: "3.6",
    componentVersion: {
        spark: "2.3",
    },
    gateway: {
        enable: true,
        password: "laDK#21",
        username: "USERname",
    },
    location: resourceGroup.apply(resourceGroup => resourceGroup.location),
    name: "example-hdisparkcluster",
    resourceGroupName: resourceGroup.apply(resourceGroup => resourceGroup.name),
    roles: {
        headNode: {
            password: "AAAlllddck11122$$3",
            username: "USerNameladkfj",
            vmSize: "Standard_A3",
        },
        workerNode: {
            password: "asdlfaDDF143k#@#",
            targetInstanceCount: 3,
            username: "USernaemls",
            vmSize: "Standard_A3",
        },
        zookeeperNode: {
            password: "ASDKLlkjjj##@@323",
            username: "USERname2323",
        },
    },
    storageAccounts: [{
        isDefault: true,
    }],
    tier: "Standard",
});

// Export the spark cluster
export const sparkClusterName = sparkCluster.name;
//export const sparkName = sparkCluster.output
//export const sparkEndpoint = sparkCluster.httpsEndpoint

预期的结果应该是 pulumi CLI 成功显示新堆栈和正在创建的 Spark 集群(然后能够在 Azure 门户上查看集群)。 而是抛出以下错误和堆栈跟踪:

Previewing update (dev):

     Type                 Name                         Plan       Info
 +   pulumi:pulumi:Stack  HDInsight_Spark_Cluster-dev  create     1 error

Diagnostics:
  pulumi:pulumi:Stack (HDInsight_Spark_Cluster-dev):
    error: Running program '/Users/workspace/Pulumi Workspace/Pulumi HDInsight Testing' failed with an unhandled exception:
    /Users/workspace/Pulumi Workspace/Pulumi HDInsight Testing/index.js:50
    export const sparkClusterName = sparkCluster.name;
    ^^^^^^

    SyntaxError: Unexpected token export
        at Module._compile (internal/modules/cjs/loader.js:703:23)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
        at Module.load (internal/modules/cjs/loader.js:628:32)
        at Function.Module._load (internal/modules/cjs/loader.js:555:12)
        at Module.require (internal/modules/cjs/loader.js:666:19)
        at require (internal/modules/cjs/helpers.js:16:16)
        at /Users/workspace/Pulumi Workspace/Pulumi HDInsight Testing/node_modules/@pulumi/pulumi/cmd/run/run.js:195:20
        at Stack.<anonymous> (/Users/workspace/Pulumi Workspace/Pulumi HDInsight Testing/node_modules/@pulumi/pulumi/runtime/stack.js:76:27)
        at Generator.next (<anonymous>)
        at fulfilled (/Users/workspace/Pulumi Workspace/Pulumi HDInsight Testing/node_modules/@pulumi/pulumi/runtime/stack.js:17:58)

我对使用 Azure 非常陌生,并且对 Javascript 仅有基本的了解,因为我的大部分经验是使用 Java 和 C/C++。我参加这个计划的目的只是帮助我通过使用 Pulumi 来使用和了解如何使用 HDInsight。

【问题讨论】:

    标签: javascript azure apache-spark azure-hdinsight pulumi


    【解决方案1】:

    您遇到了语法问题,因为 JavaScript 中的导出与 TypeScript 不同。您复制的导出将在 TS 程序中工作,但在 JS 中您应该编写:

    exports.sparkClusterName = sparkCluster.name;
    

    如果您不熟悉 JavaScript 和 TypeScript,我建议您切换到 TypeScript 并使用 Visual Studio Code 之类的编辑器在编辑时突出显示错误。您的代码中仍然存在许多:enable 而不是 enabled,zookeeperNode 中缺少 vmSize,storageAccountKey 和 storageContainerId 中缺少 storageAccounts。

    最重要的是,您的用户名和密码违反了某些政策,但您只会在运行 pulumi up 时发现这一点,而不是在编辑时。

    这是我的看法:

    const sparkCluster = new azure.hdinsight.SparkCluster("testSparkCluster", {
        clusterVersion: "3.6",
        componentVersion: {
            spark: "2.3",
        },
        gateway: {
            enabled: true,
            password: "@P6g4KMvlhjM",
            username: "username",
        },
        name: "example-hdisparkcluster",
        resourceGroupName: resourceGroup.apply(rg => rg.name),
        roles: {
            headNode: {
                password: "0@Gkv81xt!lR",
                username: "usernamehn",
                vmSize: "Standard_A3",
            },
            workerNode: {
                password: "Wx63!ZMnePHK",
                targetInstanceCount: 3,
                username: "usernamewn",
                vmSize: "Standard_A3",
            },
            zookeeperNode: {
                password: "&43MhoXfZ5ar",
                username: "usernamezn",
                vmSize: "Standard_A3",
            },
        },
        storageAccounts: [{
            isDefault: true,
            storageAccountKey: storageAccount.primaryAccessKey,
            storageContainerId: storageContainer.id,
        }],
        tier: "Standard",
    });
    

    更新:我创建了一个full working example。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-13
      • 1970-01-01
      • 2017-08-24
      • 2017-09-13
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      相关资源
      最近更新 更多