Skip to content

Commit

Permalink
feat(#2276): Migrate rest interfaces to spring (#2277)
Browse files Browse the repository at this point in the history
* Migrate REST interfaces to spring web

* Fix request parameters

* Migrate further rest interfaces, modify openapi docs

* Fix dependency conflicts

* Remove old abstract rest classes

* Modify Spring JarLauncher path

* Downgrade to Spring 6.0 to avoid EPL errors

* Remove debug level

* Revert to Spring 3.1 launcher layout

* Fix dependencies

* Fix checkstyle

* Fix retrieval of JWT keypair

* Fix content types

* Remove duplicated code from AbstractRestResource

* Modify exception handlers

---------

Co-authored-by: bossenti <[email protected]>
  • Loading branch information
dominikriemer and bossenti authored Dec 11, 2023
1 parent 06f7803 commit 4656941
Show file tree
Hide file tree
Showing 126 changed files with 2,450 additions and 3,051 deletions.
37 changes: 26 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
<jaxb-runtime.version>2.3.2</jaxb-runtime.version>
<javax-websocket-api.version>1.1</javax-websocket-api.version>
<jakarta-persistence-api.version>3.0.1</jakarta-persistence-api.version>
<jakarta.ws.rs.version>3.1.0</jakarta.ws.rs.version>
<javassist.version>3.29.2-GA</javassist.version>
<jboss-logging.version>3.5.2.Final</jboss-logging.version>
<jedis.version>4.4.3</jedis.version>
Expand All @@ -94,8 +93,8 @@
<lightcouch.version>0.2.0</lightcouch.version>
<maven-plugin-annotations.version>3.7.1</maven-plugin-annotations.version>
<mailapi.version>1.4.3</mailapi.version>
<micrometer-prometheus.version>1.11.5</micrometer-prometheus.version>
<micrometer-observation.version>1.11.5</micrometer-observation.version>
<micrometer-prometheus.version>1.12.0</micrometer-prometheus.version>
<micrometer-observation.version>1.12.0</micrometer-observation.version>
<mqtt-client.version>1.12</mqtt-client.version>
<nats.version>2.17.0</nats.version>
<netty.version>4.1.72.Final</netty.version>
Expand All @@ -119,9 +118,11 @@
<slack-api.version>1.4.0</slack-api.version>
<slf4j.version>2.0.6</slf4j.version>
<snakeyaml.version>2.2</snakeyaml.version>
<spring-boot.version>3.1.5</spring-boot.version>
<spring-security.version>6.1.5</spring-security.version>
<swagger.version>2.2.7</swagger.version>
<springdoc.version>2.3.0</springdoc.version>
<spring.version>6.1.1</spring.version>
<spring-boot.version>3.2.0</spring-boot.version>
<spring-security.version>6.2.0</spring-security.version>
<swagger.version>2.2.19</swagger.version>
<type-parser.version>0.8.1</type-parser.version>
<hawtbuf.version>1.11</hawtbuf.version>

Expand Down Expand Up @@ -154,6 +155,13 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
Expand Down Expand Up @@ -339,11 +347,6 @@
<artifactId>persistence-api</artifactId>
<version>${jakarta-persistence-api.version}</version>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${jakarta.ws.rs.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
Expand Down Expand Up @@ -510,6 +513,11 @@
<artifactId>spring-security-core</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring-security.version}</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand Down Expand Up @@ -743,6 +751,11 @@
<artifactId>quartz</artifactId>
<version>${quartz.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
Expand Down Expand Up @@ -975,6 +988,7 @@
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -1264,6 +1278,7 @@
<configuration>
<release>17</release>
<encoding>UTF-8</encoding>
<parameters>true</parameters>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ COPY --from=builder dependencies/ ./
COPY --from=builder snapshot-dependencies/ ./
COPY --from=builder spring-boot-loader/ ./
COPY --from=builder application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ COPY --from=builder dependencies/ ./
COPY --from=builder snapshot-dependencies/ ./
COPY --from=builder spring-boot-loader/ ./
COPY --from=builder application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ COPY --from=builder dependencies/ ./
COPY --from=builder snapshot-dependencies/ ./
COPY --from=builder spring-boot-loader/ ./
COPY --from=builder application/ ./
ENTRYPOINT ["java", "org.springframework.boot.loader.JarLauncher"]
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"]
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ public enum Role {
),
ROLE_CONNECT_ADMIN(
Constants.ROLE_CONNECT_ADMIN_VALUE,
Privilege.PRIVILEGE_WRITE_ADAPTER

Privilege.PRIVILEGE_WRITE_ADAPTER,
Privilege.PRIVILEGE_READ_ADAPTER,
Privilege.PRIVILEGE_DELETE_ADAPTER
),

ROLE_DASHBOARD_USER(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ public Notification(String title, String description) {
this.description = description;
}

public Notification(String title, String description,
public Notification(String title,
String description,
String additionalInformation) {
super();
this.title = title;
this.description = description;
this.additionalInformation = additionalInformation;
}

public Notification(NotificationType notificationType, String additionalInformation) {
public Notification(NotificationType notificationType,
String additionalInformation) {
this(notificationType.title(), notificationType.description(), additionalInformation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.storage.management.StorageDispatcher;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Response;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Path("v4/datalake/images")

import java.io.InputStream;

@RestController
@RequestMapping("/api/v4/datalake/images")
public class DataLakeImageResource extends AbstractAuthGuardedRestResource {

@GET
@Path("{imageId}")
@Produces("image/jpeg")
public Response getImage(@PathParam("imageId") String imageId) {
@GetMapping(path = "{imageId}", produces = "image/jpeg")
public ResponseEntity<InputStream> getImage(@PathVariable("imageId") String imageId) {
return ok(StorageDispatcher.INSTANCE.getNoSqlStore().getImageStorage().getImageBytes(imageId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@
import org.apache.streampipes.dataexplorer.influx.DataLakeMeasurementCount;
import org.apache.streampipes.model.datalake.DataLakeMeasure;
import org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
import org.apache.streampipes.rest.shared.annotation.JacksonSerialized;
import org.apache.streampipes.storage.management.StorageDispatcher;

import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Path("/v4/datalake/measure")
@RestController
@RequestMapping("/api/v4/datalake/measure")
public class DataLakeMeasureResourceV4 extends AbstractAuthGuardedRestResource {

private final IDataExplorerSchemaManagement dataLakeMeasureManagement;
Expand All @@ -53,29 +54,24 @@ public DataLakeMeasureResourceV4() {
this.dataLakeMeasureManagement = new DataExplorerSchemaManagement(dataLakeStorage);
}

@POST
@JacksonSerialized
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response addDataLake(DataLakeMeasure dataLakeMeasure) {
@PostMapping(
produces = MediaType.APPLICATION_JSON_VALUE,
consumes = MediaType.APPLICATION_JSON_VALUE
)
public ResponseEntity<DataLakeMeasure> addDataLake(@RequestBody DataLakeMeasure dataLakeMeasure) {
DataLakeMeasure result = this.dataLakeMeasureManagement.createOrUpdateMeasurement(dataLakeMeasure);
return ok(result);
}

@GET
@JacksonSerialized
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getDataLakeInfos(@QueryParam("filter") List<String> measurementNames) {
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String, Integer>> getDataLakeInfos(
@RequestParam(value = "filter", required = false) List<String> measurementNames) {
var allMeasurements = this.dataLakeMeasureManagement.getAllMeasurements();
return ok(new DataLakeMeasurementCount(allMeasurements, measurementNames).countMeasurementSizes());
}

@GET
@JacksonSerialized
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response getDataLakeMeasure(@PathParam("id") String elementId) {
@GetMapping(path = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getDataLakeMeasure(@PathVariable("id") String elementId) {
var measure = this.dataLakeMeasureManagement.getById(elementId);
if (Objects.nonNull(measure)) {
return ok(measure);
Expand All @@ -84,15 +80,9 @@ public Response getDataLakeMeasure(@PathParam("id") String elementId) {
}
}

@PUT
@JacksonSerialized
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{id}")
public Response updateDataLakeMeasure(
@PathParam("id") String elementId,
DataLakeMeasure measure
) {
@PutMapping(path = "{id}", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateDataLakeMeasure(@PathVariable("id") String elementId,
@RequestBody DataLakeMeasure measure) {
if (elementId.equals(measure.getElementId())) {
try {
this.dataLakeMeasureManagement.updateMeasurement(measure);
Expand All @@ -104,10 +94,8 @@ public Response updateDataLakeMeasure(
return badRequest();
}

@DELETE
@JacksonSerialized
@Path("{id}")
public Response deleteDataLakeMeasure(@PathParam("id") String elementId) {
@DeleteMapping(path = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> deleteDataLakeMeasure(@PathVariable("id") String elementId) {
try {
this.dataLakeMeasureManagement.deleteMeasurement(elementId);
return ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,24 @@
import org.apache.streampipes.dataexplorer.utils.DataExplorerUtils;
import org.apache.streampipes.model.datalake.DataLakeMeasure;
import org.apache.streampipes.rest.core.base.impl.AbstractRestResource;
import org.apache.streampipes.rest.shared.annotation.JacksonSerialized;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Path("/v3/datalake")
@RestController
@RequestMapping("/api/v3/datalake")
@Deprecated
public class DataLakeResourceV3 extends AbstractRestResource {
public DataLakeResourceV3() {
}

@GET
@JacksonSerialized
@Produces(MediaType.APPLICATION_JSON)
@Path("/info")
public Response getAllInfos() {
@GetMapping(path = "/info", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<DataLakeMeasure>> getAllInfos() {
List<DataLakeMeasure> result = DataExplorerUtils.getInfos();
return ok(result);
}
Expand Down
Loading

0 comments on commit 4656941

Please sign in to comment.