本文整理汇总了PHP中DBServer::LoadByID方法的典型用法代码示例。如果您正苦于以下问题:PHP DBServer::LoadByID方法的具体用法?PHP DBServer::LoadByID怎么用?PHP DBServer::LoadByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBServer
的用法示例。
在下文中一共展示了DBServer::LoadByID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "\n SELECT\n dt.id, dma.name AS application_name, servers.index AS server_index, farms.name AS farm_name, roles.name AS role_name,\n dt.status AS status, dt.dtadded AS dtadded\n FROM dm_deployment_tasks dt\n LEFT JOIN dm_applications dma ON dt.dm_application_id = dma.id\n LEFT JOIN servers ON servers.id = dt.server_id\n LEFT JOIN farms ON servers.farm_id = farms.id\n LEFT JOIN roles ON servers.farm_roleid = roles.id\n WHERE dt.`status` != ? AND dt.env_id = ?\n ";
$args = array(Scalr_Dm_DeploymentTask::STATUS_ARCHIVED, $this->getEnvironmentId());
list($sql, $args) = $this->request->prepareFarmSqlQuery($sql, $args, 'farms');
$response = $this->buildResponseFromSql2($sql, array('id', 'application_name', 'farm_name', 'role_name', 'server_index', 'status', 'dtadded', 'dtdeployed'), array(), $args);
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例2: getScriptingLogAction
public function getScriptingLogAction()
{
$this->request->restrictAccess(Acl::RESOURCE_LOGS_SCRIPTING_LOGS);
$this->request->defineParams(array('executionId' => array('type' => 'string')));
$info = $this->db->GetRow("SELECT * FROM scripting_log WHERE execution_id = ? LIMIT 1", array($this->getParam('executionId')));
if (!$info) {
throw new Exception('Script execution log not found');
}
try {
$dbServer = DBServer::LoadByID($info['server_id']);
if (!in_array($dbServer->status, array(SERVER_STATUS::INIT, SERVER_STATUS::RUNNING))) {
throw new Exception();
}
} catch (Exception $e) {
throw new Exception('Server was terminated and logs no longer available');
}
//Note! We should not check not-owned-farms permission here. It's approved by Igor.
if ($dbServer->envId != $this->environment->id) {
throw new \Scalr_Exception_InsufficientPermissions();
}
$client = Scalr_Net_Scalarizr_Client::getClient($dbServer, Scalr_Net_Scalarizr_Client::NAMESPACE_SYSTEM, $dbServer->getPort(DBServer::PORT_API));
$logs = $client->getScriptLogs($this->getParam('executionId'));
$msg = sprintf("STDERR: %s \n\n STDOUT: %s", base64_decode($logs->stderr), base64_decode($logs->stdout));
$msg = nl2br(htmlspecialchars($msg));
$this->response->data(array('message' => $msg));
}
示例3: run1
/**
* Performs upgrade literally for the stage ONE.
*
* Implementation of this method performs update steps needs to be taken
* to accomplish upgrade successfully.
*
* If there are any error during an execution of this scenario it must
* throw an exception.
*
* @param int $stage optional The stage number
* @throws \Exception
*/
protected function run1($stage)
{
if (!$this->hasTableColumn('servers', 'cloud_location')) {
$this->db->Execute("ALTER TABLE `servers`\n ADD `cloud_location` VARCHAR(255) NULL AFTER `index`,\n ADD `cloud_location_zone` VARCHAR(255) NULL AFTER `cloud_location`\n ");
} else {
if (!$this->hasTableColumnType('servers', 'cloud_location', 'varchar(255)')) {
$this->db->Execute("ALTER TABLE `servers`\n CHANGE `cloud_location` `cloud_location` VARCHAR(255) NULL,\n CHANGE `cloud_location_zone` `cloud_location_zone` VARCHAR(255) NULL\n ");
}
}
$servers = $this->db->Execute("SELECT server_id FROM servers");
while ($server = $servers->FetchRow()) {
try {
$dbServer = \DBServer::LoadByID($server['server_id']);
$dbServer->cloudLocation = $dbServer->GetCloudLocation();
if ($dbServer->platform == \SERVER_PLATFORMS::EC2) {
$dbServer->cloudLocationZone = $dbServer->GetProperty(\EC2_SERVER_PROPERTIES::AVAIL_ZONE);
}
if ($dbServer->platform == \SERVER_PLATFORMS::EUCALYPTUS) {
$dbServer->cloudLocationZone = $dbServer->GetProperty(\EUCA_SERVER_PROPERTIES::AVAIL_ZONE);
}
if ($dbServer->platform == \SERVER_PLATFORMS::GCE) {
$dbServer->cloudLocationZone = $dbServer->GetProperty(\GCE_SERVER_PROPERTIES::CLOUD_LOCATION);
}
$dbServer->Save();
} catch (\Exception $e) {
}
}
}
示例4: xGetDetailsAction
public function xGetDetailsAction()
{
$amazonEC2Client = Scalr_Service_Cloud_Aws::newEc2($this->getParam('cloudLocation'), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::PRIVATE_KEY), $this->getEnvironment()->getPlatformConfigValue(Modules_Platforms_Ec2::CERTIFICATE));
$rInstances = $amazonEC2Client->DescribeReservedInstances();
$rInstances = $rInstances->reservedInstancesSet->item;
if ($rInstances instanceof stdClass) {
$rInstances = array($rInstances);
}
$result = array();
foreach ($rInstances as $rInstance) {
if ($rInstance->state == 'active') {
$result[$rInstance->availabilityZone][$rInstance->instanceType]['rCount'] += $rInstance->instanceCount;
}
}
$servers = $this->db->Execute("SELECT servers.server_id FROM `servers` INNER JOIN server_properties ON server_properties.server_id = servers.server_id \r\n\t\t\tWHERE status=? AND name='ec2.region' AND env_id=? AND value=?", array(SERVER_STATUS::RUNNING, $this->getEnvironmentId(), $this->getParam('cloudLocation')));
while ($server = $servers->FetchRow()) {
$dbServer = DBServer::LoadByID($server['server_id']);
$result[$dbServer->GetProperty(EC2_SERVER_PROPERTIES::AVAIL_ZONE)][$dbServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_TYPE)]['iCount']++;
}
$retval = array();
foreach ($result as $availZone => $i) {
foreach ($i as $instanceType => $data) {
$retval[] = array('availZone' => $availZone, 'instanceType' => $instanceType, 'scalrInstances' => (int) $data['iCount'], 'reservedInstances' => (int) $data['rCount']);
}
}
$this->response->data(array('success' => true, 'data' => $retval));
}
示例5: run4
protected function run4()
{
$this->console->notice('Fill image_id in servers table');
// ec2
$this->db->Execute("\n UPDATE servers s JOIN server_properties sp ON s.server_id = sp.server_id\n SET s.image_id = sp.value\n WHERE sp.name = ? AND s.platform = ?\n ", [\EC2_SERVER_PROPERTIES::AMIID, \SERVER_PLATFORMS::EC2]);
// rackspace
$this->db->Execute("\n UPDATE servers s JOIN server_properties sp ON s.server_id = sp.server_id\n SET s.image_id = sp.value\n WHERE sp.name = ? AND s.platform = ?\n ", [\RACKSPACE_SERVER_PROPERTIES::IMAGE_ID, \SERVER_PLATFORMS::RACKSPACE]);
//cloudstack
foreach (PlatformFactory::getCloudstackBasedPlatforms() as $platform) {
foreach ($this->db->GetCol('SELECT server_id FROM servers WHERE platform = ?', [$platform]) as $serverId) {
try {
$dbServer = \DBServer::LoadByID($serverId);
$env = (new \Scalr_Environment())->loadById($dbServer->envId);
if ($dbServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID)) {
$lst = $env->cloudstack($platform)->instance->describe(['id' => $dbServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID)]);
if ($lst && $lst->count() == 1) {
$instance = $lst->offsetGet(0);
$dbServer->imageId = $instance->templateid;
$this->console->notice('Set imageId: %s for serverId: %s', $dbServer->imageId, $serverId);
$dbServer->save();
} else {
$this->console->warning('Instance not found: %s for serverId: %s', $dbServer->GetProperty(\CLOUDSTACK_SERVER_PROPERTIES::SERVER_ID), $serverId);
}
}
} catch (\Exception $e) {
$this->console->warning($e->getMessage());
}
}
}
// openstack
foreach (PlatformFactory::getOpenstackBasedPlatforms() as $platform) {
$this->db->Execute("\n UPDATE servers s LEFT JOIN server_properties sp ON s.server_id = sp.server_id\n SET s.image_id = sp.value\n WHERE sp.name = ? AND s.platform = ?\n ", [\OPENSTACK_SERVER_PROPERTIES::IMAGE_ID, $platform]);
}
}
示例6: doJob
public static function doJob($job)
{
$db = Core::GetDBInstance(null, true);
$messageSerializer = new Scalr_Messaging_XmlSerializer();
$message = $db->GetRow("SELECT server_id, message, id, handle_attempts FROM messages WHERE id=?", array($job->workload()));
try {
if ($message['handle_attempts'] >= 3) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
} else {
try {
$DBServer = DBServer::LoadByID($message['server_id']);
} catch (Exception $e) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
return;
}
if ($DBServer->status == SERVER_STATUS::RUNNING || $DBServer->status == SERVER_STATUS::INIT || $DBServer->status == SERVER_STATUS::IMPORTING || $DBServer->status == SERVER_STATUS::TEMPORARY || $DBServer->status == SERVER_STATUS::PENDING_TERMINATE) {
// Only 0.2-68 or greater version support this feature.
if ($DBServer->IsSupported("0.2-68")) {
$msg = $messageSerializer->unserialize($message['message']);
$DBServer->SendMessage($msg);
} else {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::UNSUPPORTED, $message['id']));
}
} elseif (in_array($DBServer->status, array(SERVER_STATUS::TERMINATED, SERVER_STATUS::PENDING_TERMINATE))) {
$db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
}
}
} catch (Exception $e) {
//var_dump($e->getMessage());
}
}
示例7: handleWork
function handleWork($msgId)
{
$message = $this->db->GetRow("SELECT server_id, message, id, handle_attempts FROM messages WHERE id=?", array($msgId));
try {
if ($message['handle_attempts'] >= 3) {
$this->db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
} else {
try {
$DBServer = DBServer::LoadByID($message['server_id']);
} catch (Exception $e) {
$this->db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
return;
}
if ($DBServer->status == SERVER_STATUS::RUNNING || $DBServer->status == SERVER_STATUS::INIT || $DBServer->status == SERVER_STATUS::IMPORTING || $DBServer->status == SERVER_STATUS::TEMPORARY || $DBServer->status == SERVER_STATUS::PENDING_TERMINATE) {
$msg = $this->messageSerializer->unserialize($message['message']);
$msg->dbMessageId = $message['id'];
$DBServer->SendMessage($msg);
} elseif (in_array($DBServer->status, array(SERVER_STATUS::TROUBLESHOOTING, SERVER_STATUS::TERMINATED, SERVER_STATUS::SUSPENDED))) {
$this->db->Execute("UPDATE messages SET status=? WHERE id=?", array(MESSAGE_STATUS::FAILED, $message['id']));
}
}
} catch (Exception $e) {
//var_dump($e->getMessage());
}
}
示例8: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json', 'default' => array('property' => 'dtadded', 'direction' => 'DESC'))));
$sql = "SELECT id FROM dm_deployment_tasks WHERE status !='" . Scalr_Dm_DeploymentTask::STATUS_ARCHIVED . "' AND env_id = '{$this->getEnvironmentId()}'";
$response = $this->buildResponseFromSql($sql, array("id"));
foreach ($response["data"] as $k => $row) {
$data = false;
try {
$deploymentTask = Scalr_Dm_DeploymentTask::init()->loadById($row['id']);
$application = $deploymentTask->getApplication();
try {
$dbServer = DBServer::LoadByID($deploymentTask->serverId);
$serverIndex = $dbServer->index;
} catch (Exception $e) {
}
$data = array('id' => $deploymentTask->id, 'application_name' => $application->name, 'application_id' => $deploymentTask->applicationId, 'server_id' => $deploymentTask->serverId, 'server_index' => $serverIndex, 'remote_path' => $deploymentTask->remotePath, 'status' => $deploymentTask->status, 'dtadded' => $deploymentTask->dtAdded ? Scalr_Util_DateTime::convertTz($deploymentTask->dtAdded) : "", 'dtdeployed' => $deploymentTask->dtDeployed ? Scalr_Util_DateTime::convertTz($deploymentTask->dtDeployed) : "Never");
try {
$dbFarmRole = DBFarmRole::LoadByID($deploymentTask->farmRoleId);
$data['farm_roleid'] = $dbFarmRole->ID;
$data['role_name'] = $dbFarmRole->GetRoleObject()->name;
$data['farm_id'] = $dbFarmRole->FarmID;
$data['farm_name'] = $dbFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
} catch (Exception $e) {
}
$response["data"][$k] = $data;
}
$this->response->data($response);
}
示例9: ServerGetExtendedInformation
public function ServerGetExtendedInformation($ServerID)
{
$DBServer = DBServer::LoadByID($ServerID);
if ($DBServer->envId != $this->Environment->id) {
throw new Exception(sprintf("Server ID #%s not found", $ServerID));
}
$response = $this->CreateInitialResponse();
$info = PlatformFactory::NewPlatform($DBServer->platform)->GetServerExtendedInformation($DBServer);
$response->ServerInfo = new stdClass();
$scalrProps = array('ServerID' => $DBServer->serverId, 'Platform' => $DBServer->platform, 'RemoteIP' => $DBServer->remoteIp ? $DBServer->remoteIp : '', 'LocalIP' => $DBServer->localIp ? $DBServer->localIp : '', 'Status' => $DBServer->status, 'Index' => $DBServer->index, 'AddedAt' => $DBServer->dateAdded);
foreach ($scalrProps as $k => $v) {
$response->ServerInfo->{$k} = $v;
}
$response->PlatformProperties = new stdClass();
if (is_array($info) && count($info)) {
foreach ($info as $name => $value) {
$name = str_replace(".", "_", $name);
$name = preg_replace("/[^A-Za-z0-9_-]+/", "", $name);
if ($name == 'MonitoringCloudWatch') {
continue;
}
$response->PlatformProperties->{$name} = $value;
}
}
$response->ScalrProperties = new stdClass();
if (count($DBServer->GetAllProperties())) {
$it = array();
foreach ($DBServer->GetAllProperties() as $name => $value) {
$name = preg_replace("/[^A-Za-z0-9-]+/", "", $name);
$response->ScalrProperties->{$name} = $value;
}
}
return $response;
}
示例10: xDisableAction
public function xDisableAction()
{
$dbServer = DBServer::LoadByID($this->getParam('serverId'));
$this->user->getPermissions()->validate($dbServer);
$aws = $this->getEnvironment()->aws($dbServer->GetCloudLocation());
$aws->ec2->instance->unmonitor($dbServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID));
$this->response->success("Cloudwatch monitoring successfully enabled for the instance");
}
示例11: getFarmRoleStaticIps
private function getFarmRoleStaticIps($cloudLocation, $farmRoleId)
{
$gceClient = $this->getGceClient($this->environment);
$projectId = $this->environment->getPlatformConfigValue(GoogleCEPlatformModule::PROJECT_ID);
$map = array();
if ($farmRoleId) {
$dbFarmRole = DBFarmRole::LoadByID($farmRoleId);
$this->user->getPermissions()->validate($dbFarmRole);
$maxInstances = $dbFarmRole->GetSetting(DBFarmRole::SETTING_SCALING_MAX_INSTANCES);
for ($i = 1; $i <= $maxInstances; $i++) {
$map[] = array('serverIndex' => $i);
}
$servers = $dbFarmRole->GetServersByFilter();
for ($i = 0; $i < count($servers); $i++) {
if ($servers[$i]->status != SERVER_STATUS::TERMINATED && $servers[$i]->status != SERVER_STATUS::TROUBLESHOOTING && $servers[$i]->index) {
$map[$servers[$i]->index - 1]['serverIndex'] = $servers[$i]->index;
$map[$servers[$i]->index - 1]['serverId'] = $servers[$i]->serverId;
$map[$servers[$i]->index - 1]['remoteIp'] = $servers[$i]->remoteIp;
$map[$servers[$i]->index - 1]['instanceId'] = $servers[$i]->GetProperty(GCE_SERVER_PROPERTIES::SERVER_NAME);
}
}
$ips = $this->db->GetAll('SELECT ipaddress, instance_index FROM elastic_ips WHERE farm_roleid = ?', array($dbFarmRole->ID));
for ($i = 0; $i < count($ips); $i++) {
$map[$ips[$i]['instance_index'] - 1]['elasticIp'] = $ips[$i]['ipaddress'];
}
}
$response = $gceClient->addresses->listAddresses($projectId, $cloudLocation);
$ips = array();
/* @var $ip \Google_Service_Compute_Address */
foreach ($response as $ip) {
var_dump($ip);
$itm = array('ipAddress' => $ip->address);
$info = $this->db->GetRow("\n SELECT * FROM elastic_ips WHERE ipaddress = ? LIMIT 1\n ", array($itm['ipAddress']));
if ($info) {
try {
if ($info['server_id'] && $itm['instanceId']) {
$dbServer = DBServer::LoadByID($info['server_id']);
if ($dbServer->GetProperty(EC2_SERVER_PROPERTIES::INSTANCE_ID) != $itm['instanceId']) {
for ($i = 0; $i < count($map); $i++) {
if ($map[$i]['elasticIp'] == $itm['ipAddress']) {
$map[$i]['warningInstanceIdDoesntMatch'] = true;
}
}
}
}
$farmRole = DBFarmRole::LoadByID($info['farm_roleid']);
$this->user->getPermissions()->validate($farmRole);
$itm['roleName'] = $farmRole->GetRoleObject()->name;
$itm['farmName'] = $farmRole->GetFarmObject()->Name;
$itm['serverIndex'] = $info['instance_index'];
} catch (Exception $e) {
}
}
//TODO: Mark Router EIP ad USED
$ips[] = $itm;
}
return array('map' => $map, 'ips' => $ips);
}
示例12: __construct
public function __construct(DBServer $DBServer)
{
parent::__construct();
$this->DBServer = $DBServer;
$r_server = Core::GetDBInstance()->GetRow("SELECT server_id FROM servers WHERE replace_server_id=?", array($DBServer->serverId));
if ($r_server) {
$this->replacementDBServer = DBServer::LoadByID($r_server['server_id']);
}
}
示例13: handle
function handle($queue, $payload)
{
$contentType = $_SERVER['CONTENT_TYPE'];
// Authenticate request
try {
$this->logger->info(sprintf("Validating server (server_id: %s)", $_SERVER["HTTP_X_SERVER_ID"]));
try {
$DBServer = DBServer::LoadByID($_SERVER["HTTP_X_SERVER_ID"]);
} catch (Exception $e) {
throw new Exception(sprintf(_("Server '%s' is not known by Scalr"), $_SERVER["HTTP_X_SERVER_ID"]));
}
$cryptoKey = $DBServer->GetKey(true);
$this->cryptoTool->setCryptoKey($cryptoKey);
// $isOneTimeKey = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_KEY_TYPE) == SZR_KEY_TYPE::ONE_TIME;
$isOneTimeKey = false;
$keyExpired = $DBServer->GetProperty(SERVER_PROPERTIES::SZR_ONETIME_KEY_EXPIRED);
if ($isOneTimeKey && $keyExpired) {
throw new Exception(_("One-time crypto key expired"));
}
$this->logger->info(sprintf(_("Validating signature '%s'"), $_SERVER["HTTP_X_SIGNATURE"]));
$this->validateSignature($payload, $_SERVER["HTTP_X_SIGNATURE"], $_SERVER["HTTP_DATE"]);
if ($isOneTimeKey) {
$DBServer->SetProperty(SERVER_PROPERTIES::SZR_ONETIME_KEY_EXPIRED, 1);
}
} catch (Exception $e) {
return array(401, $e->getMessage());
}
// Decrypt and decode message
try {
$this->logger->info(sprintf(_("Decrypting message '%s'"), $payload));
$string = $this->cryptoTool->decrypt($payload);
if ($contentType == 'application/json') {
$message = $this->jsonSerializer->unserialize($string);
$type = 'json';
} else {
$message = $this->serializer->unserialize($string);
$type = 'xml';
}
if ($isOneTimeKey && !$message instanceof Scalr_Messaging_Msg_HostInit) {
return array(401, _("One-time crypto key valid only for HostInit message"));
}
} catch (Exception $e) {
return array(400, $e->getMessage());
}
// Handle message
$accepted = false;
foreach ($this->handlers as $handler) {
if ($handler->accept($queue)) {
$this->logger->info("Notify handler " . get_class($handler));
$handler->handle($queue, $message, $string, $type);
$accepted = true;
}
}
return $accepted ? array(201, "Created") : array(400, sprintf("Unknown queue '%s'", $queue));
}
示例14: handle
function handle($queue, Scalr_Messaging_Msg $message, $rawMessage)
{
$dbserver = DBServer::LoadByID($message->getServerId());
if ($message instanceof Scalr_Messaging_Msg_ExecScriptResult) {
try {
$this->db->Execute("INSERT DELAYED INTO scripting_log SET \n\t\t\t\t\tfarmid = ?,\n\t\t\t\t\tserver_id = ?, \n\t\t\t\t\tevent = ?,\n\t\t\t\t\tmessage = ?, \n\t\t\t\t\tdtadded = NOW() \n\t\t\t\t", array($dbserver->farmId, $message->getServerId(), $message->eventName, sprintf("Script '%s' execution result (Time: %s s, Exit code: %s). %s %s", $message->scriptName, round($message->timeElapsed, 2), $message->returnCode, base64_decode($message->stderr), base64_decode($message->stdout))));
if ($message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]) {
DBServer::LoadByID($message->getServerId())->SetProperty(SERVER_PROPERTIES::SZR_VESION, $message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]);
}
} catch (Exception $e) {
$this->logger->warn($e->getMessage());
}
} elseif ($message instanceof Scalr_Messaging_Msg_Log) {
foreach ($message->entries as $entry) {
try {
$this->db->Execute("INSERT DELAYED INTO logentries SET \n\t\t\t\t\t\tserverid = ?, \n\t\t\t\t\t\tmessage = ?, \n\t\t\t\t\t\tseverity = ?, \n\t\t\t\t\t\ttime = ?, \n\t\t\t\t\t\tsource = ?, \n\t\t\t\t\t\tfarmid = ?\n\t\t\t\t\t", array($message->getServerId(), $entry->msg, self::$severityCodes[$entry->level], time(), $entry->name, $dbserver->farmId));
if ($message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]) {
DBServer::LoadByID($message->getServerId())->SetProperty(SERVER_PROPERTIES::SZR_VESION, $message->meta[Scalr_Messaging_MsgMeta::SZR_VERSION]);
}
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
}
} elseif ($message instanceof Scalr_Messaging_Msg_RebundleLog) {
try {
$this->db->Execute("INSERT INTO bundle_task_log SET \n\t\t\t\t\tbundle_task_id = ?,\n\t\t\t\t\tdtadded = NOW(),\n\t\t\t\t\tmessage = ?\n\t\t\t\t", array($message->bundleTaskId, $message->message));
} catch (Exception $e) {
$this->logger->error($e->getMessage());
}
} elseif ($message instanceof Scalr_Messaging_Msg_DeployLog) {
try {
$this->db->Execute("INSERT INTO dm_deployment_task_logs SET \n\t\t\t\t\t`dm_deployment_task_id` = ?,\n\t\t\t\t\t`dtadded` = NOW(),\n\t\t\t\t\t`message` = ?\n\t\t\t\t", array($message->deployTaskId, $message->message));
} catch (Exception $e) {
}
} elseif ($message instanceof Scalr_Messaging_Msg_OperationDefinition) {
try {
if ($message->name == 'Execute scripts') {
return;
}
$this->db->Execute("INSERT INTO server_operations SET \n\t\t\t\t\t`id` = ?,\n\t\t\t\t\t`server_id` = ?,\n\t\t\t\t\t`timestamp` = ?,\n\t\t\t\t\t`status`\t= ?,\n\t\t\t\t\t`name` = ?,\n\t\t\t\t\t`phases` = ?\n\t\t\t\t", array($message->id, $dbserver->serverId, time(), 'running', $message->name, json_encode($message->phases)));
} catch (Exception $e) {
}
} elseif ($message instanceof Scalr_Messaging_Msg_OperationProgress) {
try {
if ($message->warning) {
$msg = $message->warning->message;
$trace = $message->warning->trace;
$handler = $message->warning->handler;
}
$this->db->Execute("INSERT INTO server_operation_progress SET \n\t\t\t\t\t`operation_id` = ?,\n\t\t\t\t\t`timestamp` = ?,\n\t\t\t\t\t`phase` = ?,\n\t\t\t\t\t`step` = ?,\n\t\t\t\t\t`status` = ?,\n\t\t\t\t\t`message`= ?,\n\t\t\t\t\t`trace` = ?,\n\t\t\t\t\t`handler` = ?,\n\t\t\t\t\t`progress` = ?,\n\t\t\t\t\t`stepno` = ? \n\t\t\t\t\tON DUPLICATE KEY UPDATE status = ?, progress = ?, trace = ?, handler = ?, message = ?\n\t\t\t\t", array($message->id, $message->getTimestamp(), $message->phase, $message->step, $message->status, $msg, $trace, $handler, $message->progress, $message->stepno, $message->status, $message->progress, $trace, $handler, $msg));
} catch (Exception $e) {
}
}
}
示例15: startForking
/**
* {@inheritdoc}
* @see Scalr_System_Cronjob_MultiProcess_DefaultWorker::startForking()
*/
function startForking($workQueue)
{
// Reopen DB connection after daemonizing
$this->db = $this->getContainer()->adodb;
// Check that time has come to cleanup dead servers
$doCleanup = false;
sem_acquire($this->cleanupSem);
try {
if (time() - (int) $this->lastCleanup->get(0) >= $this->cleanupInterval) {
$doCleanup = true;
$this->lastCleanup->put(0, time());
}
} catch (Exception $e) {
sem_release($this->cleanupSem);
}
sem_release($this->cleanupSem);
if ($doCleanup) {
$this->logger->info("Cleanup dead servers");
try {
$importing_servers = $this->db->GetAll("\n SELECT server_id FROM servers\n WHERE status IN(?, ?)\n AND `dtadded` < NOW() - INTERVAL 1 DAY\n ", array(SERVER_STATUS::IMPORTING, SERVER_STATUS::TEMPORARY));
foreach ($importing_servers as $ts) {
$dbServer = DBServer::LoadByID($ts['server_id']);
if ($dbServer->status == SERVER_STATUS::TEMPORARY) {
try {
$dbServer->terminate(DBServer::TERMINATE_REASON_TEMPORARY_SERVER_ROLE_BUILDER);
} catch (Exception $e) {
}
} else {
if ($dbServer->status == SERVER_STATUS::IMPORTING) {
$dbServer->Remove();
}
}
}
$pending_launch_servers = $this->db->GetAll("SELECT server_id FROM servers WHERE status=?", array(SERVER_STATUS::PENDING_LAUNCH));
try {
foreach ($pending_launch_servers as $ts) {
$DBServer = DBServer::LoadByID($ts['server_id']);
if ($DBServer->status == SERVER_STATUS::PENDING_LAUNCH) {
$account = Scalr_Account::init()->loadById($DBServer->clientId);
if ($account->status == Scalr_Account::STATUS_ACTIVE) {
Scalr::LaunchServer(null, $DBServer);
}
}
}
} catch (Exception $e) {
Logger::getLogger(LOG_CATEGORY::FARM)->error(sprintf("Can't load server with ID #'%s'", $ts['server_id'], $e->getMessage()));
}
} catch (Exception $e) {
$this->logger->fatal("Poller::cleanup failed: {$e->getMessage()}");
}
}
}