Skip to content

Commit 751456b

Browse files
committed
Merge branch '887-manifest-docker' into 2.x
2 parents 5b2cc0d + 5c40d56 commit 751456b

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/ApplicationManifestUtils.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ private static void asBoolean(Map<String, Object> payload, String key, Consumer<
135135
as(payload, key, Boolean.class::cast, consumer);
136136
}
137137

138+
@SuppressWarnings("unchecked")
139+
private static void asDocker(Map<String, Object> payload, String key, Consumer<Docker> consumer) {
140+
as(payload, key, value -> {
141+
Map<String, String> docker = ((Map<String, String>) value);
142+
143+
return Docker.builder()
144+
.image(docker.get("image"))
145+
.password(docker.get("password"))
146+
.username(docker.get("username"))
147+
.build();
148+
}, consumer);
149+
}
150+
138151
private static void asInteger(Map<String, Object> payload, String key, Consumer<Integer> consumer) {
139152
as(payload, key, Integer.class::cast, consumer);
140153
}
@@ -292,6 +305,14 @@ private static void merge(List<Object> first, List<Object> second) {
292305
});
293306
}
294307

308+
private static Function<Path, Object> pathToString() {
309+
return path -> Optional.ofNullable(path).map(Path::toString).orElse(null);
310+
}
311+
312+
private static Function<ApplicationHealthCheck, Object> protectApplicationHealthCheck() {
313+
return applicationHealthCheck -> Optional.ofNullable(applicationHealthCheck).map(ApplicationHealthCheck::getValue).orElse(null);
314+
}
315+
295316
private static void putIfPresent(Map<String, Object> yaml, String key, Object value) {
296317
putIfPresent(yaml, key, value, Function.identity());
297318
}
@@ -305,6 +326,7 @@ private static ApplicationManifest.Builder toApplicationManifest(Map<String, Obj
305326
asString(application, "buildpack", builder::buildpack);
306327
asString(application, "command", builder::command);
307328
asMemoryInteger(application, "disk_quota", builder::disk);
329+
asDocker(application, "docker", builder::docker);
308330
asString(application, "domain", builder::domain);
309331
asListOfString(application, "domains", builder::domain);
310332
asMapOfStringString(application, "env", builder::environmentVariable);
@@ -343,14 +365,14 @@ private static Map<String, Object> toYaml(ApplicationManifest applicationManifes
343365
putIfPresent(yaml, "domains", applicationManifest.getDomains());
344366
putIfPresent(yaml, "env", applicationManifest.getEnvironmentVariables());
345367
putIfPresent(yaml, "health-check-http-endpoint", applicationManifest.getHealthCheckHttpEndpoint());
346-
putIfPresent(yaml, "health-check-type", applicationManifest.getHealthCheckType() != null ? applicationManifest.getHealthCheckType().getValue() : null);
368+
putIfPresent(yaml, "health-check-type", applicationManifest.getHealthCheckType(), protectApplicationHealthCheck());
347369
putIfPresent(yaml, "hosts", applicationManifest.getHosts());
348370
putIfPresent(yaml, "instances", applicationManifest.getInstances());
349371
putIfPresent(yaml, "memory", applicationManifest.getMemory());
350372
putIfPresent(yaml, "name", applicationManifest.getName());
351373
putIfPresent(yaml, "no-hostname", applicationManifest.getNoHostname());
352374
putIfPresent(yaml, "no-route", applicationManifest.getNoRoute());
353-
putIfPresent(yaml, "path", applicationManifest.getPath() != null ? applicationManifest.getPath().toString() : null);
375+
putIfPresent(yaml, "path", applicationManifest.getPath(), pathToString());
354376
putIfPresent(yaml, "random-route", applicationManifest.getRandomRoute());
355377
putIfPresent(yaml, "route-path", applicationManifest.getRoutePath());
356378
putIfPresent(yaml, "routes", applicationManifest.getRoutes(), ApplicationManifestUtils::toRoutesYaml);

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/_ApplicationManifest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ void check() {
6060
if (getDocker().getImage() == null && (getDocker().getUsername() != null || getDocker().getPassword() != null)) {
6161
throw new IllegalStateException("docker credentials require docker image to be set");
6262
}
63+
64+
if (getDocker().getPassword() != null && getDocker().getUsername() == null) {
65+
throw new IllegalStateException("Docker password requires username");
66+
}
67+
68+
if (getDocker().getPassword() == null && getDocker().getUsername() != null) {
69+
throw new IllegalStateException("Docker username requires password");
70+
}
6371
}
6472
}
6573

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/ApplicationManifestUtilsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ public void anchorsAndReferences() throws IOException {
4646
assertThat(actual).isEqualTo(expected);
4747
}
4848

49+
@Test
50+
public void readDocker() throws IOException {
51+
List<ApplicationManifest> expected = Collections.singletonList(
52+
ApplicationManifest.builder()
53+
.name("lima-application-1")
54+
.docker(Docker.builder()
55+
.image("lima-docker-image")
56+
.password("lima-docker-password")
57+
.username("lima-docker-username")
58+
.build())
59+
.healthCheckHttpEndpoint("lima-health-check-http-endpoint")
60+
.healthCheckType(NONE)
61+
.noRoute(false)
62+
.build());
63+
64+
List<ApplicationManifest> actual = ApplicationManifestUtils.read(new ClassPathResource("fixtures/manifest-lima.yml").getFile().toPath());
65+
66+
assertThat(actual).isEqualTo(expected);
67+
}
68+
4969
@Test
5070
public void read() throws IOException {
5171
List<ApplicationManifest> expected = Arrays.asList(

cloudfoundry-operations/src/test/resources/fixtures/manifest-alpha.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ applications:
88
health-check-type: none
99
instances: -1
1010
memory: 1M
11-
no-route: true
1211
path: /alpha-path
12+
no-route: true
1313
random-route: true
1414
routes:
1515
- route: alpha-route-1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
applications:
3+
- name: lima-application-1
4+
docker:
5+
image: lima-docker-image
6+
password: lima-docker-password
7+
username: lima-docker-username
8+
health-check-http-endpoint: lima-health-check-http-endpoint
9+
health-check-type: none
10+
no-route: false

0 commit comments

Comments
 (0)