public void apply(Cube cube) { String[] scriptsToExecute = postProcessScript(this.chaosScriptContent); for (String scriptToExecute : scriptsToExecute) { if (cube.hasMetadata(CanExecuteProcessInContainer.class)) { final String[] command = scriptToExecute.split("\\s+"); final CanExecuteProcessInContainer executeProcess = (CanExecuteProcessInContainer) cube.getMetadata(CanExecuteProcessInContainer.class); executeProcess.exec(command); } } }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
@Override public void copyLog(String cubeId, boolean follow, boolean stdout, boolean stderr, boolean timestamps, int tail, OutputStream outputStream) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to get logs command does not exist."); if (cube.hasMetadata(CanCopyFromContainer.class)) { cube.getMetadata(CanCopyFromContainer.class).copyLog(follow, stdout, stderr, timestamps, tail, outputStream); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanCopyFromContainer.class.getSimpleName() + " metadata"); } }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
@Override public void copyLog(String cubeId, boolean follow, boolean stdout, boolean stderr, boolean timestamps, int tail, OutputStream outputStream) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to get logs command does not exist."); if (cube.hasMetadata(CanCopyFromContainer.class)) { cube.getMetadata(CanCopyFromContainer.class).copyLog(follow, stdout, stderr, timestamps, tail, outputStream); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanCopyFromContainer.class.getSimpleName() + " metadata"); } }
@Override public TopContainer top(String cubeId) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to get top command does not exist."); if (cube.hasMetadata(CanSeeTop.class)) { return cube.getMetadata(CanSeeTop.class).top(); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanSeeTop.class.getSimpleName() + " metadata"); } }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
@Override public void copyFileDirectoryFromContainer(String cubeId, String from, String to) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to execute copy file command does not exist."); if (cube.hasMetadata(CanCopyFromContainer.class)) { cube.getMetadata(CanCopyFromContainer.class).copyDirectory(from, to); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanCopyFromContainer.class.getSimpleName() + " metadata"); } }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
private int getBindingPort(String cubeId, int exposedPort) { int bindPort = -1; final Cube cube = getCube(cubeId); if (cube != null) { final HasPortBindings portBindings = (HasPortBindings) cube.getMetadata(HasPortBindings.class); final HasPortBindings.PortAddress mappedAddress = portBindings.getMappedAddress(exposedPort); if (mappedAddress != null) { bindPort = mappedAddress.getPort(); } } return bindPort; }
@Override public TopContainer top(String cubeId) { Cube<?> cube = cubeRegistry.get().getCube(cubeId); Validate.notNull(cube, "Cube with id '" + cubeId + "' to get top command does not exist."); if (cube.hasMetadata(CanSeeTop.class)) { return cube.getMetadata(CanSeeTop.class).top(); } else { throw new IllegalArgumentException( "Cube " + cubeId + " does not provide the " + CanSeeTop.class.getSimpleName() + " metadata"); } }
public void generateReportEntries(@Observes AfterAutoStop event, CubeRegistry cubeRegistry) { if (cubeRegistry == null) { return; } final List<Cube<?>> reportableCubes = cubeRegistry.getByMetadata(CanReportMetrics.class); for (Cube cube : reportableCubes) { final CanReportMetrics metadata = (CanReportMetrics) cube.getMetadata(CanReportMetrics.class); final ReportInSectionBuilder sectionBuilder = metadata.report(); sectionBuilder.fire(reportEvent); } } }
public void generateReportEntries(@Observes AfterAutoStop event, CubeRegistry cubeRegistry) { if (cubeRegistry == null) { return; } final List<Cube<?>> reportableCubes = cubeRegistry.getByMetadata(CanReportMetrics.class); for (Cube cube : reportableCubes) { final CanReportMetrics metadata = (CanReportMetrics) cube.getMetadata(CanReportMetrics.class); final ReportInSectionBuilder sectionBuilder = metadata.report(); sectionBuilder.fire(reportEvent); } } }
@Test public void shouldNotRemapContainerAddressToBootToDocker() { Map<String, String> containerConfig = new HashMap<String, String>(); containerConfig.put("myHost", "10.0.10.1"); when(containerDef.getContainerProperties()).thenReturn(containerConfig); when(cube.getMetadata(HasPortBindings.class)).thenReturn(hasPortBindings); bind(ApplicationScoped.class, OperatingSystemFamily.class, OperatingSystemFamily.MAC); fire(new BeforeSetup(deployableContainer)); verify(containerDef, times(0)).overrideProperty("myHost", "192.168.0.1"); } }
@Test public void shouldSubstituteDockerServerIpContainerAddressToBootToDockerIp() { Map<String, String> containerConfig = new HashMap<String, String>(); containerConfig.put("myHost", CubeDockerConfiguration.DOCKER_SERVER_IP); when(containerDef.getContainerProperties()).thenReturn(containerConfig); when(cube.getMetadata(HasPortBindings.class)).thenReturn(hasPortBindings); bind(ApplicationScoped.class, OperatingSystemFamily.class, OperatingSystemFamily.MAC); fire(new BeforeSetup(deployableContainer)); verify(containerDef).overrideProperty("myHost", "192.168.0.1"); }
private String getInternalIp(CubeDockerConfiguration cubeDockerConfiguration, String containerName) { final Cube<?> cube = cubeRegistryInstance.get() .getCube(containerName); if (cube == null) { return cubeDockerConfiguration.getDockerServerIp(); } if (cube.hasMetadata(HasPortBindings.class)) { return cube.getMetadata(HasPortBindings.class).getInternalIP(); } return cubeDockerConfiguration.getDockerServerIp(); }
@Override public void proxyStarted(Cube<?> cube) { Proxy proxy = proxyInst.get(); if (!cube.hasMetadata(HasPortBindings.class)) { throw new IllegalStateException("Proxy Cube " + proxy.getName() + " has no PortBinding data."); } HasPortBindings bindings = cube.getMetadata(HasPortBindings.class); PortAddress communicationPort = bindings.getMappedAddress(proxy.getCommunicationPort().getExposed()); scenarioInst.set(new ToxiProxyScenario(ToxiProxyClient.Builder.create(communicationPort.getIP(), communicationPort.getPort()), injectorInstance.get())); }
@Test public void shouldGetCorrectMetadata() { Cube<?> cube = new TestCube(); cube.addMetadata(TestMetadata.class, new TestMetadataImpl()); TestMetadata metadata = cube.getMetadata(TestMetadata.class); Assert.assertTrue(metadata instanceof TestMetadataImpl); }