Search in sources :

Example 1 with AcsCorba

use of alma.acs.container.corba.AcsCorba in project ACS by ACS-Community.

the class ServicesDaemonTest method setUp.

protected void setUp() throws Exception {
    logger = ClientLogManager.getAcsLogManager().getLoggerForApplication(getFullName(), false);
    ClientLogManager.getAcsLogManager().suppressRemoteLogging();
    logger.info("\n------------ " + getName() + " --------------");
    try {
        acsCorba = new AcsCorba(logger);
        acsCorba.initCorbaForClient(false);
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "failed to initialize the ORB", ex);
        if (acsCorba != null) {
            try {
                acsCorba.shutdownORB(true, false);
                acsCorba.doneCorba();
            } catch (Exception ex2) {
                // to JUnit we want to forward the original exception, 
                // not any other exception from cleaning up the orb, 
                // which we would not have done without the first exception.
                ex2.printStackTrace();
            }
        }
        throw ex;
    }
    //or "alma78.hq.eso.org" for Heiko on eclipse
    host = ACSPorts.getIP();
    daemon = getServicesDaemon(host);
}
Also used : AcsCorba(alma.acs.container.corba.AcsCorba) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with AcsCorba

use of alma.acs.container.corba.AcsCorba in project ACS by ACS-Community.

the class AcsContainerRunner method run.

/**
	 * Startup choreography: performs the various tasks in the correct order.
	 * <p>
	 * Note on the implementation: the steps involved are grouped as private methods
	 * that access the instance variables. The intent was to make the sequence clearer.
	 *   
	 * @param args  command line args as given to <code>main</code>.
	 * @throws AcsJContainerServicesEx  at the slightest provocation...
	 */
private void run(String[] args) throws AcsJContainerEx {
    StopWatch containerStartWatch = new StopWatch();
    // just a temp logger
    m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("AcsContainerRunner", true);
    String argsString = "";
    for (String arg : args) {
        argsString += arg + " ";
    }
    m_logger.log(Level.INFO, "AcsContainerRunner#run with arguments " + argsString);
    setOptions(args);
    embeddedRunner = new AcsEmbeddedContainerRunner(false, m_recoveryModeOverride);
    embeddedRunner.setContainerName(m_containerName);
    embeddedRunner.setManagerLoc(m_managerLoc);
    checkReadyToRun();
    // now that embeddedRunner knows the container name, we can switch to the real logger  
    m_logger = embeddedRunner.getContainerLogger();
    m_acsCorba = new AcsCorba(m_logger);
    if (initialSleeptimeMillis > 0) {
        m_logger.fine("Container will sleep for " + initialSleeptimeMillis + " ms, e.g. to allow remote debuggers to attach at this early stage.");
        try {
            Thread.sleep(initialSleeptimeMillis);
        } catch (InterruptedException e) {
            m_logger.info("Woken up too early from initial-delay sleep.");
        }
    }
    m_acsCorba.initCorba(args, m_containerPort);
    m_acsCorba.runCorba();
    embeddedRunner.run(m_acsCorba);
    m_shutdownHook = new ShutdownHook(m_logger);
    Runtime.getRuntime().addShutdownHook(m_shutdownHook);
    m_shutdownHook.setAcsContainer(embeddedRunner.getContainer());
    initAcsLogging(embeddedRunner.getManagerProxy());
    m_logger.fine("entering orb loop");
    containerStartWatch.setLogger(m_logger);
    containerStartWatch.logLapTime("start the container");
    // here we hang for the life time of the container...
    m_acsCorba.blockOnORB();
    m_logger.fine("orb loop over.");
    m_logger.exiting(AcsContainerRunner.class.getName(), "run");
    m_shutdownHook.setRegularShutdownExpected();
}
Also used : AcsCorba(alma.acs.container.corba.AcsCorba) StopWatch(alma.acs.util.StopWatch)

Example 3 with AcsCorba

use of alma.acs.container.corba.AcsCorba in project ACS by ACS-Community.

the class ComponentClientTestCase method setUp.

/**
	 * Starts CORBA in the client process and connects to the manager and logger.
     * <p>
     * <b>Subclasses that override this method must call <code>super.setUp()</code>,
     * likely before any other code in that method.</b>
	 *  
	 * @see junit.framework.TestCase#setUp()
	 */
