public function chooseFileServer() { $available_servers = Abstract_Server::load_available_by_role_sorted_by_load_balancing(Server::SERVER_ROLE_FS); if (is_array($available_servers)) { $server = array_shift($available_servers); if (is_object($server)) { return $server; } } return false; }
public function getAvailableServers($type_ = NULL) { $prefs = Preferences::getInstance(); if (!$prefs) { die_error('get Preferences failed', __FILE__, __LINE__); } $default_settings = $prefs->get('general', 'session_settings_defaults'); $launch_without_apps = (int) $default_settings['launch_without_apps']; $user_profile_mode = $prefs->get('UserDB', 'enable'); $prefs_ad = $prefs->get('UserDB', 'activedirectory'); // get the list of server who the user can launch his applications $slave_server_settings = $prefs->get('general', 'slave_server_settings'); $default_settings = $prefs->get('general', 'session_settings_defaults'); $available_servers = Abstract_Server::load_available_by_role_sorted_by_load_balancing(Server::SERVER_ROLE_APS); $applications = $this->applications($type_, true); $servers_to_use = array(); foreach ($available_servers as $fqdn => $server) { if (!is_null($type_) && $server->getAttribute('type') != $type_) { continue; } if (count($applications) == 0) { break; } $applications_from_server = $server->getApplications(); foreach ($applications_from_server as $k => $an_server_application) { if (in_array($an_server_application, $applications)) { $servers_to_use[] = $server; unset($applications[array_search($an_server_application, $applications)]); } } } $servers_to_use = array_unique($servers_to_use); // TODO: bug if the user have static application if (count($applications) == 0) { return $servers_to_use; } else { if ($launch_without_apps == 1) { return $servers_to_use; } else { $application = array_pop($applications); Logger::error('main', "USER::getAvailableServers() no server found for user '" . $this->getAttribute('login') . "'. User's publication are not right, at least application named '" . $application->getAttribute('name') . "' does not have an available server"); return NULL; } } }