Commit 344b2897 authored by michael.simon's avatar michael.simon
Browse files

introducing reload capabilities for appconfig on all cluster members

parent 21810d0a
......@@ -10,10 +10,14 @@
******************************************************************************/
package edu.kit.scc.webreg.dao;
import java.util.Date;
import edu.kit.scc.webreg.entity.ApplicationConfigEntity;
public interface ApplicationConfigDao extends BaseDao<ApplicationConfigEntity, Long> {
ApplicationConfigEntity findActive();
ApplicationConfigEntity findReloadActive(Date date);
}
......@@ -10,12 +10,16 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.jpa;
import java.util.Date;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.ApplicationConfigDao;
import edu.kit.scc.webreg.entity.ApplicationConfigEntity;
import edu.kit.scc.webreg.entity.BusinessRulePackageEntity;
@Named
@ApplicationScoped
......@@ -33,6 +37,20 @@ public class JpaApplicationConfigDao extends JpaBaseDao<ApplicationConfigEntity,
}
}
@Override
@SuppressWarnings({"unchecked"})
public ApplicationConfigEntity findReloadActive(Date date) {
try {
return (ApplicationConfigEntity) em.createQuery("select e from ApplicationConfigEntity e "
+ "where e.activeConfig = :act and e.dirtyStamp > :date")
.setParameter("date", date).setParameter("act", true)
.getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public Class<ApplicationConfigEntity> getEntityClass() {
return ApplicationConfigEntity.class;
......
package edu.kit.scc.webreg.entity;
import java.util.Date;
import java.util.Map;
import javax.persistence.Column;
......@@ -24,7 +25,10 @@ public class ApplicationConfigEntity extends AbstractBaseEntity {
@Column(name = "activeConfig")
private Boolean activeConfig;
@Column(name = "dirty_stamp")
private Date dirtyStamp;
@ElementCollection(fetch = FetchType.EAGER)
@JoinTable(name = "application_config_options")
@MapKeyColumn(name = "key_data", length = 128)
......@@ -61,6 +65,14 @@ public class ApplicationConfigEntity extends AbstractBaseEntity {
public void setConfigFormatVersion(String configFormatVersion) {
this.configFormatVersion = configFormatVersion;
}
public Date getDirtyStamp() {
return dirtyStamp;
}
public void setDirtyStamp(Date dirtyStamp) {
this.dirtyStamp = dirtyStamp;
}
}
......@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.bootstrap;
import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
......@@ -35,6 +36,8 @@ public class ApplicationConfig implements Serializable {
private ApplicationConfigEntity appConfig;
private Date lastLoad;
public void init() {
logger.debug("Checking for Active Configuration");
appConfig = dao.findActive();
......@@ -48,6 +51,23 @@ public class ApplicationConfig implements Serializable {
appConfig.setConfigOptions(new HashMap<String, String>());
appConfig = dao.persist(appConfig);
}
lastLoad = new Date();
}
public void reload() {
ApplicationConfigEntity newAppConfig = dao.findReloadActive(lastLoad);
if (newAppConfig != null) {
logger.info("Reloading Application Configuration");
appConfig = newAppConfig;
lastLoad = new Date();
}
}
public void scheduleReload() {
appConfig.setDirtyStamp(new Date());
appConfig = dao.persist(appConfig);
}
public String getConfigValue(String key) {
......@@ -68,4 +88,12 @@ public class ApplicationConfig implements Serializable {
public Map<String, String> getConfigOptions() {
return appConfig.getConfigOptions();
}
public Date getLastLoad() {
return lastLoad;
}
public Date getNextScheduledReload() {
return appConfig.getDirtyStamp();
}
}
......@@ -26,6 +26,7 @@ import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.bootstrap.ApplicationConfig;
import edu.kit.scc.webreg.bootstrap.NodeConfiguration;
import edu.kit.scc.webreg.drools.BpmProcessService;
import edu.kit.scc.webreg.entity.JobClassEntity;
......@@ -60,6 +61,9 @@ public class StandardSchedulerImpl implements StandardScheduler, Serializable {
@Inject
private BpmProcessService bpmProcessService;
@Inject
private ApplicationConfig appConfig;
@Override
public void initialize() {
......@@ -153,6 +157,9 @@ public class StandardSchedulerImpl implements StandardScheduler, Serializable {
// Reload rules here
bpmProcessService.reload();
// Reload App Config here
appConfig.reload();
}
private void cancelTimer(Timer t) {
......
......@@ -52,6 +52,10 @@ public class IndexConfigBean implements Serializable {
Collections.sort(keyList);
}
public void scheduleReload() {
appConfig.scheduleReload();
}
public void saveKey(String key) {
if (configMap.get(key) == null || configMap.get(key).equals("")) {
appConfig.deleteConfigValue(key);
......
......@@ -38,19 +38,26 @@
<p:commandButton id="save" action="#{editHooksConfigBean.save}" value="#{messages.save}" />
</p:panel>
<br/><br/>
<p:panel header="#{messages.hooks}">
<ul>
<ui:repeat var="hk" value="#{editHooksConfigBean.inplaceUserHooks.toArray()}">
<li><h:outputText value="#{hk.class.name}" /></li>
</ui:repeat>
</ul>
<ul>
<ui:repeat var="hk" value="#{editHooksConfigBean.inplaceGroupHooks.toArray()}">
<li><h:outputText value="#{hk.class.name}" /></li>
</ui:repeat>
</ul>
<p:panel header="#{messages.actual_installed_hooks}" style="margin-top: 16px;">
<h:panelGrid columns="2">
<h:outputLabel value="#{messages.user_hooks}" />
<h:panelGroup>
<ul>
<ui:repeat var="hk" value="#{editHooksConfigBean.inplaceUserHooks.toArray()}">
<li><h:outputText value="#{hk.class.name}" /></li>
</ui:repeat>
</ul>
</h:panelGroup>
<h:outputLabel value="#{messages.group_hooks}" />
<h:panelGroup>
<ul>
<ui:repeat var="hk" value="#{editHooksConfigBean.inplaceGroupHooks.toArray()}">
<li><h:outputText value="#{hk.class.name}" /></li>
</ui:repeat>
</ul>
</h:panelGroup>
</h:panelGrid>
</p:panel>
</div>
</h:form>
......
......@@ -44,6 +44,10 @@
</h:panelGrid>
</p:panel>
<p:panel id="toolsPanel" header="#{messages.tools}" style="margin-top: 16px;">
<p:commandButton value="#{messages.reload_app_config}" action="#{indexConfigBean.scheduleReload()}" />
</p:panel>
</div>
</h:form>
......@@ -51,4 +55,4 @@
</ui:composition>
</f:view>
</body>
</html>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment