Skip to content

Commit 02c74f9

Browse files
committed
Support Manifest YAML Anchors and References
Previously the YAML deserialization utilized Jackson YAML support. Unfortunately, this support does not properly handle scalar-value level anchors and references. This change updates the code to make use of SnakeYAML directly, which while resulting in worse code, does have the advantage of supporting scalar-value level anchors and references. [resolves #834]
1 parent d5813f9 commit 02c74f9

File tree

7 files changed

+176
-114
lines changed

7 files changed

+176
-114
lines changed

cloudfoundry-operations/cloudfoundry-operations.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
<orderEntry type="library" scope="PROVIDED" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
1717
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.10" level="project" />
1818
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.10" level="project" />
19-
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.10" level="project" />
20-
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
2119
<orderEntry type="library" scope="TEST" name="Maven: io.projectreactor.addons:reactor-test:3.0.7.RELEASE" level="project" />
2220
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:3.0.7.RELEASE" level="project" />
2321
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.1" level="project" />
@@ -41,5 +39,6 @@
4139
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:jcl-over-slf4j:1.7.25" level="project" />
4240
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
4341
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
42+
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
4443
</component>
4544
</module>

cloudfoundry-operations/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
<groupId>com.fasterxml.jackson.core</groupId>
4444
<artifactId>jackson-databind</artifactId>
4545
</dependency>
46-
<dependency>
47-
<groupId>com.fasterxml.jackson.dataformat</groupId>
48-
<artifactId>jackson-dataformat-yaml</artifactId>
49-
</dependency>
5046
<dependency>
5147
<groupId>io.projectreactor.addons</groupId>
5248
<artifactId>reactor-test</artifactId>
@@ -91,6 +87,10 @@
9187
<artifactId>spring-boot-starter-logging</artifactId>
9288
<scope>test</scope>
9389
</dependency>
90+
<dependency>
91+
<groupId>org.yaml</groupId>
92+
<artifactId>snakeyaml</artifactId>
93+
</dependency>
9494
</dependencies>
9595

9696
<build>

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

Lines changed: 149 additions & 84 deletions
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.cloudfoundry.operations.applications;
1818

1919

20-
import com.fasterxml.jackson.annotation.JsonProperty;
2120
import org.cloudfoundry.AllowNulls;
2221
import org.cloudfoundry.Nullable;
2322
import org.immutables.value.Value;
@@ -67,147 +66,126 @@ void check() {
6766
/**
6867
* The buildpack used by the application
6968
*/
70-
@JsonProperty("buildpack")
7169
@Nullable
7270
abstract String getBuildpack();
7371

7472
/**
7573
* The command used to execute the application
7674
*/
77-
@JsonProperty("command")
7875
@Nullable
7976
abstract String getCommand();
8077

8178
/**
8279
* The disk quota in megabytes
8380
*/
84-
@JsonProperty("disk_quota")
8581
@Nullable
8682
abstract Integer getDisk();
8783

8884
/**
8985
* The docker information
9086
*/
91-
@JsonProperty("docker")
9287
@Nullable
9388
abstract Docker getDocker();
9489

9590
/**
9691
* The collection of domains bound to the application
9792
*/
98-
@JsonProperty("domains")
9993
@Nullable
10094
abstract List<String> getDomains();
10195

10296
/**
10397
* The environment variables to set on the application
10498
*/
10599
@AllowNulls
106-
@JsonProperty("env")
107100
@Nullable
108101
abstract Map<String, Object> getEnvironmentVariables();
109102

110103
/**
111104
* The HTTP health check endpoint
112105
*/
113-
@JsonProperty("health-check-http-endpoint")
114106
@Nullable
115107
abstract String getHealthCheckHttpEndpoint();
116108

117109
/**
118110
* The health check type
119111
*/
120-
@JsonProperty("health-check-type")
121112
@Nullable
122113
abstract ApplicationHealthCheck getHealthCheckType();
123114

124115
/**
125116
* The collection of hosts bound to the application
126117
*/
127-
@JsonProperty("hosts")
128118
@Nullable
129119
abstract List<String> getHosts();
130120

131121
/**
132122
* The number of instances of the application
133123
*/
134-
@JsonProperty("instances")
135124
@Nullable
136125
abstract Integer getInstances();
137126

138127
/**
139128
* The memory quota in megabytes
140129
*/
141-
@JsonProperty("memory")
142130
@Nullable
143131
abstract Integer getMemory();
144132

145133
/**
146134
* The name of the application
147135
*/
148-
@JsonProperty("name")
149136
abstract String getName();
150137

151138
/**
152139
* Map the the root domain to the app
153140
*/
154-
@JsonProperty("no-hostname")
155141
@Nullable
156142
abstract Boolean getNoHostname();
157143

158144
/**
159145
* Prevent a route being created for the app
160146
*/
161-
@JsonProperty("no-route")
162147
@Nullable
163148
abstract Boolean getNoRoute();
164149

165150
/**
166151
* The location of the application
167152
*/
168-
@JsonProperty("path")
169153
@Nullable
170154
abstract Path getPath();
171155

172156
/**
173157
* Generate a random route
174158
*/
175-
@JsonProperty("random-route")
176159
@Nullable
177160
abstract Boolean getRandomRoute();
178161

179162
/**
180163
* The route path for all applications
181164
*/
182-
@JsonProperty("route-path")
183165
@Nullable
184166
abstract String getRoutePath();
185167

186168
/**
187169
* The collection of routes bound to the application
188170
*/
189-
@JsonProperty("routes")
190171
@Nullable
191172
abstract List<Route> getRoutes();
192173

193174
/**
194175
* The collection of service names bound to the application
195176
*/
196-
@JsonProperty("services")
197177
@Nullable
198178
abstract List<String> getServices();
199179

200180
/**
201181
* The stack used to run the application
202182
*/
203-
@JsonProperty("stack")
204183
@Nullable
205184
abstract String getStack();
206185

207186
/**
208187
* The number of seconds allowed for application start
209188
*/
210-
@JsonProperty("timeout")
211189
@Nullable
212190
abstract Integer getTimeout();
213191

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@
3333

3434
public final class ApplicationManifestUtilsTest {
3535

36+
@Test
37+
public void anchorsAndReferences() throws IOException {
38+
List<ApplicationManifest> expected = Collections.singletonList(
39+
ApplicationManifest.builder()
40+
.name("test-application")
41+
.service("test-service-name")
42+
.build());
43+
44+
List<ApplicationManifest> actual = ApplicationManifestUtils.read(new ClassPathResource("fixtures/manifest-kilo.yml").getFile().toPath());
45+
46+
assertThat(actual).isEqualTo(expected);
47+
}
48+
3649
@Test
3750
public void read() throws IOException {
3851
List<ApplicationManifest> expected = Arrays.asList(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
holder:
3+
- &foo test-service-name
4+
5+
applications:
6+
- name: test-application
7+
services:
8+
- *foo

integration-test/integration-test.iml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-core:4.3.11.RELEASE" level="project" />
5252
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-web:4.3.11.RELEASE" level="project" />
5353
<orderEntry type="module" module-name="cloudfoundry-operations" scope="TEST" />
54-
<orderEntry type="library" scope="TEST" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.10" level="project" />
54+
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
5555
<orderEntry type="module" module-name="cloudfoundry-util" scope="TEST" />
5656
<orderEntry type="library" scope="TEST" name="Maven: org.atteo:evo-inflector:1.2.2" level="project" />
5757
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter:1.5.7.RELEASE" level="project" />
@@ -66,7 +66,6 @@
6666
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-core:1.1.11" level="project" />
6767
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
6868
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
69-
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
7069
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:1.5.7.RELEASE" level="project" />
7170
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:1.5.7.RELEASE" level="project" />
7271
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:1.5.7.RELEASE" level="project" />

0 commit comments

Comments
 (0)