Search in sources :

Example 1 with Application

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;
}
Also used : ClientApplicationRegisteredEvent(de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent) Application(de.codecentric.boot.admin.model.Application)

Example 2 with Application

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));
    }
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Application(de.codecentric.boot.admin.model.Application)

Example 3 with Application

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();
    }
}
Also used : Application(de.codecentric.boot.admin.model.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Application

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);
}
Also used : Application(de.codecentric.boot.admin.model.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Application

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();
    }
}
Also used : Application(de.codecentric.boot.admin.model.Application) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Application (de.codecentric.boot.admin.model.Application)36 Test (org.junit.Test)27 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)7 ServiceInstance (org.springframework.cloud.client.ServiceInstance)7 ClientApplicationRegisteredEvent (de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent)5 ClientApplicationDeregisteredEvent (de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)3 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HttpEntity (org.springframework.http.HttpEntity)2 RequestContext (com.netflix.zuul.context.RequestContext)1 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)1