HCE Project PHP language client API bindings OOP style  1.1.1
Hierarchical Cluster Engine PHP Client Interface API OOP style
 All Classes Namespaces Files Functions Variables Pages
NodeManager.inc.php
Go to the documentation of this file.
1 <?php
2 
14 namespace HCE\admin {
15 
16  require_once 'Constants.inc.php';
17  require_once 'Node.inc.php';
18  require_once 'NodeCommand.inc.php';
19  require_once 'NodeManageRequest.inc.php';
20  require_once 'NodeManageResponse.inc.php';
21 
25  class NodeManager {
29  protected $nodes = array ();
30 
34  protected $responses = array ();
35 
39  protected $error = 0;
40 
48  public function setNodes($nodes) {
49  $this->nodes = $nodes;
50  }
51 
57  public function getNodes() {
58  return $this->nodes;
59  }
60 
68  public function setErrorCode($errorCode) {
69  $this->error = $errorCode;
70  }
71 
77  public function getErrorCode() {
78  return $this->error;
79  }
86  public function addResponseItem($responseItem) {
87  if ($responseItem !== NULL) {
88  $this->responses [] = $responseItem;
89  }
90  }
91 
98  public function deleteResponseItem($index) {
99  if (isset ( $this->responses [$index] )) {
100  unset ( $this->responses [$index] );
101  }
102  }
103 
110  public function setResponses($responses) {
111  $this->responses = $responses;
112  }
113 
121  public function getResponseItem($index = NULL) {
122  if ($index === NULL) {
123  return count ( $this->responses );
124  } else {
125  return $this->responses [$index];
126  }
127  }
128 
132  public function getResponses() {
133  return $this->responses;
134  }
135 
143  public function __construct($nodes = null) {
144  // Set nodes
145  if ($nodes !== null) {
146  $this->setNodes ( $nodes );
147  }
148  }
149 
153  public function __destruct() {
154  $this->nodes = null;
155  $this->responses = null;
156  }
157 
166  public function execute($commandObject) {
167  $ret = true;
168 
169  // Make $NodeManageResponse object instance to return
170  $request = new NodeManageRequest ();
171 
172  // For each node
173  foreach ( $this->nodes as $node ) {
174  // Execute command for node
175  $response = $request->execute ( $commandObject, $node );
176  // accumulate response item
177  $this->addResponseItem ( $response );
178  if ($response->getErrorCode ()) {
179  $ret = false;
180  }
181  }
182 
183  return $ret;
184  }
185 
191  public function getResponsesDump() {
192  $ret = '';
193 
194  // Process all responses
195  foreach ( $this->responses as $response ) {
196  if ($response->getErrorCode ()) {
197  $ret .= MSG_NODE_MANAGE_RESPONSE_ITEM_ERROR . $response->getErrorCode () . PHP_EOL;
198  } else {
199  $transportResponse = $response->getResponse ();
200  if ($transportResponse->getErrorCode ()) {
201  $ret .= MSG_TRANSPORT_RESPONSE_ITEM_ERROR . $transportResponse->getErrorCode () . PHP_EOL;
202  } else {
203  // Get transport response items from transport response object
204  $transportResponsesItems = $transportResponse->getResponses ();
205  // Dump all items data
206  foreach ( $transportResponsesItems as $transportResponseItem ) {
207  $ret .= var_export ( $transportResponseItem, true );
208  }
209  }
210  }
211  }
212 
213  return $ret;
214  }
215 
221  public function getResponsesData() {
222  $ret = array ();
223 
224  // Process all responses
225  foreach ( $this->responses as $response ) {
226  $ret [] = array (
227  $response->getResponseMessageErrorCode (),
228  $response->getResponseMessageId (),
229  $response->getResponseMessageBody ()
230  );
231  }
232 
233  return $ret;
234  }
235 
242  public function getResponsesFields() {
243  $ret = array ();
244 
245  // Process all responses
246  foreach ( $this->responses as $response ) {
247  $ret [] = $response->getResponseCommandFields ();
248  }
249 
250  return $ret;
251  }
252  }
253 }
254 
255 ?>