예제 #1
0
    def get_service_performance(self, kwargs):
        """
        TODO: placeholder for obtaining performance metrics.

        No parameters.

        Returns a dict with keys:
            request_rate : int
            error_rate : int
            throughput : int
            response_time : int
        """

        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({
                 'request_rate': 0,
                                 'error_rate': 0,
                                 'throughput': 0,
                                 'response_time': 0,
                                 })
예제 #2
0
    def list_nodes(self, kwargs):
        """
        List this MySQL Galera current agents.

        No parameters.

        Returns a dict with keys:
        nodes : list of regular node identifiers
        glb_nodes : lits of load balancing node identifiers
        """
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        try:
            self.check_state([self.S_RUNNING, self.S_ADAPTING])
        except:
            return HttpJsonResponse({})

        return HttpJsonResponse({ self.ROLE_MYSQL:
                                    [ node.id for node in self.config.get_nodes() ],
                                  self.ROLE_GLB:
                                    [ node.id for node in self.config.get_glb_nodes() ]
                                })
예제 #3
0
    def get_agent_log(self, kwargs):
        """Return logfile"""
        node_ids = [ str(node.id) for node in self.nodes ]
        exp_params = [('agentId', is_in_list(node_ids)),
                      ('filename', is_string, None)]
        try:
            agent_id, filename = check_arguments(exp_params, kwargs)

            # Get the node that has the specified agent_id
            node = [ node for node in self.nodes if node.id == agent_id ][0]

            # If a filename was specified...
            if filename:
                # Get the logs for the node's role
                logs = self.get_role_logs(node.role)

                # Check that the filename is valid for that role
                filenames = map(lambda log: log['filename'], logs)
                exp_params = [('filename', is_in_list(filenames))]
                check_arguments(exp_params, dict(filename=filename))

                # Replace the filename with its corresponding path in the agent
                filename = [ log['path'] for log in logs
                                         if log['filename'] == filename ][0]

            res = self.fetch_agent_log(node.ip, self.AGENT_PORT, filename)
            return HttpJsonResponse(res)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)
예제 #4
0
    def sqldump(self, kwargs):
        """
        Dump the database.

        No parameters.

        Returns the dump of the database.
        """
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
            self.check_state([self.S_RUNNING])
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        # at least one agent since state is S_RUNNING
        one_node = self.config.get_nodes()[0]
        # adding option '--skip-lock-tables' to avoid issue
        #  mysqldump: Got error: 1142: SELECT,LOCK TABL command denied to user
        #   'root'@'10.158.0.28' for table 'cond_instances'
        #   when using LOCK TABLES
        # FIXME: is it MySQL 5.1 only? does it still occur with MySQL 5.5?
        cmd = 'mysqldump -u root -h %s --password=%s -A --skip-lock-tables' \
              % (one_node.ip, self.root_pass)
        out, error, return_code = run_cmd_code(cmd)

        if return_code == 0:
            return HttpJsonResponse(out)
        else:
            return HttpErrorResponse("Failed to run mysqldump: %s." % error)
