@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
/** * Parses a volume from specification to a {@link VolumesFrom}. * * @param serialized * the specification, e.g. <code>container:ro</code> * @return a {@link VolumesFrom} matching the specification * @throws IllegalArgumentException * if the specification cannot be parsed */ public static VolumesFrom parse(String serialized) { try { String[] parts = serialized.split(":"); switch (parts.length) { case 1: { return new VolumesFrom(parts[0]); } case 2: { return new VolumesFrom(parts[0], AccessMode.valueOf(parts[1])); } default: { throw new IllegalArgumentException(); } } } catch (Exception e) { throw new IllegalArgumentException("Error parsing Bind '" + serialized + "'"); } }
public final boolean toBoolean() { return this.equals(AccessMode.rw) ? true : false; }
/** * Returns a string representation of this {@link VolumesFrom} suitable for inclusion in a JSON message. The format is * <code><container>:<access mode></code>, like the argument in {@link #parse(String)}. * * @return a string representation of this {@link VolumesFrom} */ @Override public String toString() { return container + ":" + accessMode.toString(); }
@Override public void serialize(VolumeRW volumeRW, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException, JsonProcessingException { jsonGen.writeStartObject(); jsonGen.writeFieldName(volumeRW.getVolume().getPath()); jsonGen.writeString(Boolean.toString(volumeRW.getAccessMode().toBoolean())); jsonGen.writeEndObject(); }
public ContainerOptionsBuilder withVolume(String hostPath, String containerPath, BindMode bindMode) { setVolume(hostPath + ":" + containerPath + ":" + bindMode.accessMode.name()); return this; }
/** * Returns a string representation of this {@link Bind} suitable for inclusion in a JSON message. * The format is <code><host path>:<container path>:<access mode></code>, * like the argument in {@link #parse(String)}. * * @return a string representation of this {@link Bind} */ @Override public String toString() { return String.format("%s:%s:%s%s%s%s", path, volume.getPath(), accessMode.toString(), secMode != SELContext.none ? "," + secMode.toString() : "", noCopy != null ? ",nocopy" : "", propagationMode != PropagationMode.DEFAULT_MODE ? "," + propagationMode.toString() : ""); } }
@Override public void serialize(VolumesRW value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); for (final VolumeRW volumeRW : value.volumesRW) { jgen.writeBooleanField(volumeRW.getVolume().getPath(), volumeRW.getAccessMode().toBoolean()); } jgen.writeEndObject(); }
public ContainerOptionsBuilder withVolume(String hostPath, String containerPath, BindMode bindMode) { setVolume(hostPath + ":" + containerPath + ":" + bindMode.accessMode.name()); return this; }
@Override public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeRW> volumesRW = new ArrayList<VolumeRW>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); JsonNode value = field.getValue(); if (!value.equals(NullNode.getInstance())) { if (!value.isBoolean()) { throw deserializationContext.mappingException("Expected access mode for '" + field.getKey() + "' in host but got '" + value + "'."); } VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean())); volumesRW.add(bind); } } return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()])); } }
for (String p : flags) { if (p.length() == 2) { accessMode = AccessMode.valueOf(p.toLowerCase()); } else if ("nocopy".equals(p)) { nocopy = true;
/** * Returns a string representation of this {@link VolumesFrom} suitable for inclusion in a JSON message. The format is * <code><container>:<access mode></code>, like the argument in {@link #parse(String)}. * * @return a string representation of this {@link VolumesFrom} */ @Override public String toString() { return container + ":" + accessMode.toString(); }
@Override public void serialize(VolumeRW volumeRW, JsonGenerator jsonGen, SerializerProvider serProvider) throws IOException, JsonProcessingException { jsonGen.writeStartObject(); jsonGen.writeFieldName(volumeRW.getVolume().getPath()); jsonGen.writeString(Boolean.toString(volumeRW.getAccessMode().toBoolean())); jsonGen.writeEndObject(); }
public final boolean toBoolean() { return this.equals(AccessMode.rw) ? true : false; }
@Override public VolumeRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); if (!node.equals(NullNode.getInstance())) { Entry<String, JsonNode> field = node.fields().next(); String volume = field.getKey(); AccessMode accessMode = AccessMode.fromBoolean(field.getValue().asBoolean()); return new VolumeRW(new Volume(volume), accessMode); } else { return null; } } }
/** * Parses a volume from specification to a {@link VolumesFrom}. * * @param serialized * the specification, e.g. <code>container:ro</code> * @return a {@link VolumesFrom} matching the specification * @throws IllegalArgumentException * if the specification cannot be parsed */ public static VolumesFrom parse(String serialized) { try { String[] parts = serialized.split(":"); switch (parts.length) { case 1: { return new VolumesFrom(parts[0]); } case 2: { return new VolumesFrom(parts[0], AccessMode.valueOf(parts[1])); } default: { throw new IllegalArgumentException(); } } } catch (Exception e) { throw new IllegalArgumentException("Error parsing Bind '" + serialized + "'"); } }
/** * Returns a string representation of this {@link Bind} suitable for inclusion in a JSON message. * The format is <code><host path>:<container path>:<access mode></code>, * like the argument in {@link #parse(String)}. * * @return a string representation of this {@link Bind} */ @Override public String toString() { return String.format("%s:%s:%s%s%s%s", path, volume.getPath(), accessMode.toString(), secMode != SELContext.none ? "," + secMode.toString() : "", noCopy != null ? ",nocopy" : "", propagationMode != PropagationMode.DEFAULT_MODE ? "," + propagationMode.toString() : ""); } }
@Override public void serialize(VolumesRW value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { jgen.writeStartObject(); for (final VolumeRW volumeRW : value.volumesRW) { jgen.writeBooleanField(volumeRW.getVolume().getPath(), volumeRW.getAccessMode().toBoolean()); } jgen.writeEndObject(); }
@Override public VolumesRW deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { List<VolumeRW> volumesRW = new ArrayList<VolumeRW>(); ObjectCodec oc = jsonParser.getCodec(); JsonNode node = oc.readTree(jsonParser); for (Iterator<Map.Entry<String, JsonNode>> it = node.fields(); it.hasNext();) { Map.Entry<String, JsonNode> field = it.next(); JsonNode value = field.getValue(); if (!value.equals(NullNode.getInstance())) { if (!value.isBoolean()) { throw deserializationContext.mappingException("Expected access mode for '" + field.getKey() + "' in host but got '" + value + "'."); } VolumeRW bind = new VolumeRW(new Volume(field.getKey()), AccessMode.fromBoolean(value.asBoolean())); volumesRW.add(bind); } } return new VolumesRW(volumesRW.toArray(new VolumeRW[volumesRW.size()])); } }
for (String p : flags) { if (p.length() == 2) { accessMode = AccessMode.valueOf(p.toLowerCase()); } else if ("nocopy".equals(p)) { nocopy = true;