/** * {@inheritDoc} */ @Override public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) { final MountableFile mountableFile = MountableFile.forHostPath(hostPath); binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext)); }
@Override public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Bind> binds = new ArrayList<Bind>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<JsonNode> it = node.elements(); it.hasNext();) { JsonNode field = it.next(); binds.add(Bind.parse(field.asText())); } return new Binds(binds.toArray(new Bind[0])); } }
@Override public boolean equals(Object obj) { if (obj instanceof Bind) { Bind other = (Bind) obj; return new EqualsBuilder() .append(path, other.getPath()) .append(volume, other.getVolume()) .append(accessMode, other.getAccessMode()) .append(secMode, other.getSecMode()) .append(noCopy, other.getNoCopy()) .append(propagationMode, other.getPropagationMode()) .isEquals(); } else { return super.equals(obj); } }
private static final Bind[] toBinds(Collection<String> bindsList) { Bind[] binds = new Bind[bindsList.size()]; int i = 0; for (String bind : bindsList) { binds[i] = Bind.parse(bind); i++; } return binds; }
@Override public boolean equals(Object obj) { if (obj instanceof Bind) { Bind other = (Bind) obj; return new EqualsBuilder() .append(path, other.getPath()) .append(volume, other.getVolume()) .append(accessMode, other.getAccessMode()) .append(secMode, other.getSecMode()) .append(noCopy, other.getNoCopy()) .append(propagationMode, other.getPropagationMode()) .isEquals(); } else { return super.equals(obj); } }
private boolean checkMountableFile() { DockerClient dockerClient = client(); MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class"); Volume volume = new Volume("/dummy"); try { return runInsideDocker( createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)), (__, containerId) -> { try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) { stream.read(); return true; } catch (Exception e) { return false; } } ); } catch (Exception e) { log.debug("Failure while checking for mountable file support", e); return false; } }
private static final Bind[] toBinds(Collection<String> bindsList) { Bind[] binds = new Bind[bindsList.size()]; int i = 0; for (String bind : bindsList) { binds[i] = Bind.parse(bind); i++; } return binds; }
private static Bind parseOneBind(String definition) throws IllegalArgumentException { try { // first try as-is (using ":" as delimiter) in order to // preserve whitespace in paths return Bind.parse(definition); } catch (IllegalArgumentException e1) { try { // give it a second try assuming blanks as delimiter return Bind.parse(definition.replace(' ', ':')); } catch (Exception e2) { throw new IllegalArgumentException( "Bind mount needs to be in format 'hostPath containerPath[ rw|ro]'"); } } }
/** * {@inheritDoc} */ @Override public void addFileSystemBind(final String hostPath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) { final MountableFile mountableFile = MountableFile.forHostPath(hostPath); binds.add(new Bind(mountableFile.getResolvedPath(), new Volume(containerPath), mode.accessMode, selinuxContext.selContext)); }
@Override public Binds deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<Bind> binds = new ArrayList<Bind>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<JsonNode> it = node.elements(); it.hasNext();) { JsonNode field = it.next(); binds.add(Bind.parse(field.asText())); } return new Binds(binds.toArray(new Bind[0])); } }
void testServiceCallWithNoKeyPropertyFound() { Component componentUnderTest = new Component() { Integer getProperties(String key) { return null; // property should not be found } Request getRequest() { return new Request(...); //this request should not contain a property named "key", } Bind getBind() { return new Bind(...); //this bind should not contain a property named "key" } String makeServiceCall(String url) { if (url.endsWith("null")) { return success; } throw new AssertionError("expected url ending with null, but was " + url); } }; componentUnderTest.activate(); assertThat(componentUnderTest.getSomeString(), equalTo("success")); }
public FormValidation doCheckVolumesString(@QueryParameter String volumesString) { try { final String[] strings = splitAndFilterEmpty(volumesString, "\n"); for (String s : strings) { if (s.equals("/")) { return FormValidation.error("Invalid volume: path can't be '/'"); } final String[] group = s.split(":"); if (group.length > 3) { return FormValidation.error("Wrong syntax: " + s); } else if (group.length == 2 || group.length == 3) { if (group[1].equals("/")) { return FormValidation.error("Invalid bind mount: destination can't be '/'"); } Bind.parse(s); } else if (group.length == 1) { new Volume(s); } else { return FormValidation.error("Wrong line: " + s); } } } catch (Throwable t) { return FormValidation.error(t.getMessage()); } return FormValidation.ok(); }
private CreateContainerCmd getBaseCommand() { String hostDir = MesosCluster.getClusterHostDir().getAbsolutePath(); List<Bind> binds = new ArrayList<>(); binds.add(Bind.parse("/var/run/docker.sock:/var/run/docker.sock:rw")); binds.add(Bind.parse("/sys/fs/cgroup:/sys/fs/cgroup")); binds.add(Bind.parse(hostDir + ":" + hostDir)); if (getCluster().getMapAgentSandboxVolume()) { binds.add(Bind.parse(String.format("%s:%s:rw", hostDir + "/.minimesos/sandbox-" + getClusterId() + "/" + hostName, MESOS_AGENT_WORK_DIR + hostName + "/slaves"))); } CreateContainerCmd cmd = DockerClientFactory.build().createContainerCmd(getImageName() + ":" + getImageTag()) .withName(getName()) .withHostName(hostName) .withPrivileged(true) .withVolumes(new Volume(MESOS_AGENT_WORK_DIR + hostName)) .withEnv(newEnvironment() .withValues(getMesosAgentEnvVars()) .withValues(getSharedEnvVars()) .createEnvironment()) .withPidMode("host") .withLinks(new Link(getZooKeeper().getContainerId(), "minimesos-zookeeper")) .withBinds(binds.stream().toArray(Bind[]::new)); MesosDns mesosDns = getCluster().getMesosDns(); if (mesosDns != null) { cmd.withDns(mesosDns.getIpAddress()); } return cmd; }
@Override public CreateContainerCmd build(ServiceDescriptor sd, CreateContainerCmd cmd, Volume v) { Bind[] binds = cmd.getBinds(); String hostPath = v.useClasspath() ? Thread.currentThread().getContextClassLoader() .getResource(v.host()).getPath() : v.host(); Bind bind = new Bind(hostPath, new com.github.dockerjava.api.model.Volume(v.container()), AccessMode.fromBoolean(v.accessMode().equals(Volume.AccessMode.RW))); List<Bind> bindsList = new ArrayList<>(); if(binds != null) { bindsList.addAll(Arrays.asList(binds)); } bindsList.add(bind); return cmd.withBinds(bindsList); }
@Override protected CreateContainerCmd dockerCommand() { return DockerClientFactory.build().createContainerCmd(config.getImageName() + ":" + config.getImageTag()) .withNetworkMode("host") .withBinds(Bind.parse("/var/run/docker.sock:/tmp/docker.sock")) .withCmd("-internal", String.format("consul://%s:%d", consul.getIpAddress(), ConsulConfig.CONSUL_HTTP_PORT)) .withName(getName()); }
.withBinds(new Bind(hostConfigFilePath, configVol)); new Bind(testFilesPath, testFilesVolume, AccessMode.ro), new Bind(workspacePath, workspaceVolume, AccessMode.rw), new Bind(configFilePath, configVol)); } else { new Bind(testFilesPath, testFilesVolume, AccessMode.ro), new Bind(workspacePath, workspaceVolume, AccessMode.rw));
binds.add(Bind.parse(vol)); } else if (vol.equals("/")) { throw new IllegalArgumentException("Invalid volume: path can't be '/'");