Skip to content

Commit

Permalink
Tenant-aware integration tests for Connector
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Aug 9, 2024
1 parent 6173a93 commit 198931c
Show file tree
Hide file tree
Showing 3 changed files with 555 additions and 79 deletions.
197 changes: 121 additions & 76 deletions plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ dependencies {
implementation("software.amazon.awssdk:utils:2.25.40")
// AWS OpenSearch Service dependency
implementation("software.amazon.awssdk:apache-client:2.25.40")

configurations.all {
resolutionStrategy.force 'org.apache.httpcomponents.core5:httpcore5:5.2.4'
resolutionStrategy.force 'org.apache.httpcomponents.core5:httpcore5-h2:5.2.4'
Expand Down Expand Up @@ -134,11 +134,17 @@ publishing {
}

compileJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
options.compilerArgs.addAll([
"-processor",
'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
])
}

compileTestJava {
options.compilerArgs.addAll(["-processor", 'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'])
options.compilerArgs.addAll([
"-processor",
'lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
])
}

//TODO: check which one should be enabled
Expand Down Expand Up @@ -180,10 +186,20 @@ integTest {
systemProperty "user", System.getProperty("user")
systemProperty "password", System.getProperty("password")

// Only tenant aware test if set
if (System.getProperty("tests.rest.tenantaware") != null) {
filter {
includeTestsMatching "org.opensearch.ml.rest.*TenantAwareIT"
// mock LLM run in localhost, it will not reachable for docker or remote cluster
excludeTestsMatching "org.opensearch.ml.tools.VisualizationsToolIT"
}
}

// Only rest case can run with remote cluster
if (System.getProperty("tests.rest.cluster") != null) {
filter {
includeTestsMatching "org.opensearch.ml.rest.*IT"
excludeTestsMatching "org.opensearch.ml.rest.*TenantAwareIT"
// mock LLM run in localhost, it will not reachable for docker or remote cluster
excludeTestsMatching "org.opensearch.ml.tools.VisualizationsToolIT"
}
Expand All @@ -205,6 +221,18 @@ integTest {

// The 'doFirst' delays till execution time.
doFirst {
if (System.getProperty("tests.rest.tenantaware.remote") != null) {
def ymlFile = file("$buildDir/testclusters/integTest-0/config/opensearch.yml")
if (ymlFile.exists()) {
ymlFile.withWriterAppend { writer ->
writer.write("\n# Use a remote cluster\n")
writer.write("plugins.ml_commons.remote_metadata_type: RemoteOpenSearch\n")
writer.write("plugins.ml_commons.remote_metadata_endpoint: http://127.0.0.1\n")
}
} else {
throw new GradleException("opensearch.yml not found at: $ymlFile")
}
}
// Tell the test JVM if the cluster JVM is running under a debugger so that tests can
// use longer timeouts for requests.
def isDebuggingCluster = getDebug() || System.getProperty("test.debug") != null
Expand Down Expand Up @@ -310,45 +338,45 @@ jacocoTestReport {
}

List<String> jacocoExclusions = [
// TODO: add more unit test to meet the minimal test coverage.
'org.opensearch.ml.constant.CommonValue',
'org.opensearch.ml.plugin.MachineLearningPlugin*',
'org.opensearch.ml.indices.MLIndicesHandler',
'org.opensearch.ml.rest.RestMLPredictionAction',
'org.opensearch.ml.profile.MLModelProfile',
'org.opensearch.ml.profile.MLPredictRequestStats',
'org.opensearch.ml.action.deploy.TransportDeployModelAction',
'org.opensearch.ml.action.deploy.TransportDeployModelOnNodeAction',
'org.opensearch.ml.action.undeploy.TransportUndeployModelsAction',
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction',
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction.1',
'org.opensearch.ml.action.tasks.GetTaskTransportAction',
'org.opensearch.ml.action.tasks.SearchTaskTransportAction',
'org.opensearch.ml.model.MLModelManager',
'org.opensearch.ml.stats.MLClusterLevelStat',
'org.opensearch.ml.stats.MLStatLevel',
'org.opensearch.ml.utils.IndexUtils',
'org.opensearch.ml.cluster.MLCommonsClusterManagerEventListener',
'org.opensearch.ml.cluster.DiscoveryNodeHelper.HotDataNodePredicate',
'org.opensearch.ml.cluster.MLCommonsClusterEventListener',
'org.opensearch.ml.task.MLTaskManager',
'org.opensearch.ml.task.MLTrainingTaskRunner',
'org.opensearch.ml.task.MLPredictTaskRunner',
'org.opensearch.ml.task.MLTaskDispatcher',
'org.opensearch.ml.task.MLTrainAndPredictTaskRunner',
'org.opensearch.ml.task.MLExecuteTaskRunner',
'org.opensearch.ml.action.profile.MLProfileTransportAction',
'org.opensearch.ml.rest.RestMLPredictionAction',
'org.opensearch.ml.breaker.DiskCircuitBreaker',
'org.opensearch.ml.autoredeploy.MLModelAutoReDeployer.SearchRequestBuilderFactory',
'org.opensearch.ml.action.training.TrainingITTests',
'org.opensearch.ml.action.prediction.PredictionITTests',
'org.opensearch.ml.cluster.MLSyncUpCron',
'org.opensearch.ml.model.MLModelGroupManager',
'org.opensearch.ml.helper.ModelAccessControlHelper',
'org.opensearch.ml.action.models.DeleteModelTransportAction.2',
'org.opensearch.ml.model.MLModelCacheHelper',
'org.opensearch.ml.model.MLModelCacheHelper.1'
// TODO: add more unit test to meet the minimal test coverage.
'org.opensearch.ml.constant.CommonValue',
'org.opensearch.ml.plugin.MachineLearningPlugin*',
'org.opensearch.ml.indices.MLIndicesHandler',
'org.opensearch.ml.rest.RestMLPredictionAction',
'org.opensearch.ml.profile.MLModelProfile',
'org.opensearch.ml.profile.MLPredictRequestStats',
'org.opensearch.ml.action.deploy.TransportDeployModelAction',
'org.opensearch.ml.action.deploy.TransportDeployModelOnNodeAction',
'org.opensearch.ml.action.undeploy.TransportUndeployModelsAction',
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction',
'org.opensearch.ml.action.prediction.TransportPredictionTaskAction.1',
'org.opensearch.ml.action.tasks.GetTaskTransportAction',
'org.opensearch.ml.action.tasks.SearchTaskTransportAction',
'org.opensearch.ml.model.MLModelManager',
'org.opensearch.ml.stats.MLClusterLevelStat',
'org.opensearch.ml.stats.MLStatLevel',
'org.opensearch.ml.utils.IndexUtils',
'org.opensearch.ml.cluster.MLCommonsClusterManagerEventListener',
'org.opensearch.ml.cluster.DiscoveryNodeHelper.HotDataNodePredicate',
'org.opensearch.ml.cluster.MLCommonsClusterEventListener',
'org.opensearch.ml.task.MLTaskManager',
'org.opensearch.ml.task.MLTrainingTaskRunner',
'org.opensearch.ml.task.MLPredictTaskRunner',
'org.opensearch.ml.task.MLTaskDispatcher',
'org.opensearch.ml.task.MLTrainAndPredictTaskRunner',
'org.opensearch.ml.task.MLExecuteTaskRunner',
'org.opensearch.ml.action.profile.MLProfileTransportAction',
'org.opensearch.ml.rest.RestMLPredictionAction',
'org.opensearch.ml.breaker.DiskCircuitBreaker',
'org.opensearch.ml.autoredeploy.MLModelAutoReDeployer.SearchRequestBuilderFactory',
'org.opensearch.ml.action.training.TrainingITTests',
'org.opensearch.ml.action.prediction.PredictionITTests',
'org.opensearch.ml.cluster.MLSyncUpCron',
'org.opensearch.ml.model.MLModelGroupManager',
'org.opensearch.ml.helper.ModelAccessControlHelper',
'org.opensearch.ml.action.models.DeleteModelTransportAction.2',
'org.opensearch.ml.model.MLModelCacheHelper',
'org.opensearch.ml.model.MLModelCacheHelper.1'
]

jacocoTestCoverageVerification {
Expand Down Expand Up @@ -435,7 +463,11 @@ afterEvaluate {
}

task buildPackages(type: GradleBuild) {
tasks = ['build', 'buildRpm', 'buildDeb']
tasks = [
'build',
'buildRpm',
'buildDeb'
]
}
}

Expand Down Expand Up @@ -464,7 +496,10 @@ String opensearchMlPlugin = "opensearch-ml-" + project.version + ".zip"
testClusters {
"${baseName}$i" {
testDistribution = "ARCHIVE"
versions = [bwcShortVersion, opensearch_version]
versions = [
bwcShortVersion,
opensearch_version
]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>() {
@Override
Expand Down Expand Up @@ -496,22 +531,22 @@ String opensearchMlPlugin = "opensearch-ml-" + project.version + ".zip"
}

List<Provider<RegularFile>> plugins = [
provider(new Callable<RegularFile>() {
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
project.mkdir "$bwcFilePath/$project.version"
copy {
from "$buildDir/distributions/$opensearchMlPlugin"
into "$bwcFilePath/$project.version"
}
return fileTree(bwcFilePath + project.version).getSingleFile()
provider(new Callable<RegularFile>() {
@Override
RegularFile call() throws Exception {
return new RegularFile() {
@Override
File getAsFile() {
project.mkdir "$bwcFilePath/$project.version"
copy {
from "$buildDir/distributions/$opensearchMlPlugin"
into "$bwcFilePath/$project.version"
}
return fileTree(bwcFilePath + project.version).getSingleFile()
}
}
})
}
})
]

// Creates 2 test clusters with 3 nodes of the old version.
Expand All @@ -524,9 +559,11 @@ List<Provider<RegularFile>> plugins = [
systemProperty 'tests.rest.bwcsuite', 'old_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'old'
systemProperty 'tests.plugin_bwc_version', bwcVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}$i".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}$i".getName()}")
}
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}$i".allHttpSocketURI.join(",")
}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}$i".getName()
}")
}
}

