code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
'''Returns a tuple keys, values, count for kv_arg (which can be a dict or a
tuple containing keys, values and optinally count.'''
if isinstance(kv_arg, Mapping):
return six.iterkeys(kv_arg), six.itervalues(kv_arg), len(kv_arg)
assert 2 <= len(kv_arg) <= 3, \
'Argument must be a mappi... | def _get_kvc(kv_arg) | Returns a tuple keys, values, count for kv_arg (which can be a dict or a
tuple containing keys, values and optinally count. | 3.956728 | 2.402522 | 1.646906 |
'''Creates a database info with the given information for use with
:meth:`trace_sql_database_request`.
:param str name: The name (e.g., connection string) of the database.
:param str vendor: The type of the database (e.g., sqlite, PostgreSQL,
MySQL).
:param Channel c... | def create_database_info(
self,
name,
vendor,
channel) | Creates a database info with the given information for use with
:meth:`trace_sql_database_request`.
:param str name: The name (e.g., connection string) of the database.
:param str vendor: The type of the database (e.g., sqlite, PostgreSQL,
MySQL).
:param Channel channel: The... | 6.384422 | 2.183966 | 2.923315 |
'''Creates a web application info for use with
:meth:`trace_incoming_web_request`.
See
<https://www.dynatrace.com/support/help/server-side-services/introduction/how-does-dynatrace-detect-and-name-services/#web-request-services>
for more information about the meaning of the param... | def create_web_application_info(
self, virtual_host, application_id, context_root) | Creates a web application info for use with
:meth:`trace_incoming_web_request`.
See
<https://www.dynatrace.com/support/help/server-side-services/introduction/how-does-dynatrace-detect-and-name-services/#web-request-services>
for more information about the meaning of the parameters.
... | 5.401742 | 1.428613 | 3.781109 |
'''Create a tracer for the given database info and SQL statement.
:param DbInfoHandle database: Database information (see
:meth:`create_database_info`).
:param str sql: The SQL statement to trace.
:rtype: tracers.DatabaseRequestTracer
'''
assert isinstance(da... | def trace_sql_database_request(self, database, sql) | Create a tracer for the given database info and SQL statement.
:param DbInfoHandle database: Database information (see
:meth:`create_database_info`).
:param str sql: The SQL statement to trace.
:rtype: tracers.DatabaseRequestTracer | 5.793949 | 2.441959 | 2.372664 |
'''Create a tracer for an outgoing webrequest.
:param str url: The request URL (including scheme, hostname/port, path and query).
:param str method: The HTTP method of the request (e.g., GET or POST).
:param headers: The HTTP headers of the request. Can be either a
dictionar... | def trace_outgoing_web_request(self, url, method, headers=None) | Create a tracer for an outgoing webrequest.
:param str url: The request URL (including scheme, hostname/port, path and query).
:param str method: The HTTP method of the request (e.g., GET or POST).
:param headers: The HTTP headers of the request. Can be either a
dictionary mapping h... | 5.743077 | 1.522 | 3.773376 |
'''Creates a tracer for outgoing remote calls.
:param str method: The name of the service method/operation.
:param str service: The name of the service class/type.
:param str endpoint: A string identifying the "instance" of the the
service. See also `the general documentatio... | def trace_outgoing_remote_call(
self,
method,
service,
endpoint,
channel,
protocol_name=None) | Creates a tracer for outgoing remote calls.
:param str method: The name of the service method/operation.
:param str service: The name of the service class/type.
:param str endpoint: A string identifying the "instance" of the the
service. See also `the general documentation on servic... | 5.099754 | 1.493452 | 3.414742 |
'''Creates a tracer for incoming remote calls.
For the parameters, see :ref:`tagging` (:code:`str_tag` and
:code:`byte_tag`) and :meth:`trace_outgoing_remote_call` (all others).
:rtype: tracers.IncomingRemoteCallTracer
'''
result = tracers.IncomingRemoteCallTracer(
... | def trace_incoming_remote_call(
self,
method,
name,
endpoint,
protocol_name=None,
str_tag=None,
byte_tag=None) | Creates a tracer for incoming remote calls.
For the parameters, see :ref:`tagging` (:code:`str_tag` and
:code:`byte_tag`) and :meth:`trace_outgoing_remote_call` (all others).
:rtype: tracers.IncomingRemoteCallTracer | 3.956813 | 2.168844 | 1.824388 |
'''Creates a tracer for tracing asynchronous related processing in the same process.
For more information see :meth:`create_in_process_link`.
:param bytes link_bytes: An in-process link created using :meth:`create_in_process_link`.
:rtype: tracers.InProcessLinkTracer
.. versi... | def trace_in_process_link(self, link_bytes) | Creates a tracer for tracing asynchronous related processing in the same process.
For more information see :meth:`create_in_process_link`.
:param bytes link_bytes: An in-process link created using :meth:`create_in_process_link`.
:rtype: tracers.InProcessLinkTracer
.. versionadded:: 1... | 4.652267 | 1.850849 | 2.513585 |
'''Adds a custom request attribute to the current active tracer.
:param str key: The name of the custom request attribute, the name is mandatory and
may not be None.
:param value: The value of the custom request attribute. Currently supported types
are in... | def add_custom_request_attribute(self, key, value) | Adds a custom request attribute to the current active tracer.
:param str key: The name of the custom request attribute, the name is mandatory and
may not be None.
:param value: The value of the custom request attribute. Currently supported types
are integer, floa... | 3.418142 | 2.034614 | 1.679996 |
'''Closes the handle, if it is still open.
Usually, you should prefer using the handle as a context manager to
calling :meth:`close` manually.'''
if self.handle is not None:
self.close_handle(self.nsdk, self.handle)
self.handle = None | def close(self) | Closes the handle, if it is still open.
Usually, you should prefer using the handle as a context manager to
calling :meth:`close` manually. | 7.153658 | 2.885468 | 2.479202 |
'''Yields all (direct and indirect) children with LINK_CHILD.'''
return chain.from_iterable(
c.all_nodes_in_subtree()
for lnk, c in self.children
if lnk == self.LINK_CHILD) | def all_original_children(self) | Yields all (direct and indirect) children with LINK_CHILD. | 9.342512 | 5.195504 | 1.798192 |
'''Creates a SDK option list for use with the :code:`sdkopts` parameter of
:func:`.initialize` from a list :code:`argv` of command line parameters.
An element in :code:`argv` is treated as an SDK option if starts with
:code:`prefix`. The return value of this function will then contain the
remainder... | def sdkopts_from_commandline(argv=None, remove=False, prefix='--dt_') | Creates a SDK option list for use with the :code:`sdkopts` parameter of
:func:`.initialize` from a list :code:`argv` of command line parameters.
An element in :code:`argv` is treated as an SDK option if starts with
:code:`prefix`. The return value of this function will then contain the
remainder of tha... | 3.243554 | 1.239798 | 2.616196 |
'''Attempts to initialize the SDK with the specified options.
Even if initialization fails, a dummy SDK will be available so that SDK
functions can be called but will do nothing.
If you call this function multiple times, you must call :func:`shutdown`
just as many times. The options from all but t... | def initialize(sdkopts=(), sdklibname=None) | Attempts to initialize the SDK with the specified options.
Even if initialization fails, a dummy SDK will be available so that SDK
functions can be called but will do nothing.
If you call this function multiple times, you must call :func:`shutdown`
just as many times. The options from all but the firs... | 6.63466 | 1.719622 | 3.858208 |
'''Shut down the SDK.
:returns: An exception object if an error occurred, a falsy value otherwise.
:rtype: Exception
'''
global _sdk_ref_count #pylint:disable=global-statement
global _sdk_instance #pylint:disable=global-statement
global _should_shutdown #pylint:disable=global-statement
... | def shutdown() | Shut down the SDK.
:returns: An exception object if an error occurred, a falsy value otherwise.
:rtype: Exception | 3.579187 | 3.210112 | 1.114972 |
if not tracer_h:
return
if e_ty is None and e_val is None:
e_ty, e_val = sys.exc_info()[:2]
if e_ty is None and e_val is not None:
e_ty = type(e_val)
nsdk.tracer_error(tracer_h, getfullname(e_ty), str(e_val)) | def error_from_exc(nsdk, tracer_h, e_val=None, e_ty=None) | Attach appropriate error information to tracer_h.
If e_val and e_ty are None, the current exception is used. | 2.548128 | 2.610462 | 0.976122 |
initial = {}
if "request" in context:
initial.update({
"referrer": context["request"].META.get("HTTP_REFERER", ""),
"campaign": context["request"].GET.get("wlc", "")
})
return WaitingListEntryForm(initial=initial) | def waitinglist_entry_form(context) | Get a (new) form object to post a new comment.
Syntax::
{% waitinglist_entry_form as [varname] %} | 3.744678 | 4.860417 | 0.770444 |
host_and_port = request.urlparts[1]
try:
host, _ = host_and_port.split(':')
except ValueError:
# No port yet. Host defaults to '127.0.0.1' in bottle.request.
return DEFAULT_BIND
return host or DEFAULT_BIND | def _host() | Get the Host from the most recent HTTP request. | 6.470524 | 6.022722 | 1.074352 |
logger.debug("wait for {port_num}".format(**locals()))
t_start = time.time()
sleeps = 0.1
while time.time() - t_start < timeout:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((_host(), port_num))
return True... | def wait_for(port_num, timeout) | waits while process starts.
Args:
port_num - port number
timeout - specify how long, in seconds, a command can take before times out.
return True if process started, return False if not | 2.545629 | 2.57487 | 0.988643 |
log_file = os.path.join(dbpath, 'mongod.log')
cmd = [name, "--dbpath", dbpath, "--logpath", log_file, "--logappend",
"--repair"]
proc = subprocess.Popen(
cmd, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
timeout = 45
t_start = time.time()... | def repair_mongo(name, dbpath) | repair mongodb after usafe shutdown | 2.625686 | 2.586561 | 1.015126 |
logger.debug(
"mprocess(name={name!r}, config_path={config_path!r}, port={port!r}, "
"timeout={timeout!r})".format(**locals()))
if not (config_path and isinstance(config_path, str) and os.path.exists(config_path)):
raise OSError("can't find config file {config_path}".forma... | def mprocess(name, config_path, port=None, timeout=180, silence_stdout=True) | start 'name' process with params from config_path.
Args:
name - process name or path
config_path - path to file where should be stored configuration
port - process's port
timeout - specify how long, in seconds, a command can take before times out.
if timeout <=0 - d... | 3.442606 | 3.312762 | 1.039195 |
if PY3:
try:
return process.wait(timeout=timeout)
except subprocess.TimeoutExpired as exc:
raise TimeoutError(str(exc))
# On Python 2, simulate the timeout parameter and raise TimeoutError.
start = time.time()
while True:
exit_code = process.poll()
... | def wait_mprocess(process, timeout) | Compatibility function for waiting on a process with a timeout.
Raises TimeoutError when the timeout is reached. | 2.428396 | 2.513182 | 0.966263 |
if process and proc_alive(process):
process.terminate()
process.communicate()
return not proc_alive(process) | def kill_mprocess(process) | kill process
Args:
process - Popen object for process | 4.514599 | 6.036248 | 0.747915 |
for key in ('keyFile', 'logPath', 'dbpath'):
remove_path(cfg.get(key, None))
isinstance(config_path, str) and os.path.exists(config_path) and remove_path(config_path) | def cleanup_mprocess(config_path, cfg) | remove all process's stuff
Args:
config_path - process's options file
cfg - process's config | 5.008581 | 5.909231 | 0.847586 |
if path is None or not os.path.exists(path):
return
if platform.system() == 'Windows':
# Need to have write permission before deleting the file.
os.chmod(path, stat.S_IWRITE)
try:
if os.path.isdir(path):
shutil.rmtree(path)
elif os.path.isfile(path):
... | def remove_path(path) | remove path from file system
If path is None - do nothing | 2.462608 | 2.383775 | 1.03307 |
if config_path is None:
config_path = tempfile.mktemp(prefix="mongo-")
cfg = params.copy()
if 'setParameter' in cfg:
set_parameters = cfg.pop('setParameter')
try:
for key, value in set_parameters.items():
cfg['setParameter = ' + key] = value
... | def write_config(params, config_path=None) | write mongo*'s config file
Args:
params - options wich file contains
config_path - path to the config_file, will create if None
Return config_path
where config_path - path to mongo*'s options file | 3.629696 | 3.618781 | 1.003016 |
result = {}
with open(config_path, 'r') as fd:
for line in fd.readlines():
if '=' in line:
key, value = line.split('=', 1)
try:
result[key] = json.loads(value)
except ValueError:
result[key] = value.... | def read_config(config_path) | read config_path and return options as dictionary | 2.017526 | 1.93965 | 1.040149 |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.bind((_host(), port))
return True
except socket.error:
return False
finally:
s.close() | def __check_port(self, port) | check port status
return True if port is free, False else | 2.669137 | 2.624048 | 1.017183 |
if port in self.__closed:
self.__closed.remove(port)
self.__ports.add(port) | def release_port(self, port) | release port | 5.08552 | 4.91672 | 1.034332 |
if not self.__ports: # refresh ports if sequence is empty
self.refresh()
try:
port = self.__ports.pop()
if check:
while not self.__check_port(port):
self.release_port(port)
port = self.__ports.pop()
... | def port(self, check=False) | return next opened port
Args:
check - check is port realy free | 4.491643 | 4.337358 | 1.035571 |
if only_closed:
opened = filter(self.__check_port, self.__closed)
self.__closed = self.__closed.difference(opened)
self.__ports = self.__ports.union(opened)
else:
ports = self.__closed.union(self.__ports)
self.__ports = set(filter(self... | def refresh(self, only_closed=False) | refresh ports status
Args:
only_closed - check status only for closed ports | 3.000093 | 2.723241 | 1.101663 |
self.__init_range(min_port, max_port, port_sequence) | def change_range(self, min_port=1025, max_port=2000, port_sequence=None) | change Pool port range | 5.126773 | 4.748275 | 1.079713 |
prefix = '/' + version if version else ""
for r in routes:
path, method = r
route(prefix + path, method, routes[r]) | def setup_versioned_routes(routes, version=None) | Set up routes with a version prefix. | 6.117077 | 5.260535 | 1.162824 |
logger.info('daemonize_posix')
try:
pid = os.fork()
if pid > 0:
logger.debug('forked first child, pid = %d' % (pid,))
return pid
logger.debug('in child after first fork, pid = %d' % (pid, ))
except OSError as error:
... | def daemonize_posix(self) | do the UNIX double-fork magic, see Stevens' "Advanced
Programming in the UNIX Environment" for details (ISBN 0201563177)
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 | 1.579396 | 1.565337 | 1.008982 |
# Check for a pidfile to see if the daemon already runs
logger.info('Starting daemon')
try:
with open(self.pidfile, 'r') as fd:
pid = int(fd.read().strip())
except IOError:
pid = None
if pid:
message = "pidfile %s alre... | def start(self) | Start the daemon | 2.225248 | 2.108263 | 1.055489 |
# Get the pid from the pidfile
logger.debug("reading %s" % (self.pidfile,))
try:
with open(self.pidfile, 'r') as fd:
pid = int(fd.read().strip())
except IOError:
logger.exception("reading %s" % (self.pidfile, ))
pid = None
... | def stop(self) | Stop the daemon | 1.87355 | 1.806767 | 1.036962 |
for item in self.server_map:
self.member_del(item, reconfig=False)
self.server_map.clear() | def cleanup(self) | remove all members without reconfig | 9.852913 | 5.495946 | 1.79276 |
for key, value in self.server_map.items():
if value == hostname:
return key | def host2id(self, hostname) | return member id by hostname | 4.337164 | 3.605918 | 1.202791 |
self.server_map = dict([(member['_id'], member['host']) for member in config['members']]) | def update_server_map(self, config) | update server_map ({member_id:hostname}) | 7.722077 | 4.245595 | 1.818845 |
self.update_server_map(config)
# init_server - server which can init replica set
init_server = [member['host'] for member in config['members']
if not (member.get('arbiterOnly', False)
or member.get('priority', 1) == 0)][0]
s... | def repl_init(self, config) | create replica set by config
return True if replica set created successfuly, else False | 4.560389 | 4.26102 | 1.070258 |
# Need to use self.server_map, in case no Servers are left running.
for member_id in self.server_map:
host = self.member_id_to_host(member_id)
server_id = self._servers.host_to_server_id(host)
# Reset each member.
self._servers.command(server_id, ... | def reset(self) | Ensure all members are running and available. | 7.315045 | 6.417456 | 1.139867 |
cfg = config.copy()
cfg['version'] += 1
try:
result = self.run_command("replSetReconfig", cfg)
if int(result.get('ok', 0)) != 1:
return False
except pymongo.errors.AutoReconnect:
self.update_server_map(cfg) # use new server_ma... | def repl_update(self, config) | Reconfig Replicaset with new config | 5.926288 | 5.277911 | 1.122847 |
hosts = ','.join(x['host'] for x in self.members())
mongodb_uri = 'mongodb://' + hosts + '/?replicaSet=' + self.repl_id
result = {"id": self.repl_id,
"auth_key": self.auth_key,
"members": self.members(),
"mongodb_uri": mongodb_uri,
... | def info(self) | return information about replica set | 5.211688 | 4.623315 | 1.127262 |
repl_config = self.config
member_id = max([member['_id'] for member in repl_config['members']]) + 1
member_config = self.member_create(params, member_id)
repl_config['members'].append(member_config)
if not self.repl_update(repl_config):
self.member_del(member... | def repl_member_add(self, params) | create new mongod instances and add it to the replica set.
Args:
params - mongod params
return True if operation success otherwise False | 3.812676 | 3.813761 | 0.999716 |
logger.debug("run_command({command}, {arg}, {is_eval}, {member_id})".format(**locals()))
mode = is_eval and 'eval' or 'command'
hostname = None
if isinstance(member_id, int):
hostname = self.member_id_to_host(member_id)
result = getattr(self.connection(hostna... | def run_command(self, command, arg=None, is_eval=False, member_id=None) | run command on replica set
if member_id is specified command will be execute on this server
if member_id is not specified command will be execute on the primary
Args:
command - command string
arg - command argument
is_eval - if True execute command as eval
... | 3.209944 | 2.980452 | 1.076999 |
try:
admin = self.connection().admin
config = admin.command('replSetGetConfig')['config']
except pymongo.errors.OperationFailure:
# replSetGetConfig was introduced in 2.7.5.
config = self.connection().local.system.replset.find_one()
return... | def config(self) | return replica set config, use rs.conf() command | 4.127492 | 3.675673 | 1.122921 |
member_config = params.get('rsParams', {})
server_id = params.pop('server_id', None)
version = params.pop('version', self._version)
proc_params = {'replSet': self.repl_id}
proc_params.update(params.get('procParams', {}))
if self.enable_ipv6:
enable_ip... | def member_create(self, params, member_id) | start new mongod instances as part of replica set
Args:
params - member params
member_id - member index
return member config | 5.096691 | 4.522647 | 1.126927 |
server_id = self._servers.host_to_server_id(
self.member_id_to_host(member_id))
if reconfig and member_id in [member['_id'] for member in self.members()]:
config = self.config
config['members'].pop(member_id)
self.repl_update(config)
self.... | def member_del(self, member_id, reconfig=True) | remove member from replica set
Args:
member_id - member index
reconfig - is need reconfig replica
return True if operation success otherwise False | 4.409665 | 4.218329 | 1.045358 |
config = self.config
config['members'][member_id].update(params.get("rsParams", {}))
return self.repl_update(config) | def member_update(self, member_id, params) | update member's values with reconfig replica
Args:
member_id - member index
params - updates member params
return True if operation success otherwise False | 11.370342 | 8.78833 | 1.2938 |
server_id = self._servers.host_to_server_id(
self.member_id_to_host(member_id))
server_info = self._servers.info(server_id)
result = {'_id': member_id, 'server_id': server_id,
'mongodb_uri': server_info['mongodb_uri'],
'procInfo': server_i... | def member_info(self, member_id) | return information about member | 4.292181 | 4.271036 | 1.004951 |
server_id = self._servers.host_to_server_id(
self.member_id_to_host(member_id))
return self._servers.command(server_id, command) | def member_command(self, member_id, command) | apply command (start/stop/restart) to member instance of replica set
Args:
member_id - member index
command - string command (start/stop/restart)
return True if operation success otherwise False | 4.828486 | 5.275161 | 0.915325 |
result = list()
for member in self.run_command(command="replSetGetStatus", is_eval=False)['members']:
result.append({
"_id": member['_id'],
"host": member["name"],
"server_id": self._servers.host_to_server_id(member["name"]),
... | def members(self) | return list of members information | 5.035237 | 4.807412 | 1.04739 |
members = self.run_command(command='replSetGetStatus', is_eval=False)['members']
return [member['name'] for member in members if member['state'] == state] | def get_members_in_state(self, state) | return all members of replica set in specific state | 6.36074 | 4.068819 | 1.563289 |
if self.login and not self.restart_required:
try:
db = client[self.auth_source]
if self.x509_extra_user:
db.authenticate(
DEFAULT_SUBJECT,
mechanism='MONGODB-X509'
)
... | def _authenticate_client(self, client) | Authenticate the client if necessary. | 5.313257 | 5.114601 | 1.038841 |
logger.debug("connection({hostname}, {read_preference}, {timeout})".format(**locals()))
t_start = time.time()
servers = hostname or ",".join(self.server_map.values())
while True:
try:
if hostname is None:
c = pymongo.MongoReplicaSe... | def connection(self, hostname=None, read_preference=pymongo.ReadPreference.PRIMARY, timeout=300) | return MongoReplicaSetClient object if hostname specified
return MongoClient object if hostname doesn't specified
Args:
hostname - connection uri
read_preference - default PRIMARY
timeout - specify how long, in seconds, a command can take before server times out. | 2.685024 | 2.672918 | 1.004529 |
return [
{
"_id": self.host2id(member),
"host": member,
"server_id": self._servers.host_to_server_id(member)
}
for member in self.get_members_in_state(2)
] | def secondaries(self) | return list of secondaries members | 6.187929 | 4.94754 | 1.250708 |
return [
{
"_id": self.host2id(member),
"host": member,
"server_id": self._servers.host_to_server_id(member)
}
for member in self.get_members_in_state(7)
] | def arbiters(self) | return list of arbiters | 5.97486 | 5.513206 | 1.083736 |
members = [self.member_info(item["_id"]) for item in self.members()]
result = []
for member in members:
if member['rsInfo'].get('hidden'):
server_id = member['server_id']
result.append({
'_id': member['_id'],
... | def hidden(self) | return list of hidden members | 5.400218 | 4.725083 | 1.142883 |
servers = self.run_command('ismaster').get('passives', [])
return [member for member in self.members() if member['host'] in servers] | def passives(self) | return list of passive servers | 10.640398 | 8.314163 | 1.279792 |
t_start = time.time()
while True:
try:
for server in servers:
# TODO: use state code to check if server is reachable
server_info = self.connection(
hostname=server, timeout=5).admin.command('ismaster')
... | def wait_while_reachable(self, servers, timeout=60) | wait while all servers be reachable
Args:
servers - list of servers | 3.085078 | 3.072927 | 1.003954 |
t_start = time.time()
while not self.check_member_state():
if time.time() - t_start > timeout:
return False
time.sleep(0.1)
return True | def waiting_member_state(self, timeout=300) | Wait for all RS members to be in an acceptable state. | 2.51876 | 2.502418 | 1.006531 |
t_start = time.time()
while not self.check_config_state():
if time.time() - t_start > timeout:
return False
time.sleep(0.1)
return True | def waiting_config_state(self, timeout=300) | waiting while real state equal config state
Args:
timeout - specify how long, in seconds, a command can take before server times out.
return True if operation success otherwise False | 2.49663 | 2.352852 | 1.061108 |
bad_states = (0, 3, 4, 5, 6, 9)
try:
rs_status = self.run_command('replSetGetStatus')
bad_members = [member for member in rs_status['members']
if member['state'] in bad_states]
if bad_members:
return False
ex... | def check_member_state(self) | Verify that all RS members have an acceptable state. | 4.544603 | 3.946075 | 1.151677 |
config = self.config
self.update_server_map(config)
for member in config['members']:
cfg_member_info = self.default_params.copy()
cfg_member_info.update(member)
# Remove attributes we can't check.
for attr in ('priority', 'votes', 'tags', ... | def check_config_state(self) | Return True if real state equal config state otherwise False. | 3.316527 | 3.167645 | 1.047001 |
for member_id in self.server_map:
host = self.server_map[member_id]
server_id = self._servers.host_to_server_id(host)
server = self._servers._storage[server_id]
server.restart(timeout, config_callback)
self.waiting_member_state() | def restart(self, timeout=300, config_callback=None) | Restart each member of the replica set. | 5.318552 | 4.492019 | 1.184 |
super(ReplicaSets, self).set_settings(releases, default_release)
Servers().set_settings(releases, default_release) | def set_settings(self, releases=None, default_release=None) | set path to storage | 6.188276 | 6.278191 | 0.985678 |
repl_id = rs_params.get('id', None)
if repl_id is not None and repl_id in self:
raise ReplicaSetError(
"replica set with id={id} already exists".format(id=repl_id))
repl = ReplicaSet(rs_params)
self[repl.repl_id] = repl
return repl.repl_id | def create(self, rs_params) | create new replica set
Args:
rs_params - replica set configuration
Return repl_id which can use to take the replica set | 3.198953 | 2.79117 | 1.146097 |
repl = self[repl_id]
primary = repl.primary()
return repl.member_info(repl.host2id(primary)) | def primary(self, repl_id) | find and return primary hostname
Args:
repl_id - replica set identity | 10.573673 | 11.384813 | 0.928752 |
repl = self._storage.pop(repl_id)
repl.cleanup()
del(repl) | def remove(self, repl_id) | remove replica set with kill members
Args:
repl_id - replica set identity
return True if operation success otherwise False | 8.206385 | 12.041945 | 0.681483 |
rs = self._storage[rs_id]
try:
return getattr(rs, command)(*args)
except AttributeError:
raise ValueError("Cannot issue the command %r to ReplicaSet %s"
% (command, rs_id)) | def command(self, rs_id, command, *args) | Call a ReplicaSet method. | 4.158048 | 3.542956 | 1.17361 |
repl = self[repl_id]
result = repl.member_del(member_id)
self[repl_id] = repl
return result | def member_del(self, repl_id, member_id) | remove member from replica set (reconfig replica)
Args:
repl_id - replica set identity
member_id - member index | 3.512825 | 4.586907 | 0.765837 |
repl = self[repl_id]
member_id = repl.repl_member_add(params)
self[repl_id] = repl
return member_id | def member_add(self, repl_id, params) | create instance and add it to existing replcia
Args:
repl_id - replica set identity
params - member params
return True if operation success otherwise False | 4.2566 | 4.630814 | 0.919191 |
repl = self[repl_id]
result = repl.member_command(member_id, command)
self[repl_id] = repl
return result | def member_command(self, repl_id, member_id, command) | apply command(start, stop, restart) to the member of replica set
Args:
repl_id - replica set identity
member_id - member index
command - command: start, stop, restart
return True if operation success otherwise False | 3.115514 | 4.241361 | 0.734555 |
repl = self[repl_id]
result = repl.member_update(member_id, params)
self[repl_id] = repl
return result | def member_update(self, repl_id, member_id, params) | apply new params to replica set member
Args:
repl_id - replica set identity
member_id - member index
params - new member's params
return True if operation success otherwise False | 3.434345 | 4.00587 | 0.857328 |
if self.auth_key:
key_file_path = os.path.join(orchestration_mkdtemp(), 'key')
with open(key_file_path, 'w') as fd:
fd.write(self.auth_key)
os.chmod(key_file_path, stat.S_IRUSR)
return key_file_path | def key_file(self) | Get the path to the key file containig our auth key, or None. | 2.914724 | 2.58404 | 1.127972 |
params = proc_params.copy()
params.pop("auth", None)
params.pop("clusterAuthMode", None)
return params | def _strip_auth(self, proc_params) | Remove options from parameters that cause auth to be enabled. | 4.594841 | 3.608183 | 1.27345 |
parts = ['mongodb://']
if self.login:
parts.append(self.login)
if self.password:
parts.append(':' + self.password)
parts.append('@')
parts.append(hosts + '/')
if self.login:
parts.append('?authSource=' + self.auth_s... | def mongodb_auth_uri(self, hosts) | Get a connection string with all info necessary to authenticate. | 2.472293 | 2.386461 | 1.035966 |
if self.x509_extra_user:
# Build dict of kwargs to pass to add_user.
auth_dict = {
'name': DEFAULT_SUBJECT,
'roles': self._user_roles(db.client)
}
db.add_user(**auth_dict)
# Fix kwargs to MongoClient.
... | def _add_users(self, db, mongo_version) | Add given user, and extra x509 user if necessary. | 5.328122 | 4.874329 | 1.093099 |
link = _BASE_LINKS[rel].copy()
link['rel'] = 'self' if self_rel else rel
return link | def base_link(rel, self_rel=False) | Helper for getting a link document under the API root, given a rel. | 4.7829 | 4.182787 | 1.143472 |
links = [
base_link('get-releases'),
base_link('service'),
server_link('get-servers'),
server_link('add-server'),
replica_set_link('add-replica-set'),
replica_set_link('get-replica-sets'),
sharded_cluster_link('add-sharded-cluster'),
sharded_clust... | def all_base_links(rel_to=None) | Get a list of all links to be included to base (/) API requests. | 2.887203 | 2.840647 | 1.016389 |
servers_href = '/v1/servers'
link = _SERVER_LINKS[rel].copy()
link['href'] = link['href'].format(**locals())
link['rel'] = 'self' if self_rel else rel
return link | def server_link(rel, server_id=None, self_rel=False) | Helper for getting a Server link document, given a rel. | 4.391305 | 4.224217 | 1.039555 |
return [
server_link(rel, server_id, self_rel=(rel == rel_to))
for rel in ('delete-server', 'get-server-info', 'server-command')
] | def all_server_links(server_id, rel_to=None) | Get a list of all links to be included with Servers. | 6.343564 | 6.634352 | 0.956169 |
repls_href = '/v1/replica_sets'
link = _REPLICA_SET_LINKS[rel].copy()
link['href'] = link['href'].format(**locals())
link['rel'] = 'self' if self_rel else rel
return link | def replica_set_link(rel, repl_id=None, member_id=None, self_rel=False) | Helper for getting a ReplicaSet link document, given a rel. | 4.571668 | 4.573666 | 0.999563 |
return [
replica_set_link(rel, rs_id, self_rel=(rel == rel_to))
for rel in (
'get-replica-set-info',
'delete-replica-set', 'replica-set-command',
'get-replica-set-members', 'add-replica-set-member',
'get-replica-set-secondaries', 'get-replica-set-... | def all_replica_set_links(rs_id, rel_to=None) | Get a list of all links to be included with replica sets. | 3.096224 | 3.154579 | 0.981502 |
clusters_href = '/v1/sharded_clusters'
link = _SHARDED_CLUSTER_LINKS[rel].copy()
link['href'] = link['href'].format(**locals())
link['rel'] = 'self' if self_rel else rel
return link | def sharded_cluster_link(rel, cluster_id=None,
shard_id=None, router_id=None, self_rel=False) | Helper for getting a ShardedCluster link document, given a rel. | 4.309642 | 4.064373 | 1.060346 |
return [
sharded_cluster_link(rel, cluster_id, shard_id, router_id,
self_rel=(rel == rel_to))
for rel in (
'get-sharded-clusters', 'get-sharded-cluster-info',
'sharded-cluster-command', 'delete-sharded-cluster',
'add-shard', 'get-... | def all_sharded_cluster_links(cluster_id, shard_id=None,
router_id=None, rel_to=None) | Get a list of all links to be included with ShardedClusters. | 4.20873 | 4.199787 | 1.002129 |
ShardedClusters().cleanup()
ReplicaSets().cleanup()
Servers().cleanup()
sys.exit(0) | def cleanup_storage(*args) | Clean up processes after SIGTERM or SIGINT is received. | 19.477207 | 14.36276 | 1.356091 |
parser = argparse.ArgumentParser(description='mongo-orchestration server')
parser.add_argument('-f', '--config',
action='store', default=None, type=str, dest='config')
parser.add_argument('-e', '--env',
action='store', type=str, dest='env', default=None)
... | def read_env() | return command-line arguments | 2.102037 | 2.06701 | 1.016946 |
from mongo_orchestration import set_releases, cleanup_storage
set_releases(releases, default_release)
signal.signal(signal.SIGTERM, cleanup_storage)
signal.signal(signal.SIGINT, cleanup_storage) | def setup(releases, default_release) | setup storages | 4.753806 | 4.226957 | 1.12464 |
from bottle import default_app
default_app.push()
for module in ("mongo_orchestration.apps.servers",
"mongo_orchestration.apps.replica_sets",
"mongo_orchestration.apps.sharded_clusters"):
__import__(module)
app = default_app.pop()
return app | def get_app() | return bottle app that includes all sub-apps | 4.708878 | 4.582235 | 1.027638 |
for i in range(CONNECT_ATTEMPTS):
try:
conn = socket.create_connection((host, port), CONNECT_TIMEOUT)
conn.close()
return True
except (IOError, socket.error):
time.sleep(1)
return False | def await_connection(host, port) | Wait for the mongo-orchestration server to accept connections. | 2.409432 | 2.488177 | 0.968352 |
if self.version >= (2, 4):
params = config.get('setParameter', {})
# Set enableTestCommands by default but allow enableTestCommands:0.
params.setdefault('enableTestCommands', 1)
# Reduce transactionLifetimeLimitSeconds for faster driver testing.
... | def __init_config_params(self, config) | Conditionally enable options in the Server's config file. | 4.607162 | 4.517455 | 1.019858 |
c = pymongo.MongoClient(
self.hostname, fsync=True,
socketTimeoutMS=self.socket_timeout, **self.kwargs)
connected(c)
if not self.is_mongos and self.login and not self.restart_required:
db = c[self.auth_source]
if self.x509_extra_user:
... | def connection(self) | return authenticated connection | 4.331326 | 4.116457 | 1.052198 |
if not self.__version:
command = (self.name, '--version')
logger.debug(command)
stdout, _ = subprocess.Popen(
command, stdout=subprocess.PIPE).communicate()
version_output = str(stdout)
match = re.search(self.version_patt, vers... | def version(self) | Get the version of MongoDB that this Server runs as a tuple. | 3.031488 | 2.753084 | 1.101125 |
mode = is_eval and 'eval' or 'command'
if isinstance(arg, tuple):
name, d = arg
else:
name, d = arg, {}
result = getattr(self.connection.admin, mode)(command, name, **d)
return result | def run_command(self, command, arg=None, is_eval=False) | run command on the server
Args:
command - command string
arg - command argument
is_eval - if True execute command as eval
return command's result | 5.241944 | 5.531235 | 0.947699 |
proc_info = {"name": self.name,
"params": self.cfg,
"alive": self.is_alive,
"optfile": self.config_path}
if self.is_alive:
proc_info['pid'] = self.proc.pid
logger.debug("proc_info: {proc_info}".format(**locals())... | def info(self) | return info about server as dict object | 3.283996 | 3.186856 | 1.030482 |
if self.is_alive:
return True
try:
dbpath = self.cfg.get('dbpath')
if dbpath and self._is_locked:
# repair if needed
logger.info("Performing repair on locked dbpath %s", dbpath)
process.repair_mongo(self.name, s... | def start(self, timeout=300) | start server
return True of False | 4.368931 | 4.342755 | 1.006028 |
# Return early if this server has already exited.
if not process.proc_alive(self.proc):
return
logger.info("Attempting to connect to %s", self.hostname)
client = self.connection
# Attempt the shutdown command twice, the first attempt might fail due
# ... | def shutdown(self) | Send shutdown command and wait for the process to exit. | 5.655403 | 5.313157 | 1.064415 |
try:
self.shutdown()
except (PyMongoError, ServersError) as exc:
logger.info("Killing %s with signal, shutdown command failed: %r",
self.name, exc)
return process.kill_mprocess(self.proc) | def stop(self) | stop server | 12.36088 | 11.923445 | 1.036687 |
self.stop()
if config_callback:
self.cfg = config_callback(self.cfg.copy())
self.config_path = process.write_config(self.cfg)
return self.start(timeout) | def restart(self, timeout=300, config_callback=None) | restart server: stop() and start()
return status of start command | 4.52153 | 4.062832 | 1.112901 |
name = os.path.split(name)[1]
if server_id is None:
server_id = str(uuid4())
if server_id in self:
raise ServersError("Server with id %s already exists." % server_id)
bin_path = self.bin_path(version)
server = Server(os.path.join(bin_path, name),... | def create(self, name, procParams, sslParams={},
auth_key=None, login=None, password=None,
auth_source='admin', timeout=300, autostart=True,
server_id=None, version=None) | create new server
Args:
name - process name or path
procParams - dictionary with specific params for instance
auth_key - authorization key
login - username for the admin collection
password - password
timeout - specify how long, in seconds, a c... | 2.493801 | 2.70569 | 0.921688 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.