Search in sources :

Example 6 with StringSerializer

use of me.prettyprint.cassandra.serializers.StringSerializer in project sling by apache.

the class CassandraModifyResourceProviderRevertTest method testRevertData.

@Test
public void testRevertData() {
    String cf = "p4";
    try {
        String path1 = "/content/cassandra/" + cf + "/c1";
        CassandraResourceProvider cassandraResourceProvider = new CassandraResourceProvider();
        createColumnFamily(cf, cassandraResourceProvider.getKeyspace(), new StringSerializer());
        cassandraResourceProvider.setColumnFamily(cf);
        Map<String, Object> map1 = new HashMap<String, Object>();
        map1.put("metadata", "resolutionPathInfo=json");
        map1.put("resourceType", "nt:cassandra0");
        map1.put("resourceSuperType", "nt:supercass1");
        CassandraResourceResolver resolver = new CassandraResourceResolver();
        cassandraResourceProvider.create(resolver, path1, map1);
        Assert.assertNull("Before Commiting resource should be null", cassandraResourceProvider.getResource(resolver, path1));
        cassandraResourceProvider.revert(resolver);
        Assert.assertNull("Reverted resource should be null", cassandraResourceProvider.getResource(resolver, path1));
    } catch (Exception e) {
        LOGGER.info("Ignore err" + e.getMessage());
        Assert.fail("Failed to add data to cassandra");
    }
}
Also used : HashMap(java.util.HashMap) CassandraResourceProvider(org.apache.sling.cassandra.resource.provider.CassandraResourceProvider) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) CassandraResourceResolver(org.apache.sling.cassandra.resource.provider.CassandraResourceResolver) Test(org.junit.Test)

Example 7 with StringSerializer

use of me.prettyprint.cassandra.serializers.StringSerializer in project sling by apache.

the class AccessControlUtil method addACE.

private void addACE(String path, String policy) throws Exception {
    String rid = getrowID(path);
    createColumnFamily(ACL_CF, provider.getKeyspace(), new StringSerializer());
    String getAllACEs = "select * from " + ACL_CF + " where KEY = '" + rid + "'";
    QueryResult<CqlRows<String, String, String>> results = CassandraResourceProviderUtil.executeQuery(getAllACEs, provider.getKeyspace(), new StringSerializer());
    if (CassandraResourceProviderUtil.recordExists(results, "policy")) {
        updateACL(rid, policy, new StringSerializer(), results);
    } else {
        addACL(rid, policy, new StringSerializer());
    }
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 8 with StringSerializer

use of me.prettyprint.cassandra.serializers.StringSerializer in project archiva by apache.

the class CassandraMetadataRepository method removeNamespace.

@Override
public void removeNamespace(String repositoryId, String namespaceId) throws MetadataRepositoryException {
    try {
        String key = // 
        new Namespace.KeyBuilder().withNamespace(// 
        namespaceId).withRepositoryId(// 
        repositoryId).build();
        // 
        HFactory.createMutator(cassandraArchivaManager.getKeyspace(), new StringSerializer()).addDeletion(key, // 
        cassandraArchivaManager.getNamespaceFamilyName()).execute();
        QueryResult<OrderedRows<String, String, String>> result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getProjectFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.projectTemplate.deleteRow(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.projectVersionMetadataTemplate.deleteRow(row.getKey());
            removeMailingList(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.artifactMetadataTemplate.deleteRow(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.metadataFacetTemplate.deleteRow(row.getKey());
        }
    } catch (HInvalidRequestException e) {
        logger.error(e.getMessage(), e);
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 9 with StringSerializer

use of me.prettyprint.cassandra.serializers.StringSerializer in project archiva by apache.

the class CassandraUtils method getAsStringValue.

public static <T> String getAsStringValue(ColumnSlice<String, T> columnSlice, String columnName) {
    StringSerializer ss = StringSerializer.get();
    if (StringUtils.isEmpty(columnName)) {
        return null;
    }
    HColumn<String, T> hColumn = columnSlice.getColumnByName(columnName);
    return hColumn == null ? null : ss.fromByteBuffer(hColumn.getValueBytes());
}
Also used : StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 10 with StringSerializer

use of me.prettyprint.cassandra.serializers.StringSerializer in project cassandra-indexing by hmsonline.

the class AbstractIndexingTest method select.

protected Map<String, Map<String, String>> select(Keyspace keyspace, String columnFamily) {
    logger.debug("selecting from [" + columnFamily + "] @ [" + keyspace.getKeyspaceName() + "]");
    StringSerializer ss = new StringSerializer();
    RangeSlicesQuery<String, String, String> query = HFactory.createRangeSlicesQuery(keyspace, ss, ss, ss);
    query.setColumnFamily(columnFamily);
    query.setRange("", "", true, 100);
    query.setRowCount(100);
    query.setKeys("", "");
    List<Row<String, String, String>> rows = query.execute().get().getList();
    Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
    for (Row<String, String, String> row : rows) {
        Map<String, String> cols = new LinkedHashMap<String, String>();
        for (HColumn<String, String> col : row.getColumnSlice().getColumns()) {
            cols.put(col.getName(), col.getValue());
        }
        result.put(row.getKey(), cols);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Row(me.prettyprint.hector.api.beans.Row) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

StringSerializer (me.prettyprint.cassandra.serializers.StringSerializer)21 HInvalidRequestException (me.prettyprint.hector.api.exceptions.HInvalidRequestException)10 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 CassandraResourceProvider (org.apache.sling.cassandra.resource.provider.CassandraResourceProvider)9 Test (org.junit.Test)8 CqlRows (me.prettyprint.cassandra.model.CqlRows)6 HashMap (java.util.HashMap)5 CassandraResourceResolver (org.apache.sling.cassandra.resource.provider.CassandraResourceResolver)4 HColumn (me.prettyprint.hector.api.beans.HColumn)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CqlQuery (me.prettyprint.cassandra.model.CqlQuery)1 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)1 Row (me.prettyprint.hector.api.beans.Row)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 Namespace (org.apache.archiva.metadata.repository.cassandra.model.Namespace)1 CassandraMapperException (org.apache.sling.cassandra.resource.provider.mapper.CassandraMapperException)1