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 @@ -39,6 +39,7 @@
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_HTTP_SCHEME;
import static org.apache.hadoop.ozone.OzoneConsts.OZONE_RPC_SCHEME;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_ADDRESS_KEY;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_INTERNAL_SERVICE_ID;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
import org.apache.http.client.utils.URIBuilder;

Expand Down Expand Up @@ -157,21 +158,23 @@ public OzoneClient createClient(MutableConfigurationSource conf)
ozoneURI.getPort(), conf);
}
} else { // When host is not specified

Collection<String> omServiceIds = conf.getTrimmedStringCollection(
OZONE_OM_SERVICE_IDS_KEY);

if (omServiceIds.size() > 1) {
throw new OzoneClientException("Service ID or host name must not"
+ " be omitted when multiple ozone.om.service.ids is defined.");
} else if (omServiceIds.size() == 1) {
client = createRpcClientFromServiceId(omServiceIds.iterator().next(),
conf);
String localOmServiceId = conf.getTrimmed(OZONE_OM_INTERNAL_SERVICE_ID);
if (localOmServiceId == null) {
Collection<String> omServiceIds = conf.getTrimmedStringCollection(
OZONE_OM_SERVICE_IDS_KEY);
if (omServiceIds.size() > 1) {
throw new OzoneClientException("Service ID or host name must not"
+ " be omitted when multiple ozone.om.service.ids is defined.");
} else if (omServiceIds.size() == 1) {
client = createRpcClientFromServiceId(omServiceIds.iterator().next(),
conf);
} else {
client = createRpcClient(conf);
}
} else {
client = createRpcClient(conf);
client = createRpcClientFromServiceId(localOmServiceId, conf);
}
}

return client;
}

Expand All @@ -194,24 +197,28 @@ public OzoneClient createClientForS3Commands(
if (omServiceID != null) {
// OM HA cluster
if (OmUtils.isOmHAServiceId(conf, omServiceID)) {
return OzoneClientFactory.getRpcClient(omServiceID, conf);
return createRpcClientFromServiceId(omServiceID, conf);
} else {
throw new OzoneClientException("Service ID specified does not match" +
" with " + OZONE_OM_SERVICE_IDS_KEY + " defined in the " +
"configuration. Configured " + OZONE_OM_SERVICE_IDS_KEY + " are" +
serviceIds);
}
} else if (serviceIds.size() > 1) {
// If multiple om service ids are there,
// If multiple om service ids are there and default value isn't set,
// throw an error "om service ID must not be omitted"
String localOmServiceId = conf.getTrimmed(OZONE_OM_INTERNAL_SERVICE_ID);
if (!localOmServiceId.isEmpty()) {
return createRpcClientFromServiceId(localOmServiceId, conf);
}
throw new OzoneClientException("Service ID must not"
+ " be omitted when cluster has multiple OM Services." +
" Configured " + OZONE_OM_SERVICE_IDS_KEY + " are "
+ serviceIds);
}
// for non-HA cluster and HA cluster with only 1 service ID
// get service ID from configurations
return OzoneClientFactory.getRpcClient(conf);
return createRpcClient(conf);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.MutableConfigurationSource;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.ozone.client.OzoneClient;
import org.apache.hadoop.ozone.client.OzoneClientException;
import org.apache.hadoop.hdds.conf.InMemoryConfiguration;

import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_INTERNAL_SERVICE_ID;
import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_SERVICE_IDS_KEY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -68,6 +70,34 @@ public void implicitHaMultipleServiceId()
"service1,service2")));
}

@Test
public void implicitHaMultipleServiceIdWithDefaultServiceId()
throws OzoneClientException, IOException {
TestableOzoneAddress address =
new TestableOzoneAddress("/vol1/bucket1/key1");
InMemoryConfiguration conf = new InMemoryConfiguration(OZONE_OM_SERVICE_IDS_KEY,
"service1,service2");
conf.set(OZONE_OM_INTERNAL_SERVICE_ID, "service2");

address.createClient(conf);
assertFalse(address.simpleCreation);
assertEquals("service2", address.serviceId);
}

@Test
public void implicitHaMultipleServiceIdWithDefaultServiceIdForS3()
throws OzoneClientException, IOException {
TestableOzoneAddress address =
new TestableOzoneAddress("/vol1/bucket1/key1");
OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OZONE_OM_SERVICE_IDS_KEY, "service1,service2");
conf.set(OZONE_OM_INTERNAL_SERVICE_ID, "service2");

address.createClientForS3Commands(conf, null);
assertFalse(address.simpleCreation);
assertEquals("service2", address.serviceId);
}

@Test
public void explicitHaMultipleServiceId()
throws OzoneClientException, IOException {
Expand Down