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, })
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() ] })
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)
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)
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})
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'})
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()})
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()
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'})
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})
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()
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})
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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')
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)
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() })
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 })
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)