use of de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent in project spring-boot-admin by codecentric.
the class ApplicationRegistry method register.
/**
* Register application.
*
* @param application application to be registered.
* @return the registered application.
*/
public Application register(Application application) {
Assert.notNull(application, "Application must not be null");
Assert.hasText(application.getName(), "Name must not be null");
Assert.hasText(application.getHealthUrl(), "Health-URL must not be null");
Assert.isTrue(checkUrl(application.getHealthUrl()), "Health-URL is not valid");
Assert.isTrue(StringUtils.isEmpty(application.getManagementUrl()) || checkUrl(application.getManagementUrl()), "URL is not valid");
Assert.isTrue(StringUtils.isEmpty(application.getServiceUrl()) || checkUrl(application.getServiceUrl()), "URL is not valid");
String applicationId = generator.generateId(application);
Assert.notNull(applicationId, "ID must not be null");
Application.Builder builder = Application.copyOf(application).withId(applicationId);
Application existing = getApplication(applicationId);
if (existing != null) {
// Copy Status and Info from existing registration.
builder.withStatusInfo(existing.getStatusInfo()).withInfo(existing.getInfo());
}
Application registering = builder.build();
Application replaced = store.save(registering);
if (replaced == null) {
LOGGER.info("New Application {} registered ", registering);
publisher.publishEvent(new ClientApplicationRegisteredEvent(registering));
} else {
if (registering.getId().equals(replaced.getId())) {
LOGGER.debug("Application {} refreshed", registering);
} else {
LOGGER.warn("Application {} replaced by Application {}", registering, replaced);
}
}
return registering;
}
use of de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent in project spring-boot-admin by codecentric.
the class ApplicationEventJournalTest method test_registration.
@Test
public void test_registration() {
ClientApplicationEvent emittedEvent = new ClientApplicationRegisteredEvent(Application.create("foo").withId("bar").withHealthUrl("http://health").build());
journal.onClientApplicationEvent(emittedEvent);
Collection<ClientApplicationEvent> events = journal.getEvents();
assertThat(events.size(), is(1));
ClientApplicationEvent event = events.iterator().next();
assertThat(event, sameInstance(emittedEvent));
}
use of de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent in project spring-boot-admin by codecentric.
the class HazelcastJournaledEventStoreTest method test_store.
@Test
public void test_store() {
Application application = Application.create("foo").withId("bar").withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(new ClientApplicationRegisteredEvent(application), new ClientApplicationDeregisteredEvent(application));
for (ClientApplicationEvent event : events) {
store.store(event);
}
// Items are stored in reverse order
List<ClientApplicationEvent> reversed = new ArrayList<>(events);
Collections.reverse(reversed);
assertThat(store.findAll(), is((Collection<ClientApplicationEvent>) reversed));
}
use of de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent in project spring-boot-admin by codecentric.
the class SimpleJournaledEventStoreTest method test_store.
@Test
public void test_store() {
SimpleJournaledEventStore store = new SimpleJournaledEventStore();
Application application = Application.create("foo").withId("bar").withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(new ClientApplicationRegisteredEvent(application), new ClientApplicationDeregisteredEvent(application));
for (ClientApplicationEvent event : events) {
store.store(event);
}
assertThat(store.findAll(), is((Collection<ClientApplicationEvent>) Arrays.asList(events.get(1), events.get(0))));
}
use of de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent in project spring-boot-admin by codecentric.
the class SimpleJournaledEventStoreTest method test_store_capacity.
@Test
public void test_store_capacity() {
SimpleJournaledEventStore store = new SimpleJournaledEventStore();
store.setCapacity(2);
Application application = Application.create("foo").withId("bar").withHealthUrl("http://health").build();
List<ClientApplicationEvent> events = Arrays.asList(new ClientApplicationRegisteredEvent(application), new ClientApplicationDeregisteredEvent(application), new ClientApplicationDeregisteredEvent(application));
for (ClientApplicationEvent event : events) {
store.store(event);
}
assertThat(store.findAll(), is((Collection<ClientApplicationEvent>) Arrays.asList(events.get(2), events.get(1))));
}
Aggregations