Commit 9b4b0901 by Thomas Bosch

comments

parent 548126d9
......@@ -2,6 +2,8 @@ package de.codecentric.boot.admin.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -12,23 +14,28 @@ import org.springframework.web.bind.annotation.ResponseBody;
import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.service.ApplicationRegistry;
/**
* REST controller for controlling registration of managed applications.
*/
@Controller
public class RegistryController {
private static final Logger LOGGER = LoggerFactory.getLogger(RegistryController.class);
@Autowired
private ApplicationRegistry registry;
@RequestMapping(value = "/api/applications", method = RequestMethod.POST)
@ResponseBody
public void register(@RequestBody Application app) {
System.out.println("register " + app);
LOGGER.info("Register application with ID '{}' and URL '{}'", app.getId(), app.getUrl());
registry.register(app);
}
@RequestMapping(value = "/api/applications", method = RequestMethod.GET)
@ResponseBody
public List<Application> applications() {
System.out.println("get all");
LOGGER.debug("Deliver all registered applications");
return registry.getApplications();
}
......
......@@ -9,11 +9,20 @@ import org.springframework.stereotype.Service;
import de.codecentric.boot.admin.model.Application;
/**
* Registry for all applications that should be managed/administrated by the spring-boot-admin application.
*/
@Service
public class ApplicationRegistry {
private final List<Application> registry = new ArrayList<>();
/**
* Register application.
*
* @param app
* The Application.
*/
public void register(Application app) {
Validate.notNull(app, "Application must not be null");
Validate.notNull(app.getId(), "Application ID must not be null");
......@@ -21,10 +30,22 @@ public class ApplicationRegistry {
registry.add(app);
}
/**
* Checks, if an application is already registerd.
*
* @param app
* The application.
* @return exists?
*/
public boolean isRegistered(Application app) {
return registry.contains(app);
}
/**
* Get a list of all registered applications.
*
* @return List.
*/
public List<Application> getApplications() {
return Collections.unmodifiableList(registry);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment