<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>5.6. Asynchronous Commands</title><link rel="stylesheet" type="text/css" href="Common_Content/css/default.css" /><link rel="stylesheet" media="print" href="Common_Content/css/print.css" type="text/css" /><meta name="generator" content="publican 2.8" /><meta name="package" content="Apache_CloudStack-Developers_Guide-4.1.0-ja-JP-1-" /><script type="text/javascript" src="../../../../../toc.js"></script><script type="text/javascript">
              addID('Apache_CloudStack');
              
	      addID('Apache_CloudStack.4.1.0');
              
              addID('Apache_CloudStack.4.1.0.books');
	      addID('Apache_CloudStack.4.1.0.Developers_Guide');
              </script><link rel="home" href="index.html" title="CloudStack 開発者ガイド" /><link rel="up" href="api-calls.html" title="第5章 CloudStack API の呼び出し" /><link rel="prev" href="responses.html" title="5.5. Responses" /><link rel="next" href="working-with-usage-data.html" title="第6章 Working With Usage Data" /></head><body class="toc_embeded "><div id="tocdiv" class="toc"><iframe id="tocframe" class="toc" src="../../../../toc.html">This is an iframe, to view it upgrade your browser or enable iframe display.</iframe></div><p id="title"><a class="left" href="http://cloudstack.apache.org"><img src="Common_Content/images/image_left.png" alt="Product Site" /></a><a class="right" href="http://cloudstack.apache.org/docs"><img src="Common_Content/images/image_right.png" alt="Documentation Site" /></a></p><ul class="docnav"><li class="previous"><a accesskey="p" href="responses.html"><strong>戻る</strong></a></li><li class="next"><a accesskey="n" href="working-with-usage-data.html"><strong>次へ</strong></a></li></ul><div xml:lang="ja-JP" class="section" id="asynchronous-commands" lang="ja-JP"><div class="titlepage"><div><div><h2 class="title" id="asynchronous-commands">5.6. Asynchronous Commands</h2></div></div></div><div class="para">
		Asynchronous commands were introduced in CloudStack 2.x. Commands are designated as asynchronous when they can potentially take a long period of time to complete such as creating a snapshot or disk volume. They differ from synchronous commands by the following:
	</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				They are identified in the API Reference by an (A).
			</div></li><li class="listitem"><div class="para">
				They will immediately return a job ID to refer to the job that will be responsible in processing the command.
			</div></li><li class="listitem"><div class="para">
				If executed as a "create" resource command, it will return the resource ID as well as the job ID.
			</div><div class="para">
				You can periodically check the status of the job by making a simple API call to the command, queryAsyncJobResult and passing in the job ID.
			</div></li></ul></div><div xml:lang="ja-JP" class="section" id="job-status" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title" id="job-status">5.6.1. ジョブの状態</h3></div></div></div><div class="para">
		非同期コマンドを利用する際の重要な点はコマンドを実行した際直ちに返ってくるジョブ ID です。ジョブ ID は queryAsyncJobResult コマンドを生成することで定期的にジョブの状態をチェックすることができ、3つの整数値でジョブの状態が返ってきます。
	</div><div class="itemizedlist"><ul><li class="listitem"><div class="para">
				0 - ジョブは実行中です。続けて状態遷移を定期的にポーリングします。
			</div></li><li class="listitem"><div class="para">
				1 - ジョブは正常に完了しました。 ジョブはコマンド実行に紐づく成功値を返します。
			</div></li><li class="listitem"><div class="para">
				2 - ジョブは失敗しました。失敗した理由のコードである "jobresultcode" タグと、失敗理由を表す "jobresult" を確認してください。
			</div></li></ul></div></div><div xml:lang="ja-JP" class="section" id="asynchronous-commands-example" lang="ja-JP"><div class="titlepage"><div><div><h3 class="title" id="asynchronous-commands-example">5.6.2. 例</h3></div></div></div><div class="para">
		The following shows an example of using an asynchronous command. Assume the API command:
	</div><pre class="programlisting">command=deployVirtualMachine&amp;zoneId=1&amp;serviceOfferingId=1&amp;diskOfferingId=1&amp;templateId=1
</pre><div class="para">
		CloudStack will immediately return a job ID and any other additional data.
	</div><pre class="programlisting">
         &lt;deployvirtualmachineresponse&gt; 
              &lt;jobid&gt;1&lt;/jobid&gt;
             &lt;id&gt;100&lt;/id&gt;
         &lt;/deployvirtualmachineresponse&gt;
</pre><div class="para">
		Using the job ID, you can periodically poll for the results by using the queryAsyncJobResult command.
	</div><pre class="programlisting">command=queryAsyncJobResult&amp;jobId=1</pre><div class="para">
		Three possible results could come from this query.
	</div><div class="para">
		Job is still pending:
	</div><pre class="programlisting">
         &lt;queryasyncjobresult&gt; 
              &lt;jobid&gt;1&lt;/jobid&gt;
              &lt;jobstatus&gt;0&lt;/jobstatus&gt;
              &lt;jobprocstatus&gt;1&lt;/jobprocstatus&gt;
         &lt;/queryasyncjobresult&gt;
