From 0b0602c436df2e3858f433fe047b2eab1803884a Mon Sep 17 00:00:00 2001 From: Jonathan Shook Date: Mon, 20 Dec 2021 10:03:32 -0600 Subject: [PATCH] initial ddb driver on new driver api --- .../adapter/dynamodb/DynamoDBCmdType.java | 7 + .../dynamodb/DynamoDBDriverAdapter.java | 34 ++++ .../adapter/dynamodb/DynamoDBOpMapper.java | 55 +++++++ .../adapter/dynamodb/DynamoDBSpace.java | 56 +++++++ .../DDBCreateTableOpDispenser.java | 152 ++++++++++++++++++ .../opdispensers/DDBGetItemOpDispenser.java | 63 ++++++++ .../opdispensers/DDBPutItemOpDispenser.java | 40 +++++ .../opdispensers/RawDynamoDBOpDispenser.java | 34 ++++ .../dynamodb/optypes/DDBCreateTableOp.java | 20 +++ .../dynamodb/optypes/DDBGetItemOp.java | 27 ++++ .../dynamodb/optypes/DDBPutItemOp.java | 22 +++ .../adapter/dynamodb/optypes/DynamoDBOp.java | 17 ++ .../dynamodb/optypes/RawDynamodOp.java | 15 ++ driver-directapi/pom.xml | 4 +- nb-api/pom.xml | 3 +- pom.xml | 9 ++ 16 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBCmdType.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBDriverAdapter.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBOpMapper.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBSpace.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBCreateTableOpDispenser.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBGetItemOpDispenser.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBPutItemOpDispenser.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/RawDynamoDBOpDispenser.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBCreateTableOp.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBGetItemOp.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBPutItemOp.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DynamoDBOp.java create mode 100644 adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/RawDynamodOp.java diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBCmdType.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBCmdType.java new file mode 100644 index 000000000..b6f554b85 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBCmdType.java @@ -0,0 +1,7 @@ +package io.nosqlbench.adapter.dynamodb; + +public enum DynamoDBCmdType { + CreateTable, + PutItem, + GetItem; +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBDriverAdapter.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBDriverAdapter.java new file mode 100644 index 000000000..628a6154d --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBDriverAdapter.java @@ -0,0 +1,34 @@ +package io.nosqlbench.adapter.dynamodb; + +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.engine.api.activityimpl.OpMapper; +import io.nosqlbench.engine.api.activityimpl.uniform.BaseDriverAdapter; +import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter; +import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache; +import io.nosqlbench.nb.annotations.Service; +import io.nosqlbench.nb.annotations.Stability; +import io.nosqlbench.nb.api.config.standard.NBConfigModel; +import io.nosqlbench.nb.api.config.standard.NBConfiguration; + +import java.util.function.Function; + +@Service(value = DriverAdapter.class, selector = "dynamodb", maturity = Stability.Experimental) +public class DynamoDBDriverAdapter extends BaseDriverAdapter { + + @Override + public OpMapper getOpMapper() { + DriverSpaceCache spaceCache = getSpaceCache(); + NBConfiguration adapterConfig = getConfiguration(); + return new DynamoDBOpMapper(adapterConfig, spaceCache); + } + + @Override + public Function getSpaceInitializer(NBConfiguration cfg) { + return (s) -> new DynamoDBSpace(s,cfg); + } + + @Override + public NBConfigModel getConfigModel() { + return DynamoDBSpace.getConfigModel(); + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBOpMapper.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBOpMapper.java new file mode 100644 index 000000000..12436efd6 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBOpMapper.java @@ -0,0 +1,55 @@ +package io.nosqlbench.adapter.dynamodb; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import io.nosqlbench.adapter.dynamodb.opdispensers.DDBCreateTableOpDispenser; +import io.nosqlbench.adapter.dynamodb.opdispensers.DDBGetItemOpDispenser; +import io.nosqlbench.adapter.dynamodb.opdispensers.DDBPutItemOpDispenser; +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.engine.api.activityimpl.OpDispenser; +import io.nosqlbench.engine.api.activityimpl.OpMapper; +import io.nosqlbench.engine.api.activityimpl.uniform.DriverSpaceCache; +import io.nosqlbench.engine.api.templating.NamedTarget; +import io.nosqlbench.engine.api.templating.ParsedOp; +import io.nosqlbench.nb.api.config.standard.NBConfiguration; +import io.nosqlbench.nb.api.errors.OpConfigError; + +public class DynamoDBOpMapper implements OpMapper { + + private final NBConfiguration cfg; + private final DriverSpaceCache cache; + + public DynamoDBOpMapper(NBConfiguration cfg, DriverSpaceCache cache) { + this.cfg = cfg; + this.cache = cache; + } + + @Override + public OpDispenser apply(ParsedOp cmd) { + String space = cmd.getStaticConfigOr("space", "default"); + DynamoDB ddb = cache.get(space).getDynamoDB(); + + /* + * If the user provides a body element, then they want to provide the JSON or + * a data structure that can be converted into JSON, bypassing any further + * specialized type-checking or op-type specific features + */ + if (cmd.isDefined("body")) { + throw new RuntimeException("This mode is reserved for later. Do not use the 'body' op field."); +// return new RawDynamoDBOpDispenser(cmd); + } else { + NamedTarget cmdType = cmd.getRequiredTypeFromEnum(DynamoDBCmdType.class); + switch (cmdType.enumId) { + case CreateTable: + return new DDBCreateTableOpDispenser(ddb,cmd,cmdType.targetFunction); + case PutItem: + return new DDBPutItemOpDispenser(ddb,cmd,cmdType.targetFunction); + case GetItem: + return new DDBGetItemOpDispenser(ddb,cmd,cmdType.targetFunction); + default: + throw new OpConfigError("No implementation for " + cmdType.toString()); + } + } + + } + +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBSpace.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBSpace.java new file mode 100644 index 000000000..9ec3bf0ac --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/DynamoDBSpace.java @@ -0,0 +1,56 @@ +package io.nosqlbench.adapter.dynamodb; + +import com.amazonaws.client.builder.AwsClientBuilder; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder; +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import io.nosqlbench.nb.api.config.standard.*; +import io.nosqlbench.nb.api.errors.OpConfigError; + +import java.util.Optional; + +public class DynamoDBSpace { + private final String name; + DynamoDB dynamoDB; + + public DynamoDBSpace(String name, NBConfiguration cfg) { + this.name = name; + AmazonDynamoDB client = createClient(cfg); + dynamoDB= new DynamoDB(client); + } + + public DynamoDB getDynamoDB() { + return dynamoDB; + } + + private AmazonDynamoDB createClient(NBConfiguration cfg) { + AmazonDynamoDBClientBuilder builder = AmazonDynamoDBClientBuilder.standard(); + Optional region = cfg.getOptional("region"); + Optional endpoint = cfg.getOptional("endpoint"); + Optional signing_region = cfg.getOptional("signing_region"); + + if (region.isPresent() && (endpoint.isPresent() || signing_region.isPresent())) { + throw new OpConfigError("If you specify region, endpoint and signing_region option are ambiguous"); + } + + if (region.isPresent()) { + builder.withRegion(region.get()); + } else if (endpoint.isPresent() && signing_region.isPresent()){ + AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(endpoint.get(), signing_region.get()); + builder = builder.withEndpointConfiguration(endpointConfiguration); + } else { + throw new OpConfigError("Either region or endpoint and signing_region options are required."); + } + + return builder.build(); + } + + public static NBConfigModel getConfigModel() { + return ConfigModel.of(DynamoDBSpace.class) + .add(Param.optional("endpoint")) + .add(Param.optional("signing_region")) + .add(Param.optional("region")) + .asReadOnly(); + } + +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBCreateTableOpDispenser.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBCreateTableOpDispenser.java new file mode 100644 index 000000000..72d2d2d0d --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBCreateTableOpDispenser.java @@ -0,0 +1,152 @@ +package io.nosqlbench.adapter.dynamodb.opdispensers; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.model.*; +import io.nosqlbench.adapter.dynamodb.optypes.DDBCreateTableOp; +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.engine.api.activityimpl.OpDispenser; +import io.nosqlbench.engine.api.templating.ParsedOp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.LongFunction; + +/** + *
{@code
+ * Request Syntax
+ * {
+ *    "AttributeDefinitions": [
+ *       {
+ *          "AttributeName": "string",
+ *          "AttributeType": "string"
+ *       }
+ *    ],
+ *    "BillingMode": "string",
+ *    "GlobalSecondaryIndexes": [
+ *       {
+ *          "IndexName": "string",
+ *          "KeySchema": [
+ *             {
+ *                "AttributeName": "string",
+ *                "KeyType": "string"
+ *             }
+ *          ],
+ *          "Projection": {
+ *             "NonKeyAttributes": [ "string" ],
+ *             "ProjectionType": "string"
+ *          },
+ *          "ProvisionedThroughput": {
+ *             "ReadCapacityUnits": number,
+ *             "WriteCapacityUnits": number
+ *          }
+ *       }
+ *    ],
+ *    "KeySchema": [
+ *       {
+ *          "AttributeName": "string",
+ *          "KeyType": "string"
+ *       }
+ *    ],
+ *    "LocalSecondaryIndexes": [
+ *       {
+ *          "IndexName": "string",
+ *          "KeySchema": [
+ *             {
+ *                "AttributeName": "string",
+ *                "KeyType": "string"
+ *             }
+ *          ],
+ *          "Projection": {
+ *             "NonKeyAttributes": [ "string" ],
+ *             "ProjectionType": "string"
+ *          }
+ *       }
+ *    ],
+ *    "ProvisionedThroughput": {
+ *       "ReadCapacityUnits": number,
+ *       "WriteCapacityUnits": number
+ *    },
+ *    "SSESpecification": {
+ *       "Enabled": boolean,
+ *       "KMSMasterKeyId": "string",
+ *       "SSEType": "string"
+ *    },
+ *    "StreamSpecification": {
+ *       "StreamEnabled": boolean,
+ *       "StreamViewType": "string"
+ *    },
+ *    "TableClass": "string",
+ *    "TableName": "string",
+ *    "Tags": [
+ *       {
+ *          "Key": "string",
+ *          "Value": "string"
+ *       }
+ *    ]
+ * }
+ * }
+ */ +public class DDBCreateTableOpDispenser implements OpDispenser { + + private final DynamoDB ddb; + private final LongFunction tableNameFunc; + private final LongFunction> keySchemaFunc; + private final LongFunction> attributeDefsFunc; + private final LongFunction readCapacityFunc; + private final LongFunction writeCapacityFunc; + private final LongFunction billingModeFunc; + + public DDBCreateTableOpDispenser(DynamoDB ddb, ParsedOp cmd, LongFunction targetFunc) { + this.ddb = ddb; + this.tableNameFunc = l -> targetFunc.apply(l).toString(); + this.keySchemaFunc = resolveKeySchemaFunction(cmd); + this.attributeDefsFunc = resolveAttributeDefinitionFunction(cmd); + this.billingModeFunc = cmd.getAsFunctionOr("BillingMode", BillingMode.PROVISIONED.name()); + this.readCapacityFunc = cmd.getAsFunctionOr("ReadCapacityUnits", "10"); + this.writeCapacityFunc = cmd.getAsFunctionOr("WriteCapacityUnits", "10"); + } + + @Override + public DDBCreateTableOp apply(long cycle) { + CreateTableRequest rq = new CreateTableRequest(); + rq.setTableName(tableNameFunc.apply(cycle)); + rq.setKeySchema(keySchemaFunc.apply(cycle)); + rq.setAttributeDefinitions(attributeDefsFunc.apply(cycle)); + rq.setBillingMode(BillingMode.valueOf(billingModeFunc.apply(cycle)).name()); + if (rq.getBillingMode().equals(BillingMode.PROVISIONED.name())) { + rq.setProvisionedThroughput( + new ProvisionedThroughput( + Long.parseLong(readCapacityFunc.apply(cycle)), + Long.parseLong(writeCapacityFunc.apply(cycle))) + ); + } + return new DDBCreateTableOp(ddb, rq); + } + + private LongFunction> resolveAttributeDefinitionFunction(ParsedOp cmd) { + LongFunction attrsmap = cmd.getAsRequiredFunction("Attributes", Map.class); + return (long l) -> { + List defs = new ArrayList<>(); + attrsmap.apply(l).forEach((k, v) -> { + defs.add(new AttributeDefinition(k.toString(), ScalarAttributeType.valueOf(v.toString()))); + }); + return defs; + }; + } + + private LongFunction> resolveKeySchemaFunction(ParsedOp cmd) { + LongFunction keysmap = cmd.getAsRequiredFunction("Keys", Map.class); + + return (long l) -> { + List elems = new ArrayList<>(); + keysmap.apply(l).forEach((k, v) -> { + elems.add(new KeySchemaElement(k.toString(), KeyType.valueOf(v.toString()))); + }); + return elems; + }; + } + + +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBGetItemOpDispenser.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBGetItemOpDispenser.java new file mode 100644 index 000000000..9087c28fa --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBGetItemOpDispenser.java @@ -0,0 +1,63 @@ +package io.nosqlbench.adapter.dynamodb.opdispensers; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.PrimaryKey; +import com.amazonaws.services.dynamodbv2.document.Table; +import com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec; +import io.nosqlbench.adapter.dynamodb.optypes.DDBGetItemOp; +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.engine.api.activityimpl.OpDispenser; +import io.nosqlbench.engine.api.templating.ParsedOp; + +import java.util.Map; +import java.util.Optional; +import java.util.function.LongFunction; + +public class DDBGetItemOpDispenser implements OpDispenser { + private final DynamoDB ddb; + private final LongFunction targetTableFunction; + private final LongFunction getItemSpecFunc; + + public DDBGetItemOpDispenser(DynamoDB ddb, ParsedOp cmd, LongFunction targetFunction) { + this.ddb = ddb; + this.targetTableFunction = l -> ddb.getTable(targetFunction.apply(l).toString()); + this.getItemSpecFunc = resolveGetItemSpecFunction(cmd); + } + + private LongFunction resolveGetItemSpecFunction(ParsedOp cmd) { + + PrimaryKey primaryKey = null; + LongFunction pkfunc = null; + String projection = null; + LongFunction projfunc = null; + + LongFunction keysmap_func = cmd.getAsRequiredFunction("key",Map.class); + LongFunction pk_func = l -> { + PrimaryKey pk = new PrimaryKey(); + keysmap_func.apply(l).forEach((k,v) -> { + pk.addComponent(k.toString(),v); + }); + return pk; + }; + + Optional> projection_func = cmd.getAsOptionalFunction("projection",String.class); + LongFunction gis = l -> new GetItemSpec().withPrimaryKey(pk_func.apply(l)); + + if (projection_func.isPresent()) { + LongFunction finalGis = gis; + gis = l -> { + LongFunction pj = projection_func.get(); + return finalGis.apply(l).withProjectionExpression(pj.apply(1)); + }; + } + return gis; + + } + + @Override + public DDBGetItemOp apply(long value) { + Table table = targetTableFunction.apply(value); + GetItemSpec getitemSpec = getItemSpecFunc.apply(value); + return new DDBGetItemOp(ddb, table, getitemSpec); + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBPutItemOpDispenser.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBPutItemOpDispenser.java new file mode 100644 index 000000000..a8643ed9b --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/DDBPutItemOpDispenser.java @@ -0,0 +1,40 @@ +package io.nosqlbench.adapter.dynamodb.opdispensers; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.Item; +import io.nosqlbench.adapter.dynamodb.optypes.DDBPutItemOp; +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.engine.api.activityimpl.OpDispenser; +import io.nosqlbench.engine.api.templating.ParsedOp; +import io.nosqlbench.nb.api.errors.OpConfigError; + +import java.util.Map; +import java.util.function.LongFunction; + +public class DDBPutItemOpDispenser implements OpDispenser { + + private final DynamoDB ddb; + private final LongFunction tableNameFunc; + private final LongFunction itemfunc; + + public DDBPutItemOpDispenser(DynamoDB ddb, ParsedOp cmd, LongFunction targetFunc) { + this.ddb = ddb; + this.tableNameFunc = l -> targetFunc.apply(l).toString(); + if (cmd.isDefined("item")) { + LongFunction f1 = cmd.getAsRequiredFunction("item", Map.class); + this.itemfunc = l -> Item.fromMap(f1.apply(l)); + } else if (cmd.isDefined("json")) { + LongFunction f1 = cmd.getAsRequiredFunction("json", String.class); + this.itemfunc = l -> Item.fromJSON(f1.apply(l)); + } else { + throw new OpConfigError("PutItem op templates require either an 'item' map field or a 'json' text field"); + } + } + + @Override + public DynamoDBOp apply(long value) { + String tablename = tableNameFunc.apply(value); + Item item = itemfunc.apply(value); + return new DDBPutItemOp(ddb,tablename,item); + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/RawDynamoDBOpDispenser.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/RawDynamoDBOpDispenser.java new file mode 100644 index 000000000..fe5bc5431 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/opdispensers/RawDynamoDBOpDispenser.java @@ -0,0 +1,34 @@ +package io.nosqlbench.adapter.dynamodb.opdispensers; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import io.nosqlbench.adapter.dynamodb.optypes.DynamoDBOp; +import io.nosqlbench.adapter.dynamodb.optypes.RawDynamodOp; +import io.nosqlbench.engine.api.activityimpl.OpDispenser; +import io.nosqlbench.engine.api.templating.ParsedOp; + +import java.util.function.LongFunction; + +public class RawDynamoDBOpDispenser implements OpDispenser { + + private final LongFunction jsonFunction; + private final DynamoDB ddb; + + public RawDynamoDBOpDispenser(DynamoDB ddb, ParsedOp cmd) { + this.ddb = ddb; + + String bodytype = cmd.getValueType("body").getSimpleName(); + switch (bodytype) { + case "String": + jsonFunction=cmd.getAsRequiredFunction("body"); + break; + default: + throw new RuntimeException("Unable to create body mapping function from type '" + bodytype + "'"); + } + } + + @Override + public DynamoDBOp apply(long value) { + String body = jsonFunction.apply(value); + return new RawDynamodOp(ddb,body); + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBCreateTableOp.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBCreateTableOp.java new file mode 100644 index 000000000..c9bef4280 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBCreateTableOp.java @@ -0,0 +1,20 @@ +package io.nosqlbench.adapter.dynamodb.optypes; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.Table; +import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; + +public class DDBCreateTableOp extends DynamoDBOp { + + private final CreateTableRequest rq; + + public DDBCreateTableOp(DynamoDB ddb, CreateTableRequest rq) { + super(ddb); + this.rq = rq; + } + + @Override + public Table apply(long value) { + return ddb.createTable(rq); + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBGetItemOp.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBGetItemOp.java new file mode 100644 index 000000000..de02f620d --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBGetItemOp.java @@ -0,0 +1,27 @@ +package io.nosqlbench.adapter.dynamodb.optypes; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.Item; +import com.amazonaws.services.dynamodbv2.document.Table; +import com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec; + +/** + * @see GetItem API + * @see Expressions.Attributes + */ +public class DDBGetItemOp extends DynamoDBOp { + private final Table table; + private GetItemSpec getItemSpec; + + public DDBGetItemOp(DynamoDB ddb, Table table, GetItemSpec getItemSpec) { + super(ddb); + this.table = table; + this.getItemSpec = getItemSpec; + } + + @Override + public Item apply(long value) { + Item result = table.getItem(getItemSpec); + return result; + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBPutItemOp.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBPutItemOp.java new file mode 100644 index 000000000..a47935e14 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DDBPutItemOp.java @@ -0,0 +1,22 @@ +package io.nosqlbench.adapter.dynamodb.optypes; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.Item; +import com.amazonaws.services.dynamodbv2.document.PutItemOutcome; + +public class DDBPutItemOp extends DynamoDBOp { + private final String tablename; + private final Item item; + + public DDBPutItemOp(DynamoDB ddb, String tablename, Item item) { + super(ddb); + this.tablename = tablename; + this.item = item; + } + + @Override + public PutItemOutcome apply(long value) { + PutItemOutcome outcome = ddb.getTable(tablename).putItem(item); + return outcome; + } +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DynamoDBOp.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DynamoDBOp.java new file mode 100644 index 000000000..573da2875 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/DynamoDBOp.java @@ -0,0 +1,17 @@ +package io.nosqlbench.adapter.dynamodb.optypes; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import io.nosqlbench.engine.api.activityimpl.uniform.flowtypes.CycleOp; + +/** + * https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html?icmpid=docs_dynamodb_help_panel_hp_capacity#HowItWorks.ProvisionedThroughput.Manual + */ +public abstract class DynamoDBOp implements CycleOp { + + protected DynamoDB ddb; + + public DynamoDBOp(DynamoDB ddb) { + this.ddb = ddb; + } + +} diff --git a/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/RawDynamodOp.java b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/RawDynamodOp.java new file mode 100644 index 000000000..b0421aed2 --- /dev/null +++ b/adapter-dynamodb/src/main/java/io/nosqlbench/adapter/dynamodb/optypes/RawDynamodOp.java @@ -0,0 +1,15 @@ +package io.nosqlbench.adapter.dynamodb.optypes; + +import com.amazonaws.services.dynamodbv2.document.DynamoDB; +import com.amazonaws.services.dynamodbv2.document.Table; + +public class RawDynamodOp extends DynamoDBOp { + public RawDynamodOp(DynamoDB ddb, String body) { + super(ddb); + } + + @Override + public Table apply(long value) { + throw new RuntimeException("raw ops are not supported in this API yet"); + } +} diff --git a/driver-directapi/pom.xml b/driver-directapi/pom.xml index fc91668b2..d15617a41 100644 --- a/driver-directapi/pom.xml +++ b/driver-directapi/pom.xml @@ -6,7 +6,7 @@ mvn-defaults io.nosqlbench - 4.15.65-SNAPSHOT + 4.15.71-SNAPSHOT ../mvn-defaults @@ -23,7 +23,7 @@ io.nosqlbench drivers-api - 4.15.65-SNAPSHOT + 4.15.71-SNAPSHOT diff --git a/nb-api/pom.xml b/nb-api/pom.xml index 51c9e7fed..2ccefd9ba 100644 --- a/nb-api/pom.xml +++ b/nb-api/pom.xml @@ -64,8 +64,9 @@ com.amazonaws aws-java-sdk-s3 - 1.12.12 + 1.12.129 + javax.xml.bind jaxb-api diff --git a/pom.xml b/pom.xml index cde3f0803..9f3a9a006 100644 --- a/pom.xml +++ b/pom.xml @@ -83,6 +83,15 @@ adapter-cqld4 + + with-dynamodb + + false + + + adapter-dynamodb + + with-mongodb