本文整理汇总了Python中google3.enterprise.legacy.util.E.getCrtHostName方法的典型用法代码示例。如果您正苦于以下问题:Python E.getCrtHostName方法的具体用法?Python E.getCrtHostName怎么用?Python E.getCrtHostName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类google3.enterprise.legacy.util.E
的用法示例。
在下文中一共展示了E.getCrtHostName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replicateConfig
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def replicateConfig(self, machines):
""" Replicates the config to a list of machines """
cmd = (". %s && cd %s/local/google3/enterprise/legacy/scripts && "
"./replicate_config.py %s %s" % (
self.getGlobalParam("ENTERPRISE_BASHRC"), self.entHome,
E.getCrtHostName(), self.globalParams.GetConfigFileName()))
return E.execute(machines, cmd, None, true)
示例2: SyncOpLogs
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def SyncOpLogs(all_machines, log_dir):
""" This will sync the AdminRunner.OPERATOR.* logs to all machines """
# We have to run this only on master
master = find_master.FindMaster(2100, all_machines)
# The name of this machine
crt_machine = E.getCrtHostName()
if len(master) == 1 and master[0] == crt_machine:
for machine in all_machines:
if machine != crt_machine:
src_dir = '%s/AdminRunner.OPERATOR.*' % (log_dir)
dest_dir = '%s:/%s' % (machine, log_dir)
logging.info('Collecting operator logs from %s into %s' % (
src_dir, dest_dir))
rsync_cmd = 'rsync --timeout=20 --size-only -vau ' \
' -e ssh %s %s/' % (src_dir, dest_dir)
# rsync the logs
lockfile = '%s/syncops_lock' % log_dir
lock = E.acquire_lock(lockfile, 1, breakLockAfterGracePeriod = 0)
if lock == None:
logging.info('Cannot grab the lock. Return!')
return
try:
(status, output) = liblog.DoCommand(rsync_cmd)
if status != 0:
logging.error('Failed to collect logs from %s: %s' % (
machine, output))
finally:
lock.close()
os.unlink(lockfile)
示例3: SyncOneboxLog
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def SyncOneboxLog(config):
"""Syncs Local Onebox log file with GFS Onebox Log file ONLY on clusters.
As of 4.6.4, this is called from scripts/periodic_script.py and from
onebox_handler.py, when the user does View Log AND the machine is a cluster.
"""
onebox_port = servertype.GetPortBase('oneboxenterprise')
onebox_node = config.SERVERS[onebox_port]
crt_machine = E.getCrtHostName()
ent_config_type = config.var('ENT_CONFIG_TYPE')
#If onebox server is not running no need to sync.
if ent_config_type != 'CLUSTER' or crt_machine != onebox_node[0]:
return
tmp_dir = config.var('TMPDIR')
gfs_cell = config.var('GFS_CELL')
local_log_name = os.path.join(tmp_dir, config.var('ENTERPRISE_ONEBOX_LOG'))
gfs_log_name = os.path.join(os.sep, 'gfs', gfs_cell,
config.var('ENTERPRISE_ONEBOX_LOG'))
equalize_command = 'equalize %s %s' % (local_log_name, gfs_log_name)
# fileutil equalize copies only the difference of the log files.
err, out = E.run_fileutil_command(config, equalize_command)
if not err:
return
# files didn't match in the begining, possibly a new log file would have
# created, copy the whole log file in such case.
copy_command = 'cp -f %s %s' % (local_log_name, gfs_log_name)
err, out = E.run_fileutil_command(config, copy_command)
if err:
logging.error('Error while syncing onebox logs.')
示例4: drain_urlmanagers
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def drain_urlmanagers(self):
"""
We need to do this before advancing the epoch -- we can do it
multiple times
"""
urlmanagers = self.cfg.globalParams.GetServerHostPorts("urlmanager")
num_shards = self.cfg.globalParams.GetNumShards('urlmanager')
epoch = self.cfg.getGlobalParam('RT_EPOCH')
for (host, port) in urlmanagers:
# We don't do it here directly because of the timeout
cmd = ". %s; cd %s/local/google3/enterprise/legacy/util && "\
"./port_talker.py %s %d 'd DumpingStatusTable' %d" % (
self.cfg.getGlobalParam('ENTERPRISE_BASHRC'),
self.cfg.entHome,
host, port, 300) # 5 min timeout
err = E.execute([E.getCrtHostName()], cmd, None, 0)
if E.ERR_OK != err:
logging.error("Error draining urlmanagers [%s]" % err)
return 1
# Make sure that the file is out
shard_num = servertype.GetPortShard(port)
file = "%surlmanager_out_table_%02d_of_%02d_epoch%010d" % (
self.cfg.getGlobalParam('NAMESPACE_PREFIX'),
shard_num, num_shards, epoch)
err, out = E.run_fileutil_command(self.cfg.globalParams, "ls %s" % file)
if E.ERR_OK != err:
logging.error("The status table file [%s] is not there" % file)
return 1
return 0
示例5: _RunServeCmd
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def _RunServeCmd(cfg, version, cmd, allnodes=0):
"""Run serve_service command.
cmd: 'stop', 'start', 'activate', 'deactivate'
allnodes: 1 to run command on all nodes
"""
serve_service_cmd = (
'/export/hda3/%s/local/google3/enterprise/legacy/scripts/'
'serve_service.py %s %s' % (version,
cfg.getGlobalParam('ENTERPRISE_HOME'),
cmd))
logging.info('Running: %s' % serve_service_cmd)
if allnodes:
machines = cfg.getGlobalParam(C.MACHINES)
else:
machines = [E.getCrtHostName()]
if E.execute(machines,
SECURE_WRAPPER_COMMAND % ( \
cfg.getGlobalParam('ENTERPRISE_HOME'),
'-p2',
serve_service_cmd),
None, 0) != E.ERR_OK:
logging.error('%s: failed' % serve_service_cmd)
return 1
logging.info('%s: completed' % serve_service_cmd)
return 0
示例6: CollectLogs
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def CollectLogs(all_machines, gws_log_dir, log_collect_dir):
# We only run this on oneway or master node of cluster.
master = find_master.FindMaster(2100, all_machines)
crt_machine = E.getCrtHostName()
if len(all_machines) != 1 and (len(master) != 1 or master[0] != crt_machine):
logging.info('Not a oneway or cluster master node. Return!')
return
lockfile = '%s/lock' % log_collect_dir
# waiting up to 5 minutes for the lock.
lock = E.acquire_lock(lockfile, 30, breakLockAfterGracePeriod = 0)
if lock == None:
logging.info('Cannot grab the lock. Return!')
return
try:
for machine in all_machines:
src_pattern = '%s/partnerlog.*' % gws_log_dir
dest_dir = '%s/%s' % (log_collect_dir, machine)
# If it's a oneway or master node, we make a symlink to gws_log_dir instead
# of rsync to log_collect directory
if machine == crt_machine:
# To make it backward compatible, we need to remove old dest_dir if it's
# already an existing directory from previous version because in previous
# versions we created a dir and rsynced files even on the master node and
# one-ways.
if os.path.exists(dest_dir) and not os.path.islink(dest_dir):
if not E.rm(master, '%s/*' % dest_dir) or not E.rmdir(master, dest_dir):
logging.error('Directory %s exists and cannot be cleaned.', dest_dir)
continue
logging.info('Cleaned existing directory %s.', dest_dir)
if E.ln(master, gws_log_dir, dest_dir):
logging.info('Symlink %s to directory %s:%s for logs' %
(dest_dir, machine, gws_log_dir))
else:
logging.error('Cannot make a symlink from %s to %s' %
(dest_dir, gws_log_dir))
continue
# For non-master nodes on cluster, we need to rsync those files to master node
logging.info('Collecting logs from %s:%s into %s' % (
machine, src_pattern, dest_dir))
# make log directories if needed
liblog.MakeDir(dest_dir)
# rsync all files from one remote machine in one command.
rsync_cmd = 'rsync --timeout=60 --size-only -vau ' \
' -e ssh %s:%s %s/' % (machine, src_pattern, dest_dir)
# rsync the logs
(status, output) = liblog.DoCommand(rsync_cmd)
if status != 0:
logging.error('Failed to collect logs from %s: %s' % (
machine, output))
finally:
lock.close()
os.unlink(lockfile)
示例7: browse
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def browse(self, clientName, virtualFile, fromLine, toLine,
grepString, fileArgs):
grepString = urllib.quote_plus(grepString.strip())
fromLine = string.atoi(fromLine)
toLine = string.atoi(toLine)
fileLocation = self.makePhysicalFile(virtualFile, clientName, grepString,
fileArgs)
if not fileLocation:
raise ar_exception.ARException((
ar_exception.LOADPARAMS, M.ERR_INVALIDFILESPECIFICATION))
# Get valid start line and end line
numLines = toLine - fromLine + 1;
if numLines < 0: numLines = 0
toLine = fromLine + numLines - 1
# Get the lines
result = []
parsedGrepString = commands.mkarg(grepString)
if ( E.ERR_OK != E.execute(
[E.getCrtHostName()], "head -n %s %s | tail -n %s | grep -i -F -- %s" %
(toLine, fileLocation, numLines, parsedGrepString), result, false) ):
return "0"
return "%s\n%s" % (len(result[0]), result[0])
示例8: isMaster
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def isMaster(config):
"""Return true if is running on master node."""
if len(config.var('MACHINES')) == 1:
return 1
(status, response) = port_talker.Talk(E.getCrtHostName(),
core_utils.GSA_MASTER_PORT,
'v is_master', 5)
return status and response[0] == '1'
示例9: PeriodicScript
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def PeriodicScript(config):
"""
If we have the FANCY_CLUSTER flag on we perform some master election
"""
global apacheRecheck
machines = config.MACHINES
# The two determinants : if we run sshd and the list of active AdminRunners
sshd_alive = sshd_alive_check(config)
tries = 6
sleep_time = 10
master = DetectMaster(machines, tries, sleep_time, config.var('VERSION'))
if master is None:
raise Error, 'Could not find master in %d tries.' % tries
logging.info('%s is the master' % master)
if not sshd_alive:
# No ssh running. I restart sshd
# sshd is not running!? ..too bad
logging.error("sshd is not running on this machine. "\
"restarting sshd.")
os.system("/etc/rc.d/init.d/sshd restart >&/dev/null </dev/null");
# The name of this machine
crt_machine = E.getCrtHostName()
if master == crt_machine: # I am the master
# make sure gfs master is not running on the same node on clusters
if len(machines) > 1:
AvoidGFSMasterOnNode(config, crt_machine)
if IsAdminRunnerAlive(6, 10): # max_tries, sleep_time
# Lincense stuff -- incrrease the serving time count
IncreaseMasterCounter()
# babysit loop_AdminRunner and loop_webserve_config
StartAdminLoop(config, op='babysit')
else: # I am the master but adminrunner does not seem to be running
logging.info('I (%s) am the master but adminrunner does not seem to be'
'running.' % crt_machine)
BecomeMaster(config)
else: # I am not the master
resync_with_master = 1
if core_utils.CanRunGSAMaster(crt_machine):
if IsAdminRunnerAlive(1, 0): # max_tries, sleep_time
# Kills adminrunner related processes, webconfig.py
# calls KillProcessIfNotMaster
MasterKillMyself(config)
resync_with_master = 0
else:
KillProcessIfNotMaster(config)
if resync_with_master:
ResyncWithMaster(config.GetConfigFileName(), config.ENTERPRISE_HOME,
config.ENTERPRISE_USER, master)
# check all services and kill services I am not supposed to run
KillRedundantServices(config)
示例10: remove
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def remove(self, machine):
""" This removes a machine from the configuration """
if machine not in self.cfg.getGlobalParam('MACHINES'):
logging.error("%s doesn't exist" % machine)
return 1
ver = self.cfg.getGlobalParam('VERSION')
home = self.cfg.getGlobalParam('ENTERPRISE_HOME')
testver = install_utilities.is_test(ver)
# if possible stop the core services, ignore return code
install_utilities.stop_core(ver, home, [machine])
if machine == E.getCrtHostName():
logging.error("Cannot remove self")
return 1
# Halt the machine if APC is used.
error = self.halt(machine)
self.cfg.globalParams.ReplaceVarInParam("SERVERS", None, machine)
self.cfg.globalParams.ReplaceVarInParam("MACHINES", None, machine)
ret = core_utils.AddDeadNode(ver, testver, machine)
# remove the chunkserver running on the node
gfs_utils.DeleteGFSChunkservers(ver, testver, [machine])
if ret:
logging.error('Cannot add dead node to the lockserver.')
# we ignore this error for now
# now we need to remove the data disks that were on this machine
data_disks = self.cfg.globalParams.var_copy('DATACHUNKDISKS')
if data_disks.has_key(machine):
del data_disks[machine]
if not self.cfg.setGlobalParam('DATACHUNKDISKS', data_disks):
return 1
# This also saves the config file
if not self.cfg.DoMachineAllocation():
return 1
# Now we need to restart babysitter because the old one
# is out of sync after this
serve_service_cmd = (". %s && "
"cd %s/local/google3/enterprise/legacy/scripts && "
"./serve_service.py %s" % (
self.cfg.getGlobalParam('ENTERPRISE_BASHRC'),
self.cfg.getGlobalParam('ENTERPRISE_HOME'),
self.cfg.getGlobalParam('ENTERPRISE_HOME')))
E.exe("%s %s" % (serve_service_cmd, "babysit"))
self.restart_crawl_processes(serve_service_cmd)
if not mail_already_sent(M.MSG_MACHINEREMOVED % machine):
SendMail.send(self.cfg, None, false,
M.MSG_MACHINEREMOVED % machine, "", true)
return error
示例11: export
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def export(self, clientName, virtualFile, convert,
fileArgs):
fileLocation = self.makePhysicalFile(virtualFile, clientName, "",
fileArgs)
if not fileLocation:
raise ar_exception.ARException((
ar_exception.LOADPARAMS, M.ERR_INVALIDFILESPECIFICATION))
return "%s %s" % (E.getCrtHostName(), fileLocation)
示例12: GetMachineParams
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def GetMachineParams(self, fact_name):
""" Get facts from the machine parameter cache
Arguments:
fact_name: 'memory-total'
Returns:
12430580
"""
return self.mach_param_cache.GetFact(fact_name, E.getCrtHostName())
示例13: haltcluster
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def haltcluster(self):
machines = self.cfg.getGlobalParam("MACHINES")
machines.remove(E.getCrtHostName())
msg = M.MSG_LOGSHUTDOWN
self.writeAdminRunnerOpMsg(msg)
if len(machines) > 0:
# Halt all other machines now
if rebooter.HaltMachines(self.cfg.globalParams.GetEntHome(),
machines):
# just send an email
if not mail_already_sent(M.MSG_MACHINENEEDSHALT % string.join(machines, " ")):
SendMail.send(self.cfg, None, false,
M.MSG_MACHINENEEDSHALT % string.join(machines, " "),
"", true)
# Halt this machine after a delay
time.sleep(120)
rebooter.HaltMachines(self.cfg.globalParams.GetEntHome(),
[E.getCrtHostName()])
return 0
示例14: send_urlscheduler_command
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def send_urlscheduler_command(self, command):
schedulers = self.cfg.globalParams.GetServerHostPorts("urlscheduler")
timeout = 60 # 1 minute is good enough
for (machine, port) in schedulers:
port_talker_cmd = ". %s; cd %s/local/google3/enterprise/legacy/util && "\
"./port_talker.py %s %d 'GET /run?Flags=%s\r\n\r\n' %d" % (
self.cfg.getGlobalParam('ENTERPRISE_BASHRC'),
self.cfg.entHome,
machine, port, command, timeout)
if E.ERR_OK != E.execute([E.getCrtHostName()], port_talker_cmd, None, 0):
logging.error("Error talking to urlscheduler %s:%d" % (machine, port))
return 1
return 0
示例15: send_cmd
# 需要导入模块: from google3.enterprise.legacy.util import E [as 别名]
# 或者: from google3.enterprise.legacy.util.E import getCrtHostName [as 别名]
def send_cmd(self, server_name, cmd):
srvrs = self.cfg.globalParams.GetServerManager().Set(server_name).Servers()
for srvr in srvrs:
actual_cmd = ". %s; cd %s/local/google3/enterprise/legacy/util && "\
"./port_talker.py %s %d '%s' %d" % (
self.cfg.getGlobalParam('ENTERPRISE_BASHRC'),
self.cfg.entHome,
srvr.host(), srvr.port(), cmd, 60) # 1 min timeout
err = E.execute([E.getCrtHostName()], actual_cmd, None, 0)
if E.ERR_OK != err:
logging.error("Error talking to server at %s:%d" % (srvr.host(),
srvr.port()))
return true