</pre><div class="para">
		Job has succeeded:
	</div><pre class="programlisting">
            &lt;queryasyncjobresultresponse cloud-stack-version="3.0.1.6"&gt;
                  &lt;jobid&gt;1&lt;/jobid&gt;
                  &lt;jobstatus&gt;1&lt;/jobstatus&gt;
                  &lt;jobprocstatus&gt;0&lt;/jobprocstatus&gt;
                 &lt;jobresultcode&gt;0&lt;/jobresultcode&gt;
                  &lt;jobresulttype&gt;object&lt;/jobresulttype&gt;
                  &lt;jobresult&gt;
                    &lt;virtualmachine&gt;
                    &lt;id&gt;450&lt;/id&gt;
                    &lt;name&gt;i-2-450-VM&lt;/name&gt;
                    &lt;displayname&gt;i-2-450-VM&lt;/displayname&gt;
                    &lt;account&gt;admin&lt;/account&gt;
                    &lt;domainid&gt;1&lt;/domainid&gt;
                    &lt;domain&gt;ROOT&lt;/domain&gt;
                    &lt;created&gt;2011-03-10T18:20:25-0800&lt;/created&gt;
                    &lt;state&gt;Running&lt;/state&gt;
                    &lt;haenable&gt;false&lt;/haenable&gt;
                    &lt;zoneid&gt;1&lt;/zoneid&gt;
                    &lt;zonename&gt;San Jose 1&lt;/zonename&gt;
                    &lt;hostid&gt;2&lt;/hostid&gt;
                    &lt;hostname&gt;905-13.sjc.lab.vmops.com&lt;/hostname&gt;
                    &lt;templateid&gt;1&lt;/templateid&gt;
                    &lt;templatename&gt;CentOS 5.3 64bit LAMP&lt;/templatename&gt;
                    &lt;templatedisplaytext&gt;CentOS 5.3 64bit LAMP&lt;/templatedisplaytext&gt;
                    &lt;passwordenabled&gt;false&lt;/passwordenabled&gt;
                    &lt;serviceofferingid&gt;1&lt;/serviceofferingid&gt;
                    &lt;serviceofferingname&gt;Small Instance&lt;/serviceofferingname&gt;
                    &lt;cpunumber&gt;1&lt;/cpunumber&gt;
                    &lt;cpuspeed&gt;500&lt;/cpuspeed&gt;
                    &lt;memory&gt;512&lt;/memory&gt;
                    &lt;guestosid&gt;12&lt;/guestosid&gt;
                    &lt;rootdeviceid&gt;0&lt;/rootdeviceid&gt;
                    &lt;rootdevicetype&gt;NetworkFilesystem&lt;/rootdevicetype&gt;
                    &lt;nic&gt;
                      &lt;id&gt;561&lt;/id&gt;
                      &lt;networkid&gt;205&lt;/networkid&gt;
                      &lt;netmask&gt;255.255.255.0&lt;/netmask&gt;
                      &lt;gateway&gt;10.1.1.1&lt;/gateway&gt;
                      &lt;ipaddress&gt;10.1.1.225&lt;/ipaddress&gt;
                      &lt;isolationuri&gt;vlan://295&lt;/isolationuri&gt;
                      &lt;broadcasturi&gt;vlan://295&lt;/broadcasturi&gt;
                      &lt;traffictype&gt;Guest&lt;/traffictype&gt;
                      &lt;type&gt;Virtual&lt;/type&gt;
                      &lt;isdefault&gt;true&lt;/isdefault&gt;
                    &lt;/nic&gt;
                    &lt;hypervisor&gt;XenServer&lt;/hypervisor&gt;
                   &lt;/virtualmachine&gt;
                 &lt;/jobresult&gt;
            &lt;/queryasyncjobresultresponse&gt;
</pre><div class="para">
		Job has failed:
	</div><pre class="programlisting">
            &lt;queryasyncjobresult&gt;
                  &lt;jobid&gt;1&lt;/jobid&gt; 
                  &lt;jobstatus&gt;2&lt;/jobstatus&gt; 
                  &lt;jobprocstatus&gt;0&lt;/jobprocstatus&gt;
                  &lt;jobresultcode&gt;551&lt;/jobresultcode&gt;
                  &lt;jobresulttype&gt;text&lt;/jobresulttype&gt;
                  &lt;jobresult&gt;Unable to deploy virtual machine id = 100 due to not enough capacity&lt;/jobresult&gt; 
            &lt;/queryasyncjobresult&gt;
</pre></div></div><ul class="docnav"><li class="previous"><a accesskey="p" href="responses.html"><strong>戻る</strong>5.5. Responses</a></li><li class="up"><a accesskey="u" href="#"><strong>上に戻る</strong></a></li><li class="home"><a accesskey="h" href="index.html"><strong>ホーム</strong></a></li><li class="next"><a accesskey="n" href="working-with-usage-data.html"><strong>次へ</strong>第6章 Working With Usage Data</a></li></ul></body></html>
