本文整理汇总了PHP中Scalr_Util_DateTime::convertDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Scalr_Util_DateTime::convertDateTime方法的具体用法?PHP Scalr_Util_DateTime::convertDateTime怎么用?PHP Scalr_Util_DateTime::convertDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scalr_Util_DateTime
的用法示例。
在下文中一共展示了Scalr_Util_DateTime::convertDateTime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleWork
function handleWork($farmId)
{
try {
$dbFarm = DBFarm::LoadByID($farmId);
$governance = new Scalr_Governance($dbFarm->EnvID);
$settings = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE, 'notifications');
$curDate = new DateTime();
$td = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
if ($td > $curDate) {
// only inform user
$days = $td->diff($curDate)->days;
$notifications = json_decode($dbFarm->GetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND), true);
if (is_array($settings)) {
foreach ($settings as $n) {
if (!$notifications[$n['key']] && $n['period'] >= $days) {
$mailer = Scalr::getContainer()->mailer;
$tdHuman = Scalr_Util_DateTime::convertDateTime($td, $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE), 'M j, Y');
if ($n['to'] == 'owner') {
$user = new Scalr_Account_User();
$user->loadById($dbFarm->createdByUserId);
if (Scalr::config('scalr.auth_mode') == 'ldap') {
$email = $user->getSetting(Scalr_Account_User::SETTING_LDAP_EMAIL);
if (!$email) {
$email = $user->getEmail();
}
} else {
$email = $user->getEmail();
}
$mailer->addTo($email);
} else {
foreach (explode(',', $n['emails']) as $email) {
$mailer->addTo(trim($email));
}
}
$mailer->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/farm_lease_terminate.eml', array('{{terminate_date}}' => $tdHuman, '{{farm}}' => $dbFarm->Name, '{{envName}}' => $dbFarm->GetEnvironmentObject()->name, '{{envId}}' => $dbFarm->GetEnvironmentObject()->id));
$notifications[$n['key']] = 1;
$dbFarm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, json_encode($notifications));
$this->logger->info("Notification was sent by key: " . $n['key'] . " about farm: " . $dbFarm->Name . " by lease manager");
}
}
}
} else {
// terminate farm
$event = new FarmTerminatedEvent(0, 1, false, 1);
Scalr::FireEvent($farmId, $event);
$this->logger->info("Farm: " . $dbFarm->Name . " was terminated by lease manager");
}
} catch (Exception $e) {
var_dump($e->getMessage());
}
}
示例2: request
private function request($method, Object $params = null)
{
$requestObj = new stdClass();
$requestObj->id = microtime(true);
$requestObj->method = $method;
$requestObj->params = $params;
$jsonRequest = json_encode($requestObj);
$timestamp = date("D d M Y H:i:s T");
$dt = new DateTime($timestamp, new DateTimeZone("CDT"));
$timestamp = Scalr_Util_DateTime::convertDateTime($dt, new DateTimeZone("UTC"), new DateTimeZone("CDT"))->format("D d M Y H:i:s");
$timestamp .= " UTC";
$canonical_string = $jsonRequest . $timestamp;
$signature = base64_encode(hash_hmac('SHA1', $canonical_string, $this->dbServer->GetProperty(SERVER_PROPERTIES::SZR_KEY), 1));
$request = new HttpRequest("http://{$this->dbServer->remoteIp}:{$this->port}/", HTTP_METH_POST);
$request->setOptions(array('timeout' => 5, 'connecttimeout' => 5));
$request->setHeaders(array("Date" => $timestamp, "X-Signature" => $signature, "X-Server-Id" => $this->dbServer->serverId));
$request->setRawPostData($jsonRequest);
try {
// Send request
$request->send();
if ($request->getResponseCode() == 200) {
$response = $request->getResponseData();
$jResponse = @json_decode($response['body']);
if ($jResponse->error) {
throw new Exception("{$jResponse->error->message} ({$jResponse->error->code}): {$jResponse->error->data}");
}
return $jResponse;
} else {
throw new Exception(sprintf("Unable to perform request to update client: %s", $request->getResponseCode()));
}
} catch (HttpException $e) {
if (isset($e->innerException)) {
$msg = $e->innerException->getMessage();
} else {
$msg = $e->getMessage();
}
throw new Exception(sprintf("Unable to perform request to update client: %s", $msg));
}
}
示例3: xGetPlatformPricingHistoryAction
/**
* xGetPlatformPricingHistoryAction
*
* @param string $platform The cloud platform
* @param string $cloudLocation The cloud location
* @param string $url optional The cloud's endpoint url
*/
public function xGetPlatformPricingHistoryAction($platform, $cloudLocation, $url = '')
{
$result = [];
$types = [];
$history = $this->getContainer()->analytics->prices->getHistory($platform, $cloudLocation, $url, $this->user->getAccountId());
foreach ($history as $item) {
/* @var $item PriceHistoryEntity */
$dt = Scalr_Util_DateTime::convertDateTime($item->applied, null, 'Y-m-d');
$result[$dt] = $this->getPrice($item);
foreach ($result[$dt] as $v) {
$types[$v['type']] = ['type' => $v['type'], 'name' => $v['name']];
}
}
$this->response->data(['types' => array_values($types), 'history' => $result]);
}
示例4: extendedInfoAction
public function extendedInfoAction()
{
$this->request->restrictAccess(Acl::RESOURCE_FARMS);
if (!$this->getParam('farmId')) {
throw new Exception(_('Server not found'));
}
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
$tz = $dbFarm->GetSetting(DBFarm::SETTING_TIMEZONE);
$form = array(array('xtype' => 'fieldset', 'title' => 'General', 'labelWidth' => 220, 'items' => array(array('xtype' => 'displayfield', 'fieldLabel' => 'ID', 'value' => $dbFarm->ID), array('xtype' => 'displayfield', 'fieldLabel' => 'Name', 'value' => $dbFarm->Name), array('xtype' => 'displayfield', 'fieldLabel' => 'Hash', 'value' => $dbFarm->Hash), array('xtype' => 'displayfield', 'fieldLabel' => 'Timezone', 'value' => $tz ? $tz : date_default_timezone_get()))));
///Update settings
$scalarizrRepos = array_keys(Scalr::config('scalr.scalarizr_update.repos'));
$repo = $dbFarm->GetSetting(DBFarm::SETTING_SZR_UPD_REPOSITORY);
if (!$repo) {
$repo = Scalr::config('scalr.scalarizr_update.default_repo');
}
$schedule = $dbFarm->GetSetting(DBFarm::SETTING_SZR_UPD_SCHEDULE);
if (!$schedule) {
$schedule = "* * *";
}
$sChunks = explode(" ", $schedule);
$store = new stdClass();
$store->fields = array('name', 'description');
$store->proxy = 'object';
$itm = array('xtype' => 'fieldset', 'title' => 'Scalr agent update settings', 'labelWidth' => 220, 'items' => array(array('xtype' => 'combo', 'itemId' => 'repo', 'editable' => false, 'name' => 'szrRepository', 'fieldLabel' => 'Repository', 'queryMode' => 'local', 'store' => $store, 'value' => $repo, 'valueField' => 'name', 'displayField' => 'name'), array('xtype' => 'fieldcontainer', 'fieldLabel' => 'Schedule', 'layout' => 'hbox', 'items' => array(array('xtype' => 'textfield', 'hideLabel' => true, 'width' => 50, 'margin' => '0 3 0 0', 'value' => $sChunks[0], 'name' => 'hh'), array('xtype' => 'textfield', 'hideLabel' => true, 'value' => $sChunks[1], 'width' => 50, 'margin' => '0 3 0 0', 'name' => 'dd'), array('xtype' => 'textfield', 'hideLabel' => true, 'width' => 50, 'value' => $sChunks[2], 'name' => 'dw', 'margin' => '0 3 0 0'), array('xtype' => 'displayinfofield', 'info' => '
* * *<br>
─ ─ ─<br>
│ │ │<br>
│ │ │<br>
│ │ └───── day of week (0 - 6) (0 is Sunday)<br>
│ └─────── day of month (1 - 31)<br>
└───────── hour (0 - 23)<br>'))), array('xtype' => 'button', 'itemId' => 'updSettingsSave', 'text' => 'Save', 'flex' => 1)));
$form[] = $itm;
$b = $this->db->GetAll("SELECT DISTINCT(behavior) FROM farm_roles\n INNER JOIN role_behaviors ON role_behaviors.role_id = farm_roles.role_id WHERE farmid=?", array($this->getParam('farmId')));
$behaviors = array();
foreach ($b as $behavior) {
$behaviors[] = $behavior['behavior'];
}
//TODO get rid of code duplication here
$haveMysqlRole = in_array(ROLE_BEHAVIORS::MYSQL, $behaviors);
if (!$haveMysqlRole) {
$haveMysql2Role = in_array(ROLE_BEHAVIORS::MYSQL2, $behaviors);
}
if (!$haveMysql2Role && !$haveMysqlRole) {
$havePerconaRole = in_array(ROLE_BEHAVIORS::PERCONA, $behaviors);
}
$havePgRole = in_array(ROLE_BEHAVIORS::POSTGRESQL, $behaviors);
$haveRedisRole = in_array(ROLE_BEHAVIORS::REDIS, $behaviors);
$haveCFController = in_array(ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER, $behaviors);
$type = array();
if ($havePgRole) {
$type['postgresql'] = 'PostgreSQL';
}
if ($haveRedisRole) {
$type['redis'] = 'Redis';
}
if ($haveMysqlRole) {
$type['mysql'] = 'MySQL';
}
if ($haveMysql2Role) {
$type['mysql2'] = 'MySQL 5.5';
}
if ($havePerconaRole) {
$type['percona'] = 'Percona Server';
}
foreach ($type as $dbMsr => $name) {
$it = array(array('xtype' => 'displayfield', 'fieldCls' => 'x-form-field-info', 'anchor' => '100%', 'value' => 'Public - To connect to the service from the Internet<br / >Private - To connect to the service from another instance'), array('xtype' => 'displayfield', 'fieldLabel' => 'Writes endpoint (Public)', 'value' => "ext.master.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Reads endpoint (Public)', 'value' => "ext.slave.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Writes endpoint (Private)', 'value' => "int.master.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Reads endpoint (Private)', 'value' => "int.slave.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
$form[] = array('xtype' => 'fieldset', 'title' => "{$name} DNS endpoints", 'labelWidth' => 220, 'items' => $it);
}
if ($haveCFController) {
$it = array(array('xtype' => 'displayfield', 'fieldLabel' => 'VMC target endpoint', 'value' => "api.ext.cloudfoundry.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
$form[] = array('xtype' => 'fieldset', 'title' => "CloudFoundry connection information", 'labelWidth' => 220, 'items' => $it);
}
$governance = new Scalr_Governance($this->getEnvironmentId());
if ($governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE) && $dbFarm->GetSetting(DBFarm::SETTING_LEASE_STATUS) && $dbFarm->Status == FARM_STATUS::RUNNING) {
$terminateDate = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
$localeTerminateDate = Scalr_Util_DateTime::convertDateTime($terminateDate, $tz, 'M j, Y');
$config = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE, null);
$standardExtend = $config['leaseExtension'] == 'allow' && $terminateDate->diff(new DateTime())->days < $config['defaultLifePeriod'] && $dbFarm->GetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT) < $config['leaseExtensionStandardNumber'];
$standardExtendRemain = $config['leaseExtensionStandardNumber'] - $dbFarm->GetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT);
if ($config['leaseExtension'] == 'allow' && $terminateDate->diff(new DateTime())->days >= $config['defaultLifePeriod'] && $dbFarm->GetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT) < $config['leaseExtensionStandardNumber']) {
$standardExtendNextDate = new DateTime($dbFarm->GetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE));
$standardExtendNextDate->sub(new DateInterval('P' . intval($config['defaultLifePeriod']) . 'D'));
$standardExtendRemain .= ' (Next will be available on ' . Scalr_Util_DateTime::convertDateTime($standardExtendNextDate, $tz, 'M j, Y') . ')';
}
$nonStandardExtend = $config['leaseExtension'] == 'allow' && (bool) $config['leaseExtensionNonStandard'];
$lease = new FarmLease($dbFarm);
$last = $lease->getLastRequest();
$extendInProgress = NULL;
$extendLastError = NULL;
if ($last) {
if ($last['status'] == FarmLease::STATUS_PENDING) {
$standardExtend = false;
$nonStandardExtend = false;
$extendInProgress = 'Last request was sent at ' . Scalr_Util_DateTime::convertDateTime($last['request_time'], $tz, 'M j, Y');
if ($last['request_user_email']) {
$extendInProgress .= ' by ' . $last['request_user_email'];
}
} else {
if ($last['status'] == FarmLease::STATUS_DECLINE) {
//.........这里部分代码省略.........
示例5: xListAction
public function xListAction()
{
$sql = "SELECT `id`, `name`, `type`, `comments`, `target_id` as `targetId`, `target_server_index` as `targetServerIndex`, `target_type` as `targetType`, `start_time` as `startTime`,\n `last_start_time` as `lastStartTime`, `restart_every` as `restartEvery`, `config`, `status`, `timezone` FROM `scheduler` WHERE `env_id` = ? AND :FILTER:";
$response = $this->buildResponseFromSql2($sql, ['id', 'name', 'type', 'startTime', 'lastStartTime', 'timezone', 'status'], ['name'], [$this->getEnvironmentId()]);
foreach ($response['data'] as &$row) {
switch ($row['targetType']) {
case Scalr_SchedulerTask::TARGET_FARM:
try {
$DBFarm = DBFarm::LoadByID($row['targetId']);
$row['targetName'] = $DBFarm->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_ROLE:
try {
$DBFarmRole = DBFarmRole::LoadByID($row['targetId']);
$row['targetName'] = $DBFarmRole->GetRoleObject()->name;
$row['targetFarmId'] = $DBFarmRole->FarmID;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_INSTANCE:
try {
$DBServer = DBServer::LoadByFarmRoleIDAndIndex($row['targetId'], $row['targetServerIndex']);
$row['targetName'] = "({$DBServer->remoteIp})";
$DBFarmRole = $DBServer->GetFarmRoleObject();
$row['targetFarmId'] = $DBServer->farmId;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
$row['targetRoleId'] = $DBServer->farmRoleId;
$row['targetRoleName'] = $DBFarmRole->GetRoleObject()->name;
} catch (Exception $e) {
}
break;
default:
break;
}
//$row['type'] = Scalr_SchedulerTask::getTypeByName($row['type']);
$row['startTime'] = $row['startTime'] ? Scalr_Util_DateTime::convertDateTime($row['startTime'], $row['timezone']) : 'Now';
$row['lastStartTime'] = $row['lastStartTime'] ? Scalr_Util_DateTime::convertDateTime($row['lastStartTime'], $row['timezone']) : '';
$row['config'] = unserialize($row['config']);
$script = Script::findPk($row['config']['scriptId']);
if (!empty($script)) {
$row['config']['scriptName'] = $script->name;
}
}
$this->response->data($response);
}
示例6: xTransferAction
public function xTransferAction()
{
foreach ($this->db->GetAll('SELECT * FROM scheduler_tasks WHERE client_id = ?', array($this->user->getAccountId())) as $taskOld) {
$task = Scalr_SchedulerTask::init();
$task->name = $taskOld['task_name'];
$task->type = $taskOld['task_type'];
$task->targetId = $taskOld['target_id'];
$task->targetType = $taskOld['target_type'];
$task->timezone = $taskOld['timezone'];
$timezone = new DateTimeZone($taskOld['timezone']);
$startTm = new DateTime($taskOld['start_time_date']);
$endTm = new DateTime($taskOld['end_time_date']);
$lastStartTm = new DateTime($taskOld['last_start_time']);
// old time in timezone (from record) to server time (timezone leave for UI)
Scalr_Util_DateTime::convertDateTime($startTm, null, $timezone);
Scalr_Util_DateTime::convertDateTime($endTm, null, $timezone);
Scalr_Util_DateTime::convertDateTime($lastStartTm, null, $timezone);
$task->startTime = $startTm->format('Y-m-d H:i:s');
$task->endTime = $endTm->format('Y-m-d H:i:s');
$task->lastStartTime = $taskOld['last_start_time'] ? $lastStartTm->format('Y-m-d H:i:s') : NULL;
switch ($taskOld['target_type']) {
case SCRIPTING_TARGET::FARM:
try {
$DBFarm = DBFarm::LoadByID($taskOld['target_id']);
} catch (Exception $e) {
continue 2;
}
break;
case SCRIPTING_TARGET::ROLE:
try {
$DBFarmRole = DBFarmRole::LoadByID($taskOld['target_id']);
$a = $DBFarmRole->GetRoleObject()->name;
$a = $DBFarmRole->FarmID;
$a = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
continue 2;
}
break;
case SCRIPTING_TARGET::INSTANCE:
$serverArgs = explode(':', $taskOld['target_id']);
try {
$DBServer = DBServer::LoadByFarmRoleIDAndIndex($serverArgs[0], $serverArgs[1]);
$a = "({$DBServer->remoteIp})";
$DBFarmRole = $DBServer->GetFarmRoleObject();
$a = $DBServer->farmId;
$a = $DBFarmRole->GetFarmObject()->Name;
$a = $DBServer->farmRoleId;
$a = $DBFarmRole->GetRoleObject()->name;
} catch (Exception $e) {
continue 2;
}
break;
}
$config = unserialize($taskOld['task_config']);
$r = array();
switch ($task->type) {
case Scalr_SchedulerTask::SCRIPT_EXEC:
$r['scriptId'] = (string) $config['script_id'];
unset($config['script_id']);
$r['scriptIsSync'] = (string) $config['issync'];
unset($config['issync']);
$r['scriptTimeout'] = (string) $config['timeout'];
unset($config['timeout']);
$r['scriptVersion'] = (string) $config['revision'];
unset($config['revision']);
$r['scriptOptions'] = $config;
break;
case Scalr_SchedulerTask::LAUNCH_FARM:
break;
case Scalr_SchedulerTask::TERMINATE_FARM:
$r['deleteDNSZones'] = $config['deleteDNS'];
$r['deleteCloudObjects'] = $config['keep_elastic_ips'] == '1' || $config['keep_ebs'] == '1' ? NULL : '1';
break;
}
$task->config = $r;
$task->restartEvery = $taskOld['restart_every'];
$task->orderIndex = $taskOld['order_index'];
$task->status = $taskOld['status'];
$task->accountId = $taskOld['client_id'];
$task->envId = $taskOld['env_id'];
$task->save();
}
$this->db->Execute('DELETE FROM scheduler_tasks WHERE client_id = ?', array($this->user->getAccountId()));
$this->response->success('All tasks transfered successfully');
}
示例7: extendedInfoAction
public function extendedInfoAction()
{
if (!$this->getParam('farmId')) {
throw new Exception(_('Server not found'));
}
$dbFarm = DBFarm::LoadByID($this->getParam('farmId'));
$this->user->getPermissions()->validate($dbFarm);
$tz = $dbFarm->GetSetting(Entity\FarmSetting::TIMEZONE);
$form = array(array('xtype' => 'container', 'layout' => array('type' => 'hbox', 'align' => 'stretch'), 'cls' => 'x-fieldset-separator-bottom', 'items' => array(array('xtype' => 'fieldset', 'title' => 'General', 'flex' => 1, 'cls' => 'x-fieldset-separator-none', 'defaults' => array('labelWidth' => 130), 'items' => array(array('xtype' => 'displayfield', 'fieldLabel' => 'ID', 'value' => $dbFarm->ID), array('xtype' => 'displayfield', 'fieldLabel' => 'Name', 'value' => $dbFarm->Name), array('xtype' => 'displayfield', 'fieldLabel' => 'Hash', 'value' => $dbFarm->Hash), array('xtype' => 'displayfield', 'fieldLabel' => 'Timezone', 'value' => $tz ? $tz : date_default_timezone_get()))))));
$repo = $dbFarm->GetSetting(Entity\FarmSetting::SZR_UPD_REPOSITORY);
if (!$repo) {
$repo = Scalr::config('scalr.scalarizr_update.default_repo');
}
$schedule = $dbFarm->GetSetting(Entity\FarmSetting::SZR_UPD_SCHEDULE);
if (!$schedule) {
$schedule = "* * *";
}
$sChunks = explode(" ", $schedule);
$itm = array('xtype' => 'fieldset', 'title' => 'Scalr agent update settings', 'flex' => 1, 'cls' => 'x-fieldset-separator-left', 'defaults' => array('labelWidth' => 150), 'items' => array(array('xtype' => 'displayfield', 'fieldLabel' => 'Repository', 'value' => Scalr::isHostedScalr() ? Utils::getScalarizrUpdateRepoTitle($repo) : $repo), array('xtype' => 'fieldcontainer', 'fieldLabel' => 'Schedule (UTC time)', 'layout' => 'hbox', 'defaults' => array('margin' => '0 6 0 0'), 'items' => array(array('xtype' => 'textfield', 'hideLabel' => true, 'readOnly' => true, 'width' => 50, 'value' => $sChunks[0], 'name' => 'hh'), array('xtype' => 'textfield', 'hideLabel' => true, 'readOnly' => true, 'value' => $sChunks[1], 'width' => 50, 'name' => 'dd'), array('xtype' => 'textfield', 'hideLabel' => true, 'readOnly' => true, 'width' => 50, 'value' => $sChunks[2], 'name' => 'dw'), array('xtype' => 'displayinfofield', 'info' => '
* * *<br>
─ ─ ─<br>
│ │ │<br>
│ │ │<br>
│ │ └───── day of week (0 - 6) (0 is Sunday)<br>
│ └─────── day of month (1 - 31)<br>
└───────── hour (0 - 23)<br>')))));
$form[0]['items'][] = $itm;
$b = $this->db->GetAll("SELECT DISTINCT(behavior) FROM farm_roles\n INNER JOIN role_behaviors ON role_behaviors.role_id = farm_roles.role_id WHERE farmid=?", array($this->getParam('farmId')));
$behaviors = array();
foreach ($b as $behavior) {
$behaviors[] = $behavior['behavior'];
}
//TODO get rid of code duplication here
$haveMysqlRole = in_array(ROLE_BEHAVIORS::MYSQL, $behaviors);
if (!$haveMysqlRole) {
$haveMysql2Role = in_array(ROLE_BEHAVIORS::MYSQL2, $behaviors);
}
if (!$haveMysql2Role && !$haveMysqlRole) {
$havePerconaRole = in_array(ROLE_BEHAVIORS::PERCONA, $behaviors);
}
$havePgRole = in_array(ROLE_BEHAVIORS::POSTGRESQL, $behaviors);
$haveRedisRole = in_array(ROLE_BEHAVIORS::REDIS, $behaviors);
$haveCFController = in_array(ROLE_BEHAVIORS::CF_CLOUD_CONTROLLER, $behaviors);
$type = array();
if ($havePgRole) {
$type['postgresql'] = 'PostgreSQL';
}
if ($haveRedisRole) {
$type['redis'] = 'Redis';
}
if ($haveMysqlRole) {
$type['mysql'] = 'MySQL';
}
if ($haveMysql2Role) {
$type['mysql2'] = 'MySQL 5.5';
}
if ($havePerconaRole) {
$type['percona'] = 'Percona Server';
}
foreach ($type as $dbMsr => $name) {
$it = array(array('xtype' => 'displayfield', 'anchor' => '100%', 'cls' => 'x-form-field-info', 'value' => 'Public - To connect to the service from the Internet<br / >Private - To connect to the service from another instance'), array('xtype' => 'displayfield', 'fieldLabel' => 'Writes endpoint (Public)', 'value' => "ext.master.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Reads endpoint (Public)', 'value' => "ext.slave.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Writes endpoint (Private)', 'value' => "int.master.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')), array('xtype' => 'displayfield', 'fieldLabel' => 'Reads endpoint (Private)', 'value' => "int.slave.{$dbMsr}.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
$form[] = array('xtype' => 'fieldset', 'title' => "{$name} DNS endpoints", 'defaults' => array('labelWidth' => 220), 'items' => $it);
}
if ($haveCFController) {
$it = array(array('xtype' => 'displayfield', 'fieldLabel' => 'VMC target endpoint', 'value' => "api.ext.cloudfoundry.{$dbFarm->Hash}." . \Scalr::config('scalr.dns.static.domain_name')));
$form[] = array('xtype' => 'fieldset', 'title' => "CloudFoundry connection information", 'defaults' => array('labelWidth' => 220), 'items' => $it);
}
$governance = new Scalr_Governance($this->getEnvironmentId());
if ($governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE) && $dbFarm->GetSetting(Entity\FarmSetting::LEASE_STATUS) && $dbFarm->Status == FARM_STATUS::RUNNING) {
$terminateDate = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
$localeTerminateDate = Scalr_Util_DateTime::convertDateTime($terminateDate, $tz, 'M j, Y');
$config = $governance->getValue(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE, null);
$standardExtend = $config['leaseExtension'] == 'allow' && $terminateDate->diff(new DateTime())->days < $config['defaultLifePeriod'] && $dbFarm->GetSetting(Entity\FarmSetting::LEASE_EXTEND_CNT) < $config['leaseExtensionStandardNumber'];
$standardExtendRemain = $config['leaseExtensionStandardNumber'] - $dbFarm->GetSetting(Entity\FarmSetting::LEASE_EXTEND_CNT);
if ($config['leaseExtension'] == 'allow' && $terminateDate->diff(new DateTime())->days >= $config['defaultLifePeriod'] && $dbFarm->GetSetting(Entity\FarmSetting::LEASE_EXTEND_CNT) < $config['leaseExtensionStandardNumber']) {
$standardExtendNextDate = new DateTime($dbFarm->GetSetting(Entity\FarmSetting::LEASE_TERMINATE_DATE));
$standardExtendNextDate->sub(new DateInterval('P' . intval($config['defaultLifePeriod']) . 'D'));
$standardExtendRemain .= ' (Next will be available on ' . Scalr_Util_DateTime::convertDateTime($standardExtendNextDate, $tz, 'M j, Y') . ')';
}
$nonStandardExtend = $config['leaseExtension'] == 'allow' && (bool) $config['leaseExtensionNonStandard'];
$lease = new FarmLease($dbFarm);
$last = $lease->getLastRequest();
$extendInProgress = NULL;
$extendLastError = NULL;
if ($last) {
if ($last['status'] == FarmLease::STATUS_PENDING) {
$standardExtend = false;
$nonStandardExtend = false;
$extendInProgress = 'Last request was sent at ' . Scalr_Util_DateTime::convertDateTime($last['request_time'], $tz, 'M j, Y');
if ($last['request_user_email']) {
$extendInProgress .= ' by ' . $last['request_user_email'];
}
} else {
if ($last['status'] == FarmLease::STATUS_DECLINE) {
$extendLastError = sprintf('Last request was declined by reason "%s"', $last['answer_comment']);
}
}
}
$form[] = array('xtype' => 'fieldset', 'title' => "Lease information", 'defaults' => array('labelWidth' => 220), 'itemId' => 'lease', 'params' => array('farmLaunchPermission' => $this->request->hasPermissions($dbFarm->__getNewFarmObject(), Acl::PERM_FARMS_LAUNCH_TERMINATE), 'standardExtend' => $standardExtend, 'standardLifePeriod' => $config['defaultLifePeriod'], 'standardExtendRemain' => $standardExtendRemain, 'nonStandardExtend' => $nonStandardExtend, 'nonStandardExtendInProgress' => $extendInProgress, 'nonStandardExtendLastError' => $extendLastError, 'terminateDate' => $terminateDate->format('Y-m-d'), 'localeTerminateDate' => $localeTerminateDate));
}
//.........这里部分代码省略.........
示例8: xListAction
public function xListAction()
{
$data = $this->db->GetAll('SELECT id, name, type, comments, target_id as targetId, target_server_index as targetServerIndex, target_type as targetType, start_time as startTime,
end_time as endTime, last_start_time as lastStartTime, restart_every as restartEvery, config,
status, timezone FROM `scheduler` WHERE `env_id` = ?', [$this->getEnvironmentId()]);
foreach ($data as &$row) {
switch ($row['targetType']) {
case Scalr_SchedulerTask::TARGET_FARM:
try {
$DBFarm = DBFarm::LoadByID($row['targetId']);
$row['targetName'] = $DBFarm->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_ROLE:
try {
$DBFarmRole = DBFarmRole::LoadByID($row['targetId']);
$row['targetName'] = $DBFarmRole->GetRoleObject()->name;
$row['targetFarmId'] = $DBFarmRole->FarmID;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_INSTANCE:
try {
$DBServer = DBServer::LoadByFarmRoleIDAndIndex($row['targetId'], $row['targetServerIndex']);
$row['targetName'] = "({$DBServer->remoteIp})";
$DBFarmRole = $DBServer->GetFarmRoleObject();
$row['targetFarmId'] = $DBServer->farmId;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
$row['targetRoleId'] = $DBServer->farmRoleId;
$row['targetRoleName'] = $DBFarmRole->GetRoleObject()->name;
} catch (Exception $e) {
}
break;
default:
break;
}
//$row['type'] = Scalr_SchedulerTask::getTypeByName($row['type']);
$row['startTime'] = $row['startTime'] ? Scalr_Util_DateTime::convertDateTime($row['startTime'], $row['timezone']) : 'Now';
$row['endTime'] = $row['endTime'] ? Scalr_Util_DateTime::convertDateTime($row['endTime'], $row['timezone']) : 'Never';
$row['lastStartTime'] = $row['lastStartTime'] ? Scalr_Util_DateTime::convertDateTime($row['lastStartTime'], $row['timezone']) : '';
$row['config'] = unserialize($row['config']);
$script = Script::findPk($row['config']['scriptId']);
if ($script) {
$row['config']['scriptName'] = $script->name;
}
}
$this->response->data(['data' => $data]);
}
示例9: Run
function Run()
{
global $db;
$time = microtime(true);
$db->Execute("\r\n\t\t\t\tCREATE TABLE IF NOT EXISTS `scheduler` (\r\n\t\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t `name` varchar(255) DEFAULT NULL,\r\n\t\t\t\t `type` varchar(255) DEFAULT NULL,\r\n\t\t\t\t `target_id` varchar(255) DEFAULT NULL COMMENT 'id of farm, farm_role or farm_role:index from other tables',\r\n\t\t\t\t `target_type` varchar(255) DEFAULT NULL COMMENT 'farm, role or instance type',\r\n\t\t\t\t `start_time` datetime DEFAULT NULL COMMENT 'start task''s time',\r\n\t\t\t\t `end_time` datetime DEFAULT NULL COMMENT 'end task by this time',\r\n\t\t\t\t `last_start_time` datetime DEFAULT NULL COMMENT 'the last time task was started',\r\n\t\t\t\t `restart_every` int(11) DEFAULT '0' COMMENT 'restart task every N minutes',\r\n\t\t\t\t `config` text COMMENT 'arguments for action',\r\n\t\t\t\t `order_index` int(11) DEFAULT NULL COMMENT 'task order',\r\n\t\t\t\t `timezone` varchar(100) DEFAULT NULL,\r\n\t\t\t\t `status` varchar(11) DEFAULT NULL COMMENT 'active, suspended, finished',\r\n\t\t\t\t `account_id` int(11) DEFAULT NULL COMMENT 'Task belongs to selected account',\r\n\t\t\t\t `env_id` int(11) DEFAULT NULL,\r\n\t\t\t\t PRIMARY KEY (`id`),\r\n\t\t\t\t KEY `index` (`name`,`type`,`start_time`,`end_time`,`last_start_time`,`restart_every`,`order_index`,`status`,`account_id`,`env_id`)\r\n\t\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;\r\n\t\t\t");
$cnt = 0;
foreach ($db->GetAll('SELECT * FROM scheduler_tasks') as $taskOld) {
$task = Scalr_SchedulerTask::init();
$task->name = $taskOld['task_name'];
$task->type = $taskOld['task_type'];
$task->targetId = $taskOld['target_id'];
$task->targetType = $taskOld['target_type'];
$task->timezone = $taskOld['timezone'];
$timezone = new DateTimeZone($taskOld['timezone']);
$startTm = new DateTime($taskOld['start_time_date']);
$endTm = new DateTime($taskOld['end_time_date']);
$lastStartTm = new DateTime($taskOld['last_start_time']);
// old time in timezone (from record) to server time (timezone leave for UI)
Scalr_Util_DateTime::convertDateTime($startTm, null, $timezone);
Scalr_Util_DateTime::convertDateTime($endTm, null, $timezone);
Scalr_Util_DateTime::convertDateTime($lastStartTm, null, $timezone);
$task->startTime = $startTm->format('Y-m-d H:i:s');
$task->endTime = $endTm->format('Y-m-d H:i:s');
$task->lastStartTime = $taskOld['last_start_time'] ? $lastStartTm->format('Y-m-d H:i:s') : NULL;
switch ($taskOld['target_type']) {
case SCRIPTING_TARGET::FARM:
try {
$DBFarm = DBFarm::LoadByID($taskOld['target_id']);
} catch (Exception $e) {
continue 2;
}
break;
case SCRIPTING_TARGET::ROLE:
try {
$DBFarmRole = DBFarmRole::LoadByID($taskOld['target_id']);
$a = $DBFarmRole->GetRoleObject()->name;
$a = $DBFarmRole->FarmID;
$a = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
continue 2;
}
break;
case SCRIPTING_TARGET::INSTANCE:
$serverArgs = explode(':', $taskOld['target_id']);
try {
$DBServer = DBServer::LoadByFarmRoleIDAndIndex($serverArgs[0], $serverArgs[1]);
$a = "({$DBServer->remoteIp})";
$DBFarmRole = $DBServer->GetFarmRoleObject();
$a = $DBServer->farmId;
$a = $DBFarmRole->GetFarmObject()->Name;
$a = $DBServer->farmRoleId;
$a = $DBFarmRole->GetRoleObject()->name;
} catch (Exception $e) {
continue 2;
}
break;
}
$config = unserialize($taskOld['task_config']);
$r = array();
switch ($task->type) {
case Scalr_SchedulerTask::SCRIPT_EXEC:
$r['scriptId'] = (string) $config['script_id'];
unset($config['script_id']);
$r['scriptIsSync'] = (string) $config['issync'];
unset($config['issync']);
$r['scriptTimeout'] = (string) $config['timeout'];
unset($config['timeout']);
$r['scriptVersion'] = (string) $config['revision'];
unset($config['revision']);
$r['scriptOptions'] = $config;
break;
case Scalr_SchedulerTask::LAUNCH_FARM:
break;
case Scalr_SchedulerTask::TERMINATE_FARM:
$r['deleteDNSZones'] = $config['deleteDNS'];
$r['deleteCloudObjects'] = $config['keep_elastic_ips'] == '1' || $config['keep_ebs'] == '1' ? NULL : '1';
break;
}
$task->config = $r;
$task->restartEvery = $taskOld['restart_every'];
$task->orderIndex = $taskOld['order_index'];
$task->status = $taskOld['status'];
$task->accountId = $taskOld['client_id'];
$task->envId = $taskOld['env_id'];
$task->save();
}
print "Done.\n";
$t = round(microtime(true) - $time, 2);
print "Upgrade process took {$t} seconds\n\n\n";
}
示例10: xListTasksAction
public function xListTasksAction()
{
$this->request->defineParams(array('sort' => array('type' => 'json')));
$sql = 'SELECT id, name, type, comments, target_id as targetId, target_server_index as targetServerIndex, target_type as targetType, start_time as startTime,
end_time as endTime, last_start_time as lastStartTime, restart_every as restartEvery, config, order_index as orderIndex,
status, timezone FROM `scheduler` WHERE `env_id` = ? AND :FILTER:';
$response = $this->buildResponseFromSql2($sql, array('id', 'name', 'type', 'startTime', 'endTime', 'lastStartTime', 'timezone', 'orderIndex', 'status', 'timezone'), array('id', 'name'), array($this->getEnvironmentId()));
foreach ($response['data'] as &$row) {
switch ($row['targetType']) {
case Scalr_SchedulerTask::TARGET_FARM:
try {
$DBFarm = DBFarm::LoadByID($row['targetId']);
$row['targetName'] = $DBFarm->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_ROLE:
try {
$DBFarmRole = DBFarmRole::LoadByID($row['targetId']);
$row['targetName'] = $DBFarmRole->GetRoleObject()->name;
$row['targetFarmId'] = $DBFarmRole->FarmID;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
} catch (Exception $e) {
}
break;
case Scalr_SchedulerTask::TARGET_INSTANCE:
try {
$DBServer = DBServer::LoadByFarmRoleIDAndIndex($row['targetId'], $row['targetServerIndex']);
$row['targetName'] = "({$DBServer->remoteIp})";
$DBFarmRole = $DBServer->GetFarmRoleObject();
$row['targetFarmId'] = $DBServer->farmId;
$row['targetFarmName'] = $DBFarmRole->GetFarmObject()->Name;
$row['targetRoleId'] = $DBServer->farmRoleId;
$row['targetRoleName'] = $DBFarmRole->GetRoleObject()->name;
} catch (Exception $e) {
}
break;
default:
break;
}
$row['type'] = Scalr_SchedulerTask::getTypeByName($row['type']);
$row['startTime'] = $row['startTime'] ? Scalr_Util_DateTime::convertDateTime($row['startTime'], $row['timezone']) : 'Now';
$row['endTime'] = $row['endTime'] ? Scalr_Util_DateTime::convertDateTime($row['endTime'], $row['timezone']) : 'Never';
$row['lastStartTime'] = $row['lastStartTime'] ? Scalr_Util_DateTime::convertDateTime($row['lastStartTime'], $row['timezone']) : '';
$row['config'] = unserialize($row['config']);
$script = Script::findPk($row['config']['scriptId']);
if ($script) {
$row['config']['scriptName'] = $script->name;
}
}
$this->response->data($response);
}