如何在Jelastic安装清单中最后创建的节点上执行操作?

时间:2020-04-28 07:24:21

标签: jelastic

我有以下jps清单:

jpsVersion: 1.3
jpsType: update
application:
  id: test
  name: Test
  version: 0.0

  onInstall:
  - addNodes:
    - nodeType: docker
      count: 1
      fixedCloudlets: 1
      cloudlets: 16
      dockerName: gitlab/gitlab-runner

  onAfterAddNode:
  - installDocker

  actions:
    installDocker:
    - cmd:
      - myDockerInstallScript.sh

我的问题是,即使已成功添加节点,也不会调用onAfterAddNode操作。我究竟做错了什么?如何保证命令只能在添加的节点上运行?

编辑

我的用例如下:我不久前创建了一个环境,我想向其中添加新节点。因此,我需要通过添加新节点并在这些新节点上执行一些安装步骤来更新该环境。

2 个答案:

答案 0 :(得分:1)

如果您只需要在新创建的节点中执行操作,则可以这样做:

jpsVersion: 1.3
jpsType: update
application:
  id: test
  name: Test
  version: 0.0
  onInstall:
  - addNodes:
      nodeType: docker
      count: 1
      nodeGroup: runner
      fixedCloudlets: 1
      cloudlets: 16
      dockerName: gitlab/gitlab-runner
  - installDocker: ${nodes.runner.last.id}
  actions:
    installDocker:
    - cmd [${this}]:
      - myDockerInstallScript.sh

此外,感谢您对文档的评论,我们已对其进行了更新:https://docs.cloudscripting.com/creating-manifest/actions/#addnodes

答案 1 :(得分:0)

仅在成功完成onInstall事件之后,才会执行环境中的其他事件。 onAfterAddNode事件将在下次添加节点时运行。 Here您可以看到事件的顺序。如果您只需要在安装过程中调用该操作,则需要在onInstall中进行此操作:

示例:

jpsVersion: 1.3
jpsType: update
application:
  id: test
  name: Test
  version: 0.0
  onInstall:
  - addNodes:
    - nodeType: docker
      count: 1
      fixedCloudlets: 1
      cloudlets: 16
      dockerName: gitlab/gitlab-runner
  - installDocker
  actions:
    installDocker:
    - cmd:
      - myDockerInstallScript.sh

如果有必要在每次将节点添加到环境拓扑时也执行某种操作,那么您可以这样做:

jpsVersion: 1.3
jpsType: update
application:
  id: test
  name: Test
  version: 0.0
  onInstall:
  - addNodes:
    - nodeType: docker
      count: 1
      nodeGroup: runner
      fixedCloudlets: 1
      cloudlets: 16
      dockerName: gitlab/gitlab-runner
  - installDocker
 onAfterAddNode [runner]:
  - installDocker
  actions:
    installDocker:
    - cmd [runner]:
      - myDockerInstallScript.sh

如果您希望在缩放整个图层后执行特定的操作,则可以通过以下方式进行操作:

jpsVersion: 1.3
jpsType: update
application:
  id: test
  name: Test
  version: 0.0
  onInstall:
  - addNodes:
    - nodeType: docker
      count: 1
      nodeGroup: runner
      fixedCloudlets: 1
      cloudlets: 16
      dockerName: gitlab/gitlab-runner
  - installDocker
 onAfterScaleOut [runner]:
  forEach(event.response.nodes):
    installDocker: ${@i.id} 
  actions:
    installDocker:
    - cmd [${this}]:
      - myDockerInstallScript.sh