deniskuzZ commented on code in PR #6327:
URL: https://github.com/apache/hive/pull/6327#discussion_r2911163115
##########
standalone-metastore/metastore-rest-catalog/src/main/java/org/apache/iceberg/rest/standalone/StandaloneRESTCatalogServer.java:
##########
@@ -183,26 +124,26 @@ public static void main(String[] args) {
}
}
+ // Sync port from MetastoreConf to Spring's Environment so server.port
uses it
+ int port = MetastoreConf.getIntVar(conf, ConfVars.CATALOG_SERVLET_PORT);
+ if (port > 0) {
+ System.setProperty(ConfVars.CATALOG_SERVLET_PORT.getVarname(),
String.valueOf(port));
+ }
+
StandaloneRESTCatalogServer server = new StandaloneRESTCatalogServer(conf);
+
+ // Start Spring Boot with pre-configured beans
+ SpringApplication app = new
SpringApplication(StandaloneRESTCatalogServer.class,
IcebergCatalogConfiguration.class);
+ app.addInitializers(ctx -> {
Review Comment:
1. StandaloneRESTCatalogServer (bootstrap only)
````
/**
* Standalone REST Catalog Server bootstrap.
*/
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class StandaloneRESTCatalogServer {
public static void main(String[] args) {
SpringApplication.run(StandaloneRESTCatalogServer.class, args);
}
}
````
2. RestCatalogServerRuntime (server lifecycle + endpoint)
````
@Component
public class RestCatalogServerRuntime {
private static final Logger LOG =
LoggerFactory.getLogger(RestCatalogServerRuntime.class);
private final Configuration conf;
private String restEndpoint;
private int port;
public RestCatalogServerRuntime(Configuration conf) {
this.conf = conf;
String thriftUris = MetastoreConf.getVar(conf, ConfVars.THRIFT_URIS);
if (thriftUris == null || thriftUris.isEmpty()) {
throw new IllegalArgumentException(
"metastore.thrift.uris must be configured to connect to HMS");
}
LOG.info("Hadoop Configuration initialized");
LOG.info(" HMS Thrift URIs: {}", thriftUris);
if (LOG.isInfoEnabled()) {
LOG.info(" Warehouse: {}", MetastoreConf.getVar(conf,
ConfVars.WAREHOUSE));
}
}
@EventListener
public void onWebServerInitialized(WebServerInitializedEvent event) {
int actualPort = event.getWebServer().getPort();
if (actualPort > 0) {
this.port = actualPort;
String servletPath =
MetastoreConf.getVar(conf, ConfVars.ICEBERG_CATALOG_SERVLET_PATH);
if (servletPath == null || servletPath.isEmpty()) {
servletPath = "iceberg";
}
this.restEndpoint = "http://localhost:" + actualPort + "/" +
servletPath;
LOG.info("REST endpoint set to actual server port: {}", restEndpoint);
}
}
@VisibleForTesting
public int getPort() {
return port;
}
public String getRestEndpoint() {
return restEndpoint;
}
}
````
3. HadoopConfigurationConfig (Hadoop Configuration bean)
````
@org.springframework.context.annotation.Configuration
public class HadoopConfigurationConfig {
@Bean
public Configuration hadoopConfiguration() {
return MetastoreConf.newMetastoreConf();
}
}
````
4. IcebergCatalogConfiguration (servlet wiring)
````
@org.springframework.context.annotation.Configuration
public class IcebergCatalogConfiguration {
private static final Logger LOG =
LoggerFactory.getLogger(IcebergCatalogConfiguration.class);
private final Configuration conf;
public IcebergCatalogConfiguration(Configuration conf) {
this.conf = conf;
}
@Bean
public ServletRegistrationBean<HttpServlet> restCatalogServlet() {
String servletPath =
MetastoreConf.getVar(conf, ConfVars.ICEBERG_CATALOG_SERVLET_PATH);
if (servletPath == null || servletPath.isEmpty()) {
servletPath = "iceberg";
MetastoreConf.setVar(conf, ConfVars.ICEBERG_CATALOG_SERVLET_PATH,
servletPath);
}
int port = MetastoreConf.getIntVar(conf, ConfVars.CATALOG_SERVLET_PORT);
if (port == 0) {
port = 8080;
MetastoreConf.setLongVar(conf, ConfVars.CATALOG_SERVLET_PORT, port);
}
LOG.info("Creating REST Catalog servlet at /{}", servletPath);
org.apache.hadoop.hive.metastore.ServletServerBuilder.Descriptor
descriptor =
HMSCatalogFactory.createServlet(conf);
if (descriptor == null || descriptor.getServlet() == null) {
throw new IllegalStateException("Failed to create Iceberg REST Catalog
servlet");
}
ServletRegistrationBean<HttpServlet> registration =
new ServletRegistrationBean<>(descriptor.getServlet(), "/" +
servletPath + "/*");
registration.setName("IcebergRESTCatalog");
registration.setLoadOnStartup(1);
return registration;
}
}
````
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]