本文整理汇总了Python中heron.statemgrs.src.python.log.Log类的典型用法代码示例。如果您正苦于以下问题:Python Log类的具体用法?Python Log怎么用?Python Log使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Log类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_pplan
def create_pplan(self, topologyName, pplan):
""" create physical plan """
if not pplan or not pplan.IsInitialized():
raise StateException("Physical Plan protobuf not init properly",
StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]
path = self.get_pplan_path(topologyName)
LOG.info("Adding topology: {0} to path: {1}".format(
topologyName, path))
pplanString = pplan.SerializeToString()
try:
self.client.create(path, value=pplanString, makepath=True)
return True
except NoNodeError:
raise StateException("NoNodeError while creating pplan",
StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
except NodeExistsError:
raise StateException("NodeExistsError while creating pplan",
StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
except ZookeeperError:
raise StateException("Zookeeper while creating pplan",
StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
except Exception:
# Just re raise the exception.
raise
示例2: get_all_zk_state_managers
def get_all_zk_state_managers(conf):
"""
Connects to all the zookeeper state_managers and returns
the connected state_managers instances.
"""
state_managers = []
state_locations = conf.get_state_locations_of_type("zookeeper")
for location in state_locations:
name = location['name']
hostport = location['hostport']
host = None
port = None
if ':' in hostport:
hostportlist = hostport.split(':')
if len(hostportlist) == 2:
host = hostportlist[0]
port = int(hostportlist[1])
if not host or not port:
raise Exception("Hostport for %s must be of the format 'host:port'." % (name))
tunnelhost = location['tunnelhost']
rootpath = location['rootpath']
LOG.info("Connecting to zk hostport: " + host + ":" + str(port) + " rootpath: " + rootpath)
state_manager = ZkStateManager(name, host, port, rootpath, tunnelhost)
try:
state_manager.start()
except Exception as e:
LOG.error("Exception while connecting to state_manager.")
traceback.print_exc()
state_managers.append(state_manager)
return state_managers
示例3: get_all_zk_state_managers
def get_all_zk_state_managers(conf):
"""
Creates all the zookeeper state_managers and returns
them in a list
"""
state_managers = []
state_locations = conf.get_state_locations_of_type("zookeeper")
for location in state_locations:
name = location['name']
hostport = location['hostport']
hostportlist = []
for hostportpair in hostport.split(','):
host = None
port = None
if ':' in hostport:
hostandport = hostportpair.split(':')
if len(hostandport) == 2:
host = hostandport[0]
port = int(hostandport[1])
if not host or not port:
raise Exception("Hostport for %s must be of the format 'host:port'." % (name))
hostportlist.append((host, port))
tunnelhost = location['tunnelhost']
rootpath = location['rootpath']
LOG.info("Connecting to zk hostports: " + str(hostportlist) + " rootpath: " + rootpath)
state_manager = ZkStateManager(name, hostportlist, rootpath, tunnelhost)
state_managers.append(state_manager)
return state_managers
示例4: _get_execution_state_with_watch
def _get_execution_state_with_watch(self, topologyName, callback, isWatching):
"""
Helper function to get execution state with
a callback. The future watch is placed
only if isWatching is True.
"""
path = self.get_execution_state_path(topologyName)
if isWatching:
LOG.info("Adding data watch for path: " + path)
# pylint: disable=unused-variable, unused-argument
@self.client.DataWatch(path)
def watch_execution_state(data, stats):
""" invoke callback to watch execute state """
if data:
executionState = ExecutionState()
executionState.ParseFromString(data)
callback(executionState)
else:
callback(None)
# Returning False will result in no future watches
# being triggered. If isWatching is True, then
# the future watches will be triggered.
return isWatching
示例5: create_execution_state
def create_execution_state(self, topologyName, executionState):
""" create execution state """
if not executionState or not executionState.IsInitialized():
raise StateException("Execution State protobuf not init properly",
StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]
path = self.get_execution_state_path(topologyName)
LOG.info("Adding topology: {0} to path: {1}".format(
topologyName, path))
executionStateString = executionState.SerializeToString()
try:
self.client.create(path, value=executionStateString, makepath=True)
return True
except NoNodeError:
raise StateException("NoNodeError while creating execution state",
StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
except NodeExistsError:
raise StateException("NodeExistsError while creating execution state",
StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
except ZookeeperError:
raise StateException("Zookeeper while creating execution state",
StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
except Exception:
# Just re raise the exception.
raise
示例6: _get_scheduler_location_with_watch
def _get_scheduler_location_with_watch(self, topologyName, callback, isWatching):
"""
Helper function to get scheduler location with
a callback. The future watch is placed
only if isWatching is True.
"""
path = self.get_scheduler_location_path(topologyName)
if isWatching:
LOG.info("Adding data watch for path: " + path)
# pylint: disable=unused-variable, unused-argument
@self.client.DataWatch(path)
def watch_scheduler_location(data, stats):
""" invoke callback to watch scheduler location """
if data:
scheduler_location = SchedulerLocation()
scheduler_location.ParseFromString(data)
callback(scheduler_location)
else:
callback(None)
# Returning False will result in no future watches
# being triggered. If isWatching is True, then
# the future watches will be triggered.
return isWatching
示例7: _get_topology_with_watch
def _get_topology_with_watch(self, topologyName, callback, isWatching):
"""
Helper function to get pplan with
a callback. The future watch is placed
only if isWatching is True.
"""
path = self.get_topology_path(topologyName)
if isWatching:
LOG.info("Adding data watch for path: " + path)
# pylint: disable=unused-variable, unused-argument
@self.client.DataWatch(path)
def watch_topology(data, stats):
""" watch topology """
if data:
topology = Topology()
topology.ParseFromString(data)
callback(topology)
else:
callback(None)
# Returning False will result in no future watches
# being triggered. If isWatching is True, then
# the future watches will be triggered.
return isWatching
示例8: create_topology
def create_topology(self, topologyName, topology):
""" crate topology """
if not topology or not topology.IsInitialized():
raise_(StateException("Topology protobuf not init properly",
StateException.EX_TYPE_PROTOBUF_ERROR), sys.exc_info()[2])
path = self.get_topology_path(topologyName)
LOG.info("Adding topology: {0} to path: {1}".format(
topologyName, path))
topologyString = topology.SerializeToString()
try:
self.client.create(path, value=topologyString, makepath=True)
return True
except NoNodeError:
raise_(StateException("NoNodeError while creating topology",
StateException.EX_TYPE_NO_NODE_ERROR), sys.exc_info()[2])
except NodeExistsError:
raise_(StateException("NodeExistsError while creating topology",
StateException.EX_TYPE_NODE_EXISTS_ERROR), sys.exc_info()[2])
except ZookeeperError:
raise_(StateException("Zookeeper while creating topology",
StateException.EX_TYPE_ZOOKEEPER_ERROR), sys.exc_info()[2])
except Exception:
# Just re raise the exception.
raise
示例9: get_all_state_managers
def get_all_state_managers(conf):
"""
@param conf - An instance of Config class
Reads the config for requested state managers.
Instantiates them, start and then return them.
"""
state_managers = []
try:
state_managers.extend(get_all_zk_state_managers(conf))
state_managers.extend(get_all_file_state_managers(conf))
return state_managers
except Exception as ex:
LOG.error("Exception while getting state_managers.")
raise ex
示例10: is_host_port_reachable
def is_host_port_reachable(self):
"""
Returns true if the host is reachable. In some cases, it may not be reachable a tunnel
must be used.
"""
for hostport in self.hostportlist:
try:
socket.create_connection(hostport, StateManager.TIMEOUT_SECONDS)
return True
except:
LOG.info("StateManager %s Unable to connect to host: %s port %i"
% (self.name, hostport[0], hostport[1]))
continue
return False
示例11: get_all_file_state_managers
def get_all_file_state_managers(conf):
"""
Returns all the file state_managers.
"""
state_managers = []
state_locations = conf.get_state_locations_of_type("file")
for location in state_locations:
name = location['name']
rootpath = os.path.expanduser(location['rootpath'])
LOG.info("Connecting to file state with rootpath: " + rootpath)
state_manager = FileStateManager(name, rootpath)
state_managers.append(state_manager)
return state_managers
示例12: _get_topologies_with_watch
def _get_topologies_with_watch(self, callback, isWatching):
"""
Helper function to get topologies with
a callback. The future watch is placed
only if isWatching is True.
"""
path = self.get_topologies_path()
if isWatching:
LOG.info("Adding children watch for path: " + path)
@self.client.ChildrenWatch(path)
def watch_topologies(topologies):
callback(topologies)
# Returning False will result in no future watches
# being triggered. If isWatching is True, then
# the future watches will be triggered.
return isWatching
示例13: delete_execution_state
def delete_execution_state(self, topologyName):
path = self.get_execution_state_path(topologyName)
LOG.info("Removing topology: {0} from path: {1}".format(
topologyName, path))
try:
self.client.delete(path)
return True
except NoNodeError as e:
raise StateException("NoNodeError while deleting execution state",
StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
except NotEmptyError as e:
raise StateException("NotEmptyError while deleting execution state",
StateException.EX_TYPE_NOT_EMPTY_ERROR), None, sys.exc_info()[2]
except ZookeeperError as e:
raise StateException("Zookeeper while deleting execution state",
StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
except Exception as e:
# Just re raise the exception.
raise
示例14: get_all_file_state_managers
def get_all_file_state_managers(conf):
"""
Returns all the file state_managers.
"""
state_managers = []
state_locations = conf.get_state_locations_of_type("file")
for location in state_locations:
name = location['name']
rootpath = os.path.expanduser(location['rootpath'])
LOG.info("Connecting to file state with rootpath: " + rootpath)
state_manager = FileStateManager(name, rootpath)
try:
state_manager.start()
except Exception as e:
LOG.error("Exception while connecting to state_manager.")
traceback.print_exc()
state_managers.append(state_manager)
return state_managers
示例15: delete_pplan
def delete_pplan(self, topologyName):
""" delete physical plan info """
path = self.get_pplan_path(topologyName)
LOG.info("Removing topology: {0} from path: {1}".format(
topologyName, path))
try:
self.client.delete(path)
return True
except NoNodeError:
raise StateException("NoNodeError while deleting pplan",
StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
except NotEmptyError:
raise StateException("NotEmptyError while deleting pplan",
StateException.EX_TYPE_NOT_EMPTY_ERROR), None, sys.exc_info()[2]
except ZookeeperError:
raise StateException("Zookeeper while deleting pplan",
StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
except Exception:
# Just re raise the exception.
raise