├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.adoc ├── dashboard ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── spring │ │ │ └── sample │ │ │ └── dashboard │ │ │ ├── DashboardApplication.java │ │ │ ├── DashboardController.java │ │ │ ├── DashboardProperties.java │ │ │ ├── ReverseLookupHealthIndicator.java │ │ │ ├── SecurityConfig.java │ │ │ ├── WebConfig.java │ │ │ └── stats │ │ │ ├── Annotation.java │ │ │ ├── Client.java │ │ │ ├── ProjectCreations.java │ │ │ ├── ReverseLookupClient.java │ │ │ ├── StatsClient.java │ │ │ ├── StatsContainer.java │ │ │ ├── StatsService.java │ │ │ └── support │ │ │ ├── DateRange.java │ │ │ ├── DateTimeRange.java │ │ │ ├── Event.java │ │ │ ├── GenerationStatistics.java │ │ │ ├── GenerationStatisticsItem.java │ │ │ ├── GeneratorClient.java │ │ │ └── ReverseLookupDescriptor.java │ └── resources │ │ ├── application.properties │ │ ├── keystore.jks │ │ ├── static │ │ ├── images │ │ │ └── springboot.png │ │ └── img │ │ │ └── springboot.png │ │ └── templates │ │ ├── index.html │ │ ├── live.html │ │ └── login.html │ └── test │ └── java │ └── io │ └── spring │ └── sample │ └── dashboard │ └── DashboardControllerTests.java ├── generator ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── io │ │ │ └── spring │ │ │ └── sample │ │ │ └── generator │ │ │ ├── DataSet.java │ │ │ ├── DateRange.java │ │ │ ├── DateTimeRange.java │ │ │ ├── Event.java │ │ │ ├── GenerationStatistics.java │ │ │ ├── GenerationStatisticsItem.java │ │ │ ├── Generator.java │ │ │ ├── GeneratorApplication.java │ │ │ ├── GeneratorClient.java │ │ │ ├── GeneratorConfiguration.java │ │ │ ├── GeneratorProperties.java │ │ │ ├── Release.java │ │ │ ├── management │ │ │ └── LatencyEndpoint.java │ │ │ └── web │ │ │ ├── GeneratorController.java │ │ │ ├── GeneratorWebConfiguration.java │ │ │ ├── GeneratorWebProperties.java │ │ │ ├── RateLimiterHandlerInterceptor.java │ │ │ └── ReverseLookupDescriptor.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── io │ └── spring │ └── sample │ └── generator │ └── GeneratorTests.java ├── mvnw ├── mvnw.cmd └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.6"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bclozel/initializr-stats/f3daf53440fd5a6c15d8f2c2b88874ce87e8330f/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.1/apache-maven-3.8.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Initializr Stats 2 | See a recording of https://www.youtube.com/watch?v=LVkGL1h25DI[the talk at Spring I/O]. 3 | -------------------------------------------------------------------------------- /dashboard/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.4.4 10 | 11 | 12 | io.spring.sample 13 | dashboard 14 | 0.0.1-SNAPSHOT 15 | jar 16 | dashboard 17 | Demo project for Spring Boot 18 | 19 | 20 | 11 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-webflux 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-thymeleaf 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-security 39 | 40 | 41 | org.springframework.boot 42 | spring-boot-starter-actuator 43 | 44 | 45 | com.wavefront 46 | wavefront-spring-boot-starter 47 | 48 | 49 | 50 | org.webjars 51 | webjars-locator-core 52 | 53 | 54 | org.webjars.npm 55 | bulma 56 | 0.9.2 57 | runtime 58 | 59 | 60 | org.webjars.npm 61 | flatpickr 62 | 4.6.9 63 | runtime 64 | 65 | 66 | org.webjars 67 | font-awesome 68 | 5.15.2 69 | runtime 70 | 71 | 72 | org.webjars 73 | highcharts 74 | 8.2.2 75 | runtime 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-configuration-processor 81 | true 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-devtools 86 | true 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-starter-test 92 | test 93 | 94 | 95 | org.springframework.security 96 | spring-security-test 97 | test 98 | 99 | 100 | 101 | 102 | 103 | 104 | com.wavefront 105 | wavefront-spring-boot-bom 106 | 2.1.0 107 | pom 108 | import 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | org.springframework.boot 117 | spring-boot-maven-plugin 118 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/DashboardApplication.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 6 | 7 | @SpringBootApplication 8 | @EnableConfigurationProperties(DashboardProperties.class) 9 | public class DashboardApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(DashboardApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/DashboardController.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import java.time.LocalDate; 4 | 5 | import io.spring.sample.dashboard.stats.StatsService; 6 | import io.spring.sample.dashboard.stats.support.GenerationStatisticsItem; 7 | import reactor.core.publisher.Flux; 8 | 9 | import org.springframework.format.annotation.DateTimeFormat; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.ui.Model; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.RequestParam; 17 | 18 | @Controller 19 | public class DashboardController { 20 | 21 | private final StatsService statsService; 22 | 23 | public DashboardController(StatsService statsService) { 24 | this.statsService = statsService; 25 | } 26 | 27 | @GetMapping("/") 28 | public String index() { 29 | return redirect(LocalDate.now().minusWeeks(1).toString(), LocalDate.now().toString()); 30 | } 31 | 32 | @PostMapping("/") 33 | public String redirect(@RequestParam String fromDate, @RequestParam String toDate) { 34 | return String.format("redirect:/stats/%s/%s", fromDate, toDate); 35 | } 36 | 37 | @GetMapping("/stats/{fromDate}/{toDate}") 38 | public String showDashboard(@PathVariable @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate fromDate, 39 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @PathVariable LocalDate toDate, 40 | Model model) { 41 | model.addAttribute("fromDate", fromDate); 42 | model.addAttribute("toDate", toDate); 43 | model.addAttribute("stats", statsService.fetchStats(fromDate.toString(), toDate.toString()).block()); 44 | return "index"; 45 | } 46 | 47 | @GetMapping(path = "/live/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE) 48 | public Flux liveStats() { 49 | return this.statsService.fetchLiveStats(); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/DashboardProperties.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import java.time.Duration; 4 | 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | 7 | @ConfigurationProperties("dashboard") 8 | public class DashboardProperties { 9 | 10 | private ReverseLookup reverseLookup = new ReverseLookup(); 11 | 12 | public ReverseLookup getReverseLookup() { 13 | return reverseLookup; 14 | } 15 | 16 | public static class ReverseLookup { 17 | 18 | /** 19 | * Read timeout for the IP resolver API. 20 | */ 21 | private Duration timeout = Duration.ofMillis(500); 22 | 23 | public Duration getTimeout() { 24 | return timeout; 25 | } 26 | 27 | public void setTimeout(Duration timeout) { 28 | this.timeout = timeout; 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/ReverseLookupHealthIndicator.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import io.spring.sample.dashboard.stats.ReverseLookupClient; 4 | 5 | import org.springframework.boot.actuate.health.AbstractHealthIndicator; 6 | import org.springframework.boot.actuate.health.Health; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | class ReverseLookupHealthIndicator extends AbstractHealthIndicator { 11 | 12 | private final ReverseLookupClient client; 13 | 14 | public ReverseLookupHealthIndicator(ReverseLookupClient client) { 15 | this.client = client; 16 | } 17 | 18 | @Override 19 | protected void doHealthCheck(Health.Builder builder) { 20 | client.freeReverseLookup("10.10.10.10"); 21 | builder.up(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/SecurityConfig.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest; 4 | import org.springframework.boot.actuate.health.HealthEndpoint; 5 | import org.springframework.boot.actuate.info.InfoEndpoint; 6 | import org.springframework.boot.autoconfigure.security.servlet.PathRequest; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.core.userdetails.User; 12 | import org.springframework.security.provisioning.InMemoryUserDetailsManager; 13 | 14 | @Configuration 15 | class SecurityConfig extends WebSecurityConfigurerAdapter { 16 | 17 | @Override 18 | protected void configure(HttpSecurity http) throws Exception { 19 | http.authorizeRequests() 20 | .requestMatchers(EndpointRequest.to(InfoEndpoint.class, HealthEndpoint.class)).permitAll() 21 | .requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN") 22 | .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() 23 | .anyRequest().authenticated() 24 | .and().formLogin().loginPage("/login").permitAll() 25 | .and().httpBasic(); 26 | } 27 | 28 | @Bean 29 | @SuppressWarnings("deprecation") 30 | public InMemoryUserDetailsManager inMemoryUserDetailsManager() { 31 | return new InMemoryUserDetailsManager( 32 | User.withDefaultPasswordEncoder().username("user").password("user").roles("USER").build(), 33 | User.withDefaultPasswordEncoder().username("admin").password("admin").roles("USER", "ADMIN").build() 34 | ); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/WebConfig.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | @Configuration 8 | public class WebConfig implements WebMvcConfigurer { 9 | 10 | @Override 11 | public void addViewControllers(ViewControllerRegistry registry) { 12 | registry.addViewController("/login").setViewName("login"); 13 | registry.addViewController("/live").setViewName("live"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/Annotation.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | public class Annotation { 4 | 5 | private String text; 6 | 7 | private String date; 8 | 9 | public Annotation(String text, String date) { 10 | this.text = text; 11 | this.date = date; 12 | } 13 | 14 | public String getText() { 15 | return text; 16 | } 17 | 18 | public String getDate() { 19 | return date; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/Client.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | public class Client { 4 | 5 | private String ip; 6 | private String hostname; 7 | 8 | public Client(String ip, String hostname) { 9 | this.ip = ip; 10 | this.hostname = hostname; 11 | } 12 | 13 | public String getIp() { 14 | return ip; 15 | } 16 | 17 | public String getHostname() { 18 | return hostname; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/ProjectCreations.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | public class ProjectCreations { 4 | 5 | public ProjectCreations(String date, int count) { 6 | this.date = date; 7 | this.count = count; 8 | } 9 | 10 | private String date; 11 | 12 | private int count; 13 | 14 | public String getDate() { 15 | return date; 16 | } 17 | 18 | public void setDate(String date) { 19 | this.date = date; 20 | } 21 | 22 | public int getCount() { 23 | return count; 24 | } 25 | 26 | public void setCount(int count) { 27 | this.count = count; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/ReverseLookupClient.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | import java.util.concurrent.atomic.AtomicInteger; 4 | 5 | import io.micrometer.core.instrument.MeterRegistry; 6 | import io.spring.sample.dashboard.stats.support.ReverseLookupDescriptor; 7 | import reactor.core.publisher.Mono; 8 | 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.util.StringUtils; 11 | import org.springframework.web.reactive.function.client.ExchangeFilterFunction; 12 | import org.springframework.web.reactive.function.client.WebClient; 13 | 14 | @Component 15 | public class ReverseLookupClient { 16 | 17 | private final WebClient client; 18 | 19 | public ReverseLookupClient(WebClient.Builder builder, MeterRegistry registry) { 20 | this.client = builder.filter(rateLimitRemainingMetric(registry)).build(); 21 | } 22 | 23 | public Mono freeReverseLookup(String ip) { 24 | return this.client.get().uri("http://localhost:8081/reverse-lookup/free/{ip}", ip) 25 | .retrieve().bodyToMono(ReverseLookupDescriptor.class); 26 | } 27 | 28 | public Mono payingReverseLookup(String ip) { 29 | return this.client.get().uri("http://localhost:8081/reverse-lookup/costly/{ip}", ip) 30 | .retrieve().bodyToMono(ReverseLookupDescriptor.class); 31 | } 32 | 33 | private ExchangeFilterFunction rateLimitRemainingMetric(MeterRegistry registry) { 34 | AtomicInteger rateLimitRemaining = registry 35 | .gauge("reverselookup.ratelimit.remaining", new AtomicInteger(0)); 36 | return (request, next) -> next.exchange(request) 37 | .doOnNext(response -> { 38 | String remaining = response.headers().asHttpHeaders() 39 | .getFirst("X-RateLimit-Remaining"); 40 | if (StringUtils.hasText(remaining)) { 41 | rateLimitRemaining.set(Integer.parseInt(remaining)); 42 | } 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/StatsClient.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | import io.spring.sample.dashboard.stats.support.Event; 4 | import io.spring.sample.dashboard.stats.support.GenerationStatistics; 5 | import io.spring.sample.dashboard.stats.support.GenerationStatisticsItem; 6 | import io.spring.sample.dashboard.stats.support.GeneratorClient; 7 | import reactor.core.publisher.Flux; 8 | import reactor.core.publisher.Mono; 9 | 10 | import org.springframework.stereotype.Component; 11 | import org.springframework.web.reactive.function.client.WebClient; 12 | 13 | @Component 14 | public class StatsClient { 15 | 16 | private final WebClient client; 17 | 18 | public StatsClient(WebClient.Builder builder) { 19 | this.client = builder.baseUrl("http://localhost:8081").build(); 20 | } 21 | 22 | public Mono fetchGenerationStats(String fromDate, String toDate) { 23 | return this.client.get().uri("/statistics/{from}/{to}", fromDate, toDate) 24 | .retrieve().bodyToMono(GenerationStatistics.class); 25 | } 26 | 27 | public Flux fetchEvents(String fromDate, String toDate) { 28 | return this.client.get().uri("/events/{from}/{to}", fromDate, toDate) 29 | .retrieve().bodyToFlux(Event.class); 30 | } 31 | 32 | public Flux fetchGeneratorClients(String fromDate, String toDate) { 33 | return this.client.get().uri("/top-ips/{from}/{to}", fromDate, toDate) 34 | .retrieve().bodyToFlux(GeneratorClient.class); 35 | } 36 | 37 | public Flux liveStats() { 38 | return this.client.get().uri("/live-statistics") 39 | .retrieve().bodyToFlux(GenerationStatisticsItem.class); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/StatsContainer.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | 4 | import java.time.LocalDate; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.stream.Collectors; 8 | 9 | import io.spring.sample.dashboard.stats.support.Event; 10 | import io.spring.sample.dashboard.stats.support.GenerationStatistics; 11 | import io.spring.sample.dashboard.stats.support.ReverseLookupDescriptor; 12 | 13 | import org.springframework.util.LinkedMultiValueMap; 14 | import org.springframework.util.MultiValueMap; 15 | 16 | public class StatsContainer { 17 | 18 | private String fromDate; 19 | 20 | private String toDate; 21 | 22 | private MultiValueMap creations; 23 | 24 | private List annotations; 25 | 26 | private List topClients; 27 | 28 | StatsContainer(String fromDate, String toDate, MultiValueMap creations, 29 | List annotations, List topClients) { 30 | this.fromDate = fromDate; 31 | this.toDate = toDate; 32 | this.creations = creations; 33 | this.annotations = annotations; 34 | this.topClients = topClients; 35 | } 36 | 37 | public String getFromDate() { 38 | return fromDate; 39 | } 40 | 41 | public String getToDate() { 42 | return toDate; 43 | } 44 | 45 | public MultiValueMap getCreations() { 46 | return creations; 47 | } 48 | 49 | public List getAnnotations() { 50 | return annotations; 51 | } 52 | 53 | public List getTopClients() { 54 | return topClients; 55 | } 56 | 57 | public static Builder range(LocalDate from , LocalDate to) { 58 | return new Builder(from, to); 59 | } 60 | 61 | public static Builder range(String from , String to) { 62 | return new Builder(from, to); 63 | } 64 | 65 | public static class Builder { 66 | 67 | private String fromDate; 68 | 69 | private String toDate; 70 | 71 | private MultiValueMap creations = new LinkedMultiValueMap<>(); 72 | 73 | private List annotations = new ArrayList<>(); 74 | 75 | private List topClients = new ArrayList<>(); 76 | 77 | Builder(LocalDate fromDate, LocalDate toDate) { 78 | this.fromDate = fromDate.toString(); 79 | this.toDate = toDate.toString(); 80 | } 81 | 82 | Builder(String fromDate, String toDate) { 83 | this.fromDate = fromDate; 84 | this.toDate = toDate; 85 | } 86 | 87 | public Builder addSeries(MultiValueMap series) { 88 | series.forEach((name, records) -> { 89 | records.stream() 90 | .map(record -> new ProjectCreations(record.getDate().toString(), record.getProjectsCount())) 91 | .forEach(creation -> this.creations.add(name, creation)); 92 | }); 93 | return this; 94 | } 95 | 96 | public StatsContainer build() { 97 | return new StatsContainer(this.fromDate, this.toDate, this.creations, this.annotations, this.topClients); 98 | } 99 | 100 | public Builder addAnnotations(List events) { 101 | this.annotations.addAll(events.stream() 102 | .map(event -> new Annotation(event.getName(), event.getDate().toString())) 103 | .collect(Collectors.toList())); 104 | return this; 105 | } 106 | 107 | public Builder addTopClients(List resolvedIps) { 108 | this.topClients.addAll(resolvedIps.stream() 109 | .map(lookup -> new Client(lookup.getIp(), lookup.getDomainName())) 110 | .collect(Collectors.toList())); 111 | return this; 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/StatsService.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats; 2 | 3 | import java.time.Duration; 4 | import java.util.List; 5 | 6 | import io.spring.sample.dashboard.DashboardProperties; 7 | import io.spring.sample.dashboard.stats.support.Event; 8 | import io.spring.sample.dashboard.stats.support.GenerationStatistics; 9 | import io.spring.sample.dashboard.stats.support.GenerationStatisticsItem; 10 | import io.spring.sample.dashboard.stats.support.ReverseLookupDescriptor; 11 | import reactor.core.publisher.Flux; 12 | import reactor.core.publisher.Mono; 13 | 14 | import org.springframework.stereotype.Service; 15 | 16 | @Service 17 | public class StatsService { 18 | 19 | private final StatsClient statsClient; 20 | 21 | private final ReverseLookupClient lookupClient; 22 | 23 | private final Duration timeout; 24 | 25 | private final Flux liveStats; 26 | 27 | public StatsService(StatsClient statsClient, ReverseLookupClient lookupClient, 28 | DashboardProperties properties) { 29 | this.statsClient = statsClient; 30 | this.lookupClient = lookupClient; 31 | this.timeout = properties.getReverseLookup().getTimeout(); 32 | this.liveStats = statsClient.liveStats().share().cache(20); 33 | } 34 | 35 | public Mono fetchStats(String fromDate, String toDate) { 36 | Mono generationStats = statsClient.fetchGenerationStats(fromDate, toDate); 37 | Mono> events = statsClient.fetchEvents(fromDate, toDate).collectList(); 38 | Mono> topClients = fetchTopClients(fromDate, toDate).collectList(); 39 | return Mono.zip(generationStats, events, topClients).map(tuple -> { 40 | StatsContainer.Builder builder = StatsContainer.range(fromDate, toDate); 41 | builder.addSeries(tuple.getT1().getRecords()); 42 | builder.addAnnotations(tuple.getT2()); 43 | builder.addTopClients(tuple.getT3()); 44 | return builder.build(); 45 | }); 46 | } 47 | 48 | private Flux fetchTopClients(String fromDate, String toDate) { 49 | return statsClient.fetchGeneratorClients(fromDate, toDate) 50 | .flatMap(client -> lookupClient.freeReverseLookup(client.getIp()) 51 | .timeout(this.timeout, this.lookupClient.payingReverseLookup(client.getIp())) 52 | ); 53 | } 54 | 55 | public Flux fetchLiveStats() { 56 | return this.liveStats; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/DateRange.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class DateRange { 6 | 7 | private LocalDate from; 8 | 9 | private LocalDate to; 10 | 11 | public DateRange() { 12 | } 13 | 14 | public LocalDate getFrom() { 15 | return from; 16 | } 17 | 18 | public void setFrom(LocalDate from) { 19 | this.from = from; 20 | } 21 | 22 | public LocalDate getTo() { 23 | return to; 24 | } 25 | 26 | public void setTo(LocalDate to) { 27 | this.to = to; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/DateTimeRange.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | import org.springframework.format.annotation.DateTimeFormat; 9 | 10 | public class DateTimeRange { 11 | 12 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 13 | private LocalDateTime from; 14 | 15 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 16 | private LocalDateTime to; 17 | 18 | @JsonCreator 19 | public DateTimeRange(@JsonProperty("from") LocalDateTime from, @JsonProperty("to") LocalDateTime to) { 20 | this.from = from; 21 | this.to = to; 22 | } 23 | 24 | public LocalDateTime getFrom() { 25 | return this.from; 26 | } 27 | 28 | public void setFrom(LocalDateTime from) { 29 | this.from = from; 30 | } 31 | 32 | public LocalDateTime getTo() { 33 | return this.to; 34 | } 35 | 36 | public void setTo(LocalDateTime to) { 37 | this.to = to; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return "DateTimeRange{" + "from=" + from + ", to=" + to + '}'; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/Event.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import java.time.LocalDate; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | public class Event { 9 | 10 | private String name; 11 | 12 | private LocalDate date; 13 | 14 | private Type type; 15 | 16 | @JsonCreator 17 | public Event(@JsonProperty("name") String name, @JsonProperty("date") LocalDate date, @JsonProperty("type") Type type) { 18 | this.name = name; 19 | this.date = date; 20 | this.type = type; 21 | } 22 | 23 | public Event() { 24 | } 25 | 26 | public String getName() { 27 | return this.name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public LocalDate getDate() { 35 | return this.date; 36 | } 37 | 38 | public void setDate(LocalDate date) { 39 | this.date = date; 40 | } 41 | 42 | public Type getType() { 43 | return this.type; 44 | } 45 | 46 | public void setType(Type type) { 47 | this.type = type; 48 | } 49 | 50 | public enum Type { 51 | 52 | RELEASE, 53 | 54 | CONFERENCE, 55 | 56 | SOCIAL_OUTAGE, 57 | 58 | TOOLS_OUTAGE 59 | 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/GenerationStatistics.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import java.time.LocalDate; 4 | 5 | import com.fasterxml.jackson.annotation.JsonCreator; 6 | import com.fasterxml.jackson.annotation.JsonProperty; 7 | 8 | import org.springframework.util.LinkedMultiValueMap; 9 | import org.springframework.util.MultiValueMap; 10 | 11 | public class GenerationStatistics { 12 | 13 | private DateRange range; 14 | 15 | private LinkedMultiValueMap records; 16 | 17 | @JsonCreator 18 | public GenerationStatistics(@JsonProperty("range") DateRange range, 19 | @JsonProperty("entries") LinkedMultiValueMap records) { 20 | this.range = range; 21 | this.records = records; 22 | } 23 | 24 | public DateRange getRange() { 25 | return this.range; 26 | } 27 | 28 | public MultiValueMap getRecords() { 29 | return this.records; 30 | } 31 | 32 | public static class Record { 33 | 34 | private final LocalDate date; 35 | 36 | private final int projectsCount; 37 | 38 | @JsonCreator 39 | public Record(@JsonProperty("date") LocalDate date, @JsonProperty("projectsCount") int projectsCount) { 40 | this.date = date; 41 | this.projectsCount = projectsCount; 42 | } 43 | 44 | public LocalDate getDate() { 45 | return this.date; 46 | } 47 | 48 | public int getProjectsCount() { 49 | return this.projectsCount; 50 | } 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/GenerationStatisticsItem.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | public class GenerationStatisticsItem { 7 | 8 | private final DateTimeRange range; 9 | 10 | private final int projectsCount; 11 | 12 | @JsonCreator 13 | public GenerationStatisticsItem(@JsonProperty("range") DateTimeRange range, @JsonProperty("projectsCount") int projectsCount) { 14 | this.range = range; 15 | this.projectsCount = projectsCount; 16 | } 17 | 18 | public DateTimeRange getRange() { 19 | return this.range; 20 | } 21 | 22 | public int getProjectsCount() { 23 | return this.projectsCount; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/GeneratorClient.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | public class GeneratorClient { 4 | 5 | private String ip; 6 | 7 | public GeneratorClient() { 8 | } 9 | 10 | public GeneratorClient(String ip) { 11 | this.ip = ip; 12 | } 13 | 14 | public String getIp() { 15 | return ip; 16 | } 17 | 18 | public void setIp(String ip) { 19 | this.ip = ip; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /dashboard/src/main/java/io/spring/sample/dashboard/stats/support/ReverseLookupDescriptor.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard.stats.support; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonProperty; 5 | 6 | public class ReverseLookupDescriptor { 7 | 8 | private final String ip; 9 | private final String domainName; 10 | 11 | @JsonCreator 12 | ReverseLookupDescriptor(@JsonProperty("ip") String ip, @JsonProperty("domainName") String domainName) { 13 | this.ip = ip; 14 | this.domainName = domainName; 15 | } 16 | 17 | public String getIp() { 18 | return this.ip; 19 | } 20 | 21 | public String getDomainName() { 22 | return this.domainName; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.endpoints.web.exposure.include=* 2 | management.metrics.export.wavefront.step=15s 3 | wavefront.application.name=initializr-stats 4 | wavefront.application.service=dashboard 5 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bclozel/initializr-stats/f3daf53440fd5a6c15d8f2c2b88874ce87e8330f/dashboard/src/main/resources/keystore.jks -------------------------------------------------------------------------------- /dashboard/src/main/resources/static/images/springboot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bclozel/initializr-stats/f3daf53440fd5a6c15d8f2c2b88874ce87e8330f/dashboard/src/main/resources/static/images/springboot.png -------------------------------------------------------------------------------- /dashboard/src/main/resources/static/img/springboot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bclozel/initializr-stats/f3daf53440fd5a6c15d8f2c2b88874ce87e8330f/dashboard/src/main/resources/static/img/springboot.png -------------------------------------------------------------------------------- /dashboard/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Initializr Dashboard 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Initializr Dashboard 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Period 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | Submit 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Top HTTP clients by IP 63 | 64 | 65 | 66 | IP address 67 | Resolved Host name 68 | 69 | 70 | 71 | 72 | 127.0.0.1 73 | host.example.org 74 | 75 | 76 | 77 | 78 | 79 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/templates/live.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Initializr Dashboard 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Initializr Dashboard 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /dashboard/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Login 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Login 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /dashboard/src/test/java/io/spring/sample/dashboard/DashboardControllerTests.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.dashboard; 2 | 3 | import java.time.LocalDate; 4 | 5 | import io.spring.sample.dashboard.stats.StatsContainer; 6 | import io.spring.sample.dashboard.stats.StatsService; 7 | import org.junit.jupiter.api.Test; 8 | import reactor.core.publisher.Mono; 9 | 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 12 | import org.springframework.boot.test.mock.mockito.MockBean; 13 | import org.springframework.http.HttpHeaders; 14 | import org.springframework.security.test.context.support.WithMockUser; 15 | import org.springframework.test.web.servlet.MockMvc; 16 | 17 | import static org.mockito.BDDMockito.given; 18 | import static org.springframework.test.web.servlet.ResultMatcher.matchAll; 19 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 20 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; 21 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; 22 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 23 | 24 | @WebMvcTest(DashboardController.class) 25 | @WithMockUser 26 | class DashboardControllerTests { 27 | 28 | @Autowired 29 | private MockMvc mvc; 30 | 31 | @MockBean 32 | private StatsService statsService; 33 | 34 | @Test 35 | void indexShouldRedirectToThisWeek() throws Exception { 36 | String today = LocalDate.now().toString(); 37 | String aWeekAgo = LocalDate.now().minusDays(7).toString(); 38 | this.mvc.perform(get("/")).andExpect(matchAll(status().is(302), 39 | header().string(HttpHeaders.LOCATION, String.format("/stats/%s/%s", aWeekAgo, today)))); 40 | } 41 | 42 | @Test 43 | void showDashboardContainsStats() throws Exception { 44 | StatsContainer container = StatsContainer.range("2018-01-01", "2018-01-07").build(); 45 | given(statsService.fetchStats("2018-01-01", "2018-01-07")).willReturn(Mono.just(container)); 46 | this.mvc.perform(get("/stats/2018-01-01/2018-01-07")).andExpect(status().is(200)) 47 | .andExpect(matchAll(status().isOk(), 48 | model().attribute("fromDate", LocalDate.of(2018, 1, 1)), 49 | model().attribute("toDate", LocalDate.of(2018, 1, 7)), 50 | model().attribute("stats", container))); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /generator/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /generator/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.4.4 10 | 11 | 12 | io.spring.sample 13 | generator 14 | 0.0.1-SNAPSHOT 15 | jar 16 | generator 17 | App generating fake data for Initializr stats 18 | 19 | 20 | 11 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-webflux 31 | 32 | 33 | org.springframework.boot 34 | spring-boot-starter-actuator 35 | 36 | 37 | com.wavefront 38 | wavefront-spring-boot-starter 39 | 40 | 41 | com.github.vladimir-bukhtoyarov 42 | bucket4j-core 43 | 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-configuration-processor 48 | true 49 | 50 | 51 | org.springframework.boot 52 | spring-boot-starter-test 53 | test 54 | 55 | 56 | io.projectreactor 57 | reactor-test 58 | test 59 | 60 | 61 | 62 | 63 | 64 | 65 | com.github.vladimir-bukhtoyarov 66 | bucket4j-core 67 | 6.2.0 68 | 69 | 70 | com.wavefront 71 | wavefront-spring-boot-bom 72 | 2.1.0 73 | pom 74 | import 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.springframework.boot 83 | spring-boot-maven-plugin 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/DataSet.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.DayOfWeek; 4 | import java.time.LocalDate; 5 | 6 | public class DataSet { 7 | 8 | private DateRange range; 9 | 10 | private final Data data = new Data(); 11 | 12 | public int getBase(LocalDate localDate) { 13 | return 100; // TODO 14 | } 15 | 16 | public DateRange getRange() { 17 | return this.range; 18 | } 19 | 20 | public void setRange(DateRange range) { 21 | this.range = range; 22 | } 23 | 24 | public Data getData() { 25 | return this.data; 26 | } 27 | 28 | public static class Data { 29 | 30 | private int monday; 31 | 32 | private int tuesday; 33 | 34 | private int wednesday; 35 | 36 | private int thursday; 37 | 38 | private int friday; 39 | 40 | private int saturday; 41 | 42 | private int sunday; 43 | 44 | public int get(DayOfWeek dayOfWeek) { 45 | switch (dayOfWeek) { 46 | case MONDAY: return this.monday; 47 | case TUESDAY: return this.tuesday; 48 | case WEDNESDAY: return this.wednesday; 49 | case THURSDAY: return this.thursday; 50 | case FRIDAY: return this.friday; 51 | case SATURDAY: return this.saturday; 52 | case SUNDAY: return this.sunday; 53 | default: throw new IllegalArgumentException(); 54 | } 55 | } 56 | 57 | public int getMonday() { 58 | return this.monday; 59 | } 60 | 61 | public void setMonday(int monday) { 62 | this.monday = monday; 63 | } 64 | 65 | public int getTuesday() { 66 | return this.tuesday; 67 | } 68 | 69 | public void setTuesday(int tuesday) { 70 | this.tuesday = tuesday; 71 | } 72 | 73 | public int getWednesday() { 74 | return this.wednesday; 75 | } 76 | 77 | public void setWednesday(int wednesday) { 78 | this.wednesday = wednesday; 79 | } 80 | 81 | public int getThursday() { 82 | return this.thursday; 83 | } 84 | 85 | public void setThursday(int thursday) { 86 | this.thursday = thursday; 87 | } 88 | 89 | public int getFriday() { 90 | return this.friday; 91 | } 92 | 93 | public void setFriday(int friday) { 94 | this.friday = friday; 95 | } 96 | 97 | public int getSaturday() { 98 | return this.saturday; 99 | } 100 | 101 | public void setSaturday(int saturday) { 102 | this.saturday = saturday; 103 | } 104 | 105 | public int getSunday() { 106 | return this.sunday; 107 | } 108 | 109 | public void setSunday(int sunday) { 110 | this.sunday = sunday; 111 | } 112 | 113 | } 114 | 115 | @Override 116 | public String toString() { 117 | return "DataSet{" + "range=" + range + '}'; 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/DateRange.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.LocalDate; 4 | 5 | import org.springframework.format.annotation.DateTimeFormat; 6 | 7 | public class DateRange { 8 | 9 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 10 | private LocalDate from; 11 | 12 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 13 | private LocalDate to; 14 | 15 | public DateRange(LocalDate from, LocalDate to) { 16 | this.from = from; 17 | this.to = to; 18 | } 19 | 20 | public DateRange() { 21 | } 22 | 23 | public LocalDate getFrom() { 24 | return this.from; 25 | } 26 | 27 | public void setFrom(LocalDate from) { 28 | this.from = from; 29 | } 30 | 31 | public LocalDate getTo() { 32 | return this.to; 33 | } 34 | 35 | public void setTo(LocalDate to) { 36 | this.to = to; 37 | } 38 | 39 | 40 | public boolean match(DateRange anotherRange) { 41 | boolean rangeIncluded = isRangeIncluded(anotherRange); 42 | boolean withinRange = isWithinRange(anotherRange); 43 | return rangeIncluded || withinRange; 44 | } 45 | 46 | public boolean match(LocalDate date) { 47 | return isAfterOrEqual(date, from) 48 | && isBeforeOrEqual(date, to); 49 | } 50 | 51 | private boolean isRangeIncluded(DateRange anotherRange) { 52 | return isBeforeOrEqual(anotherRange.getFrom(), getFrom()) 53 | && isAfterOrEqual(anotherRange.getTo(), getTo()); 54 | } 55 | 56 | private boolean isWithinRange(DateRange anotherRange) { 57 | return isWithinRange(anotherRange.getFrom()) 58 | || (isWithinRange(anotherRange.getTo())); 59 | } 60 | 61 | private boolean isWithinRange(LocalDate date) { 62 | return isAfterOrEqual(date, getFrom()) 63 | && isBeforeOrEqual(date, getTo()); 64 | } 65 | 66 | private boolean isAfterOrEqual(LocalDate left, LocalDate right) { 67 | return left.isEqual(right) || left.isAfter(right); 68 | } 69 | 70 | private boolean isBeforeOrEqual(LocalDate left, LocalDate right) { 71 | return left.isEqual(right) || left.isBefore(right); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "DateRange{" + "from=" + from 77 | + ", to=" + to 78 | + '}'; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/DateTimeRange.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.springframework.format.annotation.DateTimeFormat; 6 | 7 | public class DateTimeRange { 8 | 9 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 10 | private LocalDateTime from; 11 | 12 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) 13 | private LocalDateTime to; 14 | 15 | public DateTimeRange(LocalDateTime from, LocalDateTime to) { 16 | this.from = from; 17 | this.to = to; 18 | } 19 | 20 | public LocalDateTime getFrom() { 21 | return this.from; 22 | } 23 | 24 | public void setFrom(LocalDateTime from) { 25 | this.from = from; 26 | } 27 | 28 | public LocalDateTime getTo() { 29 | return this.to; 30 | } 31 | 32 | public void setTo(LocalDateTime to) { 33 | this.to = to; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "DateTimeRange{" + "from=" + from + ", to=" + to + '}'; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/Event.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.LocalDate; 4 | import java.util.function.Function; 5 | 6 | import org.springframework.format.annotation.DateTimeFormat; 7 | 8 | public class Event { 9 | 10 | private String name; 11 | 12 | @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 13 | private LocalDate date; 14 | 15 | private Type type; 16 | 17 | public Event(String name, LocalDate date, Type type) { 18 | this.name = name; 19 | this.date = date; 20 | this.type = type; 21 | } 22 | 23 | public Event() { 24 | } 25 | 26 | public String getName() { 27 | return this.name; 28 | } 29 | 30 | public void setName(String name) { 31 | this.name = name; 32 | } 33 | 34 | public LocalDate getDate() { 35 | return this.date; 36 | } 37 | 38 | public void setDate(LocalDate date) { 39 | this.date = date; 40 | } 41 | 42 | public Type getType() { 43 | return this.type; 44 | } 45 | 46 | public void setType(Type type) { 47 | this.type = type; 48 | } 49 | 50 | public enum Type { 51 | 52 | RELEASE((value) -> Math.round(value * 1.1)), 53 | 54 | CONFERENCE((value) -> Math.round(value * 0.8)), 55 | 56 | SOCIAL_OUTAGE((value) -> Math.round(value * 1.4)), 57 | 58 | TOOLS_OUTAGE((value) -> Math.round(value * 0.4)); 59 | 60 | private final Function impact; 61 | 62 | Type(Function impact) { 63 | this.impact = impact; 64 | } 65 | 66 | public long transformValue(long value) { 67 | return this.impact.apply(value); 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GenerationStatistics.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.LocalDate; 4 | 5 | import org.springframework.util.MultiValueMap; 6 | 7 | public class GenerationStatistics { 8 | 9 | private final DateRange range; 10 | 11 | private final MultiValueMap entries; 12 | 13 | GenerationStatistics(DateRange range, MultiValueMap entries) { 14 | this.range = range; 15 | this.entries = entries; 16 | } 17 | 18 | public DateRange getRange() { 19 | return this.range; 20 | } 21 | 22 | public MultiValueMap getEntries() { 23 | return this.entries; 24 | } 25 | 26 | public static class Entry { 27 | 28 | private final LocalDate date; 29 | 30 | private final long projectsCount; 31 | 32 | public Entry(LocalDate date, long projectsCount) { 33 | this.date = date; 34 | this.projectsCount = projectsCount; 35 | } 36 | 37 | public LocalDate getDate() { 38 | return this.date; 39 | } 40 | 41 | public long getProjectsCount() { 42 | return this.projectsCount; 43 | } 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GenerationStatisticsItem.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | public class GenerationStatisticsItem { 4 | 5 | private final DateTimeRange range; 6 | 7 | private final int projectsCount; 8 | 9 | GenerationStatisticsItem(DateTimeRange range, int projectsCount) { 10 | this.range = range; 11 | this.projectsCount = projectsCount; 12 | } 13 | 14 | public DateTimeRange getRange() { 15 | return this.range; 16 | } 17 | 18 | public int getProjectsCount() { 19 | return this.projectsCount; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/Generator.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.Duration; 4 | import java.time.LocalDate; 5 | import java.time.LocalDateTime; 6 | import java.time.LocalTime; 7 | import java.time.temporal.ChronoUnit; 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | import java.util.Random; 12 | import java.util.function.Predicate; 13 | import java.util.stream.Collectors; 14 | import java.util.stream.IntStream; 15 | 16 | import reactor.core.publisher.Flux; 17 | 18 | import org.springframework.util.LinkedMultiValueMap; 19 | import org.springframework.util.MultiValueMap; 20 | 21 | public class Generator { 22 | 23 | private static final Random random = new Random(); 24 | 25 | private final List dataSets; 26 | 27 | private final List releases; 28 | 29 | private final List events; 30 | 31 | private Latency latency; 32 | 33 | public Generator(List dataSets, 34 | List releases, List events) { 35 | this.dataSets = new ArrayList<>(dataSets); 36 | this.releases = new ArrayList<>(releases); 37 | this.events = new ArrayList<>(events); 38 | this.latency = new Latency(); 39 | } 40 | 41 | public GenerationStatistics generateStatistics(DateRange range) { 42 | return new RandomGenerator(range).generate(); 43 | } 44 | 45 | public Flux generateLiveStatistics(Duration periodicity) { 46 | return Flux.interval(Duration.ZERO, periodicity) 47 | .map(i -> generateCurrentTimestamp(periodicity)).map(timestamp -> { 48 | LocalDate date = timestamp.toLocalDate(); 49 | RandomGenerator generator = new RandomGenerator( 50 | new DateRange(date, date)); 51 | return generator.generateItem(timestamp, periodicity); 52 | }).share(); 53 | } 54 | 55 | private LocalDateTime generateCurrentTimestamp(Duration periodicity) { 56 | LocalDateTime now = LocalDateTime.now(); 57 | int periodicitySeconds = (int) periodicity.getSeconds(); 58 | return now.withSecond((now.getSecond() / periodicitySeconds) * periodicitySeconds) 59 | .withNano(0); 60 | } 61 | 62 | public List getDataSets(DateRange dateRange) { 63 | return this.dataSets.stream() 64 | .filter(dataSetMatch(dateRange)) 65 | .collect(Collectors.toList()); 66 | } 67 | 68 | public List getReleases(DateRange dateRange) { 69 | return this.releases.stream() 70 | .filter(releaseMatch(dateRange)) 71 | .collect(Collectors.toList()); 72 | } 73 | 74 | public List getEvents(DateRange dateRange) { 75 | return this.events.stream() 76 | .filter(eventMatch(dateRange)) 77 | .collect(Collectors.toList()); 78 | } 79 | 80 | public List getTopIps(DateRange dateRange) { 81 | return IntStream.range(0, 10).mapToObj((i) -> new GeneratorClient(randomIp())) 82 | .collect(Collectors.toList()); 83 | } 84 | 85 | public Latency getLatency() { 86 | return this.latency; 87 | } 88 | 89 | public void updateLatency(Float ratio, Integer latencyMin, Integer latencyMax) { 90 | float newRatio = (ratio != null ? ratio : this.latency.ratio); 91 | int newMin = (latencyMin != null ? latencyMin : this.latency.latencyMin); 92 | int newMax = (latencyMax != null ? latencyMax : this.latency.latencyMax); 93 | this.latency = new Latency(newRatio, newMin, newMax); 94 | } 95 | 96 | private String randomIp() { 97 | StringBuilder sb = new StringBuilder("10."); 98 | sb.append(random.nextInt(255)).append(".") 99 | .append(random.nextInt(255)).append(".") 100 | .append(random.nextInt(255)); 101 | return sb.toString(); 102 | } 103 | 104 | private MultiValueMap indexEvents(DateRange range) { 105 | MultiValueMap events = new LinkedMultiValueMap<>(); 106 | getEvents(range).forEach((event) -> events.add(event.getDate(), event)); 107 | return events; 108 | } 109 | 110 | private Predicate dataSetMatch(DateRange range) { 111 | return (dataSet) -> dataSet.getRange().match(range); 112 | } 113 | 114 | private Predicate releaseMatch(DateRange range) { 115 | return (release) -> release.getRange().match(range); 116 | } 117 | 118 | private Predicate eventMatch(DateRange range) { 119 | return (event) -> range.match(event.getDate()); 120 | } 121 | 122 | private class RandomGenerator { 123 | 124 | private final DateRange range; 125 | 126 | private final List releases; 127 | 128 | private final List dataSets; 129 | 130 | private final MultiValueMap events; 131 | 132 | RandomGenerator(DateRange range) { 133 | this.range = range; 134 | this.releases = getReleases(range); 135 | this.dataSets = getDataSets(range); 136 | this.events = indexEvents(range); 137 | if (releases.isEmpty() || dataSets.isEmpty()) { 138 | throw new IllegalArgumentException("No available information for range " + range); 139 | } 140 | } 141 | 142 | GenerationStatistics generate() { 143 | Iterator releasesIt = releases.iterator(); 144 | Release currentRelease = releasesIt.next(); 145 | Iterator dataSetsIt = dataSets.iterator(); 146 | DataSet currentDataSet = dataSetsIt.next(); 147 | MultiValueMap entries = new LinkedMultiValueMap<>(); 148 | LocalDate currentDay = range.getFrom(); 149 | while (!currentDay.isAfter(range.getTo())) { 150 | if (!currentRelease.getRange().match(currentDay)) { 151 | if (!releasesIt.hasNext()) { 152 | throw new IllegalArgumentException("No release information for " + currentDay); 153 | } 154 | currentRelease = releasesIt.next(); 155 | } 156 | if (!currentDataSet.getRange().match(currentDay)) { 157 | if (!dataSetsIt.hasNext()) { 158 | throw new IllegalArgumentException("No data information for " + currentDay); 159 | } 160 | currentDataSet = dataSetsIt.next(); 161 | } 162 | int total = currentDataSet.getData().get(currentDay.getDayOfWeek()); 163 | String next = currentRelease.getData().getNext(); 164 | double currentRatio = (next != null ? 0.9 : 0.92); 165 | entries.add(currentRelease.getData().getCurrent(), randomValueForDay(currentDay, total, currentRatio)); 166 | if (currentRelease.getData().getMaintenance() != null) { 167 | double maintenanceRatio = (next != null ? 0.08 : 0.1); 168 | entries.add(currentRelease.getData().getMaintenance(), randomValueForDay(currentDay, total, maintenanceRatio)); 169 | } 170 | if (currentRelease.getData().getNext() != null) { 171 | double nextRatio = (next != null ? 0.02 : 0); 172 | entries.add(next, randomValueForDay(currentDay, total, nextRatio)); 173 | } 174 | currentDay = currentDay.plusDays(1); 175 | } 176 | return new GenerationStatistics(range, entries); 177 | } 178 | 179 | GenerationStatisticsItem generateItem(LocalDateTime timestamp, Duration periodicity) { 180 | if (timestamp.isBefore(this.range.getFrom().atStartOfDay()) 181 | || timestamp.isAfter(this.range.getTo().atTime(LocalTime.MAX))) { 182 | throw new IllegalArgumentException(String.format( 183 | "Timestamp %s not within range %s", timestamp, this.range)); 184 | } 185 | int dayTotal = dataSets.get(0).getData().get(timestamp.getDayOfWeek()); 186 | double ratio = (double) periodicity.toMillis() / Duration.ofDays(1).toMillis(); 187 | int total = (int) Math.ceil(dayTotal * ratio); 188 | DateTimeRange range = new DateTimeRange(timestamp, 189 | timestamp.plus(periodicity.getSeconds(), ChronoUnit.SECONDS)); 190 | return new GenerationStatisticsItem(range, randomValueForPeriodicity(timestamp, total)); 191 | } 192 | 193 | private int randomValueForPeriodicity(LocalDateTime timestamp, int total) { 194 | int ratio = 1; 195 | int hour = timestamp.getHour(); 196 | if (hour > 8 && hour < 18) { 197 | double workingHoursRatio = (random.nextFloat() < 0.4 ? 2 : 1); 198 | ratio *= workingHoursRatio; 199 | } 200 | return random.nextInt(total * ratio); 201 | } 202 | 203 | // very scientific measure 204 | private GenerationStatistics.Entry randomValueForDay(LocalDate day, int total, double ratio) { 205 | double value = ratio * total; 206 | value = value - (value * 0.05); 207 | value = value + (value * random.nextFloat() / 10); 208 | return new GenerationStatistics.Entry(day, applyEvents(day, (long) value)); 209 | } 210 | 211 | private long applyEvents(LocalDate date, long value) { 212 | List dateEvents = this.events.get(date); 213 | if (dateEvents != null) { 214 | long original = value; 215 | for (Event event : dateEvents) { 216 | value = event.getType().transformValue(original); 217 | } 218 | } 219 | return value; 220 | } 221 | 222 | } 223 | 224 | public static final class Latency { 225 | 226 | private final float ratio; 227 | 228 | private final int latencyMin; 229 | 230 | private final int latencyMax; 231 | 232 | Latency(float ratio, int latencyMin, int latencyMax) { 233 | this.ratio = ratio; 234 | this.latencyMin = latencyMin; 235 | this.latencyMax = latencyMax; 236 | } 237 | 238 | Latency() { 239 | this(0.0f, 200, 8000); 240 | } 241 | 242 | public Duration randomLatency() { 243 | boolean apply = random.nextFloat() < ratio; 244 | return apply ? generateRandomLatency() : Duration.ZERO; 245 | } 246 | 247 | public float getRatio() { 248 | return this.ratio; 249 | } 250 | 251 | public int getLatencyMin() { 252 | return this.latencyMin; 253 | } 254 | 255 | public int getLatencyMax() { 256 | return this.latencyMax; 257 | } 258 | 259 | private Duration generateRandomLatency() { 260 | int ms = random.nextInt(latencyMax - latencyMin) + latencyMin; 261 | return Duration.ofMillis(ms); 262 | } 263 | 264 | } 265 | 266 | } 267 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GeneratorApplication.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class GeneratorApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(GeneratorApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GeneratorClient.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | public class GeneratorClient { 4 | 5 | private String ip; 6 | 7 | public GeneratorClient() { 8 | } 9 | 10 | public GeneratorClient(String ip) { 11 | this.ip = ip; 12 | } 13 | 14 | public String getIp() { 15 | return ip; 16 | } 17 | 18 | public void setIp(String ip) { 19 | this.ip = ip; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GeneratorConfiguration.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | @Configuration 8 | @EnableConfigurationProperties(GeneratorProperties.class) 9 | class GeneratorConfiguration { 10 | 11 | private final GeneratorProperties properties; 12 | 13 | GeneratorConfiguration(GeneratorProperties properties) { 14 | this.properties = properties; 15 | } 16 | 17 | @Bean 18 | public Generator generatorMetadata() { 19 | return new Generator(this.properties.getDataSets(), 20 | this.properties.getReleases(), this.properties.getEvents()); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/GeneratorProperties.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | 8 | @ConfigurationProperties("initializr.stats.generator") 9 | public class GeneratorProperties { 10 | 11 | private List dataSets = new ArrayList<>(); 12 | 13 | private List releases = new ArrayList<>(); 14 | 15 | private List events = new ArrayList<>(); 16 | 17 | public List getDataSets() { 18 | return this.dataSets; 19 | } 20 | 21 | public void setDataSets(List dataSets) { 22 | this.dataSets = dataSets; 23 | } 24 | 25 | public List getReleases() { 26 | return this.releases; 27 | } 28 | 29 | public void setReleases(List releases) { 30 | this.releases = releases; 31 | } 32 | 33 | public List getEvents() { 34 | return this.events; 35 | } 36 | 37 | public void setEvents(List events) { 38 | this.events = events; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/Release.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | public class Release { 4 | 5 | private DateRange range; 6 | 7 | private final Data data = new Data(); 8 | 9 | public DateRange getRange() { 10 | return this.range; 11 | } 12 | 13 | public void setRange(DateRange range) { 14 | this.range = range; 15 | } 16 | 17 | public Data getData() { 18 | return this.data; 19 | } 20 | 21 | public static class Data { 22 | 23 | private String maintenance; 24 | 25 | private String current; 26 | 27 | private String next; 28 | 29 | public String getMaintenance() { 30 | return this.maintenance; 31 | } 32 | 33 | public void setMaintenance(String maintenance) { 34 | this.maintenance = maintenance; 35 | } 36 | 37 | public String getCurrent() { 38 | return this.current; 39 | } 40 | 41 | public void setCurrent(String current) { 42 | this.current = current; 43 | } 44 | 45 | public String getNext() { 46 | return this.next; 47 | } 48 | 49 | public void setNext(String next) { 50 | this.next = next; 51 | } 52 | 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/management/LatencyEndpoint.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.management; 2 | 3 | 4 | import io.spring.sample.generator.Generator; 5 | 6 | import org.springframework.boot.actuate.endpoint.annotation.Endpoint; 7 | import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; 8 | import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; 9 | import org.springframework.lang.Nullable; 10 | import org.springframework.stereotype.Component; 11 | 12 | /** 13 | * Custom {@link Endpoint} to control the latency of reverse lookups. 14 | * 15 | * @author Stephane Nicoll 16 | */ 17 | @Component 18 | @Endpoint(id = "latency") 19 | public class LatencyEndpoint { 20 | 21 | private final Generator generator; 22 | 23 | public LatencyEndpoint(Generator generator) { 24 | this.generator = generator; 25 | } 26 | 27 | @ReadOperation 28 | public Generator.Latency currentLatency() { 29 | return this.generator.getLatency(); 30 | } 31 | 32 | @WriteOperation 33 | public void updateLatency(@Nullable Float ratio, @Nullable Integer latencyMin, 34 | @Nullable Integer latencyMax) { 35 | this.generator.updateLatency(ratio, latencyMin, latencyMax); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/web/GeneratorController.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.web; 2 | 3 | import java.time.Duration; 4 | import java.time.LocalDate; 5 | import java.util.List; 6 | 7 | import io.github.bucket4j.Bucket; 8 | import io.spring.sample.generator.DateRange; 9 | import io.spring.sample.generator.Event; 10 | import io.spring.sample.generator.GenerationStatistics; 11 | import io.spring.sample.generator.GenerationStatisticsItem; 12 | import io.spring.sample.generator.Generator; 13 | import io.spring.sample.generator.GeneratorClient; 14 | import reactor.core.publisher.Flux; 15 | import reactor.core.publisher.Mono; 16 | 17 | import org.springframework.http.HttpStatus; 18 | import org.springframework.http.MediaType; 19 | import org.springframework.http.ResponseEntity; 20 | import org.springframework.web.bind.annotation.GetMapping; 21 | import org.springframework.web.bind.annotation.PathVariable; 22 | import org.springframework.web.bind.annotation.RequestAttribute; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | @RestController 26 | public class GeneratorController { 27 | 28 | private final Generator generator; 29 | 30 | private final Flux liveStatistics; 31 | 32 | public GeneratorController(Generator generator) { 33 | this.generator = generator; 34 | this.liveStatistics = generator.generateLiveStatistics(Duration.ofSeconds(5)); 35 | } 36 | 37 | @GetMapping("/statistics/{from}/{to}") 38 | public GenerationStatistics statistics(@PathVariable LocalDate from, 39 | @PathVariable LocalDate to) { 40 | DateRange range = new DateRange(from, to); 41 | return this.generator.generateStatistics(range); 42 | } 43 | 44 | @GetMapping(path = "/live-statistics", produces = MediaType.APPLICATION_NDJSON_VALUE) 45 | public Flux liveStatistics() { 46 | return this.liveStatistics; 47 | } 48 | 49 | @GetMapping("/events/{from}/{to}") 50 | public List events(@PathVariable LocalDate from, 51 | @PathVariable LocalDate to) { 52 | DateRange range = new DateRange(from, to); 53 | return this.generator.getEvents(range); 54 | } 55 | 56 | @GetMapping("/top-ips/{from}/{to}") 57 | public List topIps(@PathVariable LocalDate from, 58 | @PathVariable LocalDate to) { 59 | DateRange range = new DateRange(from, to); 60 | return this.generator.getTopIps(range); 61 | } 62 | 63 | @GetMapping("/reverse-lookup/costly/{ip}") 64 | public ReverseLookupDescriptor costlyReverseLookup(@PathVariable String ip) { 65 | return new ReverseLookupDescriptor(ip, ip + ".example.com"); 66 | } 67 | 68 | @GetMapping("/reverse-lookup/free/{ip}") 69 | public ResponseEntity> freeReverseLookup( 70 | @RequestAttribute("RateLimiterBucket") Bucket bucket, 71 | @PathVariable String ip) { 72 | 73 | if (bucket.tryConsume(1)) { 74 | return ResponseEntity.ok() 75 | .header("X-RateLimit-Remaining", String.valueOf(bucket.getAvailableTokens())) 76 | .body(Mono.just(costlyReverseLookup(ip)) 77 | .delayElement(this.generator.getLatency().randomLatency())); 78 | } 79 | return ResponseEntity.status(HttpStatus.FORBIDDEN) 80 | .header("X-RateLimit-Remaining", "0") 81 | .build(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/web/GeneratorWebConfiguration.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.web; 2 | 3 | import java.time.Duration; 4 | import java.util.function.Function; 5 | 6 | import io.github.bucket4j.Bandwidth; 7 | import io.github.bucket4j.Bucket; 8 | import io.github.bucket4j.Bucket4j; 9 | 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(GeneratorWebProperties.class) 17 | public class GeneratorWebConfiguration implements WebMvcConfigurer { 18 | 19 | private final GeneratorWebProperties properties; 20 | 21 | public GeneratorWebConfiguration(GeneratorWebProperties properties) { 22 | this.properties = properties; 23 | } 24 | 25 | @Override 26 | public void addInterceptors(InterceptorRegistry registry) { 27 | registry.addInterceptor(new RateLimiterHandlerInterceptor( 28 | bucketFactory(this.properties.getReverselookup().getCapacity(), 29 | this.properties.getReverselookup().getPeriod()))); 30 | } 31 | 32 | private Function bucketFactory(int capacity, Duration period) { 33 | return (remoteAddr) -> { 34 | Bandwidth limit = Bandwidth.simple(capacity, period); 35 | return Bucket4j.builder().addLimit(limit).build(); 36 | }; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/web/GeneratorWebProperties.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.web; 2 | 3 | import java.time.Duration; 4 | 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | 7 | /** 8 | * @author Stephane Nicoll 9 | */ 10 | @ConfigurationProperties("initializr.stats.generator.web") 11 | public class GeneratorWebProperties { 12 | 13 | private final Reverselookup reverselookup = new Reverselookup(); 14 | 15 | public Reverselookup getReverselookup() { 16 | return this.reverselookup; 17 | } 18 | 19 | public static class Reverselookup { 20 | 21 | /** 22 | * Number of calls per time window. 23 | */ 24 | private int capacity = 25; 25 | 26 | /** 27 | * Duration of the time window. 28 | */ 29 | private Duration period = Duration.ofSeconds(10); 30 | 31 | public int getCapacity() { 32 | return this.capacity; 33 | } 34 | 35 | public void setCapacity(int capacity) { 36 | this.capacity = capacity; 37 | } 38 | 39 | public Duration getPeriod() { 40 | return this.period; 41 | } 42 | 43 | public void setPeriod(Duration period) { 44 | this.period = period; 45 | } 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/web/RateLimiterHandlerInterceptor.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.web; 2 | 3 | import java.util.concurrent.ConcurrentHashMap; 4 | import java.util.function.Function; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import io.github.bucket4j.Bucket; 10 | 11 | import org.springframework.web.servlet.HandlerInterceptor; 12 | 13 | class RateLimiterHandlerInterceptor implements HandlerInterceptor { 14 | 15 | private static final String SESSION_BUCKET_ATTRIBUTE = "RateLimiterBucket"; 16 | 17 | private final ConcurrentHashMap buckets = new ConcurrentHashMap<>(); 18 | 19 | private final Function bucketFactory; 20 | 21 | RateLimiterHandlerInterceptor(Function bucketFactory) { 22 | this.bucketFactory = bucketFactory; 23 | } 24 | 25 | @Override 26 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 27 | Object handler) { 28 | String remoteHost = request.getRemoteHost(); 29 | Bucket bucket = buckets.computeIfAbsent(remoteHost, this.bucketFactory); 30 | request.setAttribute(SESSION_BUCKET_ATTRIBUTE, bucket); 31 | return true; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /generator/src/main/java/io/spring/sample/generator/web/ReverseLookupDescriptor.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator.web; 2 | 3 | class ReverseLookupDescriptor { 4 | 5 | private final String ip; 6 | private final String domainName; 7 | 8 | ReverseLookupDescriptor(String ip, String domainName) { 9 | this.ip = ip; 10 | this.domainName = domainName; 11 | } 12 | 13 | public String getIp() { 14 | return this.ip; 15 | } 16 | 17 | public String getDomainName() { 18 | return this.domainName; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /generator/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | initializr: 2 | stats: 3 | generator: 4 | datasets: 5 | - range: 6 | from: 2014-01-01 7 | to: 2018-12-31 8 | data: 9 | monday: 2000 10 | tuesday: 3000 11 | wednesday: 3000 12 | thursday: 4000 13 | friday: 1500 14 | saturday: 700 15 | sunday: 300 16 | - range: 17 | from: 2019-01-01 18 | to: 2019-03-31 19 | data: 20 | monday: 15000 21 | tuesday: 17000 22 | wednesday: 17000 23 | thursday: 22000 24 | friday: 15000 25 | saturday: 9000 26 | sunday: 7000 27 | - range: 28 | from: 2019-04-01 29 | to: 2019-06-30 30 | data: 31 | monday: 35000 32 | tuesday: 37000 33 | wednesday: 37000 34 | thursday: 42000 35 | friday: 35000 36 | saturday: 17000 37 | sunday: 15000 38 | - range: 39 | from: 2019-07-01 40 | to: 2019-09-30 41 | data: 42 | monday: 37000 43 | tuesday: 39000 44 | wednesday: 39000 45 | thursday: 42000 46 | friday: 37000 47 | saturday: 18000 48 | sunday: 16000 49 | - range: 50 | from: 2019-10-01 51 | to: 2019-12-31 52 | data: 53 | monday: 39000 54 | tuesday: 42000 55 | wednesday: 42000 56 | thursday: 45000 57 | friday: 39000 58 | saturday: 18000 59 | sunday: 16000 60 | - range: 61 | from: 2020-01-01 62 | to: 2020-12-31 63 | data: 64 | monday: 40000 65 | tuesday: 44000 66 | wednesday: 44000 67 | thursday: 47000 68 | friday: 41000 69 | saturday: 20000 70 | sunday: 19000 71 | - range: 72 | from: 2021-01-01 73 | to: 2021-12-31 74 | data: 75 | monday: 42000 76 | tuesday: 45000 77 | wednesday: 46000 78 | thursday: 49000 79 | friday: 43000 80 | saturday: 22000 81 | sunday: 20000 82 | releases: 83 | - range: 84 | from: 2019-10-16 85 | to: 2020-05-15 86 | data: 87 | maintenance: 2.1.x 88 | current: 2.2.x 89 | next: 2.3.x 90 | - range: 91 | from: 2020-05-15 92 | to: 2020-10-01 93 | data: 94 | maintenance: 2.2.x 95 | current: 2.3.x 96 | next: 2.4.x 97 | - range: 98 | from: 2020-11-01 99 | to: 2021-05-01 100 | data: 101 | maintenance: 2.3.x 102 | current: 2.4.x 103 | next: 2.5.x 104 | - range: 105 | from: 2021-05-01 106 | to: 2021-10-01 107 | data: 108 | maintenance: 2.4.x 109 | current: 2.5.x 110 | next: 2.6.x 111 | events: 112 | - name: "SpringOne Platform" 113 | date: 2019-10-07 114 | type: conference 115 | - name: "Spring Boot 2.3.0.RELEASE" 116 | date: 2020-05-15 117 | type: release 118 | - name: "Spring Boot 2.4.0" 119 | date: 2020-11-12 120 | type: release 121 | - name: "Spring Boot 2.4.4" 122 | date: 2021-03-18 123 | type: release 124 | - name: "Slack Down" 125 | date: 2021-04-06 126 | type: tools_outage 127 | - name: "SUG Italy" 128 | date: 2021-04-08 129 | type: conference 130 | 131 | management: 132 | endpoints: 133 | web: 134 | exposure: 135 | include: "*" 136 | metrics: 137 | tags: 138 | application: initializr-stats-generator 139 | 140 | server: 141 | port: 8081 142 | 143 | spring: 144 | mvc: 145 | format: 146 | date: yyyy-MM-dd 147 | 148 | wavefront: 149 | application: 150 | name: initializr-stats 151 | service: generator 152 | -------------------------------------------------------------------------------- /generator/src/test/java/io/spring/sample/generator/GeneratorTests.java: -------------------------------------------------------------------------------- 1 | package io.spring.sample.generator; 2 | 3 | import java.time.LocalDate; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.junit.jupiter.api.Test; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | class GeneratorTests { 12 | 13 | private final DataSet data2016 = sampleDataSet(LocalDate.of(2016, 1, 1), LocalDate.of(2016, 12, 31)); 14 | 15 | private final DataSet data2017 = sampleDataSet(LocalDate.of(2017, 1, 1), LocalDate.of(2017, 12, 31)); 16 | 17 | private final DataSet data2018 = sampleDataSet(LocalDate.of(2018, 1, 1), LocalDate.of(2018, 12, 31)); 18 | 19 | private final Release sb15 = release(LocalDate.of(2017, 5, 1), LocalDate.of(2018, 3, 1), "1.5.x"); 20 | 21 | private final Release sb20 = release(LocalDate.of(2018, 3, 1), LocalDate.of(2018, 10, 1), "2.0.x"); 22 | 23 | private final Event event2016 = new Event("Test", LocalDate.of(2016, 5, 1), Event.Type.RELEASE); 24 | 25 | private final Event event2017 = new Event("Test", LocalDate.of(2017, 6, 1), Event.Type.RELEASE); 26 | 27 | private final Generator metadata = new Generator( 28 | Arrays.asList(data2016, data2017, data2018), 29 | Arrays.asList(sb15, sb20), 30 | Arrays.asList(event2016, event2017)); 31 | 32 | 33 | @Test 34 | void getDataSetsNoMatch() { 35 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2013, 1, 5), 36 | LocalDate.of(2014, 5, 12)))).hasSize(0); 37 | } 38 | 39 | @Test 40 | void getDataSetsSingleRangeMatch() { 41 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2016, 1, 5), 42 | LocalDate.of(2016, 5, 12)))).containsExactly(data2016); 43 | } 44 | 45 | @Test 46 | void getDataSetsSingleRangeMatchExactFrom() { 47 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2016, 1, 1), 48 | LocalDate.of(2016, 5, 12)))).containsExactly(data2016); 49 | } 50 | 51 | @Test 52 | void getDataSetsSingleRangeMatchExactTo() { 53 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2016, 5, 1), 54 | LocalDate.of(2016, 12, 31)))).containsExactly(data2016); 55 | } 56 | 57 | @Test 58 | void getDataSetsMultipleRangesMatchExactFrom() { 59 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2016, 1, 1), 60 | LocalDate.of(2018, 5, 12)))).containsExactly(data2016, data2017, data2018); 61 | } 62 | 63 | @Test 64 | void getDataSetsMultipleRangesMatchExactTo() { 65 | assertThat(metadata.getDataSets(new DateRange(LocalDate.of(2016, 5, 12), 66 | LocalDate.of(2017, 12, 31)))).containsExactly(data2016, data2017); 67 | } 68 | 69 | @Test 70 | void getEventsNoMatch() { 71 | assertThat(metadata.getEvents(new DateRange(LocalDate.of(2018, 1, 1), 72 | LocalDate.of(2018, 2, 2)))).hasSize(0); 73 | } 74 | 75 | @Test 76 | void getEventsSingleMatchExactDay() { 77 | assertThat(metadata.getEvents(new DateRange(LocalDate.of(2016, 5, 1), 78 | LocalDate.of(2016, 5, 1)))).containsExactly(event2016); 79 | } 80 | 81 | @Test 82 | void getEventsSingleMatch() { 83 | assertThat(metadata.getEvents(new DateRange(LocalDate.of(2016, 1, 1), 84 | LocalDate.of(2016, 7, 1)))).containsExactly(event2016); 85 | } 86 | 87 | @Test 88 | void getEventsMultipleMatches() { 89 | assertThat(metadata.getEvents(new DateRange(LocalDate.of(2016, 1, 1), 90 | LocalDate.of(2018, 7, 1)))).containsExactly(event2016, event2017); 91 | } 92 | 93 | @Test 94 | void generateSingleRange() { 95 | GenerationStatistics statistics = metadata.generateStatistics( 96 | new DateRange(LocalDate.of(2017, 5, 1), LocalDate.of(2017, 5, 3))); 97 | assertThat(statistics).isNotNull(); 98 | assertThat(statistics.getRange().getFrom()).isEqualTo(LocalDate.of(2017, 5, 1)); 99 | assertThat(statistics.getRange().getTo()).isEqualTo(LocalDate.of(2017, 5, 3)); 100 | assertThat(statistics.getEntries()).containsOnlyKeys("1.5.x"); 101 | List entries = statistics.getEntries().get("1.5.x"); 102 | assertThat(entries).hasSize(3); 103 | assertThat(entries.get(0).getDate()).isEqualTo(LocalDate.of(2017, 5, 1)); 104 | assertThat(entries.get(0).getProjectsCount()).isGreaterThan(0); 105 | assertThat(entries.get(1).getDate()).isEqualTo(LocalDate.of(2017, 5, 2)); 106 | assertThat(entries.get(1).getProjectsCount()).isGreaterThan(0); 107 | assertThat(entries.get(2).getDate()).isEqualTo(LocalDate.of(2017, 5, 3)); 108 | assertThat(entries.get(2).getProjectsCount()).isGreaterThan(0); 109 | } 110 | 111 | private static DataSet sampleDataSet(LocalDate from, LocalDate to) { 112 | DataSet dataSet = new DataSet(); 113 | dataSet.setRange(new DateRange(from, to)); 114 | dataSet.getData().setMonday(1000); 115 | dataSet.getData().setTuesday(1200); 116 | dataSet.getData().setWednesday(1200); 117 | dataSet.getData().setThursday(1400); 118 | dataSet.getData().setFriday(900); 119 | dataSet.getData().setSaturday(500); 120 | dataSet.getData().setSunday(100); 121 | return dataSet; 122 | } 123 | 124 | private static Release release(LocalDate from, LocalDate to, String current) { 125 | Release release = new Release(); 126 | release.setRange(new DateRange(from, to)); 127 | release.getData().setCurrent(current); 128 | return release; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | io.spring.sample 7 | initializr-stats 8 | 0.0.1-SNAPSHOT 9 | pom 10 | 11 | initializr-stats 12 | Initializr Statistics 13 | 14 | 15 | dashboard 16 | generator 17 | 18 | 19 | --------------------------------------------------------------------------------
35 | 36 |
40 | 41 |