hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [48/49] hbase-site git commit: Published site at .
Date Sun, 24 Sep 2017 15:14:14 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e6bd0774/apidocs/src-html/org/apache/hadoop/hbase/quotas/QuotaSettings.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/quotas/QuotaSettings.html b/apidocs/src-html/org/apache/hadoop/hbase/quotas/QuotaSettings.html
index bddf8ca..d171636 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/quotas/QuotaSettings.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/quotas/QuotaSettings.html
@@ -25,111 +25,194 @@
 <span class="sourceLineNo">017</span> */<a name="line.17"></a>
 <span class="sourceLineNo">018</span>package org.apache.hadoop.hbase.quotas;<a
name="line.18"></a>
 <span class="sourceLineNo">019</span><a name="line.19"></a>
-<span class="sourceLineNo">020</span>import java.util.concurrent.TimeUnit;<a
name="line.20"></a>
-<span class="sourceLineNo">021</span><a name="line.21"></a>
-<span class="sourceLineNo">022</span>import org.apache.hadoop.hbase.TableName;<a
name="line.22"></a>
-<span class="sourceLineNo">023</span>import org.apache.yetus.audience.InterfaceAudience;<a
name="line.23"></a>
-<span class="sourceLineNo">024</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a
name="line.24"></a>
-<span class="sourceLineNo">025</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaRequest;<a
name="line.25"></a>
+<span class="sourceLineNo">020</span>import java.io.IOException;<a name="line.20"></a>
+<span class="sourceLineNo">021</span>import java.util.Objects;<a name="line.21"></a>
+<span class="sourceLineNo">022</span>import java.util.concurrent.TimeUnit;<a
name="line.22"></a>
+<span class="sourceLineNo">023</span><a name="line.23"></a>
+<span class="sourceLineNo">024</span>import org.apache.hadoop.hbase.TableName;<a
name="line.24"></a>
+<span class="sourceLineNo">025</span>import org.apache.yetus.audience.InterfaceAudience;<a
name="line.25"></a>
 <span class="sourceLineNo">026</span><a name="line.26"></a>
