0

Assume I have the following actions in my jps manifest:

actions:
  installDatabase:
    install:
      jps: ${baseUrl}/jelastic/postgres/manifest.jps
      envName: ${settings.pgEnvName}
      displayName: Database cluster
  myOtherAction:
  - cmd [cp]:
    - doSomethingWithTheDatabaseHostname

In the first action, I install my database. It creates a separate Jelastic environment. Then, in the second action, acting on the current environment (not the database), I would like to get the database hostname from the first action. Even more, I'd to have the database master node. How can I do that? I found nothing in the usual Jelastic or cloudscripting documentation on the topic.

EDIT

In the action myOtherAction, I want to install another jps which needs the hostname of the database installed by the action installDatabase. It can be that the other jps needs to connect to that database. I don't want to install multiple jps manifests manually. I want to install all the manifests I need automatically. In the case described here, the first manifest installs a database environment. I need to get the node id of the master node of that database and pass it to the next manifest. Is that possible?

Laurent Michel
  • 1,069
  • 3
  • 14
  • 29
  • 1
    Laurent, what exactly do you want to do with the hostname? You can create another jps with type: update and use all available placeholders in that jps https://docs.cloudscripting.com/creating-manifest/placeholders/#node-placeholders – Ruslan Apr 28 '20 at 09:34
  • Is the only solution to have multiple jps and install them with a shell script, passing values of created environments from one jps to the next with jelastic api calls? or can I make those api calls in my "root" jps manifest and route the responses of those jelastic api calls to my actions in my jps? – Laurent Michel Apr 29 '20 at 05:06

1 Answers1

2

There are several options for how you can work with several environments from one JPS, for example, you can install another JPS:

actions:
  installDatabase:
    - install:
        jps: ${baseUrl}/jelastic/postgres/manifest.jps
        envName: ${settings.pgEnvName}
        displayName: Database cluster
    - install:
        envName: ${settings.pgEnvName}
        jps:
          type: upddate
          name: Configure Database
          onInstall:            
            - cmd [${nodes.sqldb.master.id}]: 
                - echo ${nodes.sqldb.master.address}
                - doSomethingWithTheDatabaseHostname

or you can execute queries in another environment using the API:

actions:
  installDatabase:
    - install:
        jps: ${baseUrl}/jelastic/postgres/manifest.jps
        envName: ${settings.pgEnvName}
        displayName: Database cluster]     

    - script: |
        var resp = api.env.control.GetEnvInfo('${settings.pgEnvName}', session);
        if (resp.result != 0) return resp;

        for (var i = 0, node; node = resp.nodes[i]; i++ ) {
          if (node.nodeGroup == "sqldb" && node.ismaster) {
            return { result: 0, node: node };
          }
        }

        return { result : "error", message: "node not found" };

    - env.control.ExecCmdById:
       envName: ${settings.pgEnvName}
       nodeId: ${response.node.id}
       commandList:
         # doSomethingWithTheDatabaseHostname:
         - command: hostname
Virtuozzo
  • 1,993
  • 1
  • 10
  • 13
  • Oh that's cool if that works like that. I'll give the second suggestion a try. The first I know is working, but not applicable to my present problem. – Laurent Michel Apr 29 '20 at 07:22