Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding context.restore when missed and fixing model group parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
amitgalitz committed May 1, 2024
1 parent ff072de commit 3b94d22
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -311,6 +311,7 @@ void checkMaxWorkflows(TimeValue requestTimeOut, Integer maxWorkflow, ActionList
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
logger.info("Querying existing workflows to count the max");
client.search(searchRequest, ActionListener.wrap(searchResponse -> {
context.restore();
internalListener.onResponse(searchResponse.getHits().getTotalHits().value < maxWorkflow);
}, exception -> {
String errorMessage = "Unable to fetch the workflows";
Original file line number Diff line number Diff line change
@@ -250,7 +250,6 @@ public void initializeMasterKey(ActionListener<Boolean> listener) {

GetRequest getRequest = new GetRequest(CONFIG_INDEX).id(MASTER_KEY);
client.get(getRequest, ActionListener.wrap(getResponse -> {

if (!getResponse.isExists()) {

// Generate new key and index
@@ -260,6 +259,7 @@ public void initializeMasterKey(ActionListener<Boolean> listener) {
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

client.index(masterKeyIndexRequest, ActionListener.wrap(indexResponse -> {
context.restore();
// Set generated key to master
logger.info("Config has been initialized successfully");
this.masterKey = generatedKey;
@@ -270,6 +270,7 @@ public void initializeMasterKey(ActionListener<Boolean> listener) {
}));

} else {
context.restore();
// Set existing key to master
logger.info("Config has already been initialized");
this.masterKey = (String) getResponse.getSourceAsMap().get(MASTER_KEY);
@@ -300,6 +301,7 @@ void initializeMasterKeyIfAbsent() {
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
GetRequest getRequest = new GetRequest(CONFIG_INDEX).id(MASTER_KEY);
client.get(getRequest, ActionListener.wrap(response -> {
context.restore();
if (response.isExists()) {
this.masterKey = (String) response.getSourceAsMap().get(MASTER_KEY);
} else {
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

@@ -142,7 +143,7 @@ public void onFailure(Exception ex) {
String modelGroupName = (String) inputs.get(NAME_FIELD);
String description = (String) inputs.get(DESCRIPTION_FIELD);
List<String> backendRoles = getBackendRoles(inputs);
AccessMode modelAccessMode = (AccessMode) inputs.get(MODEL_ACCESS_MODE);
AccessMode modelAccessMode = AccessMode.from(((String) inputs.get(MODEL_ACCESS_MODE)).toLowerCase(Locale.ROOT));
Boolean isAddAllBackendRoles = inputs.containsKey(ADD_ALL_BACKEND_ROLES)
? Booleans.parseBoolean(inputs.get(ADD_ALL_BACKEND_ROLES).toString())
: null;

0 comments on commit 3b94d22

Please sign in to comment.