Search in sources :

Example 1 with DaemonSequenceCallback

use of alma.acsdaemon.DaemonSequenceCallback 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);
            }
        }
    }
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsCorba(alma.acs.container.corba.AcsCorba) AcsJException(alma.acs.exceptions.AcsJException) PreparedString(alma.acs.commandcenter.util.PreparedString) ServicesDaemon(alma.acsdaemon.ServicesDaemon) DaemonSequenceCallbackPOA(alma.acsdaemon.DaemonSequenceCallbackPOA) IOException(java.io.IOException) OrbInitException(alma.acs.commandcenter.meta.Firestarter.OrbInitException) AcsJException(alma.acs.exceptions.AcsJException) DaemonSequenceCallback(alma.acsdaemon.DaemonSequenceCallback) Completion(alma.ACSErr.Completion) AcsJCompletion(alma.acs.exceptions.AcsJCompletion) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) TimeUnit(java.util.concurrent.TimeUnit)

Example 2 with DaemonSequenceCallback

use of alma.acsdaemon.DaemonSequenceCallback in project ACS by ACS-Community.

the class ServicesDaemonTest method testServicesBuilder.

public void testServicesBuilder() throws Exception {
    ServiceDefinitionBuilder sdb = daemon.create_service_definition_builder(instanceNumber);
    assertNotNull(sdb);
    assertEquals("ACS instance number must match the one provided to the factory", instanceNumber, sdb.acs_instance_number());
    // now we add services in an order that is not a legal startup order, to check re-ordering
    final String cdbPath = System.getProperty("user.dir");
    sdb.add_notification_service(systemNotificationServiceDefault.value, host);
    sdb.add_manager(host, "", true);
    sdb.add_notification_service(systemNotificationServiceLogging.value, host);
    // "" means that default name "Log" should be used
    sdb.add_logging_service(host, "");
    sdb.add_naming_service(host);
    sdb.add_xml_cdb(host, true, cdbPath);
    sdb.add_interface_repository(host, true, false);
    String xmlSrvDef = sdb.get_services_definition();
    sdb.close();
    System.out.println(xmlSrvDef);
    //System.getProperty("line.separator");
    String ls = "\n";
    String xmlExpected = "<acs_services_definition instance=\"" + instanceNumber + "\">" + ls + "<notification_service name=\"" + systemNotificationServiceDefault.value + "\" host=\"" + host + "\" />" + ls + "<manager host=\"" + host + "\" recovery=\"true\" />" + ls + "<notification_service name=\"" + systemNotificationServiceLogging.value + "\" host=\"" + host + "\" />" + ls + "<logging_service host=\"" + host + "\" />" + ls + "<naming_service host=\"" + host + "\" />" + ls + "<cdb host=\"" + host + "\" recovery=\"true\" cdb_xml_dir=\"" + cdbPath + "\" />" + ls + "<interface_repository host=\"" + host + "\" load=\"true\" wait_load=\"false\" />" + ls + "</acs_services_definition>" + ls;
    assertEquals(xmlExpected, xmlSrvDef);
    // Run these services
    DaemonSequenceCallbackImpl daemonSequenceCallbackImpl = new DaemonSequenceCallbackImpl(logger);
    DaemonSequenceCallback daemonSequenceCallback = activateDaemonSequenceCallback(daemonSequenceCallbackImpl);
    daemonSequenceCallbackImpl.prepareWaitForDone();
    StopWatch sw = new StopWatch(logger);
    daemon.start_services(xmlSrvDef, false, daemonSequenceCallback);
    assertTrue("The services did not start in 2 minutes", daemonSequenceCallbackImpl.waitForDone(2, TimeUnit.MINUTES));
    sw.logLapTime("call start_services");
    // Stop the services
    daemonSequenceCallbackImpl.prepareWaitForDone();
    sw = new StopWatch(logger);
    daemon.stop_services(xmlSrvDef, daemonSequenceCallback);
    assertTrue("The services did not stop in 2 minutes", daemonSequenceCallbackImpl.waitForDone(2, TimeUnit.MINUTES));
    sw.logLapTime("call stop_services");
}
Also used : DaemonSequenceCallback(alma.acsdaemon.DaemonSequenceCallback) ServiceDefinitionBuilder(alma.acsdaemon.ServiceDefinitionBuilder) StopWatch(alma.acs.util.StopWatch)

Example 3 with DaemonSequenceCallback

use of alma.acsdaemon.DaemonSequenceCallback in project ACS by ACS-Community.

the class StartServicesHelper method internalStartServices.

/**
	 * Asks the daemon to start the services whose description is in the passed XML.
	 * <P>
	 * This method assumes that the XML has already been validated 
	 * by {@link ServiceDefinitionBuilder#is_valid(StringHolder)}
	 * 
	 * @param daemon The daemon to start the services
	 * @param builder The builder to validate the XML;
	 *                 If <code>null</code> an instance is retrieved from the daemon.
	 * @param svcsXML The XML string describing the services to start
	 * 
	 * @throws DaemonException In case of a bad parameter in the method to start the services
	 * 						   or instantiating the callback
	 */
private void internalStartServices(ServicesDaemon daemon, String svcsXML) throws DaemonException {
    if (daemon == null) {
        throw new IllegalArgumentException("The daemon can't be null");
    }
    if (svcsXML == null || svcsXML.isEmpty()) {
        throw new IllegalArgumentException("The XML list of services can't be null nor empty");
    }
    DaemonSequenceCallbackImpl callback = new DaemonSequenceCallbackImpl(logger, true);
    DaemonSequenceCallback daemonSequenceCallback = null;
    try {
        daemonSequenceCallback = DaemonSequenceCallbackHelper.narrow(acsCorba.activateOffShoot(callback, acsCorba.getRootPOA()));
    } catch (Throwable t) {
        throw new DaemonException("Error starting the callback", t);
    }
    logger.log(AcsLogLevel.DEBUG, "Asking the services daemon to start services");
    try {
        daemon.start_services(svcsXML, true, daemonSequenceCallback);
    } catch (Throwable t) {
        throw new DaemonException("Error starting the services", t);
    }
}
Also used : DaemonSequenceCallback(alma.acsdaemon.DaemonSequenceCallback)

Example 4 with DaemonSequenceCallback

use of alma.acsdaemon.DaemonSequenceCallback 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);
    }
}
Also used : DaemonSequenceCallback(alma.acsdaemon.DaemonSequenceCallback) ServicesDaemon(alma.acsdaemon.ServicesDaemon)

Aggregations

DaemonSequenceCallback (alma.acsdaemon.DaemonSequenceCallback)4 ServicesDaemon (alma.acsdaemon.ServicesDaemon)2 Completion (alma.ACSErr.Completion)1 OrbInitException (alma.acs.commandcenter.meta.Firestarter.OrbInitException)1 PreparedString (alma.acs.commandcenter.util.PreparedString)1 AcsCorba (alma.acs.container.corba.AcsCorba)1 AcsJCompletion (alma.acs.exceptions.AcsJCompletion)1 AcsJException (alma.acs.exceptions.AcsJException)1 StopWatch (alma.acs.util.StopWatch)1 DaemonSequenceCallbackPOA (alma.acsdaemon.DaemonSequenceCallbackPOA)1 ServiceDefinitionBuilder (alma.acsdaemon.ServiceDefinitionBuilder)1 IOException (java.io.IOException)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1