use of alma.acsdaemon.ServicesDaemon in project ACS by ACS-Community.
the class Executor method remoteDaemonForServices.
/**
* Starts or stops ACS via the ACS services daemon.
* This call returns only when the action has completed.
* Exceptions will be returned instead of thrown.
* @return any exception that occurs underways
*/
/* msc 2009-12: this method has never thrown exceptions, instead they can be detected through
* Flow listening, and as of today also by looking at the return value. Starting to throw exceptions
* would be too big a change that I don't want to risk. I have no time to verify it doesn't harm. */
public static Exception remoteDaemonForServices(String host, int instance, boolean startStop, String cmdFlags, NativeCommand.Listener listener) {
if (listener != null) {
listener.stdoutWritten(null, "\nIn daemon mode, output cannot be displayed.\n" + "See logs in <daemon-owner>/.acs/commandcenter on host " + host + "\n");
}
String info = ((startStop) ? "Starting" : "Stopping") + " Acs Suite on host '" + host + "' (instance " + instance + ")";
remoteServicesDaemonFlow.reset(info);
ServicesDaemon daemon = null;
// msc 2014-11 ICT-3753: finer-grained logging
String step = "";
try {
org.omg.CORBA.ORB orb;
AcsCorba acsCorba = null;
remoteServicesDaemonFlow.trying(RemoteServicesDaemonFlow.INIT_CORBA);
step = "access acs-corba object";
// throws OrbInitException
acsCorba = firestarter.giveAcsCorba();
step = "access orb";
orb = acsCorba.getORB();
remoteServicesDaemonFlow.success(RemoteServicesDaemonFlow.INIT_CORBA);
remoteServicesDaemonFlow.trying(RemoteServicesDaemonFlow.CONNECT_DAEMON);
step = "convert host name to daemon address";
String daemonLoc = AcsLocations.convertToServicesDaemonLocation(host);
step = "convert daemon address to corba reference";
org.omg.CORBA.Object object = orb.string_to_object(daemonLoc);
step = "narrow corba reference to daemon object";
daemon = ServicesDaemonHelper.narrow(object);
step = "sanity check daemon object";
if (daemon == null)
throw new NullPointerException("received null trying to retrieve acsdaemon " + daemonLoc);
try {
if (// this may be superfluous with daemons but shouldn't hurt either
daemon._non_existent())
log.log(Level.INFO, "acsdaemon '" + daemonLoc + "' reported as non_existent, trying to use it nonetheless.");
} catch (Exception exc) {
log.log(Level.INFO, "problem verifying acsdaemon " + daemonLoc + " exists, trying to use it anyhow.", exc);
}
remoteServicesDaemonFlow.success(RemoteServicesDaemonFlow.CONNECT_DAEMON);
remoteServicesDaemonFlow.trying(RemoteServicesDaemonFlow.SEND_COMMAND);
final BlockingQueue<Completion> sync = new ArrayBlockingQueue<Completion>(1);
DaemonSequenceCallbackPOA daemonCallbackImpl = new DaemonSequenceCallbackPOA() {
public void done(Completion comp) {
sync.add(comp);
}
public void working(String service, String host, short instance_number, Completion comp) {
}
};
step = "create daemon callback";
DaemonSequenceCallback daemonCallback = DaemonSequenceCallbackHelper.narrow(acsCorba.activateOffShoot(daemonCallbackImpl, acsCorba.getRootPOA()));
step = "send request to daemon";
if (startStop == true)
daemon.start_acs(daemonCallback, (short) instance, cmdFlags);
else
daemon.stop_acs(daemonCallback, (short) instance, cmdFlags);
remoteServicesDaemonFlow.success(RemoteServicesDaemonFlow.SEND_COMMAND);
remoteServicesDaemonFlow.trying(RemoteServicesDaemonFlow.AWAIT_RESPONSE);
// The services daemon's start/stop methods are implemented asynchronously,
// which means we need to wait for the callback notification.
// @TODO: Perhaps a 10 minute timeout is too much though?
step = "poll on reply queue";
long timeout = 10;
TimeUnit timeoutUnit = TimeUnit.MINUTES;
Completion daemonReplyRaw = sync.poll(timeout, timeoutUnit);
if (daemonReplyRaw == null)
throw new RuntimeException("Timeout: Acs daemon did not " + (startStop ? "start" : "stop") + " Acs within " + timeout + " " + timeoutUnit);
step = "deserialize daemon response";
AcsJCompletion daemonReply = AcsJCompletion.fromCorbaCompletion(daemonReplyRaw);
if (daemonReply.isError()) {
AcsJException exc = daemonReply.getAcsJException();
throw new Exception("daemon responded with error " + exc.getMessage(), exc);
}
remoteServicesDaemonFlow.success(RemoteServicesDaemonFlow.AWAIT_RESPONSE);
return null;
} catch (Exception exc) {
remoteServicesDaemonFlow.failure(exc);
return new Exception(remoteServicesDaemonFlow.current() + ":" + step + ": " + exc.getMessage(), exc);
} finally {
// msc 2014-11 ICT-3753: omc-to-daemon connection can get stale. this apparently helps.
if (daemon != null) {
try {
daemon._release();
} catch (Exception exc) {
log.log(Level.INFO, "failure releasing internal resources for daemon, ignoring: " + exc.getMessage(), exc);
}
}
}
}
use of alma.acsdaemon.ServicesDaemon in project ACS by ACS-Community.
the class StartServicesHelper method getServicesDaemon.
/**
* Connects to the services daemon building the corba loc from its
* host address in ({@link #daemonHost}.
*
* @return the reference to the services daemon
*
* @throws GettingDaemonException in case of error getting the services daemon
*/
private ServicesDaemon getServicesDaemon() throws GettingDaemonException {
ServicesDaemon daemon;
String daemonLoc = AcsLocations.convertToServicesDaemonLocation(daemonHost);
logger.log(AcsLogLevel.DEBUG, "Getting services daemon from " + daemonHost);
try {
org.omg.CORBA.Object object = acsCorba.getORB().string_to_object(daemonLoc);
daemon = ServicesDaemonHelper.narrow(object);
if (daemon == null)
throw new GettingDaemonException("Received null trying to retrieve acs services daemon on " + daemonHost);
if (// this may be superfluous with daemons but shouldn't hurt either
daemon._non_existent())
throw new GettingDaemonException("Acs services daemon not existing on " + daemonHost);
} catch (Throwable t) {
throw new GettingDaemonException("Error getting the services daemon " + t.getMessage(), t);
}
return daemon;
}
use of alma.acsdaemon.ServicesDaemon in project ACS by ACS-Community.
the class StartServicesHelper method startACSServices.
/**
* Starts the services whose XML definition is in the parameter.
* <P>
* The real starting of services is delegated to {@link #internalStartServices(ServicesDaemon, ServiceDefinitionBuilder, String)}
*
* The starting of the services is delegated to a acs service daemon.
* @param xmlListOfServices The XML describing the list of services to start.
* It is generally returned by getServicesDescription()
*
* @throws GettingDaemonException in case of error getting the services daemon
* @throws DaemonException In case of error from the daemon
*/
public void startACSServices(String xmlListOfServices) throws GettingDaemonException, DaemonException {
if (xmlListOfServices == null || xmlListOfServices.isEmpty()) {
throw new IllegalArgumentException("The XML list of services can't be null nor empty");
}
// Get the reference to the daemon
ServicesDaemon daemon = getServicesDaemon();
// Get the service definition builder for the current instance
ServiceDefinitionBuilder srvDefBuilder = null;
try {
srvDefBuilder = daemon.create_service_definition_builder((short) instance);
} catch (Throwable t) {
throw new DaemonException("Error getting the service definition builder", t);
}
logger.log(AcsLogLevel.DEBUG, "ServiceDefinitionBuilder got from the ACS services daemon");
try {
srvDefBuilder.add_services_definition(xmlListOfServices);
} catch (Throwable t) {
throw new DaemonException("Error adding the list of services to the daemon", t);
}
StringHolder errorStr = new StringHolder();
if (!srvDefBuilder.is_valid(errorStr)) {
// Error in the XML
throw new DaemonException("Invalid XML list of services: " + errorStr.value);
}
internalStartServices(daemon, xmlListOfServices);
}
use of alma.acsdaemon.ServicesDaemon in project ACS by ACS-Community.
the class StartServicesHelper method stopServices.
/**
* Stops the services whose definition is in the passed parameter.
*
* @param xmlListOfServices The XML describing the list of services to stop.
* @throws GettingDaemonException In case of error getting the services daemon
* @throws DaemonException In case of error from the services daemon
*/
public void stopServices(String xmlListOfServices) throws GettingDaemonException, DaemonException {
if (xmlListOfServices == null || xmlListOfServices.isEmpty()) {
throw new IllegalArgumentException("The XML list of services can't be null nor empty");
}
logger.log(AcsLogLevel.DEBUG, "Stopping ACS with the services daemon");
// Get the reference to the daemon
ServicesDaemon daemon = getServicesDaemon();
DaemonSequenceCallbackImpl callback = new DaemonSequenceCallbackImpl(logger, false);
DaemonSequenceCallback daemonSequenceCallback = null;
try {
daemonSequenceCallback = DaemonSequenceCallbackHelper.narrow(acsCorba.activateOffShoot(callback, acsCorba.getRootPOA()));
} catch (Throwable t) {
throw new DaemonException("Error instantiating the callback", t);
}
logger.log(AcsLogLevel.DEBUG, "Asking the services daemon to stop services");
try {
daemon.stop_services(xmlListOfServices, daemonSequenceCallback);
} catch (Throwable t) {
throw new DaemonException("Error stopping services", t);
}
}
use of alma.acsdaemon.ServicesDaemon in project ACS by ACS-Community.
the class StartServicesHelper method startACSServices.
/**
* Starts the services as they are defined in the TMCDB.
* This method is a convenience that before first gets the list of services from the TMCDB
* by calling getServicesDescription() and then executes startACSServices(String xmlListOfServices)
* <P>
* The real starting of services is delegated to {@link #internalStartServices(ServicesDaemon, ServiceDefinitionBuilder, String)}
*
* @return A struct with the An XML representation of the started services, to be used in {@link #stopServices}
* and a list of services as they have been read from the TMCDB
*
* @throws GettingDaemonException in case of error getting the services daemon
* @throws HibernateException In case of error reading the services from the TMCDB
* @throws DaemonExceptionIn case of error from the daemon
* @throws TMCDBException If the list of services read from the TMCDB is empty
* @see AlarmServicesDefinitionHolder
*/
public AlarmServicesDefinitionHolder startACSServices() throws GettingDaemonException, HibernateException, DaemonException, TMCDBException {
logger.log(AcsLogLevel.DEBUG, "Starting ACS with services daemon");
// Get the reference to the daemon
ServicesDaemon daemon = getServicesDaemon();
logger.log(AcsLogLevel.DEBUG, "Services daemon acquired");
// Get the services from the TMCDB
AlarmServicesDefinitionHolder holder = internalGetServicesDescription(daemon);
// Start the services
internalStartServices(daemon, holder.xmlServicesDefinition);
return holder;
}
Aggregations