Skip to content

Commit

Permalink
fix #2762 upgrade tasks for 14.10
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Aug 5, 2023
1 parent f13e89a commit a73b5e0
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
*/
package org.codelibs.fess.app.web.admin.upgrade;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.codelibs.core.lang.StringUtil;
import org.codelibs.core.stream.StreamUtil;
import org.codelibs.curl.CurlResponse;
import org.codelibs.fess.Constants;
import org.codelibs.fess.annotation.Secured;
import org.codelibs.fess.app.service.ScheduledJobService;
import org.codelibs.fess.app.web.base.FessAdminAction;
Expand All @@ -30,8 +39,10 @@
import org.codelibs.fess.es.config.exbhv.RoleTypeBhv;
import org.codelibs.fess.es.config.exbhv.WebConfigBhv;
import org.codelibs.fess.es.user.exbhv.RoleBhv;
import org.codelibs.fess.mylasta.direction.FessConfig;
import org.codelibs.fess.util.ComponentUtil;
import org.codelibs.fess.util.UpgradeUtil;
import org.codelibs.opensearch.runner.net.OpenSearchCurl;
import org.lastaflute.web.Execute;
import org.lastaflute.web.response.HtmlResponse;
import org.lastaflute.web.ruts.process.ActionRuntime;
Expand Down Expand Up @@ -99,6 +110,8 @@ public class AdminUpgradeAction extends FessAdminAction {

private static final String VERSION_14_8 = "14.8";

private static final String VERSION_14_9 = "14.9";

// ===================================================================================
// Attribute
//
Expand Down Expand Up @@ -192,6 +205,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -229,6 +243,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -265,6 +280,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -300,6 +316,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -334,6 +351,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -367,6 +385,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -399,6 +418,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -430,6 +450,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -460,6 +481,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -489,6 +511,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand Down Expand Up @@ -517,6 +540,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -543,6 +567,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -568,6 +593,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -592,6 +618,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -615,6 +642,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -638,6 +666,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -660,6 +689,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -681,6 +711,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -701,6 +732,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -720,6 +752,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -738,6 +771,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -755,6 +789,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -771,6 +806,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -786,6 +822,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -800,6 +837,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
upgradeFrom14_6();
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -813,6 +851,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
try {
upgradeFrom14_7();
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -825,6 +864,7 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
} else if (VERSION_14_8.equals(form.targetVersion)) {
try {
upgradeFrom14_8();
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));
Expand All @@ -834,6 +874,18 @@ public HtmlResponse upgradeFrom(final UpgradeForm form) {
logger.warn("Failed to upgrade data.", e);
saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, VERSION_14_8, e.getLocalizedMessage()));
}
} else if (VERSION_14_9.equals(form.targetVersion)) {
try {
upgradeFrom14_9();
upgradeFromAll();

saveInfo(messages -> messages.addSuccessStartedDataUpdate(GLOBAL));

systemHelper.reloadConfiguration();
} catch (final Exception e) {
logger.warn("Failed to upgrade data.", e);
saveError(messages -> messages.addErrorsFailedToUpgradeFrom(GLOBAL, VERSION_14_9, e.getLocalizedMessage()));
}
} else {
saveError(messages -> messages.addErrorsUnknownVersionForUpgrade(GLOBAL));
}
Expand Down Expand Up @@ -1010,6 +1062,89 @@ private void upgradeFrom14_8() {
// nothing
}

private void upgradeFrom14_9() {
// update mapping text files
final FessConfig fessConfig = ComponentUtil.getFessConfig();

final String fesenType = fessConfig.getFesenType();
switch (fesenType) {
case Constants.FESEN_TYPE_CLOUD:
case Constants.FESEN_TYPE_AWS:
// nothing
break;
default:
for (final String path : getDictionaryPaths()) {
if (path.endsWith("mapping.txt")) {
logger.debug("Updating {}", path);
final String content = getDictionaryContent(path);
if (content != null) {
sendDictionaryContent(path, StreamUtil.split(content, "\n")
.get(stream -> stream.map(s -> s.replaceFirst("#.*", StringUtil.EMPTY)).collect(Collectors.joining("\n"))));
}
}
}
try (CurlResponse response = ComponentUtil.getCurlHelper().post("/_configsync/flush").execute()) {
if (response.getHttpStatusCode() == 200) {
logger.info("Flushed config files.");
} else {
logger.warn("Failed to flush config files.");
}
} catch (final Exception e) {
logger.warn("Failed to flush config files.", e);
}
break;
}

}

private String[] getDictionaryPaths() {
try (CurlResponse response = ComponentUtil.getCurlHelper().get("/_configsync/file").param("size", "1000").execute()) {
if (response.getHttpStatusCode() == 200) {
final Map<String, Object> contentMap = response.getContent(OpenSearchCurl.jsonParser());
if (contentMap.get("path") instanceof final List<?> pathList) {
return pathList.stream().map(Object::toString).toArray(n -> new String[n]);
}
} else if (response.getContentException() != null) {
logger.warn("ConfigSync request failed.", response.getContentException());
} else {
logger.warn("ConfigSync request failed. The response is {}", response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("ConfigSync request failed.", e);
}
return new String[0];
}

private String getDictionaryContent(final String path) {
try (CurlResponse response = ComponentUtil.getCurlHelper().get("/_configsync/file").param("path", path).execute()) {
if (response.getHttpStatusCode() == 200) {
return response.getContentAsString();
}
if (response.getContentException() != null) {
logger.warn("{} is invalid path.", path, response.getContentException());
} else {
logger.warn("{} is invalid path. The response is {}", path, response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("{} is invalid path.", path, e);
}
return null;
}

private void sendDictionaryContent(final String path, final String content) {
try (CurlResponse response = ComponentUtil.getCurlHelper().post("/_configsync/file").param("path", path).body(content).execute()) {
if (response.getHttpStatusCode() == 200) {
logger.info("Updated {}", path);
} else if (response.getContentException() != null) {
logger.warn("{} is invalid path.", path, response.getContentException());
} else {
logger.warn("{} is invalid path. The response is {}", path, response.getContentAsString());
}
} catch (final IOException e) {
logger.warn("{} is invalid path.", path, e);
}
}

private void upgradeFromAll() {
// nothing
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/codelibs/fess/helper/SystemHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void init() {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
final Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.set(2024, 12 - 1, 1); // EOL Date
cal.set(2025, 1 - 1, 1); // EOL Date
eolTime = cal.getTimeInMillis();
if (isEoled()) {
logger.error("Your system is out of support. See https://fess.codelibs.org/eol.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<la:option value="14.6">14.6</la:option>
<la:option value="14.7">14.7</la:option>
<la:option value="14.8">14.8</la:option>
<la:option value="14.9">14.9</la:option>
</la:select>
</div>
</div>
Expand Down

0 comments on commit a73b5e0

Please sign in to comment.