You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by bu...@apache.org on 2014/04/26 01:12:45 UTC
[16/17] git commit: ACCUMULO-2726 cleanup for master's branch.
ACCUMULO-2726 cleanup for master's branch.
* remove things we deprecated in 1.6.0 related to this ticket.
* make sure changes in the implementations in master are reflected in the new implementation locations
* make names in Mock consistent
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f277fea9
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f277fea9
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f277fea9
Branch: refs/heads/master
Commit: f277fea98588b5e9f97d237a6479b9dfa08a37a1
Parents: 592c8b0
Author: Sean Busbey <bu...@cloudera.com>
Authored: Fri Apr 25 12:45:22 2014 -0500
Committer: Sean Busbey <bu...@cloudera.com>
Committed: Fri Apr 25 16:08:24 2014 -0500
----------------------------------------------------------------------
.../client/admin/InstanceOperationsImpl.java | 216 ---
.../client/admin/SecurityOperationsImpl.java | 291 ----
.../client/admin/TableOperationsHelper.java | 208 ---
.../core/client/admin/TableOperationsImpl.java | 1581 ------------------
.../core/client/impl/ConnectorImpl.java | 4 -
.../client/impl/InstanceOperationsImpl.java | 18 +-
.../client/impl/SecurityOperationsImpl.java | 54 +-
.../core/client/impl/TableOperationsHelper.java | 14 +-
.../core/client/impl/TableOperationsImpl.java | 99 +-
.../core/client/mock/MockConnector.java | 6 +-
.../client/mock/MockInstanceOperations.java | 73 +-
.../client/mock/MockInstanceOperationsImpl.java | 87 -
.../client/mock/MockSecurityOperations.java | 209 ++-
.../client/mock/MockSecurityOperationsImpl.java | 225 ---
.../core/client/mock/MockTableOperations.java | 431 ++++-
.../client/mock/MockTableOperationsImpl.java | 447 -----
.../core/client/mock/MockTabletLocator.java | 53 -
.../client/admin/TableOperationsHelperTest.java | 223 ---
.../apache/accumulo/shell/mock/MockShell.java | 39 -
19 files changed, 813 insertions(+), 3465 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java
deleted file mode 100644
index d3a6285..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.client.admin;
-
-import static com.google.common.base.Preconditions.checkArgument;
-
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
-import org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Client;
-import org.apache.accumulo.core.util.AddressUtil;
-import org.apache.accumulo.core.util.ThriftUtil;
-import org.apache.accumulo.core.zookeeper.ZooUtil;
-import org.apache.accumulo.fate.zookeeper.ZooCache;
-import org.apache.accumulo.trace.instrument.Tracer;
-import org.apache.thrift.TException;
-import org.apache.thrift.transport.TTransport;
-import org.apache.thrift.transport.TTransportException;
-import org.apache.accumulo.core.security.thrift.TCredentials;
-
-/**
- * Provides a class for administering the accumulo instance
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class InstanceOperationsImpl extends org.apache.accumulo.core.client.impl.InstanceOperationsImpl {
-
- /**
- * @param instance
- * the connection information for this instance
- * @param credentials
- * the Credential, containing principal and Authentication Token
- */
- public InstanceOperationsImpl(Instance instance, Credentials credentials) {
- checkArgument(instance != null, "instance is null");
- checkArgument(credentials != null, "credentials is null");
- this.instance = instance;
- this.credentials = credentials;
- }
-
- @Override
- public void setProperty(final String property, final String value) throws AccumuloException, AccumuloSecurityException {
- checkArgument(property != null, "property is null");
- checkArgument(value != null, "value is null");
- MasterClient.execute(instance, new ClientExec<MasterClientService.Client>() {
- @Override
- public void execute(MasterClientService.Client client) throws Exception {
- client.setSystemProperty(Tracer.traceInfo(), credentials.toThrift(instance), property, value);
- }
- });
- }
-
- @Override
- public void removeProperty(final String property) throws AccumuloException, AccumuloSecurityException {
- checkArgument(property != null, "property is null");
- MasterClient.execute(instance, new ClientExec<MasterClientService.Client>() {
- @Override
- public void execute(MasterClientService.Client client) throws Exception {
- client.removeSystemProperty(Tracer.traceInfo(), credentials.toThrift(instance), property);
- }
- });
- }
-
- @Override
- public Map<String,String> getSystemConfiguration() throws AccumuloException, AccumuloSecurityException {
- return ServerClient.execute(instance, new ClientExecReturn<Map<String,String>,ClientService.Client>() {
- @Override
- public Map<String,String> execute(ClientService.Client client) throws Exception {
- return client.getConfiguration(Tracer.traceInfo(), credentials.toThrift(instance), ConfigurationType.CURRENT);
- }
- });
- }
-
- @Override
- public Map<String,String> getSiteConfiguration() throws AccumuloException, AccumuloSecurityException {
- return ServerClient.execute(instance, new ClientExecReturn<Map<String,String>,ClientService.Client>() {
- @Override
- public Map<String,String> execute(ClientService.Client client) throws Exception {
- return client.getConfiguration(Tracer.traceInfo(), credentials.toThrift(instance), ConfigurationType.SITE);
- }
- });
- }
-
- @Override
- public List<String> getTabletServers() {
- ZooCache cache = ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut());
- String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS;
- List<String> results = new ArrayList<String>();
- for (String candidate : cache.getChildren(path)) {
- List<String> children = cache.getChildren(path + "/" + candidate);
- if (children != null && children.size() > 0) {
- List<String> copy = new ArrayList<String>(children);
- Collections.sort(copy);
- byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0));
- if (data != null && !"master".equals(new String(data, StandardCharsets.UTF_8))) {
- results.add(candidate);
- }
- }
- }
- return results;
- }
-
- @Override
- public List<ActiveScan> getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException {
- Client client = null;
- try {
- client = ThriftUtil.getTServerClient(tserver, ServerConfigurationUtil.getConfiguration(instance));
-
- List<ActiveScan> as = new ArrayList<ActiveScan>();
- for (org.apache.accumulo.core.tabletserver.thrift.ActiveScan activeScan : client.getActiveScans(Tracer.traceInfo(), credentials.toThrift(instance))) {
- try {
- as.add(new ActiveScan(instance, activeScan));
- } catch (TableNotFoundException e) {
- throw new AccumuloException(e);
- }
- }
- return as;
- } catch (TTransportException e) {
- throw new AccumuloException(e);
- } catch (ThriftSecurityException e) {
- throw new AccumuloSecurityException(e.user, e.code, e);
- } catch (TException e) {
- throw new AccumuloException(e);
- } finally {
- if (client != null)
- ThriftUtil.returnClient(client);
- }
- }
-
- @Override
- public boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException {
- return ServerClient.execute(instance, new ClientExecReturn<Boolean,ClientService.Client>() {
- @Override
- public Boolean execute(ClientService.Client client) throws Exception {
- return client.checkClass(Tracer.traceInfo(), credentials.toThrift(instance), className, asTypeName);
- }
- });
- }
-
- @Override
- public List<ActiveCompaction> getActiveCompactions(String tserver) throws AccumuloException, AccumuloSecurityException {
- Client client = null;
- try {
- client = ThriftUtil.getTServerClient(tserver, ServerConfigurationUtil.getConfiguration(instance));
-
- List<ActiveCompaction> as = new ArrayList<ActiveCompaction>();
- for (org.apache.accumulo.core.tabletserver.thrift.ActiveCompaction activeCompaction : client.getActiveCompactions(Tracer.traceInfo(),
- credentials.toThrift(instance))) {
- as.add(new ActiveCompaction(instance, activeCompaction));
- }
- return as;
- } catch (TTransportException e) {
- throw new AccumuloException(e);
- } catch (ThriftSecurityException e) {
- throw new AccumuloSecurityException(e.user, e.code, e);
- } catch (TException e) {
- throw new AccumuloException(e);
- } finally {
- if (client != null)
- ThriftUtil.returnClient(client);
- }
- }
-
- @Override
- public void ping(String tserver) throws AccumuloException {
- TTransport transport = null;
- try {
- transport = ThriftUtil.createTransport(AddressUtil.parseAddress(tserver, false), ServerConfigurationUtil.getConfiguration(instance));
- TabletClientService.Client client = ThriftUtil.createClient(new TabletClientService.Client.Factory(), transport);
- client.getTabletServerStatus(Tracer.traceInfo(), credentials.toThrift(instance));
- } catch (TTransportException e) {
- throw new AccumuloException(e);
- } catch (ThriftSecurityException e) {
- throw new AccumuloException(e);
- } catch (TException e) {
- throw new AccumuloException(e);
- } finally {
- if (transport != null) {
- transport.close();
- }
- }
- }
-
- /**
- * @param instance
- * the connection information for this instance
- * @param credentials
- * the Credential, containing principal and Authentication Token
- */
- public InstanceOperationsImpl(Instance instance, TCredentials credentials) {
- this(instance, Credentials.fromThrift(credentials));
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperationsImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperationsImpl.java
deleted file mode 100644
index 3d647a0..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/SecurityOperationsImpl.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.client.admin;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import java.nio.ByteBuffer;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.security.Credentials;
-import org.apache.accumulo.core.security.NamespacePermission;
-import org.apache.accumulo.core.security.SystemPermission;
-import org.apache.accumulo.core.security.TablePermission;
-import org.apache.accumulo.core.util.ByteBufferUtil;
-import org.apache.accumulo.trace.instrument.Tracer;
-import org.apache.accumulo.core.security.thrift.TCredentials;
-
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public class SecurityOperationsImpl extends org.apache.accumulo.core.client.impl.SecurityOperationsImpl {
-
- public SecurityOperationsImpl(Instance instance, Credentials credentials) {
- checkArgument(instance != null, "instance is null");
- checkArgument(credentials != null, "credentials is null");
- this.instance = instance;
- this.credentials = credentials;
- }
-
- @Deprecated
- @Override
- public void createUser(String user, byte[] password, final Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
- createLocalUser(user, new PasswordToken(password));
- changeUserAuthorizations(user, authorizations);
- }
-
- @Override
- public void createLocalUser(final String principal, final PasswordToken password) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(password != null, "password is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.createLocalUser(Tracer.traceInfo(), credentials.toThrift(instance), principal, ByteBuffer.wrap(password.getPassword()));
- }
- });
- }
-
- @Deprecated
- @Override
- public void dropUser(final String user) throws AccumuloException, AccumuloSecurityException {
- dropLocalUser(user);
- }
-
- @Override
- public void dropLocalUser(final String principal) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.dropLocalUser(Tracer.traceInfo(), credentials.toThrift(instance), principal);
- }
- });
- }
-
- @Deprecated
- @Override
- public boolean authenticateUser(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
- return authenticateUser(user, new PasswordToken(password));
- }
-
- @Override
- public boolean authenticateUser(final String principal, final AuthenticationToken token) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(token != null, "token is null");
- final Credentials toAuth = new Credentials(principal, token);
- return execute(new ClientExecReturn<Boolean,ClientService.Client>() {
- @Override
- public Boolean execute(ClientService.Client client) throws Exception {
- return client.authenticateUser(Tracer.traceInfo(), credentials.toThrift(instance), toAuth.toThrift(instance));
- }
- });
- }
-
- @Override
- @Deprecated
- public void changeUserPassword(String user, byte[] password) throws AccumuloException, AccumuloSecurityException {
- changeLocalUserPassword(user, new PasswordToken(password));
- }
-
- @Override
- public void changeLocalUserPassword(final String principal, final PasswordToken token) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(token != null, "token is null");
- final Credentials toChange = new Credentials(principal, token);
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.changeLocalUserPassword(Tracer.traceInfo(), credentials.toThrift(instance), principal, ByteBuffer.wrap(token.getPassword()));
- }
- });
- if (this.credentials.getPrincipal().equals(principal)) {
- this.credentials = toChange;
- }
- }
-
- @Override
- public void changeUserAuthorizations(final String principal, final Authorizations authorizations) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(authorizations != null, "authorizations is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.changeAuthorizations(Tracer.traceInfo(), credentials.toThrift(instance), principal,
- ByteBufferUtil.toByteBuffers(authorizations.getAuthorizations()));
- }
- });
- }
-
- @Override
- public Authorizations getUserAuthorizations(final String principal) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- return execute(new ClientExecReturn<Authorizations,ClientService.Client>() {
- @Override
- public Authorizations execute(ClientService.Client client) throws Exception {
- return new Authorizations(client.getUserAuthorizations(Tracer.traceInfo(), credentials.toThrift(instance), principal));
- }
- });
- }
-
- @Override
- public boolean hasSystemPermission(final String principal, final SystemPermission perm) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(perm != null, "perm is null");
- return execute(new ClientExecReturn<Boolean,ClientService.Client>() {
- @Override
- public Boolean execute(ClientService.Client client) throws Exception {
- return client.hasSystemPermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, perm.getId());
- }
- });
- }
-
- @Override
- public boolean hasTablePermission(final String principal, final String table, final TablePermission perm) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(table != null, "table is null");
- checkArgument(perm != null, "perm is null");
- try {
- return execute(new ClientExecReturn<Boolean,ClientService.Client>() {
- @Override
- public Boolean execute(ClientService.Client client) throws Exception {
- return client.hasTablePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, table, perm.getId());
- }
- });
- } catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() == org.apache.accumulo.core.client.security.SecurityErrorCode.NAMESPACE_DOESNT_EXIST)
- throw new AccumuloSecurityException(null, SecurityErrorCode.TABLE_DOESNT_EXIST, e);
- else
- throw e;
- }
- }
-
- @Override
- public boolean hasNamespacePermission(final String principal, final String namespace, final NamespacePermission permission) throws AccumuloException,
- AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(namespace != null, "namespace is null");
- checkArgument(permission != null, "permission is null");
- return execute(new ClientExecReturn<Boolean,ClientService.Client>() {
- @Override
- public Boolean execute(ClientService.Client client) throws Exception {
- return client.hasNamespacePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, namespace, permission.getId());
- }
- });
- }
-
- @Override
- public void grantSystemPermission(final String principal, final SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(permission != null, "permission is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.grantSystemPermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, permission.getId());
- }
- });
- }
-
- @Override
- public void grantTablePermission(final String principal, final String table, final TablePermission permission) throws AccumuloException,
- AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(table != null, "table is null");
- checkArgument(permission != null, "permission is null");
- try {
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.grantTablePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, table, permission.getId());
- }
- });
- } catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() == org.apache.accumulo.core.client.security.SecurityErrorCode.NAMESPACE_DOESNT_EXIST)
- throw new AccumuloSecurityException(null, SecurityErrorCode.TABLE_DOESNT_EXIST, e);
- else
- throw e;
- }
- }
-
- @Override
- public void grantNamespacePermission(final String principal, final String namespace, final NamespacePermission permission) throws AccumuloException,
- AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(namespace != null, "namespace is null");
- checkArgument(permission != null, "permission is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.grantNamespacePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, namespace, permission.getId());
- }
- });
- }
-
- @Override
- public void revokeSystemPermission(final String principal, final SystemPermission permission) throws AccumuloException, AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(permission != null, "permission is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.revokeSystemPermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, permission.getId());
- }
- });
- }
-
- @Override
- public void revokeTablePermission(final String principal, final String table, final TablePermission permission) throws AccumuloException,
- AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(table != null, "table is null");
- checkArgument(permission != null, "permission is null");
- try {
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.revokeTablePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, table, permission.getId());
- }
- });
- } catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() == org.apache.accumulo.core.client.security.SecurityErrorCode.NAMESPACE_DOESNT_EXIST)
- throw new AccumuloSecurityException(null, SecurityErrorCode.TABLE_DOESNT_EXIST, e);
- else
- throw e;
- }
- }
-
- @Override
- public void revokeNamespacePermission(final String principal, final String namespace, final NamespacePermission permission) throws AccumuloException,
- AccumuloSecurityException {
- checkArgument(principal != null, "principal is null");
- checkArgument(namespace != null, "namespace is null");
- checkArgument(permission != null, "permission is null");
- execute(new ClientExec<ClientService.Client>() {
- @Override
- public void execute(ClientService.Client client) throws Exception {
- client.revokeNamespacePermission(Tracer.traceInfo(), credentials.toThrift(instance), principal, namespace, permission.getId());
- }
- });
- }
-
- public SecurityOperationsImpl(Instance instance, TCredentials credentials) {
- this(instance, Credentials.fromThrift(credentials));
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/f277fea9/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java b/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
deleted file mode 100644
index 9d0d770..0000000
--- a/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsHelper.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.accumulo.core.client.admin;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.TreeMap;
-import java.util.TreeSet;
-
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
-
-/**
- * @deprecated since 1.6.0; not intended for public api and you should not use it.
- */
-@Deprecated
-public abstract class TableOperationsHelper extends org.apache.accumulo.core.client.impl.TableOperationsHelper {
-
- @Override
- public void attachIterator(String tableName, IteratorSetting setting) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
- attachIterator(tableName, setting, EnumSet.allOf(IteratorScope.class));
- }
-
- @Override
- public void attachIterator(String tableName, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException,
- TableNotFoundException {
- checkArgument(tableName != null, "tableName is null");
- checkArgument(setting != null, "setting is null");
- checkArgument(scopes != null, "scopes is null");
- checkIteratorConflicts(tableName, setting, scopes);
- for (IteratorScope scope : scopes) {
- String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), setting.getName());
- for (Entry<String,String> prop : setting.getOptions().entrySet()) {
- this.setProperty(tableName, root + ".opt." + prop.getKey(), prop.getValue());
- }
- this.setProperty(tableName, root, setting.getPriority() + "," + setting.getIteratorClass());
- }
- }
-
- @Override
- public void removeIterator(String tableName, String name, EnumSet<IteratorScope> scopes) throws AccumuloSecurityException, AccumuloException,
- TableNotFoundException {
- Map<String,String> copy = new TreeMap<String,String>();
- for (Entry<String,String> property : this.getProperties(tableName)) {
- copy.put(property.getKey(), property.getValue());
- }
- for (IteratorScope scope : scopes) {
- String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
- for (Entry<String,String> property : copy.entrySet()) {
- if (property.getKey().equals(root) || property.getKey().startsWith(root + ".opt."))
- this.removeProperty(tableName, property.getKey());
- }
- }
- }
-
- @Override
- public IteratorSetting getIteratorSetting(String tableName, String name, IteratorScope scope) throws AccumuloSecurityException, AccumuloException,
- TableNotFoundException {
- checkArgument(tableName != null, "tableName is null");
- checkArgument(name != null, "name is null");
- checkArgument(scope != null, "scope is null");
- int priority = -1;
- String classname = null;
- Map<String,String> settings = new HashMap<String,String>();
-
- String root = String.format("%s%s.%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase(), name);
- String opt = root + ".opt.";
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().equals(root)) {
- String parts[] = property.getValue().split(",");
- if (parts.length != 2) {
- throw new AccumuloException("Bad value for iterator setting: " + property.getValue());
- }
- priority = Integer.parseInt(parts[0]);
- classname = parts[1];
- } else if (property.getKey().startsWith(opt)) {
- settings.put(property.getKey().substring(opt.length()), property.getValue());
- }
- }
- if (priority <= 0 || classname == null) {
- return null;
- }
- return new IteratorSetting(priority, name, classname, settings);
- }
-
- @Override
- public Map<String,EnumSet<IteratorScope>> listIterators(String tableName) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
- Map<String,EnumSet<IteratorScope>> result = new TreeMap<String,EnumSet<IteratorScope>>();
- for (Entry<String,String> property : this.getProperties(tableName)) {
- String name = property.getKey();
- String[] parts = name.split("\\.");
- if (parts.length == 4) {
- if (parts[0].equals("table") && parts[1].equals("iterator")) {
- IteratorScope scope = IteratorScope.valueOf(parts[2]);
- if (!result.containsKey(parts[3]))
- result.put(parts[3], EnumSet.noneOf(IteratorScope.class));
- result.get(parts[3]).add(scope);
- }
- }
- }
- return result;
- }
-
- @Override
- public void checkIteratorConflicts(String tableName, IteratorSetting setting, EnumSet<IteratorScope> scopes) throws AccumuloException, TableNotFoundException {
- checkArgument(tableName != null, "tableName is null");
- checkArgument(setting != null, "setting is null");
- checkArgument(scopes != null, "scopes is null");
- for (IteratorScope scope : scopes) {
- String scopeStr = String.format("%s%s", Property.TABLE_ITERATOR_PREFIX, scope.name().toLowerCase());
- String nameStr = String.format("%s.%s", scopeStr, setting.getName());
- String optStr = String.format("%s.opt.", nameStr);
- Map<String,String> optionConflicts = new TreeMap<String,String>();
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().startsWith(scopeStr)) {
- if (property.getKey().equals(nameStr))
- throw new AccumuloException(new IllegalArgumentException("iterator name conflict for " + setting.getName() + ": " + property.getKey() + "="
- + property.getValue()));
- if (property.getKey().startsWith(optStr))
- optionConflicts.put(property.getKey(), property.getValue());
- if (property.getKey().contains(".opt."))
- continue;
- String parts[] = property.getValue().split(",");
- if (parts.length != 2)
- throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
- try {
- if (Integer.parseInt(parts[0]) == setting.getPriority())
- throw new AccumuloException(new IllegalArgumentException("iterator priority conflict: " + property.getKey() + "=" + property.getValue()));
- } catch (NumberFormatException e) {
- throw new AccumuloException("Bad value for existing iterator setting: " + property.getKey() + "=" + property.getValue());
- }
- }
- }
- if (optionConflicts.size() > 0)
- throw new AccumuloException(new IllegalArgumentException("iterator options conflict for " + setting.getName() + ": " + optionConflicts));
- }
- }
-
- @Override
- public int addConstraint(String tableName, String constraintClassName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
- TreeSet<Integer> constraintNumbers = new TreeSet<Integer>();
- TreeMap<String,Integer> constraintClasses = new TreeMap<String,Integer>();
- int i;
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
- try {
- i = Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()));
- } catch (NumberFormatException e) {
- throw new AccumuloException("Bad key for existing constraint: " + property.toString());
- }
- constraintNumbers.add(i);
- constraintClasses.put(property.getValue(), i);
- }
- }
- i = 1;
- while (constraintNumbers.contains(i))
- i++;
- if (constraintClasses.containsKey(constraintClassName))
- throw new AccumuloException("Constraint " + constraintClassName + " already exists for table " + tableName + " with number "
- + constraintClasses.get(constraintClassName));
- this.setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraintClassName);
- return i;
- }
-
- @Override
- public void removeConstraint(String tableName, int number) throws AccumuloException, AccumuloSecurityException {
- this.removeProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + number);
- }
-
- @Override
- public Map<String,Integer> listConstraints(String tableName) throws AccumuloException, TableNotFoundException {
- Map<String,Integer> constraints = new TreeMap<String,Integer>();
- for (Entry<String,String> property : this.getProperties(tableName)) {
- if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
- if (constraints.containsKey(property.getValue()))
- throw new AccumuloException("Same constraint configured twice: " + property.getKey() + "=" + Property.TABLE_CONSTRAINT_PREFIX
- + constraints.get(property.getValue()) + "=" + property.getKey());
- try {
- constraints.put(property.getValue(), Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length())));
- } catch (NumberFormatException e) {
- throw new AccumuloException("Bad key for existing constraint: " + property.toString());
- }
- }
- }
- return constraints;
- }
-}