Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@
*/
package org.apache.hadoop.ozone.s3;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.hadoop.hdds.StringUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.hdds.cli.GenericCli;
import org.apache.hadoop.hdds.cli.HddsVersionProvider;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.tracing.TracingUtil;
import org.apache.hadoop.hdds.utils.HddsServerUtil;
import org.apache.hadoop.ozone.OzoneConfigKeys;
import org.apache.hadoop.ozone.OzoneSecurityUtil;
import org.apache.hadoop.ozone.s3.metrics.S3GatewayMetrics;
import org.apache.hadoop.ozone.util.OzoneNetUtils;
Expand All @@ -38,6 +43,7 @@
import org.slf4j.LoggerFactory;
import picocli.CommandLine.Command;

import static org.apache.hadoop.hdds.StringUtils.startupShutdownMessage;
import static org.apache.hadoop.ozone.conf.OzoneServiceConfig.DEFAULT_SHUTDOWN_HOOK_PRIORITY;
import static org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_KERBEROS_KEYTAB_FILE_KEY;
import static org.apache.hadoop.ozone.s3.S3GatewayConfigKeys.OZONE_S3G_KERBEROS_PRINCIPAL_KEY;
Expand All @@ -63,13 +69,35 @@ public static void main(String[] args) throws Exception {
new Gateway().run(args);
}

private void setHttpBaseDir()
throws IOException {
if (StringUtils.isEmpty(ozoneConfiguration.get(
OzoneConfigKeys.OZONE_HTTP_BASEDIR))) {
//Setting ozone.http.basedir to cwd if not set so that server setup
// doesn't fail.
File tmpMetaDir = Files.createTempDirectory(Paths.get(""),
"ozone_s3g_tmp_base_dir").toFile();
ShutdownHookManager.get().addShutdownHook(() -> {
try {
FileUtils.deleteDirectory(tmpMetaDir);
} catch (IOException e) {
LOG.error("Failed to cleanup temporary S3 Gateway Metadir {}",
tmpMetaDir.getAbsolutePath(), e);
}
}, 0);
ozoneConfiguration.set(OzoneConfigKeys.OZONE_HTTP_BASEDIR,
tmpMetaDir.getAbsolutePath());
}
}

@Override
public Void call() throws Exception {
ozoneConfiguration = createOzoneConfiguration();
TracingUtil.initTracing("S3gateway", ozoneConfiguration);
OzoneConfigurationHolder.setConfiguration(ozoneConfiguration);
UserGroupInformation.setConfiguration(ozoneConfiguration);
loginS3GUser(ozoneConfiguration);
setHttpBaseDir();
httpServer = new S3GatewayHttpServer(ozoneConfiguration, "s3gateway");
metrics = S3GatewayMetrics.create();
start();
Expand All @@ -87,7 +115,7 @@ public Void call() throws Exception {
public void start() throws IOException {
String[] originalArgs = getCmd().getParseResult().originalArgs()
.toArray(new String[0]);
StringUtils.startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
startupShutdownMessage(OzoneVersionInfo.OZONE_VERSION_INFO,
Gateway.class, originalArgs, LOG, ozoneConfiguration);

LOG.info("Starting Ozone S3 gateway");
Expand Down