mirror of
https://github.com/Telecominfraproject/wlan-cloud-base.git
synced 2026-03-20 22:39:06 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
137e8596a2 | ||
|
|
cbad366ac3 |
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -46,7 +47,6 @@
|
||||
<module>../base-hierarchical-datastore</module>
|
||||
<module>../base-jdbc</module>
|
||||
<module>../base-jdbc-tests</module>
|
||||
<module>../base-tx-tests</module>
|
||||
<module>../base-cassandra</module>
|
||||
<module>../base-cassandra-tests</module>
|
||||
<module>../base-job</module>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-cassandra-tests</artifactId>
|
||||
@@ -14,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-cassandra</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-cassandra</artifactId>
|
||||
@@ -14,7 +14,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -61,9 +61,7 @@ public class BaseCassandraDataSource {
|
||||
sessionBuilder.withConfigLoader(DriverConfigLoader.fromClasspath("cassandra-application"));
|
||||
}
|
||||
|
||||
CqlSession session = sessionBuilder.build();
|
||||
|
||||
session = new CqlSessionWithMetrics(session);
|
||||
CqlSession session =sessionBuilder.build();
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
@@ -1,420 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.server.cassandra;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
|
||||
import com.datastax.dse.driver.api.core.cql.continuous.ContinuousAsyncResultSet;
|
||||
import com.datastax.dse.driver.api.core.cql.continuous.ContinuousResultSet;
|
||||
import com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet;
|
||||
import com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet;
|
||||
import com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet;
|
||||
import com.datastax.dse.driver.api.core.graph.GraphResultSet;
|
||||
import com.datastax.dse.driver.api.core.graph.GraphStatement;
|
||||
import com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet;
|
||||
import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
import com.datastax.oss.driver.api.core.context.DriverContext;
|
||||
import com.datastax.oss.driver.api.core.cql.AsyncResultSet;
|
||||
import com.datastax.oss.driver.api.core.cql.PrepareRequest;
|
||||
import com.datastax.oss.driver.api.core.cql.PreparedStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.ResultSet;
|
||||
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
|
||||
import com.datastax.oss.driver.api.core.cql.Statement;
|
||||
import com.datastax.oss.driver.api.core.metadata.Metadata;
|
||||
import com.datastax.oss.driver.api.core.metrics.Metrics;
|
||||
import com.datastax.oss.driver.api.core.session.Request;
|
||||
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
|
||||
import com.netflix.servo.DefaultMonitorRegistry;
|
||||
import com.netflix.servo.monitor.BasicCounter;
|
||||
import com.netflix.servo.monitor.BasicTimer;
|
||||
import com.netflix.servo.monitor.Counter;
|
||||
import com.netflix.servo.monitor.MonitorConfig;
|
||||
import com.netflix.servo.monitor.Stopwatch;
|
||||
import com.netflix.servo.monitor.Timer;
|
||||
import com.netflix.servo.tag.TagList;
|
||||
import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags;
|
||||
|
||||
public class CqlSessionWithMetrics implements CqlSession {
|
||||
|
||||
private final TagList tags = CloudMetricsTags.commonTags;
|
||||
|
||||
final Counter executeCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute").withTags(tags).build());
|
||||
final Counter executeAsyncCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute-async").withTags(tags).build());
|
||||
final Counter executeReactiveCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute-reactive").withTags(tags).build());
|
||||
|
||||
final Counter executeErrorCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute-errors").withTags(tags).build());
|
||||
final Counter executeAsyncErrorCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute-async-errors").withTags(tags).build());
|
||||
final Counter executeReactiveErrorCounter = new BasicCounter(MonitorConfig.builder("cassandra-execute-reactive-errors").withTags(tags).build());
|
||||
|
||||
private final Timer executeTimer = new BasicTimer(
|
||||
MonitorConfig.builder("cassandra-executeTimer").withTags(tags).build());
|
||||
|
||||
private final Timer executeAsyncTimer = new BasicTimer(
|
||||
MonitorConfig.builder("cassandra-executeAsyncTimer").withTags(tags).build());
|
||||
|
||||
private final Timer executeReactiveTimer = new BasicTimer(
|
||||
MonitorConfig.builder("cassandra-executeReactiveTimer").withTags(tags).build());
|
||||
|
||||
// dtop: use anonymous constructor to ensure that the following code always
|
||||
// get executed,
|
||||
// even when somebody adds another constructor in here
|
||||
{
|
||||
DefaultMonitorRegistry.getInstance().register(executeCounter);
|
||||
DefaultMonitorRegistry.getInstance().register(executeAsyncCounter);
|
||||
DefaultMonitorRegistry.getInstance().register(executeReactiveCounter);
|
||||
|
||||
DefaultMonitorRegistry.getInstance().register(executeErrorCounter);
|
||||
DefaultMonitorRegistry.getInstance().register(executeAsyncErrorCounter);
|
||||
DefaultMonitorRegistry.getInstance().register(executeReactiveErrorCounter);
|
||||
|
||||
DefaultMonitorRegistry.getInstance().register(executeTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(executeAsyncTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(executeReactiveTimer);
|
||||
}
|
||||
|
||||
private final CqlSession delegate;
|
||||
|
||||
public CqlSessionWithMetrics(CqlSession delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public CompletionStage<AsyncResultSet> executeAsync(Statement<?> statement) {
|
||||
executeAsyncCounter.increment();
|
||||
Stopwatch stopwatch = executeAsyncTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
CompletionStage<AsyncResultSet> ret = delegate.executeAsync(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeAsyncErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ReactiveGraphResultSet executeReactive(GraphStatement<?> statement) {
|
||||
executeReactiveCounter.increment();
|
||||
Stopwatch stopwatch = executeReactiveTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ReactiveGraphResultSet ret = delegate.executeReactive(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeReactiveErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<Void> closeFuture() {
|
||||
return delegate.closeFuture();
|
||||
}
|
||||
|
||||
public ResultSet execute(Statement<?> statement) {
|
||||
executeCounter.increment();
|
||||
Stopwatch stopwatch = executeTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ResultSet ret = delegate.execute(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public GraphResultSet execute(GraphStatement<?> graphStatement) {
|
||||
executeCounter.increment();
|
||||
Stopwatch stopwatch = executeTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
GraphResultSet ret = delegate.execute(graphStatement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return delegate.isClosed();
|
||||
}
|
||||
|
||||
public ReactiveResultSet executeReactive(String query) {
|
||||
executeReactiveCounter.increment();
|
||||
Stopwatch stopwatch = executeReactiveTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ReactiveResultSet ret = delegate.executeReactive(query);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeReactiveErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<AsyncResultSet> executeAsync(String query) {
|
||||
executeAsyncCounter.increment();
|
||||
Stopwatch stopwatch = executeAsyncTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
CompletionStage<AsyncResultSet> ret = delegate.executeAsync(query);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeAsyncErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<Void> closeAsync() {
|
||||
return delegate.closeAsync();
|
||||
}
|
||||
|
||||
public ReactiveResultSet executeReactive(Statement<?> statement) {
|
||||
executeReactiveCounter.increment();
|
||||
Stopwatch stopwatch = executeReactiveTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ReactiveResultSet ret = delegate.executeReactive(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeReactiveErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<Void> forceCloseAsync() {
|
||||
return delegate.forceCloseAsync();
|
||||
}
|
||||
|
||||
public CompletionStage<PreparedStatement> prepareAsync(SimpleStatement statement) {
|
||||
return delegate.prepareAsync(statement);
|
||||
}
|
||||
|
||||
public ContinuousReactiveResultSet executeContinuouslyReactive(String query) {
|
||||
executeReactiveCounter.increment();
|
||||
Stopwatch stopwatch = executeReactiveTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ContinuousReactiveResultSet ret = delegate.executeContinuouslyReactive(query);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeReactiveErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet execute(String query) {
|
||||
executeCounter.increment();
|
||||
Stopwatch stopwatch = executeTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ResultSet ret = delegate.execute(query);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void close() {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
public CompletionStage<AsyncGraphResultSet> executeAsync(GraphStatement<?> graphStatement) {
|
||||
executeAsyncCounter.increment();
|
||||
Stopwatch stopwatch = executeAsyncTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
CompletionStage<AsyncGraphResultSet> ret = delegate.executeAsync(graphStatement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeAsyncErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ContinuousReactiveResultSet executeContinuouslyReactive(Statement<?> statement) {
|
||||
executeReactiveCounter.increment();
|
||||
Stopwatch stopwatch = executeReactiveTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ContinuousReactiveResultSet ret = delegate.executeContinuouslyReactive(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeReactiveErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<PreparedStatement> prepareAsync(String query) {
|
||||
return delegate.prepareAsync(query);
|
||||
}
|
||||
|
||||
public PreparedStatement prepare(SimpleStatement statement) {
|
||||
return delegate.prepare(statement);
|
||||
}
|
||||
|
||||
public Metadata getMetadata() {
|
||||
return delegate.getMetadata();
|
||||
}
|
||||
|
||||
public ContinuousResultSet executeContinuously(Statement<?> statement) {
|
||||
executeCounter.increment();
|
||||
Stopwatch stopwatch = executeTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ContinuousResultSet ret = delegate.executeContinuously(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<PreparedStatement> prepareAsync(PrepareRequest request) {
|
||||
return delegate.prepareAsync(request);
|
||||
}
|
||||
|
||||
public boolean isSchemaMetadataEnabled() {
|
||||
return delegate.isSchemaMetadataEnabled();
|
||||
}
|
||||
|
||||
public CompletionStage<ContinuousAsyncResultSet> executeContinuouslyAsync(Statement<?> statement) {
|
||||
executeAsyncCounter.increment();
|
||||
Stopwatch stopwatch = executeAsyncTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
CompletionStage<ContinuousAsyncResultSet> ret = delegate.executeContinuouslyAsync(statement);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeAsyncErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CompletionStage<Metadata> setSchemaMetadataEnabled(Boolean newValue) {
|
||||
return delegate.setSchemaMetadataEnabled(newValue);
|
||||
}
|
||||
|
||||
public CompletionStage<Metadata> refreshSchemaAsync() {
|
||||
return delegate.refreshSchemaAsync();
|
||||
}
|
||||
|
||||
public Metadata refreshSchema() {
|
||||
return delegate.refreshSchema();
|
||||
}
|
||||
|
||||
public CompletionStage<Boolean> checkSchemaAgreementAsync() {
|
||||
return delegate.checkSchemaAgreementAsync();
|
||||
}
|
||||
|
||||
public PreparedStatement prepare(String query) {
|
||||
return delegate.prepare(query);
|
||||
}
|
||||
|
||||
public boolean checkSchemaAgreement() {
|
||||
return delegate.checkSchemaAgreement();
|
||||
}
|
||||
|
||||
public DriverContext getContext() {
|
||||
return delegate.getContext();
|
||||
}
|
||||
|
||||
public Optional<CqlIdentifier> getKeyspace() {
|
||||
return delegate.getKeyspace();
|
||||
}
|
||||
|
||||
public PreparedStatement prepare(PrepareRequest request) {
|
||||
return delegate.prepare(request);
|
||||
}
|
||||
|
||||
public Optional<Metrics> getMetrics() {
|
||||
return delegate.getMetrics();
|
||||
}
|
||||
|
||||
public <RequestT extends Request, ResultT> ResultT execute(RequestT request, GenericType<ResultT> resultType) {
|
||||
executeCounter.increment();
|
||||
Stopwatch stopwatch = executeTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try {
|
||||
ResultT ret = delegate.execute(request, resultType);
|
||||
success = true;
|
||||
return ret;
|
||||
} finally {
|
||||
stopwatch.stop();
|
||||
if(!success) {
|
||||
executeErrorCounter.increment();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-client</artifactId>
|
||||
@@ -14,25 +16,25 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-container</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.telecominfraproject.wlan.core.client;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -20,15 +22,20 @@ public abstract class BaseRemoteClient {
|
||||
protected HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
{
|
||||
// Note: APPLICATION_JSON_UTF8 is deprecated
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setContentType(new MediaType("application", "json", StandardCharsets.UTF_8));
|
||||
//Accept-Encoding: gzip,deflate
|
||||
headers.set("Accept-Encoding", "gzip,deflate");
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setRestTemplate(RestOperations restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
//build user-friendly metrics Id - remove $$EnhancedByCGlib... at the end of the class name
|
||||
String metricsId = this.getClass().getSimpleName();
|
||||
int idx = metricsId.indexOf('$');
|
||||
if(idx>0){
|
||||
metricsId = metricsId.substring(0, idx);
|
||||
}
|
||||
this.restTemplate = new RestOperationsWithMetrics(restTemplate, metricsId);
|
||||
}
|
||||
|
||||
protected String getBaseUrlFromEnvironment(String urlPropName, String defaultUrlPropName) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.springframework.core.task.TaskRejectedException;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.web.client.DefaultResponseErrorHandler;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
|
||||
@@ -39,7 +38,7 @@ public class ExceptionPropagatingErrorHandler extends DefaultResponseErrorHandle
|
||||
public void handleError(ClientHttpResponse response) throws IOException {
|
||||
try {
|
||||
super.handleError(response);
|
||||
} catch (HttpServerErrorException | HttpClientErrorException e) {
|
||||
} catch (HttpServerErrorException e) {
|
||||
// look in the response object, and if it contains any of the
|
||||
// exceptions we recognize - throw that exception instead of the
|
||||
// HttpServerErrorException
|
||||
|
||||
@@ -50,22 +50,6 @@ public class HttpClientConfigResolver {
|
||||
ret = HttpClientConfig.fromString(StreamUtils.copyToString((InputStream) configContent, StandardCharsets.UTF_8),
|
||||
HttpClientConfig.class);
|
||||
}
|
||||
|
||||
if(environment!=null){
|
||||
//override values for maxConnectionsTotal and maxConnectionsPerRoute using environment variables, if provided
|
||||
if(environment.getProperty("tip.wlan.httpClientConfig.maxConnectionsTotal") != null) {
|
||||
int maxConnectionsTotal = Integer.parseInt(environment.getProperty("tip.wlan.httpClientConfig.maxConnectionsTotal"));
|
||||
ret.setMaxConnectionsTotal(maxConnectionsTotal);
|
||||
LOG.info("Overriding http client configuration maxConnectionsTotal {}", maxConnectionsTotal);
|
||||
}
|
||||
|
||||
if(environment.getProperty("tip.wlan.httpClientConfig.maxConnectionsPerRoute") != null) {
|
||||
int maxConnectionsPerRoute = Integer.parseInt(environment.getProperty("tip.wlan.httpClientConfig.maxConnectionsPerRoute"));
|
||||
ret.setMaxConnectionsPerRoute(maxConnectionsPerRoute);
|
||||
LOG.info("Overriding http client configuration maxConnectionsPerRoute {}", maxConnectionsPerRoute);
|
||||
}
|
||||
}
|
||||
|
||||
LOG.info("Got http client configuration from {}", configLocation);
|
||||
return ret;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -0,0 +1,842 @@
|
||||
package com.telecominfraproject.wlan.core.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.client.RequestCallback;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
|
||||
import com.netflix.servo.DefaultMonitorRegistry;
|
||||
import com.netflix.servo.monitor.BasicCounter;
|
||||
import com.netflix.servo.monitor.BasicTimer;
|
||||
import com.netflix.servo.monitor.Counter;
|
||||
import com.netflix.servo.monitor.MonitorConfig;
|
||||
import com.netflix.servo.monitor.Stopwatch;
|
||||
import com.netflix.servo.monitor.Timer;
|
||||
import com.netflix.servo.tag.TagList;
|
||||
import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags;
|
||||
|
||||
public class RestOperationsWithMetrics implements RestOperations{
|
||||
final RestOperations delegate;
|
||||
|
||||
private final TagList tags = CloudMetricsTags.commonTags;
|
||||
|
||||
private final Counter getsExecuted;
|
||||
private final Counter postsExecuted;
|
||||
private final Counter putsExecuted;
|
||||
private final Counter deletesExecuted;
|
||||
private final Counter exchangesExecuted;
|
||||
private final Counter headsExecuted;
|
||||
private final Counter optionsExecuted;
|
||||
private final Counter execsExecuted;
|
||||
private final Counter patchesExecuted;
|
||||
|
||||
private final Counter getsErrors;
|
||||
private final Counter postsErrors;
|
||||
private final Counter putsErrors;
|
||||
private final Counter deletesErrors;
|
||||
private final Counter exchangesErrors;
|
||||
private final Counter headsErrors;
|
||||
private final Counter optionsErrors;
|
||||
private final Counter execsErrors;
|
||||
private final Counter patchesErrors;
|
||||
|
||||
private final Timer getsTimer;
|
||||
private final Timer postsTimer;
|
||||
private final Timer putsTimer;
|
||||
private final Timer deletesTimer;
|
||||
private final Timer exchangesTimer;
|
||||
private final Timer headsTimer;
|
||||
private final Timer optionsTimer;
|
||||
private final Timer execsTimer;
|
||||
private final Timer patchesTimer;
|
||||
|
||||
|
||||
public RestOperationsWithMetrics(RestOperations delegate, String metricsId){
|
||||
this.delegate = delegate;
|
||||
//Monitors.registerObject("RestTemplate-"+metricsId, this);
|
||||
|
||||
getsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-getsExecuted").withTags(tags).build());
|
||||
postsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-postsExecuted").withTags(tags).build());
|
||||
putsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-putsExecuted").withTags(tags).build());
|
||||
deletesExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-deletesExecuted").withTags(tags).build());
|
||||
exchangesExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-exchangesExecuted").withTags(tags).build());
|
||||
headsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-headsExecuted").withTags(tags).build());
|
||||
optionsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-optionsExecuted").withTags(tags).build());
|
||||
execsExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-execsExecuted").withTags(tags).build());
|
||||
patchesExecuted = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-patchesExecuted").withTags(tags).build());
|
||||
|
||||
getsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-getsErrors").withTags(tags).build());
|
||||
postsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-postsErrors").withTags(tags).build());
|
||||
putsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-putsErrors").withTags(tags).build());
|
||||
deletesErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-deletesErrors").withTags(tags).build());
|
||||
exchangesErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-exchangesErrors").withTags(tags).build());
|
||||
headsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-headsErrors").withTags(tags).build());
|
||||
optionsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-optionsErrors").withTags(tags).build());
|
||||
execsErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-execsErrors").withTags(tags).build());
|
||||
patchesErrors = new BasicCounter(MonitorConfig.builder("RestTemplate-"+metricsId+"-patchesErrors").withTags(tags).build());
|
||||
|
||||
getsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-getsTimer").withTags(tags).build());
|
||||
postsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-postsTimer").withTags(tags).build());
|
||||
putsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-putsTimer").withTags(tags).build());
|
||||
deletesTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-deletesTimer").withTags(tags).build());
|
||||
exchangesTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-exchangesTimer").withTags(tags).build());
|
||||
headsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-headsTimer").withTags(tags).build());
|
||||
optionsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-optionsTimer").withTags(tags).build());
|
||||
execsTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-execsTimer").withTags(tags).build());
|
||||
patchesTimer = new BasicTimer(MonitorConfig.builder("RestTemplate-"+metricsId+"-patchesTimer").withTags(tags).build());
|
||||
|
||||
DefaultMonitorRegistry.getInstance().register(getsExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(postsExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(putsExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(deletesExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(exchangesExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(headsExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(optionsExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(execsExecuted);
|
||||
|
||||
DefaultMonitorRegistry.getInstance().register(getsErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(postsErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(putsErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(deletesErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(exchangesErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(headsErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(optionsErrors);
|
||||
DefaultMonitorRegistry.getInstance().register(execsErrors);
|
||||
|
||||
DefaultMonitorRegistry.getInstance().register(getsTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(postsTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(putsTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(deletesTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(exchangesTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(headsTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(optionsTimer);
|
||||
DefaultMonitorRegistry.getInstance().register(execsTimer);
|
||||
|
||||
}
|
||||
|
||||
public <T> T getForObject(String url, Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.getForObject(url, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.getForObject(url, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.getForObject(url, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.getForEntity(url, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getForEntity(String url, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.getForEntity(url, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> getForEntity(URI url, Class<T> responseType) throws RestClientException {
|
||||
getsExecuted.increment();
|
||||
Stopwatch s = getsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.getForEntity(url, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
getsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException {
|
||||
headsExecuted.increment();
|
||||
Stopwatch s = headsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
HttpHeaders ret = delegate.headForHeaders(url, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
headsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeaders headForHeaders(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
headsExecuted.increment();
|
||||
Stopwatch s = headsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
HttpHeaders ret = delegate.headForHeaders(url, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
headsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HttpHeaders headForHeaders(URI url) throws RestClientException {
|
||||
headsExecuted.increment();
|
||||
Stopwatch s = headsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
HttpHeaders ret = delegate.headForHeaders(url);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
headsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public URI postForLocation(String url, Object request, Object... uriVariables) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
URI ret = delegate.postForLocation(url, request, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public URI postForLocation(String url, Object request, Map<String, ?> uriVariables) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
URI ret = delegate.postForLocation(url, request, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public URI postForLocation(URI url, Object request) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
URI ret = delegate.postForLocation(url, request);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T postForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.postForObject(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T postForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.postForObject(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T postForObject(URI url, Object request, Class<T> responseType) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.postForObject(url, request, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType,
|
||||
Object... uriVariables) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.postForEntity(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> postForEntity(String url, Object request, Class<T> responseType,
|
||||
Map<String, ?> uriVariables) throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.postForEntity(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> postForEntity(URI url, Object request, Class<T> responseType)
|
||||
throws RestClientException {
|
||||
postsExecuted.increment();
|
||||
Stopwatch s = postsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.postForEntity(url, request, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
postsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String url, Object request, Object... uriVariables) throws RestClientException {
|
||||
putsExecuted.increment();
|
||||
Stopwatch s = putsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.put(url, request, uriVariables);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
putsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void put(String url, Object request, Map<String, ?> uriVariables) throws RestClientException {
|
||||
putsExecuted.increment();
|
||||
Stopwatch s = putsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.put(url, request, uriVariables);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
putsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void put(URI url, Object request) throws RestClientException {
|
||||
putsExecuted.increment();
|
||||
Stopwatch s = putsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.put(url, request);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
putsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String url, Object... uriVariables) throws RestClientException {
|
||||
deletesExecuted.increment();
|
||||
Stopwatch s = deletesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.delete(url, uriVariables);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
deletesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
deletesExecuted.increment();
|
||||
Stopwatch s = deletesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.delete(url, uriVariables);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
deletesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(URI url) throws RestClientException {
|
||||
deletesExecuted.increment();
|
||||
Stopwatch s = deletesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
delegate.delete(url);
|
||||
success = true;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
deletesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<HttpMethod> optionsForAllow(String url, Object... uriVariables) throws RestClientException {
|
||||
optionsExecuted.increment();
|
||||
Stopwatch s = optionsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
Set<HttpMethod> ret = delegate.optionsForAllow(url, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
optionsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<HttpMethod> optionsForAllow(String url, Map<String, ?> uriVariables) throws RestClientException {
|
||||
optionsExecuted.increment();
|
||||
Stopwatch s = optionsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
Set<HttpMethod> ret = delegate.optionsForAllow(url, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
optionsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Set<HttpMethod> optionsForAllow(URI url) throws RestClientException {
|
||||
optionsExecuted.increment();
|
||||
Stopwatch s = optionsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
Set<HttpMethod> ret = delegate.optionsForAllow(url);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
optionsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
Class<T> responseType) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Object... uriVariables) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType, Map<String, ?> uriVariables) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(URI url, HttpMethod method, HttpEntity<?> requestEntity,
|
||||
ParameterizedTypeReference<T> responseType) throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(url, method, requestEntity, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, Class<T> responseType)
|
||||
throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(requestEntity, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> ResponseEntity<T> exchange(RequestEntity<?> requestEntity, ParameterizedTypeReference<T> responseType)
|
||||
throws RestClientException {
|
||||
exchangesExecuted.increment();
|
||||
Stopwatch s = exchangesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
ResponseEntity<T> ret = delegate.exchange(requestEntity, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
exchangesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor, Object... uriVariables) throws RestClientException {
|
||||
execsExecuted.increment();
|
||||
Stopwatch s = execsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
execsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T execute(String url, HttpMethod method, RequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor, Map<String, ?> uriVariables) throws RestClientException {
|
||||
execsExecuted.increment();
|
||||
Stopwatch s = execsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.execute(url, method, requestCallback, responseExtractor, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
execsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T execute(URI url, HttpMethod method, RequestCallback requestCallback,
|
||||
ResponseExtractor<T> responseExtractor) throws RestClientException {
|
||||
execsExecuted.increment();
|
||||
Stopwatch s = execsTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.execute(url, method, requestCallback, responseExtractor);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
execsErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T patchForObject(String url, Object request, Class<T> responseType, Object... uriVariables)
|
||||
throws RestClientException {
|
||||
patchesExecuted.increment();
|
||||
Stopwatch s = patchesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.patchForObject(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
patchesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T patchForObject(String url, Object request, Class<T> responseType, Map<String, ?> uriVariables)
|
||||
throws RestClientException {
|
||||
patchesExecuted.increment();
|
||||
Stopwatch s = patchesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.patchForObject(url, request, responseType, uriVariables);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
patchesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T patchForObject(URI url, Object request, Class<T> responseType) throws RestClientException {
|
||||
patchesExecuted.increment();
|
||||
Stopwatch s = patchesTimer.start();
|
||||
boolean success = false;
|
||||
|
||||
try{
|
||||
T ret = delegate.patchForObject(url, request, responseType);
|
||||
success = true;
|
||||
return ret;
|
||||
}finally{
|
||||
s.stop();
|
||||
if(!success){
|
||||
patchesErrors.increment();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.springframework.core.env.Environment;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.client.RestOperations;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -18,7 +18,7 @@ public class PingClientTest {
|
||||
|
||||
PingClient pingClient = mock(PingClient.class, CALLS_REAL_METHODS);
|
||||
|
||||
RestTemplate restTemplate = mock(RestTemplate.class);
|
||||
RestOperations restTemplate = mock(RestOperationsWithMetrics.class);
|
||||
|
||||
Environment env = mock(Environment.class);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-container</artifactId>
|
||||
@@ -18,7 +18,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
@@ -32,20 +32,14 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Auth0 dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>java-jwt</artifactId>
|
||||
<version>3.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.auth0</groupId>
|
||||
<artifactId>jwks-rsa</artifactId>
|
||||
<version>0.14.0</version>
|
||||
<version>0.3</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -24,15 +24,9 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.netflix.servo.DefaultMonitorRegistry;
|
||||
import com.netflix.servo.annotations.DataSourceType;
|
||||
import com.netflix.servo.annotations.Monitor;
|
||||
import com.netflix.servo.monitor.BasicCounter;
|
||||
import com.netflix.servo.monitor.Counter;
|
||||
import com.netflix.servo.monitor.MonitorConfig;
|
||||
import com.netflix.servo.monitor.NumberGauge;
|
||||
import com.netflix.servo.tag.TagList;
|
||||
import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags;
|
||||
import com.netflix.servo.monitor.Monitors;
|
||||
import com.telecominfraproject.wlan.core.server.async.example.AsyncCallerExample;
|
||||
import com.telecominfraproject.wlan.core.server.async.example.AsyncExample;
|
||||
|
||||
@@ -57,31 +51,18 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AsyncConfiguration.class);
|
||||
|
||||
@Autowired private Environment environment;
|
||||
|
||||
private final TagList tags = CloudMetricsTags.commonTags;
|
||||
|
||||
final Counter totalTasksExecuted = new BasicCounter(MonitorConfig.builder("async-totalTasksExecuted").withTags(tags).build());
|
||||
final Counter totalTasksRejected = new BasicCounter(MonitorConfig.builder("async-totalTasksRejected").withTags(tags).build());
|
||||
|
||||
|
||||
@Monitor(name="TotalAsyncThreads", type=DataSourceType.GAUGE)
|
||||
private static final AtomicInteger totalAsyncThreads = new AtomicInteger(0);
|
||||
private final NumberGauge totalAsyncThreadsGauge = new NumberGauge(
|
||||
MonitorConfig.builder("async-totalAsyncThreads").withTags(tags).build(), totalAsyncThreads);
|
||||
|
||||
@Monitor(name="TotalTasksExecuted", type=DataSourceType.COUNTER)
|
||||
private static final AtomicInteger totalTasksExecuted = new AtomicInteger(0);
|
||||
|
||||
@Monitor(name = "TotalTasksRejected", type = DataSourceType.COUNTER)
|
||||
private static final AtomicInteger totalTasksRejected = new AtomicInteger(0);
|
||||
|
||||
@Monitor(name="TasksInTheQueue", type=DataSourceType.GAUGE)
|
||||
private static final AtomicInteger tasksInTheQueue = new AtomicInteger(0);
|
||||
private final NumberGauge tasksInTheQueueGauge = new NumberGauge(
|
||||
MonitorConfig.builder("async-tasksInTheQueue").withTags(tags).build(), tasksInTheQueue);
|
||||
|
||||
// dtop: use anonymous constructor to ensure that the following code always
|
||||
// get executed,
|
||||
// even when somebody adds another constructor in here
|
||||
{
|
||||
DefaultMonitorRegistry.getInstance().register(totalTasksExecuted);
|
||||
DefaultMonitorRegistry.getInstance().register(totalTasksRejected);
|
||||
DefaultMonitorRegistry.getInstance().register(totalAsyncThreadsGauge);
|
||||
DefaultMonitorRegistry.getInstance().register(tasksInTheQueueGauge);
|
||||
}
|
||||
|
||||
static interface RunnableBlockingQueueInSpringClassloaderInterface extends BlockingQueue<Runnable> {
|
||||
}
|
||||
@@ -285,7 +266,7 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
}
|
||||
@Override
|
||||
public void execute(Runnable task) {
|
||||
totalTasksExecuted.increment();
|
||||
totalTasksExecuted.incrementAndGet();
|
||||
super.execute(task);
|
||||
}
|
||||
|
||||
@@ -293,10 +274,10 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
public Future<?> submit(Runnable task) {
|
||||
try {
|
||||
Future<?> result = super.submit(task);
|
||||
totalTasksExecuted.increment();
|
||||
totalTasksExecuted.incrementAndGet();
|
||||
return result;
|
||||
} catch (TaskRejectedException exp) {
|
||||
totalTasksRejected.increment();
|
||||
totalTasksRejected.incrementAndGet();
|
||||
throw exp;
|
||||
}
|
||||
}
|
||||
@@ -305,10 +286,10 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
public <T> Future<T> submit(Callable<T> task) {
|
||||
try {
|
||||
Future<T> result = super.submit(task);
|
||||
totalTasksExecuted.increment();
|
||||
totalTasksExecuted.incrementAndGet();
|
||||
return result;
|
||||
} catch (TaskRejectedException exp) {
|
||||
totalTasksRejected.increment();
|
||||
totalTasksRejected.incrementAndGet();
|
||||
throw exp;
|
||||
}
|
||||
}
|
||||
@@ -317,10 +298,10 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
public ListenableFuture<?> submitListenable(Runnable task) {
|
||||
try {
|
||||
ListenableFuture<?> result = super.submitListenable(task);
|
||||
totalTasksExecuted.increment();
|
||||
totalTasksExecuted.incrementAndGet();
|
||||
return result;
|
||||
} catch (TaskRejectedException exp) {
|
||||
totalTasksRejected.increment();
|
||||
totalTasksRejected.incrementAndGet();
|
||||
throw exp;
|
||||
}
|
||||
}
|
||||
@@ -329,10 +310,10 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
|
||||
try {
|
||||
ListenableFuture<T> result = super.submitListenable(task);
|
||||
totalTasksExecuted.increment();
|
||||
totalTasksExecuted.incrementAndGet();
|
||||
return result;
|
||||
} catch (TaskRejectedException exp) {
|
||||
totalTasksRejected.increment();
|
||||
totalTasksRejected.incrementAndGet();
|
||||
throw exp;
|
||||
}
|
||||
}
|
||||
@@ -365,7 +346,7 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
RejectedExecutionHandler rejectedExecutionHandler = new RejectedExecutionHandler() {
|
||||
@Override
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
|
||||
totalTasksRejected.increment();
|
||||
totalTasksRejected.incrementAndGet();
|
||||
defaultRejectionHandler.rejectedExecution(r, executor);
|
||||
}
|
||||
};
|
||||
@@ -375,6 +356,8 @@ public class AsyncConfiguration implements AsyncConfigurer {
|
||||
LOG.info("Configuring {} with CorePoolSize={} MaxPoolSize={} QueueCapacity={}",
|
||||
executor.getThreadNamePrefix(), executor.getCorePoolSize(), executor.getMaxPoolSize(), queueCapacity);
|
||||
|
||||
Monitors.registerObject(AsyncConfiguration.class.getSimpleName(), this);
|
||||
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.caffeine.CaffeineCacheManager;
|
||||
@@ -14,19 +13,16 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
public class CacheConfiguration {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CacheConfiguration.class);
|
||||
|
||||
|
||||
@Autowired
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@Qualifier("cacheManager")
|
||||
public CacheManager cacheManager() {
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
Caffeine < Object, Object > cb = caffeineCacheBuilder();
|
||||
@@ -41,12 +37,17 @@ public class CacheConfiguration {
|
||||
.initialCapacity(100)
|
||||
.maximumSize(10000)
|
||||
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||
// .weakKeys()
|
||||
.weakKeys()
|
||||
.recordStats();
|
||||
}
|
||||
|
||||
public Cache getCache(CacheType cacheType, String cacheName){
|
||||
CacheManager cm = applicationContext.getBean(CacheManager.class, cacheType.toString());
|
||||
return cm.getCache(cacheName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean
|
||||
@Qualifier("cacheManagerShortLived")
|
||||
public CacheManager cacheManagerShortLived() {
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
Caffeine < Object, Object > cb = caffeineCacheBuilderShortLived();
|
||||
@@ -61,33 +62,8 @@ public class CacheConfiguration {
|
||||
.initialCapacity(100)
|
||||
.maximumSize(10000)
|
||||
.expireAfterAccess(1, TimeUnit.MINUTES)
|
||||
// .weakKeys()
|
||||
.weakKeys()
|
||||
.recordStats();
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("cacheManagerLongLived")
|
||||
public CacheManager cacheManagerLongLived() {
|
||||
CaffeineCacheManager cacheManager = new CaffeineCacheManager();
|
||||
Caffeine<Object, Object> cb = caffeineCacheBuilderLongLived();
|
||||
cacheManager.setCaffeine(cb);
|
||||
LOG.info("Configured cache manager with expiry {}", cb);
|
||||
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
Caffeine<Object, Object> caffeineCacheBuilderLongLived() {
|
||||
return Caffeine.newBuilder()
|
||||
.initialCapacity(100)
|
||||
.maximumSize(10000)
|
||||
.expireAfterAccess(2, TimeUnit.HOURS)
|
||||
// .weakKeys() Do not use weak keys - garbage collection will remove our values when we still want them
|
||||
.recordStats();
|
||||
}
|
||||
|
||||
public Cache getCache(String cacheName, String cacheManagerQualifier) {
|
||||
CacheManager cm = applicationContext.getBeansOfType(CacheManager.class).get(cacheManagerQualifier);
|
||||
return cm.getCache(cacheName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
5
base-container/src/main/java/com/telecominfraproject/wlan/core/server/cache/CacheType.java
vendored
Normal file
5
base-container/src/main/java/com/telecominfraproject/wlan/core/server/cache/CacheType.java
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.telecominfraproject.wlan.core.server.cache;
|
||||
|
||||
public enum CacheType {
|
||||
|
||||
}
|
||||
@@ -8,51 +8,10 @@ import java.net.InetAddress;
|
||||
*/
|
||||
public interface ConnectorProperties {
|
||||
|
||||
/**
|
||||
* @return port on which this server listens for internal API requests
|
||||
*/
|
||||
int getInternalPort();
|
||||
|
||||
/**
|
||||
* @return host on which this server listens for internal API requests
|
||||
*/
|
||||
String getInternalHostName();
|
||||
|
||||
/**
|
||||
* @return ip address on which this server listens for internal API requests
|
||||
*/
|
||||
InetAddress getInternalIpAddress();
|
||||
|
||||
|
||||
/**
|
||||
* @return port on which this server listens for API requests from the outside world
|
||||
*/
|
||||
int getExternalPort();
|
||||
|
||||
/**
|
||||
* @return host on which this server listens for API requests from the outside world
|
||||
*/
|
||||
String getExternalHostName();
|
||||
|
||||
/**
|
||||
* @return ip address on which this server listens for API requests from the outside world
|
||||
*/
|
||||
int getInternalPort();
|
||||
InetAddress getExternalIpAddress();
|
||||
|
||||
|
||||
/**
|
||||
* @return port which this server advertises to clients so that they can send API requests from the outside world, could be a load-balancer port, or a kubernetes-remapped port
|
||||
*/
|
||||
int getExternallyVisiblePort();
|
||||
|
||||
/**
|
||||
* @return host which this server advertises to clients so that they can send API requests from the outside world, could be a load-balancer host, or a kubernetes-remapped host
|
||||
*/
|
||||
String getExternallyVisibleHostName();
|
||||
|
||||
/**
|
||||
* @return ip address which this server advertises to clients so that they can send API requests from the outside world, could be a load-balancer ip address, or a kubernetes-remapped ip address
|
||||
*/
|
||||
InetAddress getExternallyVisibleIpAddress();
|
||||
|
||||
InetAddress getInternalIpAddress();
|
||||
String getExternalHostName();
|
||||
String getInternalHostName();
|
||||
}
|
||||
|
||||
@@ -17,21 +17,14 @@ public class ConnectorPropertiesImpl implements ConnectorProperties {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ConnectorProperties.class);
|
||||
|
||||
//host and port on which this server listens for internal API requests
|
||||
private final int externalPort;
|
||||
private final int internalPort;
|
||||
private final String internalHostName;
|
||||
private final InetAddress externalIpAddress;
|
||||
private final InetAddress internalIpAddress;
|
||||
|
||||
//host and port on which this server listens for API requests from the outside world
|
||||
private final int externalPort;
|
||||
private final String externalHostName;
|
||||
private final InetAddress externalIpAddress;
|
||||
private final String internalHostName;
|
||||
|
||||
//host and port which this server advertises to clients so that they can send API requests from the outside world, could be a load-balancer host and port, or a kubernetes-remapped host/port
|
||||
private final int externallyVisiblePort;
|
||||
private final String externallyVisibleHostName;
|
||||
private final InetAddress externallyVisibleIpAddress;
|
||||
|
||||
public ConnectorPropertiesImpl(Environment environment){
|
||||
|
||||
int _externalPort = Integer.parseInt(environment.getProperty("server.port").trim());
|
||||
@@ -79,46 +72,26 @@ public class ConnectorPropertiesImpl implements ConnectorProperties {
|
||||
_internalHostName = _internalIpAddress.getCanonicalHostName();
|
||||
}
|
||||
|
||||
|
||||
//Populate externally-visible properties, if any
|
||||
int _externallyVisiblePort = Integer.parseInt(environment.getProperty("tip.wlan.externallyVisiblePort", "0").trim());
|
||||
if(_externallyVisiblePort == 0) {
|
||||
_externallyVisiblePort = _externalPort;
|
||||
}
|
||||
|
||||
String _externallyVisibleHostName = environment.getProperty("tip.wlan.externallyVisibleHostName");
|
||||
if(_externallyVisibleHostName == null || _externallyVisibleHostName.trim().isEmpty()) {
|
||||
_externallyVisibleHostName = _externalHostName;
|
||||
}
|
||||
|
||||
InetAddress _externallyVisibleIpAddress;
|
||||
String externallyVisibleIpAddrStr = environment.getProperty("tip.wlan.externallyVisibleIpAddress");
|
||||
if(externallyVisibleIpAddrStr == null) {
|
||||
_externallyVisibleIpAddress = _externalIpAddress;
|
||||
} else {
|
||||
try {
|
||||
_externallyVisibleIpAddress = InetAddress.getByName(externallyVisibleIpAddrStr.trim());
|
||||
} catch (UnknownHostException e) {
|
||||
throw new ConfigurationException("Cannot get externally visible address of the system", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.externalIpAddress = _externalIpAddress;
|
||||
this.externalHostName = _externalHostName;
|
||||
this.externalPort = _externalPort;
|
||||
|
||||
this.internalIpAddress = _internalIpAddress;
|
||||
this.internalHostName = _internalHostName;
|
||||
this.internalPort = _internalPort;
|
||||
|
||||
this.externallyVisibleIpAddress = _externallyVisibleIpAddress;
|
||||
this.externallyVisibleHostName = _externallyVisibleHostName;
|
||||
this.externallyVisiblePort = _externallyVisiblePort;
|
||||
|
||||
LOG.info("connectorProperties {}", this);
|
||||
}
|
||||
|
||||
public ConnectorPropertiesImpl(String externalHostName, InetAddress externalIpAddress, int externalPort,
|
||||
String internalHostName, InetAddress internalIpAddress, int internalPort) {
|
||||
this.externalIpAddress = externalIpAddress;
|
||||
this.externalHostName = externalHostName;
|
||||
this.externalPort = externalPort;
|
||||
this.internalIpAddress = internalIpAddress;
|
||||
this.internalHostName = internalHostName;
|
||||
this.internalPort = internalPort;
|
||||
}
|
||||
|
||||
public int getExternalPort() {
|
||||
return externalPort;
|
||||
@@ -144,24 +117,24 @@ public class ConnectorPropertiesImpl implements ConnectorProperties {
|
||||
return internalHostName;
|
||||
}
|
||||
|
||||
public int getExternallyVisiblePort() {
|
||||
return externallyVisiblePort;
|
||||
}
|
||||
|
||||
public String getExternallyVisibleHostName() {
|
||||
return externallyVisibleHostName;
|
||||
}
|
||||
|
||||
public InetAddress getExternallyVisibleIpAddress() {
|
||||
return externallyVisibleIpAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format(
|
||||
"ConnectorPropertiesImpl [internalPort=%s, internalHostName=%s, internalIpAddress=%s, externalPort=%s, externalHostName=%s, externalIpAddress=%s, externallyVisiblePort=%s, externallyVisibleHostName=%s, externallyVisibleIpAddress=%s]",
|
||||
internalPort, internalHostName, internalIpAddress, externalPort, externalHostName, externalIpAddress,
|
||||
externallyVisiblePort, externallyVisibleHostName, externallyVisibleIpAddress);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("ConnectorProperties [externalHostName=");
|
||||
builder.append(externalHostName);
|
||||
builder.append(", externalIpAddress=");
|
||||
builder.append(externalIpAddress);
|
||||
builder.append(", externalPort=");
|
||||
builder.append(externalPort);
|
||||
builder.append(", internalHostName=");
|
||||
builder.append(internalHostName);
|
||||
builder.append(", internalIpAddress=");
|
||||
builder.append(internalIpAddress);
|
||||
builder.append(", internalPort=");
|
||||
builder.append(internalPort);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class NoSSLContainerCustomizer extends ServletContainerCustomizer {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
connector.setAttribute(ConnectorType.CONNECTOR_ATTRIBUTE_NAME, ConnectorType.externalConnector);
|
||||
connector.setAttribute("maxThreads", Integer.parseInt(appContext.getEnvironment().getProperty("tip.wlan.maxHttpThreads", "100")));
|
||||
connector.setAttribute("maxThreads", Integer.parseInt(appContext.getEnvironment().getProperty("maxHttpThreads", "100")));
|
||||
|
||||
enableCompression(connector);
|
||||
|
||||
|
||||
@@ -178,14 +178,8 @@ public abstract class ServletContainerCustomizer implements WebServerFactoryCust
|
||||
LOG.debug("setting SSL useServerCipherSuitesOrder to {}", bValue);
|
||||
connector.setAttribute("useServerCipherSuitesOrder", bValue);
|
||||
}
|
||||
|
||||
strValue = getSslProperty(environment, "sslEnabledProtocols", sslPropPrefix);
|
||||
if (null != strValue) {
|
||||
LOG.debug("setting SSL EnabledProtocols to {}", strValue);
|
||||
connector.setProperty("enabledProtocols", strValue);
|
||||
}
|
||||
|
||||
connector.setAttribute("maxThreads", Integer.parseInt(appContext.getEnvironment().getProperty("tip.wlan.maxHttpThreads", "100")));
|
||||
|
||||
connector.setAttribute("maxThreads", Integer.parseInt(appContext.getEnvironment().getProperty("maxHttpThreads", "100")));
|
||||
|
||||
LOG.info("Configured https connector for port {} with {} threads", connector.getPort(), connector.getAttribute("maxThreads"));
|
||||
}
|
||||
|
||||
@@ -66,7 +66,6 @@ import org.springframework.security.web.header.HeaderWriter;
|
||||
import org.springframework.security.web.util.matcher.AnyRequestMatcher;
|
||||
import org.springframework.security.web.util.matcher.RequestMatcher;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
import com.telecominfraproject.wlan.core.server.container.ConnectorProperties;
|
||||
import com.telecominfraproject.wlan.core.server.security.auth0.Auth0AuthenticationEntryPoint;
|
||||
import com.telecominfraproject.wlan.core.server.security.auth0.Auth0AuthenticationFilter;
|
||||
@@ -88,9 +87,14 @@ public abstract class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WebSecurityConfig.class);
|
||||
public static final String AUTH_CACHE_NAME = "auth_details_cache";
|
||||
|
||||
|
||||
public static final SimpleGrantedAuthority USER_AUTHORITY = new SimpleGrantedAuthority("ROLE_USER");
|
||||
public static final SimpleGrantedAuthority MSP_AUTHORITY = new SimpleGrantedAuthority("ROLE_MSP");
|
||||
public static final SimpleGrantedAuthority SERVICE_PROVIDER_AUTHORITY = new SimpleGrantedAuthority("ROLE_SERVICE_PROVIDER");
|
||||
public static final SimpleGrantedAuthority TECH_SUPPORT_AUTHORITY = new SimpleGrantedAuthority("ROLE_TECH_SUPPORT");
|
||||
public static final SimpleGrantedAuthority CUSTOMER_EQUIPMENT_AUTHORITY = new SimpleGrantedAuthority("ROLE_CUSTOMER_EQUIPMENT");
|
||||
public static final SimpleGrantedAuthority API_AUTHORITY = new SimpleGrantedAuthority("ROLE_API");
|
||||
|
||||
|
||||
/**
|
||||
* Maximum number of auth0 provider
|
||||
@@ -105,13 +109,11 @@ public abstract class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
List<SimpleGrantedAuthority> authorities = PortalUserRole.getAllAuthorities();
|
||||
authorities.add(CUSTOMER_EQUIPMENT_AUTHORITY);
|
||||
authorities.add(API_AUTHORITY);
|
||||
UserDetailsService uds = new InMemoryUserDetailsManager(
|
||||
Arrays.asList(new UserDetails[] { new User(environment.getProperty("tip.wlan.serviceUser", "user"),
|
||||
environment.getProperty("tip.wlan.servicePassword", "password"), true, true, true, true,
|
||||
authorities)}));
|
||||
Arrays.asList(new SimpleGrantedAuthority[] { USER_AUTHORITY, MSP_AUTHORITY,
|
||||
SERVICE_PROVIDER_AUTHORITY, TECH_SUPPORT_AUTHORITY, API_AUTHORITY })), }));
|
||||
|
||||
return uds;
|
||||
}
|
||||
@@ -863,42 +865,38 @@ public abstract class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
*
|
||||
* @param providerIndex
|
||||
* @param defaultProperties
|
||||
* @return null if clientSecret is not set.
|
||||
* @return null if clientId is not set.
|
||||
* @throws Exception
|
||||
*/
|
||||
protected Auth0AuthenticationProvider createAuth0AuthenticationProvider(int providerIndex) throws Exception {
|
||||
String clientId;
|
||||
String clientSecret;
|
||||
String issuer;
|
||||
String securedRoute;
|
||||
String accessTypeValue;
|
||||
String jwksLocation;
|
||||
String claimsNamespace;
|
||||
if (0 == providerIndex) {
|
||||
clientId = environment.getProperty("tip.wlan.auth0.clientId", DEFAULT_AUTH0_PROPERTY);
|
||||
clientSecret = environment.getProperty("tip.wlan.auth0.clientSecret", DEFAULT_AUTH0_PROPERTY);
|
||||
issuer = environment.getProperty("tip.wlan.auth0.issuerUri", DEFAULT_AUTH0_PROPERTY);
|
||||
securedRoute = environment.getProperty("tip.wlan.auth0.securedRoute", DEFAULT_AUTH0_PROPERTY);
|
||||
accessTypeValue = environment.getProperty("tip.wlan.auth0.accessType",
|
||||
getDefaultAccessType(providerIndex));
|
||||
jwksLocation = environment.getProperty("tip.wlan.auth0.jwksLocation", DEFAULT_AUTH0_PROPERTY);
|
||||
claimsNamespace = environment.getProperty("tip.wlan.auth0.claimsNamespace", "https://wlan.telecominfraproject.com/"); // See Auth0UserDetails
|
||||
} else {
|
||||
clientId = environment.getProperty("tip.wlan.auth0.clientId" + providerIndex);
|
||||
clientSecret = environment.getProperty("tip.wlan.auth0.clientSecret" + providerIndex);
|
||||
issuer = environment.getProperty("tip.wlan.auth0.issuerUri" + providerIndex);
|
||||
securedRoute = environment.getProperty("tip.wlan.auth0.securedRoute" + providerIndex,
|
||||
DEFAULT_AUTH0_PROPERTY);
|
||||
accessTypeValue = environment.getProperty("tip.wlan.auth0.accessType" + providerIndex,
|
||||
getDefaultAccessType(providerIndex));
|
||||
jwksLocation = environment.getProperty("tip.wlan.auth0.jwksLocation" + providerIndex);
|
||||
claimsNamespace = environment.getProperty("tip.wlan.auth0.claimsNamespace" + providerIndex, "https://wlan.telecominfraproject.com/");
|
||||
}
|
||||
// Be default, use HS256 decoding which requires clientSecret
|
||||
if (null == clientSecret) {
|
||||
if (null == clientId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
AccessType accessType = AccessType.valueOf(accessTypeValue);
|
||||
Auth0AuthenticationProvider auth0Provider = new Auth0AuthenticationProvider(accessType);
|
||||
auth0Provider.setClientId(clientId);
|
||||
auth0Provider.setClientSecret(clientSecret);
|
||||
auth0Provider.setIssuer(issuer);
|
||||
auth0Provider.setJwksLocation(jwksLocation);
|
||||
auth0Provider.setClaimsNamespace(claimsNamespace);
|
||||
auth0Provider.setSecuredRoute(securedRoute);
|
||||
auth0Provider.afterPropertiesSet();
|
||||
LOG.info("Loaded configuration for auth0 provider {}", providerIndex);
|
||||
return auth0Provider;
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package com.telecominfraproject.wlan.core.server.security.auth0;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.List;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
@@ -16,43 +13,28 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import com.auth0.jwk.Jwk;
|
||||
import com.auth0.jwk.JwkException;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.exceptions.JWTDecodeException;
|
||||
import com.auth0.jwt.exceptions.JWTVerificationException;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.telecominfraproject.wlan.core.server.security.AccessType;
|
||||
import com.telecominfraproject.wlan.server.exceptions.ConfigurationException;
|
||||
|
||||
/**
|
||||
* Class that verifies the JWT token and in case of being valid, it will set
|
||||
* Class that verifies the JWT token and in case of beeing valid, it will set
|
||||
* the userdetails in the authentication object
|
||||
*
|
||||
* @author Daniel Teixeira
|
||||
* @author rlee
|
||||
*/
|
||||
public class Auth0AuthenticationProvider implements AuthenticationProvider, InitializingBean {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Auth0AuthenticationProvider.class);
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private JWTVerifier jwtVerifier = null;
|
||||
private String clientSecret = null;
|
||||
private String issuer = null;
|
||||
private String jwksLocation = null;
|
||||
private String claimsNamespace = null;
|
||||
private String clientId = null;
|
||||
private String securedRoute = null;
|
||||
private final AccessType accessType;
|
||||
private static final AuthenticationException AUTH_ERROR = new Auth0TokenException("Authentication error occured");
|
||||
|
||||
|
||||
public Auth0AuthenticationProvider(AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
}
|
||||
@@ -60,52 +42,35 @@ public class Auth0AuthenticationProvider implements AuthenticationProvider, Init
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
|
||||
String token = ((Auth0JWTToken) authentication).getJwt();
|
||||
LOG.trace("Auth0 trying to authenticate with token: {} ", token);
|
||||
|
||||
try {
|
||||
Auth0JWTToken tokenAuth = ((Auth0JWTToken) authentication);
|
||||
|
||||
DecodedJWT jwt = JWT.decode(token);
|
||||
String alg = jwt.getAlgorithm();
|
||||
|
||||
// Get jwks file
|
||||
Jwk jwk = getJwk(jwt.getKeyId());
|
||||
if (jwk == null) {
|
||||
throw new JwkException("jwk could not be found");
|
||||
}
|
||||
|
||||
Algorithm algorithm;
|
||||
if (alg.equals("RS256")) {
|
||||
// create RS256 key decoder
|
||||
algorithm = Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null);
|
||||
} else {
|
||||
// create HS256 key decoder
|
||||
algorithm = Algorithm.HMAC256(clientSecret);
|
||||
}
|
||||
|
||||
JWTVerifier verifier = JWT.require(algorithm)
|
||||
.withIssuer(issuer)
|
||||
.build();
|
||||
|
||||
jwt = verifier.verify(token);
|
||||
LOG.trace("Decoded JWT token {}", jwt);
|
||||
LOG.trace("Auth0 trying to authenticate with token: {} ", token);
|
||||
|
||||
Map<String, Object> decoded;
|
||||
try {
|
||||
|
||||
Auth0JWTToken tokenAuth = ((Auth0JWTToken) authentication);
|
||||
decoded = jwtVerifier.verify(token);
|
||||
LOG.trace("Decoded JWT token {}", decoded);
|
||||
tokenAuth.setAuthenticated(true);
|
||||
tokenAuth.setPrincipal(new Auth0UserDetails(jwt, this.accessType, claimsNamespace));
|
||||
tokenAuth.setDetails(jwt);
|
||||
tokenAuth.setPrincipal(new Auth0UserDetails(decoded, this.accessType));
|
||||
tokenAuth.setDetails(decoded);
|
||||
return authentication;
|
||||
|
||||
} catch (JWTDecodeException e) {
|
||||
LOG.error("JWTDecodeException thrown while decoding JWT token", e);
|
||||
} catch (InvalidKeyException e) {
|
||||
LOG.error("InvalidKeyException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (JWTVerificationException e) {
|
||||
LOG.error("JWTVerificationException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (JwkException e) {
|
||||
LOG.error("JwkException thrown while decoding JWT token", e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
LOG.error("NoSuchAlgorithmException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (IllegalStateException e) {
|
||||
LOG.error("IllegalStateException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (SignatureException e) {
|
||||
LOG.debug("SignatureException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,84 +79,21 @@ public class Auth0AuthenticationProvider implements AuthenticationProvider, Init
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if ((clientSecret == null) || (issuer == null)) {
|
||||
throw new ConfigurationException("Client secret or issuer URI is not set for Auth0AuthenticationProvider");
|
||||
if ((clientSecret == null) || (clientId == null)) {
|
||||
throw new ConfigurationException("Client secret or client id is not set for Auth0AuthenticationProvider");
|
||||
}
|
||||
if (securedRoute == null) {
|
||||
throw new ConfigurationException("SecureRoute is not set for Auth0AuthenticationProvider");
|
||||
}
|
||||
jwtVerifier = new JWTVerifier(clientSecret, clientId);
|
||||
}
|
||||
|
||||
private Jwk getJwk(String keyId) {
|
||||
try {
|
||||
String jwksSource = getJwksString();
|
||||
if (jwksSource == null) {
|
||||
throw new FileNotFoundException("jwks could not be found");
|
||||
}
|
||||
|
||||
List<Jwk> jwks = Lists.newArrayList();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> keys = (List<Map<String, Object>>) mapper.readValue(jwksSource, Map.class).get("keys");
|
||||
|
||||
for (Map<String, Object> values : keys) {
|
||||
jwks.add(Jwk.fromValues(values));
|
||||
}
|
||||
|
||||
if (keyId == null && jwks.size() == 1) {
|
||||
return jwks.get(0);
|
||||
}
|
||||
|
||||
if (keyId != null) {
|
||||
for (Jwk jwk : jwks) {
|
||||
if (keyId.equals(jwk.getId())) {
|
||||
// Can only contain 1 matching jwk
|
||||
return jwk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (JsonMappingException e) {
|
||||
LOG.error("JsonMappingException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (JsonProcessingException e) {
|
||||
LOG.error("JsonProcessingException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (FileNotFoundException e) {
|
||||
LOG.error("FileNotFoundException thrown while decoding JWT token", e);
|
||||
throw AUTH_ERROR;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
public String getSecuredRoute() {
|
||||
return securedRoute;
|
||||
}
|
||||
|
||||
private String getJwksString() {
|
||||
LOG.debug("Loading jwks from {}", jwksLocation);
|
||||
String ret = null;
|
||||
|
||||
try {
|
||||
Object jwksObj = ResourceUtils.getURL(jwksLocation).getContent();
|
||||
if (jwksObj instanceof InputStream) {
|
||||
ret = readFromInputStream((InputStream) jwksObj);
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
LOG.error("FileNotFoundException thrown while getting jwks", e);
|
||||
throw AUTH_ERROR;
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException thrown while getting jwks", e);
|
||||
throw AUTH_ERROR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
private String readFromInputStream(InputStream inputStream) {
|
||||
StringBuilder resultStringBuilder = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
resultStringBuilder.append(line).append("\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException thrown while getting jwks", e);
|
||||
throw AUTH_ERROR;
|
||||
}
|
||||
return resultStringBuilder.toString();
|
||||
|
||||
public void setSecuredRoute(String securedRoute) {
|
||||
this.securedRoute = securedRoute;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
@@ -202,31 +104,15 @@ public class Auth0AuthenticationProvider implements AuthenticationProvider, Init
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getIssuer() {
|
||||
return issuer;
|
||||
}
|
||||
|
||||
public void setIssuer(String issuer) {
|
||||
this.issuer = issuer;
|
||||
}
|
||||
|
||||
public String getJwksLocation() {
|
||||
return jwksLocation;
|
||||
}
|
||||
|
||||
public void setJwksLocation(String jwksLocation) {
|
||||
this.jwksLocation = jwksLocation;
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public String getClaimsNamespace() {
|
||||
return claimsNamespace;
|
||||
}
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public void setClaimsNamespace(String claimsNamespace) {
|
||||
this.claimsNamespace = claimsNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Use to encode raw secret to Base 64 URL safe string
|
||||
*
|
||||
* @param args
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.telecominfraproject.wlan.core.server.security.auth0;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -10,8 +10,6 @@ import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
import com.telecominfraproject.wlan.core.server.security.AccessType;
|
||||
import com.telecominfraproject.wlan.core.server.security.AuthProviderInfo;
|
||||
|
||||
@@ -19,8 +17,6 @@ import com.telecominfraproject.wlan.core.server.security.AuthProviderInfo;
|
||||
* Implementation of UserDetails in compliance with the decoded object returned
|
||||
* by the Auth0 JWT
|
||||
*
|
||||
* claimsNamespace is used to allow for OIDC compliance of custom claims in JWT.
|
||||
*
|
||||
* @author Daniel Teixeira
|
||||
*
|
||||
*/
|
||||
@@ -28,75 +24,52 @@ public class Auth0UserDetails implements UserDetails, AuthProviderInfo {
|
||||
|
||||
private static final long serialVersionUID = 2058797193125711681L;
|
||||
|
||||
private DecodedJWT details;
|
||||
private Map<String, Object> details;
|
||||
private String username;
|
||||
private boolean emailVerified = false;
|
||||
private Collection<GrantedAuthority> authorities = null;
|
||||
private final AccessType accessType;
|
||||
private static final String EMAIL_CLAIM = "email";
|
||||
private static final String EMAIL_VERIFIED_CLAIM = "email_verified";
|
||||
private static final String NICKNAME_CLAIM = "nickname";
|
||||
private static final String ROLES_CLAIM = "roles";
|
||||
|
||||
private static final Log LOGGER = LogFactory.getLog(Auth0UserDetails.class);
|
||||
|
||||
public Auth0UserDetails(DecodedJWT jwt, AccessType accessType) {
|
||||
this(jwt, accessType, null);
|
||||
}
|
||||
|
||||
public Auth0UserDetails(DecodedJWT jwt, AccessType accessType, String claimsNamespace) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Auth0UserDetails(Map<String, Object> map, AccessType accessType) {
|
||||
this.accessType = accessType;
|
||||
String emailClaim;
|
||||
String emailVerifiedClaim;
|
||||
String nicknameClaim;
|
||||
String rolesClaim;
|
||||
if (claimsNamespace != null) {
|
||||
emailClaim = claimsNamespace + EMAIL_CLAIM;
|
||||
emailVerifiedClaim = claimsNamespace + EMAIL_VERIFIED_CLAIM;
|
||||
nicknameClaim = claimsNamespace + NICKNAME_CLAIM;
|
||||
rolesClaim = claimsNamespace + ROLES_CLAIM;
|
||||
} else {
|
||||
emailClaim = EMAIL_CLAIM;
|
||||
emailVerifiedClaim = EMAIL_VERIFIED_CLAIM;
|
||||
nicknameClaim = NICKNAME_CLAIM;
|
||||
rolesClaim = ROLES_CLAIM;
|
||||
}
|
||||
if (!jwt.getClaim(emailClaim).isNull()) {
|
||||
this.username = jwt.getClaim(emailClaim).asString();
|
||||
} else if (!jwt.getClaim(nicknameClaim).isNull()) {
|
||||
this.username = jwt.getClaim(nicknameClaim).asString();
|
||||
} else if (jwt.getId() != null) {
|
||||
this.username = jwt.getId();
|
||||
} else if (jwt.getSubject() != null) {
|
||||
this.username = jwt.getSubject();
|
||||
if (map.containsKey("email")) {
|
||||
this.username = map.get("email").toString();
|
||||
} else if (map.containsKey("username")) {
|
||||
this.username = map.get("username").toString();
|
||||
} else if (map.containsKey("user_id")) {
|
||||
this.username = map.get("user_id").toString();
|
||||
} else {
|
||||
this.username = "UNKNOWN_USER";
|
||||
}
|
||||
|
||||
if (!jwt.getClaim(emailClaim).isNull()) {
|
||||
this.emailVerified = Boolean.valueOf(jwt.getClaim(emailVerifiedClaim).toString());
|
||||
if (map.containsKey("email")) {
|
||||
this.emailVerified = Boolean.valueOf(map.get("email_verified").toString());
|
||||
}
|
||||
|
||||
// set authorities
|
||||
authorities = new ArrayList<>();
|
||||
if (!jwt.getClaim(rolesClaim).isNull()) {
|
||||
List<String> roles = null;
|
||||
if (map.containsKey("roles")) {
|
||||
ArrayList<String> roles = null;
|
||||
try {
|
||||
roles = jwt.getClaim(rolesClaim).asList(String.class);
|
||||
roles = (ArrayList<String>) map.get("roles");
|
||||
for (String role : roles) {
|
||||
authorities.add(new SimpleGrantedAuthority(role));
|
||||
}
|
||||
} catch (java.lang.ClassCastException e) {
|
||||
// e.printStackTrace();
|
||||
LOGGER.error("Error in casting the roles object", e);
|
||||
}
|
||||
}
|
||||
|
||||
// By default, set to CustomerIT authority if nothing is added
|
||||
// By default if nothing is added
|
||||
if (authorities.isEmpty()) {
|
||||
authorities.add(PortalUserRole.CustomerIT.getAuthority());
|
||||
authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
}
|
||||
|
||||
this.details = jwt;
|
||||
this.details = map;
|
||||
|
||||
}
|
||||
|
||||
@@ -155,11 +128,7 @@ public class Auth0UserDetails implements UserDetails, AuthProviderInfo {
|
||||
* otherwise
|
||||
*/
|
||||
public Object getAuth0Attribute(String attributeName) {
|
||||
if (details.getClaim(attributeName).isNull()) {
|
||||
LOGGER.debug("No attribute was found : " + attributeName);
|
||||
return null;
|
||||
}
|
||||
return details.getClaim(attributeName);
|
||||
return details.get(attributeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package com.telecominfraproject.wlan.core.server.security.auth0.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Date;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.auth0.jwt.algorithms.Algorithm;
|
||||
import com.auth0.jwt.interfaces.DecodedJWT;
|
||||
import com.auth0.jwk.Jwk;
|
||||
import com.auth0.jwk.JwkException;
|
||||
import com.auth0.jwk.JwkProvider;
|
||||
import com.auth0.jwk.UrlJwkProvider;
|
||||
import com.auth0.jwt.JWT;
|
||||
import com.auth0.jwt.Algorithm;
|
||||
import com.auth0.jwt.ClaimSet;
|
||||
import com.auth0.jwt.JWTVerifier;
|
||||
import com.auth0.jwt.JwtSigner;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.telecominfraproject.wlan.core.server.security.auth0.Auth0TokenHelper;
|
||||
@@ -27,23 +25,26 @@ public class Auth0TokenHelperImpl implements Auth0TokenHelper<Object>, Initializ
|
||||
private static final Log Logger = LogFactory.getLog(Auth0TokenHelperImpl.class);
|
||||
|
||||
private String clientSecret = null;
|
||||
private String issuer = null;
|
||||
private String clientId = null;
|
||||
|
||||
@Override
|
||||
public String generateToken(Object object, int expiration) {
|
||||
|
||||
String token;
|
||||
String payload, token;
|
||||
try {
|
||||
|
||||
Algorithm hsEncoded = Algorithm.HMAC256(clientSecret);
|
||||
token = JWT.create()
|
||||
.withIssuer(issuer)
|
||||
.withExpiresAt(new Date(expiration))
|
||||
.withClaim("payload", new ObjectMapper().writeValueAsString(object))
|
||||
.sign(hsEncoded);
|
||||
|
||||
JwtSigner jwtSigner = new JwtSigner();
|
||||
payload = new ObjectMapper().writeValueAsString(object);
|
||||
|
||||
ClaimSet claimSet = new ClaimSet();
|
||||
claimSet.setExp(expiration); // expire in 1 year
|
||||
|
||||
token = jwtSigner.encode(Algorithm.HS256, payload, "payload", new String(Base64.decodeBase64(clientSecret)), claimSet);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
}
|
||||
|
||||
return token;
|
||||
@@ -52,43 +53,39 @@ public class Auth0TokenHelperImpl implements Auth0TokenHelper<Object>, Initializ
|
||||
|
||||
@Override
|
||||
public Object decodeToken(String token) {
|
||||
|
||||
JWTVerifier jwtVerifier = new JWTVerifier(clientSecret, clientId);
|
||||
|
||||
|
||||
JwkProvider jwkProvider = new UrlJwkProvider(issuer);
|
||||
|
||||
Map<String, Object> verify;
|
||||
try {
|
||||
DecodedJWT jwt = JWT.decode(token);
|
||||
String alg = jwt.getAlgorithm();
|
||||
|
||||
// Get jwk
|
||||
Jwk jwk = jwkProvider.get(jwt.getKeyId());
|
||||
|
||||
Algorithm algorithm;
|
||||
if (alg.equals("RS256")) {
|
||||
// create RS256 key decoder
|
||||
algorithm = Algorithm.RSA256((RSAPublicKey) jwk.getPublicKey(), null);
|
||||
} else {
|
||||
// create HS256 key decoder
|
||||
algorithm = Algorithm.HMAC256(clientSecret);
|
||||
}
|
||||
|
||||
JWTVerifier verifier = JWT.require(algorithm)
|
||||
.withIssuer(issuer)
|
||||
.build();
|
||||
|
||||
jwt = verifier.verify(token);
|
||||
|
||||
verify = jwtVerifier.verify(token);
|
||||
String payload = (String) verify.get("$");
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, String> map = new ObjectMapper().readValue(jwt.getPayload(), Map.class);
|
||||
Map<String, String> map = new ObjectMapper().readValue(payload, Map.class);
|
||||
return map;
|
||||
|
||||
} catch (IllegalStateException|IOException|JwkException e) {
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
} catch (IllegalStateException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
} catch (SignatureException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new Auth0RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(clientSecret, "The client secret is not set for " + this.getClass());
|
||||
Assert.notNull(clientId, "The client id is not set for " + this.getClass());
|
||||
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
@@ -99,4 +96,12 @@ public class Auth0TokenHelperImpl implements Auth0TokenHelper<Object>, Initializ
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.server.webconfig;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
public class ByteArrayHttpMessageConverterConfig {
|
||||
|
||||
/**
|
||||
* Create byte array http message converter
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() {
|
||||
ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
|
||||
arrayHttpMessageConverter.setSupportedMediaTypes(getSupportedMediaTypes());
|
||||
return arrayHttpMessageConverter;
|
||||
}
|
||||
|
||||
private List<MediaType> getSupportedMediaTypes() {
|
||||
List<MediaType> list = new ArrayList<>();
|
||||
list.add(MediaType.APPLICATION_OCTET_STREAM);
|
||||
list.add(MediaType.IMAGE_JPEG);
|
||||
list.add(MediaType.IMAGE_PNG);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import com.telecominfraproject.wlan.core.model.json.JsonSerializedException;
|
||||
/**
|
||||
* @author dtoptygin
|
||||
*/
|
||||
@ControllerAdvice(basePackages = "com.telecominfraproject")
|
||||
@ControllerAdvice
|
||||
public class CommonControllerAdvice {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CommonControllerAdvice.class);
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.server.webconfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
/**
|
||||
* This is an example of ServletPreInvocableHandler.
|
||||
* To enable it - activate spring profile "useExampleServletPreInvocableHandler".
|
||||
*
|
||||
* @author dtop
|
||||
*
|
||||
*/
|
||||
@Component
|
||||
@Profile("useExampleServletPreInvocableHandler")
|
||||
public class ExampleServletPreInvocableHandler implements ServletPreInvocableHandler {
|
||||
|
||||
final static Logger LOG = LoggerFactory.getLogger(ExampleServletPreInvocableHandler.class);
|
||||
|
||||
@Override
|
||||
public void preInvoke(HandlerMethod handlerMethod, Object[] args) {
|
||||
|
||||
RequestMapping reqMapping = handlerMethod.getMethodAnnotation(RequestMapping.class);
|
||||
MethodParameter[] methodParamDefs = handlerMethod.getMethodParameters();
|
||||
Map<String, Object> methodParams = new HashMap<>();
|
||||
String pName;
|
||||
for(int i=0; i< args.length; i++) {
|
||||
if(i< methodParamDefs.length) {
|
||||
pName = methodParamDefs[i].getParameterName();
|
||||
if(pName==null) {
|
||||
pName = "unknown" + i;
|
||||
}
|
||||
} else {
|
||||
pName = "unknown" + i;
|
||||
}
|
||||
methodParams.put(pName, args[i]);
|
||||
}
|
||||
|
||||
LOG.info("Calling doInvoke on {}.{} : {} {} with parameters {} ", handlerMethod.getBean().getClass().getName(), handlerMethod.getMethod().getName(),
|
||||
reqMapping.path(), reqMapping.method(), methodParams);
|
||||
|
||||
//TODO: invoke some application logic in here, like fine-grained role-based access control
|
||||
if(reqMapping.path()[0].equals("/equipment/forCustomerWithFilter")) {
|
||||
throw new RuntimeException("Cannot do that!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.server.webconfig;
|
||||
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
|
||||
/**
|
||||
* This interface defines a method that is called after all the parameters are deserialized and converted to java objects but before the Controller method gets called.
|
||||
* Can be used for fine-grained role-based access control.
|
||||
* Many classes can implement this interface.
|
||||
* When marked as @Bean, all such classes will be registered and called before every Controller method.
|
||||
*
|
||||
* @see ExampleServletPreInvocableHandler
|
||||
* @author dtop
|
||||
*
|
||||
*/
|
||||
public interface ServletPreInvocableHandler {
|
||||
void preInvoke(HandlerMethod handlerMethod, Object[] args);
|
||||
}
|
||||
@@ -6,16 +6,18 @@ import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.format.FormatterRegistry;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
@@ -26,14 +28,9 @@ import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
@Configuration
|
||||
//@EnableWebMvc - DTOP: do not use this, it will break mapping for index.html file
|
||||
// see http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-spring-mvc-auto-configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
@Autowired
|
||||
private ByteArrayHttpMessageConverter byteArrayHttpMessageConverter;
|
||||
|
||||
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
@Autowired private Environment environment;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WebConfig.class);
|
||||
private static final String WEB_RESOURCE_PROP = "tip.wlan.webResources";
|
||||
|
||||
@@ -57,6 +54,8 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
resourceHandlerRegistration.setCachePeriod(Integer.getInteger("tip.wlan.webResources.cachePeriodSec", 0));
|
||||
}
|
||||
|
||||
|
||||
super.addResourceHandlers(registry);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,7 +91,26 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
converters.add(byteArrayHttpMessageConverter);
|
||||
converters.add(byteArrayHttpMessageConverter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create byte array http message converter
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public ByteArrayHttpMessageConverter byteArrayHttpMessageConverter() {
|
||||
ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
|
||||
arrayHttpMessageConverter.setSupportedMediaTypes(getSupportedMediaTypes());
|
||||
return arrayHttpMessageConverter;
|
||||
}
|
||||
|
||||
private List<MediaType> getSupportedMediaTypes() {
|
||||
List<MediaType> list = new ArrayList<>();
|
||||
list.add(MediaType.APPLICATION_OCTET_STREAM);
|
||||
list.add(MediaType.IMAGE_JPEG);
|
||||
list.add(MediaType.IMAGE_PNG);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
package com.telecominfraproject.wlan.core.server.webconfig;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -16,30 +14,19 @@ import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.Profiles;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod;
|
||||
|
||||
/**
|
||||
* @author yongli
|
||||
* @author dtop
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcRegistrationsConfiguration {
|
||||
final static Logger LOG = LoggerFactory.getLogger(WebMvcRegistrationsConfiguration.class);
|
||||
|
||||
@Autowired(required = false)
|
||||
private List<ServletPreInvocableHandler> servletPreInvocableHandlers;
|
||||
|
||||
/**
|
||||
* Use adaptor to filter out RequestMapping methods based on condition.<br>
|
||||
* Provide a way to register pre-invoke servlet handlers - to have common logic applied
|
||||
* after the parameters have been parsed and converted to java objects but before the Controller method itself is called.
|
||||
* @see ExampleServletPreInvocableHandler
|
||||
* @see ServletPreInvocableHandler
|
||||
* Use adaptor to filter out RequestMapping methods based on condition
|
||||
*
|
||||
* @param environment
|
||||
* @return
|
||||
@@ -47,11 +34,6 @@ public class WebMvcRegistrationsConfiguration {
|
||||
@Bean
|
||||
public WebMvcRegistrations mvcRegistrations(Environment environment) {
|
||||
LOG.info("Customizing WebMvcRegistrations");
|
||||
|
||||
if(servletPreInvocableHandlers!=null) {
|
||||
servletPreInvocableHandlers.forEach(h -> LOG.info("registering pre-invoke servlet handler {}", h) );
|
||||
}
|
||||
|
||||
return new WebMvcRegistrations() {
|
||||
@Override
|
||||
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
|
||||
@@ -81,28 +63,6 @@ public class WebMvcRegistrationsConfiguration {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
|
||||
return new RequestMappingHandlerAdapter() {
|
||||
@Override
|
||||
protected ServletInvocableHandlerMethod createInvocableHandlerMethod(HandlerMethod handlerMethod) {
|
||||
return new ServletInvocableHandlerMethod(handlerMethod) {
|
||||
@Override
|
||||
protected Object doInvoke(Object... args) throws Exception {
|
||||
|
||||
//apply all registered pre-invoke servlet handlers
|
||||
if(servletPreInvocableHandlers!=null) {
|
||||
servletPreInvocableHandlers.forEach(h -> h.preInvoke(handlerMethod, args) );
|
||||
}
|
||||
|
||||
return super.doInvoke(args);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-datastore-inmemory</artifactId>
|
||||
@@ -13,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-elasticsearch</artifactId>
|
||||
@@ -14,12 +15,12 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<!-- ElasticSearch dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-hazelcast-client</artifactId>
|
||||
@@ -21,12 +23,12 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>common-hazelcast</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-hierarchical-datastore</artifactId>
|
||||
@@ -13,17 +13,17 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-hazelcast-client</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-jdbc-tests</artifactId>
|
||||
@@ -16,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-jdbc</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.telecominfraproject.wlan.core.server.jdbc.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.reflections.Reflections;
|
||||
import org.reflections.scanners.ResourcesScanner;
|
||||
import org.reflections.util.ClasspathHelper;
|
||||
import org.reflections.util.ConfigurationBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -15,19 +22,18 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.test.context.transaction.BeforeTransaction;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.server.jdbc.BaseJDbcDataSource;
|
||||
import com.telecominfraproject.wlan.core.server.jdbc.BaseKeyColumnConverter;
|
||||
import com.telecominfraproject.wlan.core.server.jdbc.KeyColumnUpperCaseConverter;
|
||||
@@ -94,70 +100,53 @@ public abstract class BaseJdbcTest {
|
||||
// creates a HSQL in-memory db populated from scripts
|
||||
// classpath:schema-hsqldb-test.sql and classpath:test-data.sql
|
||||
// this will auto-wire DataSource object
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
|
||||
|
||||
// If the EmbeddedDatabaseBuilder class had a following method, we would have used it directly:
|
||||
// public EmbeddedDatabaseBuilder addScript(Resource scriptResource) {
|
||||
// this.databasePopulator.addScript(scriptResource);
|
||||
// return this;
|
||||
// }
|
||||
// But it does not have this method, and we will have to use reflection to achieve similar effect.
|
||||
//
|
||||
// We need to expose ResourceDatabasePopulator databasePopulator field of the
|
||||
// EmbeddedDatabaseBuilder to be able to pass to it resources with the same name
|
||||
// in the classpath, i.e. schema-hsqldb-test.sql files that are defined in
|
||||
// different modules
|
||||
ResourceDatabasePopulator dbPopulator;
|
||||
try {
|
||||
Field dbPopulatorField = EmbeddedDatabaseBuilder.class.getDeclaredField("databasePopulator");
|
||||
//the field is private, so we have to use a hammer
|
||||
dbPopulatorField.setAccessible(true);
|
||||
dbPopulator = (ResourceDatabasePopulator) dbPopulatorField.get(builder);
|
||||
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) {
|
||||
throw new RuntimeException("Cannot get access to dbPopulator of the EmbeddedDatabaseBuilder : " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
//
|
||||
// Add the schema-hsqldb-test.sql scripts to the DB builder
|
||||
//
|
||||
try {
|
||||
PathMatchingResourcePatternResolver pRes = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = pRes.getResources("classpath*:schema-hsqldb-test.sql");
|
||||
if(resources!=null) {
|
||||
for(Resource r: resources) {
|
||||
dbPopulator.addScript(r);
|
||||
LOG.debug("Adding SQL script {} - {}", r.getFilename(), r.getURI());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot load SQL scripts: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
|
||||
.addScript("classpath:schema-hsqldb-test.sql");
|
||||
|
||||
builder.generateUniqueName(true);
|
||||
|
||||
//
|
||||
// Now add the test-data.sql scripts to the DB builder
|
||||
// We only want to add the test-data.sql if the file actually
|
||||
// exists.
|
||||
//
|
||||
try {
|
||||
PathMatchingResourcePatternResolver pRes = new PathMatchingResourcePatternResolver();
|
||||
Resource[] resources = pRes.getResources("classpath*:test-data.sql");
|
||||
if(resources!=null) {
|
||||
for(Resource r: resources) {
|
||||
dbPopulator.addScript(r);
|
||||
LOG.debug("Adding SQL script {} - {}", r.getFilename(), r.getURI());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot load SQL scripts: ", e);
|
||||
Set<String> testDataFiles = getReflections().getResources(Pattern.compile("test-data.sql"));
|
||||
|
||||
if (!CollectionUtils.isEmpty(testDataFiles)) {
|
||||
builder.addScript("classpath:test-data.sql");
|
||||
}
|
||||
|
||||
|
||||
EmbeddedDatabase db = builder.build();
|
||||
|
||||
return new BaseJdbcTestDatabase(db, new KeyColumnUpperCaseConverter());
|
||||
}
|
||||
|
||||
public static Reflections getReflections() {
|
||||
//scan urls that contain 'com.telecominfraproject.wlan' and vendor-specific top level packages, use the ResourcesScanner
|
||||
|
||||
List<URL> urls = new ArrayList<>();
|
||||
urls.addAll(ClasspathHelper.forPackage("com.telecominfraproject.wlan"));
|
||||
|
||||
//add vendor packages
|
||||
String vendorTopLevelPackages = BaseJsonModel.getVendorTopLevelPackages();
|
||||
|
||||
if(vendorTopLevelPackages!=null) {
|
||||
String[] vendorPkgs = vendorTopLevelPackages.split(",");
|
||||
for(int i=0; i< vendorPkgs.length; i++) {
|
||||
if(vendorPkgs[i].trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
urls.addAll(ClasspathHelper.forPackage(vendorPkgs[i]));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reflections reflections = new Reflections(new ConfigurationBuilder()
|
||||
.setUrls(urls)
|
||||
.setScanners(new ResourcesScanner() ));
|
||||
|
||||
return reflections;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager(DataSource dataSource) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-jdbc</artifactId>
|
||||
@@ -41,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -20,10 +21,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import com.netflix.servo.DefaultMonitorRegistry;
|
||||
import com.netflix.servo.monitor.BasicCounter;
|
||||
import com.netflix.servo.annotations.DataSourceType;
|
||||
import com.netflix.servo.annotations.Monitor;
|
||||
import com.netflix.servo.monitor.BasicGauge;
|
||||
import com.netflix.servo.monitor.Counter;
|
||||
import com.netflix.servo.monitor.MonitorConfig;
|
||||
import com.netflix.servo.monitor.Monitors;
|
||||
import com.netflix.servo.tag.TagList;
|
||||
import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags;
|
||||
import com.telecominfraproject.wlan.server.exceptions.ConfigurationException;
|
||||
@@ -37,14 +39,8 @@ public abstract class BaseDataSourceConfig {
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
final Counter getConnectionExecuted = new BasicCounter(MonitorConfig.builder("jdbc-getConnection").withTags(tags).build());
|
||||
|
||||
// dtop: use anonymous constructor to ensure that the following code always
|
||||
// get executed,
|
||||
// even when somebody adds another constructor in here
|
||||
{
|
||||
DefaultMonitorRegistry.getInstance().register(getConnectionExecuted);
|
||||
}
|
||||
@Monitor(name = "getConnection", type = DataSourceType.COUNTER)
|
||||
private final AtomicInteger getConnectionExecuted = new AtomicInteger(0);
|
||||
|
||||
static interface DataSourceInSpringClassloaderInterface extends DataSource {
|
||||
}
|
||||
@@ -75,7 +71,7 @@ public abstract class BaseDataSourceConfig {
|
||||
}
|
||||
|
||||
public Connection getConnection() throws SQLException {
|
||||
getConnectionExecuted.increment();
|
||||
getConnectionExecuted.incrementAndGet();
|
||||
return dataSource.getConnection();
|
||||
}
|
||||
|
||||
@@ -84,7 +80,7 @@ public abstract class BaseDataSourceConfig {
|
||||
}
|
||||
|
||||
public Connection getConnection(String username, String password) throws SQLException {
|
||||
getConnectionExecuted.increment();
|
||||
getConnectionExecuted.incrementAndGet();
|
||||
return dataSource.getConnection(username, password);
|
||||
}
|
||||
|
||||
@@ -143,6 +139,8 @@ public abstract class BaseDataSourceConfig {
|
||||
String datasourceId = getDataSourceName();
|
||||
DataSourceInSpringClassloader wrappedObj = new DataSourceInSpringClassloader(datasourceId, poolDataSource);
|
||||
|
||||
Monitors.registerObject(datasourceId, this);
|
||||
|
||||
BasicGauge<Integer> numberOfActiveJDBCConnections = new BasicGauge<>(
|
||||
MonitorConfig.builder(getDataSourceName() + "-numberOfActiveJDBCConnections").withTags(tags).build(),
|
||||
new Callable<Integer>() {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
|
||||
@@ -15,7 +16,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-models</artifactId>
|
||||
@@ -14,20 +16,20 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>json-patch-tip</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- this is used to register all subclasses of BaseJsonModel for deserialization -->
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>reflections-tip</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
|
||||
@@ -43,11 +45,6 @@
|
||||
<artifactId>base62</artifactId>
|
||||
<version>${seruco.base62.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,369 +1,49 @@
|
||||
package com.telecominfraproject.wlan.core.model.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.telecominfraproject.wlan.core.model.extensibleenum.EnumWithId;
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.model.json.JsonDeserializationUtils;
|
||||
|
||||
public class CountryCode implements EnumWithId {
|
||||
public enum CountryCode {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CountryCode.class);
|
||||
|
||||
private static Object lock = new Object();
|
||||
private static final Map<Integer, CountryCode> ELEMENTS = new ConcurrentHashMap<>();
|
||||
private static final Map<String, CountryCode> ELEMENTS_BY_NAME = new ConcurrentHashMap<>();
|
||||
|
||||
public static final CountryCode AD = new CountryCode(1, "AD"),
|
||||
AE = new CountryCode(2, "AE"),
|
||||
AF = new CountryCode(3, "AF"),
|
||||
AG = new CountryCode(4, "AG"),
|
||||
AI = new CountryCode(5, "AI"),
|
||||
AL = new CountryCode(6, "AL"),
|
||||
AM = new CountryCode(7, "AM"),
|
||||
AO = new CountryCode(8, "AO"),
|
||||
AQ = new CountryCode(9, "AQ"),
|
||||
AR = new CountryCode(10, "AR"),
|
||||
AS = new CountryCode(11, "AS"),
|
||||
AT = new CountryCode(12, "AT"),
|
||||
AU = new CountryCode(13, "AU"),
|
||||
AW = new CountryCode(14, "AW"),
|
||||
AX = new CountryCode(15, "AX"),
|
||||
AZ = new CountryCode(16, "AZ"),
|
||||
BA = new CountryCode(17, "BA"),
|
||||
BB = new CountryCode(18, "BB"),
|
||||
BD = new CountryCode(19, "BD"),
|
||||
BE = new CountryCode(20, "BE"),
|
||||
BF = new CountryCode(21, "BF"),
|
||||
BG = new CountryCode(22, "BG"),
|
||||
BH = new CountryCode(23, "BH"),
|
||||
BI = new CountryCode(24, "BI"),
|
||||
BJ = new CountryCode(25, "BJ"),
|
||||
BL = new CountryCode(26, "BL"),
|
||||
BM = new CountryCode(27, "BM"),
|
||||
BN = new CountryCode(28, "BN"),
|
||||
BO = new CountryCode(29, "BO"),
|
||||
BQ = new CountryCode(30, "BQ"),
|
||||
BR = new CountryCode(31, "BR"),
|
||||
BS = new CountryCode(32, "BS"),
|
||||
BT = new CountryCode(33, "BT"),
|
||||
BV = new CountryCode(34, "BV"),
|
||||
BW = new CountryCode(35, "BW"),
|
||||
BY = new CountryCode(36, "BY"),
|
||||
BZ = new CountryCode(37, "BZ"),
|
||||
CA = new CountryCode(38, "CA"),
|
||||
CC = new CountryCode(39, "CC"),
|
||||
CD = new CountryCode(40, "CD"),
|
||||
CF = new CountryCode(41, "CF"),
|
||||
CG = new CountryCode(42, "CG"),
|
||||
CH = new CountryCode(43, "CH"),
|
||||
CI = new CountryCode(44, "CI"),
|
||||
CK = new CountryCode(45, "CK"),
|
||||
CL = new CountryCode(46, "CL"),
|
||||
CM = new CountryCode(47, "CM"),
|
||||
CN = new CountryCode(48, "CN"),
|
||||
CO = new CountryCode(49, "CO"),
|
||||
CR = new CountryCode(50, "CR"),
|
||||
CU = new CountryCode(51, "CU"),
|
||||
CV = new CountryCode(52, "CV"),
|
||||
CW = new CountryCode(53, "CW"),
|
||||
CX = new CountryCode(54, "CX"),
|
||||
CY = new CountryCode(55, "CY"),
|
||||
CZ = new CountryCode(56, "CZ"),
|
||||
DE = new CountryCode(57, "DE"),
|
||||
DJ = new CountryCode(58, "DJ"),
|
||||
DK = new CountryCode(59, "DK"),
|
||||
DM = new CountryCode(60, "DM"),
|
||||
DO = new CountryCode(61, "DO"),
|
||||
DZ = new CountryCode(62, "DZ"),
|
||||
EC = new CountryCode(63, "EC"),
|
||||
EE = new CountryCode(64, "EE"),
|
||||
EG = new CountryCode(65, "EG"),
|
||||
EH = new CountryCode(66, "EH"),
|
||||
ER = new CountryCode(67, "ER"),
|
||||
ES = new CountryCode(68, "ES"),
|
||||
ET = new CountryCode(69, "ET"),
|
||||
FI = new CountryCode(70, "FI"),
|
||||
FJ = new CountryCode(71, "FJ"),
|
||||
FK = new CountryCode(72, "FK"),
|
||||
FM = new CountryCode(73, "FM"),
|
||||
FO = new CountryCode(74, "FO"),
|
||||
FR = new CountryCode(75, "FR"),
|
||||
GA = new CountryCode(76, "GA"),
|
||||
GB = new CountryCode(77, "GB"),
|
||||
GD = new CountryCode(78, "GD"),
|
||||
GE = new CountryCode(79, "GE"),
|
||||
GF = new CountryCode(80, "GF"),
|
||||
GG = new CountryCode(81, "GG"),
|
||||
GH = new CountryCode(82, "GH"),
|
||||
GI = new CountryCode(83, "GI"),
|
||||
GL = new CountryCode(84, "GL"),
|
||||
GM = new CountryCode(85, "GM"),
|
||||
GN = new CountryCode(86, "GN"),
|
||||
GP = new CountryCode(87, "GP"),
|
||||
GQ = new CountryCode(88, "GQ"),
|
||||
GR = new CountryCode(89, "GR"),
|
||||
GS = new CountryCode(90, "GS"),
|
||||
GT = new CountryCode(91, "GT"),
|
||||
GU = new CountryCode(92, "GU"),
|
||||
GW = new CountryCode(93, "GW"),
|
||||
GY = new CountryCode(94, "GY"),
|
||||
HK = new CountryCode(95, "HK"),
|
||||
HM = new CountryCode(96, "HM"),
|
||||
HN = new CountryCode(97, "HN"),
|
||||
HR = new CountryCode(98, "HR"),
|
||||
HT = new CountryCode(99, "HT"),
|
||||
HU = new CountryCode(100, "HU"),
|
||||
ID = new CountryCode(101, "ID"),
|
||||
IE = new CountryCode(102, "IE"),
|
||||
IL = new CountryCode(103, "IL"),
|
||||
IM = new CountryCode(104, "IM"),
|
||||
IN = new CountryCode(105, "IN"),
|
||||
IO = new CountryCode(106, "IO"),
|
||||
IQ = new CountryCode(107, "IQ"),
|
||||
IR = new CountryCode(108, "IR"),
|
||||
IS = new CountryCode(109, "IS"),
|
||||
IT = new CountryCode(110, "IT"),
|
||||
JE = new CountryCode(111, "JE"),
|
||||
JM = new CountryCode(112, "JM"),
|
||||
JO = new CountryCode(113, "JO"),
|
||||
JP = new CountryCode(114, "JP"),
|
||||
KE = new CountryCode(115, "KE"),
|
||||
KG = new CountryCode(116, "KG"),
|
||||
KH = new CountryCode(117, "KH"),
|
||||
KI = new CountryCode(118, "KI"),
|
||||
KM = new CountryCode(119, "KM"),
|
||||
KN = new CountryCode(120, "KN"),
|
||||
KP = new CountryCode(121, "KP"),
|
||||
KR = new CountryCode(122, "KR"),
|
||||
KW = new CountryCode(123, "KW"),
|
||||
KY = new CountryCode(124, "KY"),
|
||||
KZ = new CountryCode(125, "KZ"),
|
||||
LA = new CountryCode(126, "LA"),
|
||||
LB = new CountryCode(127, "LB"),
|
||||
LC = new CountryCode(128, "LC"),
|
||||
LI = new CountryCode(129, "LI"),
|
||||
LK = new CountryCode(130, "LK"),
|
||||
LR = new CountryCode(131, "LR"),
|
||||
LS = new CountryCode(132, "LS"),
|
||||
LT = new CountryCode(133, "LT"),
|
||||
LU = new CountryCode(134, "LU"),
|
||||
LV = new CountryCode(135, "LV"),
|
||||
LY = new CountryCode(136, "LY"),
|
||||
MA = new CountryCode(137, "MA"),
|
||||
MC = new CountryCode(138, "MC"),
|
||||
MD = new CountryCode(139, "MD"),
|
||||
ME = new CountryCode(140, "ME"),
|
||||
MF = new CountryCode(141, "MF"),
|
||||
MG = new CountryCode(142, "MG"),
|
||||
MH = new CountryCode(143, "MH"),
|
||||
MK = new CountryCode(144, "MK"),
|
||||
ML = new CountryCode(145, "ML"),
|
||||
MM = new CountryCode(146, "MM"),
|
||||
MN = new CountryCode(147, "MN"),
|
||||
MO = new CountryCode(148, "MO"),
|
||||
MP = new CountryCode(149, "MP"),
|
||||
MQ = new CountryCode(150, "MQ"),
|
||||
MR = new CountryCode(151, "MR"),
|
||||
MS = new CountryCode(152, "MS"),
|
||||
MT = new CountryCode(153, "MT"),
|
||||
MU = new CountryCode(154, "MU"),
|
||||
MV = new CountryCode(155, "MV"),
|
||||
MW = new CountryCode(156, "MW"),
|
||||
MX = new CountryCode(157, "MX"),
|
||||
MY = new CountryCode(158, "MY"),
|
||||
MZ = new CountryCode(159, "MZ"),
|
||||
NA = new CountryCode(160, "NA"),
|
||||
NC = new CountryCode(161, "NC"),
|
||||
NE = new CountryCode(162, "NE"),
|
||||
NF = new CountryCode(163, "NF"),
|
||||
NG = new CountryCode(164, "NG"),
|
||||
NI = new CountryCode(165, "NI"),
|
||||
NL = new CountryCode(166, "NL"),
|
||||
NO = new CountryCode(167, "NO"),
|
||||
NP = new CountryCode(168, "NP"),
|
||||
NR = new CountryCode(169, "NR"),
|
||||
NU = new CountryCode(170, "NU"),
|
||||
NZ = new CountryCode(171, "NZ"),
|
||||
OM = new CountryCode(172, "OM"),
|
||||
PA = new CountryCode(173, "PA"),
|
||||
PE = new CountryCode(174, "PE"),
|
||||
PF = new CountryCode(175, "PF"),
|
||||
PG = new CountryCode(176, "PG"),
|
||||
PH = new CountryCode(177, "PH"),
|
||||
PK = new CountryCode(178, "PK"),
|
||||
PL = new CountryCode(179, "PL"),
|
||||
PM = new CountryCode(180, "PM"),
|
||||
PN = new CountryCode(181, "PN"),
|
||||
PR = new CountryCode(182, "PR"),
|
||||
PS = new CountryCode(183, "PS"),
|
||||
PT = new CountryCode(184, "PT"),
|
||||
PW = new CountryCode(185, "PW"),
|
||||
PY = new CountryCode(186, "PY"),
|
||||
QA = new CountryCode(187, "QA"),
|
||||
RE = new CountryCode(188, "RE"),
|
||||
RO = new CountryCode(189, "RO"),
|
||||
RS = new CountryCode(190, "RS"),
|
||||
RU = new CountryCode(191, "RU"),
|
||||
RW = new CountryCode(192, "RW"),
|
||||
SA = new CountryCode(193, "SA"),
|
||||
SB = new CountryCode(194, "SB"),
|
||||
SC = new CountryCode(195, "SC"),
|
||||
SD = new CountryCode(196, "SD"),
|
||||
SE = new CountryCode(197, "SE"),
|
||||
SG = new CountryCode(198, "SG"),
|
||||
SH = new CountryCode(199, "SH"),
|
||||
SI = new CountryCode(200, "SI"),
|
||||
SJ = new CountryCode(201, "SJ"),
|
||||
SK = new CountryCode(202, "SK"),
|
||||
SL = new CountryCode(203, "SL"),
|
||||
SM = new CountryCode(204, "SM"),
|
||||
SN = new CountryCode(205, "SN"),
|
||||
SO = new CountryCode(206, "SO"),
|
||||
SR = new CountryCode(207, "SR"),
|
||||
SS = new CountryCode(208, "SS"),
|
||||
ST = new CountryCode(209, "ST"),
|
||||
SV = new CountryCode(210, "SV"),
|
||||
SX = new CountryCode(211, "SX"),
|
||||
SY = new CountryCode(212, "SY"),
|
||||
SZ = new CountryCode(213, "SZ"),
|
||||
TC = new CountryCode(214, "TC"),
|
||||
TD = new CountryCode(215, "TD"),
|
||||
TF = new CountryCode(216, "TF"),
|
||||
TG = new CountryCode(217, "TG"),
|
||||
TH = new CountryCode(218, "TH"),
|
||||
TJ = new CountryCode(219, "TJ"),
|
||||
TK = new CountryCode(220, "TK"),
|
||||
TL = new CountryCode(221, "TL"),
|
||||
TM = new CountryCode(222, "TM"),
|
||||
TN = new CountryCode(223, "TN"),
|
||||
TO = new CountryCode(224, "TO"),
|
||||
TR = new CountryCode(225, "TR"),
|
||||
TT = new CountryCode(226, "TT"),
|
||||
TV = new CountryCode(227, "TV"),
|
||||
TW = new CountryCode(228, "TW"),
|
||||
TZ = new CountryCode(229, "TZ"),
|
||||
UA = new CountryCode(230, "UA"),
|
||||
UG = new CountryCode(231, "UG"),
|
||||
UM = new CountryCode(232, "UM"),
|
||||
US = new CountryCode(233, "US"),
|
||||
UY = new CountryCode(234, "UY"),
|
||||
UZ = new CountryCode(235, "UZ"),
|
||||
VA = new CountryCode(236, "VA"),
|
||||
VC = new CountryCode(237, "VC"),
|
||||
VE = new CountryCode(238, "VE"),
|
||||
VG = new CountryCode(239, "VG"),
|
||||
VI = new CountryCode(240, "VI"),
|
||||
VN = new CountryCode(241, "VN"),
|
||||
VU = new CountryCode(242, "VU"),
|
||||
WF = new CountryCode(243, "WF"),
|
||||
WS = new CountryCode(244, "WS"),
|
||||
YE = new CountryCode(245, "YE"),
|
||||
YT = new CountryCode(246, "YT"),
|
||||
ZA = new CountryCode(247, "ZA"),
|
||||
ZM = new CountryCode(248, "ZM"),
|
||||
ZW = new CountryCode(249, "ZW"),
|
||||
|
||||
UNSUPPORTED = new CountryCode(-1, "UNSUPPORTED");
|
||||
|
||||
static {
|
||||
//try to load all the subclasses explicitly - to avoid timing issues when items coming from subclasses may be registered some time later, after the parent class is loaded
|
||||
Set<Class<? extends CountryCode>> subclasses = BaseJsonModel.getReflections().getSubTypesOf(CountryCode.class);
|
||||
for(Class<?> cls: subclasses) {
|
||||
try {
|
||||
Class.forName(cls.getName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.warn("Cannot load class {} : {}", cls.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
usa(0),
|
||||
ca(1),
|
||||
integration(1000),
|
||||
|
||||
UNSUPPORTED(-1);
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
protected CountryCode(int id, String name) {
|
||||
synchronized(lock) {
|
||||
|
||||
LOG.debug("Registering CountryCode by {} : {}", this.getClass().getSimpleName(), name);
|
||||
private static final Map<Integer, CountryCode> ELEMENTS = new HashMap<>();
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
||||
ELEMENTS_BY_NAME.values().forEach(s -> {
|
||||
if(s.getName().equals(name)) {
|
||||
throw new IllegalStateException("CountryCode item for "+ name + " is already defined, cannot have more than one of them");
|
||||
}
|
||||
});
|
||||
|
||||
if(ELEMENTS.containsKey(id)) {
|
||||
throw new IllegalStateException("CountryCode item "+ name + "("+id+") is already defined, cannot have more than one of them");
|
||||
}
|
||||
|
||||
ELEMENTS.put(id, this);
|
||||
ELEMENTS_BY_NAME.put(name, this);
|
||||
}
|
||||
private CountryCode(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static CountryCode getById(int enumId){
|
||||
public static CountryCode getById(int enumId) {
|
||||
if (ELEMENTS.isEmpty()) {
|
||||
synchronized (ELEMENTS) {
|
||||
if (ELEMENTS.isEmpty()) {
|
||||
//initialize elements map
|
||||
for(CountryCode met : CountryCode.values()) {
|
||||
ELEMENTS.put(met.getId(), met);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ELEMENTS.get(enumId);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static CountryCode getByName(String value) {
|
||||
CountryCode ret = ELEMENTS_BY_NAME.get(value);
|
||||
if (ret == null) {
|
||||
ret = UNSUPPORTED;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static List<CountryCode> getValues() {
|
||||
return new ArrayList<>(ELEMENTS.values());
|
||||
return JsonDeserializationUtils.deserializEnum(value, CountryCode.class, UNSUPPORTED);
|
||||
}
|
||||
|
||||
public static boolean isUnsupported(CountryCode value) {
|
||||
return (UNSUPPORTED.equals(value));
|
||||
return UNSUPPORTED.equals(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof CountryCode)) {
|
||||
return false;
|
||||
}
|
||||
CountryCode other = (CountryCode) obj;
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.equipment;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
|
||||
public abstract class AbstractSource<T> extends BaseJsonModel {
|
||||
private static final long serialVersionUID = 2761981826629575941L;
|
||||
protected SourceType source;
|
||||
protected T value;
|
||||
|
||||
public AbstractSource(SourceType source, T manualValue) {
|
||||
this.source = source;
|
||||
this.value = manualValue;
|
||||
}
|
||||
|
||||
protected AbstractSource() {
|
||||
// json construct
|
||||
}
|
||||
|
||||
public SourceType getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(SourceType source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(source, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof AbstractSource)) {
|
||||
return false;
|
||||
}
|
||||
AbstractSource<T> other = (AbstractSource<T>) obj;
|
||||
return this.source == other.source && Objects.equals(value, other.value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
package com.telecominfraproject.wlan.core.model.equipment;
|
||||
|
||||
public enum LedStatus {
|
||||
led_on,
|
||||
led_off,
|
||||
led_blink,
|
||||
UNKNOWN;
|
||||
}
|
||||
@@ -4,11 +4,9 @@ import java.util.Arrays;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.model.serializers.Base64UrlByteArrayDeserializer;
|
||||
import com.telecominfraproject.wlan.core.model.serializers.Base64UrlByteArraySerializer;
|
||||
|
||||
@JsonSerialize()
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@@ -42,12 +40,10 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
(byte) ((valueAsLong >> 8) & 0xff), (byte) (valueAsLong & 0xff) });
|
||||
}
|
||||
|
||||
@JsonDeserialize(using = Base64UrlByteArrayDeserializer.class)
|
||||
public void setAddress(byte[] address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@JsonSerialize(using = Base64UrlByteArraySerializer.class)
|
||||
public byte[] getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
@@ -58,7 +54,7 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
if(address.length >= 6)
|
||||
{
|
||||
long mac = 0;
|
||||
for (var i = 0; i < 6; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
long t = (address[i] & 0xffL) << ((5 - i) * 8);
|
||||
mac |= t;
|
||||
}
|
||||
@@ -73,7 +69,7 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
}
|
||||
|
||||
public String getAddressAsString() {
|
||||
var sb = new StringBuilder(124);
|
||||
StringBuilder sb = new StringBuilder(124);
|
||||
|
||||
if(address != null)
|
||||
{
|
||||
@@ -82,15 +78,14 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
}
|
||||
|
||||
sb.setLength(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public String getAsLowerCaseString() {
|
||||
var sb = new StringBuilder(124);
|
||||
StringBuilder sb = new StringBuilder(124);
|
||||
for (byte single : address) {
|
||||
sb.append(String.format("%02x", single));
|
||||
}
|
||||
@@ -132,8 +127,8 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final var prime = 31;
|
||||
var result = 1;
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + Arrays.hashCode(address);
|
||||
return result;
|
||||
}
|
||||
@@ -164,16 +159,12 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
|
||||
|
||||
private static byte[] stringToByteArray(String str) {
|
||||
if (str == null || str.equals(""))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var ret = new byte[6];
|
||||
byte[] ret = new byte[6];
|
||||
|
||||
String octets[] = str.split(":");
|
||||
if(octets.length == 1 && octets[0].length() == str.length() && str.length()<=12) {
|
||||
// hex string without colon
|
||||
for(var i = 0; i< str.length(); i+=2) {
|
||||
for(int i = 0; i< str.length(); i+=2) {
|
||||
Integer hex = Integer.parseInt(str.substring(i, i==str.length()-1?i+1:i+2), 16);
|
||||
ret[i/2] = hex.byteValue();
|
||||
}
|
||||
@@ -183,7 +174,7 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
}
|
||||
else {
|
||||
try {
|
||||
for (var i = 0; i < octets.length; i++) {
|
||||
for (int i = 0; i < octets.length; i++) {
|
||||
Integer hex = Integer.parseInt(octets[i], 16);
|
||||
ret[i] = hex.byteValue();
|
||||
}
|
||||
@@ -215,8 +206,8 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
else
|
||||
{
|
||||
String[] value = lowercaseValue.split(":");
|
||||
var sb = new StringBuilder(6);
|
||||
for(var i=0; i<3; i++)
|
||||
StringBuilder sb = new StringBuilder(6);
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
sb.append(value[i].toLowerCase());
|
||||
}
|
||||
@@ -226,11 +217,11 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
}
|
||||
|
||||
public String toOuiString() {
|
||||
if(address == null || address.length == 0) {
|
||||
if(address == null) {
|
||||
return null;
|
||||
}
|
||||
var sb = new StringBuilder(6);
|
||||
for (var i = 0; i< 3; i++) {
|
||||
StringBuilder sb = new StringBuilder(6);
|
||||
for (int i = 0; i< 3; i++) {
|
||||
sb.append(String.format("%02x", address[i]));
|
||||
}
|
||||
return sb.toString();
|
||||
@@ -293,17 +284,11 @@ public class MacAddress extends BaseJsonModel implements Comparable<MacAddress>
|
||||
* @return
|
||||
*/
|
||||
public static Long convertMacStringToLongValue(String macStr) {
|
||||
|
||||
if (macStr == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
byte[] bval = stringToByteArray(macStr);
|
||||
|
||||
if (bval != null && bval.length >= 6) {
|
||||
if (bval.length >= 6) {
|
||||
long mac = 0;
|
||||
for (var i = 0; i < 6; i++) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
long t = (bval[i] & 0xffL) << ((5 - i) * 8);
|
||||
mac |= t;
|
||||
}
|
||||
|
||||
@@ -104,8 +104,4 @@ public class RadioBestApSettings extends BaseJsonModel
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RadioBestApSettings clone() {
|
||||
return (RadioBestApSettings) super.clone();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ public enum SecurityType
|
||||
OPEN,
|
||||
RADIUS,
|
||||
PSK,
|
||||
SAE,
|
||||
|
||||
UNSUPPORTED;
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.equipment;
|
||||
|
||||
public class SourceSelectionSteering extends AbstractSource<RadioBestApSettings>{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4631172351117490997L;
|
||||
|
||||
private SourceSelectionSteering() {
|
||||
|
||||
}
|
||||
|
||||
private SourceSelectionSteering(SourceType source, RadioBestApSettings value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionSteering createAutomaticInstance(RadioBestApSettings value) {
|
||||
return new SourceSelectionSteering(SourceType.auto, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionSteering createManualInstance(RadioBestApSettings value) {
|
||||
return new SourceSelectionSteering(SourceType.manual, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionSteering createProfileInstance(RadioBestApSettings value) {
|
||||
return new SourceSelectionSteering(SourceType.profile, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnsupportedValue() {
|
||||
if (SourceType.isUnsupported(source)) {
|
||||
return true;
|
||||
}
|
||||
if ((null != value) && value.hasUnsupportedValue()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceSelectionSteering clone() {
|
||||
SourceSelectionSteering ret = (SourceSelectionSteering) super.clone();
|
||||
|
||||
if(this.value!=null) {
|
||||
ret.value = this.value.clone();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.equipment;
|
||||
|
||||
public class SourceSelectionValue extends AbstractSource<Integer>{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4631172351117490997L;
|
||||
|
||||
private SourceSelectionValue() {
|
||||
|
||||
}
|
||||
|
||||
private SourceSelectionValue(SourceType source, int value) {
|
||||
super(source, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionValue createAutomaticInstance(int value) {
|
||||
return new SourceSelectionValue(SourceType.auto, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionValue createManualInstance(int value) {
|
||||
return new SourceSelectionValue(SourceType.manual, value);
|
||||
}
|
||||
|
||||
public static SourceSelectionValue createProfileInstance(int value) {
|
||||
return new SourceSelectionValue(SourceType.profile, value);
|
||||
}
|
||||
|
||||
public static AutoOrManualValue getAutoOrManualFromSourcedValue(SourceSelectionValue param) {
|
||||
AutoOrManualValue ret = null;
|
||||
if (param.getSource() == SourceType.auto) {
|
||||
ret = AutoOrManualValue.createAutomaticInstance(param.getValue());
|
||||
} else if (param.getSource() == SourceType.profile) {
|
||||
ret = AutoOrManualValue.createManualInstance(param.getValue());
|
||||
} else { // else param.getSource == SourceType.manual
|
||||
ret = AutoOrManualValue.createManualInstance(param.getValue());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnsupportedValue() {
|
||||
if (SourceType.isUnsupported(source)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceSelectionValue clone() {
|
||||
SourceSelectionValue ret = (SourceSelectionValue) super.clone();
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.equipment;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.telecominfraproject.wlan.core.model.json.JsonDeserializationUtils;
|
||||
|
||||
public enum SourceType {
|
||||
|
||||
auto(0L),
|
||||
manual(1L),
|
||||
profile(2L),
|
||||
|
||||
UNSUPPORTED(-1L);
|
||||
|
||||
private final long id;
|
||||
private static final Map<Long, SourceType> ELEMENTS = new HashMap<>();
|
||||
|
||||
private SourceType(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public static SourceType getById(long enumId) {
|
||||
if (ELEMENTS.isEmpty()) {
|
||||
synchronized (ELEMENTS) {
|
||||
if (ELEMENTS.isEmpty()) {
|
||||
//initialize elements map
|
||||
for(SourceType met : SourceType.values()) {
|
||||
ELEMENTS.put(met.getId(), met);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ELEMENTS.get(enumId);
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static SourceType getByName(String value) {
|
||||
return JsonDeserializationUtils.deserializEnum(value, SourceType.class, UNSUPPORTED);
|
||||
}
|
||||
|
||||
public static boolean isUnsupported(SourceType value) {
|
||||
return UNSUPPORTED.equals(value);
|
||||
}
|
||||
}
|
||||
@@ -89,11 +89,6 @@ public abstract class BaseJsonModel implements Cloneable, Serializable {
|
||||
PRETTY_WRITTER = MAPPER.writer().withDefaultPrettyPrinter();
|
||||
}
|
||||
|
||||
|
||||
public static ObjectMapper getMapper() {
|
||||
return MAPPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* For NoSQL databases we do not use synthetic keys, but they are still part of the object model.
|
||||
* This method allows us to calculate a value of synthetic key from two long elements, for example equipmentId and timestamp.
|
||||
@@ -409,48 +404,7 @@ public abstract class BaseJsonModel implements Cloneable, Serializable {
|
||||
return listFromString(jsonPayload, clazz);
|
||||
}
|
||||
|
||||
public static void main_1(String[] args) {
|
||||
String plainStr = "{\"model_type\":\"CustomerDetails\",\"autoProvisioning\":{\"model_type\":\"EquipmentAutoProvisioningSettings\",\"enabled\":true,\"locationId\":8,\"equipmentProfileIdPerModel\":{\"TIP_AP\":5,\"ECW5410\":6,\"ECW5211\":6,\"AP2220\":6,\"EA8300-CA\":5,\"EA8300\":5,\"default\":5}},\"bannedChannels\":[]}";
|
||||
String encZipStr = "504b03041400080808006b513c5200000000000000000000000001000000615d4f3d0bc23010fd2f375768ab15c9166a870e4240c141445273d5409ad4f62288f4bf9b561d74ba77efde07f784c62934277ab4080c72df936bb05b23496d7a88407a72a27377dd6b67b5bd007bfe5a8a9bd76d8396f89f728b44618c216865655001a3ce6304c69d250551199855b87e1382bbd6064b25b0db8c1d63d9ae14272e80651114f93e5b2431b0e51ba74932612ed234fdd07c358fe359cedf86699ba0c25a7a43010f430495b416557e1d4778931d8ec30b504b0708be151e61b70000000a010000504b010214001400080808006b513c52be151e61b70000000a01000001000000000000000000000000000000000061504b050600000000010001002f000000e60000000000";
|
||||
|
||||
decodePostgresGzipBytea(encZipStr);
|
||||
encodePostgresGzipBytea(plainStr);
|
||||
|
||||
}
|
||||
|
||||
public static void encodePostgresGzipBytea(String plainStr) {
|
||||
|
||||
byte[] bytes = BaseJsonModel.toZippedBytesFromString(plainStr);
|
||||
|
||||
StringBuilder encZipStr = new StringBuilder(bytes.length * 2);
|
||||
|
||||
String oneByteStr;
|
||||
int unsignedByte;
|
||||
for(int i = 0; i<bytes.length; i++) {
|
||||
unsignedByte = 0x00ff & bytes[i];
|
||||
oneByteStr = Integer.toHexString(unsignedByte);
|
||||
if(oneByteStr.length()<2) {
|
||||
oneByteStr = "0" + oneByteStr;
|
||||
}
|
||||
encZipStr.append( oneByteStr );
|
||||
}
|
||||
|
||||
System.out.println(encZipStr.toString());
|
||||
}
|
||||
|
||||
|
||||
public static void decodePostgresGzipBytea(String encZipStr) {
|
||||
|
||||
byte[] bytes = new byte[encZipStr.length()/2];
|
||||
|
||||
for(int i = 0; i+2<encZipStr.length(); i+=2) {
|
||||
bytes[i/2] = (byte) Integer.parseUnsignedInt(encZipStr, i, i+2, 16);
|
||||
}
|
||||
|
||||
System.out.println(BaseJsonModel.fromZippedBytesAsString(bytes));
|
||||
}
|
||||
|
||||
public static void main_syntheticKey(String[] args) {
|
||||
public static void main(String[] args) {
|
||||
long one = 1;
|
||||
long maxEncodable = 0x3FFFFFL;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.json.interfaces;
|
||||
|
||||
/**
|
||||
* Marker interface that tells if current object can provide locationId for which it belongs to
|
||||
* @author dtop
|
||||
*
|
||||
*/
|
||||
public interface HasLocationId {
|
||||
|
||||
/**
|
||||
* @return locationId for which this object belongs to
|
||||
*/
|
||||
long getLocationId();
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.json.interfaces;
|
||||
/**
|
||||
* Marker interface that tells if current object can provide a timestamp from its source data (i.e. timestamp for stats report used to generate a ServiceMetric)
|
||||
* @author mikehansen1970
|
||||
*
|
||||
*/
|
||||
public interface HasSourceTimestamp {
|
||||
|
||||
/**
|
||||
* @return the timestamp of the source data for this object (i.e. for the stats that were used for a ServiceMetric)
|
||||
*/
|
||||
public long getSourceTimestampMs();
|
||||
}
|
||||
@@ -3,152 +3,85 @@
|
||||
*/
|
||||
package com.telecominfraproject.wlan.core.model.role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.telecominfraproject.wlan.core.model.extensibleenum.EnumWithId;
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.model.json.JsonDeserializationUtils;
|
||||
|
||||
/**
|
||||
* All available roles for the portal users that can be handled by the CloudSDK.
|
||||
* <br>This enumeration-like class can be extended by vendors - new elements can be defined by extending this class like so:
|
||||
* <br>
|
||||
* <pre>
|
||||
* public class VendorExtendedPortalUserRole extends PortalUserRole {
|
||||
*
|
||||
* public static final PortalUserRole
|
||||
* VENDOR_USER_ROLE_A = new VendorExtendedPortalUserRole(100, "VENDOR_USER_ROLE_A", 5) ,
|
||||
* VENDOR_USER_ROLE_B = new VendorExtendedPortalUserRole(101, "VENDOR_USER_ROLE_B", 5)
|
||||
* ;
|
||||
*
|
||||
* private VendorExtendedPortalUserRole(int id, String name, int permissionLevel) {
|
||||
* super(id, name, permissionLevel);
|
||||
* }
|
||||
*
|
||||
* }
|
||||
* </pre>
|
||||
* @see com.telecominfraproject.wlan.core.model.extensibleenum.EnumWithId
|
||||
* @see com.telecominfraproject.wlan.core.model.role.vendorextensions.VendorExtendedPortalUserRole
|
||||
* <br>
|
||||
* @author dtop
|
||||
* @author ekeddy
|
||||
*
|
||||
* Defines the various user roles and permissions. Highest permission
|
||||
* level has greatest permission.
|
||||
*/
|
||||
public class PortalUserRole implements EnumWithId {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PortalUserRole.class);
|
||||
|
||||
private static Object lock = new Object();
|
||||
private static final Map<Integer, PortalUserRole> ELEMENTS = new ConcurrentHashMap<>();
|
||||
private static final Map<String, PortalUserRole> ELEMENTS_BY_NAME = new ConcurrentHashMap<>();
|
||||
|
||||
public static final PortalUserRole
|
||||
|
||||
public enum PortalUserRole {
|
||||
/**
|
||||
* Public user - Read Only
|
||||
* Public user
|
||||
*/
|
||||
Public = new PortalUserRole(0, "Public", 0),
|
||||
Public(0, 0),
|
||||
/**
|
||||
* Customer - Read Write
|
||||
* Customer
|
||||
*/
|
||||
CustomerIT = new PortalUserRole(1, "CustomerIT", 10),
|
||||
CustomerIT(1, 10),
|
||||
/**
|
||||
* MSP - Read Write
|
||||
* MSP
|
||||
*/
|
||||
ManagedServiceProvider = new PortalUserRole(2, "ManagedServiceProvider", 20),
|
||||
ManagedServiceProvider(2, 20),
|
||||
/**
|
||||
* Service Distributor - Read Write
|
||||
* Service Distributor
|
||||
*/
|
||||
Distributor = new PortalUserRole(3, "Distributor", 30),
|
||||
Distributor(3, 30),
|
||||
/**
|
||||
* Technical Support - Read Write
|
||||
* Technical Support
|
||||
*/
|
||||
TechSupport = new PortalUserRole(4, "TechSupport", 40),
|
||||
TechSupport(4, 40),
|
||||
/**
|
||||
* Super User - Read Write
|
||||
* Super User
|
||||
*/
|
||||
SuperUser = new PortalUserRole(Integer.MAX_VALUE, "SuperUser", Integer.MAX_VALUE),
|
||||
/**
|
||||
* Customer - Read Only
|
||||
*/
|
||||
CustomerIT_RO = new PortalUserRole(5, "CustomerIT_RO", 5),
|
||||
/**
|
||||
* MSP - Read Only
|
||||
*/
|
||||
ManagedServiceProvider_RO = new PortalUserRole(6, "ManagedServiceProvider_RO", 15),
|
||||
/**
|
||||
* Service Distributor - Read Only
|
||||
*/
|
||||
Distributor_RO = new PortalUserRole(7, "Distributor_RO", 25),
|
||||
/**
|
||||
* Technical Support - Read Only
|
||||
*/
|
||||
TechSupport_RO = new PortalUserRole(8, "TechSupport_RO", 35),
|
||||
/**
|
||||
* Super User - Read Only
|
||||
*/
|
||||
SuperUser_RO = new PortalUserRole(Integer.MAX_VALUE - 1, "SuperUser_RO", Integer.MAX_VALUE - 5),
|
||||
SuperUser(Integer.MAX_VALUE, Integer.MAX_VALUE),
|
||||
/**
|
||||
* Unknown
|
||||
*/
|
||||
Unknown = new PortalUserRole(-1, "Unknown", -1);
|
||||
Unknown(-1, -1);
|
||||
|
||||
private final static Map<Integer, PortalUserRole> ID_MAP;
|
||||
static {
|
||||
//try to load all the subclasses explicitly - to avoid timing issues when items coming from subclasses may be registered some time later, after the parent class is loaded
|
||||
Set<Class<? extends PortalUserRole>> subclasses = BaseJsonModel.getReflections().getSubTypesOf(PortalUserRole.class);
|
||||
for(Class<?> cls: subclasses) {
|
||||
try {
|
||||
Class.forName(cls.getName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
LOG.warn("Cannot load class {} : {}", cls.getName(), e);
|
||||
ID_MAP = new HashMap<>();
|
||||
for (PortalUserRole r : PortalUserRole.values()) {
|
||||
if (PortalUserRole.isUnsupported(r)) {
|
||||
continue;
|
||||
}
|
||||
ID_MAP.put(r.getId(), r);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final String SYSTEM_IDENTIFIER = "System";
|
||||
|
||||
public static PortalUserRole getById(int id) {
|
||||
PortalUserRole result = ID_MAP.get(id);
|
||||
if (result == null) {
|
||||
return PortalUserRole.Unknown;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PortalUserRole getByName(String value) {
|
||||
return JsonDeserializationUtils.deserializEnum(value, PortalUserRole.class, Unknown);
|
||||
}
|
||||
|
||||
public static boolean isUnsupported(PortalUserRole userRole) {
|
||||
return Unknown.equals(userRole);
|
||||
}
|
||||
|
||||
private final int permissionLevel;
|
||||
private final SimpleGrantedAuthority authority;
|
||||
|
||||
private final int id;
|
||||
private final String name;
|
||||
|
||||
|
||||
protected PortalUserRole(int id, String name, int permissionLevel) {
|
||||
synchronized(lock) {
|
||||
|
||||
LOG.debug("Registering PortalUserRole by {} : {}", this.getClass().getSimpleName(), name);
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.permissionLevel = permissionLevel;
|
||||
this.authority = new SimpleGrantedAuthority(name);
|
||||
|
||||
ELEMENTS_BY_NAME.values().forEach(s -> {
|
||||
if(s.getName().equals(name)) {
|
||||
throw new IllegalStateException("PortalUserRole item for "+ name + " is already defined, cannot have more than one of them");
|
||||
}
|
||||
});
|
||||
|
||||
if(ELEMENTS.containsKey(id)) {
|
||||
throw new IllegalStateException("PortalUserRole item "+ name + "("+id+") is already defined, cannot have more than one of them");
|
||||
}
|
||||
|
||||
ELEMENTS.put(id, this);
|
||||
ELEMENTS_BY_NAME.put(name, this);
|
||||
}
|
||||
private PortalUserRole(int id, int permissionLevel) {
|
||||
this.id = id;
|
||||
this.permissionLevel = permissionLevel;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
@@ -158,76 +91,4 @@ public class PortalUserRole implements EnumWithId {
|
||||
public int getPermissionLevel() {
|
||||
return this.permissionLevel;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public SimpleGrantedAuthority getAuthority() {
|
||||
return authority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof PortalUserRole)) {
|
||||
return false;
|
||||
}
|
||||
PortalUserRole other = (PortalUserRole) obj;
|
||||
return id == other.id;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public static PortalUserRole[] values() {
|
||||
return new ArrayList<>(ELEMENTS.values()).toArray(new PortalUserRole[0]);
|
||||
}
|
||||
|
||||
public static PortalUserRole getById(int enumId){
|
||||
|
||||
PortalUserRole result = ELEMENTS.get(enumId);
|
||||
if (result == null) {
|
||||
return Unknown;
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public static PortalUserRole getByName(String value) {
|
||||
PortalUserRole ret = ELEMENTS_BY_NAME.get(value);
|
||||
if (ret == null) {
|
||||
ret = Unknown;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public static List<PortalUserRole> getValues() {
|
||||
return new ArrayList<>(ELEMENTS.values());
|
||||
}
|
||||
|
||||
public static List<SimpleGrantedAuthority> getAllAuthorities() {
|
||||
List<SimpleGrantedAuthority> authorities = new ArrayList<>();
|
||||
ELEMENTS.values().forEach(y -> authorities.add(y.getAuthority()));
|
||||
|
||||
return authorities;
|
||||
}
|
||||
|
||||
public static boolean isUnsupported(PortalUserRole value) {
|
||||
return (Unknown.equals(value));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.Base64Variants;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
/**
|
||||
* Characters plus and slash, that would need quoting in URLs, are replaced with hyphen and underscore, respectively.
|
||||
* @see com.fasterxml.jackson.core.Base64Variants.MODIFIED_FOR_URL
|
||||
*/
|
||||
public class Base64UrlByteArrayDeserializer extends JsonDeserializer<byte[]> {
|
||||
|
||||
@Override
|
||||
public byte[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
|
||||
JsonToken token = p.currentToken();
|
||||
|
||||
// we only support base64 encoded String
|
||||
if (token == JsonToken.VALUE_STRING) {
|
||||
try {
|
||||
String text = p.getText();
|
||||
return Base64Variants.MODIFIED_FOR_URL.decode(text.replace(' ', '-').replace('+', '-').replace('/', '_').replace("=", ""));
|
||||
} catch (JsonParseException e) {
|
||||
String msg = e.getOriginalMessage();
|
||||
if (msg.contains("base64")) {
|
||||
return (byte[]) ctxt.handleWeirdStringValue(byte[].class,
|
||||
p.getText().replace(' ', '+'), msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonParseException(p, "Cannot convert to byte[]");
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.serializers;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.fasterxml.jackson.core.Base64Variants;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
/**
|
||||
* Characters plus and slash, that would need quoting in URLs, are replaced with hyphen and underscore, respectively.
|
||||
* @see com.fasterxml.jackson.core.Base64Variants.MODIFIED_FOR_URL
|
||||
*/
|
||||
public class Base64UrlByteArraySerializer extends JsonSerializer<byte[]> {
|
||||
|
||||
@Override
|
||||
public void serialize(byte[] value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
gen.writeString(Base64Variants.MODIFIED_FOR_URL.encode(value));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
package com.telecominfraproject.wlan.core.model.utils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.math3.stat.descriptive.rank.Percentile;
|
||||
|
||||
|
||||
@@ -22,30 +19,6 @@ public class DecibelUtils
|
||||
return avgDbVal10;
|
||||
}
|
||||
|
||||
public static double getAverageDecibel(Collection<Integer> decibels)
|
||||
{
|
||||
if (decibels == null || decibels.isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double aggregation = 0;
|
||||
int count=0;
|
||||
Iterator<Integer> iter = decibels.iterator();
|
||||
|
||||
while(iter.hasNext()) {
|
||||
Integer value = iter.next();
|
||||
if(value!=null) {
|
||||
aggregation += Math.pow(10, value/10.0);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return 0.0;
|
||||
}else {
|
||||
return 10 * Math.log10(aggregation/count);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDecibelStandardDeviation(int[] decibels)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,6 @@ public class WebTokenRequest extends BaseJsonModel {
|
||||
private String grantType;
|
||||
private String userId;
|
||||
private String password;
|
||||
private String refreshToken;
|
||||
private String scope;
|
||||
|
||||
public String getGrantType() {
|
||||
@@ -40,11 +39,5 @@ public class WebTokenRequest extends BaseJsonModel {
|
||||
public void setScope(String scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
public void setRefreshToken(String refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ public class WebTokenResult extends BaseJsonModel {
|
||||
private boolean resetPassword;
|
||||
private String access_token;
|
||||
private String refresh_token;
|
||||
private String id_token;
|
||||
private String token_type;
|
||||
private int expires_in;
|
||||
private int idle_timeout;
|
||||
@@ -44,12 +43,6 @@ public class WebTokenResult extends BaseJsonModel {
|
||||
public void setRefresh_token(String refresh_token) {
|
||||
this.refresh_token = refresh_token;
|
||||
}
|
||||
public String getId_token() {
|
||||
return id_token;
|
||||
}
|
||||
public void setId_token(String id_token) {
|
||||
this.id_token = id_token;
|
||||
}
|
||||
public String getToken_type() {
|
||||
return token_type;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.HashMap;
|
||||
@@ -16,6 +14,8 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.equipment.MacAddress;
|
||||
|
||||
public class MacAddressTest {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MacAddressTest.class);
|
||||
|
||||
@@ -145,97 +145,5 @@ public class MacAddressTest {
|
||||
assertEquals(first, equalToFirst);
|
||||
assertNotEquals(first, notEqualToFirst);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAddress() {
|
||||
MacAddress nullCheck = new MacAddress();
|
||||
nullCheck.setAddress(null);
|
||||
assertNull(nullCheck.getAddress());
|
||||
|
||||
MacAddress realValue = new MacAddress();
|
||||
realValue.setAddress(new byte[] { 1, 2, 3, 4, 5, 6 });
|
||||
assertNotNull(realValue.getAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAddressAsLong()
|
||||
{
|
||||
MacAddress macAddress = new MacAddress("00:2a:f7:7a:1e:a0");
|
||||
assertNotNull(macAddress.getAddressAsLong());
|
||||
|
||||
MacAddress otherMacAddress = new MacAddress(new byte[] { 1, 2, 3, 4, 5});
|
||||
assertNull(otherMacAddress.getAddressAsLong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAddressAsString() {
|
||||
MacAddress macAddress = new MacAddress("00:2a:f7:7a:1e:a0");
|
||||
assertNotNull(macAddress.getAddressAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsLowerCaseString() {
|
||||
MacAddress macAddress = new MacAddress("00:2a:f7:7a:1e:a0");
|
||||
assertNotNull(macAddress.getAsLowerCaseString().toCharArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode()
|
||||
{
|
||||
MacAddress macAddress = new MacAddress("00:2a:f7:7a:1e:a0");
|
||||
|
||||
assertNotEquals(macAddress.hashCode(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringToByteArray()
|
||||
{
|
||||
MacAddress macAddress = new MacAddress();
|
||||
macAddress.setAddressAsString(null);
|
||||
assertNull(macAddress.getAddress());
|
||||
|
||||
macAddress.setAddressAsString("00:2a:f7:7a:1e:a0");
|
||||
assertNotNull(macAddress.getAddress());
|
||||
|
||||
try {
|
||||
macAddress.setAddressAsString("00:2a:f7:7a:1e:a0:b0:f1");
|
||||
fail("expected exception.");
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
//expected it
|
||||
}
|
||||
try {
|
||||
macAddress.setAddressAsString("00:2a:f7:7a:1esdafsat:a0");
|
||||
fail("expected exception.");
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
//expected it
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOuiFromLowerCaseString()
|
||||
{
|
||||
assertNotNull(MacAddress.ouiFromLowerCaseString("00:2a:f7:7a:1e:a0", true));
|
||||
assertNotNull(MacAddress.ouiFromLowerCaseString("00:2a:f7:7a:1e:a0", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToOuiString()
|
||||
{
|
||||
MacAddress macAddress = new MacAddress("00:2a:f7:7a:1e:a0");
|
||||
assertNotNull(macAddress.toOuiString());
|
||||
|
||||
MacAddress nullCheck = new MacAddress();
|
||||
nullCheck.setAddressAsString(null);
|
||||
assertNull(nullCheck.toOuiString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertMacStringToLongValue()
|
||||
{
|
||||
assertNotNull(MacAddress.convertMacStringToLongValue("00:2a:f7:7a:1e:a0"));
|
||||
assertNull(MacAddress.convertMacStringToLongValue(null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,4 +32,24 @@ public class VendorExtendedEquipmentTypeModel extends BaseJsonModel{
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
VendorExtendedEquipmentTypeModel t1 = new VendorExtendedEquipmentTypeModel("t1", EquipmentType.AP);
|
||||
VendorExtendedEquipmentTypeModel t2 = new VendorExtendedEquipmentTypeModel("t2", VendorExtendedEquipmentType.AP);
|
||||
VendorExtendedEquipmentTypeModel t3 = new VendorExtendedEquipmentTypeModel("t3", VendorExtendedEquipmentType.VENDOR_EQ_B);
|
||||
|
||||
System.out.println("t1 = "+ t1);
|
||||
System.out.println("t2 = "+ t2);
|
||||
System.out.println("t3 = "+ t3);
|
||||
|
||||
VendorExtendedEquipmentTypeModel t1d = BaseJsonModel.fromString(t1.toString(), VendorExtendedEquipmentTypeModel.class);
|
||||
VendorExtendedEquipmentTypeModel t2d = BaseJsonModel.fromString(t2.toString(), VendorExtendedEquipmentTypeModel.class);
|
||||
VendorExtendedEquipmentTypeModel t3d = BaseJsonModel.fromString(t3.toString(), VendorExtendedEquipmentTypeModel.class);
|
||||
|
||||
System.out.println("=======================");
|
||||
|
||||
System.out.println("t1d = "+ t1d);
|
||||
System.out.println("t2d = "+ t2d);
|
||||
System.out.println("t3d = "+ t3d);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.role.vendorextensions;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
|
||||
public class TestVendorExtentions {
|
||||
|
||||
@Test
|
||||
public void testExtendedEnum() {
|
||||
VendorExtendedPortalUserRoleModel t1 = new VendorExtendedPortalUserRoleModel("t1", PortalUserRole.CustomerIT);
|
||||
VendorExtendedPortalUserRoleModel t2 = new VendorExtendedPortalUserRoleModel("t2", VendorExtendedPortalUserRole.CustomerIT);
|
||||
VendorExtendedPortalUserRoleModel t3 = new VendorExtendedPortalUserRoleModel("t3", VendorExtendedPortalUserRole.VENDOR_USER_ROLE_B);
|
||||
|
||||
VendorExtendedPortalUserRoleModel t1d = BaseJsonModel.fromString(t1.toString(), VendorExtendedPortalUserRoleModel.class);
|
||||
VendorExtendedPortalUserRoleModel t2d = BaseJsonModel.fromString(t2.toString(), VendorExtendedPortalUserRoleModel.class);
|
||||
VendorExtendedPortalUserRoleModel t3d = BaseJsonModel.fromString(t3.toString(), VendorExtendedPortalUserRoleModel.class);
|
||||
|
||||
assertEquals(t1.toString(), t1d.toString());
|
||||
assertEquals(t2.toString(), t2d.toString());
|
||||
assertEquals(t3.toString(), t3d.toString());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.role.vendorextensions;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
|
||||
public class VendorExtendedPortalUserRole extends PortalUserRole {
|
||||
|
||||
public static final PortalUserRole
|
||||
VENDOR_USER_ROLE_A = new VendorExtendedPortalUserRole(100, "VENDOR_USER_ROLE_A", 5) ,
|
||||
VENDOR_USER_ROLE_B = new VendorExtendedPortalUserRole(101, "VENDOR_USER_ROLE_B", 5)
|
||||
;
|
||||
|
||||
private VendorExtendedPortalUserRole(int id, String name, int permissionLevel) {
|
||||
super(id, name, permissionLevel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.model.role.vendorextensions;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.equipment.EquipmentType;
|
||||
import com.telecominfraproject.wlan.core.model.json.BaseJsonModel;
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
|
||||
public class VendorExtendedPortalUserRoleModel extends BaseJsonModel{
|
||||
|
||||
private static final long serialVersionUID = -7571240065645860754L;
|
||||
|
||||
private String name;
|
||||
private PortalUserRole role;
|
||||
|
||||
protected VendorExtendedPortalUserRoleModel() {
|
||||
//for deserializer
|
||||
}
|
||||
|
||||
public VendorExtendedPortalUserRoleModel(String name, PortalUserRole role) {
|
||||
this.name = name;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public PortalUserRole getRole() {
|
||||
return role;
|
||||
}
|
||||
public void setRole(PortalUserRole role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-partitioner</artifactId>
|
||||
@@ -13,7 +13,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-hazelcast-client</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-remote-tests</artifactId>
|
||||
@@ -12,11 +13,9 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-tx-tests</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.telecominfraproject.wlan.remote.tests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@@ -29,10 +28,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.SimpleTransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import com.telecominfraproject.wlan.core.server.tx.test.TxTestConfig;
|
||||
import com.telecominfraproject.wlan.server.RemoteTestServer;
|
||||
|
||||
/**
|
||||
@@ -76,7 +72,6 @@ import com.telecominfraproject.wlan.server.RemoteTestServer;
|
||||
"tip.wlan.csrf-enabled=false" })
|
||||
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
|
||||
@Import(value = {
|
||||
TxTestConfig.class
|
||||
})
|
||||
public abstract class BaseRemoteTest {
|
||||
|
||||
@@ -132,6 +127,37 @@ public abstract class BaseRemoteTest {
|
||||
// @PropertySource({ "classpath:persistence-${envTarget:dev}.properties" })
|
||||
public static class Config {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
PlatformTransactionManager ptm = new PlatformTransactionManager() {
|
||||
|
||||
{
|
||||
LOG.info("*** Using simulated PlatformTransactionManager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(TransactionStatus status) throws TransactionException {
|
||||
LOG.info("Simulating Rollback for {}", status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(TransactionStatus status) throws TransactionException {
|
||||
LOG.info("Simulating Commit for {}", status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
|
||||
LOG.info("Simulating getTransaction for {}", definition);
|
||||
TransactionStatus ts = new SimpleTransactionStatus();
|
||||
return ts;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return ptm;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected int getNextCustomerId() {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-scheduler</artifactId>
|
||||
@@ -14,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-stream-consumer</artifactId>
|
||||
@@ -14,15 +14,8 @@
|
||||
<dependency>
|
||||
<artifactId>base-models</artifactId>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -9,12 +9,6 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.netflix.servo.DefaultMonitorRegistry;
|
||||
import com.netflix.servo.monitor.BasicCounter;
|
||||
import com.netflix.servo.monitor.Counter;
|
||||
import com.netflix.servo.monitor.MonitorConfig;
|
||||
import com.netflix.servo.tag.TagList;
|
||||
import com.telecominfraproject.wlan.cloudmetrics.CloudMetricsTags;
|
||||
import com.telecominfraproject.wlan.core.model.streams.QueuedStreamMessage;
|
||||
|
||||
/**
|
||||
@@ -27,21 +21,10 @@ public class StreamMessageDispatcher {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(StreamMessageDispatcher.class);
|
||||
|
||||
private final TagList tags = CloudMetricsTags.commonTags;
|
||||
|
||||
final Counter messagesProcessed = new BasicCounter(MonitorConfig.builder("stream-processors-messagesProcessed").withTags(tags).build());
|
||||
|
||||
//autowire all available stream processors
|
||||
@Autowired(required = false)
|
||||
List<StreamProcessor> streamProcessors;
|
||||
|
||||
// dtop: use anonymous constructor to ensure that the following code always
|
||||
// get executed,
|
||||
// even when somebody adds another constructor in here
|
||||
{
|
||||
DefaultMonitorRegistry.getInstance().register(messagesProcessed);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void postConstruct() {
|
||||
if(streamProcessors!=null && !streamProcessors.isEmpty()) {
|
||||
@@ -63,7 +46,7 @@ public class StreamMessageDispatcher {
|
||||
}
|
||||
|
||||
LOG.trace("Pushing message to stream processors {}", message);
|
||||
messagesProcessed.increment();
|
||||
|
||||
streamProcessors.forEach(sp -> sp.push(message));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-stream-interface</artifactId>
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>base-tx-tests</artifactId>
|
||||
<name>base-tx-tests</name>
|
||||
<description>Common classes used by the unit tests that require transaction support.</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.telecominfraproject.wlan.core.server.tx.test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.SimpleTransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
/**
|
||||
* @author dtop
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
public class TxTestConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TxTestConfig.class);
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
public PlatformTransactionManager transactionManager() {
|
||||
PlatformTransactionManager ptm = new PlatformTransactionManager() {
|
||||
private ThreadLocal<List<TransactionStatus>> currentTx = new ThreadLocal<>() ;
|
||||
|
||||
{
|
||||
LOG.info("*** Using simulated PlatformTransactionManager");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rollback(TransactionStatus status) throws TransactionException {
|
||||
LOG.debug("Simulating Rollback for {}", status);
|
||||
if(currentTx.get().size() == 1 ) {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
currentTx.remove();
|
||||
} else {
|
||||
currentTx.get().remove(currentTx.get().size() - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(TransactionStatus status) throws TransactionException {
|
||||
LOG.debug("Simulating Commit for {}", status);
|
||||
if(currentTx.get().size() == 1 ) {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager
|
||||
.getSynchronizations();
|
||||
if (synchronizations != null) {
|
||||
for (TransactionSynchronization synchronization : synchronizations) {
|
||||
synchronization.afterCommit();
|
||||
}
|
||||
}
|
||||
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
|
||||
currentTx.remove();
|
||||
} else {
|
||||
currentTx.get().remove(currentTx.get().size() - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException {
|
||||
LOG.debug("Simulating getTransaction for {}", definition);
|
||||
if (!TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.initSynchronization();
|
||||
}
|
||||
|
||||
if (currentTx.get() == null) {
|
||||
List<TransactionStatus> txList = new ArrayList<>();
|
||||
TransactionStatus ts = new SimpleTransactionStatus(true);
|
||||
txList.add(ts);
|
||||
currentTx.set(txList);
|
||||
return ts;
|
||||
} else {
|
||||
List<TransactionStatus> txList = currentTx.get();
|
||||
TransactionStatus ts = new SimpleTransactionStatus(false);
|
||||
txList.add(ts);
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
return ptm;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>cloud-metrics</artifactId>
|
||||
@@ -13,18 +14,18 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-exceptions</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-elasticsearch</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -26,19 +26,11 @@ public class CloudMetricsTags {
|
||||
public static final String localIpV4 = getPropertyAsString("container.localipv4", UNDEFINED_STR);
|
||||
|
||||
|
||||
public static final TagList commonTags;
|
||||
|
||||
static {
|
||||
if(Boolean.parseBoolean(getPropertyAsString("tip.wlan.cloudMetricTags.enabled", "false"))) {
|
||||
commonTags = new BasicTagList(Arrays.asList(
|
||||
new BasicTag("InstanceId", instanceId),
|
||||
new BasicTag("local-ipv4", localIpV4),
|
||||
new BasicTag("cloudTag", buildCloudTag())
|
||||
));
|
||||
} else {
|
||||
commonTags = BasicTagList.EMPTY;
|
||||
}
|
||||
}
|
||||
public static final TagList commonTags = new BasicTagList(Arrays.asList(
|
||||
new BasicTag("InstanceId", instanceId),
|
||||
new BasicTag("local-ipv4", localIpV4),
|
||||
new BasicTag("cloudTag", buildCloudTag())
|
||||
));
|
||||
|
||||
private static String buildCloudTag(){
|
||||
return role + "-" + stack + "-" + deployment;
|
||||
|
||||
@@ -242,12 +242,11 @@ public class StartServoMetricsCollector implements CommandLineRunner {
|
||||
MetricObserver transformElasticSearch = new CounterToRateMetricTransform(
|
||||
elasticSearchObserver, aggregationHeartbeatMultiplier * samplingIntervalMs, TimeUnit.MILLISECONDS);
|
||||
observers.add(transformElasticSearch);
|
||||
LOG.info("ElasticSearch metrics collection is ON");
|
||||
}catch(UnknownHostException e){
|
||||
LOG.error("Cannot initialize ElasticSearch client", e);
|
||||
}
|
||||
} else {
|
||||
LOG.debug("ElasticSearch metrics collection is OFF");
|
||||
LOG.info("ElasticSearch metrics collection is OFF");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>common-hazelcast</artifactId>
|
||||
@@ -19,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-models</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>reflections-tip</artifactId>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>tip-wlan-cloud-root-pom</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../wlan-cloud-root</relativePath>
|
||||
</parent>
|
||||
<artifactId>webtoken-auth-service</artifactId>
|
||||
@@ -14,13 +16,13 @@
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-container</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.telecominfraproject.wlan</groupId>
|
||||
<artifactId>base-client</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>${tip-wlan-cloud.release.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -8,10 +8,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import com.telecominfraproject.wlan.core.model.role.PortalUserRole;
|
||||
import com.telecominfraproject.wlan.core.model.webtoken.IntrospectWebTokenResult;
|
||||
import com.telecominfraproject.wlan.core.server.security.AccessType;
|
||||
import com.telecominfraproject.wlan.core.server.security.AuthProviderInfo;
|
||||
import com.telecominfraproject.wlan.core.server.security.WebSecurityConfig;
|
||||
|
||||
/**
|
||||
* Implementation of UserDetails in compliance with the decoded object returned
|
||||
@@ -42,7 +42,7 @@ public class WebtokenUserDetails implements UserDetails, AuthProviderInfo {
|
||||
|
||||
// set authorities
|
||||
authorities = new ArrayList<>();
|
||||
authorities.add(PortalUserRole.TechSupport.getAuthority());
|
||||
authorities.add(WebSecurityConfig.TECH_SUPPORT_AUTHORITY);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user