diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/DataApiOpMapper.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/DataApiOpMapper.java index 190b6f79f..c7dc84d12 100644 --- a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/DataApiOpMapper.java +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/DataApiOpMapper.java @@ -59,6 +59,9 @@ public class DataApiOpMapper implements OpMapper { case delete_one -> new DataApiDeleteOneOpDispenser(adapter, op, typeAndTarget.targetFunction); case delete_many -> new DataApiDeleteManyOpDispenser(adapter, op, typeAndTarget.targetFunction); case delete_collection -> new DataApiDropCollectionOpDispenser(adapter, op, typeAndTarget.targetFunction); + case list_collections -> new DataApiListCollectionsOpDispenser(adapter, op, typeAndTarget.targetFunction); + case list_collection_names -> + new DataApiListCollectionNamesOpDispenser(adapter, op, typeAndTarget.targetFunction); }; } } diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionNamesOpDispenser.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionNamesOpDispenser.java new file mode 100644 index 000000000..a795bb9a0 --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionNamesOpDispenser.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020-2024 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.adapter.dataapi.opdispensers; + +import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter; +import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp; +import io.nosqlbench.adapter.dataapi.ops.DataApiListCollectionNamesOp; +import io.nosqlbench.adapters.api.templating.ParsedOp; + +import java.util.function.LongFunction; + +public class DataApiListCollectionNamesOpDispenser extends DataApiOpDispenser { + private final LongFunction opFunction; + public DataApiListCollectionNamesOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction targetFunction) { + super(adapter, op, targetFunction); + this.opFunction = createOpFunction(op); + } + + private LongFunction createOpFunction(ParsedOp op) { + return l -> { + return new DataApiListCollectionNamesOp(spaceFunction.apply(l).getDatabase()); + }; + } + + @Override + public DataApiBaseOp getOp(long value) { + return opFunction.apply(value); + } +} diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionsOpDispenser.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionsOpDispenser.java new file mode 100644 index 000000000..ca7163f75 --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/opdispensers/DataApiListCollectionsOpDispenser.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.adapter.dataapi.opdispensers; + +import io.nosqlbench.adapter.dataapi.DataApiDriverAdapter; +import io.nosqlbench.adapter.dataapi.ops.DataApiBaseOp; +import io.nosqlbench.adapter.dataapi.ops.DataApiListCollectionsOp; +import io.nosqlbench.adapters.api.templating.ParsedOp; + +import java.util.function.LongFunction; + +public class DataApiListCollectionsOpDispenser extends DataApiOpDispenser { + private final LongFunction opFunction; + public DataApiListCollectionsOpDispenser(DataApiDriverAdapter adapter, ParsedOp op, LongFunction targetFunction) { + super(adapter, op, targetFunction); + this.opFunction = createOpFunction(op); + } + + private LongFunction createOpFunction(ParsedOp op) { + return l -> { + DataApiListCollectionsOp dataApiListCollectionsOp = + new DataApiListCollectionsOp( + spaceFunction.apply(l).getDatabase()); + return dataApiListCollectionsOp; + }; + } + + @Override + public DataApiBaseOp getOp(long value) { + return opFunction.apply(value); + } +} diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiBaseOp.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiBaseOp.java index 13181c5db..e705801c2 100644 --- a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiBaseOp.java +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiBaseOp.java @@ -18,8 +18,11 @@ package io.nosqlbench.adapter.dataapi.ops; import com.datastax.astra.client.Database; import io.nosqlbench.adapters.api.activityimpl.uniform.flowtypes.CycleOp; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public abstract class DataApiBaseOp implements CycleOp { + protected static final Logger logger = LogManager.getLogger(DataApiBaseOp.class); protected final Database db; public DataApiBaseOp(Database db) { diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionNamesOp.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionNamesOp.java new file mode 100644 index 000000000..f69539f2a --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionNamesOp.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020-2024 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.adapter.dataapi.ops; + +import com.datastax.astra.client.Database; + +import java.util.stream.Stream; + +public class DataApiListCollectionNamesOp extends DataApiBaseOp { + + public DataApiListCollectionNamesOp(Database db) { + super(db); + } + + @Override + public Object apply(long value) { + Stream response; + response = db.listCollectionNames(); + if(logger.isDebugEnabled()) response.forEach(logger::debug); + return response; + } +} diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionsOp.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionsOp.java new file mode 100644 index 000000000..0328588db --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiListCollectionsOp.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020-2024 nosqlbench + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.nosqlbench.adapter.dataapi.ops; + +import com.datastax.astra.client.Database; + +public class DataApiListCollectionsOp extends DataApiBaseOp { + + public DataApiListCollectionsOp(Database db) { + super(db); + } + + @Override + public Object apply(long value) { + return db.listCollections(); + } +} diff --git a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiOpType.java b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiOpType.java index 4ddae3b83..03e9b18a9 100644 --- a/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiOpType.java +++ b/nb-adapters/adapter-dataapi/src/main/java/io/nosqlbench/adapter/dataapi/ops/DataApiOpType.java @@ -31,5 +31,7 @@ public enum DataApiOpType { update_many, delete_one, delete_many, - delete_collection + delete_collection, + list_collections, + list_collection_names, } diff --git a/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collection_names.yaml b/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collection_names.yaml new file mode 100644 index 000000000..e294f0a64 --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collection_names.yaml @@ -0,0 +1,8 @@ +scenarios: + default: + list_collection_names: run driver=dataapi tags==blocks:list_collection_names cycles=1 + +blocks: + list_collection_names: + ops: + op1: diff --git a/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collections.yaml b/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collections.yaml new file mode 100644 index 000000000..26dba23dd --- /dev/null +++ b/nb-adapters/adapter-dataapi/src/main/resources/activities/list_collections.yaml @@ -0,0 +1,8 @@ +scenarios: + default: + list_collections: run driver=dataapi tags==blocks:list_collections cycles=1 + +blocks: + list_collections: + ops: + op1: