Skip to content

Commit 7051255

Browse files
committed
feat: move index management to event store client
1 parent 152f275 commit 7051255

6 files changed

Lines changed: 109 additions & 99 deletions

File tree

CLAUDE.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ The `AdminClient` class mirrors the architecture of `OrisunClient` but focuses o
9999
- **User Management**: `createUser`, `deleteUser`, `changePassword`, `listUsers`
100100
- **Authentication**: `validateCredentials`
101101
- **Statistics**: `getUserCount`, `getEventCount`
102-
- **Index Management**: `createIndex`, `dropIndex`
102+
103+
Index management is exposed on `OrisunClient` through the EventStore service.
103104

104105
Both clients share the same authentication flow, token caching mechanism, and connection management patterns.
105106

@@ -255,7 +256,7 @@ CreateIndexRequest request = CreateIndexRequest.newBuilder()
255256
.build())
256257
.setConditionCombinator(ConditionCombinator.AND)
257258
.build();
258-
adminClient.createIndex(request);
259+
orisunClient.createIndex(request);
259260
```
260261

261262
**Dropping an index:**
@@ -264,5 +265,5 @@ DropIndexRequest request = DropIndexRequest.newBuilder()
264265
.setBoundary("events-boundary")
265266
.setName("idx_user_id")
266267
.build();
267-
adminClient.dropIndex(request);
268-
```
268+
orisunClient.dropIndex(request);
269+
```

protos

src/main/java/com/orisunlabs/orisun/client/AdminClient.java

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -472,48 +472,6 @@ public long getEventCount(String boundary) throws OrisunException {
472472
return getEventCount(GetEventCountRequest.newBuilder().setBoundary(boundary).build());
473473
}
474474

475-
// Index Management Operations
476-
477-
/**
478-
* Create a new index on a boundary
479-
*/
480-
public void createIndex(CreateIndexRequest request) throws OrisunException {
481-
AdminRequestValidator.validateCreateIndexRequest(request);
482-
483-
logger.debug("Creating index '{}' on boundary: {}", request.getName(), request.getBoundary());
484-
485-
try {
486-
blockingStub
487-
.withDeadlineAfter(defaultTimeoutSeconds, TimeUnit.SECONDS)
488-
.createIndex(request);
489-
490-
logger.info("Successfully created index '{}' on boundary: {}", request.getName(), request.getBoundary());
491-
492-
} catch (StatusRuntimeException e) {
493-
throw handleException(e, "createIndex");
494-
}
495-
}
496-
497-
/**
498-
* Drop an index from a boundary
499-
*/
500-
public void dropIndex(DropIndexRequest request) throws OrisunException {
501-
AdminRequestValidator.validateDropIndexRequest(request);
502-
503-
logger.debug("Dropping index '{}' from boundary: {}", request.getName(), request.getBoundary());
504-
505-
try {
506-
blockingStub
507-
.withDeadlineAfter(defaultTimeoutSeconds, TimeUnit.SECONDS)
508-
.dropIndex(request);
509-
510-
logger.info("Successfully dropped index '{}' from boundary: {}", request.getName(), request.getBoundary());
511-
512-
} catch (StatusRuntimeException e) {
513-
throw handleException(e, "dropIndex");
514-
}
515-
}
516-
517475
private OrisunException handleException(StatusRuntimeException e, String operation) {
518476
Map<String, Object> context = new HashMap<>();
519477
context.put("operation", operation);
@@ -537,4 +495,4 @@ public void close() {
537495
}
538496
}
539497
}
540-
}
498+
}

src/main/java/com/orisunlabs/orisun/client/AdminRequestValidator.java

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -173,52 +173,4 @@ public static void validateGetEventCountRequest(GetEventCountRequest request) {
173173
}
174174
}
175175

176-
/**
177-
* Validate a CreateIndexRequest
178-
*/
179-
public static void validateCreateIndexRequest(CreateIndexRequest request) {
180-
if (request == null) {
181-
throw new OrisunException("CreateIndexRequest cannot be null")
182-
.addContext("operation", "createIndex");
183-
}
184-
185-
if (request.getBoundary() == null || request.getBoundary().trim().isEmpty()) {
186-
throw new OrisunException("Boundary is required")
187-
.addContext("operation", "createIndex");
188-
}
189-
190-
if (request.getName() == null || request.getName().trim().isEmpty()) {
191-
throw new OrisunException("Index name is required")
192-
.addContext("operation", "createIndex")
193-
.addContext("boundary", request.getBoundary());
194-
}
195-
196-
if (request.getFieldsCount() == 0) {
197-
throw new OrisunException("At least one field is required")
198-
.addContext("operation", "createIndex")
199-
.addContext("boundary", request.getBoundary())
200-
.addContext("indexName", request.getName());
201-
}
202-
}
203-
204-
/**
205-
* Validate a DropIndexRequest
206-
*/
207-
public static void validateDropIndexRequest(DropIndexRequest request) {
208-
if (request == null) {
209-
throw new OrisunException("DropIndexRequest cannot be null")
210-
.addContext("operation", "dropIndex");
211-
}
212-
213-
if (request.getBoundary() == null || request.getBoundary().trim().isEmpty()) {
214-
throw new OrisunException("Boundary is required")
215-
.addContext("operation", "dropIndex");
216-
}
217-
218-
if (request.getName() == null || request.getName().trim().isEmpty()) {
219-
throw new OrisunException("Index name is required")
220-
.addContext("operation", "dropIndex")
221-
.addContext("boundary", request.getBoundary());
222-
}
223-
}
224-
}
176+
}

src/main/java/com/orisunlabs/orisun/client/OrisunClient.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,56 @@ public void ping() throws OrisunException {
478478
}
479479
}
480480

481+
/**
482+
* Create a new index on a boundary.
483+
*/
484+
public void createIndex(Eventstore.CreateIndexRequest request) throws OrisunException {
485+
RequestValidator.validateCreateIndexRequest(request);
486+
487+
logger.debug("Creating index '{}' on boundary '{}'", request.getName(), request.getBoundary());
488+
489+
try {
490+
blockingStub
491+
.withDeadlineAfter(defaultTimeoutSeconds, TimeUnit.SECONDS)
492+
.createIndex(request);
493+
494+
logger.info("Successfully created index '{}' on boundary '{}'", request.getName(), request.getBoundary());
495+
} catch (StatusRuntimeException e) {
496+
Map<String, Object> context = new HashMap<>();
497+
context.put("operation", "createIndex");
498+
context.put("boundary", request.getBoundary());
499+
context.put("indexName", request.getName());
500+
context.put("statusCode", e.getStatus().getCode().name());
501+
502+
throw new OrisunException("Failed to create index", e, context);
503+
}
504+
}
505+
506+
/**
507+
* Drop an index from a boundary.
508+
*/
509+
public void dropIndex(Eventstore.DropIndexRequest request) throws OrisunException {
510+
RequestValidator.validateDropIndexRequest(request);
511+
512+
logger.debug("Dropping index '{}' from boundary '{}'", request.getName(), request.getBoundary());
513+
514+
try {
515+
blockingStub
516+
.withDeadlineAfter(defaultTimeoutSeconds, TimeUnit.SECONDS)
517+
.dropIndex(request);
518+
519+
logger.info("Successfully dropped index '{}' from boundary '{}'", request.getName(), request.getBoundary());
520+
} catch (StatusRuntimeException e) {
521+
Map<String, Object> context = new HashMap<>();
522+
context.put("operation", "dropIndex");
523+
context.put("boundary", request.getBoundary());
524+
context.put("indexName", request.getName());
525+
context.put("statusCode", e.getStatus().getCode().name());
526+
527+
throw new OrisunException("Failed to drop index", e, context);
528+
}
529+
}
530+
481531
/**
482532
* Check if the client is connected to the server
483533
*
@@ -518,4 +568,4 @@ public void close() {
518568
}
519569
}
520570
}
521-
}
571+
}

src/main/java/com/orisunlabs/orisun/client/RequestValidator.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,53 @@ public static void validateSubscribeRequest(Eventstore.CatchUpSubscribeToEventSt
137137
.addContext("boundary", request.getBoundary());
138138
}
139139
}
140-
}
140+
141+
/**
142+
* Validate a CreateIndexRequest
143+
*/
144+
public static void validateCreateIndexRequest(Eventstore.CreateIndexRequest request) {
145+
if (request == null) {
146+
throw new OrisunException("CreateIndexRequest cannot be null")
147+
.addContext("operation", "createIndex");
148+
}
149+
150+
if (request.getBoundary() == null || request.getBoundary().trim().isEmpty()) {
151+
throw new OrisunException("Boundary is required")
152+
.addContext("operation", "createIndex");
153+
}
154+
155+
if (request.getName() == null || request.getName().trim().isEmpty()) {
156+
throw new OrisunException("Index name is required")
157+
.addContext("operation", "createIndex")
158+
.addContext("boundary", request.getBoundary());
159+
}
160+
161+
if (request.getFieldsCount() == 0) {
162+
throw new OrisunException("At least one field is required")
163+
.addContext("operation", "createIndex")
164+
.addContext("boundary", request.getBoundary())
165+
.addContext("indexName", request.getName());
166+
}
167+
}
168+
169+
/**
170+
* Validate a DropIndexRequest
171+
*/
172+
public static void validateDropIndexRequest(Eventstore.DropIndexRequest request) {
173+
if (request == null) {
174+
throw new OrisunException("DropIndexRequest cannot be null")
175+
.addContext("operation", "dropIndex");
176+
}
177+
178+
if (request.getBoundary() == null || request.getBoundary().trim().isEmpty()) {
179+
throw new OrisunException("Boundary is required")
180+
.addContext("operation", "dropIndex");
181+
}
182+
183+
if (request.getName() == null || request.getName().trim().isEmpty()) {
184+
throw new OrisunException("Index name is required")
185+
.addContext("operation", "dropIndex")
186+
.addContext("boundary", request.getBoundary());
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)