Search in sources :

Example 1 with TConditionalSession

use of org.apache.accumulo.core.dataImpl.thrift.TConditionalSession in project accumulo by apache.

the class ConditionalWriterImpl method reserveSessionID.

private SessionID reserveSessionID(HostAndPort location, TabletClientService.Iface client, TInfo tinfo) throws ThriftSecurityException, TException {
    // avoid cost of repeatedly making RPC to create sessions, reuse sessions
    synchronized (cachedSessionIDs) {
        SessionID sid = cachedSessionIDs.get(location);
        if (sid != null) {
            if (sid.reserved)
                throw new IllegalStateException();
            if (sid.isActive()) {
                sid.reserved = true;
                return sid;
            } else {
                cachedSessionIDs.remove(location);
            }
        }
    }
    TConditionalSession tcs = client.startConditionalUpdate(tinfo, context.rpcCreds(), ByteBufferUtil.toByteBuffers(auths.getAuthorizations()), tableId.canonical(), DurabilityImpl.toThrift(durability), this.classLoaderContext);
    synchronized (cachedSessionIDs) {
        SessionID sid = new SessionID();
        sid.reserved = true;
        sid.sessionID = tcs.sessionId;
        sid.lockId = tcs.tserverLock;
        sid.ttl = tcs.ttl;
        sid.location = location;
        if (cachedSessionIDs.put(location, sid) != null)
            throw new IllegalStateException();
        return sid;
    }
}
Also used : TConditionalSession(org.apache.accumulo.core.dataImpl.thrift.TConditionalSession)

Example 2 with TConditionalSession

use of org.apache.accumulo.core.dataImpl.thrift.TConditionalSession in project accumulo by apache.

the class ThriftClientHandler method startConditionalUpdate.

@Override
public TConditionalSession startConditionalUpdate(TInfo tinfo, TCredentials credentials, List<ByteBuffer> authorizations, String tableIdStr, TDurability tdurabilty, String classLoaderContext) throws ThriftSecurityException, TException {
    TableId tableId = TableId.of(tableIdStr);
    Authorizations userauths = null;
    NamespaceId namespaceId = getNamespaceId(credentials, tableId);
    if (!security.canConditionallyUpdate(credentials, tableId, namespaceId)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    }
    userauths = security.getUserAuthorizations(credentials);
    for (ByteBuffer auth : authorizations) {
        if (!userauths.contains(ByteBufferUtil.toBytes(auth))) {
            throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
        }
    }
    ConditionalSession cs = new ConditionalSession(credentials, new Authorizations(authorizations), tableId, DurabilityImpl.fromThrift(tdurabilty));
    long sid = server.sessionManager.createSession(cs, false);
    return new TConditionalSession(sid, server.getLockID(), server.sessionManager.getMaxIdleTime());
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Authorizations(org.apache.accumulo.core.security.Authorizations) TConditionalSession(org.apache.accumulo.core.dataImpl.thrift.TConditionalSession) TConditionalSession(org.apache.accumulo.core.dataImpl.thrift.TConditionalSession) ConditionalSession(org.apache.accumulo.tserver.session.ConditionalSession) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TConditionalSession (org.apache.accumulo.core.dataImpl.thrift.TConditionalSession)2 ByteBuffer (java.nio.ByteBuffer)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1 NamespaceId (org.apache.accumulo.core.data.NamespaceId)1 TableId (org.apache.accumulo.core.data.TableId)1 Authorizations (org.apache.accumulo.core.security.Authorizations)1 ConditionalSession (org.apache.accumulo.tserver.session.ConditionalSession)1