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 @@ -121,20 +121,20 @@ public Optional<FailureDomainImpl> getFailureDomain(String clusterName, String d

public void deleteFailureDomain(String clusterName, String domainName) throws MetadataStoreException {
String path = joinPath(BASE_CLUSTERS_PATH, clusterName, FAILURE_DOMAIN, domainName);
if (exists(path)) {
delete(path);
}
delete(path);
}

public void deleteFailureDomains(String clusterName) throws MetadataStoreException {
String failureDomainPath = joinPath(BASE_CLUSTERS_PATH, clusterName, FAILURE_DOMAIN);
if (!exists(failureDomainPath)) {
return;
}

for (String domain : getChildren(failureDomainPath)) {
delete(joinPath(failureDomainPath, domain));
}

if (exists(failureDomainPath)) {
delete(failureDomainPath);
}
delete(failureDomainPath);
}

public void setFailureDomainWithCreate(String clusterName, String domainName,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* 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.pulsar.broker.admin;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;

import com.google.common.collect.Sets;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest;
import org.apache.pulsar.client.admin.PulsarAdminException;
import org.apache.pulsar.common.policies.data.ClusterData;
import org.apache.pulsar.common.policies.data.FailureDomain;
import org.awaitility.Awaitility;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

@Test(groups = "broker")
@Slf4j
public class AdminApiClusterTest extends MockedPulsarServiceBaseTest {
private final String CLUSTER = "test";

@BeforeMethod
@Override
public void setup() throws Exception {
resetConfig();
super.internalSetup();
admin.clusters()
.createCluster(CLUSTER, ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
}

@AfterMethod(alwaysRun = true)
@Override
public void cleanup() throws Exception {
super.internalCleanup();
}

@Test
public void testDeleteNonExistCluster() {
String cluster = "test-non-exist-cluster-" + UUID.randomUUID();

assertThrows(PulsarAdminException.NotFoundException.class, () -> admin.clusters().deleteCluster(cluster));
}

@Test
public void testDeleteExistCluster() throws PulsarAdminException {
String cluster = "test-exist-cluster-" + UUID.randomUUID();

admin.clusters()
.createCluster(cluster, ClusterData.builder().serviceUrl(pulsar.getWebServiceAddress()).build());
Awaitility.await().untilAsserted(() -> assertNotNull(admin.clusters().getCluster(cluster)));

admin.clusters().deleteCluster(cluster);
}

@Test
public void testDeleteNonExistentFailureDomain() {
assertThrows(PulsarAdminException.NotFoundException.class,
() -> admin.clusters().deleteFailureDomain(CLUSTER, "non-existent-failure-domain"));
}

@Test
public void testDeleteNonExistentFailureDomainInNonExistCluster() {
assertThrows(PulsarAdminException.PreconditionFailedException.class,
() -> admin.clusters().deleteFailureDomain(CLUSTER + UUID.randomUUID(),
"non-existent-failure-domain"));
}

@Test
public void testDeleteExistFailureDomain() throws PulsarAdminException {
String domainName = CLUSTER + "-failure-domain";
FailureDomain domain = FailureDomain.builder()
.brokers(Sets.newHashSet("b1", "b2", "b3"))
.build();
admin.clusters().createFailureDomain(CLUSTER, domainName, domain);
Awaitility.await().untilAsserted(() -> admin.clusters().getFailureDomain(CLUSTER, domainName));

admin.clusters().deleteFailureDomain(CLUSTER, domainName);
}
}