Return-Path: X-Original-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-accumulo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE44F9170 for ; Wed, 14 Dec 2011 20:26:55 +0000 (UTC) Received: (qmail 58082 invoked by uid 500); 14 Dec 2011 20:26:55 -0000 Delivered-To: apmail-incubator-accumulo-commits-archive@incubator.apache.org Received: (qmail 58059 invoked by uid 500); 14 Dec 2011 20:26:55 -0000 Mailing-List: contact accumulo-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: accumulo-dev@incubator.apache.org Delivered-To: mailing list accumulo-commits@incubator.apache.org Received: (qmail 58052 invoked by uid 99); 14 Dec 2011 20:26:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2011 20:26:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Dec 2011 20:26:53 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D1AD0238897F; Wed, 14 Dec 2011 20:26:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1214447 - in /incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client: admin/ impl/ mock/ Date: Wed, 14 Dec 2011 20:26:32 -0000 To: accumulo-commits@incubator.apache.org From: billie@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111214202632.D1AD0238897F@eris.apache.org> Author: billie Date: Wed Dec 14 20:26:32 2011 New Revision: 1214447 URL: http://svn.apache.org/viewvc?rev=1214447&view=rev Log: ACCUMULO-216 extracted interface from InstanceOperations, implemented MockInstanceOperations Added: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java - copied, changed from r1212505, incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java (with props) Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java?rev=1214447&r1=1214446&r2=1214447&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java Wed Dec 14 20:26:32 2011 @@ -1,4 +1,4 @@ -/* +/** * 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. @@ -16,49 +16,16 @@ */ package org.apache.accumulo.core.client.admin; -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.client.TableNotFoundException; -import org.apache.accumulo.core.client.impl.ClientExec; -import org.apache.accumulo.core.client.impl.ClientExecReturn; -import org.apache.accumulo.core.client.impl.MasterClient; -import org.apache.accumulo.core.client.impl.ServerClient; -import org.apache.accumulo.core.client.impl.thrift.ClientService; -import org.apache.accumulo.core.client.impl.thrift.ConfigurationType; -import org.apache.accumulo.core.master.thrift.MasterClientService; -import org.apache.accumulo.core.security.thrift.AuthInfo; -import org.apache.accumulo.core.tabletserver.thrift.TabletClientService; -import org.apache.accumulo.core.tabletserver.thrift.TabletClientService.Iface; -import org.apache.accumulo.core.util.ArgumentChecker; -import org.apache.accumulo.core.util.ThriftUtil; -import org.apache.accumulo.core.zookeeper.ZooCache; -import org.apache.accumulo.core.zookeeper.ZooUtil; /** - * Provides a class for administering the accumulo instance + * */ -public class InstanceOperations { - private Instance instance; - private AuthInfo credentials; - - /** - * @param instance - * the connection information for this instance - * @param credentials - * the username/password for this connection - */ - public InstanceOperations(Instance instance, AuthInfo credentials) { - ArgumentChecker.notNull(instance, credentials); - this.instance = instance; - this.credentials = credentials; - } +public interface InstanceOperations { /** * Sets an instance property in zookeeper. Tablet servers will pull this setting and override the equivalent setting in accumulo-site.xml @@ -72,15 +39,7 @@ public class InstanceOperations { * @throws AccumuloSecurityException * if the user does not have permission */ - public void setProperty(final String property, final String value) throws AccumuloException, AccumuloSecurityException { - ArgumentChecker.notNull(property, value); - MasterClient.execute(instance, new ClientExec() { - @Override - public void execute(MasterClientService.Iface client) throws Exception { - client.setSystemProperty(null, credentials, property, value); - } - }); - } + public void setProperty(final String property, final String value) throws AccumuloException, AccumuloSecurityException; /** * Removes a instance property from zookeeper @@ -94,33 +53,11 @@ public class InstanceOperations { * @throws AccumuloSecurityException * if the user does not have permission */ - public void removeProperty(final String property) throws AccumuloException, AccumuloSecurityException { - ArgumentChecker.notNull(property); - MasterClient.execute(instance, new ClientExec() { - @Override - public void execute(MasterClientService.Iface client) throws Exception { - client.removeSystemProperty(null, credentials, property); - } - }); - } - - public Map getSystemConfiguration() throws AccumuloException, AccumuloSecurityException { - return ServerClient.execute(instance, new ClientExecReturn,ClientService.Iface>() { - @Override - public Map execute(ClientService.Iface client) throws Exception { - return client.getConfiguration(ConfigurationType.CURRENT); - } - }); - } - - public Map getSiteConfiguration() throws AccumuloException, AccumuloSecurityException { - return ServerClient.execute(instance, new ClientExecReturn,ClientService.Iface>() { - @Override - public Map execute(ClientService.Iface client) throws Exception { - return client.getConfiguration(ConfigurationType.SITE); - } - }); - } + public void removeProperty(final String property) throws AccumuloException, AccumuloSecurityException; + + public Map getSystemConfiguration() throws AccumuloException, AccumuloSecurityException; + + public Map getSiteConfiguration() throws AccumuloException, AccumuloSecurityException; /** * List the currently active tablet servers participating in the accumulo instance @@ -128,23 +65,7 @@ public class InstanceOperations { * @return */ - public List getTabletServers() { - ZooCache cache = ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()); - String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS; - List results = new ArrayList(); - for (String candidate : cache.getChildren(path)) { - List children = cache.getChildren(path + "/" + candidate); - if (children != null && children.size() > 0) { - List copy = new ArrayList(children); - Collections.sort(copy); - byte[] data = cache.get(path + "/" + candidate + "/" + copy.get(0)); - if (data != null && !"master".equals(new String(data))) { - results.add(candidate); - } - } - } - return results; - } + public List getTabletServers(); /** * List the active scans on tablet server. The tablet server address should be of the form : @@ -155,24 +76,7 @@ public class InstanceOperations { * @throws AccumuloSecurityException */ - public List getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException { - List tas = ThriftUtil.execute(tserver, instance.getConfiguration(), - new ClientExecReturn,TabletClientService.Iface>() { - @Override - public List execute(Iface client) throws Exception { - return client.getActiveScans(null, credentials); - } - }); - List as = new ArrayList(); - for (org.apache.accumulo.core.tabletserver.thrift.ActiveScan activeScan : tas) { - try { - as.add(new ActiveScan(instance, activeScan)); - } catch (TableNotFoundException e) { - throw new AccumuloException(e); - } - } - return as; - } + public List getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException; /** * Test to see if the instance can load the given class as the given type. @@ -182,12 +86,6 @@ public class InstanceOperations { * @return * @throws AccumuloException */ - public boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException { - return ServerClient.execute(instance, new ClientExecReturn() { - @Override - public Boolean execute(ClientService.Iface client) throws Exception { - return client.checkClass(null, className, asTypeName); - } - }); - } + public boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException; + } Copied: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java (from r1212505, incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java) URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java?p2=incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java&p1=incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java&r1=1212505&r2=1214447&rev=1214447&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperations.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/admin/InstanceOperationsImpl.java Wed Dec 14 20:26:32 2011 @@ -44,7 +44,7 @@ import org.apache.accumulo.core.zookeepe /** * Provides a class for administering the accumulo instance */ -public class InstanceOperations { +public class InstanceOperationsImpl implements InstanceOperations { private Instance instance; private AuthInfo credentials; @@ -54,24 +54,16 @@ public class InstanceOperations { * @param credentials * the username/password for this connection */ - public InstanceOperations(Instance instance, AuthInfo credentials) { + public InstanceOperationsImpl(Instance instance, AuthInfo credentials) { ArgumentChecker.notNull(instance, credentials); this.instance = instance; this.credentials = credentials; } - /** - * Sets an instance property in zookeeper. Tablet servers will pull this setting and override the equivalent setting in accumulo-site.xml - * - * @param property - * the name of a per-table property - * @param value - * the value to set a per-table property to - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#setProperty(java.lang.String, java.lang.String) */ + @Override public void setProperty(final String property, final String value) throws AccumuloException, AccumuloSecurityException { ArgumentChecker.notNull(property, value); MasterClient.execute(instance, new ClientExec() { @@ -82,18 +74,10 @@ public class InstanceOperations { }); } - /** - * Removes a instance property from zookeeper - * - * @param tableName - * the name of the table - * @param property - * the name of a per-table property - * @throws AccumuloException - * if a general error occurs - * @throws AccumuloSecurityException - * if the user does not have permission + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#removeProperty(java.lang.String) */ + @Override public void removeProperty(final String property) throws AccumuloException, AccumuloSecurityException { ArgumentChecker.notNull(property); MasterClient.execute(instance, new ClientExec() { @@ -104,6 +88,10 @@ public class InstanceOperations { }); } + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSystemConfiguration() + */ + @Override public Map getSystemConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(instance, new ClientExecReturn,ClientService.Iface>() { @Override @@ -113,6 +101,10 @@ public class InstanceOperations { }); } + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSiteConfiguration() + */ + @Override public Map getSiteConfiguration() throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(instance, new ClientExecReturn,ClientService.Iface>() { @Override @@ -122,12 +114,11 @@ public class InstanceOperations { }); } - /** - * List the currently active tablet servers participating in the accumulo instance - * - * @return + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getTabletServers() */ + @Override public List getTabletServers() { ZooCache cache = ZooCache.getInstance(instance.getZooKeepers(), instance.getZooKeepersSessionTimeOut()); String path = ZooUtil.getRoot(instance) + Constants.ZTSERVERS; @@ -146,15 +137,11 @@ public class InstanceOperations { return results; } - /** - * List the active scans on tablet server. The tablet server address should be of the form : - * - * @param tserver - * @return - * @throws AccumuloException - * @throws AccumuloSecurityException + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getActiveScans(java.lang.String) */ + @Override public List getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException { List tas = ThriftUtil.execute(tserver, instance.getConfiguration(), new ClientExecReturn,TabletClientService.Iface>() { @@ -174,14 +161,10 @@ public class InstanceOperations { return as; } - /** - * Test to see if the instance can load the given class as the given type. - * - * @param className - * @param asTypeName - * @return - * @throws AccumuloException + /* (non-Javadoc) + * @see org.apache.accumulo.core.client.admin.InstanceOperations#testClassLoad(java.lang.String, java.lang.String) */ + @Override public boolean testClassLoad(final String className, final String asTypeName) throws AccumuloException, AccumuloSecurityException { return ServerClient.execute(instance, new ClientExecReturn() { @Override Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java?rev=1214447&r1=1214446&r2=1214447&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/impl/ConnectorImpl.java Wed Dec 14 20:26:32 2011 @@ -30,6 +30,7 @@ import org.apache.accumulo.core.client.S import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.TableOfflineException; import org.apache.accumulo.core.client.admin.InstanceOperations; +import org.apache.accumulo.core.client.admin.InstanceOperationsImpl; import org.apache.accumulo.core.client.admin.SecurityOperations; import org.apache.accumulo.core.client.admin.SecurityOperationsImpl; import org.apache.accumulo.core.client.admin.TableOperations; @@ -165,7 +166,7 @@ public class ConnectorImpl extends Conne @Override public synchronized InstanceOperations instanceOperations() { if (instanceops == null) - instanceops = new InstanceOperations(instance, credentials); + instanceops = new InstanceOperationsImpl(instance, credentials); return instanceops; } Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java?rev=1214447&r1=1214446&r2=1214447&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockAccumulo.java Wed Dec 14 20:26:32 2011 @@ -47,6 +47,10 @@ public class MockAccumulo { systemProperties.put(key, value); } + String removeProperty(String key) { + return systemProperties.remove(key); + } + void createTable(String user, String table) { createTable(user, table, true, TimeType.MILLIS); } Modified: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java?rev=1214447&r1=1214446&r2=1214447&view=diff ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java (original) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java Wed Dec 14 20:26:32 2011 @@ -95,7 +95,7 @@ public class MockConnector extends Conne @Override public InstanceOperations instanceOperations() { - return null; + return new MockInstanceOperations(acu); } } Added: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java URL: http://svn.apache.org/viewvc/incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java?rev=1214447&view=auto ============================================================================== --- incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java (added) +++ incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java Wed Dec 14 20:26:32 2011 @@ -0,0 +1,117 @@ +/** + * 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.mock; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.admin.ActiveScan; +import org.apache.accumulo.core.client.admin.InstanceOperations; +import org.apache.accumulo.start.classloader.AccumuloClassLoader; + +/** + * + */ +public class MockInstanceOperations implements InstanceOperations { + MockAccumulo acu; + + /** + * @param acu + */ + public MockInstanceOperations(MockAccumulo acu) { + this.acu = acu; + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#setProperty(java.lang.String, java.lang.String) + */ + @Override + public void setProperty(String property, String value) throws AccumuloException, AccumuloSecurityException { + acu.setProperty(property, value); + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#removeProperty(java.lang.String) + */ + @Override + public void removeProperty(String property) throws AccumuloException, AccumuloSecurityException { + acu.removeProperty(property); + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSystemConfiguration() + */ + @Override + public Map getSystemConfiguration() throws AccumuloException, AccumuloSecurityException { + return acu.systemProperties; + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getSiteConfiguration() + */ + @Override + public Map getSiteConfiguration() throws AccumuloException, AccumuloSecurityException { + return acu.systemProperties; + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getTabletServers() + */ + @Override + public List getTabletServers() { + return new ArrayList(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#getActiveScans(java.lang.String) + */ + @Override + public List getActiveScans(String tserver) throws AccumuloException, AccumuloSecurityException { + return new ArrayList(); + } + + /* + * (non-Javadoc) + * + * @see org.apache.accumulo.core.client.admin.InstanceOperations#testClassLoad(java.lang.String, java.lang.String) + */ + @Override + public boolean testClassLoad(String className, String asTypeName) throws AccumuloException, AccumuloSecurityException { + try { + AccumuloClassLoader.loadClass(className, Class.forName(asTypeName)); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + return false; + } + return true; + } +} Propchange: incubator/accumulo/branches/1.4/src/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstanceOperations.java ------------------------------------------------------------------------------ svn:eol-style = native