Skip to content

Commit

Permalink
add-checkstyle-streampipes-service (#845)
Browse files Browse the repository at this point in the history
* add checkstyle to streampipes-service-base

* add checkstyle to streampipes-service-discovery

* add checkstyle to streampipes-service-discovery-api

* add checkstyle to streampipes-service-discovery-consul

* add checkstyle to streampipes-service-extension-base
  • Loading branch information
bossenti authored Dec 4, 2022
1 parent a0080b9 commit 19d4f6c
Show file tree
Hide file tree
Showing 29 changed files with 587 additions and 450 deletions.
24 changes: 23 additions & 1 deletion streampipes-service-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>streampipes-parent</artifactId>
<groupId>org.apache.streampipes</groupId>
Expand Down Expand Up @@ -113,4 +114,25 @@
<artifactId>hibernate-validator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public class BaseNetworkingConfig {
private final String host;
private final Integer port;

public BaseNetworkingConfig(String host,
Integer port) {
this.host = host;
this.port = port;
}

public static BaseNetworkingConfig defaultResolution(Integer defaultPort) throws UnknownHostException {
String host = Networking.getHostname();
Integer port = Networking.getPort(defaultPort);

return new BaseNetworkingConfig(host, port);
}

public BaseNetworkingConfig(String host,
Integer port) {
this.host = host;
this.port = port;
}

public String getHost() {
return host;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
package org.apache.streampipes.service.base;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.streampipes.svcdiscovery.SpServiceDiscovery;
import org.apache.streampipes.svcdiscovery.api.model.SpServiceRegistrationRequest;
import org.apache.streampipes.svcdiscovery.api.model.SpServiceTag;

import org.apache.commons.lang3.RandomStringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
Expand All @@ -31,9 +32,8 @@

public abstract class StreamPipesServiceBase {

private static final Logger LOG = LoggerFactory.getLogger(StreamPipesServiceBase.class);

public static final String AUTO_GENERATED_SERVICE_ID = RandomStringUtils.randomAlphanumeric(6);
private static final Logger LOG = LoggerFactory.getLogger(StreamPipesServiceBase.class);

protected void startStreamPipesService(Class<?> serviceClass,
String serviceGroup,
Expand All @@ -54,16 +54,16 @@ private void registerService(String serviceGroup,
String serviceId,
BaseNetworkingConfig networkingConfig) {
SpServiceRegistrationRequest req = SpServiceRegistrationRequest.from(
serviceGroup,
serviceId,
networkingConfig.getHost(),
networkingConfig.getPort(),
getServiceTags(),
getHealthCheckPath());
serviceGroup,
serviceId,
networkingConfig.getHost(),
networkingConfig.getPort(),
getServiceTags(),
getHealthCheckPath());

SpServiceDiscovery
.getServiceDiscovery()
.registerService(req);
.getServiceDiscovery()
.registerService(req);
}

protected abstract List<SpServiceTag> getServiceTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class BaseResourceConfig extends ResourceConfig {
public BaseResourceConfig() {
property(ServletProperties.FILTER_FORWARD_ON_404, true);
getClassesToRegister()
.forEach(set -> set.forEach(this::register));
.forEach(set -> set.forEach(this::register));
register(ServiceHealthResource.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

public class UnauthorizedRequestEntryPoint implements AuthenticationEntryPoint {

private static final Logger LOG = LoggerFactory.getLogger(UnauthorizedRequestEntryPoint.class);
private static final Logger LOG = LoggerFactory.getLogger(UnauthorizedRequestEntryPoint.class);

@Override
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException {
LOG.error("Unauthorized request to {}", httpServletRequest.getPathInfo());
@Override
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
AuthenticationException e) throws IOException {
LOG.error("Unauthorized request to {}", httpServletRequest.getPathInfo());

httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getLocalizedMessage());
}
httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, e.getLocalizedMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@


<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
25 changes: 23 additions & 2 deletions streampipes-service-discovery-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>streampipes-parent</artifactId>
<groupId>org.apache.streampipes</groupId>
Expand All @@ -27,5 +28,25 @@

<artifactId>streampipes-service-discovery-api</artifactId>


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface ISpServiceDiscovery {
/**
* Register service.
*
* @param serviceRegistrationRequest the service registration request
* @param serviceRegistrationRequest the service registration request
*/
void registerService(SpServiceRegistrationRequest serviceRegistrationRequest);

Expand All @@ -48,10 +48,10 @@ public interface ISpServiceDiscovery {
/**
* Get service endpoints
*
* @param svcGroup service group for registered service
* @param restrictToHealthy retrieve healthy or all registered services for a service group
* @param filterByTags filter param to filter list of registered services
* @return list of services
* @param svcGroup service group for registered service
* @param restrictToHealthy retrieve healthy or all registered services for a service group
* @param filterByTags filter param to filter list of registered services
* @return list of services
*/
List<String> getServiceEndpoints(String svcGroup,
boolean restrictToHealthy,
Expand All @@ -67,7 +67,7 @@ List<String> getServiceEndpoints(String svcGroup,
/**
* Deregister registered service endpoint in Consul
*
* @param svcId service id of endpoint to be deregistered
* @param svcId service id of endpoint to be deregistered
*/
void deregisterService(String svcId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@

public interface SpConfig {

<T> void register(String key, T defaultValue, String description, ConfigurationScope configurationScope);
<T> void register(String key, T defaultValue, String description, ConfigurationScope configurationScope);

void register(String key, boolean defaultValue, String description);
void register(String key, boolean defaultValue, String description);

void register(String key, int defaultValue, String description);
void register(String key, int defaultValue, String description);

void register(String key, double defaultValue, String description);
void register(String key, double defaultValue, String description);

void register(String key, String defaultValue, String description);
void register(String key, String defaultValue, String description);

void register(ConfigItem configItem);
void register(ConfigItem configItem);

void registerObject(String key, Object defaultValue, String description);
void registerObject(String key, Object defaultValue, String description);

void registerPassword(String key, String defaultValue, String description);
void registerPassword(String key, String defaultValue, String description);

boolean getBoolean(String key);
boolean getBoolean(String key);

int getInteger(String key);
int getInteger(String key);

double getDouble(String key);
double getDouble(String key);

String getString(String key);
String getString(String key);

<T> T getObject(String key, Class<T> clazz, T defaultValue);
<T> T getObject(String key, Class<T> clazz, T defaultValue);

ConfigItem getConfigItem(String key);
ConfigItem getConfigItem(String key);

void setBoolean(String key, Boolean value);
void setBoolean(String key, Boolean value);

void setInteger(String key, int value);
void setInteger(String key, int value);

void setDouble(String key, double value);
void setDouble(String key, double value);

void setString(String key, String value);
void setString(String key, String value);

void setObject(String key, Object value);
void setObject(String key, Object value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class ConfigItem {
private ConfigurationScope configurationScope;
private boolean isPassword;

public ConfigItem() {
setPassword(false);
}

public static <T> ConfigItem from(String key,
T defaultValue,
String description) {
Expand All @@ -45,7 +49,8 @@ public static <T> ConfigItem from(String key,
String description,
ConfigurationScope configurationScope,
boolean isPassword) {
return from(key, defaultValue, description, ConfigItemUtils.getValueType(defaultValue), configurationScope, isPassword);
return from(key, defaultValue, description, ConfigItemUtils.getValueType(defaultValue), configurationScope,
isPassword);
}

public static <T> ConfigItem from(String key,
Expand All @@ -65,10 +70,6 @@ public static <T> ConfigItem from(String key,
return configItem;
}

public ConfigItem() {
setPassword(false);
}

public String getKey() {
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public class DefaultSpServiceTags {
public static final SpServiceTag PE = SpServiceTag.create(SpServiceTagPrefix.SYSTEM, "pe");
public static final SpServiceTag CONNECT_MASTER = SpServiceTag.create(SpServiceTagPrefix.SYSTEM, "connect-master");
public static final SpServiceTag CONNECT_WORKER = SpServiceTag.create(SpServiceTagPrefix.SYSTEM, "connect-worker");
public static final SpServiceTag STREAMPIPES_CLIENT = SpServiceTag.create(SpServiceTagPrefix.SYSTEM, "streampipes-client");
public static final SpServiceTag STREAMPIPES_CLIENT =
SpServiceTag.create(SpServiceTagPrefix.SYSTEM, "streampipes-client");
}
Loading

0 comments on commit 19d4f6c

Please sign in to comment.