http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/PartitionedRegionAttributeTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/PartitionedRegionAttributeTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/PartitionedRegionAttributeTask.java deleted file mode 100644 index bdda7a6..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/PartitionedRegionAttributeTask.java +++ /dev/null @@ -1,205 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.admin.AdminDistributedSystem; -import com.gemstone.gemfire.admin.AdminDistributedSystemFactory; -import com.gemstone.gemfire.admin.AdminException; -import com.gemstone.gemfire.admin.DistributedSystemConfig; -import com.gemstone.gemfire.admin.SystemMember; -import com.gemstone.gemfire.admin.SystemMemberCache; -import com.gemstone.gemfire.admin.SystemMemberRegion; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.PartitionAttributes; -import com.gemstone.gemfire.distributed.DistributedSystem; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; - -public class PartitionedRegionAttributeTask implements CommandTask -{ - private static final long serialVersionUID = 1L; - - private String regionPath; - - public CommandResults runTask(Object userData) - { - CommandResults results = new CommandResults(); - try { - PartitionAttributeInfo pai = getPartitionAttributeInfo(regionPath); - if (pai == null) { - results.setCode(CommandResults.CODE_ERROR); - results.setCodeMessage(regionPath + " is not partitioned regon"); - } - } catch (Exception ex) { - results.setCode(CommandResults.CODE_ERROR); - results.setCodeMessage(ex.getMessage()); - results.setException(ex); - } - return results; - } - - private static PartitionAttributeInfo getPartitionAttributeInfo(String regionPath) throws AdminException - { - Cache cache = CacheFactory.getAnyInstance(); - DistributedSystem ds = cache.getDistributedSystem(); - DistributedSystemConfig config = AdminDistributedSystemFactory.defineDistributedSystem(ds, null); - AdminDistributedSystem adminSystem = AdminDistributedSystemFactory.getDistributedSystem(config); - try { - adminSystem.connect(); - } catch (Exception ex) { - // already connected - } - SystemMember[] members = adminSystem.getSystemMemberApplications(); - - boolean isPR = true; - int redundantCopies = 0; - int totalNumBuckets = 0; - - PartitionAttributeInfo pai = new PartitionAttributeInfo(); - - for (int i = 0; i < members.length; i++) { - SystemMemberCache scache = members[i].getCache(); - - if (scache != null) { - SystemMemberRegion region = scache.getRegion(regionPath); - PartitionAttributes pa = region.getPartitionAttributes(); - if (pa == null) { - isPR = false; - break; - } - PartitionAttributeInfo.Partition part = new PartitionAttributeInfo.Partition(); - - part.localMaxMemory = region.getPartitionAttributes().getLocalMaxMemory(); - part.toalMaxMemory = region.getPartitionAttributes().getTotalMaxMemory(); - pai.addPartition(part); - - redundantCopies = region.getPartitionAttributes().getRedundantCopies(); - totalNumBuckets = region.getPartitionAttributes().getTotalNumBuckets(); - } - } - - if (isPR) { - pai.redundantCopies = redundantCopies; - pai.regionPath = regionPath; - pai.totalNumBuckets = totalNumBuckets; - } else { - pai = null; - } - - return pai; - } - - public static class PartitionAttributeInfo implements DataSerializable - { - private static final long serialVersionUID = 1L; - - private String regionPath; - - private int redundantCopies; - private int totalNumBuckets; - - private List partitionList = new ArrayList(); - - public PartitionAttributeInfo() {} - - public void addPartition(Partition partition) - { - partitionList.add(partition); - } - - public List getPartitionList() - { - return partitionList; - } - - public String getRegionPath() - { - return regionPath; - } - - public int getRedundantCopies() - { - return redundantCopies; - } - - public int getTotalNumBuckets() - { - return totalNumBuckets; - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - regionPath = in.readUTF(); - redundantCopies = in.readInt(); - totalNumBuckets = in.readInt(); - - partitionList = new ArrayList(); - int size = in.readInt(); - for (int i = 0; i < size; i++) { - Partition part = new Partition(); - part.memberName = in.readUTF(); - part.localMaxMemory = in.readInt(); - part.toalMaxMemory = in.readLong(); - partitionList.add(part); - } - } - - public void toData(DataOutput out) throws IOException - { - out.writeUTF(regionPath); - out.writeInt(redundantCopies); - out.writeInt(totalNumBuckets); - - int size = partitionList.size(); - out.writeInt(size); - for (int i = 0; i < size; i++) { - Partition part = (Partition)partitionList.get(i); - out.writeUTF(part.memberName); - out.writeInt(part.localMaxMemory); - out.writeLong(part.toalMaxMemory); - } - - } - - public static class Partition - { - public Partition() {} - - private String memberName; - private int localMaxMemory ; - private long toalMaxMemory; - - public String getMemberName() - { - return memberName; - } - - public int getLocalMaxMemory() - { - return localMaxMemory; - } - - public long getToalMaxMemory() - { - return toalMaxMemory; - } - } - - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - regionPath = in.readUTF(); - } - - public void toData(DataOutput out) throws IOException - { - out.writeUTF(regionPath); - } -}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryResults.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryResults.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryResults.java deleted file mode 100644 index 131bb79..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryResults.java +++ /dev/null @@ -1,123 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; - -/** - * QueryResults contains query results executed by QueryTask. - * - * @author dpark - * - */ -public class QueryResults implements DataSerializable -{ - private static final long serialVersionUID = 1L; - - public static final byte ERROR_NONE = 0; - public static final byte ERROR_QUERY = 1; - - private Object results; - private int actualSize; - private int fetchSize; - private int returnedSize; - private boolean isPR; - - public QueryResults() {} - - // Default constructor required for serialization - public QueryResults(Object results, int actualSize, int fetchSize, int returnedSize) - { - this(results, actualSize, fetchSize, returnedSize, false); - } - - public QueryResults(Object results, int actualSize, int fetchSize, int returnedSize, boolean isPR) - { - this.results = results; - this.actualSize = actualSize; - this.fetchSize = fetchSize; - this.returnedSize = returnedSize; - this.isPR = isPR; - } - - /** - * Returns the fetch size. The default is 1000. If -1, fetches - * all. - * @return fetch size - */ - public int getFetchSize() - { - return fetchSize; - } - - /** - * Sets the fetch size. The default is 1000. - * @param fetchSize The fetch size. If -1, fetches all. - */ - public void setFetchSize(int fetchSize) - { - this.fetchSize = fetchSize; - } - - public int getActualSize() - { - return actualSize; - } - - public void setActualSize(int actualSize) - { - this.actualSize = actualSize; - } - - public Object getResults() - { - return results; - } - - public void setResults(Object results) - { - this.results = results; - } - - public int getReturnedSize() - { - return returnedSize; - } - - public void setReturnedSize(int returnedSize) - { - this.returnedSize = returnedSize; - } - - public boolean isPR() - { - return isPR; - } - - public void setPR(boolean isPR) - { - this.isPR = isPR; - } - - public void fromData(DataInput input) throws IOException, - ClassNotFoundException - { - results = DataSerializer.readObject(input); - actualSize = input.readInt(); - fetchSize = input.readInt(); - returnedSize = input.readInt(); - isPR = input.readBoolean(); - } - - public void toData(DataOutput output) throws IOException - { - DataSerializer.writeObject(results, output); - output.writeInt(actualSize); - output.writeInt(fetchSize); - output.writeInt(returnedSize); - output.writeBoolean(isPR); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryTask.java deleted file mode 100644 index 330d5bd..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/QueryTask.java +++ /dev/null @@ -1,522 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.AttributesFactory; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.ExpirationAttributes; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.cache.query.Query; -import com.gemstone.gemfire.cache.query.QueryException; -import com.gemstone.gemfire.cache.query.SelectResults; -import com.gemstone.gemfire.cache.query.internal.ResultsBag; -import com.gemstone.gemfire.cache.query.internal.StructBag; -import com.gemstone.gemfire.cache.query.types.CollectionType; -import com.gemstone.gemfire.cache.query.types.ObjectType; -import com.gemstone.gemfire.internal.GemFireVersion; -import com.gemstone.gemfire.internal.cache.BucketRegion; -import com.gemstone.gemfire.internal.cache.ForceReattemptException; -import com.gemstone.gemfire.internal.cache.PartitionedRegion; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.GfshResultsBag; -import com.gemstone.gemfire.internal.tools.gfsh.command.AbstractCommandTask; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; - -/** - * QueryTask executes the specified query and returns all or a subset of the - * result set. A subset of results is returned if the specified fetch size is - * less than the result set size. The caller can request for the next subset of - * the results by setting the query string to null and nextEnabled to true. - * - * @author dpark - * - */ -public class QueryTask extends AbstractCommandTask -{ - private static final long serialVersionUID = 1L; - - static { - staticUuid = UUID.randomUUID().toString(); - } - - private static boolean priorTo6011AndNot57 = false; - - static { - priorTo6011AndNot57 = isPriorTo6011AndNot57(); - } - - static boolean isPriorTo6011AndNot57() - { - String gemfireVersion = GemFireVersion.getGemFireVersion(); - String split[] = gemfireVersion.split("\\."); - int major = 0; - int minor = 0; - int update = 0; - int update2 = 0; - for (int i = 0; i < split.length; i++) { - switch (i) { - case 0: - major = Integer.parseInt(split[i]); - break; - case 1: - try { - minor = Integer.parseInt(split[i]); - } catch (NumberFormatException ex) { - minor = Integer.parseInt(split[i].substring(0, 1)); - } - break; - case 2: - try { - update = Integer.parseInt(split[i]); - } catch (NumberFormatException e) { - update = 0; - } - break; - case 3: - try { - update2 = Integer.parseInt(split[i]); - } catch (NumberFormatException e) { - update2 = 0; - } - break; - } - } - - // System.out.println("GemFireVersion: " + major + "." + minor + "." + - // update + "." + update2); - - if (major < 6) { - return false; // 6 - } else if (minor > 0) { - return false; // 6.1 - } else if (update < 1) { - return true; // 6.0.0 - } else if (update > 1) { - return false; // 6.0.2 - } else if (update2 <= 0) { - return true; // 6.0.1.0 - } else { - return false; // 6.0.1.1 - } - - } - - public static final byte ERROR_NONE = 0; - public static final byte ERROR_QUERY = 1; - - private static final String REGION_NAME_RESULTS = "qr"; - private static int UUID_TIMEOUT = Integer.getInteger("QueryTask.uuidTimeout", 30); // the - // UUID - // timeout - // 30 - // sec - private static String staticUuid; - - private transient String uuid; - - private String queryString; - private boolean nextEnabled; - private int fetchSize = 1000; - - // if isPRLocalData is true then the entries from the local dataset are returned - private boolean isPRLocalData; - - // if keysOnly is true then only the keys are are returned - private boolean keysOnly; - - // Default constructor required for serialization - public QueryTask() - { - } - - public QueryTask(String queryString) - { - this(queryString, 1000, true, false, false); - } - - public QueryTask(String queryString, int fetchSize, boolean nextEnabled) - { - this(queryString, fetchSize, nextEnabled, true); - } - - public QueryTask(String queryString, int fetchSize, boolean nextEnabled, boolean isPRLocalData) - { - this(queryString, fetchSize, nextEnabled, isPRLocalData, false); - } - - public QueryTask(String queryString, int fetchSize, boolean nextEnabled, boolean isPRLocalData, boolean keysOnly) - { - this.queryString = queryString; - this.fetchSize = fetchSize; - this.nextEnabled = nextEnabled; - this.isPRLocalData = isPRLocalData; - this.keysOnly = keysOnly; - } - - public CommandResults runTask(Object userData) - { - CommandResults results = execute(queryString); - return results; - } - - private Region getResultRegion() - { - Region resultRegion = super.getCommandRegion().getSubregion(REGION_NAME_RESULTS); - if (resultRegion == null) { - AttributesFactory factory = new AttributesFactory(); - factory.setStatisticsEnabled(true); - factory.setScope(Scope.LOCAL); - factory.setDataPolicy(DataPolicy.NORMAL); - factory.setEntryIdleTimeout(new ExpirationAttributes(UUID_TIMEOUT, ExpirationAction.LOCAL_DESTROY)); - try { - resultRegion = super.getCommandRegion().createSubregion(REGION_NAME_RESULTS, factory.create()); - } catch (Exception ex) { - // in case another thread created it - resultRegion = super.getCommandRegion().getSubregion(REGION_NAME_RESULTS); - } - } - return resultRegion; - } - - /** - * Executes the query string. - * - * @param queryString - * The query string to execute. - * @return The command results containing the query results. - */ - protected CommandResults execute(String queryString) - { - CommandResults results = new CommandResults(); - Cache cache = CacheFactory.getAnyInstance(); - - Region resultRegion = getResultRegion(); - - // Query - try { - Object obj = null; - int returnedSize = 0; - int actualSize = 0; - boolean isPR = false; - - // next - if (queryString == null) { - ResultsContainer container = (ResultsContainer) resultRegion.get(uuid); - if (container != null) { - isPR = container.isPR; - obj = container.getSubsetResults(getFetchSize()); - actualSize = container.getActualSize(); - returnedSize = container.getReturnedSize(); - if (container.hasNext() == false) { - resultRegion.remove(uuid); - } - } - - // new query - } else { - if (nextEnabled) { - resultRegion.remove(uuid); - } - - String lowercase = queryString.trim().toLowerCase(); - if (lowercase.startsWith("select ")) { - - // Query - Query query = cache.getQueryService().newQuery(queryString); - obj = query.execute(); - if (obj instanceof SelectResults) { - SelectResults sr = (SelectResults) obj; - actualSize = sr.size(); - - if (fetchSize != -1) { - if (sr.size() <= fetchSize) { - - // 6.0 - 6.0.1 do not serialize ResultsBag - // properly. - if (isPriorTo6011AndNot57()) { // 6.0 - 6.0.1 - if (sr instanceof ResultsBag) { - SelectResultsContainer srContainer = new SelectResultsContainer(sr); - obj = srContainer.getSubsetResults(getFetchSize()); - } else { - obj = sr; - } - } else { - obj = sr; - } - returnedSize = sr.size(); - } else { - SelectResultsContainer srContainer = new SelectResultsContainer(sr); - obj = srContainer.getSubsetResults(getFetchSize()); - returnedSize = srContainer.returnedSize; - if (nextEnabled) { - resultRegion.put(uuid, srContainer); - } - } - } else { - returnedSize = sr.size(); - } - } - - } else { - - // Region - - String regionPath = queryString; - Region region = cache.getRegion(regionPath); - if (region == null) { - results.setCode(ERROR_QUERY); - results.setCodeMessage("Invalid region path. Unable to query data."); - } else { - // Return region keys or entries - isPR = region instanceof PartitionedRegion; - Region r; - Set resultSet = null; - if (isPRLocalData && isPR) { - PartitionedRegion pr = (PartitionedRegion) region; -// r = new LocalDataSet(pr, pr.getDataStore().getAllLocalPrimaryBucketIds()); - if (pr.getDataStore() == null) { - // PROXY - no data store - results.setCodeMessage("No data store"); - return results; - } - List<Integer> bucketIdList = pr.getDataStore().getLocalPrimaryBucketsListTestOnly(); - resultSet = new HashSet(); - for (Integer bucketId : bucketIdList) { - BucketRegion bucketRegion; - try { - bucketRegion = pr.getDataStore().getInitializedBucketForId(null, bucketId); - Set set; - if (keysOnly) { - set = bucketRegion.keySet(); - } else { - set = bucketRegion.entrySet(); - } - for (Object object : set) { - resultSet.add(object); - } - } catch (ForceReattemptException e) { - // ignore - } - } - } else { - r = region; - if (keysOnly) { - resultSet = r.keySet(); - } else { - resultSet = r.entrySet(); - } - } - actualSize = resultSet.size(); - RegionContainer regionContainer = new RegionContainer(resultSet, keysOnly, isPR); - obj = regionContainer.getSubsetResults(getFetchSize()); - returnedSize = regionContainer.getReturnedSize(); - if (nextEnabled && regionContainer.hasNext()) { - resultRegion.put(uuid, regionContainer); - } - } - } - } - - results.setDataObject(new QueryResults(obj, actualSize, fetchSize, returnedSize, isPR)); - - } catch (QueryException e) { - cache.getLogger().warning(e); - results.setCode(ERROR_QUERY); - results.setCodeMessage("Unable to execute command task. Invalid query."); - results.setException(e); - } - return results; - } - - public String getQuery() - { - return queryString; - } - - public void setQuery(String queryString) - { - this.queryString = queryString; - } - - /** - * Returns the fetch size. The default is 1000. If -1, fetches all. - * - * @return fetch size - */ - public int getFetchSize() - { - return fetchSize; - } - - /** - * Sets the fetch size. The default is 1000. - * - * @param fetchSize - * The fetch size. If -1, fetches all. - */ - public void setFetchSize(int fetchSize) - { - this.fetchSize = fetchSize; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - super.fromData(input); - uuid = DataSerializer.readString(input); - queryString = DataSerializer.readString(input); - nextEnabled = input.readBoolean(); - isPRLocalData = input.readBoolean(); - fetchSize = input.readInt(); - keysOnly = input.readBoolean(); - } - - public void toData(DataOutput output) throws IOException - { - super.toData(output); - DataSerializer.writeString(staticUuid, output); - DataSerializer.writeString(queryString, output); - output.writeBoolean(nextEnabled); - output.writeBoolean(isPRLocalData); - output.writeInt(fetchSize); - output.writeBoolean(keysOnly); - } - - abstract class ResultsContainer - { - boolean isPR = false; - - protected abstract Object getSubsetResults(int fetchSize); - - protected abstract boolean hasNext(); - - protected abstract int getActualSize(); - - protected abstract int getReturnedSize(); - - } - - class SelectResultsContainer extends ResultsContainer - { - SelectResults sr; - Iterator iterator; - int returnedSize = 0;; - - SelectResultsContainer(SelectResults sr) - { - this.sr = sr; - iterator = sr.iterator(); - } - - protected Object getSubsetResults(int fetchSize) - { - SelectResults sr2; - CollectionType type = sr.getCollectionType(); - ObjectType elementType = type.getElementType(); - if (elementType.isStructType()) { - sr2 = new StructBag(); - } else { - if (isPriorTo6011AndNot57()) { // 6.0 - 6.0.1 - sr2 = new GfshResultsBag(); - } else { - sr2 = new ResultsBag(); - } - } - sr2.setElementType(elementType); - - int count = 0; - while (count < fetchSize && iterator.hasNext()) { - Object object = (Object) iterator.next(); - sr2.add(object); - count++; - } - returnedSize += count; - return sr2; - } - - protected boolean hasNext() - { - return iterator.hasNext(); - } - - protected int getActualSize() - { - return sr.size(); - } - - protected int getReturnedSize() - { - return returnedSize; - } - } - - class RegionContainer extends ResultsContainer - { - Set resultSet; - Iterator iterator; - int returnedSize = 0; - boolean keysOnly; - - RegionContainer(Set resultSet, boolean keysOnly, boolean isPR) - { - this.resultSet = resultSet; - this.keysOnly = keysOnly; - super.isPR = isPR; - iterator = resultSet.iterator(); - } - - protected Object getSubsetResults(int fetchSize) - { - int count = 0; - Object retval; - - if (keysOnly) { - ArrayList list = new ArrayList(); - while (count < fetchSize && iterator.hasNext()) { - Object key = iterator.next(); - list.add(key); - count++; - } - retval = list; - } else { - HashMap map = new HashMap(); - while (count < fetchSize && iterator.hasNext()) { - Region.Entry entry = (Region.Entry)iterator.next(); - map.put(entry.getKey(), entry.getValue()); - count++; - } - retval = map; - } - returnedSize += count; - - return retval; - } - - protected boolean hasNext() - { - return iterator.hasNext(); - } - - protected int getActualSize() - { - return resultSet.size(); - } - - protected int getReturnedSize() - { - return returnedSize; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RefreshAggregatorRegionTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RefreshAggregatorRegionTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RefreshAggregatorRegionTask.java deleted file mode 100644 index 8784078..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RefreshAggregatorRegionTask.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.internal.cache.PartitionedRegion; -import com.gemstone.gemfire.internal.tools.gfsh.command.AbstractCommandTask; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; - -public class RefreshAggregatorRegionTask extends AbstractCommandTask { - private static final long serialVersionUID = 1L; - - // Default constructor required for serialization - public RefreshAggregatorRegionTask() - { - } - - private void initRegion() - { - PartitionedRegion pr = (PartitionedRegion)getCommandRegion().getSubregion("pr"); - if (pr == null) { - return; - } - int totalBuckets = pr.getAttributes().getPartitionAttributes().getTotalNumBuckets(); - for (int i = 0; i < totalBuckets; i++) { - pr.put(i, i); - pr.remove(i); - } - } - - @Override - public CommandResults runTask(Object userData) - { - new Thread(new Runnable() { - public void run() - { - initRegion(); - } - }).start(); - return null; - } - - public void fromData(DataInput input) throws IOException, - ClassNotFoundException - { - super.fromData(input); - } - - public void toData(DataOutput output) throws IOException { - super.toData(output); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionClearTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionClearTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionClearTask.java deleted file mode 100644 index 944f97c..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionClearTask.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.distributed.DistributedMember; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; - -/** - * RegionClearTask destroys a region in the server. The region destroy will be - * distributed to other caches if the scope is not Scope.LOCAL. - * CommandResults.getDataObject() returns MemberInfo. - * - * @author dpark - * - */ -public class RegionClearTask implements CommandTask -{ - private static final long serialVersionUID = 1L; - - public static final byte ERROR_REGION_CLEAR = 1; - - private String regionFullPath; - - public RegionClearTask() - { - } - - public RegionClearTask(String regionFullPath) - { - this.regionFullPath = regionFullPath; - } - - public CommandResults runTask(Object userData) - { - CommandResults results = new CommandResults(); - - MemberInfo memberInfo = new MemberInfo(); - - try { - Cache cache = CacheFactory.getAnyInstance(); - Region region = cache.getRegion(regionFullPath); - DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - memberInfo.setHost(member.getHost()); - memberInfo.setMemberId(member.getId()); - memberInfo.setMemberName(cache.getName()); - memberInfo.setPid(member.getProcessId()); - - results.setDataObject(memberInfo); - - if (region == null) { - results.setCode(ERROR_REGION_CLEAR); - results.setCodeMessage("Region undefined: " + regionFullPath); - } else { - synchronized (region) { - region.clear(); - } - } - } catch (Exception ex) { - results.setCode(ERROR_REGION_CLEAR); - results.setCodeMessage(ex.getMessage()); - results.setException(ex); - } - - return results; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - regionFullPath = DataSerializer.readString(input); - } - - public void toData(DataOutput output) throws IOException - { - DataSerializer.writeString(regionFullPath, output); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionCreateTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionCreateTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionCreateTask.java deleted file mode 100644 index 5b5b007..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionCreateTask.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.AttributesFactory; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheException; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.distributed.DistributedMember; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.RegionAttributeInfo; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.DataSerializerEx; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; -import com.gemstone.gemfire.internal.tools.gfsh.util.RegionUtil; - -/** - * - * RegionCreateTask creates a remote region. Invoke this class using - * CommandClient.execute() or CommandClient.broadcast(). CommandClient.execute() - * creates the specified region in the connected server only. - * CommandClient.Broadcast() creates the specified region in all peers in the - * distributed system. Both methods return CommandResults with the code set. - * Check CommandResults.getCode() to see the task execution status. - * RegionCreateTask.SUCCESS_CREATED for region successfully created, - * RegionCreateTask.ERROR_... for an error creating region. - * - * @author dpark - * - */ -public class RegionCreateTask implements CommandTask -{ - private static final long serialVersionUID = 1; - - public static final byte SUCCESS_CREATED = CommandResults.CODE_NORMAL; - public static final byte ERROR_REGION_NOT_CREATED = 1; - public static final byte ERROR_REGION_ALREADY_EXIST = 2; - public static final byte ERROR_REGION_PARENT_DOES_NOT_EXIST = 3; - public static final byte ERROR_REGION_INVALID_PATH = 4; - - private String regionFullPath; - private RegionAttributeInfo attrInfo; - - public RegionCreateTask() - { - } - - /** - * Constructs a RegionCreateAllTask object using the default region attribute settings. - * @param regionFullPath The region path. - */ - public RegionCreateTask(String regionFullPath) - { - this(regionFullPath, null); - } - - /** - * Constructs a RegionCreateAllTask object using the specified region attributes. - * @param regionFullPath The region path. - * @param attrInfo The region attributes. The attribute values are same as the cache.dtd values. - */ - public RegionCreateTask(String regionFullPath, RegionAttributeInfo attrInfo) - { - this.regionFullPath = regionFullPath; - this.attrInfo = attrInfo; - } - - public CommandResults runTask(Object userData) - { - return createRegion(); - } - - private CommandResults createRegion() - { - CommandResults results = new CommandResults(); - results.setCode(SUCCESS_CREATED); - - Cache cache = CacheFactory.getAnyInstance(); - MemberInfo memberInfo = new MemberInfo(); - DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - memberInfo.setHost(member.getHost()); - memberInfo.setMemberId(member.getId()); - memberInfo.setMemberName(cache.getName()); - memberInfo.setPid(member.getProcessId()); - results.setDataObject(memberInfo); - - if (regionFullPath == null) { - results.setCode(ERROR_REGION_INVALID_PATH); - results.setCodeMessage("Invalid region path: " + regionFullPath); - return results; - } - int index = regionFullPath.lastIndexOf("/"); - if (index == regionFullPath.length() - 1) { - results.setCode(ERROR_REGION_INVALID_PATH); - results.setCodeMessage("Invalid region path: " + regionFullPath); - return results; - } - - String regionName = regionFullPath.substring(index + 1); - try { - - Region region = cache.getRegion(regionFullPath); - if (region != null) { - results.setCode(ERROR_REGION_ALREADY_EXIST); - results.setCodeMessage("Region already exist: " + regionFullPath); - } else { - Region parentRegion = RegionUtil.getParentRegion(regionFullPath); - if (parentRegion == null) { - if (regionFullPath.split("/").length > 2) { - results.setCode(ERROR_REGION_PARENT_DOES_NOT_EXIST); - results.setCodeMessage("Parent region does not exist: " + regionFullPath); - } else { - if (attrInfo == null) { - region = cache.createRegion(regionName, new AttributesFactory().create()); - } else { - region = cache.createRegion(regionName, attrInfo.createRegionAttributes()); - } - if (region == null) { - results.setCode(ERROR_REGION_NOT_CREATED); - results.setCodeMessage("Unable create region: " + regionFullPath); - } else { - results.setCodeMessage("Region created: " + region.getFullPath()); - } - } - } else { - if (attrInfo == null) { - region = parentRegion.createSubregion(regionName, new AttributesFactory().create()); - } else { - region = parentRegion.createSubregion(regionName, attrInfo.createRegionAttributes()); - } - if (region == null) { - results.setCode(ERROR_REGION_NOT_CREATED); - results.setCodeMessage("Unable create region: " + regionFullPath); - } else { - results.setCodeMessage("Region created: " + region.getFullPath()); - } - } - } - } catch (CacheException ex) { - results.setCode(ERROR_REGION_NOT_CREATED); - results.setException(ex); - } - return results; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - regionFullPath = DataSerializerEx.readUTF(input); - attrInfo = (RegionAttributeInfo) DataSerializer.readObject(input); - } - - public void toData(DataOutput output) throws IOException - { - DataSerializerEx.writeUTF(regionFullPath, output); - DataSerializer.writeObject(attrInfo, output); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionDestroyTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionDestroyTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionDestroyTask.java deleted file mode 100644 index c6d9627..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionDestroyTask.java +++ /dev/null @@ -1,97 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.distributed.DistributedMember; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data.MemberInfo; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; - -/** - * RegionDestroyTask destroys a remote region. Invoke this class using - * CommandClient.execute() or CommandClient.broadcast(). CommandClient.execute() - * destroys the specified region in the connected server and distributes it to - * other servers only if the region scope is not LOCAL. - * CommandClient.Broadcast() destroys the specified region in all peers in the - * distributed system. Both methods return CommandResults with the code set. - * Check CommandResults.getCode() to see the task execution status. - * RegionDestroyTask.SUCCESS_DESTROYED for region successfully destroyed, - * RegionDestroyTask.ERROR_REGION_DESTROY for an error creating region. - * CommandResults.getDataObject() returns MemberInfo. - * - * @author dpark - */ -public class RegionDestroyTask implements CommandTask -{ - private static final long serialVersionUID = 1L; - - public static final byte ERROR_REGION_DESTROY = 1; - - private String regionFullPath; - - public RegionDestroyTask() - { - } - - /** - * Constructs a RegionDestroyTask object. - * - * @param regionFullPath - * The path of the region to destroy. - */ - public RegionDestroyTask(String regionFullPath) - { - this.regionFullPath = regionFullPath; - } - - public CommandResults runTask(Object userData) - { - CommandResults results = new CommandResults(); - - MemberInfo memberInfo = new MemberInfo(); - - try { - Cache cache = CacheFactory.getAnyInstance(); - Region region = cache.getRegion(regionFullPath); - DistributedMember member = cache.getDistributedSystem().getDistributedMember(); - memberInfo.setHost(member.getHost()); - memberInfo.setMemberId(member.getId()); - memberInfo.setMemberName(cache.getName()); - memberInfo.setPid(member.getProcessId()); - - results.setDataObject(memberInfo); - - if (region == null) { - results.setCode(ERROR_REGION_DESTROY); - results.setCodeMessage("Region undefined: " + regionFullPath); - } else { - synchronized (region) { - region.destroyRegion(); - } - } - } catch (Exception ex) { - results.setCode(ERROR_REGION_DESTROY); - results.setCodeMessage(ex.getMessage()); - results.setException(ex); - } - - return results; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - regionFullPath = DataSerializer.readString(input); - } - - public void toData(DataOutput output) throws IOException - { - DataSerializer.writeString(regionFullPath, output); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionPathTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionPathTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionPathTask.java deleted file mode 100644 index 1c8c0f4..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionPathTask.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; -import com.gemstone.gemfire.internal.tools.gfsh.util.RegionUtil; - -/** - * RegionPathTask retrieves an entire list of region paths in the connected - * server or in the entire distributed system in which the connected server - * belongs. - */ -public class RegionPathTask implements CommandTask -{ - private static final long serialVersionUID = 1L; - - private boolean regionsInDistributedSystem = false; - private boolean recursive = true; - private String parentRegionPath = null; - - /** - * Returns all region paths in the entire distributed system. This - * constructor call is equivalent to new RegonPathTask(true, true, null); - */ - public RegionPathTask() - { - } - - /** - * Returns all region paths starting from the top level. - * - * @param regionsInDistributedSystem - * if false, returns all region paths found in the cache. If - * true, returns all region paths found in the entire distributed - * system. - * @param recursive - * if true, returns all nested region paths, otherwise, returns - * the top-level region paths - */ - public RegionPathTask(boolean regionsInDistributedSystem, boolean recursive) - { - this(regionsInDistributedSystem, recursive, null); - } - - /** - * @param regionsInDistributedSystem - * if false, returns all region paths found in the cache. If - * true, returns all region paths found in the entire distributed - * system. - * @param recursive - * if true, returns all nested region paths, otherwise, returns - * the top-level region paths - * @param parentRegionPath - * the parent region path - */ - public RegionPathTask(boolean regionsInDistributedSystem, boolean recursive, String parentRegionPath) - { - this.regionsInDistributedSystem = regionsInDistributedSystem; - this.recursive = recursive; - this.parentRegionPath = parentRegionPath; - } - - public CommandResults runTask(Object userData) - { - String[] regionPaths = null; - Cache cache = CacheFactory.getAnyInstance(); - if (regionsInDistributedSystem) { - - // get region paths defined in this cache only - - if (parentRegionPath == null) { - regionPaths = RegionUtil.getAllRegionPaths(CacheFactory.getAnyInstance(), recursive); - } else { - Region region = cache.getRegion(parentRegionPath); - if (region != null) { - regionPaths = RegionUtil.getAllRegionPaths(region, recursive); - } - } - - } else { - - // get region paths defined in all of the caches in the distributed - // system - - if (parentRegionPath == null) { - regionPaths = RegionUtil.getAllRegionPathsInDistributedSystem(cache.getDistributedSystem(), recursive); - } else { - Region region = cache.getRegion(parentRegionPath); - if (region != null) { - regionPaths = RegionUtil.getAllRegionPaths(region, recursive); - } - } - - } - CommandResults results = new CommandResults(regionPaths); - return results; - } - - public boolean isRegionsInDistributedSystem() - { - return regionsInDistributedSystem; - } - - public void setRegionsInDistributedSystem(boolean regionsInDistributedSystem) - { - this.regionsInDistributedSystem = regionsInDistributedSystem; - } - - public boolean isRecursive() - { - return recursive; - } - - public void setRecursive(boolean recursive) - { - this.recursive = recursive; - } - - public String getParentRegionPath() - { - return parentRegionPath; - } - - public void setParentRegionPath(String parentRegionPath) - { - this.parentRegionPath = parentRegionPath; - } - - public void fromData(DataInput input) throws IOException, ClassNotFoundException - { - regionsInDistributedSystem = input.readBoolean(); - recursive = input.readBoolean(); - parentRegionPath = input.readUTF(); - if (parentRegionPath.equals("\0")) { - parentRegionPath = null; - } - } - - public void toData(DataOutput output) throws IOException - { - output.writeBoolean(regionsInDistributedSystem); - output.writeBoolean(recursive); - if (parentRegionPath == null) { - output.writeUTF("\0"); - } else { - output.writeUTF(parentRegionPath); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionSizeTask.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionSizeTask.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionSizeTask.java deleted file mode 100644 index de76142..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/RegionSizeTask.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheException; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.app.cache.data.MapMessage; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandTask; - -/** - * RegionSizeTask returns the region size. CommandResults.getDataObject() - * returns an integer, the region size. Use - * @author dpark - * - */ -public class RegionSizeTask implements CommandTask { - - private static final long serialVersionUID = 1; - - private String regionFullPath; - - public RegionSizeTask() { - } - - public RegionSizeTask(String regionFullPath) { - this.regionFullPath = regionFullPath; - } - - public CommandResults runTask(Object userData) { - CommandResults results = new CommandResults(); - try { - Cache cache = CacheFactory.getAnyInstance(); - MapMessage message = new MapMessage(); - message.put("MemberId", cache.getDistributedSystem().getDistributedMember().getId()); - message.put("MemberName", cache.getDistributedSystem().getName()); - message.put("Host", cache.getDistributedSystem().getDistributedMember().getHost()); - message.put("Pid", cache.getDistributedSystem().getDistributedMember().getProcessId()); - Region region = cache.getRegion(regionFullPath); - if (region == null) { - results.setCode(CommandResults.CODE_ERROR); - results.setCodeMessage("Undefined region: " + regionFullPath); - } else { - message.put("RegionSize", region.size()); - results.setDataObject(message); - } - return results; - } catch (CacheException ex) { - results.setCode(CommandResults.CODE_ERROR); - results.setCodeMessage(ex.getMessage()); - results.setException(ex); - } - return results; - } - - public void fromData(DataInput input) throws IOException, - ClassNotFoundException { - regionFullPath = DataSerializer.readString(input); - } - - public void toData(DataOutput output) throws IOException { - DataSerializer.writeString(regionFullPath, output); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/MemberInfo.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/MemberInfo.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/MemberInfo.java deleted file mode 100644 index 5095a38..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/MemberInfo.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.DataSerializerEx; - -/** - * A data class that contains member information - * @author dpark - * - */ -public class MemberInfo implements DataSerializable -{ - private static final long serialVersionUID = 1L; - - private String memberId; - private String memberName; - private String host; - private int pid; - - public String getMemberId() - { - return memberId; - } - - public void setMemberId(String memberId) - { - this.memberId = memberId; - } - - public String getMemberName() - { - return memberName; - } - - public void setMemberName(String memberName) - { - this.memberName = memberName; - } - - public String getHost() - { - return host; - } - - public void setHost(String host) - { - this.host = host; - } - - public int getPid() - { - return pid; - } - - public void setPid(int pid) - { - this.pid = pid; - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - pid = in.readInt(); - memberId = DataSerializerEx.readUTF(in); - memberName = DataSerializerEx.readUTF(in); - host = DataSerializerEx.readUTF(in); - } - - public void toData(DataOutput out) throws IOException - { - out.writeInt(pid); - DataSerializerEx.writeUTF(memberId, out); - DataSerializerEx.writeUTF(memberName, out); - DataSerializerEx.writeUTF(host, out); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/PartitionAttributeInfo.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/PartitionAttributeInfo.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/PartitionAttributeInfo.java deleted file mode 100644 index 07f6261..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/PartitionAttributeInfo.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.cache.PartitionAttributes; - -/** - * A data class that contains partition region attribute information. - * @author dpark - * - */ -public class PartitionAttributeInfo implements DataSerializable -{ - private static final long serialVersionUID = 1L; - - private long versionId = serialVersionUID; - - private String regionPath; - - private int redundantCopies; - private int totalNumBuckets; - - private List partitionList = new ArrayList(); - - public PartitionAttributeInfo() {} - - public PartitionAttributeInfo(PartitionAttributes attr) - { - - } - - public void addPartition(Partition partition) - { - partitionList.add(partition); - } - - public List getPartitionList() - { - return partitionList; - } - - public String getRegionPath() - { - return regionPath; - } - - public int getRedundantCopies() - { - return redundantCopies; - } - - public int getTotalNumBuckets() - { - return totalNumBuckets; - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - versionId = in.readLong(); - - regionPath = in.readUTF(); - redundantCopies = in.readInt(); - totalNumBuckets = in.readInt(); - - partitionList = new ArrayList(); - int size = in.readInt(); - for (int i = 0; i < size; i++) { - Partition part = new Partition(); - part.memberName = in.readUTF(); - part.localMaxMemory = in.readInt(); - part.toalMaxMemory = in.readLong(); - partitionList.add(part); - } - } - - public void toData(DataOutput out) throws IOException - { - out.writeLong(versionId); - - out.writeUTF(regionPath); - out.writeInt(redundantCopies); - out.writeInt(totalNumBuckets); - - int size = partitionList.size(); - out.writeInt(size); - for (int i = 0; i < size; i++) { - Partition part = (Partition)partitionList.get(i); - out.writeUTF(part.memberName); - out.writeInt(part.localMaxMemory); - out.writeLong(part.toalMaxMemory); - } - - } - - public static class Partition - { - public Partition() {} - - private String memberName; - private int localMaxMemory ; - private long toalMaxMemory; - - public String getMemberName() - { - return memberName; - } - - public int getLocalMaxMemory() - { - return localMaxMemory; - } - - public long getToalMaxMemory() - { - return toalMaxMemory; - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/RegionAttributeInfo.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/RegionAttributeInfo.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/RegionAttributeInfo.java deleted file mode 100644 index 06fd010..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/command/task/data/RegionAttributeInfo.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.command.task.data; - -import java.io.DataInput; -import java.io.DataOutput; -import java.io.IOException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Properties; -import java.util.Set; - -import com.gemstone.gemfire.DataSerializable; -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.cache.AttributesFactory; -import com.gemstone.gemfire.cache.DataPolicy; -import com.gemstone.gemfire.cache.ExpirationAction; -import com.gemstone.gemfire.cache.ExpirationAttributes; -import com.gemstone.gemfire.cache.PartitionAttributesFactory; -import com.gemstone.gemfire.cache.RegionAttributes; -import com.gemstone.gemfire.cache.Scope; - -/** - * A data class that contains region attribute information. - * @author dpark - * - */ -public class RegionAttributeInfo implements DataSerializable -{ - private static final long serialVersionUID = 1L; - - // Region attributes - public static final String CONCURRENCY_LEVEL = "concurrency-level"; - public static final String DATA_POLICY = "data-policy"; - public static final String EARLY_ACK = "early-ack"; - public static final String ENABLE_ASYNC_CONFLATION = "enable-async-conflation"; - public static final String ENABLE_GATEWAY = "enable-gateway"; - public static final String ENABLE_SUBSCRIPTION_CONFLATION = "enable-subscription-conflation"; - public static final String HUB_ID = "hub-id"; - public static final String IGNORE_JTA = "ignore-jta"; - public static final String INDEX_UPDATE_TYPE = "index-update-type"; - public static final String INITIAL_CAPACITY = "initial-capacity"; - public static final String IS_LOCK_GRANTOR = "is-lock-grantor"; - public static final String LOAD_FACTOR = "load-factor"; - public static final String MULTICAST_ENABLED = "multicast-enabled"; - public static final String PUBLISHER = "publisher"; - public static final String SCOPE = "scope"; - public static final String STATISTICS_ENABLED = "statistics-enabled"; - - // Region element attributes - // region-time-to-live - public static final String REGION_TIME_TO_LIVE_TIMEOUT = "region-time-to-live.timeout"; - public static final String REGION_TIME_TO_LIVE_ACTION = "region-time-to-live.action"; - - // region-idle-time - public static final String REGION_IDLE_TIME_TIMEOUT = "region-idle-time.timeout"; - public static final String REGION_IDLE_TIME_ACTION = "region-idle-time.action"; - - // entry-time-to-live - public static final String ENTRY_TIME_TO_LIVE_TIMEOUT = "entry-time-to-live.timeout"; - public static final String ENTRY_TIME_TO_LIVE_ACTION = "entry-time-to-live.action"; - - // entry-idle-time - public static final String ENTRY_IDLE_TIME_TIMEOUT = "entry-idle-time.timeout"; - public static final String ENTRY_IDLE_TIME_ACTION = "entry-idle-time.action"; - - // disk-dirs - public static final String DISK_DIRS_DISK_DIR = "disk-dirs.disk-dir"; // 1, many - - // disk-write-attributes - public static final String DISK_WRITE_ATTRIBUTES_MAX_OPLOG_SIZE = "disk-write-attributes.max-oplog-size"; - public static final String DISK_WRITE_ATTRIBUTES_ROLL_OPLOGS = "disk-write-attributes.roll-oplogs"; - public static final String DISK_WRITE_ATTRIBUTES_ASYNCHRONOUS_WRITES_TIME_INTERVAL = "disk-write-attributes.asynchronous-writes.time-interval"; - public static final String DISK_WRITE_ATTRIBUTES_ASYNCHRONOUS_WRITES_BYTES_THRESHOLD = "disk-write-attributes.asynchronous-writes.bytes-threshold"; - public static final String DISK_WRITE_ATTRIBUTES_SYNCHRONOUS_WRITES = "disk-write-attributes.synchronous-writes"; // true|false - - // membership-attributes - public static final String MEMBERSHIP_ATTRIBUTES_LOSS_ACTION = "membership-attributes.loss-action"; // 0,1 - public static final String MEMBERSHIP_ATTRIBUTES_RESUMPTION_ACTION = "membership-attributes.resumption-action"; // 0,1 - public static final String MEMBERSHIP_ATTRIBUTES_REQUIRED_ROLE = "membership-attributes.resumption-action"; // 1, many - - // subscription-attributes - public static final String SUBSCRIPTION_ATTRIBUTES_INTEREST_POLICY = "subscription-attributes.interest-policy"; // 0,1 - - // eviction-attributes.lru-entry-count - public static final String EVICTION_ATTRIBUTES_LRU_ENTRY_COUNT_ACTION = "eviction-attributes.lru-entry-count.action"; - public static final String EVICTION_ATTRIBUTES_LRU_ENTRY_COUNT_MAXIMUM = "eviction-attributes.lru-entry-count.maximum"; - - // eviction-attributes.lru-memory-size - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_ACTION = "eviction-attributes.lru-memory-size.action"; - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_MAXIMUM = "eviction-attributes.lru-memory-size.maximum"; - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_CLASS_NAME = "eviction-attributes.lru-memory-size.class-name"; - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_PARAMETER = "eviction-attributes.lru-memory-size.parameter"; - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_PARAMETER_STRING = "eviction-attributes.lru-memory-size.parameter.string"; - public static final String EVICTION_ATTRIBUTES_LRU_MEMORY_SIZE_PARAMETER_DECLARABLE = "eviction-attributes.lru-memory-size.parameter.declarable"; - - // eviction-attributes.lru-heap-percentage - public static final String EVICTION_ATTRIBUTES_LRU_HEAP_PERCENTAGE_ACTION = "eviction-attributes.lru-heap-percentage.action"; - public static final String EVICTION_ATTRIBUTES_LRU_HEAP_PERCENTAGE_CLASS_NAME = "eviction-attributes.lru-heap-percentage.class-name"; - public static final String EVICTION_ATTRIBUTES_LRU_HEAP_PERCENTAGE_PARAMETER = "eviction-attributes.lru-heap-percentage.parameter"; - public static final String EVICTION_ATTRIBUTES_LRU_HEAP_PERCENTAGE_PARAMETER_STRING = "eviction-attributes.lru-heap-percentage.parameter.string"; - public static final String EVICTION_ATTRIBUTES_LRU_HEAP_PERCENTAGE_PARAMETER_DECLARABLE = "eviction-attributes.lru-heap-percentage.parameter.declarable"; - - // key-constraint - public static final String KEY_CONTRATINT = "key-constraint"; - - // value-constraint - public static final String VALUE_CONTRATINT = "value-constraint"; - - // cache-listener - public static final String CACHE_LISTENER_CLASS_NAME = "cache-listener.class-name"; - public static final String CACHE_LISTENER_PARAMETER_NAME = "cache-listener.parameter.name"; - public static final String CACHE_LISTENER_PARAMETER_STRING = "cache-listener.parameter.string"; - public static final String CACHE_LISTENER_PARAMETER_DECLARABLE_CLASS_NAME = "cache-listener.parameter.declarable.class-name"; - public static final String CACHE_LISTENER_PARAMETER_DECLARABLE_PARAMETER_NAME = "cache-listener.parameter.declarable.parameter.name"; - public static final String CACHE_LISTENER_PARAMETER_DECLARABLE_PARAMETER_STRING = "cache-listener.parameter.declarable.parameter.string"; - - // Partition attributes - public static final String LOCAL_MAX_MEMORY = "local-max-memory"; - public static final String REDUNDANT_COPIES = "redundant-copies"; - public static final String TOTAL_MAX_MEMORY = "total-max-memory"; - public static final String TOTAL_NUM_BUCKETS = "total-num-buckets"; - - private int versionId = 1; - - private HashMap attrProperties = new HashMap(); - - public RegionAttributeInfo() {} - - public RegionAttributeInfo(Properties attrProperties) - { - this.attrProperties.putAll(attrProperties); - } - - public void setAttribute(String attributeName, String value) - { - attrProperties.put(attributeName, value); - } - - public String getAttribute(String attributeName) - { - return (String)attrProperties.get(attributeName); - } - - public RegionAttributes createRegionAttributes() - { - AttributesFactory factory = new AttributesFactory(); - PartitionAttributesFactory partitionAttrFactory = null; - - Set entrySet = attrProperties.entrySet(); - for (Iterator<Entry<String, String>> iterator = entrySet.iterator(); iterator.hasNext();) { - Entry<String, String> entry = iterator.next(); - String attr = (String)entry.getKey(); - String value = (String)entry.getValue(); - value = value.replace('-', '_'); - if (attr.equals(CONCURRENCY_LEVEL)) { - factory.setConcurrencyLevel(Integer.parseInt(value)); - } else if (attr.equals(DATA_POLICY)) { - if (value.equalsIgnoreCase(DataPolicy.EMPTY.toString())) { - factory.setDataPolicy(DataPolicy.EMPTY); - } else if (value.equalsIgnoreCase(DataPolicy.NORMAL.toString())) { - factory.setDataPolicy(DataPolicy.NORMAL); - } else if (value.equalsIgnoreCase(DataPolicy.PARTITION.toString())) { - factory.setDataPolicy(DataPolicy.PARTITION); - } else if (value.equalsIgnoreCase(DataPolicy.PERSISTENT_REPLICATE.toString())) { - factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); - } else if (value.equalsIgnoreCase(DataPolicy.PRELOADED.toString())) { - factory.setDataPolicy(DataPolicy.PRELOADED); - } else if (value.equalsIgnoreCase(DataPolicy.REPLICATE.toString())) { - factory.setDataPolicy(DataPolicy.REPLICATE); - } - } else if (attr.equals(EARLY_ACK)) { - factory.setEarlyAck(Boolean.parseBoolean(value)); - } else if (attr.equals(ENABLE_ASYNC_CONFLATION)) { - factory.setEnableAsyncConflation(Boolean.parseBoolean(value)); - } else if (attr.equals(ENABLE_SUBSCRIPTION_CONFLATION)) { - factory.setEnableSubscriptionConflation(Boolean.parseBoolean(value)); - } else if (attr.equals(IGNORE_JTA)) { - factory.setIgnoreJTA(Boolean.parseBoolean(value)); - } else if (attr.equals(INDEX_UPDATE_TYPE)) { - factory.setIndexMaintenanceSynchronous(value.equals("asynchronous")); - } else if (attr.equals(INITIAL_CAPACITY)) { - factory.setInitialCapacity(Integer.parseInt(value)); - } else if (attr.equals(IS_LOCK_GRANTOR)) { - factory.setLockGrantor(Boolean.parseBoolean(value)); - } else if (attr.equals(LOAD_FACTOR)) { - factory.setLoadFactor(Float.parseFloat(value)); - } else if (attr.equals(MULTICAST_ENABLED)) { - factory.setMulticastEnabled(Boolean.parseBoolean(value)); - } else if (attr.equals(PUBLISHER)) { - factory.setPublisher(Boolean.parseBoolean(value)); - } else if (attr.equals(SCOPE)) { - if (value.equalsIgnoreCase(Scope.DISTRIBUTED_ACK.toString())) { - factory.setScope(Scope.DISTRIBUTED_ACK); - } else if (value.equalsIgnoreCase(Scope.DISTRIBUTED_NO_ACK.toString())) { - factory.setScope(Scope.DISTRIBUTED_NO_ACK); - } else if (value.equalsIgnoreCase(Scope.GLOBAL.toString())) { - factory.setScope(Scope.GLOBAL); - } else if (value.equalsIgnoreCase(Scope.LOCAL.toString())) { - factory.setScope(Scope.LOCAL); - } - } else if (attr.equals(STATISTICS_ENABLED)) { - factory.setStatisticsEnabled(Boolean.parseBoolean(value)); - - // Partition attributes - } else if (attr.equals(LOCAL_MAX_MEMORY)) { - if (partitionAttrFactory == null) { - partitionAttrFactory = new PartitionAttributesFactory(); - } - partitionAttrFactory.setLocalMaxMemory(Integer.parseInt(value)); - } else if (attr.equals(REDUNDANT_COPIES)) { - if (partitionAttrFactory == null) { - partitionAttrFactory = new PartitionAttributesFactory(); - } - partitionAttrFactory.setRedundantCopies(Integer.parseInt(value)); - } else if (attr.equals(TOTAL_MAX_MEMORY)) { - if (partitionAttrFactory == null) { - partitionAttrFactory = new PartitionAttributesFactory(); - } - partitionAttrFactory.setTotalMaxMemory(Integer.parseInt(value)); - } else if (attr.equals(TOTAL_NUM_BUCKETS)) { - if (partitionAttrFactory == null) { - partitionAttrFactory = new PartitionAttributesFactory(); - } - partitionAttrFactory.setTotalNumBuckets(Integer.parseInt(value)); - - - // region attributes elements - additions (9/19/09) - } else if (attr.equals(ENTRY_IDLE_TIME_TIMEOUT)) { - int timeout = Integer.parseInt(value); - String action = (String)attrProperties.get(ENTRY_IDLE_TIME_ACTION); - factory.setEntryIdleTimeout(new ExpirationAttributes(timeout, getExpirationAction(action))); - } else if (attr.equals(ENTRY_TIME_TO_LIVE_TIMEOUT)) { - int timeout = Integer.parseInt(value); - String action = (String)attrProperties.get(ENTRY_TIME_TO_LIVE_ACTION); - factory.setEntryTimeToLive(new ExpirationAttributes(timeout, getExpirationAction(action))); - } else if (attr.equals(REGION_IDLE_TIME_TIMEOUT)) { - int timeout = Integer.parseInt(value); - String action = (String)attrProperties.get(REGION_IDLE_TIME_ACTION); - factory.setRegionIdleTimeout(new ExpirationAttributes(timeout, getExpirationAction(action))); - } else if (attr.equals(REGION_TIME_TO_LIVE_TIMEOUT)) { - int timeout = Integer.parseInt(value); - String action = (String)attrProperties.get(REGION_TIME_TO_LIVE_ACTION); - factory.setRegionTimeToLive(new ExpirationAttributes(timeout, getExpirationAction(action))); - } - - } - - if (partitionAttrFactory != null) { - factory.setPartitionAttributes(partitionAttrFactory.create()); - } - - return factory.create(); - } - - private ExpirationAction getExpirationAction(String action) - { - if (action == null) { - return ExpirationAttributes.DEFAULT.getAction(); - } - action = action.replace('-', '_'); - if (action.equalsIgnoreCase(ExpirationAction.DESTROY.toString())) { - return ExpirationAction.DESTROY; - } else if (action.equalsIgnoreCase(ExpirationAction.INVALIDATE.toString())) { - return ExpirationAction.INVALIDATE; - } else if (action.equalsIgnoreCase(ExpirationAction.LOCAL_DESTROY.toString())) { - return ExpirationAction.LOCAL_DESTROY; - } else if (action.equalsIgnoreCase(ExpirationAction.LOCAL_INVALIDATE.toString())) { - return ExpirationAction.LOCAL_INVALIDATE; - } else { - return ExpirationAttributes.DEFAULT.getAction(); - } - } - - public void fromData(DataInput in) throws IOException, ClassNotFoundException - { - versionId = in.readInt(); - attrProperties = (HashMap)DataSerializer.readObject(in); - } - - public void toData(DataOutput out) throws IOException - { - out.writeInt(versionId); - DataSerializer.writeObject(attrProperties, out); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/bcp.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/bcp.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/bcp.java deleted file mode 100644 index 563df6c..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/bcp.java +++ /dev/null @@ -1,527 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.PrintWriter; -import java.lang.reflect.Method; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -import com.gemstone.gemfire.cache.Cache; -import com.gemstone.gemfire.cache.CacheFactory; -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.QueryResults; -import com.gemstone.gemfire.internal.tools.gfsh.app.command.task.QueryTask; -import com.gemstone.gemfire.internal.tools.gfsh.app.misc.util.ReflectionUtil; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.ObjectUtil; -import com.gemstone.gemfire.internal.tools.gfsh.app.util.OutputUtil; -import com.gemstone.gemfire.internal.tools.gfsh.command.CommandResults; - -/** - * Bulk copy. - * @author dpark - * - */ -public class bcp implements CommandExecutable -{ - private Gfsh gfsh; - - public bcp(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("bcp <region path> {in | out} <data file>"); - gfsh.println(" [-k] [-v]"); - gfsh.println(" [-r <row terminator>]"); - gfsh.println(" [-t <field terminator>]"); - gfsh.println(" [-F <first row>]"); - gfsh.println(" [-L <last row>]"); - gfsh.println(" [-b <batch size>]"); - gfsh.println(" [-d <date format>]"); - gfsh.println(" [-f <value key field>]"); - gfsh.println(" Bulk-copy region entries to a file or bulk-copy file contents to region."); - gfsh.println(" The region path can be absolute or relative. Note that if the region is"); - gfsh.println(" a partitioned region then the 'out' option retrieves data only from"); - gfsh.println(" the local dataset of the connected server due to the potentially large"); - gfsh.println(" size of the partitioend region."); - gfsh.println(" -k Copy key fields. If both -k and -v are specified then the key field"); - gfsh.println(" takes precedence."); - gfsh.println(" -v Copy value fields. If both -k and -v are specified then the key field"); - gfsh.println(" takes precedence."); - gfsh.println(" -r Row terminator character. Default: platform specific."); - gfsh.println(" -t Field terminator charater. Default: ,"); - gfsh.println(" -F The number of the first row in the file to load."); - gfsh.println(" -L The number of the last row in the file to load."); - gfsh.println(" -b The batch size. Default: 1000"); - gfsh.println(" -d The date format (conforms to SimpleDateFormat). Teh format must be"); - gfsh.println(" enclosed in double quotes. Default: \"EEE MMM dd HH:mm:ss zzz yyyy\""); - gfsh.println(" -f The name of the key field to store or load."); - gfsh.println(" Default:"); - gfsh.println(" bcp <region path> out <file> -v -r \\n -t , -F 1 -b 1000 \\"); - gfsh.println(" -d \"EEE MMM dd HH:mm:ss zzz yyyy\""); - gfsh.println(" Example:"); - gfsh.println(" bcp /prices out price_out -t ,"); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("bcp -?")) { - help(); - } else { - bcp(command); - } - } - - private void bcp(String command) throws Exception - { - ArrayList<String> list = new ArrayList(); - gfsh.parseCommand(command, list); - if (list.size() < 4) { - gfsh.println("Error: incomplete bcp command. Run bcp -? for help."); - return; - } - - // Parse command inputs - String regionPath = list.get(1); - String directionType = list.get(2); - String filePath = list.get(3); - - // region - Cache cache = CacheFactory.getAnyInstance(); - String fullPath = gfsh.getFullPath(regionPath, gfsh.getCurrentPath()); - Region region = cache.getRegion(fullPath); - if (region == null) { - gfsh.println("Error: region undefined - " + fullPath); - return; - } - - // in | out - boolean isIn = false; - if (directionType.equalsIgnoreCase("in")) { - isIn = true; - } else if (directionType.equalsIgnoreCase("out")) { - isIn = false; - } else { - gfsh.println("Error: invalid direction type - " + directionType); - return; - } - - // file - File file = new File(filePath); - if (isIn) { - if (file.exists() == false) { - gfsh.println("Error: input file does not exist - " + file.getAbsolutePath()); - return; - } - } else { - if (file.exists()) { - gfsh.println("Error: output file already exists - " + file.getAbsolutePath()); - return; - } - } - - // options - String fieldTerminator = ","; - String rowTerminator = "\n"; - int firstRow = 1; - int lastRow = -1; - int batchSize = 1000; - SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); - String valueKeyFieldName = null; - boolean printKeys = false; - boolean printValues = false; - for (int i = 0; i < list.size(); i++) { - String val = list.get(i); - if (val.equals("-t")) { - i++; - if (list.size() > i) { - fieldTerminator = list.get(i); - } - } else if (val.equals("-r")) { - i++; - if (list.size() > i) { - rowTerminator = list.get(i); - rowTerminator = "\r\n"; - } - } else if (val.equals("-F")) { - i++; - if (list.size() > i) { - val = list.get(i); - firstRow = Integer.parseInt(val); - } - } else if (val.equals("-L")) { - i++; - if (list.size() > i) { - val = list.get(i); - lastRow = Integer.parseInt(val); - } - } else if (val.equals("-b")) { - i++; - if (list.size() > i) { - val = list.get(i); - batchSize = Integer.parseInt(val); - } - } else if (val.equals("-d")) { - i++; - if (list.size() > i) { - String str = list.get(i); - dateFormat = new SimpleDateFormat(str); - } - } else if (val.equals("-f")) { - i++; - if (list.size() > i) { - valueKeyFieldName = list.get(i); - } - } else if (val.equals("-k")) { - printKeys = true; - } else if (val.equals("-v")) { - printValues = true; - } - } - - if (isIn) { - bcpIn(region, file, fieldTerminator, rowTerminator, firstRow, lastRow, batchSize, valueKeyFieldName); - } else { - if (printKeys == false && printValues == false) { - printValues = true; - } - bcpOut(fullPath, file, fieldTerminator, rowTerminator, firstRow, lastRow, batchSize, printKeys, printValues, dateFormat, valueKeyFieldName); - } - } - - private void bcpIn(Region region, File file, - String fieldTerminator, String rowTerminator, - int firstRow, int lastRow, int batchSize, String valueKeyFieldName) throws Exception - { - BufferedReader reader = new BufferedReader(new FileReader(file)); - try { - bcpIn(region, reader, file, fieldTerminator, rowTerminator, firstRow, lastRow, batchSize, valueKeyFieldName); - } finally { - reader.close(); - } - } - - private void bcpIn(Region region, BufferedReader reader, File file, - String fieldTerminator, String rowTerminator, - int firstRow, int lastRow, int batchSize, String valueKeyFieldName) throws Exception - { - if (lastRow < 0) { - lastRow = Integer.MAX_VALUE; - } - - Class keyClass = null; - Class valueClass = null; - String keyMethodNames[] = new String[0]; - String valueMethodNames[] = null; - Map keySetterMap = null; - Map valueSetterMap = null; - Object key = null; - Object value = null; - SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy"); - Method valueKeyGetterMethod = null; - - String line = reader.readLine(); - String split[]; - HashMap map = new HashMap(); - int count = 0; - int rowCount = 0; - - long startTime = System.currentTimeMillis(); - while (line != null) { - line = line.trim(); - if (line.length() == 0) { - line = reader.readLine(); - continue; - } - - // comment - if (line.startsWith("#")) { - if (line.startsWith(OutputUtil.TAG_KEY)) { - int endIndex = line.indexOf(fieldTerminator); - String keyClassName; - if (endIndex == -1) { - keyClassName = line.substring(5); - } else { - keyClassName = line.substring(5, endIndex); - } - keyClassName = keyClassName.trim(); - keyClass = Class.forName(keyClassName); - } else if (line.startsWith(OutputUtil.TAG_VALUE_KEY)) { - if (valueKeyFieldName == null) { - int endIndex = line.indexOf(fieldTerminator); - String dateFormatString; - if (endIndex == -1) { - valueKeyFieldName = line.substring(11); - } else { - valueKeyFieldName = line.substring(11, endIndex); - } - } - valueKeyFieldName = valueKeyFieldName.trim(); - Map valueGetterMap = ReflectionUtil.getAllGettersMap(valueClass); - valueKeyGetterMethod = (Method)valueGetterMap.get("get" + valueKeyFieldName); - } else if (line.startsWith(OutputUtil.TAG_VALUE)) { - int endIndex = line.indexOf(fieldTerminator); - String valueClassName; - if (endIndex == -1) { - valueClassName = line.substring(7); - } else { - valueClassName = line.substring(7, endIndex); - } - valueClassName = valueClassName.trim(); - valueClass = Class.forName(valueClassName); - } else if (line.startsWith(OutputUtil.TAG_DATE_FORMAT)) { - int endIndex = line.indexOf(fieldTerminator); - String dateFormatString; - if (endIndex == -1) { - dateFormatString = line.substring(13); - } else { - dateFormatString = line.substring(13, endIndex); - } - dateFormatString = dateFormatString.trim(); - dateFormat = new SimpleDateFormat(dateFormatString); - } else if (line.startsWith(OutputUtil.TAG_COLUMN_SEPARATOR)) { - // header - String keyHeader = null; - String valueHeader = null; - String header = line.substring(2); - int index = header.indexOf(OutputUtil.TAG_COLUMN_SEPARATOR); - if (index != -1) { - // key & value - if (keyClass != null) { - keyHeader = header.substring(0, index); - keyMethodNames = keyHeader.split(","); - for (int i = 0; i < keyMethodNames.length; i++) { - keyMethodNames[i] = "set" + keyMethodNames[i]; - } - keySetterMap = ReflectionUtil.getAllSettersMap(keyClass); - } - index = index + 2; - } else { - index = 0; - } - - if (valueClass != null) { - valueHeader = header.substring(index); - valueMethodNames = valueHeader.split(","); - for (int i = 0; i < valueMethodNames.length; i++) { - valueMethodNames[i] = "set" + valueMethodNames[i]; - } - valueSetterMap = ReflectionUtil.getAllSettersMap(valueClass); - } - } - } else { - - count++; - if (firstRow <= count && count <= lastRow) { - // data - String tokens[] = getTokens(line); - int j = 0; - if (keyClass != null) { - key = updateObject(keyClass, keySetterMap, keyMethodNames, tokens, 0, dateFormat); - } - if (valueClass != null) { - value = updateObject(valueClass, valueSetterMap, valueMethodNames, tokens, keyMethodNames.length, dateFormat); - } - if (keyClass == null && valueKeyGetterMethod != null) { - key = valueKeyGetterMethod.invoke(value, (Object[])null); - } - - if (key == null) { - gfsh.println("Error: key is undefined. Use the option '-f' to specify the column (field) name."); - return; - } - map.put(key, value); - if (map.size() == batchSize) { - region.putAll(map); - rowCount+= map.size(); - map.clear(); - } - - } else if (count > lastRow) { - break; - } - } - - line = reader.readLine(); - } - - if (map.size() > 0) { - region.putAll(map); - rowCount+= map.size(); - } - long stopTime = System.currentTimeMillis(); - - gfsh.println("bcp in complete"); - gfsh.println(" To (region): " + region.getFullPath()); - gfsh.println(" From (file): " + file.getAbsolutePath()); - gfsh.println(" Row count: " + rowCount); - if (gfsh.isShowTime()) { - gfsh.println(" elapsed (msec): " + (stopTime - startTime)); - } - } - - private Object updateObject(Class clazz, - Map<String, Method> setterMap, - String[] setterMethodNames, - String[] tokens, - int startTokenIndex, - SimpleDateFormat dateFormat) throws Exception - { - String value = tokens[startTokenIndex]; - if (clazz == byte.class || clazz == Byte.class) { - return Byte.parseByte(value); - } else if (clazz == char.class || clazz == Character.class) { - return value.charAt(0); - } else if (clazz == short.class || clazz == Short.class) { - return Short.parseShort(value); - } else if (clazz == int.class || clazz == Integer.class) { - return Integer.parseInt(value); - } else if (clazz == long.class || clazz == Long.class) { - return Long.parseLong(value); - } else if (clazz == float.class || clazz == Float.class) { - return Float.parseFloat(value); - } else if (clazz == double.class || clazz == Double.class) { - return Double.parseDouble(value); - } else if (clazz == Date.class) { - return dateFormat.parse(value); - } else if (clazz == String.class) { - return value; - } - Object obj = clazz.newInstance(); - for (int i = 0; i < setterMethodNames.length; i++) { - ObjectUtil.updateObject(gfsh, setterMap, obj, setterMethodNames[i], tokens[startTokenIndex + i], dateFormat, true); - } - return obj; - } - - - private static String[] getTokens(String line) - { - // HBAN,23.82,300,23.79,800,"Thu, ""test"", 'helo' Jun 08 09:41:19 EDT 2006",99895,1094931009,82,99895,8,HBAN - ArrayList list = new ArrayList(); - boolean openQuote = false; - String value = ""; - for (int i = 0; i < line.length(); i++) { - char c = line.charAt(i); - - if (c == ',') { - if (openQuote == false) { - value = value.trim(); - if (value.startsWith("\"") && value.indexOf(" ") != -1) { - value = value.substring(1); - if (value.endsWith("\"")) { - value = value.substring(0, value.length() - 1); - } - } - - list.add(value); - value = ""; - continue; - } - } else if (c == '"') { - openQuote = !openQuote; - } - value += c; - } - list.add(value); - return (String[])list.toArray(new String[0]); - } - - private void bcpOut(String regionPath, File file, - String fieldTerminator, String rowTerminator, - int firstRow, int lastRow, int batchSize, - boolean printKeys, boolean printValues, - SimpleDateFormat dateFormat, - String valueKeyFieldName) throws IOException - { - PrintWriter writer = new PrintWriter(file); - try { - bcpOut(regionPath, writer, file, fieldTerminator, rowTerminator, firstRow, lastRow, batchSize, printKeys, printValues, dateFormat, valueKeyFieldName); - } finally { - writer.close(); - } - } - - private void bcpOut(String regionPath, PrintWriter writer, File file, - String fieldTerminator, String rowTerminator, - int firstRow, int lastRow, int batchSize, - boolean printKeys, boolean printValues, - SimpleDateFormat dateFormat, - String valueKeyFieldName) throws IOException - { - int totalPrinted = 0; - int actualSize = 0; - boolean printHeader = true; - int printType = OutputUtil.TYPE_VALUES; - if (printKeys && printValues) { - printType = OutputUtil.TYPE_KEYS_VALUES; - } else if (printKeys) { - printType = OutputUtil.TYPE_KEYS; - } - String taskRegionPath = regionPath; - - long startTime = System.currentTimeMillis(); - do { - CommandResults cr = gfsh.getCommandClient().execute(new QueryTask(taskRegionPath, batchSize, true)); - if (cr.getCode() == QueryTask.ERROR_QUERY) { - gfsh.println(cr.getCodeMessage()); - return; - } - QueryResults results = (QueryResults) cr.getDataObject(); - if (results == null || results.getResults() == null) { - gfsh.println("No results"); - return; - } - - Map map = (Map)results.getResults(); - if (map.size() == 0) { - gfsh.println("Region empty. File not created."); - writer.close(); - file.delete(); - return; - } - OutputUtil.printEntries(writer, map, fieldTerminator, rowTerminator, firstRow, lastRow, printType, printHeader, dateFormat, valueKeyFieldName); - totalPrinted += map.size(); - actualSize = results.getActualSize(); - taskRegionPath = null; - printHeader = false; - } while (totalPrinted < actualSize); - - long stopTime = System.currentTimeMillis(); - writer.close(); - - gfsh.println("bcp out complete"); - gfsh.println(" From (region): " + regionPath); - gfsh.println(" To (file): " + file.getAbsolutePath()); - gfsh.println(" Row count: " + totalPrinted); - if (gfsh.isShowTime()) { - gfsh.println(" elapsed (msec): " + (stopTime - startTime)); - } - - } - - public static void main(String args[]) { - - String line = "H\"B\"AN,23.82,300,23.79,800,\"Thu, \"test\", 'helo' Jun 08 09:41:19 EDT 2006\",99895,1094931009,82,99895,8,HBAN"; - String tokens[] = getTokens(line); - System.out.println(line); - for (int i = 0; i < tokens.length; i++) { - System.out.print(tokens[i] + ","); - } - System.out.println(); - for (int i = 0; i < tokens.length; i++) { - System.out.println(tokens[i]); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/49d99d4e/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/cd.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/cd.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/cd.java deleted file mode 100644 index d9a33dc..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/tools/gfsh/app/commands/cd.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.gemstone.gemfire.internal.tools.gfsh.app.commands; - -import com.gemstone.gemfire.cache.Region; -import com.gemstone.gemfire.internal.tools.gfsh.app.CommandExecutable; -import com.gemstone.gemfire.internal.tools.gfsh.app.Gfsh; - -public class cd implements CommandExecutable -{ - private Gfsh gfsh; - - private String previousPath; - - public cd(Gfsh gfsh) - { - this.gfsh = gfsh; - } - - public void help() - { - gfsh.println("cd [-] | [-?] <region path>"); - gfsh.println(" Change region path."); - gfsh.println(" - Change region path to the previous path."); - gfsh.println(); - } - - public void execute(String command) throws Exception - { - if (command.startsWith("cd -?")) { - help(); - } else if (command.equals("cd -")) { - cd_prev(); - } else { - cd(command); - } - } - - private void cd_prev() - { - chdir(previousPath); - } - - private void cd(String command) - { - int index = command.indexOf(" "); - if (index == -1) { - chdir("/"); - } else { - String newPath = command.substring(index).trim(); - chdir(newPath); - } - } - - private void chdir(String newPath) - { - if (newPath == null) { - return; - } - - String currentPath = gfsh.getCurrentPath(); - String fullPath = gfsh.getFullPath(newPath, currentPath); - if (fullPath == null) { - gfsh.println("Error: invalid region path"); - } else if (fullPath.equals("/")) { - gfsh.setCurrentRegion(null); - gfsh.setCurrentPath(fullPath); - previousPath = currentPath; - } else { - Region currentRegion = gfsh.getCache().getRegion(fullPath); - if (currentRegion == null) { - gfsh.println("Error: undefined region path " + fullPath); - return; - } else { - gfsh.setCurrentPath(fullPath); - } - gfsh.setCurrentRegion(currentRegion); - previousPath = currentPath; - } - } -}
