Search in sources :

Example 11 with StringSerializer

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

the class CassandraResource method loadResourceData.

private void loadResourceData(ResourceProvider resourceProvider) {
    CassandraResourceProvider cassandraResourceProvider = (CassandraResourceProvider) resourceProvider;
    try {
        //          TODO ColumnFamilySector is NULL and hence this..
        String cql = cassandraResourceProvider.getCassandraMapperMap().get(columnFamilySector).getCQL(columnFamilySector, remainingPath);
        QueryResult<CqlRows<String, String, String>> results = CassandraResourceProviderUtil.executeQuery(cql, ((CassandraResourceProvider) resourceProvider).getKeyspace(), new StringSerializer());
        populateDataFromResult(results);
        dataLoaded = true;
    } catch (CassandraMapperException e) {
        System.out.println("Error occurred from resource at " + resourcePath + " : " + e.getMessage());
        LOGGER.error("Error occurred from resource at " + resourcePath + " : " + e.getMessage());
    }
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) CassandraMapperException(org.apache.sling.cassandra.resource.provider.mapper.CassandraMapperException) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 12 with StringSerializer

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

the class CassandraResourceProvider method deleteResource.

private boolean deleteResource(ResourceResolver resourceResolver, String path) throws PersistenceException {
    try {
        String key = getrowID(path);
        if (key == null) {
            return false;
        }
        String _cf = CassandraResourceProviderUtil.getColumnFamilySector(path);
        createColumnFamily(_cf, this.getKeyspace(), new StringSerializer());
        StringSerializer se = new StringSerializer();
        CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(keyspace, se, se, se);
        String query = "delete FROM " + _cf + " where KEY = '" + key + "';";
        cqlQuery.setQuery(query);
        QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute();
    } catch (NoSuchAlgorithmException e) {
        throw new PersistenceException(e.getMessage());
    } catch (UnsupportedEncodingException e) {
        throw new PersistenceException(e.getMessage());
    }
    return true;
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CqlQuery(me.prettyprint.cassandra.model.CqlQuery) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 13 with StringSerializer

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

the class AccessControlUtil method updateACL.

private void updateACL(String rid, String policy, StringSerializer se, QueryResult<CqlRows<String, String, String>> results) {
    String oldACL = "";
    for (Row<String, String, String> row : ((CqlRows<String, String, String>) results.get()).getList()) {
        for (HColumn column : row.getColumnSlice().getColumns()) {
            if ("policy".equalsIgnoreCase(column.getName().toString()) && column.getValue() != null) {
                oldACL = column.getValue().toString();
            }
        }
    }
    if (!oldACL.isEmpty()) {
        oldACL = oldACL + ";" + policy;
    }
    addACL(rid, oldACL, new StringSerializer());
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) HColumn(me.prettyprint.hector.api.beans.HColumn) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 14 with StringSerializer

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

the class AccessControlUtil method getACL.

private String[] getACL(String path) throws Exception {
    if (getCassandraSystemNodeACL(path) != null) {
        return getCassandraSystemNodeACL(path);
    }
    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());
    String policy = null;
    for (Row<String, String, String> row : ((CqlRows<String, String, String>) results.get()).getList()) {
        for (HColumn column : row.getColumnSlice().getColumns()) {
            if ("policy".equalsIgnoreCase(column.getName().toString()) && column.getValue() != null) {
                policy = column.getValue().toString();
            }
        }
    }
    return policy != null ? policy.split(";") : null;
}
Also used : CqlRows(me.prettyprint.cassandra.model.CqlRows) HColumn(me.prettyprint.hector.api.beans.HColumn) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer)

Example 15 with StringSerializer

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

the class CassandraDataAddLoadTest method testAddLoadTestData.

public void testAddLoadTestData() {
    try {
        for (int k = 0; k < sizes.length; k++) {
            CassandraResourceProvider cassandraResourceProvider = new CassandraResourceProvider();
            createColumnFamily(cfs[k], cassandraResourceProvider.getKeyspace(), new StringSerializer());
            cassandraResourceProvider.setColumnFamily(cfs[k]);
            CassandraResourceResolver resolver = new CassandraResourceResolver();
            for (int i = 0; i < sizes[k]; i++) {
                String path = parentPath + cfs[k] + "/" + i;
                Map<String, Object> map1 = new HashMap<String, Object>();
                map1.put("metadata", "resolutionPathInfo=json");
                map1.put("resourceType", "nt:cassandra0");
                map1.put("resourceSuperType", "nt:supercass1");
                cassandraResourceProvider.create(resolver, path, map1);
                cassandraResourceProvider.commit(resolver);
                System.out.println(">>" + path);
            }
        }
    } 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) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CassandraResourceResolver(org.apache.sling.cassandra.resource.provider.CassandraResourceResolver)

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