-<span class="sourceLineNo">027</span>@InterfaceAudience.Public<a name="line.27"></a>
-<span class="sourceLineNo">028</span>public abstract class QuotaSettings {<a
name="line.28"></a>
-<span class="sourceLineNo">029</span>  private final String userName;<a name="line.29"></a>
-<span class="sourceLineNo">030</span>  private final String namespace;<a name="line.30"></a>
-<span class="sourceLineNo">031</span>  private final TableName tableName;<a
name="line.31"></a>
-<span class="sourceLineNo">032</span><a name="line.32"></a>
-<span class="sourceLineNo">033</span>  protected QuotaSettings(final String userName,
final TableName tableName,<a name="line.33"></a>
-<span class="sourceLineNo">034</span>      final String namespace) {<a name="line.34"></a>
-<span class="sourceLineNo">035</span>    this.userName = userName;<a name="line.35"></a>
-<span class="sourceLineNo">036</span>    this.namespace = namespace;<a name="line.36"></a>
-<span class="sourceLineNo">037</span>    this.tableName = tableName;<a name="line.37"></a>
-<span class="sourceLineNo">038</span>  }<a name="line.38"></a>
-<span class="sourceLineNo">039</span><a name="line.39"></a>
-<span class="sourceLineNo">040</span>  public abstract QuotaType getQuotaType();<a
name="line.40"></a>
-<span class="sourceLineNo">041</span><a name="line.41"></a>
-<span class="sourceLineNo">042</span>  public String getUserName() {<a name="line.42"></a>
-<span class="sourceLineNo">043</span>    return userName;<a name="line.43"></a>
-<span class="sourceLineNo">044</span>  }<a name="line.44"></a>
-<span class="sourceLineNo">045</span><a name="line.45"></a>
-<span class="sourceLineNo">046</span>  public TableName getTableName() {<a
name="line.46"></a>
-<span class="sourceLineNo">047</span>    return tableName;<a name="line.47"></a>
-<span class="sourceLineNo">048</span>  }<a name="line.48"></a>
-<span class="sourceLineNo">049</span><a name="line.49"></a>
-<span class="sourceLineNo">050</span>  public String getNamespace() {<a name="line.50"></a>
-<span class="sourceLineNo">051</span>    return namespace;<a name="line.51"></a>
-<span class="sourceLineNo">052</span>  }<a name="line.52"></a>
-<span class="sourceLineNo">053</span><a name="line.53"></a>
-<span class="sourceLineNo">054</span>  /**<a name="line.54"></a>
-<span class="sourceLineNo">055</span>   * Convert a QuotaSettings to a protocol
buffer SetQuotaRequest.<a name="line.55"></a>
-<span class="sourceLineNo">056</span>   * This is used internally by the Admin
client to serialize the quota settings<a name="line.56"></a>
-<span class="sourceLineNo">057</span>   * and send them to the master.<a name="line.57"></a>
-<span class="sourceLineNo">058</span>   */<a name="line.58"></a>
-<span class="sourceLineNo">059</span>  @InterfaceAudience.Private<a name="line.59"></a>
-<span class="sourceLineNo">060</span>  public static SetQuotaRequest buildSetQuotaRequestProto(final
QuotaSettings settings) {<a name="line.60"></a>
-<span class="sourceLineNo">061</span>    SetQuotaRequest.Builder builder = SetQuotaRequest.newBuilder();<a
name="line.61"></a>
-<span class="sourceLineNo">062</span>    if (settings.getUserName() != null)
{<a name="line.62"></a>
-<span class="sourceLineNo">063</span>      builder.setUserName(settings.getUserName());<a
name="line.63"></a>
-<span class="sourceLineNo">064</span>    }<a name="line.64"></a>
-<span class="sourceLineNo">065</span>    if (settings.getTableName() != null)
{<a name="line.65"></a>
-<span class="sourceLineNo">066</span>      builder.setTableName(ProtobufUtil.toProtoTableName(settings.getTableName()));<a
name="line.66"></a>
-<span class="sourceLineNo">067</span>    }<a name="line.67"></a>
-<span class="sourceLineNo">068</span>    if (settings.getNamespace() != null)
{<a name="line.68"></a>
-<span class="sourceLineNo">069</span>      builder.setNamespace(settings.getNamespace());<a
name="line.69"></a>
-<span class="sourceLineNo">070</span>    }<a name="line.70"></a>
-<span class="sourceLineNo">071</span>    settings.setupSetQuotaRequest(builder);<a
name="line.71"></a>
-<span class="sourceLineNo">072</span>    return builder.build();<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  }<a name="line.73"></a>
-<span class="sourceLineNo">074</span><a name="line.74"></a>
-<span class="sourceLineNo">075</span>  /**<a name="line.75"></a>
-<span class="sourceLineNo">076</span>   * Called by toSetQuotaRequestProto()<a
name="line.76"></a>
-<span class="sourceLineNo">077</span>   * the subclass should implement this
method to set the specific SetQuotaRequest<a name="line.77"></a>
-<span class="sourceLineNo">078</span>   * properties.<a name="line.78"></a>
-<span class="sourceLineNo">079</span>   */<a name="line.79"></a>
-<span class="sourceLineNo">080</span>  @InterfaceAudience.Private<a name="line.80"></a>
-<span class="sourceLineNo">081</span>  protected abstract void setupSetQuotaRequest(SetQuotaRequest.Builder
builder);<a name="line.81"></a>
-<span class="sourceLineNo">082</span><a name="line.82"></a>
-<span class="sourceLineNo">083</span>  protected String ownerToString() {<a
name="line.83"></a>
-<span class="sourceLineNo">084</span>    StringBuilder builder = new StringBuilder();<a
name="line.84"></a>
-<span class="sourceLineNo">085</span>    if (userName != null) {<a name="line.85"></a>
-<span class="sourceLineNo">086</span>      builder.append("USER =&gt; '");<a
name="line.86"></a>
-<span class="sourceLineNo">087</span>      builder.append(userName);<a name="line.87"></a>
-<span class="sourceLineNo">088</span>      builder.append("', ");<a name="line.88"></a>
-<span class="sourceLineNo">089</span>    }<a name="line.89"></a>
-<span class="sourceLineNo">090</span>    if (tableName != null) {<a name="line.90"></a>
-<span class="sourceLineNo">091</span>      builder.append("TABLE =&gt; '");<a
name="line.91"></a>
-<span class="sourceLineNo">092</span>      builder.append(tableName.toString());<a
name="line.92"></a>
-<span class="sourceLineNo">093</span>      builder.append("', ");<a name="line.93"></a>
-<span class="sourceLineNo">094</span>    }<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    if (namespace != null) {<a name="line.95"></a>
-<span class="sourceLineNo">096</span>      builder.append("NAMESPACE =&gt;
'");<a name="line.96"></a>
-<span class="sourceLineNo">097</span>      builder.append(namespace);<a name="line.97"></a>
-<span class="sourceLineNo">098</span>      builder.append("', ");<a name="line.98"></a>
-<span class="sourceLineNo">099</span>    }<a name="line.99"></a>
-<span class="sourceLineNo">100</span>    return builder.toString();<a name="line.100"></a>
-<span class="sourceLineNo">101</span>  }<a name="line.101"></a>
-<span class="sourceLineNo">102</span><a name="line.102"></a>
-<span class="sourceLineNo">103</span>  protected static String sizeToString(final
long size) {<a name="line.103"></a>
-<span class="sourceLineNo">104</span>    if (size &gt;= (1L &lt;&lt;
50)) return String.format("%dP", size / (1L &lt;&lt; 50));<a name="line.104"></a>
-<span class="sourceLineNo">105</span>    if (size &gt;= (1L &lt;&lt;
40)) return String.format("%dT", size / (1L &lt;&lt; 40));<a name="line.105"></a>
-<span class="sourceLineNo">106</span>    if (size &gt;= (1L &lt;&lt;
30)) return String.format("%dG", size / (1L &lt;&lt; 30));<a name="line.106"></a>
-<span class="sourceLineNo">107</span>    if (size &gt;= (1L &lt;&lt;
20)) return String.format("%dM", size / (1L &lt;&lt; 20));<a name="line.107"></a>
-<span class="sourceLineNo">108</span>    if (size &gt;= (1L &lt;&lt;
10)) return String.format("%dK", size / (1L &lt;&lt; 10));<a name="line.108"></a>
-<span class="sourceLineNo">109</span>    return String.format("%dB", size);<a
name="line.109"></a>
-<span class="sourceLineNo">110</span>  }<a name="line.110"></a>
-<span class="sourceLineNo">111</span><a name="line.111"></a>
-<span class="sourceLineNo">112</span>  protected static String timeToString(final
TimeUnit timeUnit) {<a name="line.112"></a>
-<span class="sourceLineNo">113</span>    switch (timeUnit) {<a name="line.113"></a>
-<span class="sourceLineNo">114</span>      case NANOSECONDS:  return "nsec";<a
name="line.114"></a>
-<span class="sourceLineNo">115</span>      case MICROSECONDS: return "usec";<a
name="line.115"></a>
-<span class="sourceLineNo">116</span>      case MILLISECONDS: return "msec";<a
name="line.116"></a>
-<span class="sourceLineNo">117</span>      case SECONDS:      return "sec";<a
name="line.117"></a>
-<span class="sourceLineNo">118</span>      case MINUTES:      return "min";<a
name="line.118"></a>
-<span class="sourceLineNo">119</span>      case HOURS:        return "hour";<a
name="line.119"></a>
-<span class="sourceLineNo">120</span>      case DAYS:         return "day";<a
name="line.120"></a>
-<span class="sourceLineNo">121</span>    }<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    throw new RuntimeException("Invalid
TimeUnit " + timeUnit);<a name="line.122"></a>
-<span class="sourceLineNo">123</span>  }<a name="line.123"></a>
-<span class="sourceLineNo">124</span>}<a name="line.124"></a>
+<span class="sourceLineNo">027</span>import org.apache.hadoop.hbase.shaded.com.google.protobuf.TextFormat;<a
name="line.27"></a>
+<span class="sourceLineNo">028</span>import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;<a
name="line.28"></a>
+<span class="sourceLineNo">029</span>import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.SetQuotaRequest;<a
name="line.29"></a>
+<span class="sourceLineNo">030</span>import org.apache.hadoop.hbase.quotas.QuotaSettingsFactory.QuotaGlobalsSettingsBypass;<a
name="line.30"></a>
+<span class="sourceLineNo">031</span><a name="line.31"></a>
+<span class="sourceLineNo">032</span>@InterfaceAudience.Public<a name="line.32"></a>
+<span class="sourceLineNo">033</span>public abstract class QuotaSettings {<a
name="line.33"></a>
+<span class="sourceLineNo">034</span>  private final String userName;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>  private final String namespace;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>  private final TableName tableName;<a
name="line.36"></a>
+<span class="sourceLineNo">037</span><a name="line.37"></a>
+<span class="sourceLineNo">038</span>  protected QuotaSettings(final String userName,
final TableName tableName,<a name="line.38"></a>
+<span class="sourceLineNo">039</span>      final String namespace) {<a name="line.39"></a>
+<span class="sourceLineNo">040</span>    this.userName = userName;<a name="line.40"></a>
+<span class="sourceLineNo">041</span>    this.namespace = namespace;<a name="line.41"></a>
+<span class="sourceLineNo">042</span>    this.tableName = tableName;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>  }<a name="line.43"></a>
+<span class="sourceLineNo">044</span><a name="line.44"></a>
+<span class="sourceLineNo">045</span>  public abstract QuotaType getQuotaType();<a
name="line.45"></a>
+<span class="sourceLineNo">046</span><a name="line.46"></a>
+<span class="sourceLineNo">047</span>  public String getUserName() {<a name="line.47"></a>
+<span class="sourceLineNo">048</span>    return userName;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>  }<a name="line.49"></a>
+<span class="sourceLineNo">050</span><a name="line.50"></a>
+<span class="sourceLineNo">051</span>  public TableName getTableName() {<a
name="line.51"></a>
+<span class="sourceLineNo">052</span>    return tableName;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>  }<a name="line.53"></a>
+<span class="sourceLineNo">054</span><a name="line.54"></a>
+<span class="sourceLineNo">055</span>  public String getNamespace() {<a name="line.55"></a>
+<span class="sourceLineNo">056</span>    return namespace;<a name="line.56"></a>
+<span class="sourceLineNo">057</span>  }<a name="line.57"></a>
+<span class="sourceLineNo">058</span><a name="line.58"></a>
+<span class="sourceLineNo">059</span>  /**<a name="line.59"></a>
+<span class="sourceLineNo">060</span>   * Converts the protocol buffer request
into a QuotaSetting POJO. Arbitrarily<a name="line.60"></a>
+<span class="sourceLineNo">061</span>   * enforces that the request only contain
one "limit", despite the message<a name="line.61"></a>
+<span class="sourceLineNo">062</span>   * allowing multiple. The public API does
not allow such use of the message.<a name="line.62"></a>
+<span class="sourceLineNo">063</span>   *<a name="line.63"></a>
+<span class="sourceLineNo">064</span>   * @param request The protocol buffer
request.<a name="line.64"></a>
+<span class="sourceLineNo">065</span>   * @return A {@link QuotaSettings} POJO.<a
name="line.65"></a>
+<span class="sourceLineNo">066</span>   */<a name="line.66"></a>
+<span class="sourceLineNo">067</span>  @InterfaceAudience.Private<a name="line.67"></a>
+<span class="sourceLineNo">068</span>  public static QuotaSettings buildFromProto(SetQuotaRequest
request) {<a name="line.68"></a>
+<span class="sourceLineNo">069</span>    String username = null;<a name="line.69"></a>
+<span class="sourceLineNo">070</span>    if (request.hasUserName()) {<a name="line.70"></a>
+<span class="sourceLineNo">071</span>      username = request.getUserName();<a
name="line.71"></a>
+<span class="sourceLineNo">072</span>    }<a name="line.72"></a>
+<span class="sourceLineNo">073</span>    TableName tableName = null;<a name="line.73"></a>
+<span class="sourceLineNo">074</span>    if (request.hasTableName()) {<a name="line.74"></a>
+<span class="sourceLineNo">075</span>      tableName = ProtobufUtil.toTableName(request.getTableName());<a
name="line.75"></a>
+<span class="sourceLineNo">076</span>    }<a name="line.76"></a>
+<span class="sourceLineNo">077</span>    String namespace = null;<a name="line.77"></a>
+<span class="sourceLineNo">078</span>    if (request.hasNamespace()) {<a name="line.78"></a>
+<span class="sourceLineNo">079</span>      namespace = request.getNamespace();<a
name="line.79"></a>
+<span class="sourceLineNo">080</span>    }<a name="line.80"></a>
+<span class="sourceLineNo">081</span>    if (request.hasBypassGlobals()) {<a
name="line.81"></a>
+<span class="sourceLineNo">082</span>      // Make sure we don't have either
of the two below limits also included<a name="line.82"></a>
+<span class="sourceLineNo">083</span>      if (request.hasSpaceLimit() || request.hasThrottle())
{<a name="line.83"></a>
+<span class="sourceLineNo">084</span>        throw new IllegalStateException(<a
name="line.84"></a>
+<span class="sourceLineNo">085</span>            "SetQuotaRequest has multiple
limits: " + TextFormat.shortDebugString(request));<a name="line.85"></a>
+<span class="sourceLineNo">086</span>      }<a name="line.86"></a>
+<span class="sourceLineNo">087</span>      return new QuotaGlobalsSettingsBypass(<a
name="line.87"></a>
+<span class="sourceLineNo">088</span>          username, tableName, namespace,
request.getBypassGlobals());<a name="line.88"></a>
+<span class="sourceLineNo">089</span>    } else if (request.hasSpaceLimit())
{<a name="line.89"></a>
+<span class="sourceLineNo">090</span>      // Make sure we don't have the below
limit as well<a name="line.90"></a>
+<span class="sourceLineNo">091</span>      if (request.hasThrottle()) {<a
name="line.91"></a>
+<span class="sourceLineNo">092</span>        throw new IllegalStateException(<a
name="line.92"></a>
+<span class="sourceLineNo">093</span>            "SetQuotaRequests has multiple
limits: " + TextFormat.shortDebugString(request));<a name="line.93"></a>
+<span class="sourceLineNo">094</span>      }<a name="line.94"></a>
+<span class="sourceLineNo">095</span>      // Sanity check on the pb received.<a
name="line.95"></a>
+<span class="sourceLineNo">096</span>      if (!request.getSpaceLimit().hasQuota())
{<a name="line.96"></a>
+<span class="sourceLineNo">097</span>        throw new IllegalArgumentException(<a
name="line.97"></a>
+<span class="sourceLineNo">098</span>            "SpaceLimitRequest is missing
the expected SpaceQuota.");<a name="line.98"></a>
+<span class="sourceLineNo">099</span>      }<a name="line.99"></a>
+<span class="sourceLineNo">100</span>      return QuotaSettingsFactory.fromSpace(<a
name="line.100"></a>
+<span class="sourceLineNo">101</span>          tableName, namespace, request.getSpaceLimit().getQuota());<a
name="line.101"></a>
+<span class="sourceLineNo">102</span>    } else if (request.hasThrottle()) {<a
name="line.102"></a>
+<span class="sourceLineNo">103</span>      return new ThrottleSettings(username,
tableName, namespace, request.getThrottle());<a name="line.103"></a>
+<span class="sourceLineNo">104</span>    } else {<a name="line.104"></a>
+<span class="sourceLineNo">105</span>      throw new IllegalStateException("Unhandled
SetRequestRequest state");<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    }<a name="line.106"></a>
+<span class="sourceLineNo">107</span>  }<a name="line.107"></a>
+<span class="sourceLineNo">108</span><a name="line.108"></a>
+<span class="sourceLineNo">109</span>  /**<a name="line.109"></a>
+<span class="sourceLineNo">110</span>   * Convert a QuotaSettings to a protocol
buffer SetQuotaRequest.<a name="line.110"></a>
+<span class="sourceLineNo">111</span>   * This is used internally by the Admin
client to serialize the quota settings<a name="line.111"></a>
+<span class="sourceLineNo">112</span>   * and send them to the master.<a name="line.112"></a>
+<span class="sourceLineNo">113</span>   */<a name="line.113"></a>
+<span class="sourceLineNo">114</span>  @InterfaceAudience.Private<a name="line.114"></a>
+<span class="sourceLineNo">115</span>  public static SetQuotaRequest buildSetQuotaRequestProto(final
QuotaSettings settings) {<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    SetQuotaRequest.Builder builder = SetQuotaRequest.newBuilder();<a
name="line.116"></a>
+<span class="sourceLineNo">117</span>    if (settings.getUserName() != null)
{<a name="line.117"></a>
+<span class="sourceLineNo">118</span>      builder.setUserName(settings.getUserName());<a
name="line.118"></a>
+<span class="sourceLineNo">119</span>    }<a name="line.119"></a>
+<span class="sourceLineNo">120</span>    if (settings.getTableName() != null)
{<a name="line.120"></a>
+<span class="sourceLineNo">121</span>      builder.setTableName(ProtobufUtil.toProtoTableName(settings.getTableName()));<a
name="line.121"></a>
+<span class="sourceLineNo">122</span>    }<a name="line.122"></a>
+<span class="sourceLineNo">123</span>    if (settings.getNamespace() != null)
{<a name="line.123"></a>
+<span class="sourceLineNo">124</span>      builder.setNamespace(settings.getNamespace());<a
name="line.124"></a>
+<span class="sourceLineNo">125</span>    }<a name="line.125"></a>
+<span class="sourceLineNo">126</span>    settings.setupSetQuotaRequest(builder);<a
name="line.126"></a>
+<span class="sourceLineNo">127</span>    return builder.build();<a name="line.127"></a>
+<span class="sourceLineNo">128</span>  }<a name="line.128"></a>
+<span class="sourceLineNo">129</span><a name="line.129"></a>
+<span class="sourceLineNo">130</span>  /**<a name="line.130"></a>
+<span class="sourceLineNo">131</span>   * Called by toSetQuotaRequestProto()<a
name="line.131"></a>
+<span class="sourceLineNo">132</span>   * the subclass should implement this
method to set the specific SetQuotaRequest<a name="line.132"></a>
+<span class="sourceLineNo">133</span>   * properties.<a name="line.133"></a>
+<span class="sourceLineNo">134</span>   */<a name="line.134"></a>
+<span class="sourceLineNo">135</span>  @InterfaceAudience.Private<a name="line.135"></a>
+<span class="sourceLineNo">136</span>  protected abstract void setupSetQuotaRequest(SetQuotaRequest.Builder
builder);<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>  protected String ownerToString() {<a
name="line.138"></a>
+<span class="sourceLineNo">139</span>    StringBuilder builder = new StringBuilder();<a
name="line.139"></a>
+<span class="sourceLineNo">140</span>    if (userName != null) {<a name="line.140"></a>
+<span class="sourceLineNo">141</span>      builder.append("USER =&gt; '");<a
name="line.141"></a>
+<span class="sourceLineNo">142</span>      builder.append(userName);<a name="line.142"></a>
+<span class="sourceLineNo">143</span>      builder.append("', ");<a name="line.143"></a>
+<span class="sourceLineNo">144</span>    }<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    if (tableName != null) {<a name="line.145"></a>
+<span class="sourceLineNo">146</span>      builder.append("TABLE =&gt; '");<a
name="line.146"></a>
+<span class="sourceLineNo">147</span>      builder.append(tableName.toString());<a
name="line.147"></a>
+<span class="sourceLineNo">148</span>      builder.append("', ");<a name="line.148"></a>
+<span class="sourceLineNo">149</span>    }<a name="line.149"></a>
+<span class="sourceLineNo">150</span>    if (namespace != null) {<a name="line.150"></a>
+<span class="sourceLineNo">151</span>      builder.append("NAMESPACE =&gt;
'");<a name="line.151"></a>
+<span class="sourceLineNo">152</span>      builder.append(namespace);<a name="line.152"></a>
+<span class="sourceLineNo">153</span>      builder.append("', ");<a name="line.153"></a>
+<span class="sourceLineNo">154</span>    }<a name="line.154"></a>
+<span class="sourceLineNo">155</span>    return builder.toString();<a name="line.155"></a>
+<span class="sourceLineNo">156</span>  }<a name="line.156"></a>
+<span class="sourceLineNo">157</span><a name="line.157"></a>
+<span class="sourceLineNo">158</span>  protected static String sizeToString(final
long size) {<a name="line.158"></a>
+<span class="sourceLineNo">159</span>    if (size &gt;= (1L &lt;&lt;
50)) return String.format("%dP", size / (1L &lt;&lt; 50));<a name="line.159"></a>
+<span class="sourceLineNo">160</span>    if (size &gt;= (1L &lt;&lt;
40)) return String.format("%dT", size / (1L &lt;&lt; 40));<a name="line.160"></a>
+<span class="sourceLineNo">161</span>    if (size &gt;= (1L &lt;&lt;
30)) return String.format("%dG", size / (1L &lt;&lt; 30));<a name="line.161"></a>
+<span class="sourceLineNo">162</span>    if (size &gt;= (1L &lt;&lt;
20)) return String.format("%dM", size / (1L &lt;&lt; 20));<a name="line.162"></a>
+<span class="sourceLineNo">163</span>    if (size &gt;= (1L &lt;&lt;
10)) return String.format("%dK", size / (1L &lt;&lt; 10));<a name="line.163"></a>
+<span class="sourceLineNo">164</span>    return String.format("%dB", size);<a
name="line.164"></a>
+<span class="sourceLineNo">165</span>  }<a name="line.165"></a>
+<span class="sourceLineNo">166</span><a name="line.166"></a>
+<span class="sourceLineNo">167</span>  protected static String timeToString(final
TimeUnit timeUnit) {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    switch (timeUnit) {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>      case NANOSECONDS:  return "nsec";<a
name="line.169"></a>
+<span class="sourceLineNo">170</span>      case MICROSECONDS: return "usec";<a
name="line.170"></a>
+<span class="sourceLineNo">171</span>      case MILLISECONDS: return "msec";<a
name="line.171"></a>
+<span class="sourceLineNo">172</span>      case SECONDS:      return "sec";<a
name="line.172"></a>
+<span class="sourceLineNo">173</span>      case MINUTES:      return "min";<a
name="line.173"></a>
+<span class="sourceLineNo">174</span>      case HOURS:        return "hour";<a
name="line.174"></a>
+<span class="sourceLineNo">175</span>      case DAYS:         return "day";<a
name="line.175"></a>
+<span class="sourceLineNo">176</span>    }<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    throw new RuntimeException("Invalid
TimeUnit " + timeUnit);<a name="line.177"></a>
+<span class="sourceLineNo">178</span>  }<a name="line.178"></a>
+<span class="sourceLineNo">179</span><a name="line.179"></a>
+<span class="sourceLineNo">180</span>  /**<a name="line.180"></a>
+<span class="sourceLineNo">181</span>   * Merges the provided settings with {@code
this} and returns a new settings<a name="line.181"></a>
+<span class="sourceLineNo">182</span>   * object to the caller if the merged
settings differ from the original.<a name="line.182"></a>
+<span class="sourceLineNo">183</span>   *<a name="line.183"></a>
+<span class="sourceLineNo">184</span>   * @param newSettings The new settings
to merge in.<a name="line.184"></a>
+<span class="sourceLineNo">185</span>   * @return The merged {@link QuotaSettings}
object or null if the quota should be deleted.<a name="line.185"></a>
+<span class="sourceLineNo">186</span>   */<a name="line.186"></a>
+<span class="sourceLineNo">187</span>  abstract QuotaSettings merge(QuotaSettings
newSettings) throws IOException;<a name="line.187"></a>
+<span class="sourceLineNo">188</span><a name="line.188"></a>
+<span class="sourceLineNo">189</span>  /**<a name="line.189"></a>
+<span class="sourceLineNo">190</span>   * Validates that settings being merged
into {@code this} is targeting the same "subject", e.g.<a name="line.190"></a>
+<span class="sourceLineNo">191</span>   * user, table, namespace.<a name="line.191"></a>
+<span class="sourceLineNo">192</span>   *<a name="line.192"></a>
+<span class="sourceLineNo">193</span>   * @param mergee The quota settings to
be merged into {@code this}.<a name="line.193"></a>
+<span class="sourceLineNo">194</span>   * @throws IllegalArgumentException if
the subjects are not equal.<a name="line.194"></a>
+<span class="sourceLineNo">195</span>   */<a name="line.195"></a>
+<span class="sourceLineNo">196</span>  void validateQuotaTarget(QuotaSettings
mergee) {<a name="line.196"></a>
+<span class="sourceLineNo">197</span>    if (!Objects.equals(getUserName(), mergee.getUserName()))
{<a name="line.197"></a>
+<span class="sourceLineNo">198</span>      throw new IllegalArgumentException("Mismatched
user names on settings to merge");<a name="line.198"></a>
+<span class="sourceLineNo">199</span>    }<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    if (!Objects.equals(getTableName(),
mergee.getTableName())) {<a name="line.200"></a>
+<span class="sourceLineNo">201</span>      throw new IllegalArgumentException("Mismatched
table names on settings to merge");<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    }<a name="line.202"></a>
+<span class="sourceLineNo">203</span>    if (!Objects.equals(getNamespace(),
mergee.getNamespace())) {<a name="line.203"></a>
+<span class="sourceLineNo">204</span>      throw new IllegalArgumentException("Mismatched
namespace on settings to merge");<a name="line.204"></a>
+<span class="sourceLineNo">205</span>    }<a name="line.205"></a>
+<span class="sourceLineNo">206</span>  }<a name="line.206"></a>
+<span class="sourceLineNo">207</span>}<a name="line.207"></a>
 
 
 


Mime
View raw message