Skip to content
Permalink
Browse files
Do not proceed with cluster creation if addCluster() fails. (#2068)
In Helix-Tools - ClusterSetup::addCluster() doesn't check return value
of HelixAdmin::addCluster() method. It proceeds even when the call
returns failure.
Check the return status of addCluster() and throw an exception if cluster creation fails.
  • Loading branch information
desaikomal committed Apr 27, 2022
1 parent 8824d22 commit b129bd664faae24f21aeb6c9e076153cc88e3635
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
@@ -223,7 +223,11 @@ public void finalize() {

public void addCluster(String clusterName, boolean overwritePrevious, CloudConfig cloudConfig)
throws HelixException {
_admin.addCluster(clusterName, overwritePrevious);
if (!_admin.addCluster(clusterName, overwritePrevious)) {
String error = "Cluster creation failed for " + clusterName;
_logger.error(error);
throw new HelixException(error);
}
for (BuiltInStateModelDefinitions def : BuiltInStateModelDefinitions.values()) {
addStateModelDef(clusterName, def.getStateModelDefinition().getId(),
def.getStateModelDefinition(), overwritePrevious);
@@ -26,6 +26,7 @@

import org.apache.helix.BaseDataAccessor;
import org.apache.helix.ConfigAccessor;
import org.apache.helix.HelixAdmin;
import org.apache.helix.HelixDataAccessor;
import org.apache.helix.HelixException;
import org.apache.helix.PropertyKey;
@@ -53,6 +54,10 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestClusterSetup extends ZkUnitTestBase {
protected static final String CLUSTER_NAME = "TestClusterSetup";
@@ -519,6 +524,28 @@ public void testAddClusterWithValidCloudConfig() throws Exception {
Assert.assertEquals(cloudConfigFromZk.getCloudProvider(), CloudProvider.CUSTOMIZED.name());
}

@Test(dependsOnMethods = "testAddClusterWithInvalidCloudConfig",
expectedExceptions = HelixException.class)
public void testAddClusterWithFailure() throws Exception {
HelixAdmin admin = mock(HelixAdmin.class);
when(admin.addCluster(anyString(), anyBoolean())).thenReturn(Boolean.FALSE);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;

CloudConfig.Builder cloudConfigInitBuilder = new CloudConfig.Builder();
cloudConfigInitBuilder.setCloudEnabled(true);
List<String> sourceList = new ArrayList<String>();
sourceList.add("TestURL");
cloudConfigInitBuilder.setCloudInfoSources(sourceList);
cloudConfigInitBuilder.setCloudProvider(CloudProvider.CUSTOMIZED);

CloudConfig cloudConfigInit = cloudConfigInitBuilder.build();

// Since setCloudInfoProcessorName is missing, this add cluster call will throw an exception
_clusterSetup.addCluster(clusterName, false, cloudConfigInit);
}

@Test(dependsOnMethods = "testAddClusterWithValidCloudConfig")
public void testAddClusterAzureProvider() throws Exception {
String className = TestHelper.getTestClassName();

0 comments on commit b129bd6

Please sign in to comment.