Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<revision>0.9.30</revision>
<revision>0.9.31</revision>
<log4j.version>2.24.1</log4j.version>
<kafka.version>3.8.0</kafka.version>
<jersey>3.1.8</jersey>
Expand Down
55 changes: 36 additions & 19 deletions src/main/java/io/rtdi/bigdata/rulesservice/RulesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.apache.avro.Schema;
import org.apache.avro.Schema.Parser;
Expand Down Expand Up @@ -69,7 +70,7 @@ public class RulesService implements ServletContextListener {
private CachedSchemaRegistryClient schemaclient;
private ServletContext context;
private Path settingsdir;
private Path rulegroupdir;
private Path rulefiledir;
private Exception globalexception;
private String properties;
private Map<String, String> propertiesmap;
Expand Down Expand Up @@ -162,26 +163,42 @@ public void contextInitialized(ServletContextEvent sce) {
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Object o = envCtx.lookup("rulesettings");
if (o != null) {
settingsdir = Path.of(o.toString());
log.info("Found JNDI resource name <java:comp/env/rulesettings>, hence the settings directory is <{}>", settingsdir);
} else {
try {
Object o = envCtx.lookup("rulesettings");
if (o != null) {
settingsdir = Path.of(o.toString());
log.info("Found JNDI resource name <java:comp/env/rulesettings>, hence the settings directory is <{}>", settingsdir);
}
} catch (NamingException e) {
log.info("No JNDI resource found in the context.xml for name <java:comp/env/rulesettings>, hence using the default");
}
try {
Object o = envCtx.lookup("rulegroups");
if (o != null) {
rulefiledir = Path.of(o.toString());
log.info("Found JNDI resource name <java:comp/env/rulegroups>, hence the rules root directory is <{}>", rulefiledir);
}
} catch (NamingException e) {
log.info("No JNDI resource found in the context.xml for name <java:comp/env/rulegroups>, hence the default");
}
} catch (Exception e) {
this.globalexception = e;
log.info("Exception when reading the webserver settings", e);
}
try {
if (settingsdir == null) {
settingsdir = Path.of("/apps/rulesservice/settings");
log.info("No JNDI resource found for name <java:comp/env/rulesettings>, hence the settings directory is the default <{}>", settingsdir);
log.info("Settings directory is the default <{}>", settingsdir);
}
o = envCtx.lookup("rulegroups");
if (o != null) {
rulegroupdir = Path.of(o.toString());
log.info("Found JNDI resource name <java:comp/env/rulegroups>, hence the rules root directory is <{}>", rulegroupdir);
} else {
rulegroupdir = Path.of("/apps/rulesservice/definitions");
log.info("No JNDI resource found for name <java:comp/env/rulegroups>, hence the rules root directory is the default <{}>", rulegroupdir);
if (rulefiledir == null) {
rulefiledir = Path.of("/apps/rulesservice/definitions");
log.info("Rulefile directory is the default <{}>", rulefiledir);
}
configure();
startService();
} catch (Exception e) {
this.globalexception = e;
log.info("Exception when reading the webserver settings", e);
}
}

Expand Down Expand Up @@ -321,12 +338,12 @@ private void configure() throws IOException, RestClientException {
}

public List<RuleFileName> getRuleFiles(String schemaname) {
List<RuleFileName> groups = RuleFileDefinition.getAllRuleFiles(rulegroupdir, schemaname);
List<RuleFileName> groups = RuleFileDefinition.getAllRuleFiles(rulefiledir, schemaname);
return groups;
}

public List<RuleFileName> getAllRuleFiles() {
List<RuleFileName> groups = RuleFileDefinition.getAllRuleFiles(rulegroupdir);
List<RuleFileName> groups = RuleFileDefinition.getAllRuleFiles(rulefiledir);
return groups;
}

Expand All @@ -349,7 +366,7 @@ public Exception getGlobalException() {
}

public Path getRuleFileRootDir() {
return this.rulegroupdir;
return this.rulefiledir;
}

public ServiceSettings getConfig(boolean isadmin) {
Expand Down Expand Up @@ -420,7 +437,7 @@ public Collection<TopicRule> getTopicsAndRules() throws IOException {
*/
public Map<String, TopicRule> getTopicRuleFiles() throws IOException {
ObjectMapper om = new ObjectMapper();
Path topicrules = rulegroupdir.resolve("topics");
Path topicrules = rulefiledir.resolve("topics");
File topicruledir = topicrules.toFile();
Map<String, TopicRule> fileset = new HashMap<>();
if (topicruledir.isDirectory()) {
Expand All @@ -437,7 +454,7 @@ public Map<String, TopicRule> getTopicRuleFiles() throws IOException {


public List<TopicRule> saveTopicRules(List<TopicRule> input) {
Path topicruledir = rulegroupdir.resolve("topics");
Path topicruledir = rulefiledir.resolve("topics");
File f = topicruledir.toFile();
if (!f.exists()) {
f.mkdirs();
Expand Down