Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,29 @@

package org.apache.hadoop.hdds.scm;

import java.util.ArrayList;
import java.util.List;

/**
* ScmInfo wraps the result returned from SCM#getScmInfo which
* contains clusterId and the SCM Id.
*/
public final class ScmInfo {
private String clusterId;
private String scmId;
private List<String> peerRoles;

/**
* Builder for ScmInfo.
*/
public static class Builder {
private String clusterId;
private String scmId;
private List<String> peerRoles;

public Builder() {
peerRoles = new ArrayList<>();
}

/**
* sets the cluster id.
Expand All @@ -53,14 +62,25 @@ public Builder setScmId(String id) {
return this;
}

/**
* Set peer address in Scm HA.
* @param roles ratis peer address in the format of [ip|hostname]:port
* @return Builder for scmInfo
*/
public Builder setRatisPeerRoles(List<String> roles) {
peerRoles.addAll(roles);
return this;
}

public ScmInfo build() {
return new ScmInfo(clusterId, scmId);
return new ScmInfo(clusterId, scmId, peerRoles);
}
}

private ScmInfo(String clusterId, String scmId) {
private ScmInfo(String clusterId, String scmId, List<String> peerRoles) {
this.clusterId = clusterId;
this.scmId = scmId;
this.peerRoles = peerRoles;
}

/**
Expand All @@ -78,4 +98,12 @@ public String getClusterId() {
public String getScmId() {
return scmId;
}

/**
* Gets the list of peer roles (currently address) in Scm HA.
* @return List of peer address
*/
public List<String> getRatisPeerRoles() {
return peerRoles;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,8 @@ Map<String, Pair<Boolean, String>> getSafeModeRuleStatuses()
*/
boolean getReplicationManagerStatus() throws IOException;


/**
* returns the list of ratis peer roles. Currently only include peer address.
*/
List<String> getScmRatisRoles() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ public ScmInfo getScmInfo() throws IOException {
.getGetScmInfoResponse();
ScmInfo.Builder builder = new ScmInfo.Builder()
.setClusterId(resp.getClusterId())
.setScmId(resp.getScmId());
.setScmId(resp.getScmId())
.setRatisPeerRoles(resp.getPeerRolesList());

return builder.build();

}
Expand Down
1 change: 1 addition & 0 deletions hadoop-hdds/interface-client/src/main/proto/hdds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ message GetScmInfoRequestProto {
message GetScmInfoResponseProto {
required string clusterId = 1;
required string scmId = 2;
repeated string peerRoles = 3;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.hadoop.hdds.scm.ha;

import java.util.List;
import org.apache.ratis.protocol.NotLeaderException;
import org.apache.ratis.protocol.RaftPeer;

Expand Down Expand Up @@ -52,6 +53,11 @@ public interface SCMHAManager {
*/
void shutdown() throws IOException;

/**
* Returns roles of ratis peers.
*/
List<String> getRatisRoles();

/**
* Returns NotLeaderException with useful info.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.hadoop.hdds.scm.ha;

import com.google.common.base.Preconditions;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.ratis.protocol.NotLeaderException;
import org.apache.ratis.protocol.RaftGroupMemberId;
Expand Down Expand Up @@ -145,6 +147,15 @@ public void shutdown() throws IOException {
ratisServer.stop();
}

@Override
public List<String> getRatisRoles() {
return getRatisServer()
.getRaftPeers()
.stream()
.map(peer -> peer.getAddress() == null ? "" : peer.getAddress())
.collect(Collectors.toList());
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ public HddsProtos.GetScmInfoResponseProto getScmInfo(
return HddsProtos.GetScmInfoResponseProto.newBuilder()
.setClusterId(scmInfo.getClusterId())
.setScmId(scmInfo.getScmId())
.addAllPeerRoles(scmInfo.getRatisPeerRoles())
.build();

}

public InSafeModeResponseProto inSafeMode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ public ScmInfo getScmInfo() throws IOException {
ScmInfo.Builder builder =
new ScmInfo.Builder()
.setClusterId(scm.getScmStorageConfig().getClusterID())
.setScmId(scm.getScmStorageConfig().getScmId());
.setScmId(scm.getScmStorageConfig().getScmId())
.setRatisPeerRoles(scm.getScmHAManager().getRatisRoles());
return builder.build();
} catch (Exception ex) {
auditSuccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,8 @@ public Map<String, String> getRuleStatusMetrics() {
}
return map;
}

public SCMHAManager getScmHAManager() {
return scmHAManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -107,6 +108,14 @@ public void shutdown() throws IOException {
ratisServer.stop();
}

@Override
public List<String> getRatisRoles() {
return Arrays.asList(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the default SCM RatisServer port. Check ratisBindPort in SCMHAConfiguration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to use the default port. In the future I will think about how to better construct MockSCMHAManager for testing purpose (as the code is evolving we can keep updating MockSCMHAManager)

"180.3.14.5:9865",
"180.3.14.21:9865",
"180.3.14.145:9865");
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,4 +508,8 @@ public boolean getReplicationManagerStatus() throws IOException {
return storageContainerLocationClient.getReplicationManagerStatus();
}

@Override
public List<String> getScmRatisRoles() throws IOException {
return storageContainerLocationClient.getScmInfo().getRatisPeerRoles();
}
}
28 changes: 28 additions & 0 deletions hadoop-ozone/dist/src/main/smoketest/admincli/scmha.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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.

*** Settings ***
Documentation Smoketest ozone cluster startup
Library OperatingSystem
Library BuiltIn
Resource ../commonlib.robot
Test Timeout 5 minutes

*** Variables ***

*** Test Cases ***
Run scm roles
${output} = Execute ozone admin scm roles
Should contain ${output} []
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.ozone.shell;

import java.net.InetSocketAddress;
import java.util.UUID;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.ScmConfigKeys;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.admin.OzoneAdmin;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* This class tests ozone admin scm commands.
*/
public class TestScmAdminHA {
private static OzoneAdmin ozoneAdmin;
private static OzoneConfiguration conf;
private static String omServiceId;
private static int numOfOMs;
private static String clusterId;
private static String scmId;
private static MiniOzoneCluster cluster;

@BeforeClass
public static void init() throws Exception {
ozoneAdmin = new OzoneAdmin();
conf = new OzoneConfiguration();

// Init HA cluster
omServiceId = "om-service-test1";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean SCM here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I meant OM. It turns out that I cannot ignore omServiceId to start the cluster (there is a check for this service id).

numOfOMs = 3;
clusterId = UUID.randomUUID().toString();
scmId = UUID.randomUUID().toString();
cluster = MiniOzoneCluster.newHABuilder(conf)
.setClusterId(clusterId)
.setScmId(scmId)
.setOMServiceId(omServiceId)
.setNumOfOzoneManagers(numOfOMs)
.build();
conf.setQuietMode(false);
// enable ratis for Scm.
conf.setBoolean(ScmConfigKeys.DFS_CONTAINER_RATIS_ENABLED_KEY, true);
cluster.waitForClusterToBeReady();
}

@AfterClass
public static void shutdown() {
if (cluster != null) {
cluster.shutdown();
}
}

@Test
public void testGetRatisRoles() {
InetSocketAddress address =
cluster.getStorageContainerManager().getClientRpcAddress();
String hostPort = address.getHostName() + ":" + address.getPort();
String[] args = {"--scm", hostPort, "scm", "roles"};
ozoneAdmin.execute(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hadoop.hdds.scm.cli.pipeline.PipelineCommands;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import org.apache.hadoop.ozone.admin.om.OMAdmin;
import org.apache.hadoop.ozone.admin.scm.ScmAdmin;
import org.apache.hadoop.util.NativeCodeLoader;

import org.apache.commons.lang3.StringUtils;
Expand All @@ -56,6 +57,7 @@
versionProvider = HddsVersionProvider.class,
subcommands = {
OMAdmin.class,
ScmAdmin.class,
SafeModeCommands.class,
ContainerCommands.class,
PipelineCommands.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.ozone.admin.scm;

import java.util.List;
import java.util.concurrent.Callable;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.scm.client.ScmClient;
import picocli.CommandLine;

/**
* Handler of scm status command.
*/
@CommandLine.Command(
name = "roles",
description = "List all SCMs and their respective Ratis server roles",
mixinStandardHelpOptions = true,
versionProvider = HddsVersionProvider.class)
public class GetScmRatisRolesSubcommand implements Callable<Void> {

@CommandLine.ParentCommand
private ScmAdmin parent;

@Override
public Void call() throws Exception {
ScmClient scmClient = parent.createScmClient();
List<String> roles = scmClient.getScmRatisRoles();
System.out.println(roles);
return null;
}
}
Loading