public void CassandraBasicFunctionality_Success() { // Arrange var cluster = CassandraHelper.ConnectToDatabase(); var session = cluster.Connect(); var keyspaceName = "test_keyspace"; var tableName = "test_table"; session.DeleteKeyspaceIfExists(keyspaceName); session.CreateKeyspace(keyspaceName); session.ChangeKeyspace(keyspaceName); CassandraHelper.DropTableIfExists(session, keyspaceName, tableName); session.Execute("CREATE TABLE test_table (id int PRIMARY KEY, first_name text, last_name text)"); session.Execute("INSERT INTO test_table (id, first_name, last_name) VALUES (1, 'test', 'user')"); // Act var rs = session.Execute("SELECT * FROM test_table"); var row = rs.GetRows().ElementAt(0); var id = row.GetValue <int>("id"); var firstName = row.GetValue <string>("first_name"); var lastName = row.GetValue <string>("last_name"); CassandraHelper.DropTableIfExists(session, keyspaceName, tableName); CassandraHelper.DropKeyspaceIfExists(session, keyspaceName); // Assert Assert.Equal(1, id); Assert.Equal("test", firstName); Assert.Equal("user", lastName); }
public static IServiceCollection AddStorage(this IServiceCollection services, IConfiguration configuration, IHostingEnvironment hostingEnvironment) { // CachedStorage is the one deployed on production to ease heroku deployment if (hostingEnvironment.EnvironmentName.ToLower().Equals("production")) { services.AddSingleton <IUserStore>(new CachedStorage()); } else { var helper = new CassandraHelper(configuration["cassandra:host"], int.Parse(configuration["cassandra:port"]), configuration["cassandra:script"]); services.AddSingleton <IUserStore>(new CassandraStorage(helper.Session)); } return(services); }
public IActionResult GetTableSchema(Guid connectionId, string keyspaceName, string tableName) { try { using (ConnectionHelper connectionHelper = new ConnectionHelper()) { Connection connection = connectionHelper.GetConnectionById(connectionId); using (CassandraHelper cassandraHelper = new CassandraHelper(connection)) { Table table = cassandraHelper.GetTableSchema(keyspaceName, tableName); return(Ok(table)); } } } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }
public IActionResult ExecuteQuery(Guid connectionId, string queryText) { try { using (ConnectionHelper connectionHelper = new ConnectionHelper()) { Connection connection = connectionHelper.GetConnectionById(connectionId); using (CassandraHelper cassandraHelper = new CassandraHelper(connection)) { QueryResult queryResult = cassandraHelper.ExecuteQuery(queryText); return(Ok(queryResult)); } } } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }
public IActionResult CreateNewTable(TableDTO newTable) { try { using (ConnectionHelper connectionHelper = new ConnectionHelper()) { Connection connection = connectionHelper.GetConnectionById(newTable.ConnectionId); using (CassandraHelper cassandraHelper = new CassandraHelper(connection)) { cassandraHelper.CreateNewTable(newTable.ToModel()); return(Ok()); } } } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }
public IActionResult GetKeyspaces(Guid connectionId) { try { using (ConnectionHelper connectionHelper = new ConnectionHelper()) { Connection connection = connectionHelper.GetConnectionById(connectionId); using (CassandraHelper cassandraHelper = new CassandraHelper(connection)) { List <Keyspace> keyspaces = cassandraHelper.GetKeyspaces(); return(Ok(keyspaces)); } } } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }
public IActionResult DeleteTableColumn(Guid connectionId, string keyspaceName, string tableName, string columnName) { try { using (ConnectionHelper connectionHelper = new ConnectionHelper()) { Connection connection = connectionHelper.GetConnectionById(connectionId); using (CassandraHelper cassandraHelper = new CassandraHelper(connection)) { cassandraHelper.DeleteTableColumn(keyspaceName, tableName, columnName); return(Ok()); } } } catch (Exception exception) { return(StatusCode(500, exception.Message)); } }
/// <summary> /// Get URL's UUID by its short form. /// </summary> /// <param name="signature">URL's short form</param> /// <param name="uuid">URL's TimeUUID to be returned</param> /// <returns>Returns true if operation was successful.</returns> public bool GetUUIDBySignature(string signature, out TimeUuid uuid) { var col = CassandraSchema.TABLE_SIGNATURES.UUID; var cql = string.Format("SELECT {0} FROM {1} WHERE {2} = ? ;", col, CassandraSchema.TABLE_SIGNATURES.TBL_SIGNATURES, CassandraSchema.TABLE_SIGNATURES.SIGNATURE); var prep = this.session.Prepare(cql); var stmt = prep.Bind(signature); var rows = this.session.Execute(stmt); var row = CassandraHelper.GetFirstRow(rows); if (row == null) { return(false); } uuid = row.GetValue <TimeUuid>(col); return(true); }
/// <summary> /// Get URL's UUID by its short form. /// </summary> /// <param name="uuid">URL's TimeUUID</param> /// <param name="signature">URL's short form to be returned</param> /// <returns>Returns true if operation was successful.</returns> public bool GetSignatureByUUID(TimeUuid uuid, out string signature) { var col = CassandraSchema.TABLE_URLS.SIGNATURE; var cql = string.Format("SELECT {0} FROM {1} WHERE {2} = ? ;", col, CassandraSchema.TABLE_URLS.TBL_URLS, CassandraSchema.TABLE_URLS.UUID); var prep = this.session.Prepare(cql); var stmt = prep.Bind(uuid); var rows = this.session.Execute(stmt); var row = CassandraHelper.GetFirstRow(rows); if (row == null) { signature = string.Empty; return(false); } signature = row.GetValue <string>(col); return(true); }
/// <summary> /// Get URL popularity. /// </summary> /// <param name="uuid">URL's TimeUUID</param> /// <param name="hits">URL popularity to be returned</param> /// <returns>Returns true if operation was successful.</returns> public bool GetURLHitCount(TimeUuid uuid, out long hits) { var col = CassandraSchema.TABLE_HITS.HIT; var cql = string.Format("SELECT {0} FROM {1} WHERE {2} = ? ;", col, CassandraSchema.TABLE_HITS.TBL_HITS, CassandraSchema.TABLE_HITS.UUID); var prep = this.session.Prepare(cql); var stmt = prep.Bind(uuid); var rows = this.session.Execute(stmt); var row = CassandraHelper.GetFirstRow(rows); if (row == null) { hits = NOT_FOUND; return(false); } hits = row.GetValue <long>(col); return(true); }
/// <summary> /// Get URL's UUID by its SHA hash. /// </summary> /// <param name="sha512">URL's SHA512</param> /// <param name="sha256">URL's SHA256</param> /// <param name="uuid">URL's UUID to be returned</param> /// <returns>Returns true if operation was successful.</returns> public bool GetUUIDBySHA(string sha512, string sha256, out TimeUuid uuid) { var col = CassandraSchema.TABLE_HASHES.UUID; var cql = string.Format("SELECT {0} FROM {1} WHERE {2} = ? AND {3} = ? ;", col, CassandraSchema.TABLE_HASHES.TBL_HASHES, CassandraSchema.TABLE_HASHES.SHA512, CassandraSchema.TABLE_HASHES.SHA256); var prep = this.session.Prepare(cql); var stmt = prep.Bind(sha512, sha256); var rows = this.session.Execute(stmt); var row = CassandraHelper.GetFirstRow(rows); if (row == null) { return(false); } uuid = row.GetValue <TimeUuid>(col); return(true); }