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 @@ -351,11 +351,18 @@ public void testForceBootstrap() throws Exception {
@Test
public void testDecommission() throws Exception {
setupCluster(3);
user = UserGroupInformation.getCurrentUser();

// Stop the 3rd OM and decommission it
user = UserGroupInformation.createUserForTesting("user", new String[]{});
// Stop the 3rd OM and decommission it using non-privileged user
String omNodeId3 = cluster.getOzoneManager(2).getOMNodeId();
cluster.stopOzoneManager(omNodeId3);
// decommission should fail
assertThrows(IOException.class, () -> decommissionOM(omNodeId3));

// Switch to admin user
user = UserGroupInformation.getCurrentUser();
// Stop the 3rd OM and decommission it
cluster.stopOzoneManager(omNodeId3);
decommissionOM(omNodeId3);

// Decommission the non leader OM and then stop it. Stopping OM before will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@

package org.apache.hadoop.ozone.protocolPB;

import static org.apache.hadoop.hdds.utils.HddsServerUtil.getRemoteUser;
import static org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.PERMISSION_DENIED;

import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.ozone.om.OzoneManager;
import org.apache.hadoop.ozone.om.exceptions.OMException;
import org.apache.hadoop.ozone.om.helpers.OMNodeDetails;
import org.apache.hadoop.ozone.om.protocolPB.OMAdminProtocolPB;
import org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer;
Expand Down Expand Up @@ -89,6 +93,9 @@ public DecommissionOMResponse decommission(RpcController controller,
}

try {
if (!ozoneManager.isAdmin(getRemoteUser())) {
throw new OMException("Only administrators are authorized to perform decommission.", PERMISSION_DENIED);
}
omRatisServer.removeOMFromRatisRing(decommNode);
} catch (IOException ex) {
return DecommissionOMResponse.newBuilder()
Expand Down