當前位置: 首頁>>代碼示例>>Java>>正文


Java Ids.OPEN_ACL_UNSAFE屬性代碼示例

本文整理匯總了Java中org.apache.zookeeper.ZooDefs.Ids.OPEN_ACL_UNSAFE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Ids.OPEN_ACL_UNSAFE屬性的具體用法?Java Ids.OPEN_ACL_UNSAFE怎麽用?Java Ids.OPEN_ACL_UNSAFE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.zookeeper.ZooDefs.Ids的用法示例。


在下文中一共展示了Ids.OPEN_ACL_UNSAFE屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setUp

@Override
public void setUp() throws Exception {
  super.setUp();
  
  zkServer = getServer(serverFactory);

  for (int i = 0; i < NUM_ELECTORS; i++) {
    cbs[i] =  Mockito.mock(ActiveStandbyElectorCallback.class);
    appDatas[i] = Ints.toByteArray(i);
    electors[i] = new ActiveStandbyElector(hostPort, 5000, PARENT_DIR,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), cbs[i],
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:14,代碼來源:TestActiveStandbyElectorRealZK.java

示例2: init

@Before
public void init() throws IOException, KeeperException {
  count = 0;
  mockZK = Mockito.mock(ZooKeeper.class);
  mockApp = Mockito.mock(ActiveStandbyElectorCallback.class);
  elector = new ActiveStandbyElectorTester("hostPort", 1000, ZK_PARENT_NAME,
      Ids.OPEN_ACL_UNSAFE, mockApp);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:8,代碼來源:TestActiveStandbyElector.java

示例3: testWithoutZKServer

/**
 * verify the zookeeper connection establishment
 */
@Test
public void testWithoutZKServer() throws Exception {
  try {
    new ActiveStandbyElector("127.0.0.1", 2000, ZK_PARENT_NAME,
        Ids.OPEN_ACL_UNSAFE, Collections.<ZKAuthInfo> emptyList(), mockApp,
        CommonConfigurationKeys.HA_FC_ELECTOR_ZK_OP_RETRIES_DEFAULT);
    Assert.fail("Did not throw zookeeper connection loss exceptions!");
  } catch (KeeperException ke) {
    GenericTestUtils.assertExceptionContains( "ConnectionLoss", ke);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:14,代碼來源:TestActiveStandbyElector.java

示例4: sendWriteRequest

public void sendWriteRequest() throws Exception {
    ByteArrayOutputStream boas = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(boas);
    CreateRequest createReq = new CreateRequest(
        "/session" + Long.toHexString(sessionId) + "-" + (++nodeId),
        new byte[0], Ids.OPEN_ACL_UNSAFE, 1);
    createReq.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(boas.toByteArray());
    Request req = new Request(null, sessionId, ++cxid, OpCode.create,
                              bb, new ArrayList<Id>());
    zks.getFirstProcessor().processRequest(req);

}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:13,代碼來源:CommitProcessorTest.java

示例5: testCreateEphemeral

/**
 * When we create ephemeral node, we need to check against global
 * session, so the leader never accept request from an expired session
 * (that we no longer track)
 *
 * This is not the same as SessionInvalidationTest since session
 * is not in closing state
 */
public void testCreateEphemeral(boolean localSessionEnabled) throws Exception {
    if (localSessionEnabled) {
        qu.enableLocalSession(true);
    }
    qu.startAll();
    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));

    CreateRequest createRequest = new CreateRequest("/impossible",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long fakeSessionId = (sid << 56) + 1;

    LOG.info("Fake session Id: " + Long.toHexString(fakeSessionId));

    Request request = new Request(null, fakeSessionId, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/impossible", null);
    Assert.assertEquals("Node from fake session get created", null, stat);

}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:45,代碼來源:LeaderSessionTrackerTest.java

示例6: testCreatePersistent

/**
 * When local session is enabled, leader will allow persistent node
 * to be create for unknown session
 */
@Test
public void testCreatePersistent() throws Exception {
    qu.enableLocalSession(true);
    qu.startAll();

    QuorumPeer leader = qu.getLeaderQuorumPeer();

    ZooKeeper zk = ClientBase.createZKClient(qu.getConnectString(leader));

    CreateRequest createRequest = new CreateRequest("/success",
            new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT.toFlag());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);
    createRequest.serialize(boa, "request");
    ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray());

    // Mimic sessionId generated by follower's local session tracker
    long sid = qu.getFollowerQuorumPeers().get(0).getActiveServer()
            .getServerId();
    long locallSession = (sid << 56) + 1;

    LOG.info("Local session Id: " + Long.toHexString(locallSession));

    Request request = new Request(null, locallSession, 0, OpCode.create,
            bb, new ArrayList<Id>());

    // Submit request directly to leader
    leader.getActiveServer().submitRequest(request);

    // Make sure that previous request is finished
    zk.create("/ok", new byte[0], Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);

    Stat stat = zk.exists("/success", null);
    Assert.assertTrue("Request from local sesson failed", stat != null);

}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:41,代碼來源:LeaderSessionTrackerTest.java

示例7: createACL

public static ArrayList<ACL> createACL(ZooKeeperWatcher zkw, String node,
  boolean isSecureZooKeeper) {
  if (!node.startsWith(zkw.baseZNode)) {
    return Ids.OPEN_ACL_UNSAFE;
  }
  if (isSecureZooKeeper) {
    ArrayList<ACL> acls = new ArrayList<ACL>();
    // add permission to hbase supper user
    String[] superUsers = zkw.getConfiguration().getStrings(Superusers.SUPERUSER_CONF_KEY);
    if (superUsers != null) {
      List<String> groups = new ArrayList<String>();
      for (String user : superUsers) {
        if (user.startsWith(AuthUtil.GROUP_PREFIX)) {
          // TODO: Set node ACL for groups when ZK supports this feature
          groups.add(user);
        } else {
          acls.add(new ACL(Perms.ALL, new Id("auth", user)));
        }
      }
      if (!groups.isEmpty()) {
        LOG.warn("Znode ACL setting for group " + groups
            + " is skipped, Zookeeper doesn't support this feature presently.");
      }
    }
    // Certain znodes are accessed directly by the client,
    // so they must be readable by non-authenticated clients
    if (zkw.isClientReadable(node)) {
      acls.addAll(Ids.CREATOR_ALL_ACL);
      acls.addAll(Ids.READ_ACL_UNSAFE);
    } else {
      acls.addAll(Ids.CREATOR_ALL_ACL);
    }
    return acls;
  } else {
    return Ids.OPEN_ACL_UNSAFE;
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:37,代碼來源:ZKUtil.java

示例8: testCreateAfterCloseShouldFail

/**
 * Test solution for ZOOKEEPER-1208. Verify that operations are not
 * accepted after a close session.
 * 
 * We're using our own marshalling here in order to force an operation
 * after the session is closed (ZooKeeper.class will not allow this). Also
 * by filling the pipe with operations it increases the likelyhood that
 * the server will process the create before FinalRequestProcessor
 * removes the session from the tracker.
 */
@Test
public void testCreateAfterCloseShouldFail() throws Exception {
    for (int i = 0; i < 10; i++) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BinaryOutputArchive boa = BinaryOutputArchive.getArchive(baos);

        // open a connection
        boa.writeInt(44, "len");
        ConnectRequest conReq = new ConnectRequest(0, 0, 30000, 0, new byte[16]);
        conReq.serialize(boa, "connect");

        // close connection
        boa.writeInt(8, "len");
        RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.closeSession);
        h.serialize(boa, "header");

        // create ephemeral znode
        boa.writeInt(52, "len"); // We'll fill this in later
        RequestHeader header = new RequestHeader(2, OpCode.create);
        header.serialize(boa, "header");
        CreateRequest createReq = new CreateRequest("/foo" + i, new byte[0],
                Ids.OPEN_ACL_UNSAFE, 1);
        createReq.serialize(boa, "request");
        baos.close();
        
        System.out.println("Length:" + baos.toByteArray().length);
        
        String hp[] = hostPort.split(":");
        Socket sock = new Socket(hp[0], Integer.parseInt(hp[1]));
        InputStream resultStream = null;
        try {
            OutputStream outstream = sock.getOutputStream();
            byte[] data = baos.toByteArray();
            outstream.write(data);
            outstream.flush();
            
            resultStream = sock.getInputStream();
            byte[] b = new byte[10000];
            int len;
            while ((len = resultStream.read(b)) >= 0) {
                // got results
                System.out.println("gotlen:" + len);
            }
        } finally {
            if (resultStream != null) {
                resultStream.close();
            }
            sock.close();
        }
    }
    
    ZooKeeper zk = createClient();
    Assert.assertEquals(1, zk.getChildren("/", false).size());

    zk.close();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:66,代碼來源:SessionInvalidationTest.java


注:本文中的org.apache.zookeeper.ZooDefs.Ids.OPEN_ACL_UNSAFE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。