From 2cecee1a0c6475ed0652045f39b071d6054584c2 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 2 Oct 2019 12:58:48 +0800 Subject: [PATCH] IDEMPIERE-4056 Implement cluster support for idempiere Monitor and Server Manager --- org.adempiere.server/META-INF/MANIFEST.MF | 2 + .../compiere/server/AdempiereServerMgr.java | 236 ++++++---- .../org/compiere/server/AlertProcessor.java | 19 +- .../org/compiere/server/IServerManager.java | 121 +++++ .../org/compiere/server/ServerCount.java | 73 +++ .../org/compiere/server/ServerInstance.java | 146 ++++++ .../server/cluster/ClusterServerMgr.java | 421 ++++++++++++++++++ .../cluster/callable/GetAllCallable.java | 66 +++ .../cluster/callable/GetServerCallable.java | 63 +++ .../callable/GetServerCountCallable.java | 69 +++ .../callable/GetStartTimeCallable.java | 62 +++ .../cluster/callable/ReloadCallable.java | 62 +++ .../server/cluster/callable/Response.java | 51 +++ .../cluster/callable/RunNowCallable.java | 68 +++ .../cluster/callable/StartAllCallable.java | 61 +++ .../cluster/callable/StartCallable.java | 69 +++ .../cluster/callable/StopAllCallable.java | 61 +++ .../server/cluster/callable/StopCallable.java | 68 +++ .../org/compiere/web/AdempiereMonitor.java | 191 +++++--- 19 files changed, 1729 insertions(+), 180 deletions(-) create mode 100644 org.adempiere.server/src/main/server/org/compiere/server/IServerManager.java create mode 100644 org.adempiere.server/src/main/server/org/compiere/server/ServerCount.java create mode 100644 org.adempiere.server/src/main/server/org/compiere/server/ServerInstance.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/ClusterServerMgr.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetAllCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCountCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetStartTimeCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/ReloadCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/Response.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/RunNowCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartAllCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopAllCallable.java create mode 100644 org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopCallable.java diff --git a/org.adempiere.server/META-INF/MANIFEST.MF b/org.adempiere.server/META-INF/MANIFEST.MF index ae950c0e95..85e29c3d63 100644 --- a/org.adempiere.server/META-INF/MANIFEST.MF +++ b/org.adempiere.server/META-INF/MANIFEST.MF @@ -38,6 +38,8 @@ Import-Package: javax.jms;version="1.1.0", Export-Package: org.adempiere.server, org.compiere.ldap, org.compiere.server, + org.idempiere.server.cluster, + org.idempiere.server.cluster.callable, org.idempiere.server.factory Bundle-ActivationPolicy: lazy Service-Component: OSGI-INF/*.xml diff --git a/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java b/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java index 790f1bba56..0860b104ea 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/AdempiereServerMgr.java @@ -35,6 +35,7 @@ import org.compiere.model.MScheduler; import org.compiere.model.MSession; import org.compiere.util.CLogger; import org.compiere.util.Env; +import org.idempiere.server.cluster.ClusterServerMgr; import org.osgi.framework.BundleEvent; import org.osgi.framework.BundleListener; import org.osgi.framework.ServiceReference; @@ -47,19 +48,15 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; * @author Jorg Janke * @version $Id: AdempiereServerMgr.java,v 1.4 2006/10/09 00:23:26 jjanke Exp $ */ -public class AdempiereServerMgr implements ServiceTrackerCustomizer, IServerFactory>, BundleListener +public class AdempiereServerMgr implements ServiceTrackerCustomizer, IServerFactory>, BundleListener, IServerManager { private static ServiceTracker, IServerFactory> serviceTracker; - public static int SERVER_STATE_NOT_SCHEDULE = 0; - public static int SERVER_STATE_STARTED = 1; - public static int SERVER_STATE_STOPPED = 2; - /** * Get Adempiere Server Manager * @return mgr */ - public synchronized static AdempiereServerMgr get() + public synchronized static IServerManager get() { return get(true); } @@ -68,7 +65,7 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer(); + m_servers=new ArrayList(); processorClass = new HashSet(); } // AdempiereServerMgr /** The Servers */ - private ArrayList m_servers = new ArrayList(); + private ArrayList m_servers = new ArrayList(); /** Context */ private Properties m_ctx = Env.getCtx(); /** Start */ @@ -129,14 +126,15 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer(); + m_servers=new ArrayList(); processorClass = new HashSet(); //osgi server @@ -150,7 +148,7 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer factory) { @@ -164,13 +162,18 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer list = new ArrayList(); + ArrayList list = new ArrayList(); for (int i = 0; i < m_servers.size(); i++) { - ServerWrapper server = (ServerWrapper)m_servers.get(i); + LocalServerController server = (LocalServerController)m_servers.get(i); if (server != null && server.scheduleFuture != null && !server.scheduleFuture.isDone()) list.add (server); } - ServerWrapper[] retValue = new ServerWrapper[list.size ()]; + LocalServerController[] retValue = new LocalServerController[list.size ()]; list.toArray (retValue); return retValue; } // getActive @@ -439,16 +446,16 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer list = new ArrayList(); + ArrayList list = new ArrayList(); for (int i = 0; i < m_servers.size(); i++) { - ServerWrapper server = m_servers.get(i); + LocalServerController server = m_servers.get(i); if (server != null && (server.scheduleFuture == null || server.scheduleFuture.isDone())) list.add (server); } - ServerWrapper[] retValue = new ServerWrapper[list.size()]; + LocalServerController[] retValue = new LocalServerController[list.size()]; list.toArray (retValue); return retValue; } // getInActive @@ -457,33 +464,32 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer responses = new ArrayList<>(); + LocalServerController[] controllers = getLocalServerControllers(); + for (LocalServerController controller : controllers) { + if (controller.getServer() != null) { + ServerInstance response = new ServerInstance(controller.getServer().getServerID(), controller.getServer().getModel(), + controller.isAlive(), controller.isInterrupted(), controller.getServer().isSleeping(), + controller.getServer().getStartTime(), controller.getServer().getStatistics(), controller.getServer().getServerInfo()); + responses.add(response); } } - return status; + return responses.toArray(new ServerInstance[0]); + } + + public synchronized int getStatus(AdempiereProcessor processor) + { + return getServerStatus(processor.getServerID()); } /** @@ -491,13 +497,34 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + Response response = f.get(); + if (response.getServerId() != null) { + return response.getError(); + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return "Server " + serverId + " not found"; + } + return null; + + } + + @Override + public String start(String serverId) { + IClusterService service = getClusterService(); + if (service == null) + return "Cluster service not available"; + + StartCallable callable = new StartCallable(serverId); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + Response response = f.get(); + if (response != null && response.getServerId() != null) { + return response.getError(); + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return "Server " + serverId + " not found"; + } else { + return "Failed to send start request through cluster service"; + } + } + + @Override + public String stop(String serverId) { + IClusterService service = getClusterService(); + if (service == null) + return "Cluster service not available"; + + StopCallable callable = new StopCallable(serverId); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + Response response = f.get(); + if (response != null && response.getServerId() != null) { + return response.getError(); + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return "Server " + serverId + " not found"; + } else { + return "Failed to send stop request through cluster service"; + } + } + + @Override + public String reload() { + IClusterService service = getClusterService(); + if (service == null) + return "Cluster service not available"; + + ReloadCallable callable = new ReloadCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + String response = f.get(); + if (response != null) { + return response; + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return null; + } else { + return "Failed to send reload request through cluster service"; + } + } + + @Override + public Timestamp getStartTime() { + IClusterService service = getClusterService(); + if (service == null) + return null; + + Timestamp earliest = null; + GetStartTimeCallable callable = new GetStartTimeCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + Timestamp response = f.get(); + if (response != null) { + if (earliest == null) + earliest = response; + else if (response.before(earliest)) + earliest = response; + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + return earliest; + } + + @Override + public ServerCount getServerCount() { + IClusterService service = getClusterService(); + if (service == null) + return null; + + ServerCount serverCount = null; + GetServerCountCallable callable = new GetServerCountCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + ServerCount response = f.get(); + if (response != null) { + if (serverCount == null) { + serverCount = response; + } else { + serverCount.addStarted(response.getStarted()); + serverCount.addStopped(response.getStopped()); + } + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + return serverCount; + } + + @Override + public ServerInstance[] getServerInstances() { + IClusterService service = getClusterService(); + if (service == null) + return null; + + List servers = new ArrayList<>(); + GetAllCallable callable = new GetAllCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Set>> results = futureMap.entrySet(); + for(Entry> f : results) { + ServerInstance[] response = f.getValue().get(); + if (response != null) { + Arrays.stream(response).forEach(e -> { + e.setClusterMember(f.getKey()); + servers.add(e); + }); + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + return servers.toArray(new ServerInstance[0]); + } + + @Override + public String getDescription() { + return Adempiere.getVersion(); + } + + @Override + public String startAll() { + IClusterService service = getClusterService(); + if (service == null) + return "Cluster service not available"; + + StartAllCallable callable = new StartAllCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + String response = f.get(); + if (response != null) { + return response; + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return null; + } else { + return "Failed to send start all request through cluster servie"; + } + } + + @Override + public String stopAll() { + IClusterService service = getClusterService(); + if (service == null) + return "Cluster service not available"; + + StopAllCallable callable = new StopAllCallable(); + Map> futureMap = service.execute(callable, service.getMembers()); + if (futureMap != null) { + try { + Collection> results = futureMap.values(); + for(Future f : results) { + String response = f.get(); + if (response != null) { + return response; + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + return null; + } else { + return "Failed to send stop all request through cluster servie"; + } + } + + /** + * find server instance from non-local nodes + * @param serverId + * @return ServerInstance + */ + public ServerInstance getServerInstanceAtOtherMembers(String serverId) { + IClusterService service = getClusterService(); + if (service == null) + return null; + + GetServerCallable callable = new GetServerCallable(serverId); + Collection members = service.getMembers(); + if (members == null || members.isEmpty()) + return null; + final IClusterMember local = service.getLocalMember(); + if (local == null) + return null; + List others = new ArrayList<>(); + members.forEach(e -> { + if (!e.getId().equals(local.getId())) { + others.add(e); + } + }); + if (others.size() > 0) { + Map> futureMap = service.execute(callable, others); + if (futureMap != null) { + try { + Set>> results = futureMap.entrySet(); + for(Entry> f : results) { + ServerInstance i = f.getValue().get(); + if (i != null) { + i.setClusterMember(f.getKey()); + return i; + } + } + } catch (InterruptedException e) { + throw new RuntimeException(e.getMessage(), e); + } catch (ExecutionException e) { + throw new RuntimeException(e.getMessage(), e); + } + } + } + return null; + } +} \ No newline at end of file diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetAllCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetAllCallable.java new file mode 100644 index 0000000000..ac58120016 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetAllCallable.java @@ -0,0 +1,66 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class GetAllCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = -2658045266402067579L; + + /** + * default constructor + */ + public GetAllCallable() { + } + + @Override + public ServerInstance[] call() throws Exception { + List responses = new ArrayList<>(); + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + ServerInstance[] servers = serverMgr.getServerInstances(); + for (ServerInstance server : servers) { + responses.add(server); + } + } + return responses.toArray(new ServerInstance[0]); + } +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCallable.java new file mode 100644 index 0000000000..88603449f4 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCallable.java @@ -0,0 +1,63 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class GetServerCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = -2658045266402067579L; + + private String serverId; + + /** + * @param serverId + */ + public GetServerCallable(String serverId) { + this.serverId = serverId; + } + + @Override + public ServerInstance call() throws Exception { + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + return serverMgr.getServerInstance(serverId); + } + return null; + } +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCountCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCountCallable.java new file mode 100644 index 0000000000..ba6a14c5c5 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetServerCountCallable.java @@ -0,0 +1,69 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerCount; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class GetServerCountCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + + /** + * default constructor + */ + public GetServerCountCallable() { + } + + @Override + public ServerCount call() throws Exception { + ServerCount serverCount = new ServerCount(); + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + ServerInstance[] servers = serverMgr.getServerInstances(); + for (ServerInstance server : servers) { + if (server.isStarted()) + serverCount.addStarted(1); + else + serverCount.addStopped(1); + } + } + + return serverCount; + } +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetStartTimeCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetStartTimeCallable.java new file mode 100644 index 0000000000..0d20547709 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/GetStartTimeCallable.java @@ -0,0 +1,62 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.sql.Timestamp; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; + +/** + * @author hengsin + * + */ +public class GetStartTimeCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + + /** + * default constructor + */ + public GetStartTimeCallable() { + } + + @Override + public Timestamp call() throws Exception { + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + return serverMgr.getStartTime(); + } + + return null; + } + +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/ReloadCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/ReloadCallable.java new file mode 100644 index 0000000000..3f0deef35d --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/ReloadCallable.java @@ -0,0 +1,62 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; + +/** + * @author hengsin + * + */ +public class ReloadCallable implements Callable, Serializable { + + + /** + * generated serial + */ + private static final long serialVersionUID = -477156440432070776L; + + /** + * default constructor + */ + public ReloadCallable() { + } + + @Override + public String call() throws Exception { + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + return serverMgr.reload(); + } + + return null; + } + +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/Response.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/Response.java new file mode 100644 index 0000000000..f86f1f028b --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/Response.java @@ -0,0 +1,51 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; + +/** + * + * @author hengsin + * + */ +public class Response implements Serializable { + /** + * generated serial id + */ + private static final long serialVersionUID = -62222370378270354L; + + protected String error = null; + protected String serverId = null; + + public String getError() { + return error; + } + + public String getServerId() { + return serverId; + } +} \ No newline at end of file diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/RunNowCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/RunNowCallable.java new file mode 100644 index 0000000000..f681386f92 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/RunNowCallable.java @@ -0,0 +1,68 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class RunNowCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3629305666372614289L; + + private String serverId; + + /** + * @param serverId + */ + public RunNowCallable(String serverId) { + this.serverId = serverId; + } + + @Override + public Response call() throws Exception { + Response response = new Response(); + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + ServerInstance serverInstance = serverMgr.getServerInstance(serverId); + if (serverInstance != null) { + response.serverId = serverInstance.getServerId(); + response.error = serverMgr.runNow(serverId); + } + } + return response; + } +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartAllCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartAllCallable.java new file mode 100644 index 0000000000..ef9f2703b4 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartAllCallable.java @@ -0,0 +1,61 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; + +/** + * @author hengsin + * + */ +public class StartAllCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + + /** + * default constructor + */ + public StartAllCallable() { + } + + @Override + public String call() throws Exception { + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + return serverMgr.startAll(); + } + + return null; + } + +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartCallable.java new file mode 100644 index 0000000000..b2febe26c1 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StartCallable.java @@ -0,0 +1,69 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class StartCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + + private String serverId; + + /** + * @param serverId + */ + public StartCallable(String serverId) { + this.serverId = serverId; + } + + @Override + public Response call() throws Exception { + Response response = new Response(); + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + ServerInstance server = serverMgr.getServerInstance(serverId); + if (server != null) { + response.error = serverMgr.start(serverId); + response.serverId = server.getServerId(); + } + } + + return response; + } +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopAllCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopAllCallable.java new file mode 100644 index 0000000000..3def25b0dc --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopAllCallable.java @@ -0,0 +1,61 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; + +/** + * @author hengsin + * + */ +public class StopAllCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + + /** + * default constructor + */ + public StopAllCallable() { + } + + @Override + public String call() throws Exception { + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + return serverMgr.stopAll(); + } + + return null; + } + +} diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopCallable.java b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopCallable.java new file mode 100644 index 0000000000..ab7869d181 --- /dev/null +++ b/org.adempiere.server/src/main/server/org/idempiere/server/cluster/callable/StopCallable.java @@ -0,0 +1,68 @@ +/********************************************************************** +* This file is part of iDempiere ERP Open Source * +* http://www.idempiere.org * +* * +* Copyright (C) Contributors * +* * +* This program is free software; you can redistribute it and/or * +* modify it under the terms of the GNU General Public License * +* as published by the Free Software Foundation; either version 2 * +* of the License, or (at your option) any later version. * +* * +* This program is distributed 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 General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program; if not, write to the Free Software * +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * +* MA 02110-1301, USA. * +* * +* Contributors: * +* - Trek Global Corporation * +* - Heng Sin Low * +**********************************************************************/ +package org.idempiere.server.cluster.callable; + +import java.io.Serializable; +import java.util.concurrent.Callable; + +import org.compiere.server.AdempiereServerMgr; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerInstance; + +/** + * @author hengsin + * + */ +public class StopCallable implements Callable, Serializable { + + /** + * generated serial + */ + private static final long serialVersionUID = 3496041492358893501L; + private String serverId; + + /** + * @param serverId + */ + public StopCallable(String serverId) { + this.serverId = serverId; + } + + @Override + public Response call() throws Exception { + Response response = new Response(); + IServerManager serverMgr = AdempiereServerMgr.get(false); + if (serverMgr != null) { + ServerInstance server = serverMgr.getServerInstance(serverId); + if (server != null) { + response.error = serverMgr.stop(serverId); + response.serverId = server.getServerId(); + } + } + + return response; + } +} diff --git a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java index 9ca3a77637..5bb28f85c4 100644 --- a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java +++ b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java @@ -26,6 +26,7 @@ import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.RuntimeMXBean; import java.lang.management.ThreadMXBean; +import java.net.InetAddress; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -39,6 +40,8 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.adempiere.base.IServiceHolder; +import org.adempiere.base.Service; import org.adempiere.util.LogAuthFailure; import org.apache.ecs.HtmlColor; import org.apache.ecs.xhtml.a; @@ -69,10 +72,11 @@ import org.compiere.model.MStore; import org.compiere.model.MSysConfig; import org.compiere.model.MSystem; import org.compiere.model.Query; -import org.compiere.server.AdempiereServer; import org.compiere.server.AdempiereServerGroup; import org.compiere.server.AdempiereServerMgr; -import org.compiere.server.AdempiereServerMgr.ServerWrapper; +import org.compiere.server.IServerManager; +import org.compiere.server.ServerCount; +import org.compiere.server.ServerInstance; import org.compiere.util.CLogFile; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; @@ -83,9 +87,12 @@ import org.compiere.util.Env; import org.compiere.util.Ini; import org.compiere.util.TimeUtil; import org.compiere.util.Trx; +import org.compiere.util.Util; import org.compiere.util.WebDoc; import org.compiere.util.WebEnv; import org.compiere.util.WebUtil; +import org.idempiere.distributed.IClusterService; +import org.idempiere.server.cluster.ClusterServerMgr; /** * Adempiere Server Monitor @@ -103,7 +110,7 @@ public class AdempiereMonitor extends HttpServlet /** Logger */ private static CLogger log = CLogger.getCLogger(AdempiereMonitor.class); /** The Server */ - private static AdempiereServerMgr m_serverMgr = null; + private static IServerManager m_serverMgr = null; /** Message */ private static p m_message = null; @@ -189,8 +196,8 @@ public class AdempiereMonitor extends HttpServlet return false; if (log.isLoggable(Level.INFO)) log.info ("ServerID=" + serverID); - ServerWrapper server = m_serverMgr.getServer(serverID); - if (server == null || server.getServer() == null) + ServerInstance server = m_serverMgr.getServerInstance(serverID); + if (server == null) { m_message = new p(); m_message.addElement(new strong("Server not found: ")); @@ -207,7 +214,7 @@ public class AdempiereMonitor extends HttpServlet para.addElement(link); b.addElement(para); // - b.addElement(new h2(server.getServer().getName())); + b.addElement(new h2(server.getModel().getName())); // table table = new table(); table.setBorder(1); @@ -224,7 +231,7 @@ public class AdempiereMonitor extends HttpServlet // line.addElement(new th().addElement("Description")); table.addElement(line); - AdempiereProcessorLog[] logs = server.getServer().getLogs(); + AdempiereProcessorLog[] logs = server.getModel().getLogs(); for (int i = 0; i < logs.length; i++) { AdempiereProcessorLog pLog = logs[i]; @@ -260,8 +267,8 @@ public class AdempiereMonitor extends HttpServlet return false; if (log.isLoggable(Level.INFO)) log.info ("ServerID=" + serverID); - ServerWrapper server = m_serverMgr.getServer(serverID); - if (server == null || server.getServer() == null) + ServerInstance server = m_serverMgr.getServerInstance(serverID); + if (server == null) { m_message = new p(); m_message.addElement(new strong("Server not found: ")); @@ -269,32 +276,14 @@ public class AdempiereMonitor extends HttpServlet return false; } // - AdempiereServer serverInstance = server.getServer(); - if (serverInstance.isSleeping()) + String error = m_serverMgr.runNow(serverID); + if (!Util.isEmpty(error, true)) { - serverInstance.runNow(); - } - else - { - int count = 0; - while(!serverInstance.isSleeping() && count < 5) - { - count++; - try { - Thread.sleep(60000); - } catch (InterruptedException e) { - Thread.interrupted(); - } - } - if (serverInstance.isSleeping()) - serverInstance.runNow(); - else - { - m_message = new p(); - m_message.addElement(new strong("Timeout waiting for server process to be available for execution.")); - m_message.addElement(serverID); - } + m_message = new p(); + m_message.addElement(new strong(error)); + m_message.addElement(serverID); } + // return true; } // processRunParameter @@ -323,9 +312,9 @@ public class AdempiereMonitor extends HttpServlet { if (start) { - ok = m_serverMgr.startAll(); + ok = m_serverMgr.startAll()==null; } else{ - ok = m_serverMgr.stopAll(); + ok = m_serverMgr.stopAll()==null; } m_message.addElement("All"); @@ -334,22 +323,22 @@ public class AdempiereMonitor extends HttpServlet { if (reload) { - ok=m_serverMgr.reload(); + ok=m_serverMgr.reload()==null; this.createSummaryPage(request, response,true); m_dirAccessList = getDirAcessList(); } else { - ServerWrapper server = m_serverMgr.getServer(serverID); - if (server == null || server.getServer() == null) { + ServerInstance server = m_serverMgr.getServerInstance(serverID); + if (server == null) { m_message = new p(); m_message.addElement(new strong("Server not found: ")); m_message.addElement(serverID); return; } else { if (start) - ok = m_serverMgr.start(serverID); + ok = m_serverMgr.start(serverID)==null; else - ok = m_serverMgr.stop(serverID); - m_message.addElement(server.getServer().getName()); + ok = m_serverMgr.stop(serverID)==null; + m_message.addElement(server.getModel().getName()); } } } @@ -631,13 +620,24 @@ public class AdempiereMonitor extends HttpServlet table.addElement(line); line = new tr(); line.addElement(new th().addElement("Servers")); - line.addElement(new td().addElement(WebEnv.getCellContent(m_serverMgr.getServerCount()))); + line.addElement(new td().addElement(WebEnv.getCellContent(createServerCountMessage(m_serverMgr.getServerCount())))); table.addElement(line); line = new tr(); line.addElement(new th().addElement("Last Updated")); line.addElement(new td().addElement(new Timestamp(System.currentTimeMillis()).toString())); table.addElement(line); bb.addElement(table); + + IServiceHolder holder = Service.locator().locate(IClusterService.class); + IClusterService service = holder != null ? holder.getService() : null; + if (service != null && service.getLocalMember() != null) + { + line = new tr(); + line.addElement(new th().addElement("Cluster Node Id")); + line.addElement(new td().addElement(WebEnv.getCellContent(service.getLocalMember().getId()))); + table.addElement(line); + bb.addElement(table); + } // p para = new p(); a link = new a ("idempiereMonitor?Action=Start_All", "Start All"); @@ -656,16 +656,16 @@ public class AdempiereMonitor extends HttpServlet // ***** Server Links ***** bb.addElement(new hr()); para = new p(); - ServerWrapper[] servers = m_serverMgr.getAll(); + ServerInstance[] servers = m_serverMgr.getServerInstances(); for (int i = 0; i < servers.length; i++) { if (i > 0) para.addElement(new br()); - ServerWrapper server = servers[i]; - link = new a ("#" + server.getServer().getServerID(), server.getServer().getName()); + ServerInstance server = servers[i]; + link = new a ("#" + server.getServerId(), server.getModel().getName()); para.addElement(link); font status = null; - if (server.isAlive()) + if (server.isStarted()) status = new font().setColor(HtmlColor.GREEN).addElement(" (Running)"); else status = new font().setColor(HtmlColor.RED).addElement(" (Stopped)"); @@ -680,10 +680,10 @@ public class AdempiereMonitor extends HttpServlet bb.removeEndEndModifier(); for (int i = 0; i < servers.length; i++) { - ServerWrapper server = servers[i]; + ServerInstance server = servers[i]; bb.addElement(new hr()); - bb.addElement(new a().setName(server.getServer().getServerID())); - bb.addElement(new h2(server.getServer().getName())); + bb.addElement(new a().setName(server.getServerId())); + bb.addElement(new h2(server.getModel().getName())); // table = new table(); table.setBorder(1); @@ -691,11 +691,11 @@ public class AdempiereMonitor extends HttpServlet table.setCellPadding(2); // Status line = new tr(); - if (server.isAlive()) + if (server.isStarted()) { String msg = "Stop"; - link = new a ("idempiereMonitor?Action=Stop_" + server.getServer().getServerID(), msg); - if (server.getServer().isSleeping()) + link = new a ("idempiereMonitor?Action=Stop_" + server.getServerId(), msg); + if (server.isSleeping()) { line.addElement(new th().addElement("Sleeping")); line.addElement(new td().addElement(link)); @@ -708,54 +708,74 @@ public class AdempiereMonitor extends HttpServlet table.addElement(line); line = new tr(); line.addElement(new th().addElement("Start - Elapsed")); - line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getStartTime()) - + " - " + TimeUtil.formatElapsed(server.getServer().getStartTime()))); + line.addElement(new td().addElement(WebEnv.getCellContent(server.getStartTime()) + + " - " + TimeUtil.formatElapsed(server.getStartTime()))); } else { String msg = "Start"; line.addElement(new th().addElement("Not Started")); - link = new a ("idempiereMonitor?Action=Start_" + server.getServer().getServerID(), msg); + link = new a ("idempiereMonitor?Action=Start_" + server.getServerId(), msg); line.addElement(new td().addElement(link)); } table.addElement(line); // line = new tr(); line.addElement(new th().addElement("Description")); - line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getDescription()))); + line.addElement(new td().addElement(WebEnv.getCellContent(server.getModel().getDescription()))); table.addElement(line); // line = new tr(); line.addElement(new th().addElement("Last Run")); - line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getDateLastRun()))); + line.addElement(new td().addElement(WebEnv.getCellContent(server.getModel().getDateLastRun()))); table.addElement(line); line = new tr(); line.addElement(new th().addElement("Info")); - line.addElement(new td().addElement(WebEnv.getCellContent(server.getServer().getServerInfo()))); + line.addElement(new td().addElement(WebEnv.getCellContent(server.getServerInfo()))); table.addElement(line); // line = new tr(); line.addElement(new th().addElement("Next Run")); td td = new td(); - td.addElement(WebEnv.getCellContent(server.getServer().getDateNextRun(false))); + td.addElement(WebEnv.getCellContent(server.getModel().getDateNextRun(false))); td.addElement(" - "); - link = new a ("idempiereMonitor?RunNow=" + server.getServer().getServerID(), "(Run Now)"); + link = new a ("idempiereMonitor?RunNow=" + server.getServerId(), "(Run Now)"); td.addElement(link); line.addElement(td); table.addElement(line); // line = new tr(); line.addElement(new th().addElement("Statistics")); - line.addElement(new td().addElement(server.getServer().getStatistics())); + line.addElement(new td().addElement(server.getStatistics())); table.addElement(line); // + if (server.getClusterMember() != null) + { + InetAddress address = server.getClusterMember().getAddress(); + String ip = address != null ? address.getHostAddress() : null; + if (ip != null && + (ip.startsWith("10.") || + ip.startsWith("172.16") || + ip.startsWith("192.168"))) + { + line = new tr(); + line.addElement(new th().addElement("Cluster Node IP")); + line.addElement(new td().addElement(ip)); + } + table.addElement(line); + line = new tr(); + line.addElement(new th().addElement("Cluster Node Id")); + line.addElement(new td().addElement(server.getClusterMember().getId())); + table.addElement(line); + + } // Add table to Body bb.addElement(table); link = new a ("#top", "Top"); bb.addElement(link); bb.addElement(" - "); - link = new a ("idempiereMonitor?Log=" + server.getServer().getServerID(), "Log"); + link = new a ("idempiereMonitor?Log=" + server.getServerId(), "Log"); bb.addElement(link); bb.addElement(" - "); link = new a ("idempiereMonitor", "Refresh"); @@ -766,6 +786,20 @@ public class AdempiereMonitor extends HttpServlet WebUtil.createResponse (request, response, this, null, doc, false); } // createSummaryPage + private String createServerCountMessage(ServerCount serverCount) { + StringBuilder builder = new StringBuilder(); + + if (serverCount != null) { + builder.append(serverCount.getStarted()+serverCount.getStopped()) + .append(" - Running=") + .append(serverCount.getStarted()) + .append(" - Stopped=") + .append(serverCount.getStopped()); + } + + return builder.toString(); + } + /************************************************************************** * Create & Return Summary Page * @param request request @@ -817,29 +851,29 @@ public class AdempiereMonitor extends HttpServlet writer.print(m_serverMgr.getServerCount()); writer.println(""); - ServerWrapper[] servers = m_serverMgr.getAll(); + ServerInstance[] servers = m_serverMgr.getServerInstances(); for (int i = 0; i < servers.length; i++) { - ServerWrapper server = servers[i]; + ServerInstance server = servers[i]; writer.println("\t\t"); writer.print("\t\t\t"); - writer.print(server.getServer().getServerID()); + writer.print(server.getServerId()); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getName()); + writer.print(server.getModel().getName()); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getDescription()); + writer.print(server.getModel().getDescription()); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getServerInfo()); + writer.print(server.getServerInfo()); writer.println(""); writer.print("\t\t\t"); - if (server.isAlive()) + if (server.isStarted()) { if (server.isInterrupted()) writer.print("Interrupted"); - else if (server.getServer().isSleeping()) + else if (server.isSleeping()) writer.print("Sleeping"); else writer.print("Running"); @@ -848,16 +882,16 @@ public class AdempiereMonitor extends HttpServlet writer.print("Stopped"); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getStartTime()); + writer.print(server.getStartTime()); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getDateLastRun()); + writer.print(server.getModel().getDateLastRun()); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getDateNextRun(false)); + writer.print(server.getModel().getDateNextRun(false)); writer.println(""); writer.print("\t\t\t"); - writer.print(server.getServer().getStatistics()); + writer.print(server.getStatistics()); writer.println(""); writer.println("\t\t"); } @@ -1148,7 +1182,16 @@ public class AdempiereMonitor extends HttpServlet { WebEnv.initWeb(config); log.info (""); + + //always create the local server manager instance m_serverMgr = AdempiereServerMgr.get(); + + //switch to cluster manager if cluster service is available + IServiceHolder holder = Service.locator().locate(IClusterService.class); + IClusterService service = holder != null ? holder.getService() : null; + if (service != null) + m_serverMgr = ClusterServerMgr.getInstance(); + m_dirAccessList = getDirAcessList(); } // init