-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add groovy config change listener for servers.
- Loading branch information
abhishekbafna
committed
Feb 10, 2025
1 parent
9c8adeb
commit 9812e00
Showing
5 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...cal/src/main/java/org/apache/pinot/segment/local/function/GroovyConfigChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.segment.local.function; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.pinot.spi.config.provider.PinotClusterConfigChangeListener; | ||
import org.apache.pinot.spi.utils.CommonConstants; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
||
public class GroovyConfigChangeListener implements PinotClusterConfigChangeListener { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(GroovyConfigChangeListener.class); | ||
|
||
@Override | ||
public void onChange(Set<String> changedConfigs, Map<String, String> clusterConfigs) { | ||
if (changedConfigs.contains(CommonConstants.GROOVY_STATIC_ANALYZER_CONFIG)) { | ||
try { | ||
String configJson = clusterConfigs.get(CommonConstants.GROOVY_STATIC_ANALYZER_CONFIG); | ||
LOGGER.info("Updating Groovy Static Analyzer configuration with latest config: {}", configJson); | ||
GroovyStaticAnalyzerConfig config = GroovyStaticAnalyzerConfig.fromJson(configJson); | ||
GroovyFunctionEvaluator.setConfig(config); | ||
} catch (Exception e) { | ||
LOGGER.error("Failed to update Groovy Static Analyzer configuration", e); | ||
} | ||
} else { | ||
LOGGER.debug("Skip updating Groovy Static Analyzer configuration."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...src/test/java/org/apache/pinot/segment/local/function/GroovyConfigChangeListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pinot.segment.local.function; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.apache.pinot.spi.utils.CommonConstants; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertNotNull; | ||
import static org.testng.Assert.assertNull; | ||
|
||
|
||
public class GroovyConfigChangeListenerTest { | ||
|
||
@BeforeMethod | ||
public void setUp() | ||
throws JsonProcessingException { | ||
assertNull(GroovyFunctionEvaluator.getConfig()); | ||
GroovyStaticAnalyzerConfig groovyConfig = new GroovyStaticAnalyzerConfig( | ||
List.of("java.lang.Math"), | ||
List.of("java.lang.Math"), | ||
List.of("java.lang.Math"), | ||
List.of("invoke", "execute"), | ||
false); | ||
GroovyFunctionEvaluator.setConfig(groovyConfig); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() | ||
throws JsonProcessingException { | ||
GroovyFunctionEvaluator.setConfig(null); | ||
} | ||
|
||
@Test | ||
public void testGroovyConfigIsUpdated() { | ||
Set<String> changedConfigs = Set.of(CommonConstants.GROOVY_STATIC_ANALYZER_CONFIG); | ||
String updatedConfig = "{\"allowedReceivers\" : [\"java.lang.String\"]}"; | ||
Map<String, String> clusterConfigs = Map.of(CommonConstants.GROOVY_STATIC_ANALYZER_CONFIG, updatedConfig); | ||
assertEquals(GroovyFunctionEvaluator.getConfig().getAllowedReceivers(), List.of("java.lang.Math")); | ||
GroovyConfigChangeListener groovyConfigChangeListener = new GroovyConfigChangeListener(); | ||
groovyConfigChangeListener.onChange(changedConfigs, clusterConfigs); | ||
assertNotNull(GroovyFunctionEvaluator.getConfig()); | ||
assertEquals(GroovyFunctionEvaluator.getConfig().getAllowedReceivers(), List.of("java.lang.String")); | ||
} | ||
|
||
@Test | ||
public void testGroovyConfigIsUnchanged() { | ||
Set<String> changedConfigs = Set.of("random.test.key"); | ||
Map<String, String> clusterConfigs = Map.of("random.test.key", "random.test.value"); | ||
GroovyConfigChangeListener groovyConfigChangeListener = new GroovyConfigChangeListener(); | ||
groovyConfigChangeListener.onChange(changedConfigs, clusterConfigs); | ||
assertNotNull(GroovyFunctionEvaluator.getConfig()); | ||
assertEquals(GroovyFunctionEvaluator.getConfig().getAllowedReceivers(), List.of("java.lang.Math")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters