HDFS-13348. Ozone: Update IP and hostname in Datanode from SCM's response to the register call. Contributed by Shashikant Banerjee.
This commit is contained in:
parent
12d80f8cae
commit
aae3ba24ca
@ -20,9 +20,10 @@
|
|||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
|
||||||
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
|
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
|
||||||
import org.apache.hadoop.hdds.protocol.proto.HddsProtos.DatanodeDetailsProto;
|
|
||||||
import org.apache.hadoop.ozone.container.common.statemachine
|
import org.apache.hadoop.ozone.container.common.statemachine
|
||||||
.EndpointStateMachine;
|
.EndpointStateMachine;
|
||||||
|
import org.apache.hadoop.hdds.protocol.proto
|
||||||
|
.StorageContainerDatanodeProtocolProtos.SCMRegisteredCmdResponseProto;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ public final class RegisterEndpointTask implements
|
|||||||
private final EndpointStateMachine rpcEndPoint;
|
private final EndpointStateMachine rpcEndPoint;
|
||||||
private final Configuration conf;
|
private final Configuration conf;
|
||||||
private Future<EndpointStateMachine.EndPointStates> result;
|
private Future<EndpointStateMachine.EndPointStates> result;
|
||||||
private DatanodeDetailsProto datanodeDetailsProto;
|
private DatanodeDetails datanodeDetails;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a register endpoint task.
|
* Creates a register endpoint task.
|
||||||
@ -57,22 +58,22 @@ public RegisterEndpointTask(EndpointStateMachine rpcEndPoint,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the DatanodeDetailsProto Proto.
|
* Get the DatanodeDetails.
|
||||||
*
|
*
|
||||||
* @return DatanodeDetailsProto
|
* @return DatanodeDetailsProto
|
||||||
*/
|
*/
|
||||||
public DatanodeDetailsProto getDatanodeDetailsProto() {
|
public DatanodeDetails getDatanodeDetails() {
|
||||||
return datanodeDetailsProto;
|
return datanodeDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the contiainerNodeID Proto.
|
* Set the contiainerNodeID Proto.
|
||||||
*
|
*
|
||||||
* @param datanodeDetailsProto - Container Node ID.
|
* @param datanodeDetails - Container Node ID.
|
||||||
*/
|
*/
|
||||||
public void setDatanodeDetailsProto(
|
public void setDatanodeDetails(
|
||||||
DatanodeDetailsProto datanodeDetailsProto) {
|
DatanodeDetails datanodeDetails) {
|
||||||
this.datanodeDetailsProto = datanodeDetailsProto;
|
this.datanodeDetails = datanodeDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,8 +85,8 @@ public void setDatanodeDetailsProto(
|
|||||||
@Override
|
@Override
|
||||||
public EndpointStateMachine.EndPointStates call() throws Exception {
|
public EndpointStateMachine.EndPointStates call() throws Exception {
|
||||||
|
|
||||||
if (getDatanodeDetailsProto() == null) {
|
if (getDatanodeDetails() == null) {
|
||||||
LOG.error("Container ID proto cannot be null in RegisterEndpoint task, " +
|
LOG.error("DatanodeDetails cannot be null in RegisterEndpoint task, " +
|
||||||
"shutting down the endpoint.");
|
"shutting down the endpoint.");
|
||||||
return rpcEndPoint.setState(EndpointStateMachine.EndPointStates.SHUTDOWN);
|
return rpcEndPoint.setState(EndpointStateMachine.EndPointStates.SHUTDOWN);
|
||||||
}
|
}
|
||||||
@ -94,8 +95,13 @@ public EndpointStateMachine.EndPointStates call() throws Exception {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
// TODO : Add responses to the command Queue.
|
// TODO : Add responses to the command Queue.
|
||||||
rpcEndPoint.getEndPoint().register(datanodeDetailsProto,
|
SCMRegisteredCmdResponseProto response = rpcEndPoint.getEndPoint()
|
||||||
conf.getStrings(ScmConfigKeys.OZONE_SCM_NAMES));
|
.register(datanodeDetails.getProtoBufMessage(),
|
||||||
|
conf.getStrings(ScmConfigKeys.OZONE_SCM_NAMES));
|
||||||
|
if (response.hasHostname() && response.hasIpAddress()) {
|
||||||
|
datanodeDetails.setHostName(response.getHostname());
|
||||||
|
datanodeDetails.setIpAddress(response.getIpAddress());
|
||||||
|
}
|
||||||
EndpointStateMachine.EndPointStates nextState =
|
EndpointStateMachine.EndPointStates nextState =
|
||||||
rpcEndPoint.getState().getNextState();
|
rpcEndPoint.getState().getNextState();
|
||||||
rpcEndPoint.setState(nextState);
|
rpcEndPoint.setState(nextState);
|
||||||
@ -187,7 +193,7 @@ public RegisterEndpointTask build() {
|
|||||||
|
|
||||||
RegisterEndpointTask task = new RegisterEndpointTask(this
|
RegisterEndpointTask task = new RegisterEndpointTask(this
|
||||||
.endPointStateMachine, this.conf);
|
.endPointStateMachine, this.conf);
|
||||||
task.setDatanodeDetailsProto(datanodeDetails.getProtoBufMessage());
|
task.setDatanodeDetails(datanodeDetails);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,20 @@ public class RegisteredCommand extends
|
|||||||
private String datanodeUUID;
|
private String datanodeUUID;
|
||||||
private String clusterID;
|
private String clusterID;
|
||||||
private ErrorCode error;
|
private ErrorCode error;
|
||||||
|
private String hostname;
|
||||||
|
private String ipAddress;
|
||||||
|
|
||||||
public RegisteredCommand(final ErrorCode error, final String datanodeUUID,
|
public RegisteredCommand(final ErrorCode error, final String datanodeUUID,
|
||||||
final String clusterID) {
|
final String clusterID) {
|
||||||
|
this(error, datanodeUUID, clusterID, null, null);
|
||||||
|
}
|
||||||
|
public RegisteredCommand(final ErrorCode error, final String datanodeUUID,
|
||||||
|
final String clusterID, final String hostname, final String ipAddress) {
|
||||||
this.datanodeUUID = datanodeUUID;
|
this.datanodeUUID = datanodeUUID;
|
||||||
this.clusterID = clusterID;
|
this.clusterID = clusterID;
|
||||||
this.error = error;
|
this.error = error;
|
||||||
|
this.hostname = hostname;
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,6 +96,22 @@ public ErrorCode getError() {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hostname.
|
||||||
|
*
|
||||||
|
* @return - hostname
|
||||||
|
*/
|
||||||
|
public String getHostName() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ipAddress of the dataNode.
|
||||||
|
*/
|
||||||
|
public String getIpAddress() {
|
||||||
|
return ipAddress;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the protobuf message of this object.
|
* Gets the protobuf message of this object.
|
||||||
*
|
*
|
||||||
@ -95,11 +119,15 @@ public ErrorCode getError() {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] getProtoBufMessage() {
|
public byte[] getProtoBufMessage() {
|
||||||
return SCMRegisteredCmdResponseProto.newBuilder()
|
SCMRegisteredCmdResponseProto.Builder builder =
|
||||||
.setClusterID(this.clusterID)
|
SCMRegisteredCmdResponseProto.newBuilder()
|
||||||
.setDatanodeUUID(this.datanodeUUID)
|
.setClusterID(this.clusterID)
|
||||||
.setErrorCode(this.error)
|
.setDatanodeUUID(this.datanodeUUID)
|
||||||
.build().toByteArray();
|
.setErrorCode(this.error);
|
||||||
|
if (hostname != null && ipAddress != null) {
|
||||||
|
builder.setHostname(hostname).setIpAddress(ipAddress);
|
||||||
|
}
|
||||||
|
return builder.build().toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -109,6 +137,8 @@ public static class Builder {
|
|||||||
private String datanodeUUID;
|
private String datanodeUUID;
|
||||||
private String clusterID;
|
private String clusterID;
|
||||||
private ErrorCode error;
|
private ErrorCode error;
|
||||||
|
private String ipAddress;
|
||||||
|
private String hostname;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sets UUID.
|
* sets UUID.
|
||||||
@ -130,9 +160,16 @@ public Builder setDatanodeUUID(String dnUUID) {
|
|||||||
public RegisteredCommand getFromProtobuf(SCMRegisteredCmdResponseProto
|
public RegisteredCommand getFromProtobuf(SCMRegisteredCmdResponseProto
|
||||||
response) {
|
response) {
|
||||||
Preconditions.checkNotNull(response);
|
Preconditions.checkNotNull(response);
|
||||||
return new RegisteredCommand(response.getErrorCode(),
|
if (response.hasHostname() && response.hasIpAddress()) {
|
||||||
response.hasDatanodeUUID() ? response.getDatanodeUUID(): "",
|
return new RegisteredCommand(response.getErrorCode(),
|
||||||
response.hasClusterID() ? response.getClusterID(): "");
|
response.hasDatanodeUUID() ? response.getDatanodeUUID() : "",
|
||||||
|
response.hasClusterID() ? response.getClusterID() : "",
|
||||||
|
response.getHostname(), response.getIpAddress());
|
||||||
|
} else {
|
||||||
|
return new RegisteredCommand(response.getErrorCode(),
|
||||||
|
response.hasDatanodeUUID() ? response.getDatanodeUUID() : "",
|
||||||
|
response.hasClusterID() ? response.getClusterID() : "");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -157,21 +194,38 @@ public Builder setErrorCode(ErrorCode errorCode) {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the hostname.
|
||||||
|
*/
|
||||||
|
public Builder setHostname(String hostname) {
|
||||||
|
this.hostname = hostname;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setIpAddress(String ipAddress) {
|
||||||
|
this.ipAddress = ipAddress;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the command object.
|
* Build the command object.
|
||||||
*
|
*
|
||||||
* @return RegisteredCommand
|
* @return RegisteredCommand
|
||||||
*/
|
*/
|
||||||
public RegisteredCommand build() {
|
public RegisteredCommand build() {
|
||||||
if ((this.error == ErrorCode.success) &&
|
if ((this.error == ErrorCode.success) && (this.datanodeUUID == null
|
||||||
(this.datanodeUUID == null || this.datanodeUUID.isEmpty()) ||
|
|| this.datanodeUUID.isEmpty()) || (this.clusterID == null
|
||||||
(this.clusterID == null || this.clusterID.isEmpty())) {
|
|| this.clusterID.isEmpty())) {
|
||||||
throw new IllegalArgumentException("On success, RegisteredCommand " +
|
throw new IllegalArgumentException("On success, RegisteredCommand "
|
||||||
"needs datanodeUUID and ClusterID.");
|
+ "needs datanodeUUID and ClusterID.");
|
||||||
|
}
|
||||||
|
if (hostname != null && ipAddress != null) {
|
||||||
|
return new RegisteredCommand(this.error, this.datanodeUUID,
|
||||||
|
this.clusterID, this.hostname, this.ipAddress);
|
||||||
|
} else {
|
||||||
|
return new RegisteredCommand(this.error, this.datanodeUUID,
|
||||||
|
this.clusterID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new
|
|
||||||
RegisteredCommand(this.error, this.datanodeUUID, this.clusterID);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,8 @@ message SCMRegisteredCmdResponseProto {
|
|||||||
optional string datanodeUUID = 3;
|
optional string datanodeUUID = 3;
|
||||||
optional string clusterID = 4;
|
optional string clusterID = 4;
|
||||||
optional SCMNodeAddressList addressList = 5;
|
optional SCMNodeAddressList addressList = 5;
|
||||||
|
optional string hostname = 6;
|
||||||
|
optional string ipAddress = 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -745,13 +745,15 @@ public VersionResponse getVersion(SCMVersionRequestProto versionRequest) {
|
|||||||
@Override
|
@Override
|
||||||
public SCMCommand register(DatanodeDetailsProto datanodeDetailsProto) {
|
public SCMCommand register(DatanodeDetailsProto datanodeDetailsProto) {
|
||||||
|
|
||||||
|
String hostname = null;
|
||||||
|
String ip = null;
|
||||||
DatanodeDetails datanodeDetails = DatanodeDetails.getFromProtoBuf(
|
DatanodeDetails datanodeDetails = DatanodeDetails.getFromProtoBuf(
|
||||||
datanodeDetailsProto);
|
datanodeDetailsProto);
|
||||||
InetAddress dnAddress = Server.getRemoteIp();
|
InetAddress dnAddress = Server.getRemoteIp();
|
||||||
if (dnAddress != null) {
|
if (dnAddress != null) {
|
||||||
// Mostly called inside an RPC, update ip and peer hostname
|
// Mostly called inside an RPC, update ip and peer hostname
|
||||||
String hostname = dnAddress.getHostName();
|
hostname = dnAddress.getHostName();
|
||||||
String ip = dnAddress.getHostAddress();
|
ip = dnAddress.getHostAddress();
|
||||||
datanodeDetails.setHostName(hostname);
|
datanodeDetails.setHostName(hostname);
|
||||||
datanodeDetails.setIpAddress(ip);
|
datanodeDetails.setIpAddress(ip);
|
||||||
}
|
}
|
||||||
@ -788,11 +790,14 @@ public SCMCommand register(DatanodeDetailsProto datanodeDetailsProto) {
|
|||||||
}
|
}
|
||||||
LOG.info("Data node with ID: {} Registered.",
|
LOG.info("Data node with ID: {} Registered.",
|
||||||
datanodeDetails.getUuid());
|
datanodeDetails.getUuid());
|
||||||
return RegisteredCommand.newBuilder()
|
RegisteredCommand.Builder builder =
|
||||||
.setErrorCode(ErrorCode.success)
|
RegisteredCommand.newBuilder().setErrorCode(ErrorCode.success)
|
||||||
.setDatanodeUUID(datanodeDetails.getUuidString())
|
.setDatanodeUUID(datanodeDetails.getUuidString())
|
||||||
.setClusterID(this.clusterID)
|
.setClusterID(this.clusterID);
|
||||||
.build();
|
if (hostname != null && ip != null) {
|
||||||
|
builder.setHostname(hostname).setIpAddress(ip);
|
||||||
|
}
|
||||||
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,9 +228,7 @@ private EndpointStateMachine registerTaskHelper(InetSocketAddress scmAddress,
|
|||||||
new RegisterEndpointTask(rpcEndPoint, conf);
|
new RegisterEndpointTask(rpcEndPoint, conf);
|
||||||
if (!clearDatanodeDetails) {
|
if (!clearDatanodeDetails) {
|
||||||
DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
|
DatanodeDetails datanodeDetails = TestUtils.getDatanodeDetails();
|
||||||
HddsProtos.DatanodeDetailsProto datanodeDetailsProto =
|
endpointTask.setDatanodeDetails(datanodeDetails);
|
||||||
datanodeDetails.getProtoBufMessage();
|
|
||||||
endpointTask.setDatanodeDetailsProto(datanodeDetailsProto);
|
|
||||||
}
|
}
|
||||||
endpointTask.call();
|
endpointTask.call();
|
||||||
return rpcEndPoint;
|
return rpcEndPoint;
|
||||||
|
Loading…
Reference in New Issue
Block a user