|
10 | 10 | */ |
11 | 11 | package org.phoebus.channelfinder; |
12 | 12 |
|
| 13 | +import io.swagger.v3.oas.annotations.OpenAPIDefinition; |
| 14 | +import io.swagger.v3.oas.annotations.servers.Server; |
13 | 15 | import java.io.File; |
14 | 16 | import java.io.FileOutputStream; |
15 | 17 | import java.io.IOException; |
|
19 | 21 | import java.util.ServiceLoader; |
20 | 22 | import java.util.logging.Level; |
21 | 23 | import java.util.logging.Logger; |
22 | | - |
23 | | -import io.swagger.v3.oas.annotations.OpenAPIDefinition; |
24 | | -import io.swagger.v3.oas.annotations.servers.Server; |
25 | 24 | import org.phoebus.channelfinder.example.PopulateService; |
26 | 25 | import org.phoebus.channelfinder.processors.ChannelProcessor; |
27 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
|
38 | 37 | import org.springframework.util.FileCopyUtils; |
39 | 38 |
|
40 | 39 | @EnableAutoConfiguration |
41 | | -@ComponentScan(basePackages="org.phoebus.channelfinder") |
| 40 | +@ComponentScan(basePackages = "org.phoebus.channelfinder") |
42 | 41 | @EnableScheduling |
43 | | -@OpenAPIDefinition( |
44 | | - servers = { |
45 | | - @Server(url = "/") |
46 | | - } |
47 | | -) |
| 42 | +@OpenAPIDefinition(servers = {@Server(url = "/")}) |
48 | 43 | @SpringBootApplication |
49 | 44 | public class Application implements ApplicationRunner { |
50 | 45 |
|
51 | | - static final Logger logger = Logger.getLogger(Application.class.getName()); |
| 46 | + static final Logger logger = Logger.getLogger(Application.class.getName()); |
52 | 47 |
|
53 | | - public static void main(String[] args){ |
54 | | - // Set the java truststore used by channelfinder |
55 | | - configureTruststore(); |
56 | | - SpringApplication.run(Application.class, args); |
57 | | - } |
| 48 | + public static void main(String[] args) { |
| 49 | + // Set the java truststore used by channelfinder |
| 50 | + configureTruststore(); |
| 51 | + SpringApplication.run(Application.class, args); |
| 52 | + } |
58 | 53 |
|
59 | | - /** |
60 | | - * Set the default ssl trust store |
61 | | - */ |
62 | | - private static void configureTruststore() { |
63 | | - if (System.getProperty("javax.net.ssl.trustStore") == null) { |
64 | | - logger.log(Level.INFO, "using default javax.net.ssl.trustStore"); |
65 | | - try (InputStream in = Application.class.getResourceAsStream("/keystore/cacerts")) { |
66 | | - // read input |
67 | | - File tempFile= File.createTempFile("cf-", "-truststore"); |
68 | | - FileOutputStream out = new FileOutputStream(tempFile); |
69 | | - FileCopyUtils.copy(in, out); |
70 | | - tempFile.deleteOnExit(); |
71 | | - System.setProperty("javax.net.ssl.trustStore", tempFile.getAbsolutePath()); |
72 | | - } catch (IOException e) { |
73 | | - logger.log(Level.SEVERE, "failed to configure channelfinder truststore", e); |
74 | | - } |
75 | | - } |
76 | | - if (System.getProperty("javax.net.ssl.trustStorePassword") == null) { |
77 | | - logger.log(Level.INFO, "using default javax.net.ssl.trustStorePassword"); |
78 | | - System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
79 | | - } |
| 54 | + /** Set the default ssl trust store */ |
| 55 | + private static void configureTruststore() { |
| 56 | + if (System.getProperty("javax.net.ssl.trustStore") == null) { |
| 57 | + logger.log(Level.INFO, "using default javax.net.ssl.trustStore"); |
| 58 | + try (InputStream in = Application.class.getResourceAsStream("/keystore/cacerts")) { |
| 59 | + // read input |
| 60 | + File tempFile = File.createTempFile("cf-", "-truststore"); |
| 61 | + FileOutputStream out = new FileOutputStream(tempFile); |
| 62 | + FileCopyUtils.copy(in, out); |
| 63 | + tempFile.deleteOnExit(); |
| 64 | + System.setProperty("javax.net.ssl.trustStore", tempFile.getAbsolutePath()); |
| 65 | + } catch (IOException e) { |
| 66 | + logger.log(Level.SEVERE, "failed to configure channelfinder truststore", e); |
| 67 | + } |
| 68 | + } |
| 69 | + if (System.getProperty("javax.net.ssl.trustStorePassword") == null) { |
| 70 | + logger.log(Level.INFO, "using default javax.net.ssl.trustStorePassword"); |
| 71 | + System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
80 | 72 | } |
| 73 | + } |
81 | 74 |
|
82 | | - @Autowired |
83 | | - PopulateService service; |
| 75 | + @Autowired PopulateService service; |
84 | 76 |
|
85 | | - public void run(ApplicationArguments args) throws Exception { |
86 | | - if(args.containsOption("demo-data")) { |
87 | | - int numberOfCells = args.getOptionValues("demo-data").stream().mapToInt(Integer::valueOf).max().orElse(1); |
88 | | - logger.log(Level.INFO, "Populating the channelfinder service with demo data"); |
89 | | - service.createDB(numberOfCells); |
90 | | - } |
91 | | - if(args.containsOption("cleanup")) { |
92 | | - int numberOfCells = args.getOptionValues("cleanup").stream().mapToInt(Integer::valueOf).max().orElse(1); |
93 | | - // This is kind of a hack, the create Db is being called to reset the channels and then deleting them |
94 | | - logger.log(Level.INFO, "Populating the channelfinder service with demo data first, then deleting them"); |
95 | | - service.createDB(numberOfCells); |
96 | | - logger.log(Level.INFO, "Cleaning up the populated demo data"); |
97 | | - service.cleanupDB(); |
98 | | - } |
| 77 | + public void run(ApplicationArguments args) throws Exception { |
| 78 | + if (args.containsOption("demo-data")) { |
| 79 | + int numberOfCells = |
| 80 | + args.getOptionValues("demo-data").stream().mapToInt(Integer::valueOf).max().orElse(1); |
| 81 | + logger.log(Level.INFO, "Populating the channelfinder service with demo data"); |
| 82 | + service.createDB(numberOfCells); |
99 | 83 | } |
100 | | - |
101 | | - /** |
102 | | - * List of {@link ChannelProcessor} implementations called when new channels are created or existing channels are updated |
103 | | - * |
104 | | - * @return A list of {@link ChannelProcessor}s, if any have been registered over SPI. |
105 | | - */ |
106 | | - @Bean |
107 | | - public List<ChannelProcessor> channelProcessors() { |
108 | | - List<ChannelProcessor> processors = new ArrayList<>(); |
109 | | - ServiceLoader<ChannelProcessor> loader = ServiceLoader.load(ChannelProcessor.class); |
110 | | - loader.stream().forEach(p -> { |
111 | | - ChannelProcessor notifier = p.get(); |
112 | | - processors.add(notifier); |
113 | | - }); |
114 | | - return processors; |
| 84 | + if (args.containsOption("cleanup")) { |
| 85 | + int numberOfCells = |
| 86 | + args.getOptionValues("cleanup").stream().mapToInt(Integer::valueOf).max().orElse(1); |
| 87 | + // This is kind of a hack, the create Db is being called to reset the channels and then |
| 88 | + // deleting them |
| 89 | + logger.log( |
| 90 | + Level.INFO, |
| 91 | + "Populating the channelfinder service with demo data first, then deleting them"); |
| 92 | + service.createDB(numberOfCells); |
| 93 | + logger.log(Level.INFO, "Cleaning up the populated demo data"); |
| 94 | + service.cleanupDB(); |
115 | 95 | } |
| 96 | + } |
116 | 97 |
|
117 | | - /** |
118 | | - * {@link TaskExecutor} used when calling {@link ChannelProcessor}s. |
119 | | - * |
120 | | - * @return A {@link TaskExecutor} |
121 | | - */ |
122 | | - @Bean |
123 | | - public TaskExecutor taskExecutor() { |
124 | | - ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); |
125 | | - taskExecutor.setCorePoolSize(3); |
126 | | - taskExecutor.setMaxPoolSize(10); |
127 | | - taskExecutor.setQueueCapacity(25); |
| 98 | + /** |
| 99 | + * List of {@link ChannelProcessor} implementations called when new channels are created or |
| 100 | + * existing channels are updated |
| 101 | + * |
| 102 | + * @return A list of {@link ChannelProcessor}s, if any have been registered over SPI. |
| 103 | + */ |
| 104 | + @Bean |
| 105 | + public List<ChannelProcessor> channelProcessors() { |
| 106 | + List<ChannelProcessor> processors = new ArrayList<>(); |
| 107 | + ServiceLoader<ChannelProcessor> loader = ServiceLoader.load(ChannelProcessor.class); |
| 108 | + loader.stream() |
| 109 | + .forEach( |
| 110 | + p -> { |
| 111 | + ChannelProcessor notifier = p.get(); |
| 112 | + processors.add(notifier); |
| 113 | + }); |
| 114 | + return processors; |
| 115 | + } |
128 | 116 |
|
129 | | - return taskExecutor; |
130 | | - } |
| 117 | + /** |
| 118 | + * {@link TaskExecutor} used when calling {@link ChannelProcessor}s. |
| 119 | + * |
| 120 | + * @return A {@link TaskExecutor} |
| 121 | + */ |
| 122 | + @Bean |
| 123 | + public TaskExecutor taskExecutor() { |
| 124 | + ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); |
| 125 | + taskExecutor.setCorePoolSize(3); |
| 126 | + taskExecutor.setMaxPoolSize(10); |
| 127 | + taskExecutor.setQueueCapacity(25); |
131 | 128 |
|
| 129 | + return taskExecutor; |
| 130 | + } |
132 | 131 | } |
0 commit comments