예제 #5
0
    def get_service_history(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({'state_log': self.state_log})
예제 #6
0
    def get_service_info(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({'state': self.state_get(), 'type': 'helloworld'})
예제 #7
0
    def list_authorized_keys(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({'authorizedKeys' : git.get_authorized_keys()})
예제 #8
0
    def check_process(self, kwargs):
        """Check if agent process started - just return an empty response"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse()
예제 #9
0
    def get_service_info(self, kwargs):
        """Return the service state and type"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({'state': self.state_get(), 'type': 'generic'})
예제 #10
0
    def get_helloworld(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        self.logger.info('Agent returned hello')
        return HttpJsonResponse({'result': self.gen_string})
예제 #11
0
    def startup(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        self.logger.info('Agent started up')
        return HttpJsonResponse()
예제 #12
0
    def get_configuration(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        config = self._configuration_get()
        return HttpJsonResponse({'codeVersionId': config.currentCodeVersion})
예제 #13
0
    def getTomcatState(self, kwargs):
        """GET state of Tomcat"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.tomcat_lock:
            return self._get(kwargs, self.tomcat_file, role.Tomcat)
예제 #14
0
    def stopPHP(self, kwargs):
        """KILL the PHPProcessManager"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.php_lock:
            return self._stop(kwargs, self.php_file, role.PHPProcessManager)
예제 #15
0
    def getPHPState(self, kwargs):
        """GET state of PHPProcessManager"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.php_lock:
            return self._get(kwargs, self.php_file, role.PHPProcessManager)
예제 #16
0
    def stopHttpProxy(self, kwargs):
        """KILL the HttpProxy"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.httpproxy_lock:
            return self._stop(kwargs, self.httpproxy_file, self.HttpProxy)
예제 #17
0
    def stopWebServer(self, kwargs):
        """KILL the WebServer"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.web_lock:
            return self._stop(kwargs, self.webserver_file, self.WebServer)
예제 #18
0
    def getHttpProxyState(self, kwargs):
        """GET state of HttpProxy"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.httpproxy_lock:
            return self._get(kwargs, self.httpproxy_file, self.HttpProxy)
예제 #19
0
    def stopTomcat(self, kwargs):
        """KILL Tomcat"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.tomcat_lock:
            return self._stop(kwargs, self.tomcat_file, role.Tomcat)
예제 #20
0
    def createDIR(self, kwargs):
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('uuid', is_string)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.dir_lock:
            return self._create(orig_kwargs, self.dir_file, self.DIR)
예제 #21
0
    def stopOSD(self, kwargs):
        """Kill the OSD service"""
        orig_kwargs = copy.copy(kwargs)
        try:
            exp_params = [('drain', is_bool, False)]
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.osd_lock:
            return self._stop(orig_kwargs, self.osd_file, self.OSD)
예제 #22
0
    def stopMRC(self, kwargs):
        """Kill the MRC service"""
        orig_kwargs = copy.copy(kwargs)
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.mrc_lock:
            return self._stop(orig_kwargs, self.mrc_file, self.MRC)
예제 #23
0
    def createTomcat(self, kwargs):
        """Create Tomcat"""
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('tomcat_port', is_pos_int)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.tomcat_lock:
            return self._create(orig_kwargs, self.tomcat_file, role.Tomcat)
예제 #24
0
    def createScalaris(self, kwargs):
        """Create the ScalarisProcessManager"""
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('first_node', is_bool),
                      ('known_hosts', is_string)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.scalaris_lock:
            return self._create(orig_kwargs, self.scalaris_file, role.ScalarisProcessManager)
예제 #25
0
    def createMRC(self, kwargs):
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('dir_serviceHost', is_string),
                      ('uuid', is_string),
                      ('hostname', is_string)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.mrc_lock:
            return self._create(orig_kwargs, self.mrc_file, self.MRC)
예제 #26
0
    def get_manager_log(self, kwargs):
        """Return logfile"""
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        try:
            return HttpJsonResponse({'log': file_get_contents(self.logfile)})
        except:
            return HttpErrorResponse('Failed to read log')
예제 #27
0
    def updateWebServer(self, kwargs):
        """UPDATE the WebServer"""
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('port', is_pos_int),
                      ('code_versions', is_list)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.web_lock:
            return self._update(orig_kwargs, self.webserver_file, self.WebServer)
예제 #28
0
    def get_app_info(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        return HttpJsonResponse({
                                # 'methods': self._get_supporeted_functions(),
                                'states': self._get_manager_states(),
                                'nodes': [node.id for node in self.nodes],
                                'volumes': self.volumes.keys()
                                })
예제 #29
0
    def get_script_status(self, kwargs):
        try:
            exp_params = []
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        scripts = {}
        for command in ( 'init', 'notify', 'run', 'interrupt', 'cleanup' ):
            script_name = "%s.sh" % command
            scripts[script_name] = self._get_script_status(command)

        return HttpJsonResponse({ 'scripts' : scripts })
예제 #30
0
    def updatePHP(self, kwargs):
        """UPDATE the PHPProcessManager"""
        orig_kwargs = copy.copy(kwargs)
        exp_params = [('port', is_pos_int),
                      ('scalaris', is_string),
                      ('configuration', is_dict)]
        try:
            check_arguments(exp_params, kwargs)
        except Exception as ex:
            return HttpErrorResponse("%s" % ex)

        with self.php_lock:
            return self._update(orig_kwargs, self.php_file, role.PHPProcessManager)