Search in sources :

Example 26 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project fabric8 by jboss-fuse.

the class CreateAction method doExecute.

@Override
protected void doExecute(CuratorFramework curator) throws Exception {
    List<ACL> acls = acl == null ? ZooDefs.Ids.OPEN_ACL_UNSAFE : parseACLs(acl);
    CreateMode mode;
    if (ephemeral && sequential) {
        mode = CreateMode.EPHEMERAL_SEQUENTIAL;
    } else if (ephemeral) {
        mode = CreateMode.EPHEMERAL;
    } else if (sequential) {
        mode = CreateMode.PERSISTENT_SEQUENTIAL;
    } else {
        mode = CreateMode.PERSISTENT;
    }
    String nodeData = data;
    if (importUrl) {
        nodeData = loadUrl(new URL(data));
    }
    try {
        CreateBuilder createBuilder = curator.create();
        if (recursive) {
            createBuilder.creatingParentsIfNeeded();
        }
        BackgroundPathAndBytesable<String> create = createBuilder.withMode(mode).withACL(acls);
        if (nodeData == null) {
            create.forPath(path);
        } else {
            create.forPath(path, nodeData.getBytes());
        }
    } catch (KeeperException.NodeExistsException e) {
        if (overwrite) {
            curator.setData().forPath(path, nodeData.getBytes());
        } else {
            throw e;
        }
    }
}
Also used : CreateMode(org.apache.zookeeper.CreateMode) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ACL(org.apache.zookeeper.data.ACL) URL(java.net.URL) KeeperException(org.apache.zookeeper.KeeperException)

Example 27 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project knox by apache.

the class RemoteConfigurationRegistryClientServiceTest method initializeTestClientAndZNodes.

/**
 * Create a ZooKeeper client with SASL digest auth configured, and initialize the test znodes.
 */
private CuratorFramework initializeTestClientAndZNodes(TestingCluster zkCluster, String principal) throws Exception {
    // Create the client for the test cluster
    CuratorFramework setupClient = CuratorFrameworkFactory.builder().connectString(zkCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
    assertNotNull(setupClient);
    setupClient.start();
    List<ACL> acls = new ArrayList<>();
    if (principal != null) {
        acls.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", principal)));
    } else {
        acls.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/descriptors");
    setupClient.create().creatingParentsIfNeeded().withACL(acls).forPath("/knox/config/shared-providers");
    List<ACL> negativeACLs = new ArrayList<>();
    if (principal != null) {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, new Id("sasl", "notyou")));
    } else {
        negativeACLs.add(new ACL(ZooDefs.Perms.ALL, ZooDefs.Ids.ANYONE_ID_UNSAFE));
    }
    setupClient.create().creatingParentsIfNeeded().withACL(negativeACLs).forPath("/someotherconfig");
    return setupClient;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ArrayList(java.util.ArrayList) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 28 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project phoenix by apache.

the class LoadBalanceZookeeperConfImpl method getAcls.

@Override
public List<ACL> getAcls() {
    ACL acl = new ACL();
    acl.setId(new Id("digest", getZkLbUserName() + ":" + getZkLbPassword()));
    acl.setPerms(ZooDefs.Perms.READ);
    return Arrays.asList(acl);
}
Also used : ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id)

Example 29 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project atlas by apache.

the class ActiveInstanceState method update.

/**
 * Update state of the active server instance.
 *
 * This method writes this instance's Server Address to a shared node in Zookeeper.
 * This information is used by other passive instances to locate the current active server.
 * @throws Exception
 * @param serverId ID of this server instance
 */
