Skip to content

Commit

Permalink
Merge pull request #7618 from dotCMS/issue-7596-autoscaling
Browse files Browse the repository at this point in the history
#7596: Using ENABLE_SERVER_HEARTBEAT in write to Disk and Network Tab
  • Loading branch information
Jason Tesser committed May 6, 2015
2 parents e55886e + 4e0006e commit 15e81bc
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 34 deletions.
12 changes: 9 additions & 3 deletions dotCMS/html/portlet/ext/cmsconfig/main.jsp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%@ page import="com.dotmarketing.util.Config" %>

<%@ include file="/html/portlet/ext/cmsconfig/init.jsp" %>

<%if(request.getAttribute(com.dotmarketing.util.WebKeys.CMS_CRUMBTRAIL_OPTIONS)==null){%>
Expand Down Expand Up @@ -29,9 +31,13 @@
<div id="licenseTabContentDiv"></div>
</div>

<div id="networkTab" dojoType="dijit.layout.ContentPane" title="<%=LanguageUtil.get(pageContext, "Network")%>" >
<div id="networkTabContentDiv"></div>
</div>
<% if(Config.getBooleanProperty("ENABLE_SERVER_HEARTBEAT", true)) { %>
<div id="networkTab" dojoType="dijit.layout.ContentPane" title="<%=LanguageUtil.get(pageContext, "Network")%>" >
<div id="networkTabContentDiv"></div>
</div>
<%
}
%>

<div id="remotePublishingTab" dojoType="dijit.layout.ContentPane" title="<%= LanguageUtil.get(pageContext, "publisher_Publishing_Environment") %>" >
<div id="remotePublishingTabContentDiv"></div>
Expand Down
8 changes: 8 additions & 0 deletions dotCMS/html/portlet/ext/cmsconfig/new_cluster_config.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
<%@page import="com.dotmarketing.util.Config"%>
<%@ page import="com.liferay.portal.language.LanguageUtil"%>
<%@ page import="com.dotcms.enterprise.LicenseUtil" %>
<%@ page import="com.dotmarketing.util.Config" %>

<% if(!Config.getBooleanProperty("ENABLE_SERVER_HEARTBEAT", true)) { //In case user tries to acess jsp directly%>
<%@ include file="/html/portlet/ext/cmsconfig/network/not_licensed.jsp" %>
<%
return;
}
%>

<% if( LicenseUtil.getLevel()<300){ %>
<%@ include file="/html/portlet/ext/cmsconfig/network/not_licensed.jsp" %>
Expand Down
21 changes: 21 additions & 0 deletions src-conf/dotcms-config-cluster.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
## Required for cluster environments
## Note the dotCMS cluster will set itself up by setting the DIST_INDEXATION_ENABLED=true.
CLUSTER_AUTOWIRE=true
#User can turn off the Heartbeat Monitor.
#When set to off Network Portlet will be disabled.
ENABLE_SERVER_HEARTBEAT=true
HEARTBEAT_CRON_EXPRESSION=0 0/1 * * * ?
# period of time without writing heartbeat for considering a Node timed out. Expressed in seconds
HEARTBEAT_TIMEOUT=300
#Max number of days a server will be accepted to be down before remode it
MAX_DAYS_HEARTBEAT_INACTIVE=1

#########################################
## REMOVE INACTIVE CLUSTER SERVER
#########################################
ENABLE_REMOVE_INACTIVE_CLUSTER_SERVER=true
REMOVE_INACTIVE_CLUSTER_SERVER_CRON_EXPRESSION=59 59 23 * * ?

## This variable specify the maximun amount of time a server without heartbeats will be allowed in
## the cluster. The variable is composed by a unique amountUnit value, the first value it's for the
## quantity followed by the initial of the time unit, for example 30M means 30 minutes, 2D means 2 days,
##1W means one week. These are the time units values allowed/valids : M (for Minutes),H (for Hours),
##D (for Days) or W (for Weeks)
REMOVE_INACTIVE_CLUSTER_SERVER_PERIOD=2W
#DIST_INDEXATION_ENABLED=true
CACHE_DISK_SHOULD_DELETE=false

Expand Down
20 changes: 0 additions & 20 deletions src-conf/dotmarketing-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -685,26 +685,6 @@ COOKIES_HTTP_ONLY=false
# values: never|always|https
COOKIES_SECURE_FLAG=never

ENABLE_SERVER_HEARTBEAT=true
HEARTBEAT_CRON_EXPRESSION=0 0/1 * * * ?
# period of time without writing heartbeat for considering a Node timed out. Expressed in seconds
HEARTBEAT_TIMEOUT=300
#Max number of days a server will be accepted to be down before remode it
MAX_DAYS_HEARTBEAT_INACTIVE=1

#########################################
## REMOVE INACTIVE CLUSTER SERVER
#########################################
ENABLE_REMOVE_INACTIVE_CLUSTER_SERVER=true
REMOVE_INACTIVE_CLUSTER_SERVER_CRON_EXPRESSION=59 59 23 * * ?

## This variable specify the maximun amount of time a server without heartbeats will be allowed in
## the cluster. The variable is composed by a unique amountUnit value, the first value it's for the
## quantity followed by the initial of the time unit, for example 30M means 30 minutes, 2D means 2 days,
##1W means one week. These are the time units values allowed/valids : M (for Minutes),H (for Hours),
##D (for Days) or W (for Weeks)
REMOVE_INACTIVE_CLUSTER_SERVER_PERIOD=2W

########################################
## CMS MAINTENANCE - Assets Search and Replace
########################################
Expand Down
32 changes: 21 additions & 11 deletions src/com/dotcms/cluster/business/ServerAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.dotmarketing.business.APILocator;
import com.dotmarketing.business.FactoryLocator;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.ConfigUtils;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
Expand Down Expand Up @@ -85,20 +86,29 @@ public void writeServerIdToDisk(String serverId) throws IOException {
}

public void writeHeartBeatToDisk(String serverId) throws IOException {
String realPath = APILocator.getFileAPI().getRealAssetPath()
+ java.io.File.separator + "server" + java.io.File.separator + serverId;
File serverDir = new File(realPath);

if(!serverDir.exists()) {
serverDir.mkdirs();
}
//First We need to check if the heartbeat job is enable.
if ( Config.getBooleanProperty("ENABLE_SERVER_HEARTBEAT", true) ) {
String realPath = APILocator.getFileAPI().getRealAssetPath()
+ java.io.File.separator
+ "server"
+ java.io.File.separator
+ serverId;

File serverDir = new File(realPath);
if(!serverDir.exists()) {
serverDir.mkdirs();
}

File heartBeat = new File(realPath + java.io.File.separator + "heartbeat.dat");
File heartBeat = new File(realPath + java.io.File.separator + "heartbeat.dat");

OutputStream os = new FileOutputStream(heartBeat);
os.write(UtilMethods.dateToHTMLDate(new Date(), "yyyy-MM-dd H:mm:ss").getBytes());
os.flush();
os.close();
OutputStream os = new FileOutputStream(heartBeat);
os.write(UtilMethods.dateToHTMLDate(new Date(), "yyyy-MM-dd H:mm:ss").getBytes());
os.flush();
os.close();
} else {
Logger.warn(ServerAPIImpl.class, "ENABLE_SERVER_HEARTBEAT is set to false to we do not need to write to Disk " );
}

}

Expand Down

0 comments on commit 15e81bc

Please sign in to comment.