Example #1
0
    def api_config(self, config=None):
        # Read the configuration.
        api_path = paths.endpoint("api")
        if config == None:
            config = self.scale_manager.zk_conn.read(api_path) or ''

        # Update basic information.
        api_config = EndpointConfig(str(config))
        if self.scale_manager.domain:
            url = "http://api.%s" % self.scale_manager.domain
        else:
            url = "http://"
        api_config._set("endpoint", "url", url)
        api_config._set("scaling",  "url", url)
        api_config._set("endpoint", "port", "8080")
        api_config._set("endpoint", "public", "false")
        api_config._set("endpoint", "enabled", "true")

        # Update the static IPs in the configuration.
        addresses = self.scale_manager.zk_servers
        addresses.sort()
        address_str = ",".join(addresses)
        api_config._set("endpoint", "static_instances", address_str)

        if not(api_config._is_clean()):
            # Save the config if it was changed.
            self.scale_manager.zk_conn.write(paths.endpoint("api"), str(api_config))

        return api_config
Example #2
0
    def add_endpoint(self, endpoint):

        self.__add_endpoint(endpoint)

        def local_lock(fn):
            def wrapped_fn(*args, **kwargs):
                try:
                    self.cond.acquire()
                    return fn(*args, **kwargs)
                finally:
                    self.cond.release()
            return wrapped_fn

        @local_lock
        def update_state(value):
            endpoint.update_state(value)
            if self.endpoint_owned(endpoint):
                endpoint.update()

        @local_lock
        def update_config(value):
            endpoint.update_config(value)
            if self.endpoint_owned(endpoint):
                endpoint.update()

        @local_lock
        def update_confirmed(ips):
            if ips:
                self.confirmed[endpoint.name] = ips
            elif endpoint.name in self.confirmed:
                del self.confirmed[endpoint.name]

            # Kick off a loadbalancer update.
            self.update_loadbalancer(endpoint)

        # Watch the config for this endpoint.
        logging.info("Watching endpoint %s." % (endpoint.name))
        update_state(
            self.zk_conn.watch_contents(paths.endpoint_state(endpoint.name),
                                        update_state, '',
                                        clean=True))
        update_config(
            self.zk_conn.watch_contents(paths.endpoint(endpoint.name),
                                        update_config, '',
                                        clean=True))

        # Select the manager for this endpoint.
        self.manager_select(endpoint)

        # Update the loadbalancer for this endpoint.
        update_confirmed(
            self.zk_conn.watch_children(paths.confirmed_ips(endpoint.name),
                                        update_confirmed,
                                        clean=True))
Example #3
0
    def remove_endpoint(self, endpoint_name, unmanage=False):
        """
        This removes / unmanages the endpoint.
        """
        logging.info("Removing endpoint %s from manager %s" % (endpoint_name, self.uuid))
        endpoint = self.endpoints.get(endpoint_name, None)

        if endpoint:
            self.zk_conn.clear_watch_path(paths.endpoint_state(endpoint.name))
            self.zk_conn.clear_watch_path(paths.endpoint(endpoint.name))
            self.zk_conn.clear_watch_path(paths.confirmed_ips(endpoint.name))

            # Update the loadbalancer for this endpoint.
            self.update_loadbalancer(endpoint, remove=True)
            self.__remove_endpoint(endpoint, unmanage)
            self.manager_remove(endpoint)
Example #4
0
 def get_endpoint_config(self, endpoint_name):
     return self.zk_conn.read(paths.endpoint(endpoint_name))
Example #5
0
 def update_endpoint(self, endpoint_name, config):
     self.zk_conn.write(paths.endpoint(endpoint_name), config)
Example #6
0
 def unmanage_endpoint(self, endpoint_name):
     self.zk_conn.delete(paths.endpoint(endpoint_name))