org.apache.zookeeper.proto.CreateRequest Java Examples

The following examples show how to use org.apache.zookeeper.proto.CreateRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClientCnxnAspect.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private EventType checkType(Record response) {

        if (response == null) {
            return EventType.other;
        } else if (response instanceof ConnectRequest) {
            return EventType.write;
        } else if (response instanceof CreateRequest) {
            return EventType.write;
        } else if (response instanceof DeleteRequest) {
            return EventType.write;
        } else if (response instanceof SetDataRequest) {
            return EventType.write;
        } else if (response instanceof SetACLRequest) {
            return EventType.write;
        } else if (response instanceof SetMaxChildrenRequest) {
            return EventType.write;
        } else if (response instanceof SetSASLRequest) {
            return EventType.write;
        } else if (response instanceof SetWatches) {
            return EventType.write;
        } else if (response instanceof SyncRequest) {
            return EventType.write;
        } else if (response instanceof ExistsRequest) {
            return EventType.read;
        } else if (response instanceof GetDataRequest) {
            return EventType.read;
        } else if (response instanceof GetMaxChildrenRequest) {
            return EventType.read;
        } else if (response instanceof GetACLRequest) {
            return EventType.read;
        } else if (response instanceof GetChildrenRequest) {
            return EventType.read;
        } else if (response instanceof GetChildren2Request) {
            return EventType.read;
        } else if (response instanceof GetSASLRequest) {
            return EventType.read;
        } else {
            return EventType.other;
        }
    }
 
Example #2
Source File: ClientCnxnInterceptorTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterceptor() throws Throwable {
    InetSocketAddress address = new InetSocketAddress("localhost", 2800);
    List<InetSocketAddress> serverAddresses = new ArrayList<InetSocketAddress>();
    serverAddresses.add(address);
    StaticHostProvider provider = new StaticHostProvider(serverAddresses);
    interceptor.onConstruct(instance, new Object[] {
        null,
        provider
    });
    RequestHeader header = new RequestHeader(1, 1);
    CreateRequest createRequest = new CreateRequest("/path", null, null, 0);
    interceptor.beforeMethod(instance, null, new Object[] {
        header,
        null,
        createRequest
    }, null, null);
    interceptor.afterMethod(instance, null, null, null, null);
    MatcherAssert.assertThat((String) instance.getSkyWalkingDynamicField(), Is.is("localhost:2800;"));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).getOperationName(), is("Zookeeper/create"));
    assertThat(spans.get(0).isExit(), is(true));
    assertThat(SpanHelper.getComponentId(spans.get(0)), is(58));
    List<TagValuePair> tags = SpanHelper.getTags(spans.get(0));
    assertThat(tags.get(0).getValue(), is("Zookeeper"));
    assertThat(SpanHelper.getLayer(spans.get(0)), CoreMatchers.is(SpanLayer.CACHE));
}
 
Example #3
Source File: CuratorMultiTransactionImpl.java    From curator with Apache License 2.0 5 votes vote down vote up
@Override
public List<CuratorTransactionResult> forOperations(List<CuratorOp> operations) throws Exception
{
    operations = Preconditions.checkNotNull(operations, "operations cannot be null");
    Preconditions.checkArgument(!operations.isEmpty(), "operations list cannot be empty");

    CuratorMultiTransactionRecord record = new CuratorMultiTransactionRecord();
    for ( CuratorOp curatorOp : operations )
    {
        Schema schema = client.getSchemaSet().getSchema(curatorOp.getTypeAndPath().getForPath());
        record.add(curatorOp.get(), curatorOp.getTypeAndPath().getType(), curatorOp.getTypeAndPath().getForPath());
        if ( (curatorOp.get().getType() == ZooDefs.OpCode.create) || (curatorOp.get().getType() == ZooDefs.OpCode.createContainer) )
        {
            CreateRequest createRequest = (CreateRequest)curatorOp.get().toRequestRecord();
            CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags(), CreateMode.PERSISTENT);
            schema.validateCreate(createMode, createRequest.getPath(), createRequest.getData(), createRequest.getAcl());
        }
        else if ( (curatorOp.get().getType() == ZooDefs.OpCode.delete) || (curatorOp.get().getType() == ZooDefs.OpCode.deleteContainer) )
        {
            DeleteRequest deleteRequest = (DeleteRequest)curatorOp.get().toRequestRecord();
            schema.validateDelete(deleteRequest.getPath());
        }
        else if ( curatorOp.get().getType() == ZooDefs.OpCode.setData )
        {
            SetDataRequest setDataRequest = (SetDataRequest)curatorOp.get().toRequestRecord();
            schema.validateGeneral(setDataRequest.getPath(), setDataRequest.getData(), null);
        }
    }

    if ( backgrounding.inBackground() )
    {
        client.processBackgroundOperation(new OperationAndData<>(this, record, backgrounding.getCallback(), null, backgrounding.getContext(), null), null);
        return null;
    }
    else
    {
        return forOperationsInForeground(record);
    }
}
 
Example #4
Source File: ChaosMonkeyCnxnFactory.java    From xian with Apache License 2.0 4 votes vote down vote up
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        ((NIOServerCnxn)si.cnxn).close();
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( si.type == ZooDefs.OpCode.create )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                ((NIOServerCnxn)si.cnxn).close();
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            ((NIOServerCnxn)si.cnxn).close();
        }
    }
}
 
Example #5
Source File: ChaosMonkeyCnxnFactory.java    From curator with Apache License 2.0 4 votes vote down vote up
@Override
public void submitRequest(Request si)
{
    long remaining = firstError != 0 ? LOCKOUT_DURATION_MS - (System.currentTimeMillis() - firstError) : 0;
    if ( si.type != ZooDefs.OpCode.createSession && si.type != ZooDefs.OpCode.sync && si.type != ZooDefs.OpCode.ping
        && firstError != 0 && remaining > 0 )
    {
        log.debug("Rejected : " + si.toString());
        // Still reject request
        log.debug("Still not ready for " + remaining + "ms");
        Compatibility.serverCnxnClose(si.cnxn);
        return;
    }
    // Submit the request to the legacy Zookeeper server
    log.debug("Applied : " + si.toString());
    super.submitRequest(si);
    // Raise an error if a lock is created
    if ( (si.type == ZooDefs.OpCode.create) || (si.type == ZooDefs.OpCode.create2) )
    {
        CreateRequest createRequest = new CreateRequest();
        try
        {
            ByteBuffer duplicate = si.request.duplicate();
            duplicate.rewind();
            ByteBufferInputStream.byteBuffer2Record(duplicate, createRequest);
            if ( createRequest.getPath().startsWith(CHAOS_ZNODE_PREFIX)
                && firstError == 0 )
            {
                firstError = System.currentTimeMillis();
                // The znode has been created, close the connection and don't tell it to client
                log.warn("Closing connection right after " + createRequest.getPath() + " creation");
                Compatibility.serverCnxnClose(si.cnxn);
            }
        }
        catch ( Exception e )
        {
            // Should not happen
            Compatibility.serverCnxnClose(si.cnxn);
        }
    }
}