Skip to content

Commit 276b05d

Browse files
authored
Merge pull request #170 from amosproj/sprint-10
Sprint 10
2 parents 9b1ce84 + 770b06d commit 276b05d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1272
-469
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# force line ending to lf on windows since this will be executed in a linux container
22
demodata/setup-topology/setup-topology.sh eol=lf
3+
demodata/setup-topology/setup-topology-local.sh eol=lf
4+
demodata/setup-topology/setup-topology-aws.sh eol=lf

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.env
2+
13
# Node
24
logs
35
npm-debug.log*

README.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ We want to achieve this by structuring our UI according to the topology of Apach
1616

1717
First, build the application JAR from the `backend` directory with:
1818

19-
```./mvnw package -DskipTests```
20-
19+
`./mvnw package -DskipTests`
2120

2221
Then, start Docker Desktop and create the pulsar setup from the root-directory with:
2322

24-
```docker-compose --profile demodata --profile backend up --build```
23+
```bash
24+
echo BACKEND_IP=localhost >> .env
25+
docker-compose --profile demodata --profile backend --profile frontend up --build -d
26+
```
2527

2628
Notes:
2729
* `--build` is needed for the first startup, or when the demodata docker images are changed
30+
* `-d` runs the container in the background, so u can close the terminal without terminating the app itself.
2831
* `--profile demodata` is needed when you want to create the demo topology and start the demo producers & consumers, that will continuously send and receive messages
2932
* `--profile backend` is needed when you want to start the backend via the docker-compose setup. See below for starting it manually.
33+
* `--profile frontend` is needed when you want to start the frontend via the docker-compose setup.
3034

3135
### Starting the backend separately
3236

3337
If you want to start the backend individually (e.g. during development), simply omit the `--profile backend` from the docker-compose command.
3438
Instead, start the application from the `backend` directory with:
3539

36-
```./mvnw spring-boot:run```
40+
`./mvnw spring-boot:run`
3741

3842
### Tests
3943

@@ -42,10 +46,23 @@ but instead use testcontainers. Therefore, docker needs to be running.
4246

4347
To start the tests use:
4448

45-
```./mvnw test```
49+
`./mvnw test`
4650

4751
### REST API
4852

4953
The backend is running on Port 8081 and the prefix of the REST endpoint is `/api`. A complete documentation can
5054
be found here:
5155
http://localhost:8081/api/swagger-ui/index.html
56+
57+
58+
### Running on AWS
59+
60+
For testing the scalability of our project, we want to test it on AWS with a bigger topology.
61+
We created a separate setup-topology for that - To start the backend using this, you need to run the following command.
62+
Each time the EC2 instance is started again, it will be assigned a new IP address,
63+
so you need to pass it to the `docker-compose` via `-e` flag.
64+
65+
```bash
66+
echo BACKEND_IP=${EC2_IP_ADDRESS} >> .env
67+
docker-compose --profile demodata-aws --profile backend --profile frontend up --build -d
68+
```

