Search in sources :

Example 1 with Completion

use of alma.ACSErr.Completion 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 Completion

use of alma.ACSErr.Completion in project ACS by ACS-Community.

the class ManagerProxy method releaseComponentAsync.

public void releaseComponentAsync(int id, URI curl, LongCompletionCallback callback) throws AcsJNoPermissionEx, AcsJBadParameterEx {
    try {
        final LongCompletionCallback fcallback = callback;
        CBlongPOA cbo = new CBlongPOA() {

            public boolean negotiate(long time_to_transmit, CBDescOut desc) {
                return false;
            }

            public void working(int value, Completion c, CBDescOut desc) {
            // noop
            }

            public void done(int value, Completion c, CBDescOut desc) {
                if (c.code == 0 && c.type == 0)
                    fcallback.done(value);
                else
                    // TODO maybe convert to specific exceptions
                    fcallback.failed(value, AcsJCompletion.fromCorbaCompletion(c).getAcsJException());
            }
        };
        CBDescIn desc = new CBDescIn(0, 0, 0);
        manager.release_component_async(id, curl.toString(), cbo._this(), desc);
    } catch (NoPermissionEx nop) {
        throw new AcsJNoPermissionEx(nop);
    }
}
Also used : Completion(alma.ACSErr.Completion) AcsJCompletion(alma.acs.exceptions.AcsJCompletion) CBDescOut(alma.ACS.CBDescOut) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CBlongPOA(alma.ACS.CBlongPOA) NoPermissionEx(alma.maciErrType.NoPermissionEx) AcsJNoPermissionEx(alma.maciErrType.wrappers.AcsJNoPermissionEx) CBDescIn(alma.ACS.CBDescIn)

Example 3 with Completion

use of alma.ACSErr.Completion in project ACS by ACS-Community.

the class ResponderUtil method respond.

/**
	 * @param exc
	 * @param cb
	 * @param descIn
	 */
public static void respond(Exception exc, CBlongSeq cb, CBDescIn descIn) {
    Completion completion = ResponderUtil.giveCompletion(exc);
    CBDescOut cbDescOut = ResponderUtil.giveDescOut(descIn);
    cb.done(new int[] {}, completion, cbDescOut);
}
Also used : Completion(alma.ACSErr.Completion) MyAcsJCompletion(alma.acs.callbacks.Objects.MyAcsJCompletion) CBDescOut(alma.ACS.CBDescOut)

Example 4 with Completion

use of alma.ACSErr.Completion in project ACS by ACS-Community.

the class ResponderUtil method respond.

/**
	 * @param exc
	 * @param cb
	 * @param descIn
	 */
public static void respond(Exception exc, CBstring cb, CBDescIn descIn) {
    Completion completion = ResponderUtil.giveCompletion(exc);
    CBDescOut cbDescOut = ResponderUtil.giveDescOut(descIn);
    cb.done("", completion, cbDescOut);
}
Also used : Completion(alma.ACSErr.Completion) MyAcsJCompletion(alma.acs.callbacks.Objects.MyAcsJCompletion) CBDescOut(alma.ACS.CBDescOut)

Example 5 with Completion

use of alma.ACSErr.Completion in project ACS by ACS-Community.

the class ResponderUtil method respond.

/**
	 * @param returnValue
	 * @param cb
	 * @param descIn
	 */
public static void respond(String[] returnValue, CBstringSeq cb, CBDescIn descIn) {
    Completion completion = ResponderUtil.giveCompletion();
    CBDescOut cbDescOut = ResponderUtil.giveDescOut(descIn);
    cb.done(returnValue, completion, cbDescOut);
}
Also used : Completion(alma.ACSErr.Completion) MyAcsJCompletion(alma.acs.callbacks.Objects.MyAcsJCompletion) CBDescOut(alma.ACS.CBDescOut)

Aggregations

Completion (alma.ACSErr.Completion)27 MyAcsJCompletion (alma.acs.callbacks.Objects.MyAcsJCompletion)14 CBDescOut (alma.ACS.CBDescOut)13 CBDescIn (alma.ACS.CBDescIn)7 Callback (alma.ACS.Callback)6 BACIDispatchAction (alma.ACS.jbaci.BACIDispatchAction)6 ErrorTrace (alma.ACSErr.ErrorTrace)2 AcsJCompletion (alma.acs.exceptions.AcsJCompletion)2 AcsJException (alma.acs.exceptions.AcsJException)2 CBlongPOA (alma.ACS.CBlongPOA)1 CompletionHolder (alma.ACSErr.CompletionHolder)1 NameValue (alma.ACSErr.NameValue)1 ACSErrTest1AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest1AcsJCompletion)1 ACSErrTest2AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest2AcsJCompletion)1 ACSErrTest3AcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTest3AcsJCompletion)1 ACSErrTestOKAcsJCompletion (alma.ACSErrTypeTest.wrappers.ACSErrTestOKAcsJCompletion)1 AcsJACSErrTest1Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest1Ex)1 AcsJACSErrTest2Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest2Ex)1 AcsJACSErrTest3Ex (alma.ACSErrTypeTest.wrappers.AcsJACSErrTest3Ex)1 MyAcsJException (alma.acs.callbacks.Objects.MyAcsJException)1