public void update(String serverId) throws AtlasBaseException {
    try {
        CuratorFramework client = curatorFactory.clientInstance();
        HAConfiguration.ZookeeperProperties zookeeperProperties = HAConfiguration.getZookeeperProperties(configuration);
        String atlasServerAddress = HAConfiguration.getBoundAddressForId(configuration, serverId);
        List<ACL> acls = Arrays.asList(new ACL[] { AtlasZookeeperSecurityProperties.parseAcl(zookeeperProperties.getAcl(), ZooDefs.Ids.OPEN_ACL_UNSAFE.get(0)) });
        Stat serverInfo = client.checkExists().forPath(getZnodePath(zookeeperProperties));
        if (serverInfo == null) {
            client.create().withMode(CreateMode.EPHEMERAL).withACL(acls).forPath(getZnodePath(zookeeperProperties));
        }
        client.setData().forPath(getZnodePath(zookeeperProperties), atlasServerAddress.getBytes(Charset.forName("UTF-8")));
    } catch (Exception e) {
        throw new AtlasBaseException(AtlasErrorCode.CURATOR_FRAMEWORK_UPDATE, e, "forPath: getZnodePath");
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Stat(org.apache.zookeeper.data.Stat) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) HAConfiguration(org.apache.atlas.ha.HAConfiguration) ACL(org.apache.zookeeper.data.ACL) AtlasException(org.apache.atlas.AtlasException) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException)

Example 30 with ACL

use of org.apache.flink.shaded.zookeeper3.org.apache.zookeeper.data.ACL in project atlas by apache.

the class ActiveInstanceStateTest method testSharedPathIsCreatedWithRightACLIfNotExists.

@Test
public void testSharedPathIsCreatedWithRightACLIfNotExists() throws Exception {
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_ADDRESS_PREFIX + "id1")).thenReturn(HOST_PORT);
    when(configuration.getString(HAConfiguration.HA_ZOOKEEPER_ACL)).thenReturn("sasl:myclient@EXAMPLE.COM");
    when(configuration.getString(HAConfiguration.ATLAS_SERVER_HA_ZK_ROOT_KEY, HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT)).thenReturn(HAConfiguration.ATLAS_SERVER_ZK_ROOT_DEFAULT);
    when(curatorFactory.clientInstance()).thenReturn(curatorFramework);
    ExistsBuilder existsBuilder = mock(ExistsBuilder.class);
    when(curatorFramework.checkExists()).thenReturn(existsBuilder);
    when(existsBuilder.forPath(getPath())).thenReturn(null);
    CreateBuilder createBuilder = mock(CreateBuilder.class);
    when(curatorFramework.create()).thenReturn(createBuilder);
    when(createBuilder.withMode(CreateMode.EPHEMERAL)).thenReturn(createBuilder);
    ACL expectedAcl = new ACL(ZooDefs.Perms.ALL, new Id("sasl", "myclient@EXAMPLE.COM"));
    when(createBuilder.withACL(Arrays.asList(new ACL[] { expectedAcl }))).thenReturn(createBuilder);
    SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
    when(curatorFramework.setData()).thenReturn(setDataBuilder);
    ActiveInstanceState activeInstanceState = new ActiveInstanceState(configuration, curatorFactory);
    activeInstanceState.update("id1");
    verify(createBuilder).forPath(getPath());
}
Also used : SetDataBuilder(org.apache.curator.framework.api.SetDataBuilder) CreateBuilder(org.apache.curator.framework.api.CreateBuilder) ExistsBuilder(org.apache.curator.framework.api.ExistsBuilder) ACL(org.apache.zookeeper.data.ACL) Id(org.apache.zookeeper.data.Id) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ACL (org.apache.zookeeper.data.ACL)215 Id (org.apache.zookeeper.data.Id)85 ArrayList (java.util.ArrayList)61 Test (org.junit.Test)56 Stat (org.apache.zookeeper.data.Stat)45 KeeperException (org.apache.zookeeper.KeeperException)35 Test (org.testng.annotations.Test)32 CuratorFramework (org.apache.curator.framework.CuratorFramework)20 Test (org.junit.jupiter.api.Test)18 Configuration (org.apache.hadoop.conf.Configuration)17 ZooKeeper (org.apache.zookeeper.ZooKeeper)16 ACLProvider (org.apache.curator.framework.api.ACLProvider)15 List (java.util.List)11 IOException (java.io.IOException)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)8 TestableZooKeeper (org.apache.zookeeper.TestableZooKeeper)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 CreateMode (org.apache.zookeeper.CreateMode)6