|
40 | 40 | import java.util.LinkedList; |
41 | 41 | import java.util.List; |
42 | 42 | import java.util.Map; |
| 43 | +import java.util.regex.Matcher; |
| 44 | +import java.util.regex.Pattern; |
43 | 45 | import org.sciserver.authentication.client.AuthenticatedUser; |
44 | 46 | import org.sciserver.compute.AppConfig; |
45 | 47 | import org.sciserver.compute.core.registry.Container; |
@@ -255,13 +257,58 @@ public ExecutableContainer createContainer(String name, String description, Auth |
255 | 257 | } |
256 | 258 | } |
257 | 259 |
|
258 | | - private void addVolumes(String source, String dest, Boolean ro, List<V1Volume> vols, List<V1VolumeMount> mounts) { |
259 | | - String srv = source.split("/")[2]; |
260 | | - String path = "/" + source.split("/", 4)[3]; |
261 | | - String name = "vol-" + vols.size(); |
262 | | - vols.add(new V1VolumeBuilder().withName(name).withNewNfs().withServer(srv).withPath(path).withReadOnly(ro) |
263 | | - .endNfs().build()); |
264 | | - mounts.add(new V1VolumeMountBuilder().withName(name).withMountPath(dest).withReadOnly(ro).build()); |
| 260 | + private void addVolumes(String source, String dest, Boolean ro, List<V1Volume> vols, List<V1VolumeMount> mounts) |
| 261 | + throws Exception { |
| 262 | + Pattern pattern = Pattern.compile("(.*)://([^/]+)/(.*)"); |
| 263 | + Matcher matcher = pattern.matcher(source); |
| 264 | + if (matcher.find()) { |
| 265 | + String type = matcher.group(1); |
| 266 | + String srv = matcher.group(2); |
| 267 | + String path = matcher.group(3); |
| 268 | + String name = "vol-" + vols.size(); |
| 269 | + |
| 270 | + V1Volume volume = null; |
| 271 | + V1VolumeMount volumeMount = null; |
| 272 | + |
| 273 | + switch (type) { |
| 274 | + case "nfs": |
| 275 | + volume = new V1VolumeBuilder() |
| 276 | + .withName(name) |
| 277 | + .withNewNfs() |
| 278 | + .withServer(srv) |
| 279 | + .withPath(path) |
| 280 | + .withReadOnly(ro) |
| 281 | + .endNfs() |
| 282 | + .build(); |
| 283 | + volumeMount = new V1VolumeMountBuilder() |
| 284 | + .withName(name) |
| 285 | + .withMountPath(dest) |
| 286 | + .withReadOnly(ro) |
| 287 | + .build(); |
| 288 | + break; |
| 289 | + case "pvc": |
| 290 | + volume = new V1VolumeBuilder() |
| 291 | + .withName(name) |
| 292 | + .withNewPersistentVolumeClaim() |
| 293 | + .withClaimName(srv) |
| 294 | + .endPersistentVolumeClaim() |
| 295 | + .build(); |
| 296 | + volumeMount = new V1VolumeMountBuilder() |
| 297 | + .withName(name) |
| 298 | + .withSubPath(path) |
| 299 | + .withMountPath(dest) |
| 300 | + .withReadOnly(ro) |
| 301 | + .build(); |
| 302 | + break; |
| 303 | + default: |
| 304 | + throw new Exception("Unrecognized mount type: " + type); |
| 305 | + } |
| 306 | + |
| 307 | + vols.add(volume); |
| 308 | + mounts.add(volumeMount); |
| 309 | + } else { |
| 310 | + throw new Exception("Cannot parse mount source: " + source); |
| 311 | + } |
265 | 312 | } |
266 | 313 |
|
267 | 314 | @Override |
|
0 commit comments