use of software.amazon.awssdk.services.applicationautoscaling.model.PutScalingPolicyRequest in project scalardb by scalar-labs.
the class DynamoAdmin method createIndex.
@Override
public void createIndex(String namespace, String table, String columnName, Map<String, String> options) throws ExecutionException {
long ru = Long.parseLong(options.getOrDefault(REQUEST_UNIT, DEFAULT_REQUEST_UNIT));
TableMetadata metadata = getTableMetadata(namespace, table);
try {
client.updateTable(UpdateTableRequest.builder().tableName(getFullTableName(namespace, table)).attributeDefinitions(AttributeDefinition.builder().attributeName(columnName).attributeType(SECONDARY_INDEX_DATATYPE_MAP.get(metadata.getColumnDataType(columnName))).build()).globalSecondaryIndexUpdates(GlobalSecondaryIndexUpdate.builder().create(CreateGlobalSecondaryIndexAction.builder().indexName(getGlobalIndexName(namespace, table, columnName)).keySchema(KeySchemaElement.builder().attributeName(columnName).keyType(KeyType.HASH).build()).projection(Projection.builder().projectionType(ProjectionType.ALL).build()).provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(ru).writeCapacityUnits(ru).build()).build()).build()).build());
} catch (Exception e) {
throw new ExecutionException("creating the secondary index failed", e);
}
waitForIndexCreation(namespace, table, columnName);
// enable auto scaling
boolean noScaling = Boolean.parseBoolean(options.getOrDefault(NO_SCALING, DEFAULT_NO_SCALING));
if (!noScaling) {
List<RegisterScalableTargetRequest> registerScalableTargetRequestList = new ArrayList<>();
List<PutScalingPolicyRequest> putScalingPolicyRequestList = new ArrayList<>();
// write, read scaling of global indexes (secondary indexes)
for (String scalingType : SECONDARY_INDEX_SCALING_TYPE_SET) {
registerScalableTargetRequestList.add(buildRegisterScalableTargetRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType, (int) ru));
putScalingPolicyRequestList.add(buildPutScalingPolicyRequest(getGlobalIndexResourceID(namespace, table, columnName), scalingType));
}
registerScalableTarget(registerScalableTargetRequestList);
putScalingPolicy(putScalingPolicyRequestList);
}
// update metadata
TableMetadata tableMetadata = getTableMetadata(namespace, table);
putTableMetadata(namespace, table, TableMetadata.newBuilder(tableMetadata).addSecondaryIndex(columnName).build());
}
use of software.amazon.awssdk.services.applicationautoscaling.model.PutScalingPolicyRequest in project scalardb by scalar-labs.
the class DynamoAdmin method enableAutoScaling.
private void enableAutoScaling(String namespace, String table, Set<String> secondaryIndexes, long ru) throws ExecutionException {
List<RegisterScalableTargetRequest> registerScalableTargetRequestList = new ArrayList<>();
List<PutScalingPolicyRequest> putScalingPolicyRequestList = new ArrayList<>();
// write, read scaling of table
for (String scalingType : TABLE_SCALING_TYPE_SET) {
registerScalableTargetRequestList.add(buildRegisterScalableTargetRequest(getTableResourceID(namespace, table), scalingType, (int) ru));
putScalingPolicyRequestList.add(buildPutScalingPolicyRequest(getTableResourceID(namespace, table), scalingType));
}
// write, read scaling of global indexes (secondary indexes)
for (String secondaryIndex : secondaryIndexes) {
for (String scalingType : SECONDARY_INDEX_SCALING_TYPE_SET) {
registerScalableTargetRequestList.add(buildRegisterScalableTargetRequest(getGlobalIndexResourceID(namespace, table, secondaryIndex), scalingType, (int) ru));
putScalingPolicyRequestList.add(buildPutScalingPolicyRequest(getGlobalIndexResourceID(namespace, table, secondaryIndex), scalingType));
}
}
// request
for (RegisterScalableTargetRequest registerScalableTargetRequest : registerScalableTargetRequestList) {
try {
applicationAutoScalingClient.registerScalableTarget(registerScalableTargetRequest);
} catch (Exception e) {
throw new ExecutionException("Unable to register scalable target for " + registerScalableTargetRequest.resourceId(), e);
}
}
for (PutScalingPolicyRequest putScalingPolicyRequest : putScalingPolicyRequestList) {
try {
applicationAutoScalingClient.putScalingPolicy(putScalingPolicyRequest);
} catch (Exception e) {
throw new ExecutionException("Unable to put scaling policy request for " + putScalingPolicyRequest.resourceId(), e);
}
}
}
Aggregations