コード例 #1
0
ファイル: actions.php プロジェクト: skdong/nfs-ovd
                        popup_info(sprintf(_("Session '%s' successfully deleted"), $session->id));
                    }
                }
            }
            redirect('sessions.php');
        }
    }
}
if ($_REQUEST['name'] == 'Server') {
    if (!checkAuthorization('manageServers')) {
        redirect();
    }
    if ($_REQUEST['action'] == 'del') {
        if (isset($_REQUEST['checked_servers']) && is_array($_REQUEST['checked_servers'])) {
            foreach ($_REQUEST['checked_servers'] as $fqdn) {
                $sessions = Abstract_Session::getByServer($fqdn);
                if (count($sessions) > 0) {
                    popup_error(sprintf(_("Unable to delete the server '%s' because there are active sessions on it."), $fqdn));
                    continue;
                }
                $buf = Abstract_Server::load($fqdn);
                if (is_object($buf)) {
                    $buf->orderDeletion();
                    Abstract_Server::delete($buf->fqdn);
                    popup_info(sprintf(_("Server '%s' successfully deleted"), $buf->getAttribute('fqdn')));
                }
            }
            $buf = count(Abstract_Server::load_registered(false));
            if ($buf == 0) {
                redirect('servers.php');
            } else {
コード例 #2
0
     if ($session['status'] != $buf->servers[Server::SERVER_ROLE_APS][$session['server']]['status']) {
         $modified = true;
         $buf->setServerStatus($session['server'], $session['status']);
     }
     if ($session['status'] == Session::SESSION_STATUS_ACTIVE) {
         $modified = true;
         $buf->reportRunningApplicationsOnServer($ret['server'], $session['instances']);
     }
     if ($modified === true) {
         Abstract_Session::save($buf);
     }
     //update Session cache timestamp
 }
 // Check state of sessions not present in xml
 Logger::debug('main', "Checking session from " . $server->fqdn);
 $sessions = Abstract_Session::getByServer($server->id);
 foreach ($sessions as $session) {
     Logger::debug('main', "Inspecting session " . $session->id);
     if (!array_key_exists($server->id, $session->servers[Server::SERVER_ROLE_APS])) {
         Logger::debug('main', "Session " . $session->id . " on " . $server->fqdn . " is not an APS session");
         continue;
     }
     // Check if the session id unknown by the APS
     if (!in_array($session->id, $monitored_session)) {
         $serverStatus = $session->servers[Server::SERVER_ROLE_APS][$server->id]['status'];
         // If the monitoring is received during the APS session creation,
         // monitoring do not state about creating session and the session is destroy
         if (in_array($serverStatus, array(Session::SESSION_STATUS_CREATED, Session::SESSION_STATUS_READY))) {
             if (time() - $session->start_time > DEFAULT_UNUSED_SESSION_DURATION) {
                 Logger::info('main', "Session " . $session->id . " is expired");
                 $session->setServerStatus($server->id, Session::SESSION_STATUS_DESTROYED);
コード例 #3
0
ファイル: api.php プロジェクト: bloveing/openulteo
 public function sessions_list_by_server($server_, $offset_)
 {
     $this->check_authorized('viewStatus');
     $ret = array();
     $search_limit = $this->prefs->get('general', 'max_items_per_page');
     $sessions = Abstract_Session::getByServer($server_, $search_limit, $offset_);
     foreach ($sessions as $session) {
         $s = self::generate_session_array($session);
         $ret[$s['id']] = $s;
     }
     return $ret;
 }
コード例 #4
0
ファイル: Server.class.php プロジェクト: skdong/nfs-ovd
 public function setStatus($status_)
 {
     Logger::debug('main', 'Starting Server::setStatus for \'' . $this->fqdn . '\'');
     $ev = new ServerStatusChanged(array('fqdn' => $this->fqdn, 'status' => $status_ == 'ready' ? ServerStatusChanged::$ONLINE : ServerStatusChanged::$OFFLINE));
     switch ($status_) {
         case 'ready':
             $this->setAttribute('status', 'ready');
             if ($this->getAttribute('registered') && is_array($this->roles) && array_key_exists(Server::SERVER_ROLE_APS, $this->roles)) {
                 if (!$this->updateApplications()) {
                     Logger::critical('main', 'Server::setStatus(' . $status_ . ') - updateApplications failed, status switched to "broken"');
                     $this->setStatus(Server::SERVER_STATUS_BROKEN);
                     return false;
                 }
             }
             break;
     }
     switch ($status_) {
         case 'pending':
             Logger::warning('main', 'Status set to "pending" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'pending');
             break;
         case 'ready':
             Logger::info('main', 'Status set to "ready" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'ready');
             break;
         case 'down':
             Logger::warning('main', 'Status set to "down" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'down');
             break;
         case 'broken':
         default:
             Logger::error('main', 'Status set to "broken" for server \'' . $this->fqdn . '\'');
             $this->setAttribute('status', 'broken');
             break;
     }
     $ev->emit();
     Abstract_Server::save($this);
     switch ($this->getAttribute('status')) {
         case 'pending':
             break;
         case 'down':
             $sessions = Abstract_Session::getByServer($this->fqdn);
             foreach ($sessions as $session) {
                 Logger::warning('main', 'Server \'' . $this->fqdn . '\' status is now "down", killing Session \'' . $session->id . '\'');
                 $session->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_SERVER_DOWN);
                 Abstract_Session::delete($session->id);
             }
             break;
         case 'broken':
         default:
             $sessions = Abstract_Session::getByServer($this->fqdn);
             foreach ($sessions as $session) {
                 Logger::warning('main', 'Server \'' . $this->fqdn . '\' status is now "broken", killing Session \'' . $session->id . '\'');
                 $session->setStatus(Session::SESSION_STATUS_WAIT_DESTROY, Session::SESSION_END_STATUS_SERVER_BROKEN);
                 Abstract_Session::delete($session->id);
             }
             break;
     }
     return true;
 }
コード例 #5
0
function server_display_role_preparation_aps($server)
{
    $ret = array();
    $server_online = $server->isOnline();
    if ($server_online) {
        $buf = $server->updateApplications();
        if (!$buf) {
            popup_error(_('Cannot list available applications'));
        }
    }
    $applicationDB = ApplicationDB::getInstance();
    $applications_all = $applicationDB->getList(true);
    $applications = $server->getApplications();
    if (!is_array($applications)) {
        $applications = array();
    }
    usort($applications, 'application_cmp');
    $applications_available = array();
    $static_applications_available = array();
    if (!$server_online && count($applications) == 0) {
        $applications_all = array();
    }
    $servers_all = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    foreach ($servers_all as $k => $v) {
        if ($v->fqdn == $server->fqdn) {
            unset($servers_all[$k]);
        }
    }
    $servers_replication = Abstract_Server::load_by_status(Server::SERVER_STATUS_ONLINE);
    foreach ($servers_replication as $k => $v) {
        if ($v->fqdn == $server->fqdn) {
            unset($servers_replication[$k]);
        }
        if ($v->type != $server->getAttribute('type')) {
            unset($servers_replication[$k]);
        }
        if (!array_key_exists('aps', $v->roles) || $v->roles['aps'] !== true) {
            unset($servers_replication[$k]);
        }
        if ($server->hasAttribute('ulteo_system') == false || $server->getAttribute('ulteo_system') == 0) {
            unset($servers_replication[$k]);
        }
    }
    $sessions = array();
    $total = Abstract_Session::countByServer($_GET['fqdn']);
    if ($total > 0) {
        $has_sessions = true;
        $prefs = Preferences::getInstance();
        if (!$prefs) {
            die_error('get Preferences failed', __FILE__, __LINE__);
        }
        if ($total > $prefs->get('general', 'max_items_per_page')) {
            if (!isset($_GET['start']) || (!is_numeric($_GET['start']) || $_GET['start'] >= $total)) {
                $start = 0;
            } else {
                $start = $_GET['start'];
            }
            $pagechanger = get_pagechanger('servers.php?action=manage&fqdn=' . $_GET['fqdn'] . '&', $prefs->get('general', 'max_items_per_page'), $total);
            $sessions = Abstract_Session::getByServer($_GET['fqdn'], $prefs->get('general', 'max_items_per_page'), $start);
        } else {
            $sessions = Abstract_Session::getByServer($_GET['fqdn']);
        }
    } else {
        $has_sessions = false;
    }
    $external_name_checklist = array('localhost', '127.0.0.1');
    if (in_array($server->fqdn, $external_name_checklist) && in_array($server->getAttribute('external_name'), $external_name_checklist)) {
        popup_error(sprintf(_('Server "%s": redirection name may be invalid!'), $server->fqdn));
    }
    if ($server->getAttribute('external_name') == '') {
        popup_error(sprintf(_('Server "%s": redirection name cannot be empty!'), $server->fqdn));
    }
    if ($server_online) {
        //FIX ME ?
        $tm = new Tasks_Manager();
        $tm->load_from_server($server->fqdn);
        $tm->refresh_all();
        $apps_in_remove = array();
        $apps_in_install = array();
        $tasks = array();
        if ($server_online) {
            foreach ($tm->tasks as $task) {
                if (!$task->succeed()) {
                    $tasks[] = $task;
                }
            }
            foreach ($tasks as $task) {
                if (get_class($task) == 'Task_install') {
                    foreach ($task->applications as $app) {
                        if (!in_array($app, $apps_in_install)) {
                            $apps_in_install[] = $app;
                        }
                    }
                }
                if (get_class($task) == 'Task_remove') {
                    foreach ($task->applications as $app) {
                        if (!in_array($app, $apps_in_remove)) {
                            $apps_in_remove[] = $app;
                        }
                    }
                }
            }
            foreach ($applications_all as $app) {
                if (in_array($app, $applications)) {
                    continue;
                }
                if (in_array($app, $apps_in_install)) {
                    continue;
                }
                if ($app->getAttribute('type') != $server->getAttribute('type')) {
                    continue;
                }
                $applications_available[] = $app;
            }
        }
        $ret['tasks'] = $tasks;
        $ret['apps_in_install'] = $apps_in_install;
        $ret['apps_in_remove'] = $apps_in_remove;
    }
    $ret['can_do_action'] = isAuthorized('manageServers');
    $ret['web_port'] = $server->getAttribute('web_port');
    $ret['can_use_apt'] = isset($server->ulteo_system) && $server->ulteo_system == 1 ? true : false;
    $ret['server_online'] = $server_online;
    $ret['sessions'] = $sessions;
    $ret['has_sessions'] = $has_sessions;
    $ret['total_sessions'] = $total;
    if (isset($pagechanger)) {
        $ret['pagechanger'] = $pagechanger;
    }
    $ret['applications'] = $applications;
    $ret['applications_available'] = $applications_available;
    $ret['applications_all'] = $applications_all;
    $ret['servers_all'] = $servers_all;
    $ret['servers_replication'] = $servers_replication;
    return $ret;
}