Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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 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()
Exemplo n.º 4
0
    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 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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    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 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)
Exemplo n.º 11
0
 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)