Updates bus endpoints to use new boot @Endpoint infrastructure.
This commit is contained in:
@@ -20,14 +20,13 @@ package org.springframework.cloud.bus;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.trace.TraceRepository;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.bus.endpoint.BusEndpoint;
|
||||
import org.springframework.cloud.bus.endpoint.EnvironmentBusEndpoint;
|
||||
import org.springframework.cloud.bus.endpoint.RefreshBusEndpoint;
|
||||
import org.springframework.cloud.bus.event.AckRemoteApplicationEvent;
|
||||
@@ -176,15 +175,6 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(Endpoint.class)
|
||||
protected static class BusEndpointConfiguration {
|
||||
@Bean
|
||||
public BusEndpoint busEndpoint() {
|
||||
return new BusEndpoint();
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass({ Endpoint.class, RefreshScope.class })
|
||||
@ConditionalOnBean(ContextRefresher.class)
|
||||
@@ -200,9 +190,8 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
||||
@ConditionalOnProperty(value = "endpoints.spring.cloud.bus.refresh.enabled", matchIfMissing = true)
|
||||
protected static class BusRefreshEndpointConfiguration {
|
||||
@Bean
|
||||
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context,
|
||||
BusEndpoint busEndpoint) {
|
||||
return new RefreshBusEndpoint(context, context.getId(), busEndpoint);
|
||||
public RefreshBusEndpoint refreshBusEndpoint(ApplicationContext context) {
|
||||
return new RefreshBusEndpoint(context, context.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,8 +227,8 @@ public class BusAutoConfiguration implements ApplicationEventPublisherAware {
|
||||
protected static class EnvironmentBusEndpointConfiguration {
|
||||
@Bean
|
||||
public EnvironmentBusEndpoint environmentBusEndpoint(
|
||||
ApplicationContext context, BusEndpoint busEndpoint) {
|
||||
return new EnvironmentBusEndpoint(context, context.getId(), busEndpoint);
|
||||
ApplicationContext context) {
|
||||
return new EnvironmentBusEndpoint(context, context.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,27 +17,21 @@
|
||||
|
||||
package org.springframework.cloud.bus.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
public class AbstractBusEndpoint implements MvcEndpoint {
|
||||
public class AbstractBusEndpoint {
|
||||
|
||||
private ApplicationEventPublisher context;
|
||||
|
||||
private BusEndpoint delegate;
|
||||
|
||||
private String appId;
|
||||
|
||||
public AbstractBusEndpoint(ApplicationEventPublisher context, String appId,
|
||||
BusEndpoint busEndpoint) {
|
||||
public AbstractBusEndpoint(ApplicationEventPublisher context, String appId) {
|
||||
this.context = context;
|
||||
this.appId = appId;
|
||||
this.delegate = busEndpoint;
|
||||
}
|
||||
|
||||
protected String getInstanceId() {
|
||||
@@ -48,19 +42,4 @@ public class AbstractBusEndpoint implements MvcEndpoint {
|
||||
context.publishEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return "/" + this.delegate.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSensitive() {
|
||||
return this.delegate.isSensitive();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Class<? extends Endpoint> getEndpointType() {
|
||||
return this.delegate.getClass();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.bus.endpoint;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "endpoints.bus", ignoreUnknownFields = false)
|
||||
public class BusEndpoint extends AbstractEndpoint<Collection<String>> {
|
||||
|
||||
public BusEndpoint() {
|
||||
super("bus");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> invoke() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -17,36 +17,37 @@
|
||||
|
||||
package org.springframework.cloud.bus.endpoint;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
|
||||
import org.springframework.cloud.bus.event.EnvironmentChangeRemoteApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ManagedResource
|
||||
@Endpoint(id = "bus-env") //TODO: document
|
||||
public class EnvironmentBusEndpoint extends AbstractBusEndpoint {
|
||||
|
||||
public EnvironmentBusEndpoint(ApplicationEventPublisher context, String id,
|
||||
BusEndpoint delegate) {
|
||||
super(context, id, delegate);
|
||||
public EnvironmentBusEndpoint(ApplicationEventPublisher context, String id) {
|
||||
super(context, id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "env", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@ManagedOperation
|
||||
// TODO: make this an abstract method in AbstractBusEndpoint?
|
||||
public void env(@RequestParam Map<String, String> params,
|
||||
@RequestParam(value = "destination", required = false) String destination) {
|
||||
@WriteOperation
|
||||
public void env(String name, String value, @Selector String destination) { //TODO: document params
|
||||
Map<String, String> params = Collections.singletonMap(name, value);
|
||||
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(),
|
||||
destination, params));
|
||||
}
|
||||
|
||||
@WriteOperation
|
||||
public void env(String name, String value) { //TODO: document params
|
||||
Map<String, String> params = Collections.singletonMap(name, value);
|
||||
publish(new EnvironmentChangeRemoteApplicationEvent(this, getInstanceId(),
|
||||
null, params));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,32 +17,30 @@
|
||||
|
||||
package org.springframework.cloud.bus.endpoint;
|
||||
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.Selector;
|
||||
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
|
||||
import org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.jmx.export.annotation.ManagedOperation;
|
||||
import org.springframework.jmx.export.annotation.ManagedResource;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* @author Spencer Gibb
|
||||
*/
|
||||
@ManagedResource
|
||||
@Endpoint(id = "bus-refresh") //TODO: document new id
|
||||
public class RefreshBusEndpoint extends AbstractBusEndpoint {
|
||||
|
||||
public RefreshBusEndpoint(ApplicationEventPublisher context, String id,
|
||||
BusEndpoint delegate) {
|
||||
super(context, id, delegate);
|
||||
public RefreshBusEndpoint(ApplicationEventPublisher context, String id) {
|
||||
super(context, id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "refresh", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
@ManagedOperation
|
||||
public void refresh(
|
||||
@RequestParam(value = "destination", required = false) String destination) {
|
||||
@WriteOperation
|
||||
public void refresh(@Selector String destination) { //TODO: document destination
|
||||
publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), destination));
|
||||
}
|
||||
|
||||
@WriteOperation
|
||||
public void refresh() {
|
||||
publish(new RefreshRemoteApplicationEvent(this, getInstanceId(), null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class BusAutoConfigurationTests {
|
||||
OutboundMessageHandlerConfiguration outbound = this.context
|
||||
.getBean(OutboundMessageHandlerConfiguration.class);
|
||||
outbound.latch.await(2000L, TimeUnit.MILLISECONDS);
|
||||
String message = (String) outbound.message.getPayload();
|
||||
String message = new String((byte[]) outbound.message.getPayload()); //FIXME: byte[] vs string
|
||||
assertTrue("Wrong ackId: " + message,
|
||||
message.contains("\"ackId\":\"" + refresh.getId()));
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ public class RefreshBusEndpointTests {
|
||||
|
||||
@Test
|
||||
public void instanceId() throws Exception {
|
||||
RefreshBusEndpoint endpoint = new RefreshBusEndpoint(null, "foo",
|
||||
new BusEndpoint());
|
||||
RefreshBusEndpoint endpoint = new RefreshBusEndpoint(null, "foo");
|
||||
assertEquals("foo", endpoint.getInstanceId());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user