Skip to content

Commit

Permalink
Not relying on status fetching to fetch About box information anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimo committed Apr 17, 2023
1 parent 1df4811 commit c8c8f70
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 16 deletions.
105 changes: 105 additions & 0 deletions src/main/java/ch/niceideas/eskimo/controlers/AboutController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* This file is part of the eskimo project referenced at www.eskimo.sh. The licensing information below apply just as
* well to this individual file than to the Eskimo Project as a whole.
*
* Copyright 2019 - 2023 eskimo.sh / https://www.eskimo.sh - All rights reserved.
* Author : eskimo.sh / https://www.eskimo.sh
*
* Eskimo is available under a dual licensing model : commercial and GNU AGPL.
* If you did not acquire a commercial licence for Eskimo, you can still use it and consider it free software under the
* terms of the GNU Affero Public License. You can redistribute it and/or modify it under the terms of the GNU Affero
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* Compliance to each and every aspect of the GNU Affero Public License is mandatory for users who did no acquire a
* commercial license.
*
* Eskimo is distributed as a free software under GNU AGPL in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero Public License for more details.
*
* You should have received a copy of the GNU Affero Public License along with Eskimo. If not,
* see <https://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA, 02110-1301 USA.
*
* You can be released from the requirements of the license by purchasing a commercial license. Buying such a
* commercial license is mandatory as soon as :
* - you develop activities involving Eskimo without disclosing the source code of your own product, software,
* platform, use cases or scripts.
* - you deploy eskimo as part of a commercial product, platform or software.
* For more information, please contact eskimo.sh at https://www.eskimo.sh
*
* The above copyright notice and this licensing notice shall be included in all copies or substantial portions of the
* Software.
*/

package ch.niceideas.eskimo.controlers;

import ch.niceideas.common.utils.Pair;
import ch.niceideas.eskimo.services.ApplicationStatusService;
import ch.niceideas.eskimo.services.ApplicationStatusServiceImpl;
import ch.niceideas.eskimo.services.NotificationService;
import ch.niceideas.eskimo.utils.ReturnStatusHelper;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;


