Class Util

java.lang.Object
com.mapr.baseutils.utils.Util

public class Util extends Object
Utility class Mostly static functions
  • Field Details

    • SEC

      public static int SEC
    • MIN

      public static int MIN
    • FIVE_MIN

      public static int FIVE_MIN
    • PORT_MIN

      public static int PORT_MIN
    • PORT_MAX

      public static int PORT_MAX
    • IPV4_ADDR_SIZE

      public static final int IPV4_ADDR_SIZE
      See Also:
    • IPV6_ADDR_SIZE

      public static final int IPV6_ADDR_SIZE
      See Also:
    • nodePropertiesFile

      public static final String nodePropertiesFile
    • PATH_SEPERATOR_STR

      public static final String PATH_SEPERATOR_STR
      See Also:
    • ROOT

      public static final String ROOT
      See Also:
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • intToIp

      public static String intToIp(int i)
    • isValidPort

      public static boolean isValidPort(int port)
    • ipAddrMsgToByteArray

      public static byte[] ipAddrMsgToByteArray(com.mapr.fs.proto.Security.IpAddrMsg ipAddrMsg)
    • intToByteArray

      public static byte[] intToByteArray(int val)
    • isValidIpAddress

      public static boolean isValidIpAddress(byte[] byteArr)
    • ipv4ByteArrToStr

      public static String ipv4ByteArrToStr(byte[] byteArr) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • ipv6ByteArrToStr

      public static String ipv6ByteArrToStr(byte[] byteArr) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • byteArrToSocketAddrStr

      public static String byteArrToSocketAddrStr(byte[] byteArr, int port)
    • byteArrToIpAddrMsg

      public static com.mapr.fs.proto.Security.IpAddrMsg byteArrToIpAddrMsg(byte[] byteIpArr)
    • rpcCallContextToIPAddress

      public static com.mapr.fs.proto.Common.IPAddress rpcCallContextToIPAddress(RpcCallContext context)
    • byteArrToIPAddress

      public static com.mapr.fs.proto.Common.IPAddress byteArrToIPAddress(byte[] byteIpArr)
    • byteArraytoInt

      public static int byteArraytoInt(byte[] byteArray)
    • isNullOrEmpty

      public static boolean isNullOrEmpty(String str)
    • ipToInt

      public static int ipToInt(String addr)
    • ipToLong

      public static long ipToLong(String ipAddress)
    • getSocketAddrListFromIPPort

      public static List<CLDBRpcCommonUtils.SocketAddr> getSocketAddrListFromIPPort(com.mapr.fs.proto.Common.IPPort ipPort)
    • longToIp

      public static String longToIp(long i)
    • readableSizeMB

      public static String readableSizeMB(long sizeMB)
    • readableSizeToSizeMB

      public static long readableSizeToSizeMB(String size)
    • limitDecimalTo2

      public static String limitDecimalTo2(double d)
    • makeLongFromInts

      public static long makeLongFromInts(long higher, long lower)
    • getHigherIntFromLong

      public static int getHigherIntFromLong(long number)
    • getLowerIntFromLong

      public static int getLowerIntFromLong(long number)
    • getMin

      public static long getMin(int number)
    • getMax

      public static long getMax(int number)
    • ipBelongsToServer

      public static boolean ipBelongsToServer(com.mapr.fs.proto.Common.Server server, com.mapr.fs.proto.Common.IPAddress toCompare)
    • printSimpleDateFormat

      public static String printSimpleDateFormat(com.mapr.fs.proto.Common.FileTimeMsg time)
    • printFidMsg

      public static String printFidMsg(com.mapr.fs.proto.Common.FidMsg a)
    • printIPAddress

      public static String printIPAddress(int host, int port)
    • printServerList

      public static String printServerList(List<com.mapr.fs.proto.Common.Server> servers)
    • printServer

      public static String printServer(com.mapr.fs.proto.Common.Server server)
    • printIPAddress

      public static String printIPAddress(com.mapr.fs.proto.Common.IPAddress ip)
    • exceptionToString

      public static String exceptionToString(Exception e)
    • printIPAddresses

      public static String printIPAddresses(com.mapr.fs.proto.Common.Server server)
    • printOneIpAddress

      public static String printOneIpAddress(com.mapr.fs.proto.Common.Server server)
    • printOneIpAddress

      public static String printOneIpAddress(List<com.mapr.fs.proto.Common.IPAddress> ips)
    • printIpAddrListAndPortListInfo

      public static String printIpAddrListAndPortListInfo(List<CLDBRpcCommonUtils.IpAddr> ipAddrList, List<Integer> ports)
    • getIpAddrListFromIp

      public static List<CLDBRpcCommonUtils.IpAddr> getIpAddrListFromIp(List<Integer> ipv4AddressList, List<com.mapr.fs.proto.Security.IpAddrMsg> ipv6AdressList)
    • printIPAddresses

      public static String printIPAddresses(List<com.mapr.fs.proto.Common.IPAddress> ips)
    • printIPAddressesWithHostname

      public static String printIPAddressesWithHostname(List<com.mapr.fs.proto.Common.IPAddress> ips)
    • printPorts

      public static String printPorts(List<Integer> ports)
    • printSPIds

      public static String printSPIds(List<com.mapr.fs.proto.Common.StoragePoolInfo> sps)
    • printServerWithState

      public static String printServerWithState(com.mapr.fs.proto.Common.Server s)
    • printServerWithNoState

      public static String printServerWithNoState(com.mapr.fs.proto.Common.Server s)
    • printContainerInfoWithServerId

      public static String printContainerInfoWithServerId(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo c)
    • printContainerInfoWithServerId

      public static String printContainerInfoWithServerId(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo c, boolean verbose)
    • getLogMsgIfMalformed

      public static String getLogMsgIfMalformed(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo cInfo)
    • printInitialContainerInfo

      public static String printInitialContainerInfo(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo c)
    • replicaStateToString

      public static String replicaStateToString(com.mapr.fs.proto.Common.Server.ReplicaState replState)
    • printContainerSizeInfo

      public static String printContainerSizeInfo(com.mapr.fs.cldb.proto.CLDBProto.ContainerSizeInfo c)
    • compareIPAddress

      public static boolean compareIPAddress(com.mapr.fs.proto.Common.IPAddress a, com.mapr.fs.proto.Common.IPAddress b)
    • getIPAddressList

      public static List<com.mapr.fs.proto.Common.IPAddress> getIPAddressList(com.mapr.fs.cldb.proto.CLDBProto.FileServerRegisterRequest freq)
    • compareIpFromServer

      public static boolean compareIpFromServer(com.mapr.fs.proto.Common.Server server1, com.mapr.fs.proto.Common.Server server2, int index)
    • getPort

      public static Integer getPort(com.mapr.fs.proto.Common.Server server, int index)
    • getIPAddressList

      public static List<com.mapr.fs.proto.Common.IPAddress> getIPAddressList(com.mapr.fs.proto.Common.Server server, boolean isExternal)
    • getIPAddress

      public static com.mapr.fs.proto.Common.IPAddress getIPAddress(com.mapr.fs.proto.Common.Server server, boolean isExternal)
    • getHostname

      public static String getHostname(com.mapr.fs.proto.Common.Server server, int index)
    • getOneIPAddress

      public static CLDBRpcCommonUtils.IpAddr getOneIPAddress(List<com.mapr.fs.proto.Common.IPAddress> ips, boolean isIPv6)
    • isDuplicateIPinServer

      public static boolean isDuplicateIPinServer(com.mapr.fs.proto.Common.Server s)
    • isDuplicateIPinContainer

      public static void isDuplicateIPinContainer(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo cInfo)
    • compareServers

      public static boolean compareServers(com.mapr.fs.proto.Common.Server a, com.mapr.fs.proto.Common.Server b)
    • compareServers

      public static boolean compareServers(com.mapr.fs.proto.Common.Server a, long b)
    • compareFidMsg

      public static boolean compareFidMsg(com.mapr.fs.proto.Common.FidMsg a, com.mapr.fs.proto.Common.FidMsg b)
    • getFloor

      public static long getFloor(long val, long interval)
    • getCeil

      public static long getCeil(long val, long interval)
    • aeKeyToString

      public static String aeKeyToString(com.mapr.fs.cldb.proto.CLDBProto.AeKey key)
    • getHostIPAddresses

      public static List<String> getHostIPAddresses()
      Return all local IPAddress. Will filter out 127.0.0.1 and 127.0.1.1
      Returns:
    • hexToLong

      public static long hexToLong(byte[] bytes)
      Converts a string of ascii hexadecimal characters into a Long integer. The need for this function arises from the limitation of Long.parseLong function for signed long integers.
      Parameters:
      bytes - string of hexademical characters. Valid characters are '0-9', and 'a-z'.
      Returns:
      long long values of the hexadecimal string.
    • isInteger

      public static boolean isInteger(String s)
    • isNonNegativeInteger

      public static boolean isNonNegativeInteger(String s)
    • roundTimeStampToMidnight

      public static long roundTimeStampToMidnight(long timeOfDay)
      Computes millis since epoch at midnight for the day represented by timeOfDay. The date is interpreted in UTC timezone.
      Returns:
      millis since epoch at midnight of the day in UTC
    • getContainerActualSize

      public static int getContainerActualSize(com.mapr.fs.cldb.proto.CLDBProto.ContainerSizeInfo c)
    • getContainerActualSize

      public static int getContainerActualSize(int ownedSizeMB, int sharedSizeMB, int chainSizeMB)
    • hasOverlap

      public static boolean hasOverlap(List<?> list1, List<?> list2)
    • hasDeviceOverlap

      public static boolean hasDeviceOverlap(List<com.mapr.fs.proto.Common.InterfaceInfo> list1, List<com.mapr.fs.proto.Common.InterfaceInfo> list2)
    • elapsedTimeGreaterThan

      public static long elapsedTimeGreaterThan(long lastLoggedTime, long skipMillis)
    • shrinkSpId

      public static String shrinkSpId(String spid)
      shrink and expand spid from hexadecimal to a string
      Parameters:
      spid -
      Returns:
    • expandSpId

      public static String expandSpId(String spid)
    • printIPAddressForCLI

      public static String printIPAddressForCLI(com.mapr.fs.proto.Common.IPAddress ip)
    • printIPAddressesForCLI

      public static String printIPAddressesForCLI(com.mapr.fs.proto.Common.Server server)
    • parseSocket

      public static CLDBRpcCommonUtils.SocketAddr parseSocket(String socketAddress)
    • PrintExtIpAddressesForCli

      public static String PrintExtIpAddressesForCli(com.mapr.fs.proto.Common.Server server)
    • printIPAddressesForCLI

      public static String printIPAddressesForCLI(List<com.mapr.fs.proto.Common.IPAddress> ips)
    • printExternalIPAddressesForCLI

      public static String printExternalIPAddressesForCLI(List<com.mapr.fs.proto.Common.IPAddress> ips, List<Integer> ports)
    • printRdmaPort

      public static String printRdmaPort(com.mapr.fs.proto.Common.Server s, int firstPort)
    • printServerWithStateForCLI

      public static String printServerWithStateForCLI(com.mapr.fs.proto.Common.Server s) throws Exception
      Throws:
      Exception
    • printServerWithStateForCLI

      public static String printServerWithStateForCLI(com.mapr.fs.proto.Common.Server s, boolean getCtime) throws Exception
      Throws:
      Exception
    • printServerWithNoStateForCLI

      public static String printServerWithNoStateForCLI(com.mapr.fs.proto.Common.Server s) throws Exception
      Throws:
      Exception
    • printServerWithNoStateForCLI

      public static String printServerWithNoStateForCLI(com.mapr.fs.proto.Common.Server s, boolean getCtime) throws Exception
      Throws:
      Exception
    • printContainerInfoForCLI

      public static String printContainerInfoForCLI(com.mapr.fs.cldb.proto.CLDBProto.ContainerInfo c)
    • printCredentials

      public static String printCredentials(com.mapr.fs.proto.Security.CredentialsMsg creds)
    • getUniqueVolumeUuid

      public static com.mapr.fs.proto.Common.GuidMsg getUniqueVolumeUuid(com.mapr.fs.proto.Common.GuidMsg clusterUuid, com.mapr.fs.cldb.proto.CLDBProto.VolumeProperties volProps)
    • pringGuid

      public static String pringGuid(com.mapr.fs.proto.Common.GuidMsg guid)
    • getChangedAlarmGroupEntries

      public static List<KeyValue> getChangedAlarmGroupEntries(com.mapr.fs.proto.Common.AlarmGroupConfigMsg oldConfig, com.mapr.fs.proto.Common.AlarmGroupConfigMsg newConfig)
    • getChangedOffloadRuleProps

      public static List<KeyValue> getChangedOffloadRuleProps(com.mapr.fs.cldb.proto.CLDBProto.OffloadRuleProperties oldProps, com.mapr.fs.cldb.proto.CLDBProto.OffloadRuleProperties newProps)
    • getChangedTierProps

      public static List<KeyValue> getChangedTierProps(com.mapr.fs.cldb.proto.CLDBProto.TierProperties oldProps, com.mapr.fs.cldb.proto.CLDBProto.TierProperties newProps)
    • getNameFromVolumenoteKey

      public static String getNameFromVolumenoteKey(String noteKey)
    • getVolIdFromVolumenoteKey

      public static int getVolIdFromVolumenoteKey(String noteKey)
    • getVolumenoteKey

      public static String getVolumenoteKey(int volId, String noteName)
    • getCurrentDate

      public static String getCurrentDate()
    • getVolumeEnforcementModeName

      public static String getVolumeEnforcementModeName(boolean enforcePolicies, boolean enforceAces, boolean auditOnlyPolicyCheck)
    • printVolumeAccessControl

      public static String printVolumeAccessControl(int volId, com.mapr.fs.proto.Common.VolumeAces va)
    • getMapRTimeInSeconds

      public static int getMapRTimeInSeconds(long millis)
    • currentMillisFromMapRTime

      public static long currentMillisFromMapRTime(int seconds)
    • getSHA256

      public static byte[] getSHA256(String input)
    • printableKey

      public static String printableKey(byte[] bytes)
    • getNodeProperties

      public static com.mapr.fs.proto.Common.NodeProperties getNodeProperties()
    • getParentInTopology

      public static String getParentInTopology(String topo)
    • updatesTruststore

      public static void updatesTruststore(String inCertificate, KeyStore truststore, String alias) throws FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      FileNotFoundException
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException
    • delete_ssocert_in_truststore

      public static void delete_ssocert_in_truststore(KeyStore truststore, String alias) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException
    • AddToTruststore

      public static boolean AddToTruststore(Map<String,String> clusterCert, String truststorePath, boolean alreadyExist)
    • AddToTruststore

      public static boolean AddToTruststore(String certificate, String cluster, String truststorePath, boolean alreadyExist) throws FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      FileNotFoundException
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException
    • moveTrustStore

      public static boolean moveTrustStore(String srcTrustStorePath, String dstTrustStorePath) throws FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      FileNotFoundException
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException
    • removeFromTruststore

      public static void removeFromTruststore(String cluster, String truststorePath) throws FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      FileNotFoundException
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException
    • existInTruststore

      public static boolean existInTruststore(String cluster, String truststorePath) throws FileNotFoundException, IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException
      Throws:
      FileNotFoundException
      IOException
      NoSuchAlgorithmException
      CertificateException
      KeyStoreException