Skip to content

Commit d8f3e38

Browse files
authored
Merge pull request #470 from Consdata/IKC-470
IKC-470 reset form when cluster was changed
2 parents 8cc146f + bdad132 commit d8f3e38

File tree

13 files changed

+623
-309
lines changed

13 files changed

+623
-309
lines changed

kouncil-backend/src/main/java/com/consdata/kouncil/topic/TopicController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.consdata.kouncil.topic;
22

3+
import static com.consdata.kouncil.model.admin.SystemFunctionNameConstants.TOPIC_SEND_MESSAGE;
4+
35
import com.consdata.kouncil.KouncilRuntimeException;
46
import com.consdata.kouncil.logging.EntryExitLogger;
57
import com.consdata.kouncil.model.admin.SystemFunctionNameConstants;
@@ -39,7 +41,7 @@ public TopicMessagesDto getTopicMessages(@PathVariable("topicName") String topic
3941
return topicService.getTopicMessages(topicName, partitions, pageParam, limitParam, beginningTimestampMillis, endTimestampMillis, offset, serverId);
4042
}
4143

42-
@RolesAllowed(SystemFunctionNameConstants.TOPIC_SEND_MESSAGE)
44+
@RolesAllowed(TOPIC_SEND_MESSAGE)
4345
@PostMapping("/send/{topicName}/{count}")
4446
@EntryExitLogger
4547
public void send(@PathVariable("topicName") String topicName,
@@ -87,4 +89,11 @@ public TopicData getTopicData(@PathVariable("topicName") String topicName, @Requ
8789
public void removeTopic(@PathVariable("topicName") String topicName, @RequestParam("serverId") String serverId) throws KouncilRuntimeException {
8890
topicService.removeTopic(topicName, serverId);
8991
}
92+
93+
@RolesAllowed(SystemFunctionNameConstants.TOPIC_MESSAGES)
94+
@GetMapping("/is-topic-exist/{topicName}")
95+
@EntryExitLogger
96+
public void isTopicExist(@PathVariable("topicName") String topicName, @RequestParam("serverId") String serverId) {
97+
topicService.isTopicExist(topicName, serverId);
98+
}
9099
}

kouncil-backend/src/main/java/com/consdata/kouncil/topic/TopicService.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
import org.springframework.beans.factory.annotation.Value;
5151
import org.springframework.kafka.core.KafkaTemplate;
5252
import org.springframework.stereotype.Service;
53-
import org.springframework.web.bind.annotation.PathVariable;
54-
import org.springframework.web.bind.annotation.RequestParam;
5553

5654
@Slf4j
5755
@Service
@@ -69,14 +67,14 @@ public class TopicService {
6967
@Value("${resendHeadersToKeep:}")
7068
private String[] resendHeadersToKeep;
7169

72-
TopicMessagesDto getTopicMessages(@PathVariable("topicName") String topicName,
73-
@PathVariable("partition") String partitions,
74-
@RequestParam("page") String pageParam,
75-
@RequestParam("limit") String limitParam,
76-
@RequestParam(value = "beginningTimestampMillis", required = false) Long beginningTimestampMillis,
77-
@RequestParam(value = "endTimestampMillis", required = false) Long endTimestampMillis,
78-
@RequestParam(value = "offset", required = false) Long offset,
79-
@RequestParam("serverId") String serverId) {
70+
TopicMessagesDto getTopicMessages(String topicName,
71+
String partitions,
72+
String pageParam,
73+
String limitParam,
74+
Long beginningTimestampMillis,
75+
Long endTimestampMillis,
76+
Long offset,
77+
String serverId) {
8078
messagesHelper.validateTopics(serverId, singletonList(topicName));
8179
int limit = Integer.parseInt(limitParam); // per partition!
8280
long page = Long.parseLong(pageParam); // per partition!
@@ -368,4 +366,8 @@ public void removeTopic(String topicName, String serverId) {
368366
throw new KouncilRuntimeException(e.getMessage());
369367
}
370368
}
369+
370+
public void isTopicExist(String topicName, String serverId) {
371+
messagesHelper.validateTopics(serverId, List.of(topicName));
372+
}
371373
}

kouncil-frontend/apps/kouncil/src/app/schemas/form/form/schema-form.component.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
1-
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import {
2+
ChangeDetectorRef,
3+
Component,
4+
EventEmitter,
5+
Input,
6+
OnDestroy,
7+
OnInit,
8+
Output
9+
} from '@angular/core';
210
import { ProgressBarService, ViewMode } from '@app/common-utils';
311
import {
412
Compatibility,
513
MessageFormat,
614
Schema,
7-
SchemaRegistryService,
15+
SchemaRegistryService, SchemaStateService,
816
SubjectType
917
} from '@app/schema-registry';
1018
import { ServersService } from '@app/common-servers';
11-
import { ActivatedRoute } from '@angular/router';
19+
import {ActivatedRoute, Router} from '@angular/router';
1220
import { TopicsService } from '@app/feat-topics';
1321
import { SelectableItem } from '@app/common-components';
1422
import { Topics } from '@app/common-model';
1523
import { first } from 'rxjs/operators';
1624
import { MatSelectChange } from '@angular/material/select';
1725
import { FormControl, FormGroup, Validators } from '@angular/forms';
26+
import {Subscription} from 'rxjs';
1827

1928
@Component({
2029
selector: 'app-schema-form',
@@ -83,7 +92,7 @@ import { FormControl, FormGroup, Validators } from '@angular/forms';
8392
`,
8493
styleUrls: ['./schema-form.component.scss']
8594
})
86-
export class SchemaFormComponent implements OnInit {
95+
export class SchemaFormComponent implements OnInit, OnDestroy {
8796

8897
model: Schema;
8998
subjectTypes: SelectableItem[] = Object.keys(SubjectType).map(format => new SelectableItem(format, format, false));
@@ -109,13 +118,16 @@ export class SchemaFormComponent implements OnInit {
109118
compatibility: new FormControl(),
110119
plainTextSchema: new FormControl('')
111120
});
121+
private readonly subscription: Subscription = new Subscription();
112122

113123
constructor(private schemaRegistry: SchemaRegistryService,
114124
private servers: ServersService,
115125
private progressBarService: ProgressBarService,
116126
private route: ActivatedRoute,
117127
private topicsService: TopicsService,
118-
private cdr: ChangeDetectorRef) {
128+
private cdr: ChangeDetectorRef,
129+
private schemaStateService: SchemaStateService,
130+
private router: Router) {
119131
}
120132

121133
ngOnInit(): void {
@@ -142,6 +154,16 @@ export class SchemaFormComponent implements OnInit {
142154
this.topics = topics.topics.map((tm) => new SelectableItem(tm.name, tm.name, false));
143155
this.progressBarService.setProgress(false);
144156
});
157+
158+
this.subscription.add(this.schemaStateService.isSchemaConfigured$(this.servers.getSelectedServerId()).subscribe((hasSchemaConnected) => {
159+
if (!hasSchemaConnected) {
160+
this.router.navigate(['/schemas']);
161+
}
162+
}));
163+
}
164+
165+
ngOnDestroy(): void {
166+
this.subscription.unsubscribe();
145167
}
146168

147169
private defineDisabled() {

kouncil-frontend/apps/kouncil/src/app/schemas/list/schemas.component.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Component, OnInit} from '@angular/core';
2-
import {Schema, SchemaRegistryService} from '@app/schema-registry';
2+
import {Schema, SchemaRegistryService, SchemaStateService} from '@app/schema-registry';
33
import {ServersService} from '@app/common-servers';
44
import {AbstractTableComponent, SelectableItem, TableColumn} from '@app/common-components';
55
import {ProgressBarService, SnackBarComponent, SnackBarData, SnackBarType} from '@app/common-utils';
@@ -39,7 +39,7 @@ const log = LoggerFactory.getLogger('SchemasComponent');
3939
Clear filters
4040
</button>
4141
42-
<button mat-button *ngIf="authService.canAccess([SystemFunctionName.SCHEMA_CREATE])"
42+
<button mat-button *ngIf="authService.canAccess([SystemFunctionName.SCHEMA_CREATE]) && serverHasSchemaConnected"
4343
class="action-button-blue" [routerLink]="['/schemas/create']">
4444
Add new schema
4545
</button>
@@ -151,6 +151,7 @@ export class SchemasComponent extends AbstractTableComponent implements OnInit {
151151
topicFilterForm: FormGroup = new FormGroup({
152152
topicFilterControl: new FormControl()
153153
});
154+
serverHasSchemaConnected: boolean = false;
154155

155156
constructor(private progressBarService: ProgressBarService,
156157
private schemaRegistry: SchemaRegistryService,
@@ -159,7 +160,8 @@ export class SchemasComponent extends AbstractTableComponent implements OnInit {
159160
private snackbar: MatSnackBar,
160161
protected authService: AuthService,
161162
private topicsService: TopicsService,
162-
private router: Router) {
163+
private router: Router,
164+
private schemaStateService: SchemaStateService) {
163165
super();
164166
}
165167

@@ -179,6 +181,10 @@ export class SchemasComponent extends AbstractTableComponent implements OnInit {
179181
this.filtered = data;
180182
this.progressBarService.setProgress(false);
181183
});
184+
185+
this.schemaStateService.isSchemaConfigured$(this.servers.getSelectedServerId()).subscribe(hasSchemaConnected=>{
186+
this.serverHasSchemaConnected = hasSchemaConnected;
187+
});
182188
}
183189

184190
deleteSchema(subject: string, version: string): void {

kouncil-frontend/apps/kouncil/src/app/toolbar/toolbar.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export class ToolbarComponent implements OnInit, AfterViewInit, OnDestroy {
113113

114114
public serverSelectionChanged(): void {
115115
localStorage.setItem('lastSelectedServer', this.servers.getSelectedServerId());
116+
this.servers.selectedServerChanged();
116117
this.router.navigate([this.router.url]);
117118
}
118119

kouncil-frontend/apps/kouncil/src/app/topic/topic.backend.service.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {TopicMessages} from './topic-messages';
55
import {Page} from './page';
66
import {HttpClient, HttpParams} from '@angular/common/http';
77
import {ProgressBarService} from '@app/common-utils';
8+
import {map} from 'rxjs/operators';
89

910
@Injectable({
1011
providedIn: 'root'
@@ -15,16 +16,16 @@ export class TopicBackendService implements TopicService {
1516
partitionEndOffsets: { [key: number]: number } = {};
1617
partitions?: number[];
1718
selectedPartition?: string;
18-
private convertTopicMessagesJsonToGrid$: Subject<TopicMessages> = new Subject<TopicMessages>();
19-
private numberOfPartitionsChanged$: Subject<number> = new Subject<number>();
19+
private readonly convertTopicMessagesJsonToGrid$: Subject<TopicMessages> = new Subject<TopicMessages>();
20+
private readonly numberOfPartitionsChanged$: Subject<number> = new Subject<number>();
2021
// eslint-disable-next-line rxjs/no-exposed-subjects
2122
protected paginationChanged$: BehaviorSubject<Page> = new BehaviorSubject<Page>({pageNumber: 1, size: 10});
2223

2324
constructor(protected http: HttpClient, protected progressBarService: ProgressBarService) {
2425
}
2526

2627
getMessages(serverId: string, topicName: string, offset?: number): void {
27-
let url;
28+
let url: string;
2829
if (typeof this.selectedPartition !== 'undefined') {
2930
url = `/api/topic/messages/${topicName}/${this.selectedPartition}`;
3031
} else {
@@ -92,4 +93,12 @@ export class TopicBackendService implements TopicService {
9293
goToOffset(serverId: string, topicName: string, offset: number): void {
9394
this.getMessages(serverId, topicName, offset);
9495
}
96+
97+
isTopicExist$(serverId: string, topicName: string): Observable<boolean>{
98+
const params = new HttpParams().set('serverId', serverId);
99+
100+
return this.http.get<void>(`/api/topic/is-topic-exist/${topicName}`, {params}).pipe(map(() => {
101+
return true;
102+
}));
103+
}
95104
}

kouncil-frontend/apps/kouncil/src/app/topic/topic.component.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {Observable, Subscription} from 'rxjs';
1313
import {JsonGrid} from './json-grid';
1414
import {TopicMessages} from './topic-messages';
1515
import {MessageData, MessageDataService} from '@app/message-data';
16-
import {DrawerService, ProgressBarService, SearchService} from '@app/common-utils';
16+
import {
17+
DrawerService,
18+
ProgressBarService,
19+
SearchService,
20+
} from '@app/common-utils';
1721
import {ServersService} from '@app/common-servers';
1822
import {SendComponent} from '@app/feat-send';
1923
import {AbstractTableComponent, TableColumn} from '@app/common-components';
@@ -83,17 +87,17 @@ export class TopicComponent extends AbstractTableComponent implements OnInit, On
8387
paging$: Observable<Page> = this.topicService.getPagination$();
8488

8589
constructor(
86-
private route: ActivatedRoute,
87-
private searchService: SearchService,
88-
private jsonGrid: JsonGrid,
89-
private titleService: Title,
90-
private progressBarService: ProgressBarService,
91-
private topicService: TopicService,
92-
private drawerService: DrawerService,
93-
private servers: ServersService,
94-
private messageDataService: MessageDataService,
95-
private router: Router,
96-
private location: Location
90+
private readonly route: ActivatedRoute,
91+
private readonly searchService: SearchService,
92+
private readonly jsonGrid: JsonGrid,
93+
private readonly titleService: Title,
94+
private readonly progressBarService: ProgressBarService,
95+
private readonly topicService: TopicService,
96+
private readonly drawerService: DrawerService,
97+
private readonly servers: ServersService,
98+
private readonly messageDataService: MessageDataService,
99+
private readonly router: Router,
100+
private readonly location: Location
97101
) {
98102
super();
99103
this.jsonToGridSubscription = this.topicService
@@ -116,10 +120,7 @@ export class TopicComponent extends AbstractTableComponent implements OnInit, On
116120
this.progressBarService.setProgress(true);
117121
this.route.params.subscribe((params) => {
118122
this.topicName = params['topic'];
119-
this.topicService.getMessages(
120-
this.servers.getSelectedServerId(),
121-
this.topicName
122-
);
123+
this.getMessageIfTopicExist();
123124
this.titleService.setTitle(this.topicName + ' Kouncil');
124125
this.paused = true;
125126
});
@@ -336,4 +337,11 @@ export class TopicComponent extends AbstractTableComponent implements OnInit, On
336337
const urlTree = this.router.createUrlTree([], {relativeTo: this.route, queryParams: {page}});
337338
this.location.go(urlTree.toString());
338339
}
340+
341+
private getMessageIfTopicExist() {
342+
this.topicService.isTopicExist$(this.servers.getSelectedServerId(), this.topicName).subscribe({
343+
next: ()=> this.topicService.getMessages(this.servers.getSelectedServerId(), this.topicName),
344+
error: ()=> this.router.navigate(['/topics'])
345+
});
346+
}
339347
}

kouncil-frontend/apps/kouncil/src/app/topic/topic.demo.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {TopicBackendService} from './topic.backend.service';
44
import {MessageData, MessageDataHeader} from '@app/message-data';
55
import {Crypto, RandomUtils} from '@app/common-utils';
66
import {demoTopics} from '@app/feat-topics';
7+
import {Observable, of} from 'rxjs';
78

89
@Injectable()
910
export class TopicDemoService extends TopicBackendService {
@@ -76,4 +77,8 @@ export class TopicDemoService extends TopicBackendService {
7677
topicName: ''
7778
} as MessageData;
7879
}
80+
81+
override isTopicExist$(_serverId: string, _topicName: string): Observable<boolean> {
82+
return of(true);
83+
}
7984
}

kouncil-frontend/apps/kouncil/src/app/topic/topic.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export abstract class TopicService {
2727
abstract goToOffset(serverId: string, topicName: string, offset?: number): void;
2828

2929
abstract getPagination$(): Observable<Page>;
30+
31+
abstract isTopicExist$(serverId: string, topicName: string): Observable<boolean>;
3032
}
3133

3234
export function topicServiceFactory(http: HttpClient, progressBarService: ProgressBarService): TopicService {

kouncil-frontend/apps/kouncil/src/app/track/track-filter/track-filter.component.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import {Component, OnInit, ViewChild} from '@angular/core';
1+
import {
2+
Component,
3+
OnDestroy,
4+
OnInit,
5+
ViewChild
6+
} from '@angular/core';
27
import {TrackService} from '../track.service';
38
import {FormControl, FormGroup, NgForm} from '@angular/forms';
49
import {TrackFilter, TrackOperator} from './track-filter';
510
import {TopicsService} from '@app/feat-topics';
611
import {Topics} from '@app/common-model';
712
import {ServersService} from '@app/common-servers';
813
import {SelectableItem} from '@app/common-components';
14+
import {Subscription} from 'rxjs';
915

1016
@Component({
1117
selector: 'app-track-filter',
@@ -109,7 +115,7 @@ import {SelectableItem} from '@app/common-components';
109115
`,
110116
styleUrls: ['./track-filter.component.scss'],
111117
})
112-
export class TrackFilterComponent implements OnInit {
118+
export class TrackFilterComponent implements OnInit, OnDestroy {
113119
@ViewChild('filtersForm', {static: false}) filtersForm?: NgForm;
114120

115121
operators: { name: string; index: number }[] = Object.keys(TrackOperator)
@@ -136,11 +142,11 @@ export class TrackFilterComponent implements OnInit {
136142
correlationTooltip: string = 'Filter messages by specifying the name and value of a message header.\nYou can select the matching method:\n' +
137143
'~ - contains value\n!~ - does not contain value\nis - exact match\nis not - does not match\nregex - regular expression match ';
138144

139-
constructor(
140-
private trackService: TrackService,
141-
private topicsService: TopicsService,
142-
private servers: ServersService
143-
) {
145+
private readonly subscription: Subscription = new Subscription();
146+
147+
constructor(private readonly trackService: TrackService,
148+
private readonly topicsService: TopicsService,
149+
private readonly servers: ServersService) {
144150
this.trackFilter = this.trackService.getStoredTrackFilter();
145151
}
146152

@@ -153,9 +159,17 @@ export class TrackFilterComponent implements OnInit {
153159
});
154160
this.trackFilter = this.trackService.getStoredTrackFilter();
155161

156-
this.trackService.trackFinished.subscribe(() => {
162+
this.subscription.add(this.trackService.trackFinished.subscribe(() => {
157163
this.loading = false;
158-
});
164+
}));
165+
166+
this.subscription.add(this.servers.selectedServerChanged$.subscribe(() => {
167+
this.trackService.resetStoredTrackFilter();
168+
}));
169+
}
170+
171+
ngOnDestroy(): void {
172+
this.subscription.unsubscribe();
159173
}
160174

161175
toggleAsyncMode(): void {

0 commit comments

Comments
 (0)