使用 REST 命令部署应用程序:一个示例

以下示例描述如何使用 REST 命令来部署应用程序。

开始之前

此示例将执行教程创建简单的 helloWorld 部署中的步骤。在尝试执行此示例之前,请复查该教程。按配置 helloWorld 教程系统中所述配置您的系统。将值替换为您的服务器名称、用户名和密码(如果适用)。

关于此任务

此示例显示如何使用 Linux curl 程序来运行 REST 命令。您可以使用许多其他程序或编程语言来运行 REST 命令。该代码通过在命令行上指定用户名和密码来向服务器进行认证。要了解有关运行 REST 命令以及认证的更多信息,请参阅运行 REST 命令进行认证以运行 REST 命令

此示例中使用的服务器是 server.example.com。用户是 nsmith,密码是 passwd

过程

  1. 创建并导入组件。
    1. 使用 createComponent PUT 命令来创建组件。
      curl -k -u nsmith:passwd
        https://server.example.com:8443/cli/component/create
        -X PUT -d @newComponent.json
      注: 必须在一行上输入命令。此处为了简明而将此命令拆分成不同行。
      以下 JSON 文件表示该组件:
      {
        "name": "helloWorld",
        "description": "",
        "importAutomatically": false,
        "useVfs": true,
        "sourceConfigPlugin": "File System (Versioned)",
        "defaultVersionType": "FULL",
        "properties": {
          "FileSystemVersionedComponentProperties/basePath": "/home/user1/artifacts/shared/helloWorld"
        }
      }
      该命令将返回类似于以下 JSON 信息的结果:
      {
        "id":"cf355787-a772-4533-be45-3e169e9da6eb",
        "securityResourceId":"23504603-ab8c-4740-bc2d-d18c08f790e9",
        "name":"helloWorld",
        "description":"",
        "created":1396878409753,
        "importAutomatically":false,
        "useVfs":true,
        "active":true,
        "integrationFailed":false,
        "deleted":false,
        "defaultVersionType":"FULL",
        "cleanupDaysToKeep":0,
        "cleanupCountToKeep":0,
        "tags":[],
        "user":"nsmith"
      }
    2. 使用 setComponentProperty PUT 命令来设置组件属性。
      curl -k -u nsmith:passwd 
        "https://server.example.com:8443/cli/
        component/propValue?component=helloWorld&name=helloHome&value=c%3A%5ChelloWorld" -X PUT
      该命令将返回类似于以下 JSON 信息的结果:
      {
        "id":"194b6e0c-3f30-4d9a-b3cf-dd61dd1a7328",
        "name":"helloHome",
        "value":"c:\\helloWorld",
        "secure":false
      }
    3. 使用 importVersions PUT 命令来导入组件版本。
      curl -k -u nsmith:passwd 
        https://server.example.com:8443/cli/component/integrate
        -X PUT -d {"component":"helloWorld"}
      该命令将返回以下结果:
      {}
  2. 使用 createComponentProcess PUT 命令来创建组件进程。
    curl -k -u nsmith:passwd
      https://server.example.com:8443/cli/componentProcess/create
      -X PUT -d @componentProcess.json
    以下 JSON 文件表示此组件进程:
    {
      "active": "true",
      "component": "helloWorld",
      "configActionType": "ADD",
      "defaultWorkingDir": "${p:resource/work.dir}/${p:component.name}",
      "description": "",
      "inventoryActionType": "ADD",
      "name": "helloProcess",
      "propDefs": [],
      "rootActivity": {
        "children": [
          {
            "allowFailure": false,
            "children": [],
            "commandName": "Delete Files and Directories",
            "impersonationUseSudo": false,
            "name": "Clean work space",
            "pluginName": "File Utils",
            "pluginVersion": 31,
            "properties":{
                "baseDir":".",
                "includes":"*",
                "excludes":"",
                "followSymlinks":"false",
                "caseSensitive":"true"
             },
            "showHidden": false,
            "type": "plugin",
            "useImpersonation": false
          },
          {
            "allowFailure": false,
            "children": [],
            "commandName": "Download Artifacts",
            "impersonationUseSudo": false,
            "name": "Download Artifacts",
            "pluginName": "IBM UrbanCode Deploy Versioned File Storage",
            "pluginVersion": 18,
            "properties":{
               "directoryOffset":".",
               "artifactSetBaseDir":"",
               "fileIncludePatterns":"**/*",
               "fileExcludePatterns":"",
               "syncMode":"true",
               "fullVerification":"true",
               "setFileExecuteBits":"false",
               "verifyFileIntegrity":"false",
               "repositoryUrl":"${p:server.url}/vfs",
               "repositoryId":"${p:component/code_station/repository}",
               "label":"${p:version.name}",
               "serverUrl":"${p:server.url}",
               "compId":"${p:component.id}",
               "resId":"${p:resource.id}",
               "charset":""
            },
            "showHidden": false,
            "type": "plugin",
            "useImpersonation": false
          },
          {
             "allowFailure":false,
             "children": [],
             "commandName":"Create .zip File",
             "impersonationUseSudo":false,
             "name":"Compress artifacts",
             "pluginName":"File Utils",
             "pluginVersion":31,
             "properties":{
                "zipName":"helloWorld.zip",
                "baseDir":".",
                "includes":"*",
                "excludes":"",
                "update":"false",
                "followSymlinks":"false",
                "caseSensitive":"true"
             },
            "showHidden": false,
            "type": "plugin",
            "useImpersonation": false
          },
          {
             "allowFailure":false,
             "children": [],
             "commandName":"Move Directory",
             "impersonationUseSudo":false,
             "name":"Deploy artifacts",
             "pluginName":"File Utils",
             "pluginVersion":31,
             "properties":{
                "sourceDir":".",
                "destDir":"${p:helloHome}/target",
                "includes":"*.zip",
                "excludes":"",
                "mapperRules":""
             },
            "showHidden": false,
            "type": "plugin",
            "useImpersonation": false
          },
          {
            "children": [],
            "name": "FINISH",
            "type": "finish"
          }
        ],
        "edges": [
          {
            "to": "Clean work space",
            "type": "ALWAYS",
            "value": ""
          },
          {
            "from": "Clean work space",
            "to": "Download Artifacts",
            "type": "ALWAYS",
            "value": ""
          },
          {
            "from": "Download Artifacts",
            "to": "Compress artifacts",
            "type": "ALWAYS",
            "value": ""
          },
          {
            "from": "Compress artifacts",
            "to": "Deploy artifacts",
            "type": "ALWAYS",
            "value": ""
          },
          {
            "from": "Deploy artifacts",
            "to": "FINISH",
            "type": "ALWAYS",
            "value": ""
          }
        ],
        "name": "GRAPH",
        "offsets": [
          {
            "name": "Clean work space",
            "x": "-65",
            "y": "90"
          },
          {
            "name": "Download Artifacts",
            "x": "-70",
            "y": "210"
          },
          {
            "name": "Compress artifacts",
            "x": "-70",
            "y": "290"
          },
          {
            "name": "Deploy artifacts",
            "x": "-65",
            "y": "370"
          },
          {
            "name": "FINISH",
            "x": "-60",
            "y": "450"
          }
        ],
        "type": "graph"
      },
      "status": "Active",
      "takesVersion": "true"
    }
    该命令将返回类似于以下 JSON 信息的结果:
    {
      "id":"12f65517-5fc1-44ff-a58b-2401cfba8f2f",
      "name":"helloProcess",
      "description":"",
      "defaultWorkingDir":"${p:resource\/work.dir}\/${p:component.name}",
      "takesVersion":true,
      "inventoryActionType":"ADD",
      "status":"Active",
      "active":true,
      "versionCount":1,
      "version":1,
      "commit":0,
      "path":"components\/cf355787-a772-4533-be45-3e169e9da6eb\/processes\/12f65517-5fc1-44ff-a58b-2401cfba8f2f"
    }
  3. 创建应用程序,然后使组件与应用程序相关联。
    1. 使用 createApplication PUT 命令来创建应用程序。
      curl -k -u nsmith:passwd
        https://server.example.com:8443/cli/application/create
        -X PUT -d @newApplication.json
      以下 JSON 文件表示该应用程序:
      {
        "name": "hello Application",
        "description": "",
        "notificationScheme": "None",
        "enforceCompleteSnapshots": "false"
      }
      该命令将返回类似于以下 JSON 信息的结果:
      {
        "id":"932452cc-3562-4545-8de5-c57aa7efbcc4",
        "securityResourceId":"2bc72218-dbfe-4c11-b16f-752b7ca63d06",
        "name":"hello Application",
        "description":"",
        "created":1396882026943,
        "enforceCompleteSnapshots":false,
        "active":true,
        "tags":[],
        "user":"nsmith"
      }
    2. 使用 addComponentToApp PUT 命令来使组件与应用程序相关联。
      curl -k -u nsmith:passwd 
        "https://server.example.com:8443/cli/
        application/addComponentToApp?component=helloWorld&application=hello%20Application"
        -X PUT
      该命令将返回以下结果:
      {}
  4. 创建环境,然后使环境与资源相关联。
    1. 使用 createEnvironment PUT 命令来创建环境。
      curl -k -u nsmith:passwd 
        "https://server.example.com:8443/cli/environment/createEnvironment?application=hello%20Application&name=helloDeploy"
        -X PUT
      该命令将返回环境的标识,该标识类似于以下字符串:
      2142c0e3-7ebe-4a2f-9e0d-14ccacc70a79
    2. 使用 addEnvironmentBaseResources PUT 命令来使您先前配置的资源与环境相关联。
      curl -k -u nsmith:passwd 
        "https://server.example.com:8443/cli/environment/addBaseResource?application=hello%20Application&environment=helloDeploy&resource=%2FhelloWorld%20Tutorial"
        -X PUT
      如果已正确地使该资源与环境相关联,那么此命令不会返回结果。
    3. 使用 createResource PUT 命令来将 helloWorld 组件映射至代理程序资源。
      curl -k -u nsmith:passwd 
        https://server.example.com:8443/cli/resource/resource 
        -X PUT -d @componentResource.json
      以下 JSON 文件表示该组件资源:
      {
        "roleId":"09456abd-65e3-469e-94c6-a6a873b971a8",
        "name":"helloWorld",
        "description":"",
        "inheritTeam":"true",
        "useImpersonation":"false",
        "roleProperties":{},
        "parentId":"b2ff919e-b4c0-4d13-8973-eff44e4835e2",
        "teamMappings":[]
      }
      该命令将返回类似于以下 JSON 信息的结果:
      {
        "id":"ba958487-fb86-4290-9240-da766af37963",
        "securityResourceId":"66685b67-21ab-411d-99bb-f577a74d88b3",
        "name":"helloWorld",
        "path":"\/helloWorld Tutorial\/fit-vm11-157\/helloWorld",
        "active":true,
        "description":"",
        "inheritTeam":true,
        "impersonationPassword":"****",
        "impersonationUseSudo":false,
        "impersonationForce":false,
        "type":"subresource",
        "status":"ONLINE",
        "hasAgent":true,
        "tags":[]
      }
    4. 使用 addTagToResource PUT 命令来将标记添加到组件资源。
      curl -k -u nsmith:passwd
        "https://server.example.com:8443/cli/
        resource/tag?resource=ba958487-fb86-4290-9240-da766af37963&tag=blueCycle&color=0000FF"
        -X PUT
      如果已正确标记该组件,那么此命令不会返回结果。
  5. 使用 createApplicationProcess PUT 命令来创建应用程序进程。
    curl -k -u nsmith:passwd
      https://server.example.com:8443/cli/application/create
      -X PUT -d @applicationProcess.json
    以下 JSON 文件表示该应用程序进程。应用程序标识与步骤 3 中返回的标识相同。
    {
      "application": "932452cc-3562-4545-8de5-c57aa7efbcc4",
      "description": "",
      "inventoryManagementType": "AUTOMATIC",
      "name": "hello App Process",
      "offlineAgentHandling": "PRE_EXECUTION_CHECK",
      "rootActivity": {
        "children": [
          {
            "children": [{
              "children": [{
                "allowFailure": false,
                "children": [],
                "componentName": "helloWorld",
                "componentProcessName": "helloProcess",
                "name": "Deploy helloWorld",
                "properties": {},
                "type": "componentProcess"
              }],
              "componentName": "helloWorld",
              "name": "inventoryVersionCheck",
              "status": "Active",
              "type": "inventoryVersionDiff"
            }],
            "componentName": "helloWorld",
            "failFast": "false",
            "maxIteration": "-1",
            "name": "Deploy helloWorld",
            "runOnlyOnFirst": "false",
            "type": "componentEnvironmentIterator"
          },
          {
            "children": [],
            "name": "FINISH",
            "type": "finish"
          }
        ],
        "edges": [
          {
            "to": "Deploy helloWorld",
            "type": "ALWAYS",
            "value": ""
          },
          {
            "from": "Deploy helloWorld",
            "to": "FINISH",
            "type": "ALWAYS",
            "value": ""
          }
        ],
        "name": "GRAPH",
        "offsets": [
          {
            "name": "Deploy helloWorld",
            "x": "-35",
            "y": "210"
          },
          {
            "name": "FINISH",
            "x": "0",
            "y": "420"
          }
        ],
        "propDefs": [],
        "type": "graph"
      }
    }
    该命令将返回类似于以下 JSON 信息的结果:
    {
      "id":"37d563ce-7885-48f1-b8c0-f79046c0f024",
      "name":"hello App Process",
      "description":"",
      "active":true,
      "inventoryManagementType":"AUTOMATIC",
      "offlineAgentHandling":"PRE_EXECUTION_CHECK",
      "versionCount":1,
      "version":1,
      "commit":0,
      "path":"applications\/932452cc-3562-4545-8de5-c57aa7efbcc4\/processes\/37d563ce-7885-48f1-b8c0-f79046c0f024"
    }
  6. 使用 requestApplicationProcess PUT 命令来部署应用程序。
    curl -k -u nsmith:passwd
      https://server.example.com:8443/cli/applicationProcessRequest/request
      -X PUT -d @applicationDeploy.json
    以下 JSON 文件表示该部署请求:
    {
      "application": "hello Application",
      "applicationProcess": "hello App Process",
      "environment": "helloDeploy",
      "versions": [{
        "version": "1.0",
        "component": "helloWorld"
      }]
    }
    该命令将返回类似于以下 JSON 信息的结果:
    {"requestId":"bffff82f-ff69-4c07-b010-26ca3f21be39"}

反馈