Example #1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::GetServerRealStatus()
  */
 public function GetServerRealStatus(DBServer $DBServer)
 {
     $cloudLocation = $DBServer->cloudLocation;
     $environment = $DBServer->GetEnvironmentObject();
     $cacheKey = sprintf('%s:%s', $environment->id, $cloudLocation);
     $operationId = $DBServer->GetProperty(\GCE_SERVER_PROPERTIES::PROVISIONING_OP_ID);
     $iid = $DBServer->GetCloudServerID();
     if (!$iid) {
         $status = 'not-found';
     } elseif (!isset($this->instancesListCache[$cacheKey][$iid])) {
         $gce = $this->getClient($environment);
         $projectId = $DBServer->GetEnvironmentObject()->keychain(SERVER_PLATFORMS::GCE)->properties[Entity\CloudCredentialsProperty::GCE_PROJECT_ID];
         try {
             $result = $gce->instances->get($projectId, $cloudLocation, $DBServer->serverId);
             $status = $result->status;
         } catch (Exception $e) {
             if (stristr($e->getMessage(), "not found")) {
                 $status = 'not-found';
             } else {
                 throw $e;
             }
         }
         if ($status == 'not-found') {
             if ($operationId) {
                 try {
                     $info = $gce->zoneOperations->get($projectId, $cloudLocation, $operationId);
                     if ($info->status != 'DONE') {
                         $status = 'PROVISIONING';
                     }
                 } catch (Exception $e) {
                     \Scalr::getContainer()->logger("GCE")->info("GCE: operation was not found: {$operationId}, ServerID: {$DBServer->serverId}, ServerStatus: {$DBServer->status}");
                 }
             } else {
                 if ($DBServer->status == \SERVER_STATUS::PENDING) {
                     $status = 'PROVISIONING';
                 } else {
                     \Scalr::getContainer()->logger("GCE")->error("GCE: OPID: {$operationId}, ServerID: {$DBServer->serverId}, ServerStatus: {$DBServer->status}");
                 }
             }
         }
     } else {
         $status = $this->instancesListCache[$cacheKey][$iid]['status'];
     }
     return StatusAdapter::load($status);
 }
 /**
  * {@inheritdoc}
  * @see \Scalr\Modules\PlatformModuleInterface::GetServerRealStatus()
  */
 public function GetServerRealStatus(DBServer $DBServer)
 {
     $cloudLocation = $DBServer->GetProperty(\GCE_SERVER_PROPERTIES::CLOUD_LOCATION);
     $environment = $DBServer->GetEnvironmentObject();
     $operationId = $DBServer->GetProperty(\GCE_SERVER_PROPERTIES::PROVISIONING_OP_ID);
     $iid = $DBServer->serverId;
     if (!$iid) {
         $status = 'not-found';
     } elseif (!$this->instancesListCache[$environment->id][$cloudLocation][$iid]) {
         $gce = $this->getClient($environment);
         try {
             $result = $gce->instances->get($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PROJECT_ID), $cloudLocation, $DBServer->serverId);
             $status = $result->status;
         } catch (\Exception $e) {
             if (stristr($e->getMessage(), "not found")) {
                 $status = 'not-found';
             } else {
                 throw $e;
             }
         }
         if ($status == 'not-found') {
             if ($operationId) {
                 try {
                     $info = $gce->zoneOperations->get($DBServer->GetEnvironmentObject()->getPlatformConfigValue(self::PROJECT_ID), $cloudLocation, $operationId);
                     if ($info->status != 'DONE') {
                         $status = 'PROVISIONING';
                     }
                 } catch (Exception $e) {
                     \Logger::getLogger("GCE")->info("GCE: operation was not found: {$operationId}, ServerID: {$DBServer->serverId}, ServerStatus: {$DBServer->status}");
                 }
             } else {
                 if ($DBServer->status == \SERVER_STATUS::PENDING) {
                     $status = 'PROVISIONING';
                 } else {
                     \Logger::getLogger("GCE")->error("GCE: OPID: {$operationId}, ServerID: {$DBServer->serverId}, ServerStatus: {$DBServer->status}");
                 }
             }
         }
     } else {
         $status = $this->instancesListCache[$environment->id][$cloudLocation][$DBServer->serverId];
     }
     return StatusAdapter::load($status);
 }