use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class BatchHandler method throwException.
private void throwException(CosmosException exception) throws ExecutionException {
LOGGER.error(exception.getMessage(), exception);
int statusCode = exception.getSubStatusCode();
if (statusCode == CosmosErrorCode.PRECONDITION_FAILED.get()) {
throw new NoMutationException("no mutation was applied.");
} else if (statusCode == CosmosErrorCode.RETRY_WITH.get()) {
throw new RetriableExecutionException(exception.getMessage(), exception);
}
throw new ExecutionException(exception.getMessage(), exception);
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method createContainer.
private void createContainer(String database, String table, TableMetadata metadata) throws ExecutionException {
if (!databaseExists(database)) {
throw new ExecutionException("the database does not exists");
}
CosmosDatabase cosmosDatabase = client.getDatabase(database);
CosmosContainerProperties properties = computeContainerProperties(table, metadata);
cosmosDatabase.createContainer(properties);
CosmosStoredProcedureProperties storedProcedureProperties = computeContainerStoredProcedureProperties();
cosmosDatabase.getContainer(table).getScripts().createStoredProcedure(storedProcedureProperties);
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method createTable.
@Override
public void createTable(String namespace, String table, TableMetadata metadata, Map<String, String> options) throws ExecutionException {
checkMetadata(metadata);
try {
createContainer(namespace, table, metadata);
putTableMetadata(namespace, table, metadata);
} catch (RuntimeException e) {
throw new ExecutionException("creating the container failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method updateIndexingPolicy.
private void updateIndexingPolicy(String databaseName, String containerName, TableMetadata newTableMetadata) throws ExecutionException {
CosmosDatabase database = client.getDatabase(databaseName);
try {
// get the existing container properties
CosmosContainerResponse response = database.createContainerIfNotExists(containerName, PARTITION_KEY_PATH);
CosmosContainerProperties properties = response.getProperties();
// set the new index policy to the container properties
properties.setIndexingPolicy(computeIndexingPolicy(newTableMetadata));
// update the container properties
database.getContainer(containerName).replace(properties);
} catch (RuntimeException e) {
throw new ExecutionException("updating the indexing policy failed", e);
}
}
use of com.scalar.db.exception.storage.ExecutionException in project scalardb by scalar-labs.
the class CosmosAdmin method getTableMetadata.
@Override
public TableMetadata getTableMetadata(String namespace, String table) throws ExecutionException {
try {
String fullName = getFullTableName(namespace, table);
CosmosTableMetadata cosmosTableMetadata = readMetadata(fullName);
if (cosmosTableMetadata == null) {
return null;
}
return convertToTableMetadata(cosmosTableMetadata);
} catch (RuntimeException e) {
throw new ExecutionException("getting the container metadata failed", e);
}
}
Aggregations