2022-02-02 14:23:28 +01:00
|
|
|
package eu.dnetlib.scholix.api;
|
|
|
|
|
|
|
|
import eu.dnetlib.common.app.AbstractDnetApp;
|
2022-02-04 15:52:49 +01:00
|
|
|
import io.micrometer.core.aop.TimedAspect;
|
2022-02-07 16:36:26 +01:00
|
|
|
import io.micrometer.core.instrument.*;
|
2022-02-04 15:52:49 +01:00
|
|
|
import io.micrometer.core.instrument.config.MeterFilter;
|
|
|
|
import io.micrometer.core.instrument.distribution.DistributionStatisticConfig;
|
2022-02-02 14:23:28 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
import org.springframework.cache.annotation.EnableCaching;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
2022-02-04 15:52:49 +01:00
|
|
|
import org.springframework.context.annotation.ComponentScan;
|
2022-02-02 14:23:28 +01:00
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
import springfox.documentation.builders.ApiInfoBuilder;
|
|
|
|
import springfox.documentation.builders.RequestHandlerSelectors;
|
|
|
|
import springfox.documentation.service.ApiInfo;
|
|
|
|
import springfox.documentation.spi.DocumentationType;
|
|
|
|
import springfox.documentation.spring.web.plugins.Docket;
|
|
|
|
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
|
|
|
|
2022-02-04 15:52:49 +01:00
|
|
|
import java.time.Duration;
|
2022-02-07 16:36:26 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2022-02-04 15:52:49 +01:00
|
|
|
|
2022-02-02 14:23:28 +01:00
|
|
|
@SpringBootApplication
|
|
|
|
@EnableSwagger2
|
|
|
|
@EnableCaching
|
|
|
|
@EnableScheduling
|
2022-02-04 15:52:49 +01:00
|
|
|
@ComponentScan(basePackages = "eu.dnetlib")
|
2022-02-02 14:23:28 +01:00
|
|
|
public class MainApplication extends AbstractDnetApp {
|
|
|
|
|
2022-02-07 16:36:26 +01:00
|
|
|
private double scale = 1000000000;
|
|
|
|
|
|
|
|
private double[] histogramValues =new double[]{.005 * scale, .01 * scale, .25 * scale, .5 * scale, .75 * scale, scale, 2.5 * scale, 5.0 * scale, 7.5 * scale, 10.0 * scale};
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-02 14:23:28 +01:00
|
|
|
@Value("${dhp.swagger.api.host}")
|
|
|
|
private String swaggetHost;
|
|
|
|
|
|
|
|
@Value("${dhp.swagger.api.basePath}")
|
|
|
|
private String swaggerPath;
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(final String[] args) {
|
|
|
|
SpringApplication.run(MainApplication.class, args);
|
|
|
|
}
|
|
|
|
|
2022-02-04 15:52:49 +01:00
|
|
|
|
2022-02-07 16:36:26 +01:00
|
|
|
|
|
|
|
@Bean
|
|
|
|
public TaggedCounter myCounter(MeterRegistry meterRegistry) {
|
|
|
|
|
2022-02-08 09:57:45 +01:00
|
|
|
return new TaggedCounter(ScholixAPIConstants.SCHOLIX_MANAGER_COUNTER_NAME, ScholixAPIConstants.SCHOLIX_MANAGER_TAG_NAME,meterRegistry);
|
2022-02-07 16:36:26 +01:00
|
|
|
}
|
|
|
|
|
2022-02-04 15:52:49 +01:00
|
|
|
@Bean
|
|
|
|
public TimedAspect timedAspect(MeterRegistry meterRegistry) {
|
|
|
|
MeterFilter mf = new MeterFilter() {
|
|
|
|
@Override
|
|
|
|
public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
|
2022-02-08 09:57:45 +01:00
|
|
|
if (id.getName().startsWith(ScholixAPIConstants.SCHOLIX_COUNTER_PREFIX)) {
|
2022-02-04 15:52:49 +01:00
|
|
|
|
|
|
|
return DistributionStatisticConfig.builder()
|
|
|
|
.percentilesHistogram(false)
|
2022-02-07 16:36:26 +01:00
|
|
|
.serviceLevelObjectives( histogramValues)
|
2022-02-04 15:52:49 +01:00
|
|
|
.build()
|
|
|
|
.merge(config);
|
|
|
|
}
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
meterRegistry.config().meterFilter(mf);
|
|
|
|
return new TimedAspect(meterRegistry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-02 14:23:28 +01:00
|
|
|
@Override
|
|
|
|
protected void configSwagger(final Docket docket) {
|
|
|
|
docket
|
|
|
|
.host(swaggetHost)
|
|
|
|
.pathMapping(swaggerPath)
|
2022-02-08 09:57:45 +01:00
|
|
|
.groupName(ScholixAPIConstants.API_V1_NAME)
|
2022-02-02 14:23:28 +01:00
|
|
|
.select()
|
|
|
|
.apis(RequestHandlerSelectors.any())
|
|
|
|
.paths(p -> p.startsWith("/v1"))
|
|
|
|
.build()
|
|
|
|
.apiInfo(new ApiInfoBuilder()
|
2022-02-08 09:57:45 +01:00
|
|
|
.title(ScholixAPIConstants.API_V1_NAME)
|
|
|
|
.description(ScholixAPIConstants.API_DESCRIPTION)
|
2022-02-02 14:23:28 +01:00
|
|
|
.version("1.0")
|
|
|
|
.contact(ApiInfo.DEFAULT_CONTACT)
|
|
|
|
.license("Apache 2.0")
|
|
|
|
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-02-08 09:57:45 +01:00
|
|
|
@Bean (name = "SpringDocketv2")
|
2022-02-02 14:23:28 +01:00
|
|
|
public Docket v2Docket() {
|
|
|
|
final Docket docket = new Docket(DocumentationType.SWAGGER_2);
|
|
|
|
docket
|
|
|
|
.host(swaggetHost)
|
|
|
|
.pathMapping(swaggerPath)
|
2022-02-08 09:57:45 +01:00
|
|
|
.groupName(ScholixAPIConstants.API_V2_NAME)
|
2022-02-02 14:23:28 +01:00
|
|
|
.select()
|
|
|
|
.apis(RequestHandlerSelectors.any())
|
|
|
|
.paths(p -> p.startsWith("/v2"))
|
|
|
|
.build()
|
|
|
|
.apiInfo(new ApiInfoBuilder()
|
2022-02-08 09:57:45 +01:00
|
|
|
.title(ScholixAPIConstants.API_V2_NAME)
|
|
|
|
.description(ScholixAPIConstants.API_DESCRIPTION)
|
2022-02-02 14:23:28 +01:00
|
|
|
.version("2.0")
|
|
|
|
.contact(ApiInfo.DEFAULT_CONTACT)
|
|
|
|
.license("Apache 2.0")
|
|
|
|
.licenseUrl("http://www.apache.org/licenses/LICENSE-2.0")
|
|
|
|
.build());
|
|
|
|
|
|
|
|
return docket;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|