Skip to content
Permalink
Browse files

MSK-488 KillSwitch Info/Management page

  • Loading branch information...
gsokolov
gsokolov committed Mar 14, 2019
1 parent f86b5ea commit 016184a981173b6be1c26c784a10be7f785f8238
@@ -3,6 +3,8 @@
import org.configureme.annotations.Configure;
import org.configureme.annotations.ConfigureMe;

import java.io.Serializable;

/**
* This configuration provides possibilities to disable parts of MoSKito. Even if the authors of the framework
* do not understand, why you would disable it, we decided to support it finally.
@@ -14,7 +16,13 @@
* @since 2019-03-12 22:23
*/
@ConfigureMe
public class KillSwitchConfiguration {
public class KillSwitchConfiguration implements Serializable {

/**
* SerialVersionUID.
*/
private static final long serialVersionUID = 5671582449272126029L;

/**
* If true no metrics will be collected, if supported by the collector.
* Will be supported by AOP, CDI and Proxies in first turn.
@@ -32,8 +32,10 @@
import net.anotheria.moskito.webui.journey.action.ShowJourneysAction;
import net.anotheria.moskito.webui.more.action.AdditionalSectionAction;
import net.anotheria.moskito.webui.more.action.ShowConfigAction;
import net.anotheria.moskito.webui.more.action.ShowKillSwitchAction;
import net.anotheria.moskito.webui.more.action.ShowLibsAction;
import net.anotheria.moskito.webui.more.action.ShowMBeansAction;
import net.anotheria.moskito.webui.more.action.SwitchKillSettingAction;
import net.anotheria.moskito.webui.more.action.UpdateAction;
import net.anotheria.moskito.webui.plugins.action.RemovePluginAction;
import net.anotheria.moskito.webui.plugins.action.ShowPluginsAction;
@@ -279,7 +281,12 @@
mappings.addMapping("mskPlugins", ShowPluginsAction.class,
new CommandForward("success", "/net/anotheria/moskito/webui/more/jsp/Plugins.jsp")
);

mappings.addMapping("mskKillSwitch", ShowKillSwitchAction.class,
new CommandForward("success", "/net/anotheria/moskito/webui/more/jsp/KillSwitch.jsp")
);
mappings.addMapping("mskSwitchKillSetting", SwitchKillSettingAction.class,
new CommandForward("success", "/net/anotheria/moskito/webui/more/jsp/KillSwitch.jsp")
);
mappings.addMapping("mskRemovePlugin", RemovePluginAction.class,
new CommandDeepLinkRedirect("redirect", "mskPlugins")
);
@@ -0,0 +1,51 @@
package net.anotheria.moskito.webui.more.action;

import net.anotheria.maf.action.ActionCommand;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.maf.bean.FormBean;
import net.anotheria.moskito.core.config.KillSwitchConfiguration;
import net.anotheria.moskito.core.config.MoskitoConfiguration;
import net.anotheria.moskito.webui.shared.bean.NaviItem;
import net.anotheria.moskito.webui.util.APILookupUtility;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* This action shows current kill switch options.
*
*/
public class ShowKillSwitchAction extends BaseAdditionalAction{
@Override
protected String getLinkToCurrentPage(HttpServletRequest req) {
return "mskKillSwitch?ts="+System.currentTimeMillis();
}

@Override
public ActionCommand execute(ActionMapping mapping, FormBean formBean, HttpServletRequest req, HttpServletResponse res) throws Exception {

if (!APILookupUtility.isLocal()) {
MoskitoConfiguration config = getAdditionalFunctionalityAPI().getConfiguration();
KillSwitchConfiguration killSwitchConfiguration = config.getKillSwitch();

req.setAttribute("killSwitchConfiguration", killSwitchConfiguration != null ? killSwitchConfiguration : new KillSwitchConfiguration());
}
return mapping.success();
}

@Override
protected String getPageName() {
return "killswitch";
}

@Override
protected NaviItem getCurrentSubNaviItem() {
return NaviItem.MORE_KILLSWITCH;
}

@Override
protected String getSubTitle() {
return "Kill Switch";
}

}
@@ -0,0 +1,39 @@
package net.anotheria.moskito.webui.more.action;

import net.anotheria.maf.action.ActionCommand;
import net.anotheria.maf.action.ActionMapping;
import net.anotheria.maf.bean.FormBean;
import net.anotheria.moskito.core.config.KillSwitchConfiguration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* This action creates a new accumulator.
*/
public class SwitchKillSettingAction extends BaseAdditionalAction {

@Override
protected String getLinkToCurrentPage(HttpServletRequest req) {
return "mskKillSwitch?ts="+System.currentTimeMillis();
}

@Override
public ActionCommand execute(ActionMapping mapping, FormBean formBean, HttpServletRequest request, HttpServletResponse response) throws Exception {
String name = request.getParameter("name");
String value = request.getParameter("value");
boolean val = Boolean.parseBoolean(value);

KillSwitchConfiguration killSwitchConfiguration = getAdditionalFunctionalityAPI().getConfiguration().getKillSwitch();
if (killSwitchConfiguration == null)
killSwitchConfiguration = new KillSwitchConfiguration();

if ("disableMetricCollection".equals(name))
killSwitchConfiguration.setDisableMetricCollection(val);

getAdditionalFunctionalityAPI().setKillSwitchConfiguration(killSwitchConfiguration);

return mapping.success();
}

}
@@ -0,0 +1,49 @@
<%@ page language="java" contentType="text/html;charset=UTF-8" session="true" %>
<%@ taglib prefix="ano" uri="http://www.anotheria.net/ano-tags" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<jsp:include page="../../shared/jsp/Header.jsp" flush="false"/>
<section id="main">
<div class="content">
<ano:notPresent name="killSwitchConfiguration">
<div class="box">
<div class="box-content paddner">
No connection to remote component.
</div>
</div>
</ano:notPresent>

<ano:present name="killSwitchConfiguration">
<div class="box">
<div class="box-content paddner">
<dl class="dl-horizontal">
<dt>Disable metric collection</dt>
<dd><input type="checkbox" class="js-switch-color" data-switcher="disableMetricCollection" <ano:equal name="killSwitchConfiguration" property="disableMetricCollection" value="true">checked</ano:equal> /></dd>
</dl>
</div>
</div>
</ano:present>
</div>

<jsp:include page="../../shared/jsp/Footer.jsp" flush="false"/>

<script>
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch-color'));
elems.forEach(function(html) {
var switchery = new Switchery(html, { color: '#64bd63', secondaryColor: '#ff6a00'});
html.onchange = function() {
$.ajax({url: "mskSwitchKillSetting?name=" + this.getAttribute('data-switcher') + "&value=" + this.checked,
dataType: "json",
success: function (data) {
console.log("Switched " + this.getAttribute('data-switcher') + ": " + this.checked);
}
});
};
});
</script>

</section>
</body>
</html>
@@ -3,6 +3,7 @@
import net.anotheria.anoplass.api.API;
import net.anotheria.anoplass.api.APIException;
import net.anotheria.anoprise.metafactory.Service;
import net.anotheria.moskito.core.config.KillSwitchConfiguration;
import net.anotheria.moskito.core.config.MoskitoConfiguration;
import org.distributeme.annotation.DistributeMe;
import org.distributeme.annotation.FailBy;
@@ -79,4 +80,11 @@
*/
List<CaughtErrorAO> getCaughtErrorsByExceptionName(String catcherName, String catcherType) throws APIException;


/**
* Update Kill Switch configuration.
* @param killSwitchConfiguration configuration to set
* @throws APIException
*/
void setKillSwitchConfiguration(KillSwitchConfiguration killSwitchConfiguration) throws APIException;
}
@@ -5,6 +5,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import net.anotheria.anoplass.api.APIException;
import net.anotheria.moskito.core.config.KillSwitchConfiguration;
import net.anotheria.moskito.core.config.MoskitoConfiguration;
import net.anotheria.moskito.core.config.MoskitoConfigurationHolder;
import net.anotheria.moskito.core.config.plugins.PluginConfig;
@@ -245,6 +246,15 @@ public MoskitoConfiguration getConfiguration(){
}
}

