Util.ecl 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*##############################################################################
  2. ## HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®. All rights reserved.
  3. ############################################################################## */
  4. import lib_fileservices;
  5. /**
  6. * Various utility functions for accessing system function.
  7. */
  8. RETURN MODULE
  9. /**
  10. * Returns the host name associated with a particular ip.
  11. *
  12. * @param ipaddress The ip address to resolve.
  13. * @returns The host name.
  14. */
  15. EXPORT varstring GetHostName(varstring ipaddress ) :=
  16. lib_fileservices.FileServices.GetHostName(ipaddress );
  17. /**
  18. * Returns the ip address for a host name.
  19. *
  20. * @param hostname The name of the host to resolve.
  21. * @returns The associated ip address.
  22. */
  23. EXPORT varstring ResolveHostName(varstring hostname ) :=
  24. lib_fileservices.FileServices.ResolveHostName(hostname );
  25. /**
  26. * Returns a number that is unique for a particular dali.
  27. *
  28. * @param foreigndali The ip address of the dali to provide the unique number. Defaults to current.
  29. * @returns A 64bit integer which is unique (e.g., across all slaves) to the dali that provided it.
  30. */
  31. EXPORT unsigned8 getUniqueInteger(varstring foreigndali='') :=
  32. lib_fileservices.FileServices.getUniqueInteger(foreigndali);
  33. /**
  34. * Simple function that tests a full version string against the individual
  35. * platform version constants to determine if the platform's version is at
  36. * least as high as the argument.
  37. *
  38. * Note that this function will be evaluated at compile-time if the argument
  39. * is a constant. This makes it useful for embedding in #IF() declarations:
  40. *
  41. * #IF(PlatformVersionCheck('6.2.0-1'))
  42. * OUTPUT('Platform check TRUE');
  43. * #ELSE
  44. * OUTPUT('Platform check FALSE');
  45. * #END
  46. *
  47. * @param v The minimum platform version in either xx.xx.xx, xx.xx,
  48. * or xx format (where xx is an integer and does not need
  49. * to be zero-padded); extra trailing characters (such as
  50. * the '-1' in the example above) are ignored; REQUIRED
  51. *
  52. * @return If TRUE, the platform's current version is equal to or higher than
  53. * the argument.
  54. */
  55. EXPORT PlatformVersionCheck(STRING v) := FUNCTION
  56. major := (INTEGER)REGEXFIND('^(\\d+)', v, 1);
  57. minor := (INTEGER)REGEXFIND('^\\d+\\.(\\d+)', v, 1);
  58. subminor := (INTEGER)REGEXFIND('^\\d+\\.\\d+\\.(\\d+)', v, 1);
  59. RETURN MAP
  60. (
  61. __ecl_version_major__ > major => TRUE,
  62. __ecl_version_major__ = major AND __ecl_version_minor__ > minor => TRUE,
  63. __ecl_version_major__ = major AND __ecl_version_minor__ = minor AND __ecl_version_subminor__ >= subminor => TRUE,
  64. FALSE
  65. );
  66. END;
  67. END;