YARN-7919. Refactor timelineservice-hbase module into submodules. Contributed by...
[hadoop.git] / hadoop-yarn-project / hadoop-yarn / hadoop-yarn-server / hadoop-yarn-server-timelineservice-hbase / hadoop-yarn-server-timelineservice-hbase-common / src / main / java / org / apache / hadoop / yarn / server / timelineservice / storage / application / ApplicationColumnPrefix.java
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.hadoop.yarn.server.timelineservice.storage.application;
19
20 import org.apache.hadoop.hbase.util.Bytes;
21 import org.apache.hadoop.yarn.server.timelineservice.storage.common.ColumnFamily;
22 import org.apache.hadoop.yarn.server.timelineservice.storage.common.ColumnHelper;
23 import org.apache.hadoop.yarn.server.timelineservice.storage.common.ColumnPrefix;
24 import org.apache.hadoop.yarn.server.timelineservice.storage.common.GenericConverter;
25 import org.apache.hadoop.yarn.server.timelineservice.storage.common.LongConverter;
26 import org.apache.hadoop.yarn.server.timelineservice.storage.common.Separator;
27 import org.apache.hadoop.yarn.server.timelineservice.storage.common.ValueConverter;
28 import org.apache.hadoop.yarn.server.timelineservice.storage.flow.Attribute;
29
30 /**
31 * Identifies partially qualified columns for the application table.
32 */
33 public enum ApplicationColumnPrefix implements ColumnPrefix<ApplicationTable> {
34
35 /**
36 * To store TimelineEntity getIsRelatedToEntities values.
37 */
38 IS_RELATED_TO(ApplicationColumnFamily.INFO, "s"),
39
40 /**
41 * To store TimelineEntity getRelatesToEntities values.
42 */
43 RELATES_TO(ApplicationColumnFamily.INFO, "r"),
44
45 /**
46 * To store TimelineEntity info values.
47 */
48 INFO(ApplicationColumnFamily.INFO, "i"),
49
50 /**
51 * Lifecycle events for an application.
52 */
53 EVENT(ApplicationColumnFamily.INFO, "e"),
54
55 /**
56 * Config column stores configuration with config key as the column name.
57 */
58 CONFIG(ApplicationColumnFamily.CONFIGS, null),
59
60 /**
61 * Metrics are stored with the metric name as the column name.
62 */
63 METRIC(ApplicationColumnFamily.METRICS, null, new LongConverter());
64
65 private final ColumnFamily<ApplicationTable> columnFamily;
66
67 /**
68 * Can be null for those cases where the provided column qualifier is the
69 * entire column name.
70 */
71 private final String columnPrefix;
72 private final byte[] columnPrefixBytes;
73 private final ValueConverter valueConverter;
74
75 /**
76 * Private constructor, meant to be used by the enum definition.
77 *
78 * @param columnFamily that this column is stored in.
79 * @param columnPrefix for this column.
80 */
81 private ApplicationColumnPrefix(ColumnFamily<ApplicationTable> columnFamily,
82 String columnPrefix) {
83 this(columnFamily, columnPrefix, GenericConverter.getInstance());
84 }
85
86 /**
87 * Private constructor, meant to be used by the enum definition.
88 *
89 * @param columnFamily that this column is stored in.
90 * @param columnPrefix for this column.
91 * @param converter used to encode/decode values to be stored in HBase for
92 * this column prefix.
93 */
94 private ApplicationColumnPrefix(ColumnFamily<ApplicationTable> columnFamily,
95 String columnPrefix, ValueConverter converter) {
96 this.valueConverter = converter;
97 this.columnFamily = columnFamily;
98 this.columnPrefix = columnPrefix;
99 if (columnPrefix == null) {
100 this.columnPrefixBytes = null;
101 } else {
102 // Future-proof by ensuring the right column prefix hygiene.
103 this.columnPrefixBytes =
104 Bytes.toBytes(Separator.SPACE.encode(columnPrefix));
105 }
106 }
107
108 /**
109 * @return the column name value
110 */
111 private String getColumnPrefix() {
112 return columnPrefix;
113 }
114
115 @Override
116 public byte[] getColumnPrefixBytes(byte[] qualifierPrefix) {
117 return ColumnHelper.getColumnQualifier(
118 this.columnPrefixBytes, qualifierPrefix);
119 }
120
121 @Override
122 public byte[] getColumnPrefixBytes(String qualifierPrefix) {
123 return ColumnHelper.getColumnQualifier(
124 this.columnPrefixBytes, qualifierPrefix);
125 }
126
127 @Override
128 public byte[] getColumnFamilyBytes() {
129 return columnFamily.getBytes();
130 }
131
132 @Override
133 public byte[] getColumnPrefixInBytes() {
134 return columnPrefixBytes != null ? columnPrefixBytes.clone() : null;
135 }
136
137 @Override
138 public Attribute[] getCombinedAttrsWithAggr(Attribute... attributes) {
139 return attributes;
140 }
141
142 @Override
143 public boolean supplementCellTimeStamp() {
144 return false;
145 }
146
147 public ValueConverter getValueConverter() {
148 return valueConverter;
149 }
150 }