-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): only allow KV to be created for an existing namespace (#4522)
Fix: #4522
- Loading branch information
1 parent
02c8689
commit c2c4150
Showing
10 changed files
with
124 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
core/src/main/java/io/kestra/core/services/NamespaceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.kestra.core.services; | ||
|
||
import io.kestra.core.repositories.FlowRepositoryInterface; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Singleton | ||
public class NamespaceService { | ||
|
||
private final FlowRepositoryInterface flowRepository; | ||
|
||
@Inject | ||
public NamespaceService(FlowRepositoryInterface flowRepository) { | ||
this.flowRepository = flowRepository; | ||
} | ||
|
||
/** | ||
* Checks whether a given namespace exists. | ||
* | ||
* @param tenant The tenant ID | ||
* @param namespace The namespace - cannot be null. | ||
* @return {@code true} if the namespace exist. Otherwise {@link false}. | ||
*/ | ||
public boolean isNamespaceExists(String tenant, String namespace) { | ||
Objects.requireNonNull(namespace, "namespace cannot be null"); | ||
|
||
List<String> namespaces = flowRepository.findDistinctNamespace(tenant); | ||
return namespaces.stream().anyMatch(ns -> ns.equals(namespace)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
core/src/main/java/io/kestra/core/storages/kv/KVStoreException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.kestra.core.storages.kv; | ||
|
||
import io.kestra.core.exceptions.KestraRuntimeException; | ||
|
||
import java.io.Serial; | ||
|
||
/** | ||
* The base class for all other KVStore exceptions. | ||
*/ | ||
public class KVStoreException extends KestraRuntimeException { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
public KVStoreException() { | ||
} | ||
|
||
public KVStoreException(String message) { | ||
super(message); | ||
} | ||
|
||
public KVStoreException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public KVStoreException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters