public class CassandraArchiveRepository extends java.lang.Object implements ArchiveRepository
ScriptArchive
s stored in Cassandra.
This implementation is based on the Astyanax and requires CQL 3 support to be enabled.
The query algorithm attempts to divide up read operations such that they won't overwhelm Cassandra
if many instances are using this implementation to poll for updates.
Upon insertion, all archives are assigned a shard number calculated as (moduleId.hashCode() % shardNum)
.
The shard number is subsequently inserted into a column for which a secondary index has been defined.
RepositoryView poller methods will first search each shard for any rows with an update timestamp greater than
the last poll time, and if any are found, the contents of those archives are loaded in small batches.
Default Schema: CREATE TABLE script_repo ( module_id varchar, module_name varchar, module_version varchar, shard_num int, last_update timestamp, module_spec varchar, archive_content_hash blob, archive_content blob, PRIMARY KEY (module_id) ); CREATE INDEX script_repo_shard_num_index on script_repo (shard_num);See
CassandraArchiveRepositoryConfig
to override the default table name.Modifier and Type | Class and Description |
---|---|
static class |
CassandraArchiveRepository.Columns
column names
|
protected class |
CassandraArchiveRepository.DefaultView |
Modifier and Type | Field and Description |
---|---|
protected RepositoryView |
defaultView |
Constructor and Description |
---|
CassandraArchiveRepository(CassandraArchiveRepositoryConfig config)
Construct a instance of the repository with the given configuration
|
CassandraArchiveRepository(CassandraArchiveRepositoryConfig config,
RepositoryView defaultView)
Construct a instance of the repository with the given configuration
|
Modifier and Type | Method and Description |
---|---|
protected byte[] |
calculateHash(byte[] content) |
protected int |
calculateShardNum(ModuleId moduleId) |
void |
deleteArchive(ModuleId moduleId)
Delete an archive by ID
|
protected java.lang.String |
generateSelectByShardCql(java.util.EnumSet<?> columns,
java.lang.Integer shardNum)
Generate the CQL to select specific columns by shard number.
|
CassandraArchiveRepositoryConfig |
getConfig() |
RepositoryView |
getDefaultView()
The default view reports all archives inserted into this repository.
|
java.lang.String |
getRepositoryId()
Get the ID of this repository
|
protected java.lang.Iterable<com.netflix.astyanax.model.Row<java.lang.String,java.lang.String>> |
getRows(java.util.EnumSet<?> columns)
Get all of the rows in in the table.
|
java.util.Set<ScriptArchive> |
getScriptArchives(java.util.Set<ModuleId> moduleIds)
Get all of the
ScriptArchive s for the given set of moduleIds. |
RepositoryView |
getView(java.lang.String view)
No named views supported by this repository!
Throws UnsupportedOperationException.
|
void |
insertArchive(JarScriptArchive jarScriptArchive)
insert a Jar into the script archive
|
void |
insertArchive(JarScriptArchive jarScriptArchive,
java.util.Map<java.lang.String,java.lang.Object> initialDeploySpecs)
Unsupported.
|
protected boolean |
verifyHash(byte[] expectedHashCode,
byte[] content) |
protected final RepositoryView defaultView
public CassandraArchiveRepository(CassandraArchiveRepositoryConfig config)
config
- public CassandraArchiveRepository(CassandraArchiveRepositoryConfig config, RepositoryView defaultView)
config
- public java.lang.String getRepositoryId()
ArchiveRepository
getRepositoryId
in interface ArchiveRepository
public RepositoryView getDefaultView()
getDefaultView
in interface ArchiveRepository
public RepositoryView getView(java.lang.String view)
getView
in interface ArchiveRepository
view
- the name of the view.RepositoryView
that matches the given name or null if
one wasn't found.public void insertArchive(JarScriptArchive jarScriptArchive) throws java.io.IOException
insertArchive
in interface ArchiveRepository
jarScriptArchive
- script archive which describes the jar and
the ModuleSpec which should be insertedjava.io.IOException
public void insertArchive(JarScriptArchive jarScriptArchive, java.util.Map<java.lang.String,java.lang.Object> initialDeploySpecs) throws java.io.IOException
insertArchive
in interface ArchiveRepository
jarScriptArchive
- script archive which describes the jar and
the ModuleSpec which should be insertedinitialDeploySpecs
- a set of initial deployment specs.java.io.IOException
public java.util.Set<ScriptArchive> getScriptArchives(java.util.Set<ModuleId> moduleIds) throws java.io.IOException
ScriptArchive
s for the given set of moduleIds. Will perform the operation in batches
as specified by CassandraArchiveRepositoryConfig.getArchiveFetchBatchSize()
and outputs the jar files in
the path specified by CassandraArchiveRepositoryConfig.getArchiveOutputDirectory()
.getScriptArchives
in interface ArchiveRepository
moduleIds
- keys to search forjava.io.IOException
public void deleteArchive(ModuleId moduleId) throws java.io.IOException
deleteArchive
in interface ArchiveRepository
moduleId
- module id to deletejava.io.IOException
protected java.lang.Iterable<com.netflix.astyanax.model.Row<java.lang.String,java.lang.String>> getRows(java.util.EnumSet<?> columns) throws java.lang.Exception
columns
- which columns to selectjava.lang.Exception
protected java.lang.String generateSelectByShardCql(java.util.EnumSet<?> columns, java.lang.Integer shardNum)
SELECT ${columns}... FROM script_repo WHERE shard_num = ?
protected boolean verifyHash(byte[] expectedHashCode, byte[] content)
protected byte[] calculateHash(byte[] content)
protected int calculateShardNum(ModuleId moduleId)
public CassandraArchiveRepositoryConfig getConfig()