Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit 93d7535

Browse files
committed
More fixes to support jackson 2
- adjust BrooklynJacksonSerializer to use jackson 2 api - fix web.xml for rest-api and rest-client
1 parent 151ec2f commit 93d7535

File tree

13 files changed

+138
-146
lines changed

13 files changed

+138
-146
lines changed

brooklyn-server/parent/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@
198198
<artifactId>jackson-module-jaxb-annotations</artifactId>
199199
<version>${fasterxml.jackson.version}</version>
200200
</dependency>
201+
<dependency>
202+
<groupId>com.fasterxml.jackson.datatype</groupId>
203+
<artifactId>jackson-datatype-guava</artifactId>
204+
<version>${fasterxml.jackson.version}</version>
205+
</dependency>
201206
<dependency>
202207
<groupId>io.swagger</groupId>
203208
<artifactId>swagger-annotations</artifactId>

brooklyn-server/rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/ApplicationApi.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.brooklyn.rest.domain.ApplicationSpec;
3939
import org.apache.brooklyn.rest.domain.ApplicationSummary;
4040
import org.apache.brooklyn.rest.domain.EntitySummary;
41+
import org.apache.brooklyn.rest.domain.EntityDetail;
4142

4243
import io.swagger.annotations.ApiResponse;
4344
import io.swagger.annotations.ApiResponses;
@@ -55,7 +56,7 @@ public interface ApplicationApi {
5556
@ApiOperation(
5657
value = "Fetch display details for all applications and optionally selected additional entities"
5758
)
58-
public List<EntitySummary> fetch(
59+
public List<EntityDetail> fetch(
5960
@ApiParam(value="Selected additional entity ID's to include, comma-separated", required=false)
6061
@DefaultValue("")
6162
@QueryParam("items") String items);

brooklyn-server/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/EntityDetail.java

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import java.util.Map;
2323
import java.util.Objects;
2424

25+
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
26+
2527
import com.fasterxml.jackson.annotation.JsonProperty;
2628
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2729
import com.google.common.collect.ImmutableList;
28-
import com.google.common.collect.ImmutableMap;
2930

3031
public class EntityDetail extends EntitySummary {
3132

@@ -35,22 +36,25 @@ public class EntityDetail extends EntitySummary {
3536
@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
3637
private final List<EntitySummary> children;
3738
private final List<String> groupIds;
38-
private final Map<String, String> members;
39+
private final List<Map<String, String>> members;
3940

4041
public EntityDetail(
4142
@JsonProperty("id") String id,
4243
@JsonProperty("parentId") String parentId,
4344
@JsonProperty("name") String name,
4445
@JsonProperty("type") String type,
46+
@JsonProperty("serviceUp") Boolean serviceUp,
47+
@JsonProperty("serviceState") Lifecycle serviceState,
48+
@JsonProperty("iconUrl") String iconUrl,
4549
@JsonProperty("catalogItemId") String catalogItemId,
4650
@JsonProperty("children") List<EntitySummary> children,
4751
@JsonProperty("groupIds") List<String> groupIds,
48-
@JsonProperty("members") Map<String, String> members) {
52+
@JsonProperty("members") List<Map<String, String>> members) {
4953
super(id, name, type, catalogItemId, null);
5054
this.parentId = parentId;
5155
this.children = (children == null) ? ImmutableList.<EntitySummary>of() : ImmutableList.copyOf(children);
5256
this.groupIds = (groupIds == null) ? ImmutableList.<String>of() : ImmutableList.copyOf(groupIds);
53-
this.members = (members == null) ? ImmutableMap.<String,String> of() : ImmutableMap.copyOf(members);
57+
this.members = (members == null) ? ImmutableList.<Map<String,String>>of() : ImmutableList.copyOf(members);
5458
}
5559

5660
public static long getSerialVersionUID() {
@@ -69,34 +73,8 @@ public List<String> getGroupIds() {
6973
return groupIds;
7074
}
7175

72-
public Map<String, String> getMembers() {
76+
public List<Map<String, String>> getMembers() {
7377
return members;
7478
}
7579

76-
@Override
77-
public boolean equals(Object o) {
78-
if (this == o) return true;
79-
if (!(o instanceof EntityDetail)) return false;
80-
if (!super.equals(o)) return false;
81-
EntityDetail that = (EntityDetail) o;
82-
return Objects.equals(parentId, that.parentId) &&
83-
Objects.equals(children, that.children) &&
84-
Objects.equals(groupIds, that.groupIds) &&
85-
Objects.equals(members, that.members);
86-
}
87-
88-
@Override
89-
public int hashCode() {
90-
return Objects.hash(super.hashCode(), parentId, children, groupIds, members);
91-
}
92-
93-
@Override
94-
public String toString() {
95-
return "EntityDetail{" +
96-
"parentId='" + parentId + '\'' +
97-
", children=" + children +
98-
", groupIds=" + groupIds +
99-
", members=" + members +
100-
'}';
101-
}
10280
}

brooklyn-server/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/TaskSummary.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public class TaskSummary implements HasId, Serializable {
5252

5353
private final String currentStatus;
5454
private final Object result;
55-
private final boolean isError;
56-
private final boolean isCancelled;
55+
private final boolean error;
56+
private final boolean cancelled;
5757

5858
private final List<LinkWithMetadata> children;
5959
private final LinkWithMetadata submittedByTask;
@@ -82,8 +82,8 @@ public TaskSummary(
8282
@JsonProperty("endTimeUtc") Long endTimeUtc,
8383
@JsonProperty("currentStatus") String currentStatus,
8484
@JsonProperty("result") Object result,
85-
@JsonProperty("isError") boolean isError,
86-
@JsonProperty("isCancelled") boolean isCancelled,
85+
@JsonProperty("error") boolean error,
86+
@JsonProperty("cancelled") boolean cancelled,
8787
@JsonProperty("children") List<LinkWithMetadata> children,
8888
@JsonProperty("submittedByTask") LinkWithMetadata submittedByTask,
8989
@JsonProperty("blockingTask") LinkWithMetadata blockingTask,
@@ -102,8 +102,8 @@ public TaskSummary(
102102
this.endTimeUtc = endTimeUtc;
103103
this.currentStatus = currentStatus;
104104
this.result = result;
105-
this.isError = isError;
106-
this.isCancelled = isCancelled;
105+
this.error = error;
106+
this.cancelled = cancelled;
107107
this.children = children;
108108
this.blockingDetails = blockingDetails;
109109
this.blockingTask = blockingTask;
@@ -168,26 +168,26 @@ public Object getResult() {
168168
return result;
169169
}
170170

171-
/** @deprecated since 0.7.0 use {@link #isError} instead. */
171+
/** @deprecated since 0.7.0 use {@link #error} instead. */
172172
@Deprecated
173173
@JsonIgnore
174174
public boolean getIsError() {
175-
return isError;
175+
return error;
176176
}
177177

178-
/** @deprecated since 0.7.0 use {@link #isCancelled} instead. */
178+
/** @deprecated since 0.7.0 use {@link #cancelled} instead. */
179179
@Deprecated
180180
@JsonIgnore
181181
public boolean getIsCancelled() {
182-
return isCancelled;
182+
return cancelled;
183183
}
184184

185185
public boolean isError() {
186-
return isError;
186+
return error;
187187
}
188188

189189
public boolean isCancelled() {
190-
return isCancelled;
190+
return cancelled;
191191
}
192192

193193
public List<LinkWithMetadata> getChildren() {
@@ -223,8 +223,8 @@ public boolean equals(Object o) {
223223
if (this == o) return true;
224224
if (!(o instanceof TaskSummary)) return false;
225225
TaskSummary that = (TaskSummary) o;
226-
return isError == that.isError &&
227-
isCancelled == that.isCancelled &&
226+
return error == that.error &&
227+
cancelled == that.cancelled &&
228228
Objects.equals(id, that.id) &&
229229
Objects.equals(displayName, that.displayName) &&
230230
Objects.equals(entityId, that.entityId) &&
@@ -247,7 +247,7 @@ public boolean equals(Object o) {
247247

248248
@Override
249249
public int hashCode() {
250-
return Objects.hash(id, displayName, entityId, entityDisplayName, description, tags, submitTimeUtc, startTimeUtc, endTimeUtc, currentStatus, result, isError, isCancelled, children, submittedByTask, blockingTask, blockingDetails, detailedStatus, streams, links);
250+
return Objects.hash(id, displayName, entityId, entityDisplayName, description, tags, submitTimeUtc, startTimeUtc, endTimeUtc, currentStatus, result, error, cancelled, children, submittedByTask, blockingTask, blockingDetails, detailedStatus, streams, links);
251251
}
252252

253253
@Override
@@ -264,8 +264,8 @@ public String toString() {
264264
", endTimeUtc=" + endTimeUtc +
265265
", currentStatus='" + currentStatus + '\'' +
266266
", result=" + result +
267-
", isError=" + isError +
268-
", isCancelled=" + isCancelled +
267+
", error=" + error +
268+
", cancelled=" + cancelled +
269269
", children=" + children +
270270
", submittedByTask=" + submittedByTask +
271271
", blockingTask=" + blockingTask +

brooklyn-server/rest/rest-api/src/main/webapp/WEB-INF/web.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@
8383
<!-- load our REST API jersey resources -->
8484
<init-param>
8585
<param-name>com.sun.jersey.config.property.packages</param-name>
86-
<param-value>io.swagger.jaxrs.listing;org.codehaus.jackson.jaxrs;org.apache.brooklyn.rest.resources;org.apache.brooklyn.rest.util</param-value>
86+
<param-value>io.swagger.jaxrs.listing;com.fasterxml.jackson.jaxrs;org.apache.brooklyn.rest.resources;org.apache.brooklyn.rest.util</param-value>
8787
</init-param>
8888

8989
<!-- install Jackson and turn on pojo/json serialization (could add org.codehaus.jackson.jaxrs
9090
above but seems cleaner to pull in just the class -->
9191
<init-param>
9292
<param-name>com.sun.jersey.config.property.classnames</param-name>
93-
<param-value>org.codehaus.jackson.jaxrs.JacksonJsonProvider</param-value>
93+
<param-value>com.fasterxml.jackson.jaxrs.JacksonJsonProvider</param-value>
9494
</init-param>
9595
<init-param>
9696
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>

brooklyn-server/rest/rest-client/src/test/webapp/WEB-INF/web.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<param-value>
8585
org.apache.brooklyn.rest.apidoc.ApidocHelpMessageBodyWriter;
8686
org.apache.brooklyn.rest.util.FormMapProvider;
87-
org.codehaus.jackson.jaxrs.JacksonJsonProvider;
87+
com.fasterxml.jackson.jaxrs.JacksonJsonProvider;
8888
org.apache.brooklyn.rest.resources.ActivityResource;
8989
org.apache.brooklyn.rest.resources.ApidocResource;
9090
org.apache.brooklyn.rest.resources.ApplicationResource;

brooklyn-server/rest/rest-server/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@
9797
<dependency>
9898
<groupId>com.fasterxml.jackson.datatype</groupId>
9999
<artifactId>jackson-datatype-guava</artifactId>
100-
<version>${fasterxml.jackson.version}</version>
100+
</dependency>
101+
<dependency>
102+
<groupId>com.fasterxml.jackson.jaxrs</groupId>
103+
<artifactId>jackson-jaxrs-json-provider</artifactId>
101104
</dependency>
102105
<dependency>
103106
<groupId>com.sun.jersey</groupId>

brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/resources/ApplicationResource.java

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.net.URI;
2727
import java.net.URISyntaxException;
28+
import java.util.Collection;
2829
import java.util.Collections;
2930
import java.util.Iterator;
3031
import java.util.List;
@@ -38,6 +39,7 @@
3839
import org.apache.brooklyn.api.entity.Application;
3940
import org.apache.brooklyn.api.entity.Entity;
4041
import org.apache.brooklyn.api.entity.EntitySpec;
42+
import org.apache.brooklyn.api.entity.Group;
4143
import org.apache.brooklyn.api.location.Location;
4244
import org.apache.brooklyn.api.mgmt.Task;
4345
import org.apache.brooklyn.api.objs.BrooklynObject;
@@ -58,9 +60,11 @@
5860
import org.apache.brooklyn.core.sensor.Sensors;
5961
import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
6062
import org.apache.brooklyn.core.typereg.RegisteredTypes;
63+
import org.apache.brooklyn.entity.group.AbstractGroup;
6164
import org.apache.brooklyn.rest.api.ApplicationApi;
6265
import org.apache.brooklyn.rest.domain.ApplicationSpec;
6366
import org.apache.brooklyn.rest.domain.ApplicationSummary;
67+
import org.apache.brooklyn.rest.domain.EntityDetail;
6468
import org.apache.brooklyn.rest.domain.EntitySummary;
6569
import org.apache.brooklyn.rest.domain.TaskSummary;
6670
import org.apache.brooklyn.rest.filter.HaHotStateRequired;
@@ -79,11 +83,9 @@
7983
import org.slf4j.Logger;
8084
import org.slf4j.LoggerFactory;
8185

82-
import com.fasterxml.jackson.databind.JsonNode;
83-
import com.fasterxml.jackson.databind.node.ArrayNode;
84-
import com.fasterxml.jackson.databind.node.ObjectNode;
8586
import com.google.common.base.Throwables;
8687
import com.google.common.collect.FluentIterable;
88+
import com.google.common.collect.ImmutableMap;
8789
import com.google.common.collect.Iterables;
8890
import com.google.common.collect.Lists;
8991

@@ -95,67 +97,88 @@ public class ApplicationResource extends AbstractBrooklynRestResource implements
9597
@Context
9698
private UriInfo uriInfo;
9799

98-
private ObjectNode entityBase(Entity entity) {
99-
ObjectNode aRoot = mapper().createObjectNode();
100-
aRoot.put("name", entity.getDisplayName());
101-
aRoot.put("id", entity.getId());
102-
aRoot.put("type", entity.getEntityType().getName());
103-
100+
private EntityDetail fromEntity(Entity entity) {
104101
Boolean serviceUp = entity.getAttribute(Attributes.SERVICE_UP);
105-
if (serviceUp!=null) aRoot.put("serviceUp", serviceUp);
106102

107103
Lifecycle serviceState = entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
108-
if (serviceState!=null) aRoot.put("serviceState", serviceState.toString());
109104

110105
String iconUrl = entity.getIconUrl();
111106
if (iconUrl!=null) {
112107
if (brooklyn().isUrlServerSideAndSafe(iconUrl))
113108
// route to server if it is a server-side url
114109
iconUrl = EntityTransformer.entityUri(entity)+"/icon";
115-
aRoot.put("iconUrl", iconUrl);
116110
}
117111

118-
return aRoot;
119-
}
112+
List<EntitySummary> children = Lists.newArrayList();
113+
if (!entity.getChildren().isEmpty()) {
114+
for (Entity child : entity.getChildren()) {
115+
children.add(fromEntity(child));
116+
}
117+
}
120118

121-
private JsonNode recursiveTreeFromEntity(Entity entity) {
122-
ObjectNode aRoot = entityBase(entity);
119+
String parentId = null;
120+
if (entity.getParent()!= null) {
121+
parentId = entity.getParent().getId();
122+
}
123+
124+
List<String> groupIds = Lists.newArrayList();
125+
if (!entity.groups().isEmpty()) {
126+
groupIds.addAll(entitiesIdAsArray(entity.groups()));
127+
}
123128

124-
if (!entity.getChildren().isEmpty())
125-
aRoot.put("children", childEntitiesRecursiveAsArray(entity));
129+
List<Map<String, String>> members = Lists.newArrayList();
130+
if (entity instanceof Group) {
131+
// use attribute instead of method in case it is read-only
132+
Collection<Entity> memberEntities = entity.getAttribute(AbstractGroup.GROUP_MEMBERS);
133+
if (memberEntities != null && !memberEntities.isEmpty())
134+
members.addAll(entitiesIdAndNameAsList(memberEntities));
135+
}
126136

127-
return aRoot;
137+
return new EntityDetail(entity.getId(), parentId, entity.getDisplayName(),
138+
entity.getEntityType().getName(), serviceUp, serviceState, iconUrl, entity.getCatalogItemId(),
139+
children, groupIds, members);
128140
}
129141

130-
private ArrayNode childEntitiesRecursiveAsArray(Entity entity) {
131-
ArrayNode node = mapper().createArrayNode();
132-
for (Entity e : entity.getChildren()) {
142+
private List<Map<String, String>> entitiesIdAndNameAsList(Collection<? extends Entity> entities) {
143+
List<Map<String, String>> members = Lists.newArrayList();
144+
for (Entity entity : entities) {
133145
if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
134-
node.add(recursiveTreeFromEntity(e));
146+
members.add(ImmutableMap.of("id", entity.getId(), "name", entity.getDisplayName()));
135147
}
136148
}
137-
return node;
149+
return members;
150+
}
151+
152+
private List<String> entitiesIdAsArray(Iterable<? extends Entity> entities) {
153+
List<String> ids = Lists.newArrayList();
154+
for (Entity entity : entities) {
155+
if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
156+
ids.add(entity.getId());
157+
}
158+
}
159+
return ids;
138160
}
139161

140162
@Override
141-
public List<EntitySummary> fetch(String entityIds) {
142-
List<EntitySummary> result = Lists.newArrayList();
143-
for (Application application : mgmt().getApplications()) {
144-
result.add(EntityTransformer.entitySummary(application));
163+
public List<EntityDetail> fetch(String entityIds) {
164+
165+
List<EntityDetail> entitySummaries = Lists.newArrayList();
166+
for (Entity application : mgmt().getApplications()) {
167+
entitySummaries.add(fromEntity(application));
145168
}
146169

147170
if (entityIds != null) {
148171
for (String entityId: entityIds.split(",")) {
149172
Entity entity = mgmt().getEntityManager().getEntity(entityId.trim());
150173
while (entity != null && entity.getParent() != null) {
151174
if (Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) {
152-
result.add(EntityTransformer.entitySummary(entity));
175+
entitySummaries.add(fromEntity(entity));
153176
}
154177
entity = entity.getParent();
155178
}
156179
}
157180
}
158-
return result;
181+
return entitySummaries;
159182
}
160183

161184
@Override

0 commit comments

Comments
 (0)