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);
}