|
15 | 15 | */ |
16 | 16 | package de.codecentric.boot.admin.config; |
17 | 17 |
|
18 | | -import org.springframework.beans.factory.annotation.Qualifier; |
19 | | -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
20 | | -import org.springframework.boot.context.properties.EnableConfigurationProperties; |
21 | | -import org.springframework.boot.web.client.RestTemplateBuilder; |
22 | | -import org.springframework.context.annotation.Bean; |
23 | | -import org.springframework.context.annotation.Configuration; |
24 | | -import org.springframework.http.HttpStatus; |
25 | | -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
26 | | -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
27 | | -import org.springframework.web.client.DefaultResponseErrorHandler; |
28 | | - |
29 | 18 | import de.codecentric.boot.admin.journal.ApplicationEventJournal; |
30 | 19 | import de.codecentric.boot.admin.journal.store.JournaledEventStore; |
31 | 20 | import de.codecentric.boot.admin.journal.store.SimpleJournaledEventStore; |
|
40 | 29 | import de.codecentric.boot.admin.web.client.BasicAuthHttpHeaderProvider; |
41 | 30 | import de.codecentric.boot.admin.web.client.HttpHeadersProvider; |
42 | 31 |
|
| 32 | +import org.springframework.beans.factory.annotation.Qualifier; |
| 33 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| 34 | +import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| 35 | +import org.springframework.boot.web.client.RestTemplateBuilder; |
| 36 | +import org.springframework.context.annotation.Bean; |
| 37 | +import org.springframework.context.annotation.Configuration; |
| 38 | +import org.springframework.http.HttpStatus; |
| 39 | +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; |
| 40 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
| 41 | +import org.springframework.web.client.DefaultResponseErrorHandler; |
| 42 | + |
43 | 43 | @Configuration |
44 | 44 | @EnableConfigurationProperties(AdminServerProperties.class) |
45 | 45 | public class AdminServerCoreConfiguration { |
46 | | - private final AdminServerProperties adminServerProperties; |
47 | | - |
48 | | - public AdminServerCoreConfiguration(AdminServerProperties adminServerProperties) { |
49 | | - this.adminServerProperties = adminServerProperties; |
50 | | - } |
51 | | - |
52 | | - @Bean |
53 | | - @ConditionalOnMissingBean |
54 | | - public ApplicationRegistry applicationRegistry(ApplicationStore applicationStore, |
55 | | - ApplicationIdGenerator applicationIdGenerator) { |
56 | | - return new ApplicationRegistry(applicationStore, applicationIdGenerator); |
57 | | - } |
58 | | - |
59 | | - @Bean |
60 | | - @ConditionalOnMissingBean |
61 | | - public ApplicationIdGenerator applicationIdGenerator() { |
62 | | - return new HashingApplicationUrlIdGenerator(); |
63 | | - } |
64 | | - |
65 | | - @Bean |
66 | | - @ConditionalOnMissingBean |
67 | | - public HttpHeadersProvider httpHeadersProvider() { |
68 | | - return new BasicAuthHttpHeaderProvider(); |
69 | | - } |
70 | | - |
71 | | - @Bean |
72 | | - @ConditionalOnMissingBean |
73 | | - public ApplicationOperations applicationOperations(RestTemplateBuilder restTemplBuilder, |
74 | | - HttpHeadersProvider headersProvider) { |
75 | | - RestTemplateBuilder builder = restTemplBuilder |
76 | | - .messageConverters(new MappingJackson2HttpMessageConverter()) |
77 | | - .errorHandler(new DefaultResponseErrorHandler() { |
78 | | - @Override |
79 | | - protected boolean hasError(HttpStatus statusCode) { |
80 | | - return false; |
81 | | - } |
82 | | - }); |
83 | | - return new ApplicationOperations(builder.build(), headersProvider); |
84 | | - }; |
85 | | - |
86 | | - @Bean |
87 | | - @ConditionalOnMissingBean |
88 | | - public StatusUpdater statusUpdater(ApplicationStore applicationStore, |
89 | | - ApplicationOperations applicationOperations) { |
90 | | - |
91 | | - StatusUpdater statusUpdater = new StatusUpdater(applicationStore, applicationOperations); |
92 | | - statusUpdater.setStatusLifetime(adminServerProperties.getMonitor().getStatusLifetime()); |
93 | | - return statusUpdater; |
94 | | - } |
95 | | - |
96 | | - @Bean |
97 | | - @Qualifier("updateTaskScheduler") |
98 | | - public ThreadPoolTaskScheduler updateTaskScheduler() { |
99 | | - ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); |
100 | | - taskScheduler.setPoolSize(1); |
101 | | - taskScheduler.setRemoveOnCancelPolicy(true); |
102 | | - taskScheduler.setThreadNamePrefix("updateTask"); |
103 | | - return taskScheduler; |
104 | | - } |
105 | | - |
106 | | - @Bean |
107 | | - @ConditionalOnMissingBean |
108 | | - public StatusUpdateApplicationListener statusUpdateApplicationListener( |
109 | | - StatusUpdater statusUpdater, |
110 | | - @Qualifier("updateTaskScheduler") ThreadPoolTaskScheduler taskScheduler) { |
111 | | - StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener( |
112 | | - statusUpdater, taskScheduler); |
113 | | - listener.setUpdatePeriod(adminServerProperties.getMonitor().getPeriod()); |
114 | | - return listener; |
115 | | - } |
116 | | - |
117 | | - @Bean |
118 | | - @ConditionalOnMissingBean |
119 | | - public ApplicationEventJournal applicationEventJournal( |
120 | | - JournaledEventStore journaledEventStore) { |
121 | | - return new ApplicationEventJournal(journaledEventStore); |
122 | | - } |
123 | | - |
124 | | - @Bean |
125 | | - @ConditionalOnMissingBean |
126 | | - public JournaledEventStore journaledEventStore() { |
127 | | - return new SimpleJournaledEventStore(); |
128 | | - } |
129 | | - |
130 | | - @Bean |
131 | | - @ConditionalOnMissingBean |
132 | | - public ApplicationStore applicationStore() { |
133 | | - return new SimpleApplicationStore(); |
134 | | - } |
| 46 | + private final AdminServerProperties adminServerProperties; |
| 47 | + |
| 48 | + public AdminServerCoreConfiguration(AdminServerProperties adminServerProperties) { |
| 49 | + this.adminServerProperties = adminServerProperties; |
| 50 | + } |
| 51 | + |
| 52 | + @Bean |
| 53 | + @ConditionalOnMissingBean |
| 54 | + public ApplicationRegistry applicationRegistry(ApplicationStore applicationStore, |
| 55 | + ApplicationIdGenerator applicationIdGenerator) { |
| 56 | + return new ApplicationRegistry(applicationStore, applicationIdGenerator); |
| 57 | + } |
| 58 | + |
| 59 | + @Bean |
| 60 | + @ConditionalOnMissingBean |
| 61 | + public ApplicationIdGenerator applicationIdGenerator() { |
| 62 | + return new HashingApplicationUrlIdGenerator(); |
| 63 | + } |
| 64 | + |
| 65 | + @Bean |
| 66 | + @ConditionalOnMissingBean |
| 67 | + public HttpHeadersProvider httpHeadersProvider() { |
| 68 | + return new BasicAuthHttpHeaderProvider(); |
| 69 | + } |
| 70 | + |
| 71 | + @Bean |
| 72 | + @ConditionalOnMissingBean |
| 73 | + public ApplicationOperations applicationOperations(RestTemplateBuilder restTemplBuilder, |
| 74 | + HttpHeadersProvider headersProvider) { |
| 75 | + RestTemplateBuilder builder = restTemplBuilder.messageConverters(new MappingJackson2HttpMessageConverter()) |
| 76 | + .errorHandler(new DefaultResponseErrorHandler() { |
| 77 | + @Override |
| 78 | + protected boolean hasError(HttpStatus statusCode) { |
| 79 | + return false; |
| 80 | + } |
| 81 | + }); |
| 82 | + builder = builder.setConnectTimeout(adminServerProperties.getMonitor().getConnectTimeout()) |
| 83 | + .setReadTimeout(adminServerProperties.getMonitor().getReadTimeout()); |
| 84 | + return new ApplicationOperations(builder.build(), headersProvider); |
| 85 | + } |
| 86 | + |
| 87 | + @Bean |
| 88 | + @ConditionalOnMissingBean |
| 89 | + public StatusUpdater statusUpdater(ApplicationStore applicationStore, ApplicationOperations applicationOperations) { |
| 90 | + StatusUpdater statusUpdater = new StatusUpdater(applicationStore, applicationOperations); |
| 91 | + statusUpdater.setStatusLifetime(adminServerProperties.getMonitor().getStatusLifetime()); |
| 92 | + return statusUpdater; |
| 93 | + } |
| 94 | + |
| 95 | + @Bean |
| 96 | + @Qualifier("updateTaskScheduler") |
| 97 | + public ThreadPoolTaskScheduler updateTaskScheduler() { |
| 98 | + ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); |
| 99 | + taskScheduler.setPoolSize(1); |
| 100 | + taskScheduler.setRemoveOnCancelPolicy(true); |
| 101 | + taskScheduler.setThreadNamePrefix("updateTask"); |
| 102 | + return taskScheduler; |
| 103 | + } |
| 104 | + |
| 105 | + @Bean |
| 106 | + @ConditionalOnMissingBean |
| 107 | + public StatusUpdateApplicationListener statusUpdateApplicationListener(StatusUpdater statusUpdater, |
| 108 | + @Qualifier("updateTaskScheduler") ThreadPoolTaskScheduler taskScheduler) { |
| 109 | + StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(statusUpdater, taskScheduler); |
| 110 | + listener.setUpdatePeriod(adminServerProperties.getMonitor().getPeriod()); |
| 111 | + return listener; |
| 112 | + } |
| 113 | + |
| 114 | + @Bean |
| 115 | + @ConditionalOnMissingBean |
| 116 | + public ApplicationEventJournal applicationEventJournal(JournaledEventStore journaledEventStore) { |
| 117 | + return new ApplicationEventJournal(journaledEventStore); |
| 118 | + } |
| 119 | + |
| 120 | + @Bean |
| 121 | + @ConditionalOnMissingBean |
| 122 | + public JournaledEventStore journaledEventStore() { |
| 123 | + return new SimpleJournaledEventStore(); |
| 124 | + } |
| 125 | + |
| 126 | + @Bean |
| 127 | + @ConditionalOnMissingBean |
| 128 | + public ApplicationStore applicationStore() { |
| 129 | + return new SimpleApplicationStore(); |
| 130 | + } |
135 | 131 |
|
136 | 132 | } |
0 commit comments