Skip to content

Commit f267917

Browse files
xiaoyuyaobharatviswa504
authored andcommitted
HDDS-2282. scmcli pipeline list command throws NullPointerException. Contributed by Xiaoyu Yao. (#1642)
1 parent 9c72bf4 commit f267917

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/XceiverClientManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ public class XceiverClientManager implements Closeable {
7878
private boolean isSecurityEnabled;
7979
private final boolean topologyAwareRead;
8080
/**
81-
* Creates a new XceiverClientManager.
81+
* Creates a new XceiverClientManager for non secured ozone cluster.
82+
* For security enabled ozone cluster, client should use the other constructor
83+
* with a valid ca certificate in pem string format.
8284
*
8385
* @param conf configuration
8486
*/

hadoop-hdds/tools/src/main/java/org/apache/hadoop/hdds/scm/cli/SCMCLI.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.hadoop.hdds.cli.GenericCli;
2626
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
2727
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
28+
import org.apache.hadoop.hdds.protocol.SCMSecurityProtocol;
2829
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
2930
import org.apache.hadoop.hdds.scm.XceiverClientManager;
3031
import org.apache.hadoop.hdds.scm.cli.container.ContainerCommands;
@@ -36,17 +37,20 @@
3637
import org.apache.hadoop.hdds.scm.protocolPB
3738
.StorageContainerLocationProtocolClientSideTranslatorPB;
3839
import org.apache.hadoop.hdds.scm.protocolPB.StorageContainerLocationProtocolPB;
40+
import org.apache.hadoop.hdds.security.x509.SecurityConfig;
3941
import org.apache.hadoop.hdds.tracing.TracingUtil;
4042
import org.apache.hadoop.ipc.Client;
4143
import org.apache.hadoop.ipc.ProtobufRpcEngine;
4244
import org.apache.hadoop.ipc.RPC;
4345
import org.apache.hadoop.net.NetUtils;
4446
import org.apache.hadoop.ozone.OzoneConsts;
47+
import org.apache.hadoop.ozone.OzoneSecurityUtil;
4548
import org.apache.hadoop.security.UserGroupInformation;
4649
import org.apache.hadoop.util.NativeCodeLoader;
4750

4851
import org.apache.commons.lang3.StringUtils;
4952
import static org.apache.hadoop.hdds.HddsUtils.getScmAddressForClients;
53+
import static org.apache.hadoop.hdds.HddsUtils.getScmSecurityClient;
5054
import static org.apache.hadoop.hdds.scm.ScmConfigKeys
5155
.OZONE_SCM_CLIENT_ADDRESS_KEY;
5256
import static org.apache.hadoop.hdds.scm.ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE;
@@ -136,8 +140,21 @@ public ScmClient createScmClient()
136140
NetUtils.getDefaultSocketFactory(ozoneConf),
137141
Client.getRpcTimeout(ozoneConf))),
138142
StorageContainerLocationProtocol.class, ozoneConf);
139-
return new ContainerOperationClient(
140-
client, new XceiverClientManager(ozoneConf));
143+
144+
XceiverClientManager xceiverClientManager = null;
145+
if (OzoneSecurityUtil.isSecurityEnabled(ozoneConf)) {
146+
SecurityConfig securityConfig = new SecurityConfig(ozoneConf);
147+
SCMSecurityProtocol scmSecurityProtocolClient = getScmSecurityClient(
148+
(OzoneConfiguration) securityConfig.getConfiguration());
149+
String caCertificate =
150+
scmSecurityProtocolClient.getCACertificate();
151+
xceiverClientManager = new XceiverClientManager(ozoneConf,
152+
OzoneConfiguration.of(ozoneConf).getObject(XceiverClientManager
153+
.ScmClientConfig.class), caCertificate);
154+
} else {
155+
xceiverClientManager = new XceiverClientManager(ozoneConf);
156+
}
157+
return new ContainerOperationClient(client, xceiverClientManager);
141158
}
142159

143160
public void checkContainerExists(ScmClient scmClient, long containerId)

hadoop-ozone/dist/src/main/compose/ozonesecure/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ execute_robot_test scm ozonefs/ozonefs.robot
3535

3636
execute_robot_test s3g s3
3737

38+
execute_robot_test scm scmcli
39+
3840
stop_docker_env
3941

4042
generate_report
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
*** Settings ***
17+
Documentation Smoketest ozone cluster startup
18+
Library OperatingSystem
19+
Library BuiltIn
20+
Resource ../commonlib.robot
21+
22+
*** Variables ***
23+
24+
25+
*** Test Cases ***
26+
Run list pipeline
27+
${output} = Execute ozone scmcli pipeline list
28+
Should contain ${output} Type:RATIS, Factor:ONE, State:OPEN

0 commit comments

Comments
 (0)