|
|
|
|
@@ -9,35 +9,58 @@
|
|
|
|
|
*/
|
|
|
|
|
package org.eclipse.hawkbit.event;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.concurrent.Executor;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.eclipse.hawkbit.repository.event.ApplicationEventFilter;
|
|
|
|
|
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
|
|
|
|
import org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEvent;
|
|
|
|
|
import org.eclipse.hawkbit.repository.event.remote.RemoteTenantAwareEvent;
|
|
|
|
|
import org.eclipse.hawkbit.repository.event.EventPublisherHolder;
|
|
|
|
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
|
|
import org.springframework.cloud.stream.config.BindingProperties;
|
|
|
|
|
import org.springframework.context.ApplicationEvent;
|
|
|
|
|
import org.springframework.context.ApplicationEventPublisher;
|
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.PropertySource;
|
|
|
|
|
import org.springframework.context.event.ApplicationEventMulticaster;
|
|
|
|
|
import org.springframework.context.event.SimpleApplicationEventMulticaster;
|
|
|
|
|
import org.springframework.context.support.AbstractApplicationContext;
|
|
|
|
|
import org.springframework.core.ResolvableType;
|
|
|
|
|
import org.springframework.core.env.ConfigurableEnvironment;
|
|
|
|
|
import org.springframework.core.io.support.ResourcePropertySource;
|
|
|
|
|
import org.springframework.messaging.converter.MessageConverter;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Autoconfiguration for the events.
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Configuration
|
|
|
|
|
@PropertySource("classpath:/hawkbit-events-defaults.properties")
|
|
|
|
|
public class EventPublisherConfiguration {
|
|
|
|
|
|
|
|
|
|
private final ConfigurableEnvironment environment;
|
|
|
|
|
|
|
|
|
|
public EventPublisherConfiguration(ConfigurableEnvironment environment) {
|
|
|
|
|
this.environment = environment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void registerProperties() {
|
|
|
|
|
try {
|
|
|
|
|
ResourcePropertySource props = new ResourcePropertySource("classpath:/hawkbit-events-defaults.properties");
|
|
|
|
|
// load manually to ensure that they are with the lowest precedence allowing to override them
|
|
|
|
|
environment.getPropertySources().addLast(props);
|
|
|
|
|
} catch (IOException ex) {
|
|
|
|
|
log.error("Failed to load default properties for event publisher", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Server internal event publisher that allows parallel event processing if the event listener is marked as so.
|
|
|
|
|
*
|
|
|
|
|
@@ -116,29 +139,22 @@ public class EventPublisherConfiguration {
|
|
|
|
|
return publisher::publishEvent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnProperty(name = "org.eclipse.hawkbit.events.remote-enabled", havingValue = "true")
|
|
|
|
|
@ConditionalOnProperty(name = "spring.cloud.stream.default.content-type", havingValue = "application/binary+stuff")
|
|
|
|
|
protected static class EventProtoStuffAutoConfiguration {
|
|
|
|
|
public MessageConverter eventMessageConverter(BindingProperties bindingProperties) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the protostuff io message converter for events
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public MessageConverter eventProtoStuffConverter() {
|
|
|
|
|
return new EventProtoStuffMessageConverter();
|
|
|
|
|
final String contentType = bindingProperties.getContentType();
|
|
|
|
|
|
|
|
|
|
if (contentType == null) {
|
|
|
|
|
throw new IllegalStateException("RemoteEvents are enabled and Content type must be specified in spring.cloud.stream.default.content-type.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ConditionalOnProperty(name = "org.eclipse.hawkbit.events.remote-enabled", havingValue = "true")
|
|
|
|
|
@ConditionalOnProperty(name = "spring.cloud.stream.default.content-type", havingValue = "application/remote-event-json")
|
|
|
|
|
protected static class EventJacksonAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the Jackson message converter for events
|
|
|
|
|
*/
|
|
|
|
|
@Bean
|
|
|
|
|
public MessageConverter eventJacksonMessageConverter() {
|
|
|
|
|
if (contentType.equals("application/binary+protostuff")) {
|
|
|
|
|
return new EventProtoStuffMessageConverter();
|
|
|
|
|
} else if (contentType.equals("application/remote-event-json")) {
|
|
|
|
|
return new EventJacksonMessageConverter();
|
|
|
|
|
} else {
|
|
|
|
|
throw new IllegalStateException("Unsupported content type: " + contentType + ". Supported types: application/x-protostuff, application/remote-event-json");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|