Scalr\Model\Entity\Server::getTerminateReason PHP Méthode

getTerminateReason() public static méthode

Gets terminate reason
public static getTerminateReason ( integer $reasonId ) : string
$reasonId integer Reason id
Résultat string
    public static function getTerminateReason($reasonId)
    {
        $reasons = [1 => 'Shutting-down %s cluster.', 2 => 'Removing replica set from %s cluster.', 3 => 'Farm role does not exist.', 4 => 'Role removed from farm.', 5 => 'Server did not send %s event in %s seconds after launch.', 6 => 'Terminating temporary server.', 7 => 'Terminating role builder temporary server.', 8 => 'Scaling down.', 9 => 'Snapshot cancellation.', 10 => 'Manually terminated by %s.', 11 => 'Terminated through the Scalr API by %s.', 12 => 'Farm was in "%s" state. Server terminated when bundle task has been finished. Bundle task #%s.', 13 => 'Terminating server because the farm has been terminated.', 14 => 'Server replaced with new one after snapshotting.', 15 => 'Server launch was canceled', 16 => 'Server was terminated in cloud or from within an OS'];
        if ($reasonId && !isset($reasons[$reasonId])) {
            throw new InvalidArgumentException(sprintf('Terminate reason %d doesn\'t have message', $reasonId));
        }
        return $reasonId ? $reasons[$reasonId] : '';
    }

Usage Example

Exemple #1
0
 /**
  * Marks server as to be terminated.
  *
  * @param   int|array       $reason      The reason possibly with the format parameters.
  * @param   bool            $forcefully  optional Method: forcefully (true) | gracefully (false)
  * @param   User            $user        optional The user entity
  * @return  bool
  */
 public function terminate($reason, $forcefully = null, $user = null)
 {
     if (in_array($this->status, [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED])) {
         return false;
     }
     $forcefully = $forcefully === null ? true : (bool) $forcefully;
     $fnGetReason = function ($reasonId) {
         $args = func_get_args();
         $args[0] = Server::getTerminateReason($reasonId);
         return [call_user_func_array('sprintf', $args), $reasonId];
     };
     list($reason, $reasonId) = is_array($reason) ? call_user_func_array($fnGetReason, $reason) : $fnGetReason($reason);
     $properties = $this->properties;
     if ($user instanceof User) {
         $properties[self::TERMINATED_BY_ID] = $user->getId();
         $properties[self::TERMINATED_BY_EMAIL] = $user->getEmail();
     }
     $properties[self::REBOOTING] = 0;
     $properties->save();
     $this->update(['status' => Server::STATUS_PENDING_TERMINATE, 'shutdownScheduled' => new DateTime($forcefully ? 'now' : Scalr::config('scalr.system.server_terminate_timeout'))]);
     $this->getHistory()->markAsTerminated($reason, $reasonId);
     if (isset($this->farmId)) {
         $DBServer = $this->__getDBServer();
         Scalr::FireEvent($this->farmId, new BeforeHostTerminateEvent($DBServer, false));
         // If instance was terminated outside scalr, we need manually fire HostDown
         if ($reasonId == self::TERMINATE_REASON_CRASHED) {
             Scalr::FireEvent($this->farmId, new HostDownEvent($DBServer, false));
         }
     }
     return true;
 }