Пример #1
0
 /**
  *
  * Kill all processes under current credentials
  *
  * @param Account $account
  * @throws Exception
  */
 public function killProcesses(Account $account)
 {
     $this->logDebug("Killing Redshift process for account {$account->getId()}", $account->getDebugData());
     $conn = $this->connect($account->getDatabase());
     // Kill processes
     $processes = $conn->fetchAll("\n   \t\t\tSELECT *\n   \t\t\tFROM stv_sessions\n   \t\t\tWHERE TRIM(user_name) = '{$account->getUser()}'\n   \t\t\t\tAND TRIM(db_name) = '{$account->getDatabase()}';\n   \t\t\t");
     if (count($processes)) {
         foreach ($processes as $process) {
             try {
                 $conn->exec("SELECT pg_terminate_backend({$process["process"]});");
             } catch (DBALException $e) {
                 // ignore this one, processes may be linked
             }
         }
     }
     $conn->close();
 }
Пример #2
0
 /**
  * @param Account $account
  */
 public function removeAccount(Account $account)
 {
     $servers = $this->getServersByHostname($account->getHostname());
     if (!$servers || !isset($servers[0]) || !$servers[0]) {
         return;
     }
     $server = $servers[0];
     if ($account->getGroupId()) {
         $accounts = $this->getAccountRepository()->findBy(array("hostname" => $account->getHostname(), "groupId" => $account->getGroupId(), "active" => true));
         $otherAccounts = array();
         foreach ($accounts as $item) {
             if ($item->getId() != $account->getId()) {
                 $otherAccounts[] = $item;
             }
         }
         if (!count($otherAccounts)) {
             $server->dropAccount($account);
         } else {
             try {
                 $server->killProcesses($account);
                 $server->revokePermission($account, $account->getDatabase());
             } catch (InvalidCredentialsException $e) {
                 // Skip this exception
             }
         }
     } else {
         $server->dropAccount($account);
     }
 }