Skip to content

Commit f92ff21

Browse files
committed
Import developments of ESB-210 e ESB-658 in admin-console module:
- reload config async
1 parent b489f88 commit f92ff21

File tree

16 files changed

+607
-111
lines changed

16 files changed

+607
-111
lines changed

Dockerfile.tomcat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LABEL name="Entando App" \
1010
summary="Entando Application" \
1111
description="This Entando app engine application provides APIs and composition for Entando applications"
1212

13-
COPY target/generated-resources/licenses /licenses
14-
COPY target/generated-resources/licenses.xml /
13+
#COPY target/generated-resources/licenses /licenses
14+
#COPY target/generated-resources/licenses.xml /
1515

1616
COPY --chown=185:0 webapp/target/*.war /usr/local/tomcat/webapps/
1717
# Copy CookieProcessor JAR if it exists

admin-console/src/main/java/com/agiletec/apsadmin/admin/BaseAdminAction.java

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@
1313
*/
1414
package com.agiletec.apsadmin.admin;
1515

16-
import java.util.ArrayList;
17-
import java.util.Enumeration;
18-
import java.util.Iterator;
19-
import java.util.List;
20-
import java.util.Map;
21-
22-
import org.entando.entando.ent.util.EntLogging.EntLogger;
23-
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
24-
import org.springframework.web.context.WebApplicationContext;
16+
import static com.agiletec.apsadmin.admin.reload.ReloadConfigThread.RELOAD_THREAD;
2517

2618
import com.agiletec.aps.system.SystemConstants;
2719
import com.agiletec.aps.system.common.entity.event.ReloadingEntitiesReferencesEvent;
@@ -31,7 +23,18 @@
3123
import com.agiletec.aps.system.services.page.IPage;
3224
import com.agiletec.aps.system.services.page.IPageManager;
3325
import com.agiletec.aps.util.ApsWebApplicationUtils;
26+
import com.agiletec.apsadmin.admin.reload.ReloadConfigThread;
3427
import com.agiletec.apsadmin.system.BaseAction;
28+
import java.util.ArrayList;
29+
import java.util.Enumeration;
30+
import java.util.HashMap;
31+
import java.util.Iterator;
32+
import java.util.List;
33+
import java.util.Map;
34+
import org.apache.commons.lang3.StringUtils;
35+
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
36+
import org.entando.entando.ent.util.EntLogging.EntLogger;
37+
import org.springframework.web.context.WebApplicationContext;
3538

3639
/**
3740
* This base action implements the default actions available for the system
@@ -43,23 +46,61 @@ public class BaseAdminAction extends BaseAction {
4346

4447
private static final EntLogger logger = EntLogFactory.getSanitizedLogger(BaseAdminAction.class);
4548

49+
public static final String RELOAD_ERROR = "reloadError";
50+
public static final String IN_PROGRESS = "inProgress";
51+
public static final String NEW_PARAM_MARKER = "_newParamMarker";
52+
4653
/**
4754
* Reload the system configuration.
4855
*
4956
* @return the result code.
5057
*/
5158
public String reloadConfig() {
5259
try {
53-
ApsWebApplicationUtils.executeSystemRefresh(this.getRequest());
54-
logger.info("Reload config started");
55-
this.setReloadingResult(SUCCESS_RELOADING_RESULT_CODE);
56-
} catch (Throwable t) {
57-
logger.error("error in reloadConfig", t);
60+
if (!ApsWebApplicationUtils.isReloadInProgress()) {
61+
ReloadConfigThread rct = new ReloadConfigThread(this.getRequest());
62+
logger.info("Starting reload configuration thread");
63+
rct.start();
64+
} else {
65+
logger.info("Reload operation already in progress!");
66+
}
67+
this.setReloadingResult(PROGRESS_RELOADING_RESULT_CODE);
68+
} catch (Exception e) {
69+
logger.error("unexpected error while launching system reload", e);
5870
this.setReloadingResult(FAILURE_RELOADING_RESULT_CODE);
71+
return RELOAD_ERROR;
72+
}
73+
return SUCCESS;
74+
}
75+
76+
public String reloadStatus() {
77+
if (ApsWebApplicationUtils.isReloadInProgress()) {
78+
this.setReloadingResult(PROGRESS_RELOADING_RESULT_CODE);
79+
return IN_PROGRESS;
5980
}
81+
updateReloadStatusResult();
6082
return SUCCESS;
6183
}
6284

