Search in sources :

Example 1 with FailedToStartContainerEx

use of alma.acsdaemonErrType.FailedToStartContainerEx in project ACS by ACS-Community.

the class ContainerUtil method startContainer.

/**
	 * Starts (possibly remote) containers using container daemons. 
	 * <p>
	 * Note that outside of performance tests it is required to start containers either through the OMC
	 * or by the manager in case of CDB-configured autostart containers. 
	 * Here we do it from application code in order to run flexible tests that don't require a CDB setup.
	 * <p>
	 * Similar code from module acscommandcenter (Executor#remoteDaemonForContainers) does not seem to implement
	 * synchronization on the container becoming available. 
	 * 
	 * @param host Name of container host. Can be <code>null</code> for localhost.
	 * @param containerType
	 * @param containerName
	 * @param flags
	 * @param waitContainerReady  If true, waits for the container to be ready, as indicated by a callback from the manager (requires prior login to the manager).
	 * @throws FailedToStartContainerEx 
	 * @throws BadParameterEx 
	 */
public void startContainer(String host, ContainerImplLangType containerType, String containerName, String flags, boolean waitContainerReady) throws AcsJBadParameterEx, AcsJFailedToStartContainerEx {
    if (!loggedInToManager && waitContainerReady) {
        throw new IllegalStateException("must be logged in to the manager if waitContainerReady==true");
    }
    if (host == null || host.isEmpty()) {
        host = ACSPorts.getIP();
    }
    if (flags == null) {
        flags = "";
    }
    ContainerDaemonOperations daemon = getContainerDaemon(host);
    // TODO check that string is as expected by daemon, e.g. "py" vs. "python"
    String containerTypeName = containerType.toString();
    short instanceNumber = (short) ACSPorts.getBasePort();
    try {
        daemon.start_container(containerTypeName, containerName, instanceNumber, new String[0], flags);
    } catch (BadParameterEx ex) {
        throw new AcsJBadParameterEx();
    } catch (FailedToStartContainerEx ex) {
        throw new AcsJFailedToStartContainerEx();
    }
    if (waitContainerReady) {
        boolean containerOK = false;
        try {
            containerOK = managerAdminClient.awaitContainerLogin(containerName, 30, TimeUnit.SECONDS);
        } catch (InterruptedException ex) {
        // just leave containerOK = false
        }
        if (!containerOK) {
            throw new AcsJFailedToStartContainerEx("Did not receive manager notification about container '" + containerName + "' having logged in.");
        }
    }
}
Also used : AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) FailedToStartContainerEx(alma.acsdaemonErrType.FailedToStartContainerEx) AcsJFailedToStartContainerEx(alma.acsdaemonErrType.wrappers.AcsJFailedToStartContainerEx) ContainerDaemonOperations(alma.acsdaemon.ContainerDaemonOperations) AcsJBadParameterEx(alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx) BadParameterEx(alma.ACSErrTypeCommon.BadParameterEx) AcsJFailedToStartContainerEx(alma.acsdaemonErrType.wrappers.AcsJFailedToStartContainerEx)

Aggregations

BadParameterEx (alma.ACSErrTypeCommon.BadParameterEx)1 AcsJBadParameterEx (alma.ACSErrTypeCommon.wrappers.AcsJBadParameterEx)1 ContainerDaemonOperations (alma.acsdaemon.ContainerDaemonOperations)1 FailedToStartContainerEx (alma.acsdaemonErrType.FailedToStartContainerEx)1 AcsJFailedToStartContainerEx (alma.acsdaemonErrType.wrappers.AcsJFailedToStartContainerEx)1