storagenode.class.php (fogproject-1.5.5) | : | storagenode.class.php (fogproject-1.5.6) | ||
---|---|---|---|---|
skipping to change at line 46 | skipping to change at line 46 | |||
'id' => 'ngmID', | 'id' => 'ngmID', | |||
'name' => 'ngmMemberName', | 'name' => 'ngmMemberName', | |||
'description' => 'ngmMemberDescription', | 'description' => 'ngmMemberDescription', | |||
'isMaster' => 'ngmIsMasterNode', | 'isMaster' => 'ngmIsMasterNode', | |||
'storagegroupID' => 'ngmGroupID', | 'storagegroupID' => 'ngmGroupID', | |||
'isEnabled' => 'ngmIsEnabled', | 'isEnabled' => 'ngmIsEnabled', | |||
'isGraphEnabled' => 'ngmGraphEnabled', | 'isGraphEnabled' => 'ngmGraphEnabled', | |||
'path' => 'ngmRootPath', | 'path' => 'ngmRootPath', | |||
'ftppath' => 'ngmFTPPath', | 'ftppath' => 'ngmFTPPath', | |||
'bitrate' => 'ngmMaxBitrate', | 'bitrate' => 'ngmMaxBitrate', | |||
'helloInterval' => 'ngmHelloInterval', | ||||
'snapinpath' => 'ngmSnapinPath', | 'snapinpath' => 'ngmSnapinPath', | |||
'sslpath' => 'ngmSSLPath', | 'sslpath' => 'ngmSSLPath', | |||
'ip' => 'ngmHostname', | 'ip' => 'ngmHostname', | |||
'maxClients' => 'ngmMaxClients', | 'maxClients' => 'ngmMaxClients', | |||
'user' => 'ngmUser', | 'user' => 'ngmUser', | |||
'pass' => 'ngmPass', | 'pass' => 'ngmPass', | |||
'key' => 'ngmKey', | 'key' => 'ngmKey', | |||
'interface' => 'ngmInterface', | 'interface' => 'ngmInterface', | |||
'bandwidth' => 'ngmBandwidthLimit', | 'bandwidth' => 'ngmBandwidthLimit', | |||
'webroot' => 'ngmWebroot' | 'webroot' => 'ngmWebroot' | |||
skipping to change at line 116 | skipping to change at line 117 | |||
'snapinpath', | 'snapinpath', | |||
'sslpath', | 'sslpath', | |||
'webroot' | 'webroot' | |||
); | ); | |||
if (in_array($key, $pathvars)) { | if (in_array($key, $pathvars)) { | |||
if (trim(parent::get($key)) === '/') { | if (trim(parent::get($key)) === '/') { | |||
return parent::get($key); | return parent::get($key); | |||
} | } | |||
return rtrim(parent::get($key), '/'); | return rtrim(parent::get($key), '/'); | |||
} | } | |||
if ($key === 'pass') { | ||||
return htmlspecialchars_decode(parent::get($key), ENT_QUOTES | ENT_H | ||||
TML401); | ||||
} | ||||
$loaders = array( | $loaders = array( | |||
'snapinfiles' => 'getSnapinfiles', | 'snapinfiles' => 'getSnapinfiles', | |||
'images' => 'getImages', | 'images' => 'getImages', | |||
'logfiles' => 'getLogfiles' | 'logfiles' => 'getLogfiles' | |||
); | ); | |||
if (in_array($key, array_keys($loaders)) | if (in_array($key, array_keys($loaders)) | |||
&& !$this->isLoaded($key) | && !$this->isLoaded($key) | |||
) { | ) { | |||
$func = $loaders[$key]; | $func = $loaders[$key]; | |||
$this->{$func}(); | $this->{$func}(); | |||
skipping to change at line 184 | skipping to change at line 188 | |||
return $Failed; | return $Failed; | |||
} | } | |||
/** | /** | |||
* Loads the logfiles available on this node. | * Loads the logfiles available on this node. | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public function getLogfiles() | public function getLogfiles() | |||
{ | { | |||
$paths = array_values( | ||||
array_filter( | ||||
$this->_getData('logfiles') | ||||
) | ||||
); | ||||
natcasesort($paths); | ||||
$this->set('logfiles', (array)$paths); | ||||
} | ||||
/** | ||||
* Get's the storage node snapins, logfiles, and images | ||||
* in a single multi call rather than three individual calls. | ||||
* | ||||
* @return array | ||||
*/ | ||||
private function _getData($item) | ||||
{ | ||||
if (!$this->get('online')) { | if (!$this->get('online')) { | |||
return; | return; | |||
} | } | |||
$url = sprintf( | $logpaths = array( | |||
'%s://%s/fog/status/getfiles.php?path=%s', | ||||
self::$httpproto, | ||||
$this->get('ip'), | ||||
'%s' | ||||
); | ||||
$paths = array( | ||||
'/var/log/nginx', | '/var/log/nginx', | |||
'/var/log/httpd', | '/var/log/httpd', | |||
'/var/log/apache2', | '/var/log/apache2', | |||
'/var/log/fog', | '/var/log/fog', | |||
'/var/log/php7.0-fpm', | '/var/log/php7.0-fpm', | |||
'/var/log/php-fpm', | '/var/log/php-fpm', | |||
'/var/log/php5-fpm', | '/var/log/php5-fpm', | |||
'/var/log/php5.6-fpm', | '/var/log/php5.6-fpm', | |||
); | ); | |||
$url = sprintf( | $items = array( | |||
$url, | 'images' => urlencode($this->get('path')), | |||
urlencode(implode(':', $paths)) | 'snapinfiles' => urlencode($this->get('snapinpath')), | |||
'logfiles' => urlencode(implode(':', $logpaths)) | ||||
); | ); | |||
$paths = self::$FOGURLRequests->process($url); | if (!array_key_exists($item, $items)) { | |||
$tmppath = array(); | ||||
foreach ((array)$paths as $index => &$response) { | ||||
$tmppath = self::fastmerge( | ||||
(array)$tmppath, | ||||
(array)json_decode($response, true) | ||||
); | ||||
unset($response); | ||||
} | ||||
$paths = array_filter($tmppath); | ||||
$paths = array_values($paths); | ||||
natcasesort($paths); | ||||
$this->set('logfiles', (array)$paths); | ||||
} | ||||
/** | ||||
* Get's the storage node snapins, logfiles, and images | ||||
* in a single multi call rather than three individual calls. | ||||
* | ||||
* @return void | ||||
*/ | ||||
private function _getData() | ||||
{ | ||||
if (!$this->get('online')) { | ||||
return; | return; | |||
} | } | |||
$url = sprintf( | $url = sprintf( | |||
'%s://%s/fog/status/getfiles.php', | '%s://%s/fog/status/getfiles.php?path=%s', | |||
self::$httpproto, | self::$httpproto, | |||
$this->get('ip') | $this->get('ip'), | |||
$items[$item] | ||||
); | ); | |||
$keys = array( | $response = self::$FOGURLRequests->process($url); | |||
'images' => urlencode($this->get('path')), | return preg_grep( | |||
'snapinfiles' => urlencode($this->get('snapinpath')) | '#dev|postdownloadscripts|ssl#', | |||
json_decode($response[0], true), | ||||
PREG_GREP_INVERT | ||||
); | ); | |||
$urls = array(); | ||||
foreach ((array)$keys as $key => &$data) { | ||||
$urls[] = sprintf( | ||||
'%s?path=%s', | ||||
$url, | ||||
$data | ||||
); | ||||
unset($data); | ||||
} | ||||
$paths = self::$FOGURLRequests->process($urls); | ||||
$pat = '#dev|postdownloadscripts|ssl#'; | ||||
$values = array(); | ||||
$index = 0; | ||||
foreach ((array)$keys as $key => &$data) { | ||||
$values = $paths[$index]; | ||||
unset($paths[$index]); | ||||
$values = json_decode($values, true); | ||||
$values = array_map('basename', (array)$values); | ||||
$values = preg_replace( | ||||
$pat, | ||||
'', | ||||
$values | ||||
); | ||||
$values = array_unique( | ||||
(array)$values | ||||
); | ||||
$values = array_filter( | ||||
(array)$values | ||||
); | ||||
if ($key === 'images') { | ||||
$values = self::getSubObjectIDs( | ||||
'Image', | ||||
array('path' => $values) | ||||
); | ||||
} | ||||
$this->set($key, $values); | ||||
$index++; | ||||
unset($data); | ||||
} | ||||
unset($values, $paths); | ||||
} | } | |||
/** | /** | |||
* Loads the snapins available on this node. | * Loads the snapins available on this node. | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public function getSnapinfiles() | public function getSnapinfiles() | |||
{ | { | |||
$this->_getData(); | $response = $this->_getData('snapinfiles'); | |||
$values = array_map('basename', (array)$response); | ||||
$this->set('snapinfiles', $values); | ||||
} | } | |||
/** | /** | |||
* Loads the images available on this node. | * Loads the images available on this node. | |||
* | * | |||
* @return void | * @return void | |||
*/ | */ | |||
public function getImages() | public function getImages() | |||
{ | { | |||
$this->_getData(); | $response = $this->_getData('images'); | |||
$values = array_map('basename', (array)$response); | ||||
$values = self::getSubObjectIDs( | ||||
'Image', | ||||
array('path' => $values) | ||||
); | ||||
$this->set('images', $values); | ||||
} | } | |||
/** | /** | |||
* Gets this node's load of clients. | * Gets this node's load of clients. | |||
* | * | |||
* @return float | * @return float | |||
*/ | */ | |||
public function getClientLoad() | public function getClientLoad() | |||
{ | { | |||
if ($this->getUsedSlotCount() + $this->getQueuedSlotCount() < 0) { | if ($this->getUsedSlotCount() + $this->getQueuedSlotCount() < 0) { | |||
return 0; | return 0; | |||
End of changes. 12 change blocks. | ||||
80 lines changed or deleted | 45 lines changed or added |