85+
public String reloadStatusJson() {
86+
return SUCCESS;
87+
}
88+
89+
public boolean isReloadingErrorDetect() {
90+
return ApsWebApplicationUtils.getReloadInfo()
91+
.values()
92+
.stream()
93+
.anyMatch(StringUtils::isNotBlank);
94+
}
95+
96+
public int getReloadProgress() {
97+
return ApsWebApplicationUtils.getReloadProgress();
98+
}
99+
100+
public Map<String, String> getReloadInfo() {
101+
return new HashMap<>(ApsWebApplicationUtils.getReloadInfo());
102+
}
103+
63104
/**
64105
* Reload the references of all the existing entities.
65106
*
@@ -87,7 +128,7 @@ public void setReloadingResult(int reloadingResult) {
87128
}
88129

89130
/**
90-
* Get the system parameters in order to edit them.
131+
* Get the system parameters to edit them.
91132
*
92133
* @return the result code.
93134
*/
@@ -144,7 +185,7 @@ protected String getConfigParameter() {
144185
* Refresh the map of parameters with values fetched from the request
145186
*
146187
* @param keepOldParam when true, when a system parameter is not found in
147-
* request, the previous system parameter will be stored
188+
* the request, the previous system parameter will be stored
148189
*/
149190
protected void updateLocalParams(boolean keepOldParam) {
150191
Iterator<String> paramNames = this.getSystemParams().keySet().iterator();
@@ -205,6 +246,16 @@ private void addFreePublicPages(IPage page, List<IPage> pages) {
205246
}
206247
}
207248

249+
protected void updateReloadStatusResult() {
250+
if (ApsWebApplicationUtils.getReloadInfo().containsKey(RELOAD_THREAD)) {
251+
this.setReloadingResult(FAILURE_RELOADING_RESULT_CODE);
252+
} else if (isReloadingErrorDetect()) {
253+
this.setReloadingResult(WARNING_RELOADING_RESULT_CODE);
254+
} else {
255+
this.setReloadingResult(SUCCESS_RELOADING_RESULT_CODE);
256+
}
257+
}
258+
208259
protected ConfigInterface getConfigManager() {
209260
return _configManager;
210261
}
@@ -230,7 +281,7 @@ public void setSystemParams(Map<String, String> systemParams) {
230281
}
231282

232283
public String getExternalParamMarker() {
233-
return "_newParamMarker";
284+
return NEW_PARAM_MARKER;
234285
}
235286

236287
private ConfigInterface _configManager;
@@ -242,5 +293,7 @@ public String getExternalParamMarker() {
242293

243294
public static final int FAILURE_RELOADING_RESULT_CODE = 0;
244295
public static final int SUCCESS_RELOADING_RESULT_CODE = 1;
296+
public static final int PROGRESS_RELOADING_RESULT_CODE = 2;
297+
public static final int WARNING_RELOADING_RESULT_CODE = 3;
245298

246299
}

admin-console/src/main/java/com/agiletec/apsadmin/admin/baseAdmin.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
<package name="core_do/BaseAdmin" namespace="/do/BaseAdmin" extends="entando-default">
99

10+
<interceptors>
11+
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor" />
12+
<interceptor-stack name="jsonStack">
13+
<interceptor-ref name="json">
14+
<param name="enableSMD">true</param>
15+
</interceptor-ref>
16+
</interceptor-stack>
17+
</interceptors>
18+
1019
<action name="settings" class="baseAdminAction">
1120
<result type="tiles">admin.BaseAdmin.settings</result>
1221
<interceptor-ref name="entandoDefaultStack"><param name="requestAuth.requiredPermission">superuser</param></interceptor-ref>
@@ -17,7 +26,21 @@
1726
<interceptor-ref name="entandoDefaultStack"><param name="requestAuth.requiredPermission">superuser</param></interceptor-ref>
1827
</action>
1928
<action name="reloadConfig" class="baseAdminAction" method="reloadConfig">
29+
<result type="tiles">admin.BaseAdmin.reloadInProgress</result>
30+
<result type="tiles" name="reloadError">admin.BaseAdmin.reloadConfigResult</result>
31+
<interceptor-ref name="entandoDefaultStack"><param name="requestAuth.requiredPermission">superuser</param></interceptor-ref>
32+
</action>
33+
34+
<action name="reloadStatus" class="baseAdminAction" method="reloadStatus">
2035
<result type="tiles">admin.BaseAdmin.reloadConfigResult</result>
36+
<result type="tiles" name="inProgress">admin.BaseAdmin.reloadInProgress</result>
37+
<interceptor-ref name="entandoDefaultStack"><param name="requestAuth.requiredPermission">superuser</param></interceptor-ref>
38+
</action>
39+
40+
<action name="reloadStatusJson" class="baseAdminAction" method="reloadStatusJson">
41+
<result type="json" >
42+
<param name="root">reloadProgress</param>
43+
</result>
2144
<interceptor-ref name="entandoDefaultStack"><param name="requestAuth.requiredPermission">superuser</param></interceptor-ref>
2245
</action>
2346

admin-console/src/main/java/com/agiletec/apsadmin/admin/package_en.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name.editor.ckeditor=CKEditor
99
name.editor.hoofed=Hoofed (moo-Entando component)
1010

1111
message.reloadConfig.ok=The configuration has been reloaded
12+
message.reloadConfig.warning=Some services reported an error during the reload
1213
message.reloadConfig.ko=Something went wrong while reloading the configuration. Try again in a minute.
1314
message.reloadEntities.ok=Reloading Entity references
1415
message.configSystemParams.ok=The settings have been updated
@@ -22,3 +23,11 @@ page.reloadConfig.help=The Reload Configuration section allows you to reload the
2223
title.entityManagement = Entities
2324
title.entityAdmin.manage = Entities
2425
title.entityAdmin.entityManagers.reload = Reload the references
26+
27+
28+
reload.table.head.beanId=Service ID
29+
reload.table.head.status=Status
30+
reload.bean.status.ok=Success
31+
reload.bean.status.ko=ERROR
32+
33+
reload.legend.info=The information displayed depends on how the service was implemented. Any internal errors may not appear on this screen but are visible in the system logs.

admin-console/src/main/java/com/agiletec/apsadmin/admin/package_it.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ name.editor.ckeditor=CKEditor
1010
name.editor.hoofed=Hoofed (fa parte di moo-Entando)
1111

1212
message.reloadConfig.ok=La configurazione di sistema &egrave; stata ricaricata
13+
message.reloadConfig.warning=Durante il ricaricamento alcuni servizi hanno riportato un errore
1314
message.reloadConfig.ko=Non &egrave; stato possibile ricaricare la configurazione di sistema
1415
message.reloadEntities.ok=Il ricaricamento delle referenze delle Entit&agrave; &egrave; in corso
1516
message.configSystemParams.ok=I cambiamenti sono stati salvati
@@ -23,3 +24,11 @@ page.reloadConfig.help=Dalla sezione RICARICA CONFIGURAZIONE &egrave; possibile
2324
title.entityManagement = Entit&agrave;
2425
title.entityAdmin.manage = Entit&agrave;
2526
title.entityAdmin.entityManagers.reload = Ricarica le referenze
27+
28+
29+
reload.table.head.beanId=Service ID
30+
reload.table.head.status=Status
31+
reload.bean.status.ok=Success
32+
reload.bean.status.ko=ERROR
33+
34+
reload.legend.info=The information displayed depends on how the service was implemented. Any internal errors may not appear on this screen but are visible in the system logs.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.agiletec.apsadmin.admin.reload;
2+
3+
import com.agiletec.aps.util.ApsWebApplicationUtils;
4+
import org.entando.entando.ent.util.EntLogging.EntLogFactory;
5+
import org.slf4j.Logger;
6+
7+
import jakarta.servlet.http.HttpServletRequest;
8+
9+
public class ReloadConfigThread extends Thread {
10+
11+
public static final String RELOAD_THREAD = "RELOAD THREAD";
12+
13+
private final Logger log = EntLogFactory.getSanitizedLogger(ReloadConfigThread.class);
14+
private final HttpServletRequest request;
15+
16+
public ReloadConfigThread(final HttpServletRequest request) {
17+
this.request = request;
18+
}
19+
20+
@Override
21+
public void run() {
22+
try {
23+
ApsWebApplicationUtils.executeSystemRefresh(request);
24+
log.info("ReloadConfigThread completed execution");
25+
} catch (InterruptedException e) {
26+
ApsWebApplicationUtils.getReloadInfo().put(RELOAD_THREAD, e.getMessage());
27+
log.error("Thread interrupted", e);
28+
Thread.currentThread().interrupt();
29+
} catch (Throwable e) {
30+
ApsWebApplicationUtils.getReloadInfo().put(RELOAD_THREAD, e.getMessage());
31+
log.error("unexpected thread error", e);
32+
Thread.currentThread().interrupt();
33+
}
34+
}
35+
36+
}

admin-console/src/main/java/com/agiletec/apsadmin/global-messages_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ label.preview=Preview
2828
label.remove=Delete
2929
label.refresh=Refresh
3030
label.reload=Reload
31+
label.reload.check=Refresh
3132
label.swap=Swap
3233
label.move=Move
3334
label.moveUp=Move up

admin-console/src/main/java/com/agiletec/apsadmin/global-messages_it.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ label.preview=Anteprima
2929
label.remove=Elimina
3030
label.refresh=Aggiorna
3131
label.reload=Ricarica
32+
label.reload.check=Aggiorna
3233
label.swap=Scambia
3334

3435
label.move=Sposta

admin-console/src/main/java/com/agiletec/apsadmin/system/BaseAction.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected boolean isCurrentUserMemberOf(String groupName) {
6262

6363
/**
6464
* Check if the current user has the given permission granted. It always returns true if the
65-
* user has the the "superuser" permission set in some role.
65+
* user has the "superuser" permission set in some role.
6666
* @param permissionName The name of the permission to check against the current user.
6767
* @return true if the user has the permission granted, false otherwise.
6868
*/
@@ -125,25 +125,24 @@ protected List<Group> getActualAllowedGroups() {
125125
}
126126
}
127127
}
128-
Collections.sort(this._actualAllowedGroups, new BeanComparator("description"));
128+
this._actualAllowedGroups.sort(new BeanComparator<>("description"));
129129
return this._actualAllowedGroups;
130130
}
131131

