-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing agent execution for multi-tenancy (#2792)
Signed-off-by: Dhrubo Saha <[email protected]>
- Loading branch information
Showing
10 changed files
with
119 additions
and
21 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/src/main/java/org/opensearch/ml/common/settings/SettingsChangeListener.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,10 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.common.settings; | ||
|
||
public interface SettingsChangeListener { | ||
void onMultiTenancyEnabledChanged(boolean isEnabled); | ||
} |
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
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
68 changes: 68 additions & 0 deletions
68
plugin/src/test/java/org/opensearch/ml/settings/MLFeatureEnabledSettingTests.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,68 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ml.settings; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_AGENT_FRAMEWORK_ENABLED; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_LOCAL_MODEL_ENABLED; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_MULTI_TENANCY_ENABLED; | ||
import static org.opensearch.ml.settings.MLCommonsSettings.ML_COMMONS_REMOTE_INFERENCE_ENABLED; | ||
|
||
import java.util.Set; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.opensearch.cluster.service.ClusterService; | ||
import org.opensearch.common.settings.ClusterSettings; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.ml.common.settings.SettingsChangeListener; | ||
|
||
public class MLFeatureEnabledSettingTests { | ||
@Mock | ||
private ClusterService clusterService; | ||
private Settings settings; | ||
private MLFeatureEnabledSetting mlFeatureEnabledSetting; | ||
private SettingsChangeListener listener; | ||
|
||
@Before | ||
public void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
settings = Settings.builder().put(ML_COMMONS_MULTI_TENANCY_ENABLED.getKey(), false).build(); | ||
when(clusterService.getSettings()).thenReturn(settings); | ||
when(clusterService.getClusterSettings()) | ||
.thenReturn( | ||
new ClusterSettings( | ||
settings, | ||
Set | ||
.of( | ||
ML_COMMONS_MULTI_TENANCY_ENABLED, | ||
ML_COMMONS_REMOTE_INFERENCE_ENABLED, | ||
ML_COMMONS_AGENT_FRAMEWORK_ENABLED, | ||
ML_COMMONS_LOCAL_MODEL_ENABLED | ||
) | ||
) | ||
); | ||
|
||
mlFeatureEnabledSetting = new MLFeatureEnabledSetting(clusterService, settings); | ||
listener = mock(SettingsChangeListener.class); | ||
} | ||
|
||
@Test | ||
public void testAddListenerAndNotify() { | ||
mlFeatureEnabledSetting.addListener(listener); | ||
|
||
// Simulate settings change | ||
mlFeatureEnabledSetting.notifyMultiTenancyListeners(false); | ||
|
||
// Verify listener is notified | ||
verify(listener, times(1)).onMultiTenancyEnabledChanged(false); | ||
} | ||
} |