HDDS-1694. TestNodeReportHandler is failing with NPE

Closes #978
This commit is contained in:
Márton Elek 2019-06-18 08:46:20 +02:00
parent dd4a7633ec
commit e188bb12b0
No known key found for this signature in database
GPG Key ID: D51EA8F00EE79B28
4 changed files with 25 additions and 17 deletions

View File

@ -30,7 +30,7 @@
import org.apache.hadoop.hdds.scm.pipeline.PipelineID;
import org.apache.hadoop.hdds.scm.node.states.NodeAlreadyExistsException;
import org.apache.hadoop.hdds.scm.node.states.NodeNotFoundException;
import org.apache.hadoop.hdds.scm.server.StorageContainerManager;
import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
import org.apache.hadoop.hdds.scm.VersionInfo;
import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric;
import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeStat;
@ -94,13 +94,12 @@ public class SCMNodeManager implements NodeManager {
LoggerFactory.getLogger(SCMNodeManager.class);
private final NodeStateManager nodeStateManager;
private final String clusterID;
private final VersionInfo version;
private final CommandQueue commandQueue;
private final SCMNodeMetrics metrics;
// Node manager MXBean
private ObjectName nmInfoBean;
private final StorageContainerManager scmManager;
private final SCMStorageConfig scmStorageConfig;
private final NetworkTopology clusterMap;
private final DNSToSwitchMapping dnsToSwitchMapping;
private final boolean useHostname;
@ -108,18 +107,17 @@ public class SCMNodeManager implements NodeManager {
/**
* Constructs SCM machine Manager.
*/
public SCMNodeManager(OzoneConfiguration conf, String clusterID,
StorageContainerManager scmManager, EventPublisher eventPublisher)
throws IOException {
public SCMNodeManager(OzoneConfiguration conf,
SCMStorageConfig scmStorageConfig, EventPublisher eventPublisher,
NetworkTopology networkTopology) {
this.nodeStateManager = new NodeStateManager(conf, eventPublisher);
this.clusterID = clusterID;
this.version = VersionInfo.getLatestVersion();
this.commandQueue = new CommandQueue();
this.scmManager = scmManager;
this.scmStorageConfig = scmStorageConfig;
LOG.info("Entering startup safe mode.");
registerMXBean();
this.metrics = SCMNodeMetrics.create(this);
this.clusterMap = scmManager.getClusterMap();
this.clusterMap = networkTopology;
Class<? extends DNSToSwitchMapping> dnsToSwitchMappingClass =
conf.getClass(DFSConfigKeys.NET_TOPOLOGY_NODE_SWITCH_MAPPING_IMPL_KEY,
TableMapping.class, DNSToSwitchMapping.class);
@ -221,9 +219,8 @@ public VersionResponse getVersion(SCMVersionRequestProto versionRequest) {
return VersionResponse.newBuilder()
.setVersion(this.version.getVersion())
.addValue(OzoneConsts.SCM_ID,
this.scmManager.getScmStorageConfig().getScmId())
.addValue(OzoneConsts.CLUSTER_ID, this.scmManager.getScmStorageConfig()
.getClusterID())
this.scmStorageConfig.getScmId())
.addValue(OzoneConsts.CLUSTER_ID, this.scmStorageConfig.getClusterID())
.build();
}
@ -274,7 +271,7 @@ public RegisteredCommand register(
return RegisteredCommand.newBuilder().setErrorCode(ErrorCode.success)
.setDatanodeUUID(datanodeDetails.getUuidString())
.setClusterID(this.clusterID)
.setClusterID(this.scmStorageConfig.getClusterID())
.setHostname(datanodeDetails.getHostName())
.setIpAddress(datanodeDetails.getIpAddress())
.build();

View File

@ -378,7 +378,7 @@ private void initializeSystemManagers(OzoneConfiguration conf,
scmNodeManager = configurator.getScmNodeManager();
} else {
scmNodeManager = new SCMNodeManager(
conf, scmStorageConfig.getClusterID(), this, eventQueue);
conf, scmStorageConfig, eventQueue, clusterMap);
}
ContainerPlacementPolicy containerPlacementPolicy =

View File

@ -36,6 +36,7 @@
import org.apache.hadoop.hdds.scm.events.SCMEvents;
import org.apache.hadoop.hdds.scm.pipeline.PipelineManager;
import org.apache.hadoop.hdds.scm.pipeline.SCMPipelineManager;
import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
import org.apache.hadoop.hdds.server.events.EventQueue;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.test.PathUtils;
@ -48,7 +49,6 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
import static org.apache.hadoop.hdds.scm.ScmConfigKeys
@ -94,8 +94,12 @@ SCMNodeManager createNodeManager(OzoneConfiguration config)
Mockito.mock(StaleNodeHandler.class));
eventQueue.addHandler(SCMEvents.DEAD_NODE,
Mockito.mock(DeadNodeHandler.class));
SCMStorageConfig storageConfig = Mockito.mock(SCMStorageConfig.class);
Mockito.when(storageConfig.getClusterID()).thenReturn("cluster1");
SCMNodeManager nodeManager = new SCMNodeManager(config,
UUID.randomUUID().toString(), null, eventQueue);
storageConfig, eventQueue, null);
return nodeManager;
}

View File

@ -24,7 +24,9 @@
import org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto;
import org.apache.hadoop.hdds.scm.TestUtils;
import org.apache.hadoop.hdds.scm.container.placement.metrics.SCMNodeMetric;
import org.apache.hadoop.hdds.scm.net.NetworkTopology;
import org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.NodeReportFromDatanode;
import org.apache.hadoop.hdds.scm.server.SCMStorageConfig;
import org.apache.hadoop.hdds.server.events.Event;
import org.apache.hadoop.hdds.server.events.EventPublisher;
import org.apache.hadoop.hdds.server.events.EventQueue;
@ -32,6 +34,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -50,7 +53,11 @@ public class TestNodeReportHandler implements EventPublisher {
@Before
public void resetEventCollector() throws IOException {
OzoneConfiguration conf = new OzoneConfiguration();
nodeManager = new SCMNodeManager(conf, "cluster1", null, new EventQueue());
SCMStorageConfig storageConfig = Mockito.mock(SCMStorageConfig.class);
Mockito.when(storageConfig.getClusterID()).thenReturn("cluster1");
nodeManager =
new SCMNodeManager(conf, storageConfig, new EventQueue(), Mockito.mock(
NetworkTopology.class));
nodeReportHandler = new NodeReportHandler(nodeManager);
}