Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package org.apache.hadoop.ozone.s3;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
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 Down Expand Up @@ -70,6 +76,25 @@ public Void call() throws Exception {
OzoneConfigurationHolder.setConfiguration(ozoneConfiguration);
UserGroupInformation.setConfiguration(ozoneConfiguration);
loginS3GUser(ozoneConfiguration);

if (StringUtils.isEmpty(ozoneConfiguration.get(
OzoneConfigKeys.OZONE_HTTP_BASEDIR))) {
//Setting ozone.metadata.dirs if not set so that server setup doesn't
// fail.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment, setting to tmp directory from current working directory, cwd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Path tmpMetaDir = Files.createTempDirectory(Paths.get(""),
"ozone_s3g_tmp_base_dir");
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ShutdownHookManager to add the shutdown hook. Also, I think it should be executed after the other hook (which stops the server), so use a lower than default priority.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swamirishi do you plan to address this? Also, we can change this PR to change the logic for all the webUIs to see the $CWD.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kerneltime Should I do the web ui change as part of another PR?

try {
FileUtils.deleteDirectory(tmpMetaDir.toFile());
} catch (IOException e) {
LOG.error("Failed to cleanup temporary S3 Gateway Metadir {}",
tmpMetaDir.toFile().getAbsolutePath(), e);
}
}));
ozoneConfiguration.set(OzoneConfigKeys.OZONE_HTTP_BASEDIR,
tmpMetaDir.toFile().getAbsolutePath());
}

httpServer = new S3GatewayHttpServer(ozoneConfiguration, "s3gateway");
metrics = S3GatewayMetrics.create();
start();
Expand All @@ -87,7 +112,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