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
      注: コマンドは 1 行で入力する必要があります。ここでは見やすくするためにコマンドの行を分けてあります。
      以下の 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
      コマンドは環境の ID を返します。環境の ID は以下のような文字列になります。
      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 ファイルはアプリケーション・プロセスを表します。 アプリケーション ID は、ステップ 3 で返された ID と同じです。
    {
      "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"}

フィードバック