|
@@ -15,10 +15,13 @@
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
-package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline;
|
|
|
+package org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.query;
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
+import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.PhoenixHBaseAccessor;
|
|
|
+import org.apache.hadoop.yarn.server.applicationhistoryservice.metrics.timeline.Precision;
|
|
|
+
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
@@ -33,7 +36,8 @@ import java.util.concurrent.TimeUnit;
|
|
|
*/
|
|
|
public class PhoenixTransactSQL {
|
|
|
|
|
|
- static final Log LOG = LogFactory.getLog(PhoenixTransactSQL.class);
|
|
|
+ public static final Log LOG = LogFactory.getLog(PhoenixTransactSQL.class);
|
|
|
+
|
|
|
/**
|
|
|
* Create table to store individual metric records.
|
|
|
*/
|
|
@@ -566,405 +570,4 @@ public class PhoenixTransactSQL {
|
|
|
|
|
|
return stmt;
|
|
|
}
|
|
|
-
|
|
|
- static interface Condition {
|
|
|
-
|
|
|
- boolean isEmpty();
|
|
|
-
|
|
|
- List<String> getMetricNames();
|
|
|
- boolean isPointInTime();
|
|
|
- boolean isGrouped();
|
|
|
- void setStatement(String statement);
|
|
|
- String getHostname();
|
|
|
- Precision getPrecision();
|
|
|
- void setPrecision(Precision precision);
|
|
|
- String getAppId();
|
|
|
- String getInstanceId();
|
|
|
- StringBuilder getConditionClause();
|
|
|
- String getOrderByClause(boolean asc);
|
|
|
- String getStatement();
|
|
|
- Long getStartTime();
|
|
|
- Long getEndTime();
|
|
|
- Integer getLimit();
|
|
|
- Integer getFetchSize();
|
|
|
- void setFetchSize(Integer fetchSize);
|
|
|
- void addOrderByColumn(String column);
|
|
|
- void setNoLimit();
|
|
|
- }
|
|
|
-
|
|
|
- static class DefaultCondition implements Condition {
|
|
|
- List<String> metricNames;
|
|
|
- String hostname;
|
|
|
- String appId;
|
|
|
- String instanceId;
|
|
|
- Long startTime;
|
|
|
- Long endTime;
|
|
|
- Precision precision;
|
|
|
- Integer limit;
|
|
|
- boolean grouped;
|
|
|
- boolean noLimit = false;
|
|
|
- Integer fetchSize;
|
|
|
- String statement;
|
|
|
- Set<String> orderByColumns = new LinkedHashSet<String>();
|
|
|
-
|
|
|
- DefaultCondition(List<String> metricNames, String hostname, String appId,
|
|
|
- String instanceId, Long startTime, Long endTime, Precision precision,
|
|
|
- Integer limit, boolean grouped) {
|
|
|
- this.metricNames = metricNames;
|
|
|
- this.hostname = hostname;
|
|
|
- this.appId = appId;
|
|
|
- this.instanceId = instanceId;
|
|
|
- this.startTime = startTime;
|
|
|
- this.endTime = endTime;
|
|
|
- this.precision = precision;
|
|
|
- this.limit = limit;
|
|
|
- this.grouped = grouped;
|
|
|
- }
|
|
|
-
|
|
|
- public String getStatement() {
|
|
|
- return statement;
|
|
|
- }
|
|
|
-
|
|
|
- public void setStatement(String statement) {
|
|
|
- this.statement = statement;
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getMetricNames() {
|
|
|
- return metricNames == null || metricNames.isEmpty() ? null : metricNames;
|
|
|
- }
|
|
|
-
|
|
|
- public StringBuilder getConditionClause() {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- boolean appendConjunction = false;
|
|
|
- StringBuilder metricsLike = new StringBuilder();
|
|
|
- StringBuilder metricsIn = new StringBuilder();
|
|
|
-
|
|
|
- if (getMetricNames() != null) {
|
|
|
- for (String name : getMetricNames()) {
|
|
|
- if (name.contains("%")) {
|
|
|
- if (metricsLike.length() > 1) {
|
|
|
- metricsLike.append(" OR ");
|
|
|
- }
|
|
|
- metricsLike.append("METRIC_NAME LIKE ?");
|
|
|
- } else {
|
|
|
- if (metricsIn.length() > 0) {
|
|
|
- metricsIn.append(", ");
|
|
|
- }
|
|
|
- metricsIn.append("?");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (metricsIn.length()>0) {
|
|
|
- sb.append("(METRIC_NAME IN (");
|
|
|
- sb.append(metricsIn);
|
|
|
- sb.append(")");
|
|
|
- appendConjunction = true;
|
|
|
- }
|
|
|
-
|
|
|
- if (metricsLike.length() > 0) {
|
|
|
- if (appendConjunction) {
|
|
|
- sb.append(" OR ");
|
|
|
- } else {
|
|
|
- sb.append("(");
|
|
|
- }
|
|
|
- sb.append(metricsLike);
|
|
|
- appendConjunction = true;
|
|
|
- }
|
|
|
-
|
|
|
- if (appendConjunction) {
|
|
|
- sb.append(")");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- appendConjunction = append(sb, appendConjunction, getHostname(), " HOSTNAME = ?");
|
|
|
- appendConjunction = append(sb, appendConjunction, getAppId(), " APP_ID = ?");
|
|
|
- appendConjunction = append(sb, appendConjunction, getInstanceId(), " INSTANCE_ID = ?");
|
|
|
- appendConjunction = append(sb, appendConjunction, getStartTime(), " SERVER_TIME >= ?");
|
|
|
- append(sb, appendConjunction, getEndTime(), " SERVER_TIME < ?");
|
|
|
-
|
|
|
- return sb;
|
|
|
- }
|
|
|
-
|
|
|
- protected static boolean append(StringBuilder sb,
|
|
|
- boolean appendConjunction,
|
|
|
- Object value, String str) {
|
|
|
- if (value != null) {
|
|
|
- if (appendConjunction) {
|
|
|
- sb.append(" AND");
|
|
|
- }
|
|
|
-
|
|
|
- sb.append(str);
|
|
|
- appendConjunction = true;
|
|
|
- }
|
|
|
- return appendConjunction;
|
|
|
- }
|
|
|
-
|
|
|
- public String getHostname() {
|
|
|
- return hostname == null || hostname.isEmpty() ? null : hostname;
|
|
|
- }
|
|
|
-
|
|
|
- public Precision getPrecision() {
|
|
|
- return precision;
|
|
|
- }
|
|
|
-
|
|
|
- public void setPrecision(Precision precision) {
|
|
|
- this.precision = precision;
|
|
|
- }
|
|
|
-
|
|
|
- public String getAppId() {
|
|
|
- if (appId != null && !appId.isEmpty()) {
|
|
|
- if (!(appId.equals("HOST") || appId.equals("FLUME_HANDLER")) ) {
|
|
|
- return appId.toLowerCase();
|
|
|
- } else {
|
|
|
- return appId;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public String getInstanceId() {
|
|
|
- return instanceId == null || instanceId.isEmpty() ? null : instanceId;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Convert to millis.
|
|
|
- */
|
|
|
- public Long getStartTime() {
|
|
|
- if (startTime == null) {
|
|
|
- return null;
|
|
|
- } else if (startTime < 9999999999l) {
|
|
|
- return startTime * 1000;
|
|
|
- } else {
|
|
|
- return startTime;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Long getEndTime() {
|
|
|
- if (endTime == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- if (endTime < 9999999999l) {
|
|
|
- return endTime * 1000;
|
|
|
- } else {
|
|
|
- return endTime;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void setNoLimit() {
|
|
|
- this.noLimit = true;
|
|
|
- }
|
|
|
-
|
|
|
- public Integer getLimit() {
|
|
|
- if (noLimit) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return limit == null ? PhoenixHBaseAccessor.RESULTSET_LIMIT : limit;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isGrouped() {
|
|
|
- return grouped;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isPointInTime() {
|
|
|
- return getStartTime() == null && getEndTime() == null;
|
|
|
- }
|
|
|
-
|
|
|
- public boolean isEmpty() {
|
|
|
- return (metricNames == null || metricNames.isEmpty())
|
|
|
- && (hostname == null || hostname.isEmpty())
|
|
|
- && (appId == null || appId.isEmpty())
|
|
|
- && (instanceId == null || instanceId.isEmpty())
|
|
|
- && startTime == null
|
|
|
- && endTime == null;
|
|
|
- }
|
|
|
-
|
|
|
- public Integer getFetchSize() {
|
|
|
- return fetchSize;
|
|
|
- }
|
|
|
-
|
|
|
- public void setFetchSize(Integer fetchSize) {
|
|
|
- this.fetchSize = fetchSize;
|
|
|
- }
|
|
|
-
|
|
|
- public void addOrderByColumn(String column) {
|
|
|
- orderByColumns.add(column);
|
|
|
- }
|
|
|
-
|
|
|
- public String getOrderByClause(boolean asc) {
|
|
|
- String orderByStr = " ORDER BY ";
|
|
|
- if (!orderByColumns.isEmpty()) {
|
|
|
- StringBuilder sb = new StringBuilder(orderByStr);
|
|
|
- for (String orderByColumn : orderByColumns) {
|
|
|
- if (sb.length() != orderByStr.length()) {
|
|
|
- sb.append(", ");
|
|
|
- }
|
|
|
- sb.append(orderByColumn);
|
|
|
- if (!asc) {
|
|
|
- sb.append(" DESC");
|
|
|
- }
|
|
|
- }
|
|
|
- sb.append(" ");
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String toString() {
|
|
|
- return "Condition{" +
|
|
|
- "metricNames=" + metricNames +
|
|
|
- ", hostname='" + hostname + '\'' +
|
|
|
- ", appId='" + appId + '\'' +
|
|
|
- ", instanceId='" + instanceId + '\'' +
|
|
|
- ", startTime=" + startTime +
|
|
|
- ", endTime=" + endTime +
|
|
|
- ", limit=" + limit +
|
|
|
- ", grouped=" + grouped +
|
|
|
- ", orderBy=" + orderByColumns +
|
|
|
- ", noLimit=" + noLimit +
|
|
|
- '}';
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static class SplitByMetricNamesCondition implements Condition {
|
|
|
- private final Condition adaptee;
|
|
|
- private String currentMetric;
|
|
|
-
|
|
|
- SplitByMetricNamesCondition(Condition condition){
|
|
|
- this.adaptee = condition;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isEmpty() {
|
|
|
- return adaptee.isEmpty();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> getMetricNames() {
|
|
|
- return Collections.singletonList(currentMetric);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isPointInTime() {
|
|
|
- return adaptee.isPointInTime();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean isGrouped() {
|
|
|
- return adaptee.isGrouped();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setStatement(String statement) {
|
|
|
- adaptee.setStatement(statement);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getHostname() {
|
|
|
- return adaptee.getHostname();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Precision getPrecision() {
|
|
|
- return adaptee.getPrecision();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setPrecision(Precision precision) {
|
|
|
- adaptee.setPrecision(precision);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getAppId() {
|
|
|
- return adaptee.getAppId();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getInstanceId() {
|
|
|
- return adaptee.getInstanceId();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public StringBuilder getConditionClause() {
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- boolean appendConjunction = false;
|
|
|
-
|
|
|
- if (getMetricNames() != null) {
|
|
|
- for (String name : getMetricNames()) {
|
|
|
- if (sb.length() > 1) {
|
|
|
- sb.append(" OR ");
|
|
|
- }
|
|
|
- sb.append("METRIC_NAME = ?");
|
|
|
- }
|
|
|
-
|
|
|
- appendConjunction = true;
|
|
|
- }
|
|
|
-
|
|
|
- appendConjunction = DefaultCondition.append(sb, appendConjunction,
|
|
|
- getHostname(), " HOSTNAME = ?");
|
|
|
- appendConjunction = DefaultCondition.append(sb, appendConjunction,
|
|
|
- getAppId(), " APP_ID = ?");
|
|
|
- appendConjunction = DefaultCondition.append(sb, appendConjunction,
|
|
|
- getInstanceId(), " INSTANCE_ID = ?");
|
|
|
- appendConjunction = DefaultCondition.append(sb, appendConjunction,
|
|
|
- getStartTime(), " SERVER_TIME >= ?");
|
|
|
- DefaultCondition.append(sb, appendConjunction, getEndTime(),
|
|
|
- " SERVER_TIME < ?");
|
|
|
-
|
|
|
- return sb;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getOrderByClause(boolean asc) {
|
|
|
- return adaptee.getOrderByClause(asc);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getStatement() {
|
|
|
- return adaptee.getStatement();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getStartTime() {
|
|
|
- return adaptee.getStartTime();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Long getEndTime() {
|
|
|
- return adaptee.getEndTime();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Integer getLimit() {
|
|
|
- return adaptee.getLimit();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Integer getFetchSize() {
|
|
|
- return adaptee.getFetchSize();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setFetchSize(Integer fetchSize) {
|
|
|
- adaptee.setFetchSize(fetchSize);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addOrderByColumn(String column) {
|
|
|
- adaptee.addOrderByColumn(column);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setNoLimit() {
|
|
|
- adaptee.setNoLimit();
|
|
|
- }
|
|
|
-
|
|
|
- public List<String> getOriginalMetricNames() {
|
|
|
- return adaptee.getMetricNames();
|
|
|
- }
|
|
|
-
|
|
|
- public void setCurrentMetric(String currentMetric) {
|
|
|
- this.currentMetric = currentMetric;
|
|
|
- }
|
|
|
- }
|
|
|
}
|