@Override
public void setKillSwitchConfiguration(KillSwitchConfiguration killSwitchConfiguration) throws APIException {
if (killSwitchConfiguration == null)
return;

MoskitoConfiguration config = MoskitoConfigurationHolder.getConfiguration();
config.setKillSwitch(killSwitchConfiguration);
}

private CaughtErrorAO makeCaughtErrorAO(CaughtError error){
CaughtErrorAO ao = new CaughtErrorAO();
ao.setMessage(error.getThrowable().getMessage());
@@ -86,7 +86,11 @@
/**
* Navi item for gauges.
*/
MORE_GAUGES("Gauges");
MORE_GAUGES("Gauges"),
/**
* Navi item for kill switch.
*/
MORE_KILLSWITCH("Kill Switch");

/**
* Caption of the navi item.
@@ -258,6 +258,7 @@
<li ${currentSubNaviItem.isSelected("more_libs") ? "class=\"active\"" : ""}><mos:deepLink href="mskLibs" title="Libs" class="sidebar-tooltip-right">Libs <i class="fa fa-file-text"></i></mos:deepLink></li>
<li ${currentSubNaviItem.isSelected("more_update") ? "class=\"active\"" : ""}><mos:deepLink href="mskUpdate" title="Update" class="sidebar-tooltip-right">Update <i class="fa fa-upload"></i></mos:deepLink></li>
<li ${currentSubNaviItem.isSelected("more_gauges") ? "class=\"active\"" : ""}><mos:deepLink href="mskGauges" title="Gauges" class="sidebar-tooltip-right">Gauges <i class="fa fa-tachometer"></i></mos:deepLink></li>
<li ${currentSubNaviItem.isSelected("more_killswitch") ? "class=\"active\"" : ""}><mos:deepLink href="mskKillSwitch" title="Kill Switch" class="sidebar-tooltip-right">Kill Switch <i class="fa fa-cog"></i></mos:deepLink></li>
<%--<li ${currentSubNaviItem.isSelected("more_plugins") ? "class=\"active\"" : ""}><a href="mskPlugins" title="Plugins" class="sidebar-tooltip-right">Plugins <i class="fa fa-cloud"></i></a></li>--%>
</ul>
</li>
@@ -5,6 +5,8 @@
*
*/

/* Switchery defaults. */

.switchery {
background-color: #fff;
border: 1px solid #dfdfdf;
@@ -15,6 +17,14 @@
position: relative;
vertical-align: middle;
width: 50px;

-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
box-sizing: content-box;
background-clip: content-box;
}

.switchery > small {
@@ -25,4 +35,30 @@
position: absolute;
top: 0;
width: 30px;
}
}

/* Switchery sizes. */

.switchery-small {
border-radius: 20px;
height: 20px;
width: 33px;
}

.switchery-small > small {
height: 20px;
width: 20px;
}

.switchery-large {
border-radius: 40px;
height: 40px;
width: 66px;
}

.switchery-large > small {
height: 40px;
width: 40px;
}


Oops, something went wrong.

0 comments on commit 016184a

Please sign in to comment.
You can’t perform that action at this time.