Refine search
@Override public RuntimeException call() throws Exception { try { if (connectionMode.isAllowReconnect() && isCubeRunning(cubeId)) { controlEvent.fire(new PreRunningCube(cubeId)); return null; } controlEvent.fire(new CreateCube(cubeId)); controlEvent.fire(new StartCube(cubeId)); if (connectionMode.isAllowReconnect() && !connectionMode.isStoppable()) { // If we allow reconnections and containers are none stoppable which means that they will be able to be // reused in next executions then at this point we can assume that the container is a prerunning container. controlEvent.fire(new PreRunningCube(cubeId)); } } catch (RuntimeException e) { return e; } return null; } }
public static CubeConfiguration fromMap(Map<String, String> map) { CubeConfiguration cubeConfiguration = new CubeConfiguration(); if (map.containsKey(CONNECTION_MODE)) { cubeConfiguration.connectionMode = ConnectionMode.valueOf(ConnectionMode.class, map.get(CONNECTION_MODE)); } return cubeConfiguration; }
@Test public void shouldUsePreRunningContainerInStartOrConnectMode() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(true); fire(new BeforeStart(deployableContainer)); assertEventFired(PreRunningCube.class, 1); }
public void startCubeMappedContainer(@Observes BeforeStart event, CubeRegistry cubeRegistry, ContainerRegistry containerRegistry, CubeConfiguration cubeConfiguration) { Container container = ContainerUtil.getContainerByDeployableContainer(containerRegistry, event.getDeployableContainer()); if (container == null) { return; } Cube<?> cube = cubeRegistry.getCube(ContainerUtil.getCubeIDForContainer(container)); if (cube == null) { return; // No Cube found matching Container name, not managed by Cube } ConnectionMode connectionMode = cubeConfiguration.getConnectionMode(); if (connectionMode.isAllowReconnect() && cube.isRunningOnRemote()) { controlEvent.fire(new PreRunningCube(cube)); return; } controlEvent.fire(new CreateCube(cube)); controlEvent.fire(new StartCube(cube)); if (connectionMode.isAllowReconnect() && !connectionMode.isStoppable()) { // If we allow reconnections and containers are none stoppable which means that they will be able to be // reused in next executions then at this point we can assume that the container is a prerunning container. controlEvent.fire(new PreRunningCube(cube)); } }
@Test public void shouldStartAContainerInStartOrConnectLeaveModeAndNotStopIt() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECTANDLEAVE.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(false); fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); assertEventFired(PreRunningCube.class, 1); }
public void startCubeMappedContainer(@Observes BeforeStart event, CubeRegistry cubeRegistry, ContainerRegistry containerRegistry, CubeConfiguration cubeConfiguration) { Container container = ContainerUtil.getContainerByDeployableContainer(containerRegistry, event.getDeployableContainer()); if (container == null) { return; } Cube<?> cube = cubeRegistry.getCube(ContainerUtil.getCubeIDForContainer(container)); if (cube == null) { return; // No Cube found matching Container name, not managed by Cube } ConnectionMode connectionMode = cubeConfiguration.getConnectionMode(); if (connectionMode.isAllowReconnect() && cube.isRunningOnRemote()) { controlEvent.fire(new PreRunningCube(cube)); return; } controlEvent.fire(new CreateCube(cube)); controlEvent.fire(new StartCube(cube)); if (connectionMode.isAllowReconnect() && !connectionMode.isStoppable()) { // If we allow reconnections and containers are none stoppable which means that they will be able to be // reused in next executions then at this point we can assume that the container is a prerunning container. controlEvent.fire(new PreRunningCube(cube)); } }
@Test public void shouldStartAContainerInStartOrConnectModeAndStopIt() { Map<String, String> data = new HashMap<String, String>(); data.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); bind(ApplicationScoped.class, CubeConfiguration.class, CubeConfiguration.fromMap(data)); when(cube.isRunningOnRemote()).thenReturn(false); fire(new BeforeStart(deployableContainer)); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); assertEventFired(PreRunningCube.class, 0); }
public static CubeConfiguration fromMap(Map<String, String> map) { CubeConfiguration cubeConfiguration = new CubeConfiguration(); if (map.containsKey(CONNECTION_MODE)) { cubeConfiguration.connectionMode = ConnectionMode.valueOf(ConnectionMode.class, map.get(CONNECTION_MODE)); } return cubeConfiguration; }
@Override public RuntimeException call() throws Exception { try { if (connectionMode.isAllowReconnect() && isCubeRunning(cubeId)) { controlEvent.fire(new PreRunningCube(cubeId)); return null; } controlEvent.fire(new CreateCube(cubeId)); controlEvent.fire(new StartCube(cubeId)); if (connectionMode.isAllowReconnect() && !connectionMode.isStoppable()) { // If we allow reconnections and containers are none stoppable which means that they will be able to be // reused in next executions then at this point we can assume that the container is a prerunning container. controlEvent.fire(new PreRunningCube(cubeId)); } } catch (RuntimeException e) { return e; } return null; } }
@Test public void shouldStartAContainerInStartOrConnectModeAndStopIt() { Map<String, String> cubeData = new HashMap<String, String>(); cubeData.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); Map<String, String> dockerData = new HashMap<String, String>(); dockerData.put("autoStartContainers", "a,b"); dockerData.put("dockerContainers", "a:\n image: a\nb:\n image: a\n"); CubeConfiguration cubeConfiguration = CubeConfiguration.fromMap(cubeData); bind(ApplicationScoped.class, CubeConfiguration.class, cubeConfiguration); CubeDockerConfiguration dockerConfiguration = CubeDockerConfiguration.fromMap(dockerData, null); bind(ApplicationScoped.class, CubeDockerConfiguration.class, dockerConfiguration); Container container = mock(Container.class); when(container.getNames()).thenReturn(new String[] {"alreadyrun"}); when(executor.listRunningContainers()).thenReturn(Arrays.asList(container)); bind(ApplicationScoped.class, DockerClientExecutor.class, executor); fire(new BeforeSuite()); assertEventFired(CreateCube.class, 2); assertEventFired(StartCube.class, 2); assertEventFired(PreRunningCube.class, 0); assertEventFiredOnOtherThread(CreateCube.class); assertEventFiredOnOtherThread(StartCube.class); }
@Test public void shouldUsePreRunningContainers() { Map<String, String> cubeData = new HashMap<String, String>(); cubeData.put("connectionMode", ConnectionMode.STARTORCONNECT.name()); Map<String, String> dockerData = new HashMap<String, String>(); dockerData.put("autoStartContainers", "a,b"); dockerData.put("dockerContainers", "a:\n image: a\nb:\n image: a\n"); CubeConfiguration cubeConfiguration = CubeConfiguration.fromMap(cubeData); bind(ApplicationScoped.class, CubeConfiguration.class, cubeConfiguration); CubeDockerConfiguration dockerConfiguration = CubeDockerConfiguration.fromMap(dockerData, null); bind(ApplicationScoped.class, CubeDockerConfiguration.class, dockerConfiguration); Container container = mock(Container.class); when(container.getNames()).thenReturn(new String[] {"a"}); when(executor.listRunningContainers()).thenReturn(Arrays.asList(container)); bind(ApplicationScoped.class, DockerClientExecutor.class, executor); fire(new BeforeSuite()); assertEventFired(CreateCube.class, 1); assertEventFired(StartCube.class, 1); assertEventFired(PreRunningCube.class, 1); assertEventFiredOnOtherThread(CreateCube.class); assertEventFiredOnOtherThread(StartCube.class); assertEventFiredOnOtherThread(PreRunningCube.class); }
@Test public void shouldStartAContainerInStartOrConnectAndLeaveModeAndNotStopIt() { Map<String, String> cubeData = new HashMap<String, String>(); cubeData.put("connectionMode", ConnectionMode.STARTORCONNECTANDLEAVE.name()); Map<String, String> dockerData = new HashMap<String, String>(); dockerData.put("autoStartContainers", "a,b"); dockerData.put("dockerContainers", "a:\n image: a\nb:\n image: a\n"); CubeConfiguration cubeConfiguration = CubeConfiguration.fromMap(cubeData); bind(ApplicationScoped.class, CubeConfiguration.class, cubeConfiguration); CubeDockerConfiguration dockerConfiguration = CubeDockerConfiguration.fromMap(dockerData, null); bind(ApplicationScoped.class, CubeDockerConfiguration.class, dockerConfiguration); Container container = mock(Container.class); when(container.getNames()).thenReturn(new String[] {"alreadyrun"}); when(executor.listRunningContainers()).thenReturn(Arrays.asList(container)); bind(ApplicationScoped.class, DockerClientExecutor.class, executor); fire(new BeforeSuite()); assertEventFired(CreateCube.class, 2); assertEventFired(StartCube.class, 2); assertEventFired(PreRunningCube.class, 2); assertEventFiredOnOtherThread(CreateCube.class); assertEventFiredOnOtherThread(StartCube.class); assertEventFiredOnOtherThread(PreRunningCube.class); } }