// Upgrade one node of the old cluster to new OpenSearch version with upgraded plugin version
Expand All @@ -537,15 +574,17 @@ task "${baseName}#mixedClusterTask"(type: StandaloneRestIntegTestTask) {
dependsOn "${baseName}#oldVersionClusterTask0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
}
filter {
includeTestsMatching "org.opensearch.ml.bwc.*IT"
}
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'first'
systemProperty 'tests.plugin_bwc_version', bwcVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")
}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()
}")
}

// Upgrades the second node to new OpenSearch version with upgraded plugin version after the first node is upgraded.
Expand All @@ -556,15 +595,17 @@ task "${baseName}#twoThirdsUpgradedClusterTask"(type: StandaloneRestIntegTestTas
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
}
filter {
includeTestsMatching "org.opensearch.ml.bwc.*IT"
}
}
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'second'
systemProperty 'tests.plugin_bwc_version', bwcVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")
}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()
}")
}

// Upgrade the third node to new OpenSearch version with upgraded plugin version after the second node is upgraded.
Expand All @@ -575,16 +616,18 @@ task "${baseName}#rollingUpgradeClusterTask"(type: StandaloneRestIntegTestTask)
useCluster testClusters."${baseName}0"
doFirst {
testClusters."${baseName}0".upgradeNodeAndPluginToNextVersion(plugins)
}
}
filter {
includeTestsMatching "org.opensearch.ml.bwc.*IT"
}
}
mustRunAfter "${baseName}#mixedClusterTask"
systemProperty 'tests.rest.bwcsuite', 'mixed_cluster'
systemProperty 'tests.rest.bwcsuite_round', 'third'
systemProperty 'tests.plugin_bwc_version', bwcVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()}")
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}0".allHttpSocketURI.join(",")
}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}0".getName()
}")
}

