def host(self, host_name, connection=None): if connection is None: host = Host(host_name, self.connection, self.save_connection) else: host = Host(host_name, connection, False) return host.read()
def restart(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}." .format(connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Restarting cluster...") cluster.restart() # Make sure it's back up status = self.status(args,config,connection,internal=True) while status != 'up': time.sleep(2) status = self.status(args,config,connection,internal=True) else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname,connection=connection).read() print("Restarting host...") host.restart() # Make sure it's back up status = self.status(args,config,connection,internal=True) while status != 'up': time.sleep(2) status = self.status(args,config,connection,internal=True)
def stop(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}.".format( connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Shutting down cluster...") cluster.shutdown() else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname, connection=connection).read() print("Shutting down host...") host.shutdown() status = self.status(args, config, connection, internal=True) while status == 'up': time.sleep(2) status = self.status(args, config, connection, internal=True)
def instance_init(cls, host): """ Performs first-time initialization of a newly installed server. :param host: The name or IP address of the host to initialize """ conn = Connection(host, None) uri = "{0}://{1}:8001/admin/v1/init".format(conn.protocol, conn.host) logger = logging.getLogger("marklogic") logger.debug("Initializing {0}".format(host)) # This call is a little odd; we special case the 400 error that # occurs if the host has alreadya been initialized. try: response = conn.post( uri, content_type='application/x-www-form-urlencoded') except UnexpectedManagementAPIResponse: response = conn.response if response.status_code == 400: err = json.loads(response.text) if "errorResponse" in err: if "messageCode" in err["errorResponse"]: if err["errorResponse"][ "messageCode"] == "MANAGE-ALREADYINIT": return Host(host) raise if response.status_code != 202: raise UnexpectedManagementAPIResponse(response.text) return Host(host)._set_just_initialized()
def stop(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}." .format(connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Shutting down cluster...") cluster.shutdown() else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname,connection=connection).read() print("Shutting down host...") host.shutdown() status = self.status(args,config,connection,internal=True) while status == 'up': time.sleep(2) status = self.status(args,config,connection,internal=True)
def ml_init(self, hostname): print("{0}: initialize host...".format(hostname)) try: host = MarkLogic.instance_init(hostname) except UnauthorizedAPIRequest: # Assume that this happened because the host is already initialized host = Host(hostname) return host.just_initialized()
def add_host(self, host, connection=None): if connection is None: connection = self.connection if isinstance(host, str): host = Host(host) xml = host._get_server_config() cfgzip = self._post_server_config(xml,connection) host_connection = Connection(host.host_name(), connection.auth) host._post_cluster_config(cfgzip,host_connection)
def stop(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}.".format( connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Shutting down cluster...") cluster.shutdown() else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname, connection=connection).read() if host.group_name() is None: ml = MarkLogic(connection) if len(ml.hosts()) == 1: host = Host(ml.hosts()[0], connection=connection).read() else: print("Failed to identify host:", ml.hosts()) sys.exit(1) print("Shutting down host: " + host.host_name()) host.shutdown() status = self.status(args, config, connection, internal=True) while status == 'up': time.sleep(2) status = self.status(args, config, connection, internal=True)
def ml_init(self, ip, container): if container in self.hostname: hostname = self.hostname[container] else: hostname = container print("{0}: initialize host {1}...".format(ip,hostname)) try: host = MarkLogic.instance_init(ip) except UnauthorizedAPIRequest: # Assume that this happened because the host is already initialized host = Host(ip) self.blacklist[container] = "used" self.save_blacklist() return host.just_initialized()
def ml_init(self, ip, container): if container in self.hostname: hostname = self.hostname[container] else: hostname = container print("{0}: initialize host {1}...".format(ip, hostname)) try: host = MarkLogic.instance_init(ip) except UnauthorizedAPIRequest: # Assume that this happened because the host is already initialized host = Host(ip) self.blacklist[container] = "used" self.save_blacklist() return host.just_initialized()
def hosts(self, connection=None): """ Get a list of the hosts in the local cluster. """ if connection is None: connection = self.connection return Host.list(connection)
def join(self, args, config, connection): cluster = LocalCluster(connection=connection) cluster.read() self.logger.info("Initializing {0}...".format(args['host'])) MarkLogic.instance_init(args['host']) host = Host(args['host']) self.logger.info("Joining cluster...") cluster.add_host(host)
def restart(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}.".format( connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Restarting cluster...") cluster.restart() else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname, connection=connection).read() print("Restarting host...") host.restart()
def stop(self, args, config, connection): status = self.status(args, config, connection, internal=True) if status == 'down': print("MarkLogic server on {0} appears to be {1}." .format(connection.host, status)) else: if 'cluster' in args: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() cluster = LocalCluster(connection=connection).read() print("Shutting down cluster...") cluster.shutdown() else: hostname = connection.host if hostname == 'localhost': hostname = socket.gethostname() host = Host(hostname,connection=connection).read() if host.group_name() is None: ml = MarkLogic(connection) if len(ml.hosts()) == 1: host = Host(ml.hosts()[0], connection=connection).read() else: print("Failed to identify host:",ml.hosts()) sys.exit(1) print("Shutting down host: " + host.host_name()) host.shutdown() status = self.status(args,config,connection,internal=True) while status == 'up': time.sleep(2) status = self.status(args,config,connection,internal=True)
self.logger.info("Create simple application") data_database = Database(self._db_name, hostname) data_database.set_forest_names(self._forests) modules_database = Database(self._modules_db_name, hostname) server = HttpServer(self._http_server, "Default", self._app_port, self._db_name, self._modules_db_name) server.set_modules_database_name(self._modules_db_name) data_database.create(conn) modules_database.create(conn) server.create(conn) return { u'content': data_database, u'modules': modules_database, u'server': server } if __name__ == "__main__": logging.basicConfig(level=logging.WARNING) logging.getLogger("requests").setLevel(logging.WARNING) logging.getLogger("marklogic").setLevel(logging.DEBUG) logging.getLogger("marklogic.examples").setLevel(logging.INFO) simpleapp = SimpleApplication(tc.appname, tc.port) conn = Connection(tc.hostname, HTTPDigestAuth(tc.admin, tc.password)) hostname = Host.list(conn)[0] myapp = simpleapp.create(conn, hostname)
def ml_join(self, boothost, hostname): print("{0}: join cluster with {1}...".format(hostname, boothost)) cluster = self.marklogic.cluster() host = Host(hostname) cluster.add_host(host)
def ml_join(self, bootip, ip): print("{0}: join cluster with {1}...".format(ip, bootip)) cluster = self.marklogic.cluster() host = Host(ip) cluster.add_host(host)
def hosts(self, connection=None): if connection is None: connection = self.connection return Host.list(connection)