Search in sources :

Example 1 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class TriggersTest method assertUpdateIsAugmented.

private void assertUpdateIsAugmented(int key) {
    UntypedResultSet rs = QueryProcessor.executeInternal(String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cfName, key));
    assertTrue(String.format("Expected value (%s) for augmented cell v2 was not found", key), rs.one().has("v2"));
    assertEquals(999, rs.one().getInt("v2"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 2 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class CassandraAuthorizer method revokeAllFrom.

// Called when deleting a role with DROP ROLE query.
// Internal hook, so no permission checks are needed here.
// Executes a logged batch removing the granted premissions
// for the role as well as the entries from the reverse index
// table
public void revokeAllFrom(RoleResource revokee) {
    try {
        UntypedResultSet rows = process(String.format("SELECT resource FROM %s.%s WHERE role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(revokee.getRoleName())));
        List<CQLStatement> statements = new ArrayList<>();
        for (UntypedResultSet.Row row : rows) {
            statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE resource = '%s' AND role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(row.getString("resource")), escape(revokee.getRoleName())), ClientState.forInternalCalls()).statement);
        }
        statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE role = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(revokee.getRoleName())), ClientState.forInternalCalls()).statement);
        executeLoggedBatch(statements);
    } catch (RequestExecutionException | RequestValidationException e) {
        logger.warn("CassandraAuthorizer failed to revoke all permissions of {}: {}", revokee.getRoleName(), e);
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 3 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class CassandraAuthorizer method revokeAllOn.

// Called after a resource is removed (DROP KEYSPACE, DROP TABLE, etc.).
// Execute a logged batch removing all the permissions for the resource
// as well as the index table entry
public void revokeAllOn(IResource droppedResource) {
    try {
        UntypedResultSet rows = process(String.format("SELECT role FROM %s.%s WHERE resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(droppedResource.getName())));
        List<CQLStatement> statements = new ArrayList<>();
        for (UntypedResultSet.Row row : rows) {
            statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE role = '%s' AND resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.ROLE_PERMISSIONS, escape(row.getString("role")), escape(droppedResource.getName())), ClientState.forInternalCalls()).statement);
        }
        statements.add(QueryProcessor.getStatement(String.format("DELETE FROM %s.%s WHERE resource = '%s'", SchemaConstants.AUTH_KEYSPACE_NAME, AuthKeyspace.RESOURCE_ROLE_INDEX, escape(droppedResource.getName())), ClientState.forInternalCalls()).statement);
        executeLoggedBatch(statements);
    } catch (RequestExecutionException | RequestValidationException e) {
        logger.warn("CassandraAuthorizer failed to revoke all permissions on {}: {}", droppedResource, e);
        return;
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 4 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class CassandraAuthorizer method addPermissionsForRole.

// Add every permission on the resource granted to the role
private void addPermissionsForRole(Set<Permission> permissions, IResource resource, RoleResource role) throws RequestExecutionException, RequestValidationException {
    QueryOptions options = QueryOptions.forInternalCalls(ConsistencyLevel.LOCAL_ONE, Lists.newArrayList(ByteBufferUtil.bytes(role.getRoleName()), ByteBufferUtil.bytes(resource.getName())));
    SelectStatement statement;
    // is being upgraded and so is running with mixed versions of the authz schema
    if (Schema.instance.getTableMetadata(SchemaConstants.AUTH_KEYSPACE_NAME, USER_PERMISSIONS) == null)
        statement = authorizeRoleStatement;
    else {
        // If the permissions table was initialised only after the statement got prepared, re-prepare (CASSANDRA-12813)
        if (legacyAuthorizeRoleStatement == null)
            legacyAuthorizeRoleStatement = prepare(USERNAME, USER_PERMISSIONS);
        statement = legacyAuthorizeRoleStatement;
    }
    ResultMessage.Rows rows = statement.execute(QueryState.forInternalCalls(), options, System.nanoTime());
    UntypedResultSet result = UntypedResultSet.create(rows.result);
    if (!result.isEmpty() && result.one().has(PERMISSIONS)) {
        for (String perm : result.one().getSet(PERMISSIONS, UTF8Type.instance)) {
            permissions.add(Permission.valueOf(perm));
        }
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Example 5 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SystemKeyspace method getReleaseVersion.

/**
     * Get release version for given endpoint.
     * If release version is unknown, then this returns null.
     *
     * @param ep endpoint address to check
     * @return Release version or null if version is unknown.
     */
public static CassandraVersion getReleaseVersion(InetAddress ep) {
    try {
        if (FBUtilities.getBroadcastAddress().equals(ep)) {
            return new CassandraVersion(FBUtilities.getReleaseVersionString());
        }
        String req = "SELECT release_version FROM system.%s WHERE peer=?";
        UntypedResultSet result = executeInternal(format(req, PEERS), ep);
        if (result != null && result.one().has("release_version")) {
            return new CassandraVersion(result.one().getString("release_version"));
        }
        // version is unknown
        return null;
    } catch (IllegalArgumentException e) {
        // version string cannot be parsed
        return null;
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)107 Test (org.junit.Test)35 UUID (java.util.UUID)8 ByteBuffer (java.nio.ByteBuffer)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 HashSet (java.util.HashSet)5 Mutation (org.apache.cassandra.db.Mutation)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)3 Predicate (com.google.common.base.Predicate)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2