132132
protected List<String> getActualAllowedGroupCodes() {
133133
List<String> codes = new ArrayList<>();
134134
List<Group> groups = this.getActualAllowedGroups();
135-
for (int i = 0; i < groups.size(); i++) {
136-
Group group = groups.get(i);
137-
if (null != group && !codes.contains(group.getName())) {
138-
codes.add(group.getName());
139-
}
140-
}
135+
for (Group group : groups) {
136+
if (null != group && !codes.contains(group.getName())) {
137+
codes.add(group.getName());
138+
}
139+
}
141140
return codes;
142141
}
143142

144143
/**
145144
* Return the current system language used in the back-end interface. If this language does not
146-
* belong to those known by the system the default language is returned. A log line will
145+
* belong to those known by the system, the default language is returned. A log line will
147146
* report the problem.
148147
* @return The current language.
149148
*/
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<%@ taglib prefix="s" uri="/struts-tags" %>
2+
<%@ taglib prefix="wp" uri="/aps-core" %>
3+
4+
<ol class="breadcrumb page-tabs-header breadcrumb-position">
5+
<li><s:text name="menu.configure"/></li>
6+
<li>
7+
<a href="<s:url action="reloadChoose" namespace="/do/BaseAdmin" />">
8+
<s:text name="title.reload.config" />
9+
</a>
10+
</li>
11+
<li class="page-title-container">
12+
<s:text name="menu.reload.config" />
13+
</li>
14+
</ol>
15+
<h1 class="page-title-container">
16+
<div>
17+
<s:text name="menu.reload.config" />
18+
<span class="pull-right">
19+
<button type="button" class="btn btn-link" data-toggle="popover" data-trigger="focus" data-html="true"
20+
title=""
21+
data-content="<s:text name='page.reloadConfig.help' />"
22+
data-placement="left" data-original-title="">
23+
<i class="fa fa-question-circle-o fa-2x" aria-hidden="true"></i>
24+
</button>
25+
</span>
26+
</div>
27+
</h1>
28+
<div class="text-right">
29+
<div class="form-group-separator"></div>
30+
</div>
31+
<br>
32+
<br>

0 commit comments

Comments
 (0)