use of de.codecentric.boot.admin.model.Application 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.model.Application in project spring-boot-admin by codecentric.
the class StatusUpdater method updateStatus.
public void updateStatus(Application application) {
StatusInfo oldStatus = application.getStatusInfo();
StatusInfo newStatus = queryStatus(application);
boolean statusChanged = !newStatus.equals(oldStatus);
Application.Builder builder = Application.copyOf(application).withStatusInfo(newStatus);
if (statusChanged && !newStatus.isOffline() && !newStatus.isUnknown()) {
builder.withInfo(queryInfo(application));
}
Application newState = builder.build();
store.save(newState);
if (statusChanged) {
publisher.publishEvent(new ClientApplicationStatusChangedEvent(newState, oldStatus, newStatus));
}
}
use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.
the class RegistryController method get.
/**
* Get a single application out of the registry.
*
* @param id The application identifier.
* @return The registered application.
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> get(@PathVariable String id) {
LOGGER.debug("Deliver registered application with ID '{}'", id);
Application application = registry.getApplication(id);
if (application != null) {
return ResponseEntity.ok(application);
} else {
return ResponseEntity.notFound().build();
}
}
use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.
the class RegistryController method register.
/**
* Register an application within this admin application.
*
* @param application The application infos.
* @return The registered application.
*/
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<Application> register(@RequestBody Application application) {
Application applicationWithSource = Application.copyOf(application).withSource("http-api").build();
LOGGER.debug("Register application {}", applicationWithSource.toString());
Application registeredApp = registry.register(applicationWithSource);
return ResponseEntity.status(HttpStatus.CREATED).body(registeredApp);
}
use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.
the class RegistryController method unregister.
/**
* Unregister an application within this admin application.
*
* @param id The application id.
* @return the unregistered application.
*/
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity<?> unregister(@PathVariable String id) {
LOGGER.debug("Unregister application with ID '{}'", id);
Application application = registry.deregister(id);
if (application != null) {
return ResponseEntity.ok(application);
} else {
return ResponseEntity.notFound().build();
}
}
Aggregations