protected void setUp() throws Exception {
    m_logger = ClientLogManager.getAcsLogManager().getLoggerForApplication(getFullName(), true);
    m_logger.info("-------------------------------");
    m_logger.info("ComponentClientTestCase#setUp()");
    POA rootPOA = null;
    try {
        acsCorba = new AcsCorba(m_logger);
        rootPOA = acsCorba.initCorbaForClient(false);
        connectToManager();
        DAL cdb = DALHelper.narrow(m_acsManagerProxy.get_service("CDB", false));
        m_threadFactory = new CleaningDaemonThreadFactory(m_namePrefix, m_logger);
        m_containerServices = new ContainerServicesImpl(m_acsManagerProxy, cdb, rootPOA, acsCorba, m_logger, m_acsManagerProxy.getManagerHandle(), this.getClass().getName(), null, m_threadFactory) {

            public AcsLogger getLogger() {
                return m_logger;
            }
        };
        managerClientImpl.setContainerServices(m_containerServices);
        initRemoteLogging();
        ACSAlarmSystemInterfaceFactory.init(m_containerServices);
    } catch (Exception ex1) {
        m_logger.log(Level.SEVERE, "failed to initialize the ORB, or connect to the ACS Manager, " + "or to set up the container services.", ex1);
        if (acsCorba != null) {
            try {
                acsCorba.shutdownORB(true, false);
                acsCorba.doneCorba();
            } catch (Exception ex2) {
                // to JUnit we want to forward the original exception ex1, 
                // not any other exception from cleaning up the orb 
                // which we would not have done without the first exception.
                // Thus we simply print ex2 but let ex1 fly
                ex2.printStackTrace();
            }
        }
        throw ex1;
    }
}
Also used : ContainerServicesImpl(alma.acs.container.ContainerServicesImpl) AcsCorba(alma.acs.container.corba.AcsCorba) POA(org.omg.PortableServer.POA) CleaningDaemonThreadFactory(alma.acs.container.CleaningDaemonThreadFactory) DAL(com.cosylab.CDB.DAL) AcsLogger(alma.acs.logging.AcsLogger)

Example 4 with AcsCorba

use of alma.acs.container.corba.AcsCorba in project ACS by ACS-Community.

the class CorbaAnyExtractionTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    acsCorba = new AcsCorba(logger);
    acsCorba.initCorbaForClient(false);
    monitorPointExpert = new TestMonitorPointExpert();
    anyExtractor = new AnyExtractor(logger, monitorPointExpert);
    clobber = new Clobber(logger);
}
Also used : AcsCorba(alma.acs.container.corba.AcsCorba) Clobber(alma.acs.monitoring.DAO.Clobber) TestMonitorPointExpert(alma.acs.monitoring.blobber.TestBlobber.TestMonitorPointExpert) Before(org.junit.Before)

Example 5 with AcsCorba

use of alma.acs.container.corba.AcsCorba 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)

Aggregations

AcsCorba (alma.acs.container.corba.AcsCorba)8 Completion (alma.ACSErr.Completion)1 OrbInitException (alma.acs.commandcenter.meta.Firestarter.OrbInitException)1 PreparedString (alma.acs.commandcenter.util.PreparedString)1 CleaningDaemonThreadFactory (alma.acs.container.CleaningDaemonThreadFactory)1 ContainerServicesImpl (alma.acs.container.ContainerServicesImpl)1 AcsJCompletion (alma.acs.exceptions.AcsJCompletion)1 AcsJException (alma.acs.exceptions.AcsJException)1 AcsLogger (alma.acs.logging.AcsLogger)1 Clobber (alma.acs.monitoring.DAO.Clobber)1 TestMonitorPointExpert (alma.acs.monitoring.blobber.TestBlobber.TestMonitorPointExpert)1 StopWatch (alma.acs.util.StopWatch)1 DaemonSequenceCallback (alma.acsdaemon.DaemonSequenceCallback)1 DaemonSequenceCallbackPOA (alma.acsdaemon.DaemonSequenceCallbackPOA)1 ServicesDaemon (alma.acsdaemon.ServicesDaemon)1 DAL (com.cosylab.CDB.DAL)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ExecutionException (java.util.concurrent.ExecutionException)1