backend/src/main/java/de/amos/apachepulsarui/config/CaffeineCacheConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class CaffeineCacheConfig {
1414
@Bean
1515
public Caffeine<Object, Object> caffeineConfig() {
1616
return Caffeine.newBuilder()
17-
.initialCapacity(10)
18-
.maximumSize(100)
19-
.expireAfterWrite(10, TimeUnit.MINUTES)
17+
.initialCapacity(10_000)
18+
.maximumSize(10_000)
19+
.expireAfterWrite(1, TimeUnit.DAYS)
2020
.recordStats();
2121
}
2222

backend/src/main/java/de/amos/apachepulsarui/controller/ClusterController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package de.amos.apachepulsarui.controller;
22

3-
import de.amos.apachepulsarui.dto.ClusterDto;
3+
import de.amos.apachepulsarui.dto.ClusterDetailDto;
44
import de.amos.apachepulsarui.dto.ClustersDto;
55
import de.amos.apachepulsarui.service.ClusterService;
66
import lombok.RequiredArgsConstructor;
@@ -19,7 +19,7 @@ public class ClusterController {
1919
private final ClusterService clusterService;
2020

2121
@GetMapping()
22-
public ResponseEntity<ClusterDto> getClusterDetails(@RequestParam String clusterName) {
22+
public ResponseEntity<ClusterDetailDto> getClusterDetails(@RequestParam String clusterName) {
2323
return new ResponseEntity<>(clusterService.getClusterDetails(clusterName), HttpStatus.OK);
2424
}
2525

backend/src/main/java/de/amos/apachepulsarui/controller/MessageController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ public class MessageController {
2828

2929
@GetMapping
3030
public ResponseEntity<MessagesDto> getMessages(@RequestParam String topic,
31-
@RequestParam(required = false, defaultValue = "10") Integer numMessages) {
32-
List<MessageDto> messageDtos = messageService.getLatestMessagesOfTopic(topic, numMessages);
31+
@RequestParam(required = false, defaultValue = "10") Integer numMessages,
32+
@RequestParam(required = false, defaultValue = "") List<String> producers,
33+
@RequestParam(required = false, defaultValue = "") List<String> subscriptions) {
34+
List<MessageDto> messageDtos = messageService.getLatestMessagesFiltered(topic, numMessages, producers, subscriptions);
3335
return new ResponseEntity<>(new MessagesDto(messageDtos), HttpStatus.OK);
3436
}
3537
}

backend/src/main/java/de/amos/apachepulsarui/controller/TopicController.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@
66

77
package de.amos.apachepulsarui.controller;
88

9-
import de.amos.apachepulsarui.dto.*;
10-
import de.amos.apachepulsarui.exception.BadRequestException;
9+
import de.amos.apachepulsarui.dto.ConsumerDto;
10+
import de.amos.apachepulsarui.dto.ProducerDto;
11+
import de.amos.apachepulsarui.dto.SubscriptionDto;
12+
import de.amos.apachepulsarui.dto.TopicDetailDto;
13+
import de.amos.apachepulsarui.dto.TopicDto;
14+
import de.amos.apachepulsarui.dto.TopicsDto;
1115
import de.amos.apachepulsarui.service.NamespaceService;
1216
import de.amos.apachepulsarui.service.TenantService;
1317
import de.amos.apachepulsarui.service.TopicService;
1418
import lombok.RequiredArgsConstructor;
15-
import org.apache.pulsar.common.naming.TopicName;
1619
import org.springframework.http.HttpStatus;
1720
import org.springframework.http.ResponseEntity;
18-
import org.springframework.web.bind.annotation.*;
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.PathVariable;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.RequestParam;
25+
import org.springframework.web.bind.annotation.RestController;
1926

2027
import java.util.List;
2128

@@ -77,15 +84,6 @@ public ResponseEntity<ConsumerDto> getConsumerByNameAndTopic(@RequestParam Strin
7784
return new ResponseEntity<>(topicService.getConsumerByTopic(topic, consumer), HttpStatus.OK);
7885
}
7986

80-
@PostMapping("/new")
81-
public ResponseEntity<Void> newTopic(@RequestParam String topic) {
82-
if (!TopicName.isValid(topic)) {
83-
throw new BadRequestException.InvalidTopicName();
84-
}
85-
topicService.createNewTopic(topic);
86-
return new ResponseEntity<>(HttpStatus.CREATED);
87-
}
88-
8987
private ResponseEntity<TopicsDto> wrapInEntity(List<TopicDto> topicDtos) {
9088
return new ResponseEntity<>(new TopicsDto(topicDtos), HttpStatus.OK);
9189
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* SPDX-FileCopyrightText: 2023 Niklas Teschner <niklas.teschner@web.de>
4+
*/
5+
6+
package de.amos.apachepulsarui.dto;
7+
8+
import lombok.AccessLevel;
9+
import lombok.Builder;
10+
import lombok.Data;
11+
import lombok.Setter;
12+
13+
import java.util.List;
14+
15+
@Data
16+
@Builder
17+
public class ClusterDetailDto {
18+
19+
private String name;
20+
21+
private List<String> tenants;
22+
23+
private List<String> brokers;
24+
25+
@Setter(AccessLevel.PRIVATE)
26+
private int amountOfTenants;
27+
28+
@Setter(AccessLevel.PRIVATE)
29+
private int amountOfBrokers;
30+
31+
private String brokerServiceUrl;
32+
33+
private String serviceUrl;
34+
35+
}

backend/src/main/java/de/amos/apachepulsarui/dto/ClusterDto.java

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,19 @@
55

66
package de.amos.apachepulsarui.dto;
77

8-
import lombok.AccessLevel;
98
import lombok.Builder;
109
import lombok.Data;
11-
import lombok.Setter;
12-
13-
import java.util.List;
1410

1511
@Data
1612
@Builder
1713
public class ClusterDto {
1814

1915
private String name;
2016

21-
private List<String> tenants;
22-
23-
private List<String> brokers;
24-
25-
@Setter(AccessLevel.PRIVATE)
26-
private int amountOfTenants;
27-
28-
@Setter(AccessLevel.PRIVATE)
29-
private int amountOfBrokers;
30-
31-
private String brokerServiceUrl;
32-
33-
private String serviceUrl;
17+
private long numberOfTenants;
3418

19+
private long numberOfNamespces;
20+
public static ClusterDto create(String name) {
21+
return ClusterDto.builder().name(name).build();
22+
}
3523
}

backend/src/main/java/de/amos/apachepulsarui/dto/ClustersDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
@AllArgsConstructor
1515
public class ClustersDto {
1616

17-
private List<String> clusters;
17+
private List<ClusterDto> clusters;
1818

1919
}

0 commit comments

Comments
 (0)