Guest User

Untitled

a guest
Dec 10th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /*
  2. * Generic helper functions, not db specific.
  3. */
  4.  
  5. function hostMatchesFilter(host, hostAndPort)
  6. {
  7. if(hostAndPort === #N/A ||
  8. hostAndPort.toString() == "" ||
  9. hostAndPort.toString()=="*" )
  10. return true;
  11.  
  12. hostPortArray = hostAndPort.split(,":");
  13. hostname=hostPortArray[0];
  14. port=hostPortArray[1];
  15. if(host.port() == port.toInt() && host.hostName() == hostname.toString())
  16. {
  17. return true;
  18. }
  19. return false;
  20. }
  21.  
  22. function executeOnController(command)
  23. {
  24. var hosts = cluster::hosts();
  25. var retval = {};
  26.  
  27. for (idx = 0; idx < hosts.size(); idx++) {
  28. host = hosts[idx];
  29. hmap = host.toMap();
  30.  
  31. if (hmap['nodetype'] == "controller") {
  32. retval = host.system(command);
  33. break;
  34. }
  35. }
  36. return retval;
  37. }
  38.  
  39. // Compare host version versus version string
  40. function checkHostVersion(host, version) {
  41. serverVersion = host.serverVersion();
  42. if (serverVersion.startsWith(version))
  43. return true;
  44. return false;
  45. //return host.serverVersion().toString().startsWith(version.toString());
  46. }
  47.  
  48. // Check if the host is of mysql type
  49. function isMySqlHost(host) {
  50. return host.nodeType() === 'mysql' ||
  51. host.nodeType() === 'galera';
  52. }
  53.  
  54. function isMySql57Host(host) {
  55. return isMySqlHost(host) && checkHostVersion(host, '5.7');
  56. }
  57.  
  58. function isMariaDb102Host(host) {
  59. return isMySqlHost(host) && checkHostVersion(host, '10.2');
  60. }
Add Comment
Please, Sign In to add comment