* @param string $director director name
* @param string $component_name component name
* @param string $type output type (e.g. header, running, terminated ...etc.)
+ * @param integer $limit item limit
+ * @param integer $offset item offset
* @return array ready array parsed component status output
*/
- public function getStatus($director, $component_name = null, $type = null) {
+ public function getStatus($director, $component_name = null, $type = null, $limit = 0, $offset = 0) {
$ret = array('output' => array(), 'error' => 0);
$result = $this->getModule('bconsole')->bconsoleCommand(
$director,
);
if ($result->exitcode === 0) {
$ret['output'] = $this->parseStatus($result->output, $type);
- if (is_string($type) && key_exists($type, $ret['output'])) {
+ $is_type = (is_string($type) && key_exists($type, $ret['output']));
+ if ($is_type) {
if ($type === self::OUTPUT_TYPE_HEADER) {
$ret['output'] = array_pop($ret['output'][$type]);
} else {
$ret['output'] = $ret['output'][$type];
}
}
+ if ($limit > 0 || $offset > 0 && (!$type || $type != self::OUTPUT_TYPE_HEADER)) {
+ $output = $ret['output'];
+ if ($is_type) {
+ $output = [$type => $output];
+ }
+ $item_types = [
+ self::OUTPUT_TYPE_SCHEDULED,
+ self::OUTPUT_TYPE_RUNNING,
+ self::OUTPUT_TYPE_TERMINATED
+ ];
+ foreach ($output as $type => $values) {
+ if (!in_array($type, $item_types)) {
+ continue;
+ }
+ $output[$type] = array_slice($values, $offset, $limit);
+ }
+ if ($is_type) {
+ $ret['output'] = $output[$type];
+ } else {
+ $ret['output'] = $output;
+ }
+ }
} else {
$ret['output'] = $result->output;
}
);
$opts = array();
for($i = 0; $i < count($output); $i++) {
+ if (preg_match('/^(error|errmsg)=/', $output[$i]) === 1) {
+ // skip error type items
+ continue;
+ }
if (in_array($output[$i], $types)) { // check if type
$type = rtrim($output[$i], ':');
- } elseif ($type === self::OUTPUT_TYPE_HEADER && count($opts) == 0 && $output[$i] === '') {
+ } elseif ($type === self::OUTPUT_TYPE_HEADER && count($opts) == 1 && strpos($output[$i], 'level') === 0) {
/**
* special treating 'scheduled' type because this type
* is missing in the api status dir output.
class DirectorStatus extends ConsoleOutputPage {
public function get() {
+ $misc = $this->getModule('misc');
$status = $this->getModule('status_dir');
$director = $this->Request->contains('name') && $this->getModule('misc')->isValidName($this->Request['name']) ? $this->Request['name'] : null;
$type = $this->Request->contains('type') && $status->isValidOutputType($this->Request['type']) ? $this->Request['type'] : null;
$out_format = $this->Request->contains('output') && $this->isOutputFormatValid($this->Request['output']) ? $this->Request['output'] : parent::OUTPUT_FORMAT_RAW;
+ $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
+ $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$dirs = [];
$result = $this->getModule('bconsole')->getDirectors();
} elseif ($out_format === parent::OUTPUT_FORMAT_JSON) {
$out = $this->getJSONOutput([
'director' => $director,
- 'type' => $type
+ 'type' => $type,
+ 'limit' => $limit,
+ 'offset' => $offset
]);
}
$this->output = $out['output'];
return $status->getStatus(
$params['director'],
null,
- $params['type']
+ $params['type'],
+ $params['limit'],
+ $params['offset']
);
}
}