@Controller
public class AboutController extends AbstractInformationController<JSONObject, List<JSONObject>> {

private static final Logger logger = Logger.getLogger(AboutController.class);

@Value("${build.version}")
private String buildVersion;

@Value("${build.timestamp}")
private String buildTimestamp;

@Value("${eskimo.enableKubernetesSubsystem}")
private Boolean enableKubernetesSubsystem;

@Value("${eskimo.demoMode}")
private Boolean demoMode;

@Value("${setup.packagesDownloadUrlRoot}")
private String packagesDownloadUrlRoot;

@GetMapping("/fetch-about-info")
@ResponseBody
public String fetchAboutInfo() {

try {

return ReturnStatusHelper.createOKStatus(map -> {

map.put("about-eskimo-version", buildVersion);

map.put("about-eskimo-build-timestamp", buildTimestamp);
map.put("about-eskimo-runtime-timestamp", ApplicationStatusServiceImpl.getRuntimeStartDate());
map.put("about-eskimo-kube-enabled", enableKubernetesSubsystem);
map.put("about-eskimo-demo-mode", demoMode);
map.put("about-eskimo-packages-url", packagesDownloadUrlRoot);

map.put("about-eskimo-java-home", System.getProperty("java.home"));
map.put("about-eskimo-java-version", System.getProperty("java.version"));
map.put("about-eskimo-working-dir", System.getProperty("user.dir"));
map.put("about-eskimo-os-name", System.getProperty("os.name"));
map.put("about-eskimo-os-version", System.getProperty("os.version"));
});

} catch (JSONException e) {
logger.error (e, e);
throw new IllegalStateException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class ApplicationStatusServiceImpl implements ApplicationStatusService {
@Value("${eskimo.enableKubernetesSubsystem}")
private String enableKubernetes = "true";

private final ThreadLocal<SimpleDateFormat> localDateFormatter
private final static ThreadLocal<SimpleDateFormat> localDateFormatter
= ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));

private final ReentrantLock statusUpdateLock = new ReentrantLock();
Expand All @@ -119,7 +119,7 @@ public ApplicationStatusServiceImpl() {
this.scheduler = Executors.newSingleThreadScheduledExecutor();

logger.info ("Initializing Application Status update scheduler ...");
scheduler.scheduleAtFixedRate(this::updateStatus, 15L * 1000L, 15L * 1000L, TimeUnit.SECONDS);
scheduler.scheduleAtFixedRate(this::updateStatus, 15L, 15L, TimeUnit.SECONDS);
}

@PreDestroy
Expand Down Expand Up @@ -177,12 +177,7 @@ public void updateStatus() {

feedInKubeConfigInfo(systemStatus);

// Get JVM's thread system bean
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
long startTime = runtimeMXBean.getStartTime();
Date startDate = new Date(startTime);

systemStatus.setValueForPath("startTimestamp", localDateFormatter.get().format(startDate));
systemStatus.setValueForPath("startTimestamp", getRuntimeStartDate());

lastStatus.set (systemStatus);

Expand All @@ -191,6 +186,15 @@ public void updateStatus() {
}
}

public static String getRuntimeStartDate() {
// Get JVM's thread system bean
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
long startTime = runtimeMXBean.getStartTime();
Date startDate = new Date(startTime);

return localDateFormatter.get().format(startDate);
}

private void feedInKubeConfigInfo(JsonWrapper systemStatus) {
systemStatus.setValueForPath(AVAILABLE_KUBE_SERVICES, servicesDefinition.countKubernetesServices());
try {
Expand Down
42 changes: 37 additions & 5 deletions src/main/webapp/html/eskimoAbout.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,48 @@ <h4 class="modal-title">About Eskimo CE</h4>
<button id="about-modal-header-close" type="button" class="btn-close" ></button>
</div>
<div id="about-modal-body" class="modal-body">
<div class="text-center">
<h3>Eskimo CE v.<span id="about-eskimo-version"></span></h3>
</div>
<div class="text-center">
<div class="row justify-content-center text-center">
<img src="images/eskimo-icon-black.png" alt="Eskimo Icon Black" style="width: 100px;">
</div>
<div class="text-center">
<div class="row justify-content-center text-center">
<a target="_blank" rel="noopener noreferrer" href="https://www.eskimo.sh">www.eskimo.sh</a>
<br>
</div>
<div class="row justify-content-center text-center border-bottom">
<h3>Eskimo CE v.<span id="about-eskimo-version"></span></h3>
<br><br>
</div>
<div class="row border-bottom">
<div class="col-sm-12 col-md-12 col-lg-6">
Eskimo build timestamp : <span id="about-eskimo-build-timestamp"></span>
<br>
Runtime Start timestamp : <span id="about-eskimo-runtime-timestamp"></span>
<br>
Kubernetes Enabled : <span id="about-eskimo-kube-enabled"></span>
<br>
Demo Mode : <span id="about-eskimo-demo-mode"></span>
<br>
Packages Download URL : <span id="about-eskimo-packages-url"></span>
<br>
</div>
<div class="col-sm-12 col-md-12 col-lg-6">
Java Home : <span id="about-eskimo-java-home"></span>
<br>
Java Version : <span id="about-eskimo-java-version"></span>
<br>
Working Dir : <span id="about-eskimo-working-dir"></span>
<br>
OS Name : <span id="about-eskimo-os-name"></span>
<br>
OS Version : <span id="about-eskimo-os-version"></span>
</div>
</div>
<div class="row justify-content-center text-center">
&nbsp;
<br><br>
<h3>Eskimo Licensing</h3>
<br><br>
</div>
<div>
<p>
Copyright 2019 - 2023 eskimo.sh / https://www.eskimo.sh - All rights reserved.<br>
Expand Down
32 changes: 29 additions & 3 deletions src/main/webapp/scripts/eskimoAbout.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,35 @@ eskimo.About = function() {

function showAbout () {

$("#about-eskimo-version").html($("#system-information-version").html());

$('#about-modal').modal("show");
$.ajaxGet({
timeout: 1000 * 10,
url: "fetch-about-info",
success: (data, status, jqXHR) => {

if (!data || data.error) {
console.error(data.error);
eskimoMain.alert(ESKIMO_ALERT_LEVEL.ERROR, data.error);

} else {

$("#about-eskimo-version").html(data["about-eskimo-version"]);

$("#about-eskimo-build-timestamp").html(data["about-eskimo-build-timestamp"]);
$("#about-eskimo-runtime-timestamp").html(data["about-eskimo-runtime-timestamp"]);
$("#about-eskimo-kube-enabled").html("" + data["about-eskimo-kube-enabled"]);
$("#about-eskimo-demo-mode").html("" + data["about-eskimo-demo-mode"]);
$("#about-eskimo-packages-url").html(data["about-eskimo-packages-url"]);

$("#about-eskimo-java-home").html(data["about-eskimo-java-home"]);
$("#about-eskimo-java-version").html(data["about-eskimo-java-version"]);
$("#about-eskimo-working-dir").html(data["about-eskimo-working-dir"]);
$("#about-eskimo-os-name").html(data["about-eskimo-os-name"]);
$("#about-eskimo-os-version").html(data["about-eskimo-os-version"]);

$('#about-modal').modal("show");
}
}
});
}
this.showAbout = showAbout;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* This file is part of the eskimo project referenced at www.eskimo.sh. The licensing information below apply just as
* well to this individual file than to the Eskimo Project as a whole.
*
* Copyright 2019 - 2023 eskimo.sh / https://www.eskimo.sh - All rights reserved.
* Author : eskimo.sh / https://www.eskimo.sh
*
* Eskimo is available under a dual licensing model : commercial and GNU AGPL.
* If you did not acquire a commercial licence for Eskimo, you can still use it and consider it free software under the
* terms of the GNU Affero Public License. You can redistribute it and/or modify it under the terms of the GNU Affero
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option)
* any later version.
* Compliance to each and every aspect of the GNU Affero Public License is mandatory for users who did no acquire a
* commercial license.
*
* Eskimo is distributed as a free software under GNU AGPL in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero Public License for more details.
*
* You should have received a copy of the GNU Affero Public License along with Eskimo. If not,
* see <https://www.gnu.org/licenses/> or write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA, 02110-1301 USA.
*
* You can be released from the requirements of the license by purchasing a commercial license. Buying such a
* commercial license is mandatory as soon as :
* - you develop activities involving Eskimo without disclosing the source code of your own product, software,
* platform, use cases or scripts.
* - you deploy eskimo as part of a commercial product, platform or software.
* For more information, please contact eskimo.sh at https://www.eskimo.sh
*
* The above copyright notice and this licensing notice shall be included in all copies or substantial portions of the
* Software.
*/


package ch.niceideas.eskimo.controlers;

import ch.niceideas.common.json.JsonWrapper;
import ch.niceideas.eskimo.EskimoApplication;
import ch.niceideas.eskimo.services.NotificationService;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

@ContextConfiguration(classes = EskimoApplication.class)
@SpringBootTest(classes = EskimoApplication.class)
@TestPropertySource("classpath:application-test.properties")
@ActiveProfiles({"no-web-stack", "test-system", "test-setup"})
public class AboutControllerTest {

@Autowired
private AboutController aboutController;

@Test
public void testNominal() {

JsonWrapper result = new JsonWrapper(aboutController.fetchAboutInfo());

assertEquals ("false", result.getValueForPathAsString("about-eskimo-demo-mode"));
assertEquals ("true", result.getValueForPathAsString("about-eskimo-kube-enabled"));
assertEquals ("https://www.eskimo.sh/eskimo/V0.4/", result.getValueForPathAsString("about-eskimo-packages-url"));
assertEquals ("OK", result.getValueForPathAsString("status"));

// all the rest can't be tested as it changes dynamically unfortunately
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;

public class EskimoAboutTest extends AbstractWebTest {

@BeforeEach
Expand All @@ -59,12 +61,43 @@ public void setUp() throws Exception {
@Test
public void testNominal() throws Exception {

js("$.ajaxGet = function (dataObj) {" +
" dataObj.success({\n" +
" \"about-eskimo-demo-mode\": false,\n" +
" \"about-eskimo-runtime-timestamp\": \"2023-04-17 16:51:13\",\n" +
" \"about-eskimo-kube-enabled\": true,\n" +
" \"about-eskimo-os-version\": \"6.1.0-5-amd64\",\n" +
" \"about-eskimo-version\": \"0.5-SNAPSHOT\",\n" +
" \"about-eskimo-build-timestamp\": \"2023-04-17T10:17:18Z\",\n" +
" \"about-eskimo-packages-url\": \"https://www.eskimo.sh/eskimo/V0.5/\",\n" +
" \"about-eskimo-java-home\": \"/usr/lib/jvm/java-11-openjdk-amd64\",\n" +
" \"about-eskimo-working-dir\": \"/data/badtrash/work/eskimo\",\n" +
" \"about-eskimo-os-name\": \"Linux\",\n" +
" \"status\": \"OK\",\n" +
" \"about-eskimo-java-version\": \"11.0.17\"\n" +
"});" +
"}");

js("eskimoAbout.showAbout()");
ActiveWaiter.wait(() -> js("return $('#about-modal').css('display')").equals("block"));

assertCssEquals("block", "#about-modal", "display");
assertCssEquals("visible", "#about-modal", "visibility");

assertJavascriptEquals("0.5-SNAPSHOT", "$('#about-eskimo-version').html()");

assertJavascriptEquals("false", "$('#about-eskimo-demo-mode').html()");
assertJavascriptEquals("2023-04-17 16:51:13", "$('#about-eskimo-runtime-timestamp').html()");
assertJavascriptEquals("true", "$('#about-eskimo-kube-enabled').html()");
assertJavascriptEquals("2023-04-17T10:17:18Z", "$('#about-eskimo-build-timestamp').html()");
assertJavascriptEquals("https://www.eskimo.sh/eskimo/V0.5/", "$('#about-eskimo-packages-url').html()");

assertJavascriptEquals("6.1.0-5-amd64", "$('#about-eskimo-os-version').html()");
assertJavascriptEquals("/usr/lib/jvm/java-11-openjdk-amd64", "$('#about-eskimo-java-home').html()");
assertJavascriptEquals("/data/badtrash/work/eskimo", "$('#about-eskimo-working-dir').html()");
assertJavascriptEquals("Linux", "$('#about-eskimo-os-name').html()");
assertJavascriptEquals("11.0.17", "$('#about-eskimo-java-version').html()");

js("eskimoAbout.cancelAbout()");
ActiveWaiter.wait(() -> {
Object display = js("$('#about-modal').css('display')");
Expand All @@ -73,6 +106,7 @@ public void testNominal() throws Exception {

//assertCssValue("#about-modal", "visibility", "hidden");
assertCssEquals("none", "#about-modal", "display");

}

}
Expand Down

0 comments on commit c8c8f70

Please sign in to comment.