http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationRequestPBImpl.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationRequestPBImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationRequestPBImpl.java new file mode 100644 index 0000000..5091360 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationRequestPBImpl.java @@ -0,0 +1,95 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.protocol.impl.pb; + +import java.io.IOException; + +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.UpdateNamenodeRegistrationRequestProto; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.UpdateNamenodeRegistrationRequestProtoOrBuilder; +import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState; +import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateNamenodeRegistrationRequest; +import org.apache.hadoop.hdfs.server.federation.store.records.impl.pb.PBRecord; + +import com.google.protobuf.Message; + +/** + * Protobuf implementation of the state store API object + * OverrideNamenodeRegistrationRequest. + */ +public class UpdateNamenodeRegistrationRequestPBImpl + extends UpdateNamenodeRegistrationRequest implements PBRecord { + + private FederationProtocolPBTranslator< + UpdateNamenodeRegistrationRequestProto, + UpdateNamenodeRegistrationRequestProto.Builder, + UpdateNamenodeRegistrationRequestProtoOrBuilder> translator = + new FederationProtocolPBTranslator< + UpdateNamenodeRegistrationRequestProto, + UpdateNamenodeRegistrationRequestProto.Builder, + UpdateNamenodeRegistrationRequestProtoOrBuilder>( + UpdateNamenodeRegistrationRequestProto.class); + + public UpdateNamenodeRegistrationRequestPBImpl() { + } + + @Override + public UpdateNamenodeRegistrationRequestProto getProto() { + return this.translator.build(); + } + + @Override + public void setProto(Message protocol) { + this.translator.setProto(protocol); + } + + @Override + public void readInstance(String base64String) throws IOException { + this.translator.readInstance(base64String); + } + + @Override + public String getNameserviceId() { + return this.translator.getProtoOrBuilder().getNameserviceId(); + } + + @Override + public String getNamenodeId() { + return this.translator.getProtoOrBuilder().getNamenodeId(); + } + + @Override + public FederationNamenodeServiceState getState() { + return FederationNamenodeServiceState + .valueOf(this.translator.getProtoOrBuilder().getState()); + } + + @Override + public void setNameserviceId(String nsId) { + this.translator.getBuilder().setNameserviceId(nsId); + } + + @Override + public void setNamenodeId(String nnId) { + this.translator.getBuilder().setNamenodeId(nnId); + } + + @Override + public void setState(FederationNamenodeServiceState state) { + this.translator.getBuilder().setState(state.toString()); + } +} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationResponsePBImpl.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationResponsePBImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationResponsePBImpl.java new file mode 100644 index 0000000..4558f06 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/UpdateNamenodeRegistrationResponsePBImpl.java @@ -0,0 +1,73 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.protocol.impl.pb; + +import java.io.IOException; + +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.UpdateNamenodeRegistrationResponseProto; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.UpdateNamenodeRegistrationResponseProtoOrBuilder; +import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateNamenodeRegistrationResponse; +import org.apache.hadoop.hdfs.server.federation.store.records.impl.pb.PBRecord; + +import com.google.protobuf.Message; + +/** + * Protobuf implementation of the state store API object + * OverrideNamenodeRegistrationResponse. + */ +public class UpdateNamenodeRegistrationResponsePBImpl + extends UpdateNamenodeRegistrationResponse implements PBRecord { + + private FederationProtocolPBTranslator< + UpdateNamenodeRegistrationResponseProto, + UpdateNamenodeRegistrationResponseProto.Builder, + UpdateNamenodeRegistrationResponseProtoOrBuilder> translator = + new FederationProtocolPBTranslator< + UpdateNamenodeRegistrationResponseProto, + UpdateNamenodeRegistrationResponseProto.Builder, + UpdateNamenodeRegistrationResponseProtoOrBuilder>( + UpdateNamenodeRegistrationResponseProto.class); + + public UpdateNamenodeRegistrationResponsePBImpl() { + } + + @Override + public UpdateNamenodeRegistrationResponseProto getProto() { + return this.translator.build(); + } + + @Override + public void setProto(Message proto) { + this.translator.setProto(proto); + } + + @Override + public void readInstance(String base64String) throws IOException { + this.translator.readInstance(base64String); + } + + @Override + public boolean getResult() { + return this.translator.getProtoOrBuilder().getStatus(); + } + + @Override + public void setResult(boolean result) { + this.translator.getBuilder().setStatus(result); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/package-info.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/package-info.java new file mode 100644 index 0000000..43c94be --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/impl/pb/package-info.java @@ -0,0 +1,29 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Protobuf implementations of FederationProtocolBase request/response objects + * used by state store APIs. Each state store API is defined in the + * org.apache.hadoop.hdfs.server.federation.store.protocol package. + */ +@InterfaceAudience.Private +@InterfaceStability.Evolving +package org.apache.hadoop.hdfs.server.federation.store.protocol.impl.pb; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/package-info.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/package-info.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/package-info.java new file mode 100644 index 0000000..0249d2c --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/protocol/package-info.java @@ -0,0 +1,31 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Contains the abstract definitions of the API request and response objects for + * the various state store APIs. The state store supports multiple interface + * APIs and multiple data records. Each protocol object requires a serialization + * implementation, the default is protobuf. + */ +@InterfaceAudience.Private +@InterfaceStability.Evolving + +package org.apache.hadoop.hdfs.server.federation.store.protocol; + +import org.apache.hadoop.classification.InterfaceAudience; +import org.apache.hadoop.classification.InterfaceStability; http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/BaseRecord.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/BaseRecord.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/BaseRecord.java new file mode 100644 index 0000000..d5e60ce --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/BaseRecord.java @@ -0,0 +1,215 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.util.Map; + +import org.apache.hadoop.util.Time; + +/** + * Abstract base of a data record in the StateStore. All StateStore records are + * derived from this class. Data records are persisted in the data store and + * are identified by their primary key. Each data record contains: + * <ul> + * <li>A primary key consisting of a combination of record data fields. + * <li>A modification date. + * <li>A creation date. + * </ul> + */ +public abstract class BaseRecord implements Comparable<BaseRecord> { + public static final String ERROR_MSG_CREATION_TIME_NEGATIVE = + "The creation time for the record cannot be negative."; + public static final String ERROR_MSG_MODIFICATION_TIME_NEGATIVE = + "The modification time for the record cannot be negative."; + + /** + * Set the modification time for the record. + * + * @param time Modification time of the record. + */ + public abstract void setDateModified(long time); + + /** + * Get the modification time for the record. + * + * @return Modification time of the record. + */ + public abstract long getDateModified(); + + /** + * Set the creation time for the record. + * + * @param time Creation time of the record. + */ + public abstract void setDateCreated(long time); + + /** + * Get the creation time for the record. + * + * @return Creation time of the record + */ + public abstract long getDateCreated(); + + /** + * Get the expiration time for the record. + * + * @return Expiration time for the record. + */ + public abstract long getExpirationMs(); + + /** + * Map of primary key names->values for the record. The primary key can be a + * combination of 1-n different State Store serialized values. + * + * @return Map of key/value pairs that constitute this object's primary key. + */ + public abstract Map<String, String> getPrimaryKeys(); + + /** + * Initialize the object. + */ + public void init() { + // Call this after the object has been constructed + initDefaultTimes(); + } + + /** + * Initialize default times. The driver may update these timestamps on insert + * and/or update. This should only be called when initializing an object that + * is not backed by a data store. + */ + private void initDefaultTimes() { + long now = Time.now(); + this.setDateCreated(now); + this.setDateModified(now); + } + + /** + * Join the primary keys into one single primary key. + * + * @return A string that is guaranteed to be unique amongst all records of + * this type. + */ + public String getPrimaryKey() { + return generateMashupKey(getPrimaryKeys()); + } + + /** + * Generates a cache key from a map of values. + * + * @param keys Map of values. + * @return String mashup of key values. + */ + protected static String generateMashupKey(final Map<String, String> keys) { + StringBuilder builder = new StringBuilder(); + for (Object value : keys.values()) { + if (builder.length() > 0) { + builder.append("-"); + } + builder.append(value); + } + return builder.toString(); + } + + /** + * Check if this record matches a partial record. + * + * @param other Partial record. + * @return If this record matches. + */ + public boolean like(BaseRecord other) { + if (other == null) { + return false; + } + Map<String, String> thisKeys = this.getPrimaryKeys(); + Map<String, String> otherKeys = other.getPrimaryKeys(); + if (thisKeys == null) { + return otherKeys == null; + } + return thisKeys.equals(otherKeys); + } + + /** + * Override equals check to use primary key(s) for comparison. + */ + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BaseRecord)) { + return false; + } + + BaseRecord baseObject = (BaseRecord) obj; + Map<String, String> keyset1 = this.getPrimaryKeys(); + Map<String, String> keyset2 = baseObject.getPrimaryKeys(); + return keyset1.equals(keyset2); + } + + /** + * Override hash code to use primary key(s) for comparison. + */ + @Override + public int hashCode() { + Map<String, String> keyset = this.getPrimaryKeys(); + return keyset.hashCode(); + } + + @Override + public int compareTo(BaseRecord record) { + if (record == null) { + return -1; + } + // Descending date order + return (int) (record.getDateModified() - this.getDateModified()); + } + + /** + * Called when the modification time and current time is available, checks for + * expirations. + * + * @param currentTime The current timestamp in ms from the data store, to be + * compared against the modification and creation dates of the + * object. + * @return boolean True if the record has been updated and should be + * committed to the data store. Override for customized behavior. + */ + public boolean checkExpired(long currentTime) { + long expiration = getExpirationMs(); + if (getDateModified() > 0 && expiration > 0) { + return (getDateModified() + expiration) < currentTime; + } + return false; + } + + /** + * Validates the record. Called when the record is created, populated from the + * state store, and before committing to the state store. If validate failed, + * there throws an exception. + */ + public void validate() { + if (getDateCreated() <= 0) { + throw new IllegalArgumentException(ERROR_MSG_CREATION_TIME_NEGATIVE); + } else if (getDateModified() <= 0) { + throw new IllegalArgumentException(ERROR_MSG_MODIFICATION_TIME_NEGATIVE); + } + } + + @Override + public String toString() { + return getPrimaryKey(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipState.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipState.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipState.java new file mode 100644 index 0000000..e33dedf --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipState.java @@ -0,0 +1,336 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import static org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState.ACTIVE; +import static org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState.EXPIRED; +import static org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState.UNAVAILABLE; + +import java.io.IOException; +import java.util.Comparator; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeContext; +import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState; +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; + +/** + * Data schema for storing NN registration information in the + * {@link org.apache.hadoop.hdfs.server.federation.store.StateStoreService + * FederationStateStoreService}. + */ +public abstract class MembershipState extends BaseRecord + implements FederationNamenodeContext { + public static final String ERROR_MSG_NO_NS_SPECIFIED = + "Invalid registration, no nameservice specified "; + public static final String ERROR_MSG_NO_WEB_ADDR_SPECIFIED = + "Invalid registration, no web address specified "; + public static final String ERROR_MSG_NO_RPC_ADDR_SPECIFIED = + "Invalid registration, no rpc address specified "; + public static final String ERROR_MSG_NO_BP_SPECIFIED = + "Invalid registration, no block pool specified "; + + /** Expiration time in ms for this entry. */ + private static long expirationMs; + + + /** Comparator based on the name.*/ + public static final Comparator<MembershipState> NAME_COMPARATOR = + new Comparator<MembershipState>() { + public int compare(MembershipState m1, MembershipState m2) { + return m1.compareNameTo(m2); + } + }; + + + /** + * Constructors. + */ + public MembershipState() { + super(); + } + + /** + * Create a new membership instance. + * @return Membership instance. + * @throws IOException + */ + public static MembershipState newInstance() { + MembershipState record = + StateStoreSerializer.newRecord(MembershipState.class); + record.init(); + return record; + } + + /** + * Create a new membership instance. + * + * @param router Identifier of the router. + * @param nameservice Identifier of the nameservice. + * @param namenode Identifier of the namenode. + * @param clusterId Identifier of the cluster. + * @param blockPoolId Identifier of the blockpool. + * @param rpcAddress RPC address. + * @param serviceAddress Service RPC address. + * @param lifelineAddress Lifeline RPC address. + * @param webAddress HTTP address. + * @param state State of the federation. + * @param safemode If the safe mode is enabled. + * @return Membership instance. + * @throws IOException If we cannot create the instance. + */ + public static MembershipState newInstance(String router, String nameservice, + String namenode, String clusterId, String blockPoolId, String rpcAddress, + String serviceAddress, String lifelineAddress, String webAddress, + FederationNamenodeServiceState state, boolean safemode) { + + MembershipState record = MembershipState.newInstance(); + record.setRouterId(router); + record.setNameserviceId(nameservice); + record.setNamenodeId(namenode); + record.setRpcAddress(rpcAddress); + record.setServiceAddress(serviceAddress); + record.setLifelineAddress(lifelineAddress); + record.setWebAddress(webAddress); + record.setIsSafeMode(safemode); + record.setState(state); + record.setClusterId(clusterId); + record.setBlockPoolId(blockPoolId); + record.validate(); + return record; + } + + public abstract void setRouterId(String routerId); + + public abstract String getRouterId(); + + public abstract void setNameserviceId(String nameserviceId); + + public abstract void setNamenodeId(String namenodeId); + + public abstract void setWebAddress(String webAddress); + + public abstract void setRpcAddress(String rpcAddress); + + public abstract void setServiceAddress(String serviceAddress); + + public abstract void setLifelineAddress(String lifelineAddress); + + public abstract void setIsSafeMode(boolean isSafeMode); + + public abstract void setClusterId(String clusterId); + + public abstract void setBlockPoolId(String blockPoolId); + + public abstract void setState(FederationNamenodeServiceState state); + + public abstract String getNameserviceId(); + + public abstract String getNamenodeId(); + + public abstract String getClusterId(); + + public abstract String getBlockPoolId(); + + public abstract String getRpcAddress(); + + public abstract String getServiceAddress(); + + public abstract String getLifelineAddress(); + + public abstract String getWebAddress(); + + public abstract boolean getIsSafeMode(); + + public abstract FederationNamenodeServiceState getState(); + + public abstract void setStats(MembershipStats stats); + + public abstract MembershipStats getStats(); + + public abstract void setLastContact(long contact); + + public abstract long getLastContact(); + + @Override + public boolean like(BaseRecord o) { + if (o instanceof MembershipState) { + MembershipState other = (MembershipState)o; + if (getRouterId() != null && + !getRouterId().equals(other.getRouterId())) { + return false; + } + if (getNameserviceId() != null && + !getNameserviceId().equals(other.getNameserviceId())) { + return false; + } + if (getNamenodeId() != null && + !getNamenodeId().equals(other.getNamenodeId())) { + return false; + } + if (getRpcAddress() != null && + !getRpcAddress().equals(other.getRpcAddress())) { + return false; + } + if (getClusterId() != null && + !getClusterId().equals(other.getClusterId())) { + return false; + } + if (getBlockPoolId() != null && + !getBlockPoolId().equals(other.getBlockPoolId())) { + return false; + } + if (getState() != null && + !getState().equals(other.getState())) { + return false; + } + return true; + } + return false; + } + + @Override + public String toString() { + return getRouterId() + "->" + getNameserviceId() + ":" + getNamenodeId() + + ":" + getRpcAddress() + "-" + getState(); + } + + @Override + public SortedMap<String, String> getPrimaryKeys() { + SortedMap<String, String> map = new TreeMap<String, String>(); + map.put("routerId", getRouterId()); + map.put("nameserviceId", getNameserviceId()); + map.put("namenodeId", getNamenodeId()); + return map; + } + + /** + * Check if the namenode is available. + * + * @return If the namenode is available. + */ + public boolean isAvailable() { + return getState() == ACTIVE; + } + + /** + * Validates the entry. Throws an IllegalArgementException if the data record + * is missing required information. + */ + @Override + public void validate() { + super.validate(); + if (getNameserviceId() == null || getNameserviceId().length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_NO_NS_SPECIFIED + this); + } + if (getWebAddress() == null || getWebAddress().length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_NO_WEB_ADDR_SPECIFIED + this); + } + if (getRpcAddress() == null || getRpcAddress().length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_NO_RPC_ADDR_SPECIFIED + this); + } + if (!isBadState() && + (getBlockPoolId().isEmpty() || getBlockPoolId().length() == 0)) { + throw new IllegalArgumentException( + ERROR_MSG_NO_BP_SPECIFIED + this); + } + } + + + /** + * Overrides the cached getBlockPoolId() with an update. The state will be + * reset when the cache is flushed + * + * @param newState Service state of the namenode. + */ + public void overrideState(FederationNamenodeServiceState newState) { + this.setState(newState); + } + + /** + * Sort by nameservice, namenode, and router. + * + * @param other Another membership to compare to. + * @return If this object goes before the parameter. + */ + public int compareNameTo(MembershipState other) { + int ret = this.getNameserviceId().compareTo(other.getNameserviceId()); + if (ret == 0) { + ret = this.getNamenodeId().compareTo(other.getNamenodeId()); + } + if (ret == 0) { + ret = this.getRouterId().compareTo(other.getRouterId()); + } + return ret; + } + + /** + * Get the identifier of this namenode registration. + * @return Identifier of the namenode. + */ + public String getNamenodeKey() { + return getNamenodeKey(this.getNameserviceId(), this.getNamenodeId()); + } + + /** + * Generate the identifier for a Namenode in the HDFS federation. + * + * @param nsId Nameservice of the Namenode. + * @param nnId Namenode within the Nameservice (HA). + * @return Namenode identifier within the federation. + */ + public static String getNamenodeKey(String nsId, String nnId) { + return nsId + "-" + nnId; + } + + /** + * Check if the membership is in a bad state (expired or unavailable). + * @return If the membership is in a bad state (expired or unavailable). + */ + private boolean isBadState() { + return this.getState() == EXPIRED || this.getState() == UNAVAILABLE; + } + + @Override + public boolean checkExpired(long currentTime) { + if (super.checkExpired(currentTime)) { + this.setState(EXPIRED); + // Commit it + return true; + } + return false; + } + + @Override + public long getExpirationMs() { + return MembershipState.expirationMs; + } + + /** + * Set the expiration time for this class. + * + * @param time Expiration time in milliseconds. + */ + public static void setExpirationMs(long time) { + MembershipState.expirationMs = time; + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipStats.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipStats.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipStats.java new file mode 100644 index 0000000..654140c --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MembershipStats.java @@ -0,0 +1,130 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.io.IOException; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; + +/** + * Data schema for storing NN stats in the + * {@link org.apache.hadoop.hdfs.server.federation.store.StateStoreService + * StateStoreService}. + */ +public abstract class MembershipStats extends BaseRecord { + + public static MembershipStats newInstance() throws IOException { + MembershipStats record = + StateStoreSerializer.newRecord(MembershipStats.class); + record.init(); + return record; + } + + public abstract void setTotalSpace(long space); + + public abstract long getTotalSpace(); + + public abstract void setAvailableSpace(long space); + + public abstract long getAvailableSpace(); + + public abstract void setProvidedSpace(long capacity); + + public abstract long getProvidedSpace(); + + public abstract void setNumOfFiles(long files); + + public abstract long getNumOfFiles(); + + public abstract void setNumOfBlocks(long blocks); + + public abstract long getNumOfBlocks(); + + public abstract void setNumOfBlocksMissing(long blocks); + + public abstract long getNumOfBlocksMissing(); + + public abstract void setNumOfBlocksPendingReplication(long blocks); + + public abstract long getNumOfBlocksPendingReplication(); + + public abstract void setNumOfBlocksUnderReplicated(long blocks); + + public abstract long getNumOfBlocksUnderReplicated(); + + public abstract void setNumOfBlocksPendingDeletion(long blocks); + + public abstract long getNumOfBlocksPendingDeletion(); + + public abstract void setNumOfActiveDatanodes(int nodes); + + public abstract int getNumOfActiveDatanodes(); + + public abstract void setNumOfDeadDatanodes(int nodes); + + public abstract int getNumOfDeadDatanodes(); + + public abstract void setNumOfDecommissioningDatanodes(int nodes); + + public abstract int getNumOfDecommissioningDatanodes(); + + public abstract void setNumOfDecomActiveDatanodes(int nodes); + + public abstract int getNumOfDecomActiveDatanodes(); + + public abstract void setNumOfDecomDeadDatanodes(int nodes); + + public abstract int getNumOfDecomDeadDatanodes(); + + @Override + public SortedMap<String, String> getPrimaryKeys() { + // This record is not stored directly, no key needed + SortedMap<String, String> map = new TreeMap<String, String>(); + return map; + } + + @Override + public long getExpirationMs() { + // This record is not stored directly, no expiration needed + return -1; + } + + @Override + public void setDateModified(long time) { + // We don't store this record directly + } + + @Override + public long getDateModified() { + // We don't store this record directly + return 0; + } + + @Override + public void setDateCreated(long time) { + // We don't store this record directly + } + + @Override + public long getDateCreated() { + // We don't store this record directly + return 0; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MountTable.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MountTable.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MountTable.java new file mode 100644 index 0000000..0eab043 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/MountTable.java @@ -0,0 +1,430 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.io.IOException; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.hdfs.protocol.HdfsConstants; +import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation; +import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder; +import org.apache.hadoop.hdfs.server.federation.router.RouterPermissionChecker; +import org.apache.hadoop.hdfs.server.federation.router.RouterQuotaUsage; +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; +import org.apache.hadoop.hdfs.server.namenode.NameNode; +import org.apache.hadoop.security.UserGroupInformation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Data schema for + * {@link org.apache.hadoop.hdfs.server.federation.store. + * MountTableStore FederationMountTableStore} data stored in the + * {@link org.apache.hadoop.hdfs.server.federation.store. + * StateStoreService FederationStateStoreService}. Supports string + * serialization. + */ +public abstract class MountTable extends BaseRecord { + + private static final Logger LOG = LoggerFactory.getLogger(MountTable.class); + public static final String ERROR_MSG_NO_SOURCE_PATH = + "Invalid entry, no source path specified "; + public static final String ERROR_MSG_MUST_START_WITH_BACK_SLASH = + "Invalid entry, all mount points must start with / "; + public static final String ERROR_MSG_NO_DEST_PATH_SPECIFIED = + "Invalid entry, no destination paths specified "; + public static final String ERROR_MSG_INVAILD_DEST_NS = + "Invalid entry, invalid destination nameservice "; + public static final String ERROR_MSG_INVAILD_DEST_PATH = + "Invalid entry, invalid destination path "; + public static final String ERROR_MSG_ALL_DEST_MUST_START_WITH_BACK_SLASH = + "Invalid entry, all destination must start with / "; + + /** Comparator for paths which considers the /. */ + public static final Comparator<String> PATH_COMPARATOR = + new Comparator<String>() { + @Override + public int compare(String o1, String o2) { + String s1 = o1.replace('/', ' '); + String s2 = o2.replace('/', ' '); + return s1.compareTo(s2); + } + }; + + /** Comparator based on the mount table source. */ + public static final Comparator<MountTable> SOURCE_COMPARATOR = + new Comparator<MountTable>() { + public int compare(MountTable m1, MountTable m2) { + String src1 = m1.getSourcePath(); + String src2 = m2.getSourcePath(); + return PATH_COMPARATOR.compare(src1, src2); + } + }; + + + /** + * Default constructor for a mount table entry. + */ + public MountTable() { + super(); + } + + public static MountTable newInstance() { + MountTable record = StateStoreSerializer.newRecord(MountTable.class); + record.init(); + return record; + } + + /** + * Constructor for a mount table entry with a single destinations. + * + * @param src Source path in the mount entry. + * @param destinations Nameservice destination of the mount point. + * @param dateCreated Created date. + * @param dateModified Modified date. + * @throws IOException + */ + public static MountTable newInstance(final String src, + final Map<String, String> destinations, + long dateCreated, long dateModified) throws IOException { + + MountTable record = newInstance(src, destinations); + record.setDateCreated(dateCreated); + record.setDateModified(dateModified); + return record; + } + + /** + * Constructor for a mount table entry with multiple destinations. + * + * @param src Source path in the mount entry. + * @param destinations Nameservice destinations of the mount point. + * @throws IOException + */ + public static MountTable newInstance(final String src, + final Map<String, String> destinations) throws IOException { + MountTable record = newInstance(); + + // Normalize the mount path + record.setSourcePath(normalizeFileSystemPath(src)); + + // Build a list of remote locations + final List<RemoteLocation> locations = new LinkedList<>(); + for (Entry<String, String> entry : destinations.entrySet()) { + String nsId = entry.getKey(); + String path = normalizeFileSystemPath(entry.getValue()); + RemoteLocation location = new RemoteLocation(nsId, path); + locations.add(location); + } + + // Set the serialized dest string + record.setDestinations(locations); + + // Set permission fields + UserGroupInformation ugi = NameNode.getRemoteUser(); + record.setOwnerName(ugi.getShortUserName()); + String group = ugi.getGroups().isEmpty() ? ugi.getShortUserName() + : ugi.getPrimaryGroupName(); + record.setGroupName(group); + record.setMode(new FsPermission( + RouterPermissionChecker.MOUNT_TABLE_PERMISSION_DEFAULT)); + + // Set quota for mount table + RouterQuotaUsage quota = new RouterQuotaUsage.Builder() + .fileAndDirectoryCount(RouterQuotaUsage.QUOTA_USAGE_COUNT_DEFAULT) + .quota(HdfsConstants.QUOTA_DONT_SET) + .spaceConsumed(RouterQuotaUsage.QUOTA_USAGE_COUNT_DEFAULT) + .spaceQuota(HdfsConstants.QUOTA_DONT_SET).build(); + record.setQuota(quota); + + // Validate + record.validate(); + return record; + } + + /** + * Get source path in the federated namespace. + * + * @return Source path in the federated namespace. + */ + public abstract String getSourcePath(); + + /** + * Set source path in the federated namespace. + * + * @param path Source path in the federated namespace. + */ + public abstract void setSourcePath(String path); + + /** + * Get a list of destinations (namespace + path) present for this entry. + * + * @return List of RemoteLocation destinations. Null if no destinations. + */ + public abstract List<RemoteLocation> getDestinations(); + + /** + * Set the destination paths. + * + * @param paths Destination paths. + */ + public abstract void setDestinations(List<RemoteLocation> dests); + + /** + * Add a new destination to this mount table entry. + */ + public abstract boolean addDestination(String nsId, String path); + + /** + * Check if the entry is read only. + * + * @return If the entry is read only. + */ + public abstract boolean isReadOnly(); + + /** + * Set an entry to be read only. + * + * @param ro If the entry is read only. + */ + public abstract void setReadOnly(boolean ro); + + /** + * Get the order of the destinations for this mount table entry. + * + * @return Order of the destinations. + */ + public abstract DestinationOrder getDestOrder(); + + /** + * Set the order of the destinations for this mount table entry. + * + * @param order Order of the destinations. + */ + public abstract void setDestOrder(DestinationOrder order); + + /** + * Get owner name of this mount table entry. + * + * @return Owner name + */ + public abstract String getOwnerName(); + + /** + * Set owner name of this mount table entry. + * + * @param owner Owner name for mount table entry + */ + public abstract void setOwnerName(String owner); + + /** + * Get group name of this mount table entry. + * + * @return Group name + */ + public abstract String getGroupName(); + + /** + * Set group name of this mount table entry. + * + * @param group Group name for mount table entry + */ + public abstract void setGroupName(String group); + + /** + * Get permission of this mount table entry. + * + * @return FsPermission permission mode + */ + public abstract FsPermission getMode(); + + /** + * Set permission for this mount table entry. + * + * @param mode Permission for mount table entry + */ + public abstract void setMode(FsPermission mode); + + /** + * Get quota of this mount table entry. + * + * @return RouterQuotaUsage quota usage + */ + public abstract RouterQuotaUsage getQuota(); + + /** + * Set quota for this mount table entry. + * + * @param quota QuotaUsage for mount table entry + */ + public abstract void setQuota(RouterQuotaUsage quota); + + /** + * Get the default location. + * @return The default location. + */ + public RemoteLocation getDefaultLocation() { + List<RemoteLocation> dests = this.getDestinations(); + if (dests == null || dests.isEmpty()) { + return null; + } + return dests.get(0); + } + + @Override + public boolean like(final BaseRecord o) { + if (o instanceof MountTable) { + MountTable other = (MountTable)o; + if (getSourcePath() != null && + !getSourcePath().equals(other.getSourcePath())) { + return false; + } + if (getDestinations() != null && + !getDestinations().equals(other.getDestinations())) { + return false; + } + return true; + } + return false; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(this.getSourcePath()); + sb.append("->"); + List<RemoteLocation> destinations = this.getDestinations(); + sb.append(destinations); + if (destinations != null && destinations.size() > 1) { + sb.append("[" + this.getDestOrder() + "]"); + } + if (this.isReadOnly()) { + sb.append("[RO]"); + } + + if (this.getOwnerName() != null) { + sb.append("[owner:").append(this.getOwnerName()).append("]"); + } + + if (this.getGroupName() != null) { + sb.append("[group:").append(this.getGroupName()).append("]"); + } + + if (this.getMode() != null) { + sb.append("[mode:").append(this.getMode()).append("]"); + } + + if (this.getQuota() != null) { + sb.append("[quota:").append(this.getQuota()).append("]"); + } + + return sb.toString(); + } + + @Override + public SortedMap<String, String> getPrimaryKeys() { + SortedMap<String, String> map = new TreeMap<>(); + map.put("sourcePath", this.getSourcePath()); + return map; + } + + @Override + public void validate() { + super.validate(); + if (this.getSourcePath() == null || this.getSourcePath().length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_NO_SOURCE_PATH + this); + } + if (!this.getSourcePath().startsWith("/")) { + throw new IllegalArgumentException( + ERROR_MSG_MUST_START_WITH_BACK_SLASH + this); + } + if (this.getDestinations() == null || this.getDestinations().size() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_NO_DEST_PATH_SPECIFIED + this); + } + for (RemoteLocation loc : getDestinations()) { + String nsId = loc.getNameserviceId(); + if (nsId == null || nsId.length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_INVAILD_DEST_NS + this); + } + if (loc.getDest() == null || loc.getDest().length() == 0) { + throw new IllegalArgumentException( + ERROR_MSG_INVAILD_DEST_PATH + this); + } + if (!loc.getDest().startsWith("/")) { + throw new IllegalArgumentException( + ERROR_MSG_ALL_DEST_MUST_START_WITH_BACK_SLASH + this); + } + } + } + + @Override + public long getExpirationMs() { + return 0; + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 31) + .append(this.getSourcePath()) + .append(this.getDestinations()) + .append(this.isReadOnly()) + .append(this.getDestOrder()) + .toHashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MountTable) { + MountTable other = (MountTable)obj; + if (!this.getSourcePath().equals(other.getSourcePath())) { + return false; + } else if (!this.getDestinations().equals(other.getDestinations())) { + return false; + } else if (this.isReadOnly() != other.isReadOnly()) { + return false; + } else if (!this.getDestOrder().equals(other.getDestOrder())) { + return false; + } + return true; + } + return false; + } + + /** + * Normalize a path for that filesystem. + * + * @param path Path to normalize. + * @return Normalized path. + */ + private static String normalizeFileSystemPath(final String path) { + Path normalizedPath = new Path(path); + return normalizedPath.toString(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/Query.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/Query.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/Query.java new file mode 100644 index 0000000..3c59abf --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/Query.java @@ -0,0 +1,66 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +/** + * Check if a record matches a query. The query is usually a partial record. + * + * @param <T> Type of the record to query. + */ +public class Query<T extends BaseRecord> { + + /** Partial object to compare against. */ + private final T partial; + + + /** + * Create a query to search for a partial record. + * + * @param partial It defines the attributes to search. + */ + public Query(final T part) { + this.partial = part; + } + + /** + * Get the partial record used to query. + * + * @return The partial record used for the query. + */ + public T getPartial() { + return this.partial; + } + + /** + * Check if a record matches the primary keys or the partial record. + * + * @param other Record to check. + * @return If the record matches. Don't match if there is no partial. + */ + public boolean matches(T other) { + if (this.partial == null) { + return false; + } + return this.partial.like(other); + } + + @Override + public String toString() { + return "Checking: " + this.partial; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/QueryResult.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/QueryResult.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/QueryResult.java new file mode 100644 index 0000000..64c2c71 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/QueryResult.java @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.util.Collections; +import java.util.List; + +/** + * Encapsulates a state store query result that includes a set of records and a + * time stamp for the result. + */ +public class QueryResult<T extends BaseRecord> { + + /** Data result. */ + private final List<T> records; + /** Time stamp of the data results. */ + private final long timestamp; + + public QueryResult(final List<T> recs, final long time) { + this.records = recs; + this.timestamp = time; + } + + /** + * Get the result of the query. + * + * @return List of records. + */ + public List<T> getRecords() { + return Collections.unmodifiableList(this.records); + } + + /** + * The timetamp in driver time of this query. + * + * @return Timestamp in driver time. + */ + public long getTimestamp() { + return this.timestamp; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/RouterState.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/RouterState.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/RouterState.java new file mode 100644 index 0000000..c90abcc --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/RouterState.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.io.IOException; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.hadoop.hdfs.server.federation.router.FederationUtil; +import org.apache.hadoop.hdfs.server.federation.router.RouterServiceState; +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Entry to log the state of a + * {@link org.apache.hadoop.hdfs.server.federation.router.Router Router} in the + * {@link org.apache.hadoop.hdfs.server.federation.store.StateStoreService + * FederationStateStoreService}. + */ +public abstract class RouterState extends BaseRecord { + + private static final Logger LOG = LoggerFactory.getLogger(RouterState.class); + + /** Expiration time in ms for this entry. */ + private static long expirationMs; + + /** + * Constructors. + */ + public RouterState() { + super(); + } + + public static RouterState newInstance() { + RouterState record = StateStoreSerializer.newRecord(RouterState.class); + record.init(); + return record; + } + + public static RouterState newInstance(String addr, long startTime, + RouterServiceState status) { + RouterState record = newInstance(); + record.setDateStarted(startTime); + record.setAddress(addr); + record.setStatus(status); + record.setCompileInfo(FederationUtil.getCompileInfo()); + record.setVersion(FederationUtil.getVersion()); + return record; + } + + public abstract void setAddress(String address); + + public abstract void setDateStarted(long dateStarted); + + public abstract String getAddress(); + + public abstract StateStoreVersion getStateStoreVersion() throws IOException; + + public abstract void setStateStoreVersion(StateStoreVersion version); + + public abstract RouterServiceState getStatus(); + + public abstract void setStatus(RouterServiceState newStatus); + + public abstract String getVersion(); + + public abstract void setVersion(String version); + + public abstract String getCompileInfo(); + + public abstract void setCompileInfo(String info); + + public abstract long getDateStarted(); + + /** + * Get the identifier for the Router. It uses the address. + * + * @return Identifier for the Router. + */ + public String getRouterId() { + return getAddress(); + } + + @Override + public boolean like(BaseRecord o) { + if (o instanceof RouterState) { + RouterState other = (RouterState)o; + if (getAddress() != null && + !getAddress().equals(other.getAddress())) { + return false; + } + if (getStatus() != null && + !getStatus().equals(other.getStatus())) { + return false; + } + return true; + } + return false; + } + + @Override + public String toString() { + return getAddress() + " -> " + getStatus() + "," + getVersion(); + } + + @Override + public SortedMap<String, String> getPrimaryKeys() { + SortedMap<String, String> map = new TreeMap<>(); + map.put("address", getAddress()); + return map; + } + + @Override + public void validate() { + super.validate(); + if ((getAddress() == null || getAddress().length() == 0) && + getStatus() != RouterServiceState.INITIALIZING) { + throw new IllegalArgumentException( + "Invalid router entry, no address specified " + this); + } + } + + @Override + public int compareTo(BaseRecord other) { + if (other == null) { + return -1; + } else if (other instanceof RouterState) { + RouterState router = (RouterState) other; + return this.getAddress().compareTo(router.getAddress()); + } else { + return super.compareTo(other); + } + } + + @Override + public boolean checkExpired(long currentTime) { + if (super.checkExpired(currentTime)) { + setStatus(RouterServiceState.EXPIRED); + return true; + } + return false; + } + + @Override + public long getExpirationMs() { + return RouterState.expirationMs; + } + + public static void setExpirationMs(long time) { + RouterState.expirationMs = time; + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/StateStoreVersion.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/StateStoreVersion.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/StateStoreVersion.java new file mode 100644 index 0000000..ce86eb0 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/StateStoreVersion.java @@ -0,0 +1,91 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records; + +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; + +/** + * Entry to track the version of the State Store data stored in the State Store + * by a Router. + */ +public abstract class StateStoreVersion extends BaseRecord { + + public static StateStoreVersion newInstance() { + return StateStoreSerializer.newRecord(StateStoreVersion.class); + } + + public static StateStoreVersion newInstance(long membershipVersion, + long mountTableVersion) { + StateStoreVersion record = newInstance(); + record.setMembershipVersion(membershipVersion); + record.setMountTableVersion(mountTableVersion); + return record; + } + + public abstract long getMembershipVersion(); + + public abstract void setMembershipVersion(long version); + + public abstract long getMountTableVersion(); + + public abstract void setMountTableVersion(long version); + + @Override + public SortedMap<String, String> getPrimaryKeys() { + // This record is not stored directly, no key needed + SortedMap<String, String> map = new TreeMap<String, String>(); + return map; + } + + @Override + public long getExpirationMs() { + // This record is not stored directly, no expiration needed + return -1; + } + + @Override + public void setDateModified(long time) { + // We don't store this record directly + } + + @Override + public long getDateModified() { + // We don't store this record directly + return 0; + } + + @Override + public void setDateCreated(long time) { + // We don't store this record directly + } + + @Override + public long getDateCreated() { + // We don't store this record directly + return 0; + } + + @Override + public String toString() { + return "Membership: " + getMembershipVersion() + + " Mount Table: " + getMountTableVersion(); + } +} http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatePBImpl.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatePBImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatePBImpl.java new file mode 100644 index 0000000..614957b --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatePBImpl.java @@ -0,0 +1,335 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records.impl.pb; + +import java.io.IOException; + +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipRecordProto; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipRecordProto.Builder; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipRecordProtoOrBuilder; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipStatsRecordProto; +import org.apache.hadoop.hdfs.server.federation.resolver.FederationNamenodeServiceState; +import org.apache.hadoop.hdfs.server.federation.store.driver.StateStoreSerializer; +import org.apache.hadoop.hdfs.server.federation.store.protocol.impl.pb.FederationProtocolPBTranslator; +import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState; +import org.apache.hadoop.hdfs.server.federation.store.records.MembershipStats; + +import com.google.protobuf.Message; + +/** + * Protobuf implementation of the MembershipState record. + */ +public class MembershipStatePBImpl extends MembershipState implements PBRecord { + + private FederationProtocolPBTranslator<NamenodeMembershipRecordProto, Builder, + NamenodeMembershipRecordProtoOrBuilder> translator = + new FederationProtocolPBTranslator<NamenodeMembershipRecordProto, + Builder, NamenodeMembershipRecordProtoOrBuilder>( + NamenodeMembershipRecordProto.class); + + public MembershipStatePBImpl() { + } + + public MembershipStatePBImpl(NamenodeMembershipRecordProto proto) { + this.translator.setProto(proto); + } + + @Override + public NamenodeMembershipRecordProto getProto() { + return this.translator.build(); + } + + @Override + public void setProto(Message proto) { + this.translator.setProto(proto); + } + + @Override + public void readInstance(String base64String) throws IOException { + this.translator.readInstance(base64String); + } + + @Override + public void setRouterId(String routerId) { + Builder builder = this.translator.getBuilder(); + if (routerId == null) { + builder.clearRouterId(); + } else { + builder.setRouterId(routerId); + } + } + + @Override + public void setNameserviceId(String nameserviceId) { + Builder builder = this.translator.getBuilder(); + if (nameserviceId == null) { + builder.clearNameserviceId(); + } else { + builder.setNameserviceId(nameserviceId); + } + } + + @Override + public void setNamenodeId(String namenodeId) { + Builder builder = this.translator.getBuilder(); + if (namenodeId == null) { + builder.clearNamenodeId(); + } else { + builder.setNamenodeId(namenodeId); + } + } + + @Override + public void setWebAddress(String webAddress) { + Builder builder = this.translator.getBuilder(); + if (webAddress == null) { + builder.clearWebAddress(); + } else { + builder.setWebAddress(webAddress); + } + } + + @Override + public void setRpcAddress(String rpcAddress) { + Builder builder = this.translator.getBuilder(); + if (rpcAddress == null) { + builder.clearRpcAddress(); + } else { + builder.setRpcAddress(rpcAddress); + } + } + + @Override + public void setServiceAddress(String serviceAddress) { + this.translator.getBuilder().setServiceAddress(serviceAddress); + } + + @Override + public void setLifelineAddress(String lifelineAddress) { + Builder builder = this.translator.getBuilder(); + if (lifelineAddress == null) { + builder.clearLifelineAddress(); + } else { + builder.setLifelineAddress(lifelineAddress); + } + } + + @Override + public void setIsSafeMode(boolean isSafeMode) { + Builder builder = this.translator.getBuilder(); + builder.setIsSafeMode(isSafeMode); + } + + @Override + public void setClusterId(String clusterId) { + Builder builder = this.translator.getBuilder(); + if (clusterId == null) { + builder.clearClusterId(); + } else { + builder.setClusterId(clusterId); + } + } + + @Override + public void setBlockPoolId(String blockPoolId) { + Builder builder = this.translator.getBuilder(); + if (blockPoolId == null) { + builder.clearBlockPoolId(); + } else { + builder.setBlockPoolId(blockPoolId); + } + } + + @Override + public void setState(FederationNamenodeServiceState state) { + Builder builder = this.translator.getBuilder(); + if (state == null) { + builder.clearState(); + } else { + builder.setState(state.toString()); + } + } + + @Override + public String getRouterId() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasRouterId()) { + return null; + } + return proto.getRouterId(); + } + + @Override + public String getNameserviceId() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasNameserviceId()) { + return null; + } + return this.translator.getProtoOrBuilder().getNameserviceId(); + } + + @Override + public String getNamenodeId() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasNamenodeId()) { + return null; + } + return this.translator.getProtoOrBuilder().getNamenodeId(); + } + + @Override + public String getClusterId() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasClusterId()) { + return null; + } + return this.translator.getProtoOrBuilder().getClusterId(); + } + + @Override + public String getBlockPoolId() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasBlockPoolId()) { + return null; + } + return this.translator.getProtoOrBuilder().getBlockPoolId(); + } + + @Override + public String getRpcAddress() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasRpcAddress()) { + return null; + } + return this.translator.getProtoOrBuilder().getRpcAddress(); + } + + @Override + public String getServiceAddress() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasServiceAddress()) { + return null; + } + return this.translator.getProtoOrBuilder().getServiceAddress(); + } + + @Override + public String getWebAddress() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasWebAddress()) { + return null; + } + return this.translator.getProtoOrBuilder().getWebAddress(); + } + + @Override + public String getLifelineAddress() { + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasLifelineAddress()) { + return null; + } + return this.translator.getProtoOrBuilder().getLifelineAddress(); + } + + @Override + public boolean getIsSafeMode() { + return this.translator.getProtoOrBuilder().getIsSafeMode(); + } + + @Override + public FederationNamenodeServiceState getState() { + FederationNamenodeServiceState ret = + FederationNamenodeServiceState.UNAVAILABLE; + NamenodeMembershipRecordProtoOrBuilder proto = + this.translator.getProtoOrBuilder(); + if (!proto.hasState()) { + return null; + } + try { + ret = FederationNamenodeServiceState.valueOf(proto.getState()); + } catch (IllegalArgumentException e) { + // Ignore this error + } + return ret; + } + + @Override + public void setStats(MembershipStats stats) { + if (stats instanceof MembershipStatsPBImpl) { + MembershipStatsPBImpl statsPB = (MembershipStatsPBImpl)stats; + NamenodeMembershipStatsRecordProto statsProto = + (NamenodeMembershipStatsRecordProto)statsPB.getProto(); + this.translator.getBuilder().setStats(statsProto); + } + } + + @Override + public MembershipStats getStats() { + NamenodeMembershipStatsRecordProto statsProto = + this.translator.getProtoOrBuilder().getStats(); + MembershipStats stats = + StateStoreSerializer.newRecord(MembershipStats.class); + if (stats instanceof MembershipStatsPBImpl) { + MembershipStatsPBImpl statsPB = (MembershipStatsPBImpl)stats; + statsPB.setProto(statsProto); + return statsPB; + } else { + throw new IllegalArgumentException( + "Cannot get stats for the membership"); + } + } + + @Override + public void setLastContact(long contact) { + this.translator.getBuilder().setLastContact(contact); + } + + @Override + public long getLastContact() { + return this.translator.getProtoOrBuilder().getLastContact(); + } + + @Override + public void setDateModified(long time) { + this.translator.getBuilder().setDateModified(time); + } + + @Override + public long getDateModified() { + return this.translator.getProtoOrBuilder().getDateModified(); + } + + @Override + public void setDateCreated(long time) { + this.translator.getBuilder().setDateCreated(time); + } + + @Override + public long getDateCreated() { + return this.translator.getProtoOrBuilder().getDateCreated(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/hadoop/blob/87700d45/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatsPBImpl.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatsPBImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatsPBImpl.java new file mode 100644 index 0000000..3347bc6 --- /dev/null +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/records/impl/pb/MembershipStatsPBImpl.java @@ -0,0 +1,201 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hdfs.server.federation.store.records.impl.pb; + +import java.io.IOException; + +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipStatsRecordProto; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipStatsRecordProto.Builder; +import org.apache.hadoop.hdfs.federation.protocol.proto.HdfsServerFederationProtos.NamenodeMembershipStatsRecordProtoOrBuilder; +import org.apache.hadoop.hdfs.server.federation.store.protocol.impl.pb.FederationProtocolPBTranslator; +import org.apache.hadoop.hdfs.server.federation.store.records.MembershipStats; + +import com.google.protobuf.Message; + +/** + * Protobuf implementation of the MembershipStats record. + */ +public class MembershipStatsPBImpl extends MembershipStats + implements PBRecord { + + private FederationProtocolPBTranslator<NamenodeMembershipStatsRecordProto, + Builder, NamenodeMembershipStatsRecordProtoOrBuilder> translator = + new FederationProtocolPBTranslator<NamenodeMembershipStatsRecordProto, + Builder, NamenodeMembershipStatsRecordProtoOrBuilder>( + NamenodeMembershipStatsRecordProto.class); + + public MembershipStatsPBImpl() { + } + + @Override + public NamenodeMembershipStatsRecordProto getProto() { + return this.translator.build(); + } + + @Override + public void setProto(Message proto) { + this.translator.setProto(proto); + } + + @Override + public void readInstance(String base64String) throws IOException { + this.translator.readInstance(base64String); + } + + @Override + public void setTotalSpace(long space) { + this.translator.getBuilder().setTotalSpace(space); + } + + @Override + public long getTotalSpace() { + return this.translator.getProtoOrBuilder().getTotalSpace(); + } + + @Override + public void setAvailableSpace(long space) { + this.translator.getBuilder().setAvailableSpace(space); + } + + @Override + public long getAvailableSpace() { + return this.translator.getProtoOrBuilder().getAvailableSpace(); + } + + @Override + public void setProvidedSpace(long capacity) { + this.translator.getBuilder().setProvidedSpace(capacity); + } + + @Override + public long getProvidedSpace() { + return this.translator.getProtoOrBuilder().getProvidedSpace(); + } + + @Override + public void setNumOfFiles(long files) { + this.translator.getBuilder().setNumOfFiles(files); + } + + @Override + public long getNumOfFiles() { + return this.translator.getProtoOrBuilder().getNumOfFiles(); + } + + @Override + public void setNumOfBlocks(long blocks) { + this.translator.getBuilder().setNumOfBlocks(blocks); + } + + @Override + public long getNumOfBlocks() { + return this.translator.getProtoOrBuilder().getNumOfBlocks(); + } + + @Override + public void setNumOfBlocksMissing(long blocks) { + this.translator.getBuilder().setNumOfBlocksMissing(blocks); + } + + @Override + public long getNumOfBlocksMissing() { + return this.translator.getProtoOrBuilder().getNumOfBlocksMissing(); + } + + @Override + public void setNumOfBlocksPendingReplication(long blocks) { + this.translator.getBuilder().setNumOfBlocksPendingReplication(blocks); + } + + @Override + public long getNumOfBlocksPendingReplication() { + return this.translator.getProtoOrBuilder() + .getNumOfBlocksPendingReplication(); + } + + @Override + public void setNumOfBlocksUnderReplicated(long blocks) { + this.translator.getBuilder().setNumOfBlocksUnderReplicated(blocks); + } + + @Override + public long getNumOfBlocksUnderReplicated() { + return this.translator.getProtoOrBuilder().getNumOfBlocksUnderReplicated(); + } + + @Override + public void setNumOfBlocksPendingDeletion(long blocks) { + this.translator.getBuilder().setNumOfBlocksPendingDeletion(blocks); + } + + @Override + public long getNumOfBlocksPendingDeletion() { + return this.translator.getProtoOrBuilder().getNumOfBlocksPendingDeletion(); + } + + @Override + public void setNumOfActiveDatanodes(int nodes) { + this.translator.getBuilder().setNumOfActiveDatanodes(nodes); + } + + @Override + public int getNumOfActiveDatanodes() { + return this.translator.getProtoOrBuilder().getNumOfActiveDatanodes(); + } + + @Override + public void setNumOfDeadDatanodes(int nodes) { + this.translator.getBuilder().setNumOfDeadDatanodes(nodes); + } + + @Override + public int getNumOfDeadDatanodes() { + return this.translator.getProtoOrBuilder().getNumOfDeadDatanodes(); + } + + @Override + public void setNumOfDecommissioningDatanodes(int nodes) { + this.translator.getBuilder().setNumOfDecommissioningDatanodes(nodes); + } + + @Override + public int getNumOfDecommissioningDatanodes() { + return this.translator.getProtoOrBuilder() + .getNumOfDecommissioningDatanodes(); + } + + @Override + public void setNumOfDecomActiveDatanodes(int nodes) { + this.translator.getBuilder().setNumOfDecomActiveDatanodes(nodes); + } + + @Override + public int getNumOfDecomActiveDatanodes() { + return this.translator.getProtoOrBuilder().getNumOfDecomActiveDatanodes(); + } + + @Override + public void setNumOfDecomDeadDatanodes(int nodes) { + this.translator.getBuilder().setNumOfDecomDeadDatanodes(nodes); + } + + @Override + public int getNumOfDecomDeadDatanodes() { + return this.translator.getProtoOrBuilder().getNumOfDecomDeadDatanodes(); + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org