diff options
6 files changed, 107 insertions, 5 deletions
diff --git a/engine-d-standalone/src/main/assembly/bin/run.sh b/engine-d-standalone/src/main/assembly/bin/run.sh index 7c800b5..850a8e1 100644 --- a/engine-d-standalone/src/main/assembly/bin/run.sh +++ b/engine-d-standalone/src/main/assembly/bin/run.sh @@ -26,7 +26,7 @@ echo @JAVA@ $JAVA main_path=$RUNHOME/.. cd $main_path JAVA_OPTS="-Xms256m -Xmx1g" -port=8312 +port=9202 #JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=*:$port,server=y,suspend=n" echo @JAVA_OPTS@ $JAVA_OPTS @@ -96,7 +96,7 @@ fi cat "$main_path/conf/engine-d.yml" -./bin/initDB.sh $JDBC_USERNAME $JDBC_PASSWORD $DB_NAME $DB_PORT "${URL_JDBC%:*}" +${RUNHOME}/initDB.sh $JDBC_USERNAME $JDBC_PASSWORD $DB_NAME $DB_PORT "${URL_JDBC%:*}" "$JAVA" $JAVA_OPTS -classpath "$class_path" org.onap.holmes.engine.EngineDActiveApp server "$main_path/conf/engine-d.yml" diff --git a/engine-d-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_engine-createobj.sql b/engine-d-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_engine-createobj.sql index 276957c..82eed4a 100644 --- a/engine-d-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_engine-createobj.sql +++ b/engine-d-standalone/src/main/assembly/dbscripts/postgresql/onap-holmes_engine-createobj.sql @@ -39,5 +39,14 @@ CREATE TABLE ALARM_INFO ( PRIMARY KEY (EVENTID) ); +CREATE TABLE IF NOT EXISTS ENGINE_ENTITY ( + ID VARCHAR(150) NOT NULL, + IP VARCHAR(128) NOT NULL, + PORT SMALLINT NOT NULL, + LASTMODIFIED BIGINT NOT NULL, + PRIMARY KEY (ID) +); + GRANT ALL PRIVILEGES ON ALARM_INFO TO DBUSER; +GRANT ALL PRIVILEGES ON ENGINE_ENTITY TO DBUSER; diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java index 6808e98..78f2677 100644 --- a/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java +++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/DroolsEngine.java @@ -33,6 +33,7 @@ import org.kie.api.runtime.rule.FactHandle; import org.onap.holmes.common.api.entity.AlarmInfo; import org.onap.holmes.common.api.entity.CorrelationRule; import org.onap.holmes.common.api.stat.VesAlarm; +import org.onap.holmes.common.config.MicroServiceConfig; import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache; import org.onap.holmes.common.exception.AlarmInfoException; import org.onap.holmes.common.exception.CorrelationException; @@ -65,6 +66,7 @@ public class DroolsEngine { private ReleaseId compilationRelease = ks.newReleaseId("org.onap.holmes", "compilation", "1.0.0-SNAPSHOT"); private KieContainer container; private KieSession session; + private String instanceIp; @Inject public void setRuleMgtWrapper(RuleMgtWrapper ruleMgtWrapper) { @@ -100,6 +102,7 @@ public class DroolsEngine { log.error("Failed to startup the engine of Holmes: " + e.getMessage(), e); throw ExceptionUtil.buildExceptionResponse("Failed to startup Drools!"); } + instanceIp = MicroServiceConfig.getMicroServiceIpAndPort()[0]; } public void stop() { @@ -123,7 +126,11 @@ public class DroolsEngine { } private void initRules() throws CorrelationException { - List<CorrelationRule> rules = ruleMgtWrapper.queryRuleByEnable(ENABLE); + List<CorrelationRule> rules = ruleMgtWrapper.queryRuleByEnable(ENABLE) + .stream() + .filter(r -> r.getEngineInstance().equals(instanceIp)) + .collect(Collectors.toList()); + if (rules.isEmpty()) { return; } diff --git a/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java b/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java new file mode 100644 index 0000000..0b15999 --- /dev/null +++ b/engine-d/src/main/java/org/onap/holmes/engine/manager/status/EntityStatusRefreshTask.java @@ -0,0 +1,82 @@ +/** + * Copyright 2020 ZTE Corporation. + * <p> + * Licensed 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 + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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.onap.holmes.engine.manager.status; + +import org.jvnet.hk2.annotations.Service; +import org.onap.holmes.common.config.MicroServiceConfig; +import org.onap.holmes.common.engine.entity.EngineEntity; +import org.onap.holmes.common.engine.service.EngineEntityService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import java.util.Optional; +import java.util.Timer; +import java.util.TimerTask; + +import static java.util.concurrent.TimeUnit.SECONDS; + +@Service +public class EntityStatusRefreshTask extends TimerTask { + private static final Logger logger = LoggerFactory.getLogger(EntityStatusRefreshTask.class); + private final long INTERVAL = SECONDS.toMillis(15); + private EngineEntity engineEntity; + private Timer timer = new Timer("EntityStatusRefreshTimer", true); + private EngineEntityService engineEntityService; + + @Inject + public EntityStatusRefreshTask(EngineEntityService engineEntityService) { + this.engineEntityService = engineEntityService; + } + + @PostConstruct + private void initialize() { + String[] serviceAddrInfo = MicroServiceConfig.getMicroServiceIpAndPort(); + if (null != serviceAddrInfo) { + String ip = serviceAddrInfo[0]; + String port = Optional.ofNullable(serviceAddrInfo[1]).orElse("9201"); + port = port.equals("80") ? "9201" : port; + engineEntity = new EngineEntity(ip, Integer.parseInt(port)); + + timer.schedule(this, SECONDS.toMillis(1), INTERVAL); + } else { + logger.warn("Failed to get the address info of current engine. " + + "Problems will be caused when it comes to a multi-instance scenario!"); + } + } + + @Override + public void run() { + if (engineEntity == null) { + logger.warn("No engine entity is specified. The status refresh task will return immediately."); + return; + } + + engineEntity.setLastModified(System.currentTimeMillis()); + + try { + if (engineEntityService.getEntity(engineEntity.getId()) == null) { + engineEntityService.insertEntity(engineEntity); + } else { + engineEntityService.updateEntity(engineEntity); + } + } catch (Exception e) { + logger.warn("Failed to update engine instance information.", e); + } + } +} diff --git a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java index f7b7fbd..cb28faa 100644 --- a/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java +++ b/engine-d/src/test/java/org/onap/holmes/engine/manager/DroolsEngineTest.java @@ -1,5 +1,5 @@ /**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ import org.junit.rules.ExpectedException; import org.onap.holmes.common.api.entity.AlarmInfo;
import org.onap.holmes.common.api.entity.CorrelationRule;
import org.onap.holmes.common.api.stat.VesAlarm;
+import org.onap.holmes.common.config.MicroServiceConfig;
import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
import org.onap.holmes.common.exception.CorrelationException;
import org.onap.holmes.common.utils.DbDaoUtil;
@@ -55,6 +56,7 @@ public class DroolsEngineTest { private ClosedLoopControlNameCache closedLoopControlNameCache;
public DroolsEngineTest() throws Exception {
+ System.setProperty(MicroServiceConfig.HOSTNAME, "127.0.0.1:80");
droolsEngine = new DroolsEngine();
ruleMgtWrapper = new RuleMgtWrapperStub();
dbDaoUtilStub = new DbDaoUtilStub();
@@ -64,6 +66,7 @@ public class DroolsEngineTest { droolsEngine.setRuleMgtWrapper(ruleMgtWrapper);
Whitebox.invokeMethod(droolsEngine, "init");
+ System.clearProperty(MicroServiceConfig.HOSTNAME);
}
@Before
@@ -250,6 +253,7 @@ class RuleMgtWrapperStub extends RuleMgtWrapper { rule.setContent("package org.onap.holmes;");
rule.setPackageName("UT");
rule.setClosedControlLoopName(UUID.randomUUID().toString());
+ rule.setEngineInstance("127.0.0.1");
rules.add(rule);
}
@@ -164,7 +164,7 @@ <dependency> <groupId>org.onap.holmes.common</groupId> <artifactId>holmes-actions</artifactId> - <version>1.3.0</version> + <version>1.3.1</version> <exclusions> <exclusion> <groupId>io.dropwizard</groupId> |