INT-3967: Add contentDescriptor to Object Model

JIRA: https://jira.spring.io/browse/INT-3967

Polishing

Polishing

Polishing - remove componentName
This commit is contained in:
Gary Russell
2016-04-22 16:34:42 -04:00
committed by Artem Bilan
parent 439559f255
commit 2370296b95
6 changed files with 54 additions and 13 deletions

View File

@@ -261,6 +261,12 @@ subprojects { subproject ->
archives javadocJar
}
jar {
manifest {
attributes('Implementation-Version': version)
}
}
build.dependsOn jacocoTestReport
}

View File

@@ -17,6 +17,7 @@
package org.springframework.integration.support.management.graph;
import java.util.Collection;
import java.util.Map;
/**
* This object can be exposed, for example, as a JSON object over
@@ -29,15 +30,22 @@ import java.util.Collection;
*/
public class Graph {
private final Map<String, Object> contentDescriptor;
private final Collection<IntegrationNode> nodes;
private final Collection<LinkNode> links;
public Graph(Collection<IntegrationNode> nodes, Collection<LinkNode> links) {
public Graph(Map<String, Object> descriptor, Collection<IntegrationNode> nodes, Collection<LinkNode> links) {
this.contentDescriptor = descriptor;
this.nodes = nodes;
this.links = links;
}
public Map<String, Object> getContentDescriptor() {
return this.contentDescriptor;
}
public Collection<IntegrationNode> getNodes() {
return this.nodes;
}

View File

@@ -43,17 +43,31 @@ import org.springframework.messaging.MessageChannel;
*/
public class IntegrationGraphServer implements ApplicationContextAware, ApplicationListener<ContextRefreshedEvent> {
private static final float GRAPH_VERSION = 1.0f;
private final NodeFactory nodeFactory = new NodeFactory();
private ApplicationContext applicationContext;
private Graph graph;
private String applicationName;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/**
* Set the application name that will appear in the 'contentDescriptor' under
* the 'name' key. If not provided, the property 'spring.application.name' from
* the application context environment will be used (if present).
* @param applicationName the application name.
*/
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
/**
* Return the cached graph. Although the graph is cached, the data therein (stats
* etc.) are dynamic.
@@ -79,6 +93,21 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
}
private synchronized Graph buildGraph() {
String implementationVersion = IntegrationGraphServer.class.getPackage().getImplementationVersion();
if (implementationVersion == null) {
implementationVersion = "unknown - is Spring Integration running from the distribution jar?";
}
Map<String, Object> descriptor = new HashMap<String, Object>();
descriptor.put("provider", "spring-integration");
descriptor.put("providerVersion", implementationVersion);
descriptor.put("providerFormatVersion", GRAPH_VERSION);
String name = this.applicationName;
if (name == null) {
name = this.applicationContext.getEnvironment().getProperty("spring.application.name");
}
if (name != null) {
descriptor.put("name", name);
}
this.nodeFactory.reset();
Collection<IntegrationNode> nodes = new ArrayList<IntegrationNode>();
Collection<LinkNode> links = new ArrayList<LinkNode>();
@@ -87,7 +116,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat
gateways(nodes, links, channelNodes);
producers(nodes, links, channelNodes);
consumers(nodes, links, channelNodes);
this.graph = new Graph(nodes, links);
this.graph = new Graph(descriptor, nodes, links);
return this.graph;
}

View File

@@ -35,15 +35,11 @@ public abstract class IntegrationNode {
private final String componentType;
private final String componentName;
protected IntegrationNode(int nodeId, String name, Object nodeObject, Stats stats) {
this.nodeId = nodeId;
this.name = name;
this.componentType = nodeObject instanceof NamedComponent ? ((NamedComponent) nodeObject).getComponentType()
: nodeObject.getClass().getSimpleName();
this.componentName = nodeObject instanceof NamedComponent ? ((NamedComponent) nodeObject).getComponentName()
: nodeObject.toString();
this.stats = stats;
}
@@ -59,10 +55,6 @@ public abstract class IntegrationNode {
return this.componentType;
}
public String getComponentName() {
return this.componentName;
}
public Stats getStats() {
return this.stats.isAvailable() ? this.stats : null;
}

View File

@@ -70,7 +70,7 @@ public class IntegrationGraphServerTests {
objectMapper.writeValue(baos, graph);
// System . out . println(new String(baos.toByteArray()));
Map<?, ?> map = objectMapper.readValue(baos.toByteArray(), Map.class);
assertThat(map.size(), is(equalTo(2)));
assertThat(map.size(), is(equalTo(3)));
@SuppressWarnings("unchecked")
List<Map<?, ?>> nodes = (List<Map<?, ?>>) map.get("nodes");
assertThat(nodes, is(notNullValue()));
@@ -87,8 +87,10 @@ public class IntegrationGraphServerTests {
public static class Config {
@Bean
public IntegrationGraphServer builder() {
return new IntegrationGraphServer();
public IntegrationGraphServer server() {
IntegrationGraphServer server = new IntegrationGraphServer();
server.setApplicationName("myAppName:1.0");
return server;
}
@Bean

View File

@@ -44,6 +44,7 @@ import org.springframework.integration.http.config.EnableIntegrationGraphControl
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
@@ -63,6 +64,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@WebAppConfiguration
@TestPropertySource(properties = "spring.application.name:testApplication")
public class IntegrationGraphControllerTests {
@Autowired
@@ -86,6 +88,8 @@ public class IntegrationGraphControllerTests {
.andExpect(jsonPath("$.nodes..name")
.value(Matchers.containsInAnyOrder("nullChannel", "errorChannel",
"_org.springframework.integration.errorLogger")))
// .andDo(print())
.andExpect(jsonPath("$.contentDescriptor.name").value("testApplication"))
.andExpect(jsonPath("$.links").exists());
}