Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
BZ 1030082 1029384 - shutdown the server if it was decommissioned (th…
Browse files Browse the repository at this point in the history
…at is, its server entry was removed from the server table)
  • Loading branch information
jmazzitelli committed Apr 16, 2014
1 parent 4f2297a commit 02513a8
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.jboss.as.controller.client.ModelControllerClient;

import org.rhq.common.jbossas.client.controller.CoreJBossASClient;
import org.rhq.common.jbossas.client.controller.MCCHelper;
import org.rhq.core.domain.cloud.PartitionEventType;
import org.rhq.core.domain.cloud.Server;
import org.rhq.core.domain.cloud.Server.OperationMode;
Expand All @@ -57,14 +61,14 @@
/**
* If you want to manipulate or report on the {@link Server} instance that
* some piece of code is currently executing on, use the {@link ServerManagerBean}.
*
*
* This session bean determines the identity of the server it's running on by
* reading the <code>rhq.server.high-availability.name</code> property from the
* rhq-server.properties file.
*
*
* The functionality provided here is useful when you need to execute something
* on every server in the cloud, such as partitioned services and data.
*
*
* @author Joseph Marques
*/
@Stateless
Expand Down Expand Up @@ -100,7 +104,7 @@ public class ServerManagerBean implements ServerManagerLocal {
private ServerManagerLocal serverManager;

public void scheduleServerHeartbeat() {
/* each time the webapp is reloaded, it would create
/* each time the webapp is reloaded, it would create
* duplicate events if we don't cancel the existing ones
*/
Collection<Timer> timers = timerService.getTimers();
Expand Down Expand Up @@ -307,10 +311,24 @@ public void syncEndpointAddress() throws SyncEndpointAddressException {

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void beat() {
Server server = getServer();
server.setMtime(System.currentTimeMillis());
try {
Server server = getServer();
server.setMtime(System.currentTimeMillis());
} catch (ServerNotFoundException snfe) {
// an admin removed our server entity, that means we are to be decommissioned so immediately shutdown
ModelControllerClient mcc = null;
try {
log.info("This server has been decommissioned!!! It will now shutdown.");
mcc = MCCHelper.createModelControllerClient();
new CoreJBossASClient(mcc).shutdown(false);
} catch (Exception e) {
log.fatal("This server was decommissioned, however, it failed to shut itself down. This server will now behave in an indeterminate manner. Please shut it down.");
} finally {
MCCHelper.safeClose(mcc);
}
}

// Handles server mode state changes
// Handles server mode state changes
// note: this call should be fast. if not we need to break the heart beat into its own job
establishCurrentServerMode();
}
Expand Down

0 comments on commit 02513a8

Please sign in to comment.