diff --git a/docs/resource-groups-api.md b/docs/resource-groups-api.md
index 330e93616..ba0a14b67 100644
--- a/docs/resource-groups-api.md
+++ b/docs/resource-groups-api.md
@@ -111,12 +111,12 @@ curl -X POST http://localhost:8080/trino/resourcegroup/delete/{INSERT_ID_HERE}
## Add a selector
-To add a single selector, specify all relevant fields in the body. Resource
-group id should not be specified since the database should autoincrement it.
+To add a single selector, specify all relevant fields in the body.
```$xslt
curl -X POST http://localhost:8080/trino/selector/create \
-d '{
+ "resourceGroupId": 1, \
"priority": 1, \
"userRegex": "selector1", \
"sourceRegex": "resourcegroup1", \
diff --git a/gateway-ha/pom.xml b/gateway-ha/pom.xml
index ed167fe02..e1466aee3 100644
--- a/gateway-ha/pom.xml
+++ b/gateway-ha/pom.xml
@@ -362,6 +362,13 @@
slf4j-api
+
+ com.oracle.database.jdbc
+ ojdbc10
+ 19.21.0.0
+ runtime
+
+
io.dropwizard
dropwizard-views-freemarker
diff --git a/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/ResourceGroups.java b/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/ResourceGroups.java
index c27ad439b..7809d1b2b 100644
--- a/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/ResourceGroups.java
+++ b/gateway-ha/src/main/java/io/trino/gateway/ha/persistence/dao/ResourceGroups.java
@@ -90,7 +90,6 @@ public static List upcast(List resourceGro
*/
public static void create(ResourceGroups model, ResourceGroupsDetail resourceGroupDetail)
{
- model.set(resourceGroupId, resourceGroupDetail.getResourceGroupId());
model.set(name, resourceGroupDetail.getName());
model.set(parent, resourceGroupDetail.getParent());
diff --git a/gateway-ha/src/main/resources/gateway-ha-persistence-oracle.sql b/gateway-ha/src/main/resources/gateway-ha-persistence-oracle.sql
new file mode 100644
index 000000000..af642c2b0
--- /dev/null
+++ b/gateway-ha/src/main/resources/gateway-ha-persistence-oracle.sql
@@ -0,0 +1,70 @@
+CREATE TABLE gateway_backend (
+ name VARCHAR(256) PRIMARY KEY,
+ routing_group VARCHAR (256),
+ backend_url VARCHAR (256),
+ external_url VARCHAR (256),
+ active NUMBER(1)
+);
+
+CREATE TABLE query_history (
+ query_id VARCHAR(256) PRIMARY KEY,
+ query_text VARCHAR (256),
+ created NUMBER,
+ backend_url VARCHAR (256),
+ user_name VARCHAR(256),
+ source VARCHAR(256)
+);
+CREATE INDEX query_history_created_idx ON query_history(created);
+
+CREATE TABLE resource_groups (
+ resource_group_id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1),
+ name VARCHAR(250) NOT NULL,
+ -- OPTIONAL POLICY CONTROLS
+ parent NUMBER,
+ jmx_export CHAR(1),
+ scheduling_policy VARCHAR(128),
+ scheduling_weight NUMBER,
+ -- REQUIRED QUOTAS
+ soft_memory_limit VARCHAR(128) NOT NULL,
+ max_queued INT NOT NULL,
+ hard_concurrency_limit NUMBER NOT NULL,
+ -- OPTIONAL QUOTAS
+ soft_concurrency_limit NUMBER,
+ soft_cpu_limit VARCHAR(128),
+ hard_cpu_limit VARCHAR(128),
+ environment VARCHAR(128),
+ PRIMARY KEY(resource_group_id),
+ FOREIGN KEY (parent) REFERENCES resource_groups (resource_group_id) ON DELETE CASCADE
+);
+
+CREATE TABLE selectors (
+ resource_group_id NUMBER NOT NULL,
+ priority NUMBER NOT NULL,
+ -- Regex fields -- these will be used as a regular expression pattern to
+ -- match against the field of the same name on queries
+ user_regex VARCHAR(512),
+ source_regex VARCHAR(512),
+ -- Selector fields -- these must match exactly.
+ query_type VARCHAR(512),
+ client_tags VARCHAR(512),
+ selector_resource_estimate VARCHAR(1024),
+ FOREIGN KEY (resource_group_id) REFERENCES resource_groups (resource_group_id) ON DELETE CASCADE
+);
+
+CREATE TABLE resource_groups_global_properties (
+ name VARCHAR(128) NOT NULL PRIMARY KEY,
+ value VARCHAR(512) NULL,
+ CHECK (name in ('cpu_quota_period'))
+);
+
+CREATE TABLE exact_match_source_selectors(
+ environment VARCHAR(256),
+ update_time TIMESTAMP NOT NULL,
+ -- Selector fields which must exactly match a query
+ source VARCHAR(512) NOT NULL,
+ query_type VARCHAR(512),
+ resource_group_id VARCHAR(256) NOT NULL,
+ PRIMARY KEY (environment, source, resource_group_id),
+ UNIQUE (source, environment, query_type, resource_group_id)
+);
+
diff --git a/gateway-ha/src/main/resources/gateway-ha-persistence.sql b/gateway-ha/src/main/resources/gateway-ha-persistence.sql
index 6e1c09a47..ef818b71e 100644
--- a/gateway-ha/src/main/resources/gateway-ha-persistence.sql
+++ b/gateway-ha/src/main/resources/gateway-ha-persistence.sql
@@ -18,7 +18,7 @@ CREATE INDEX query_history_created_idx ON query_history(created);
CREATE TABLE IF NOT EXISTS resource_groups (
resource_group_id BIGINT NOT NULL AUTO_INCREMENT,
- name VARCHAR(250) NOT NULL UNIQUE,
+ name VARCHAR(250) NOT NULL,
-- OPTIONAL POLICY CONTROLS
parent BIGINT NULL,
@@ -75,4 +75,4 @@ CREATE TABLE IF NOT EXISTS exact_match_source_selectors (
PRIMARY KEY (environment, source, query_type),
UNIQUE (source, environment, query_type, resource_group_id)
-);
\ No newline at end of file
+);
diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java
index 1fab74d6a..d5d8412d6 100644
--- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java
+++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestResourceGroupsManager.java
@@ -70,7 +70,7 @@ public void testReadResourceGroup()
List resourceGroups = resourceGroupManager.readAllResourceGroups(null);
assertThat(resourceGroups).hasSize(1);
- assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(0L);
+ assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(1L);
assertThat(resourceGroups.get(0).getName()).isEqualTo("admin");
assertThat(resourceGroups.get(0).getHardConcurrencyLimit()).isEqualTo(20);
assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(200);
@@ -83,7 +83,7 @@ public void testReadResourceGroup()
public void testUpdateResourceGroup()
{
ResourceGroupsDetail resourceGroup = new ResourceGroupsDetail();
- resourceGroup.setResourceGroupId(0L);
+ resourceGroup.setResourceGroupId(1L);
resourceGroup.setName("admin");
resourceGroup.setHardConcurrencyLimit(50);
resourceGroup.setMaxQueued(50);
@@ -96,7 +96,7 @@ public void testUpdateResourceGroup()
/* Update resourceGroups that do not exist yet.
* In this case, new resourceGroups should be created. */
- resourceGroup.setResourceGroupId(1L);
+ resourceGroup.setResourceGroupId(2L);
resourceGroup.setName("localization-eng");
resourceGroup.setHardConcurrencyLimit(50);
resourceGroup.setMaxQueued(70);
@@ -118,14 +118,14 @@ public void testUpdateResourceGroup()
assertThat(resourceGroups).hasSize(3); // updated 2 non-existing groups, so count should be 3
- assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(0L);
+ assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(1L);
assertThat(resourceGroups.get(0).getName()).isEqualTo("admin");
assertThat(resourceGroups.get(0).getHardConcurrencyLimit()).isEqualTo(50);
assertThat(resourceGroups.get(0).getMaxQueued()).isEqualTo(50);
assertThat(resourceGroups.get(0).getJmxExport()).isEqualTo(Boolean.FALSE);
assertThat(resourceGroups.get(0).getSoftMemoryLimit()).isEqualTo("20%");
- assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(1L);
+ assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(2L);
assertThat(resourceGroups.get(1).getName()).isEqualTo("localization-eng");
assertThat(resourceGroups.get(1).getHardConcurrencyLimit()).isEqualTo(50);
assertThat(resourceGroups.get(1).getMaxQueued()).isEqualTo(70);
@@ -141,15 +141,15 @@ public void testDeleteResourceGroup()
List resourceGroups = resourceGroupManager.readAllResourceGroups(null);
assertThat(resourceGroups).hasSize(3);
- assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(0L);
- assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(1L);
+ assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(1L);
+ assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(2L);
assertThat(resourceGroups.get(2).getResourceGroupId()).isEqualTo(3L);
resourceGroupManager.deleteResourceGroup(resourceGroups.get(1).getResourceGroupId(), null);
resourceGroups = resourceGroupManager.readAllResourceGroups(null);
assertThat(resourceGroups).hasSize(2);
- assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(0L);
+ assertThat(resourceGroups.get(0).getResourceGroupId()).isEqualTo(1L);
assertThat(resourceGroups.get(1).getResourceGroupId()).isEqualTo(3L);
}
@@ -158,7 +158,7 @@ public void testDeleteResourceGroup()
public void testCreateSelector()
{
SelectorsDetail selector = new SelectorsDetail();
- selector.setResourceGroupId(0L);
+ selector.setResourceGroupId(1L);
selector.setPriority(0L);
selector.setUserRegex("data-platform-admin");
selector.setSourceRegex("admin");
@@ -178,7 +178,7 @@ public void testReadSelector()
List selectors = resourceGroupManager.readAllSelectors(null);
assertThat(selectors).hasSize(1);
- assertThat(selectors.get(0).getResourceGroupId()).isEqualTo(0L);
+ assertThat(selectors.get(0).getResourceGroupId()).isEqualTo(1L);
assertThat(selectors.get(0).getPriority()).isEqualTo(0L);
assertThat(selectors.get(0).getUserRegex()).isEqualTo("data-platform-admin");
assertThat(selectors.get(0).getSourceRegex()).isEqualTo("admin");
@@ -193,7 +193,7 @@ public void testUpdateSelector()
{
SelectorsDetail selector = new SelectorsDetail();
- selector.setResourceGroupId(0L);
+ selector.setResourceGroupId(1L);
selector.setPriority(0L);
selector.setUserRegex("data-platform-admin_updated");
selector.setSourceRegex("admin_updated");
@@ -246,7 +246,7 @@ public void testDeleteSelector()
{
List selectors = resourceGroupManager.readAllSelectors(null);
assertThat(selectors).hasSize(3);
- assertThat(selectors.get(0).getResourceGroupId()).isEqualTo(0L);
+ assertThat(selectors.get(0).getResourceGroupId()).isEqualTo(1L);
resourceGroupManager.deleteSelector(selectors.get(0), null);
selectors = resourceGroupManager.readAllSelectors(null);
diff --git a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestSpecificDbResourceGroupsManager.java b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestSpecificDbResourceGroupsManager.java
index aa89acc39..0c9951619 100644
--- a/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestSpecificDbResourceGroupsManager.java
+++ b/gateway-ha/src/test/java/io/trino/gateway/ha/router/TestSpecificDbResourceGroupsManager.java
@@ -57,7 +57,6 @@ private void createResourceGroup()
{
ResourceGroupsDetail resourceGroup = new ResourceGroupsDetail();
- resourceGroup.setResourceGroupId(1L);
resourceGroup.setName("admin2");
resourceGroup.setHardConcurrencyLimit(20);
resourceGroup.setMaxQueued(200);