Skip to content

Commit e18f771

Browse files
authored
Merge pull request #1261 from schulzh/fix-manifest
fix docker, disk_quota and health+readiness check type serialization
2 parents 5216e50 + 00f7096 commit e18f771

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,11 @@ static Map<String, Object> toApplicationYaml(_ApplicationManifestCommon applicat
423423
if (null != disk) {
424424
putIfPresent(yaml, "disk_quota", applicationManifest.getDisk().toString() + "M");
425425
}
426-
putIfPresent(yaml, "docker", applicationManifest.getDocker());
426+
putIfPresent(
427+
yaml,
428+
"docker",
429+
applicationManifest.getDocker(),
430+
ApplicationManifestUtilsCommon::toDockerYaml);
427431
putIfPresent(yaml, "domains", applicationManifest.getDomains());
428432
putIfPresent(yaml, "env", applicationManifest.getEnvironmentVariables());
429433
putIfPresent(

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private static ManifestV3Process getProcess(
197197

198198
asString(raw, "type", variables, builder::type);
199199
asString(raw, "command", variables, builder::command);
200-
asString(raw, "disk", variables, builder::disk);
200+
asString(raw, "disk_quota", variables, builder::disk);
201201
asString(raw, "health-check-http-endpoint", variables, builder::healthCheckHttpEndpoint);
202202
asInteger(
203203
raw,
@@ -315,8 +315,13 @@ private static Map<String, Object> toProcessYaml(ManifestV3Process process) {
315315
putIfPresent(yaml, "health-check-http-endpoint", process.getHealthCheckHttpEndpoint());
316316
putIfPresent(
317317
yaml, "health-check-invocation-timeout", process.getHealthCheckInvocationTimeout());
318-
putIfPresent(yaml, "health-check-type", process.getHealthCheckType().getValue());
319-
putIfPresent(yaml, "readiness-health-check-type", process.getReadinessHealthCheckType());
318+
putIfPresent(
319+
yaml, "health-check-type", process.getHealthCheckType(), HealthCheckType::getValue);
320+
putIfPresent(
321+
yaml,
322+
"readiness-health-check-type",
323+
process.getReadinessHealthCheckType(),
324+
ReadinessHealthCheckType::getValue);
320325
putIfPresent(
321326
yaml,
322327
"readiness-health-check-http-endpoint",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package org.cloudfoundry.operations.applications;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.io.IOException;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
import org.cloudfoundry.client.v3.processes.ReadinessHealthCheckType;
9+
import org.junit.jupiter.api.Test;
10+
11+
class ApplicationManifestUtilsV3Test {
12+
@Test
13+
void testGenericApplication() throws IOException {
14+
ManifestV3 manifest =
15+
ManifestV3.builder()
16+
.application(
17+
ManifestV3Application.builder()
18+
.name("test-app")
19+
.buildpack("test-buildpack")
20+
.command("test-command")
21+
.disk(512)
22+
.healthCheckHttpEndpoint("test-health-check-http-endpoint")
23+
.instances(2)
24+
.memory(512)
25+
.randomRoute(true)
26+
.stack("test-stack")
27+
.timeout(120)
28+
.environmentVariable("TEST_KEY_1", "test-value-1")
29+
.processe(
30+
ManifestV3Process.builder()
31+
.type("web")
32+
.command("test-command-1")
33+
.readinessHealthCheckType(
34+
ReadinessHealthCheckType.HTTP)
35+
.readinessHealthCheckHttpEndpoint(
36+
"test-readiness-health-check-http-endpoint")
37+
.readinessHealthCheckInvocationTimeout(120)
38+
.build())
39+
.service(
40+
ManifestV3Service.builder()
41+
.name("test-service-1")
42+
.build())
43+
.build())
44+
.build();
45+
46+
assertSerializeDeserialize(manifest);
47+
}
48+
49+
@Test
50+
void testWithDockerApp() throws IOException {
51+
ManifestV3 manifest =
52+
ManifestV3.builder()
53+
.application(
54+
ManifestV3Application.builder()
55+
.name("test-app")
56+
.docker(Docker.builder().image("test-image").build())
57+
.build())
58+
.build();
59+
60+
assertSerializeDeserialize(manifest);
61+
}
62+
63+
private void assertSerializeDeserialize(ManifestV3 manifest) throws IOException {
64+
Path file = Files.createTempFile("test-manifest-", ".yml");
65+
ApplicationManifestUtilsV3.write(file, manifest);
66+
ManifestV3 read = ApplicationManifestUtilsV3.read(file);
67+
68+
assertEquals(manifest, read);
69+
}
70+
}

0 commit comments

Comments
 (0)