Search in sources :

Example 1 with AcsJCompletion

use of alma.acs.exceptions.AcsJCompletion 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 AcsJCompletion

use of alma.acs.exceptions.AcsJCompletion in project ACS by ACS-Community.

the class StateChangeListener method getCurrentState.

/**
	 * Reads the current state hierarchy.
	 * @return State hierarchy with outmost state first
	 * @throws AcsJIllegalStateEventEx if the state can't be read ; @TODO: use better fitting ex (don't want to create one now right before the release)
	 */
public String[] getCurrentState() throws AcsJIllegalStateEventEx {
    CompletionHolder ch = new CompletionHolder();
    String[] statesHierarchy = statesProperty.get_sync(ch);
    AcsJCompletion statesSyncCompletion = AcsJCompletion.fromCorbaCompletion(ch.value);
    if (statesSyncCompletion.isError() || statesSyncCompletion.getType() != ACSErrTypeOK.value || statesSyncCompletion.getCode() != ACSErrOK.value || statesHierarchy == null) {
        throw new AcsJIllegalStateEventEx("Failed to retrieve current subsystem state.");
    }
    return statesHierarchy;
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsJIllegalStateEventEx(alma.ACSErrTypeCommon.wrappers.AcsJIllegalStateEventEx) CompletionHolder(alma.ACSErr.CompletionHolder)

Example 3 with AcsJCompletion

use of alma.acs.exceptions.AcsJCompletion in project ACS by ACS-Community.

the class StateChangeListener method logNotification.

/**
	 * Logs a state change notification.
	 * @param value  the new state hierarchy
	 * @param completion  an optional completion 
	 */
protected void logNotification(String[] value, Completion completion) {
    String msg = "hierarchical state = '";
    for (int i = 0; i < value.length; i++) {
        msg += value[i];
        if (i < value.length - 1) {
            msg += '/';
        }
    }
    msg += "'. ";
    if (completion != null) {
        msg += "Completion=";
        AcsJCompletion compl = AcsJCompletion.fromCorbaCompletion(completion);
        if (compl.isError()) {
            msg += compl.getAcsJException().toString();
        } else {
            msg += "ok";
        }
    }
    logger.finer(msg);
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion)

Example 4 with AcsJCompletion

use of alma.acs.exceptions.AcsJCompletion in project ACS by ACS-Community.

the class MasterComponentImplBase method updateStateHierarchy.

/**
	 * Sets the property value of <code>currentStateHierarchy</code>
	 * to match the current (sub-)states from the state machine.
	 * <p>
	 * This method should not be overloaded by subclasses! We just don't make it final to meet special testing needs. 
	 */
public void updateStateHierarchy() throws AcsJException {
    AcsState[] stateHierarchy = m_stateMachine.getCurrentTopLevelState().getStateHierarchy();
    String newState = AcsStateUtil.stateHierarchyToString(stateHierarchy);
    // convert to String[]
    String[] stateNameHierarchy = new String[stateHierarchy.length];
    for (int i = 0; i < stateHierarchy.length; i++) {
        stateNameHierarchy[i] = stateHierarchy[i].stateName();
    }
    // set Baci property and announce the notification to the checker object beforehand if checking is enabled
    if (StateChangeNotificationChecker.monitorStateChangeNotification) {
        stateChangeNotificationChecker.announceStateChangeNotification(stateNameHierarchy);
    }
    CompletionHolder ch = new CompletionHolder();
    m_currentStateHierarchyDataAccess.set(stateNameHierarchy, ch);
    // optimization usually leaves out the completion if ok
    if (ch.value != null) {
        AcsJCompletion compl = AcsJCompletion.fromCorbaCompletion(ch.value);
        if (compl.isError()) {
            m_logger.log(Level.WARNING, "failed to update state property!", compl.getAcsJException());
            throw compl.getAcsJException();
        } else {
            m_logger.finest("Changed state property to '" + newState + "'.");
        }
    } else {
        m_logger.finest("Changed state property to '" + newState + "'.");
    }
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsState(alma.acs.genfw.runtime.sm.AcsState) CompletionHolder(alma.ACSErr.CompletionHolder)

Example 5 with AcsJCompletion

use of alma.acs.exceptions.AcsJCompletion in project ACS by ACS-Community.

the class ErrorComponentTest method testCompletionFromCompletion.

public void testCompletionFromCompletion() {
    // depth == 0
    AcsJCompletion comp = null;
    try {
        // call the component method
        comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromCompletion((short) 0));
    } catch (Throwable th) {
        m_logger.info("Caught an unexpected Exception");
        AcsJUnknownEx ex = new AcsJUnknownEx(th);
        ex.log(m_logger);
        fail("No exception should be thrown");
    }
    verifyErrorTrace(1, new AcsJGenericErrorEx(comp.getAcsJException()));
    // depth > 0
    short[] depths = new short[] { 1, 2, 3, 5, 13 };
    for (int i = 0; i < depths.length; i++) {
        try {
            // call the component method
            comp = AcsJCompletion.fromCorbaCompletion(errorComp.completionFromCompletion((depths[i])));
        } catch (Throwable th) {
            m_logger.info("Caught an unexpected Exception at depth " + depths[i]);
            AcsJUnknownEx ex = new AcsJUnknownEx(th);
            ex.log(m_logger);
            fail("No exception should be thrown");
        }
        verifyErrorTrace(depths[i] + 1, new AcsJGenericErrorEx(comp.getAcsJException()));
    }
}
Also used : AcsJCompletion(alma.acs.exceptions.AcsJCompletion) AcsJGenericErrorEx(alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx) AcsJUnknownEx(alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)

Aggregations

AcsJCompletion (alma.acs.exceptions.AcsJCompletion)8 CompletionHolder (alma.ACSErr.CompletionHolder)3 AcsJGenericErrorEx (alma.ACSErrTypeCommon.wrappers.AcsJGenericErrorEx)2 AcsJUnknownEx (alma.ACSErrTypeCommon.wrappers.AcsJUnknownEx)2 Completion (alma.ACSErr.Completion)1 AcsJIllegalStateEventEx (alma.ACSErrTypeCommon.wrappers.AcsJIllegalStateEventEx)1 GenericErrorAcsJCompletion (alma.ACSErrTypeCommon.wrappers.GenericErrorAcsJCompletion)1 ACSErrOKAcsJCompletion (alma.ACSErrTypeOK.wrappers.ACSErrOKAcsJCompletion)1 OrbInitException (alma.acs.commandcenter.meta.Firestarter.OrbInitException)1 PreparedString (alma.acs.commandcenter.util.PreparedString)1 AcsCorba (alma.acs.container.corba.AcsCorba)1 AcsJException (alma.acs.exceptions.AcsJException)1 AcsState (alma.acs.genfw.runtime.sm.AcsState)1 DaemonSequenceCallback (alma.acsdaemon.DaemonSequenceCallback)1 DaemonSequenceCallbackPOA (alma.acsdaemon.DaemonSequenceCallbackPOA)1 ServicesDaemon (alma.acsdaemon.ServicesDaemon)1 IOException (java.io.IOException)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 TimeUnit (java.util.concurrent.TimeUnit)1