// Upgrades all the nodes of the old cluster to new OpenSearch version with upgraded plugin version
Expand All @@ -594,14 +637,16 @@ task "${baseName}#fullRestartClusterTask"(type: StandaloneRestIntegTestTask) {
useCluster testClusters."${baseName}1"
doFirst {
testClusters."${baseName}1".upgradeAllNodesAndPluginsToNextVersion(plugins)
}
}
filter {
includeTestsMatching "org.opensearch.ml.bwc.*IT"
}
}
systemProperty 'tests.rest.bwcsuite', 'upgraded_cluster'
systemProperty 'tests.plugin_bwc_version', bwcVersion
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()}")
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}1".allHttpSocketURI.join(",")
}")
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}1".getName()
}")
}

// A bwc test suite which runs all the bwc tasks combined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ private void validateRequest4AccessControl(MLCreateConnectorInput input, User us

private void validateSecurityDisabledOrConnectorAccessControlDisabled(MLCreateConnectorInput input) {
if (input.getAccess() != null || input.getAddAllBackendRoles() != null || !CollectionUtils.isEmpty(input.getBackendRoles())) {
throw new IllegalArgumentException(
"You cannot specify connector access control parameters because the Security plugin or connector access control is disabled on your cluster."
);
// TODO: Get Security Plugin installed and working
// throw new IllegalArgumentException(
// "You cannot specify connector access control parameters because the Security plugin or connector access control is disabled
// on your cluster."
// );
}
}

Expand Down
Loading

0 comments on commit 198931c

Please sign in to comment.