Skip to content

Commit

Permalink
GEODE-2404: Added gfsh support for destroying a lucene index
Browse files Browse the repository at this point in the history
  • Loading branch information
boglesby committed Mar 23, 2017
1 parent 5ed0b4d commit b89427f
Show file tree
Hide file tree
Showing 20 changed files with 906 additions and 380 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public final class Version implements Comparable<Version> {
/** byte used as ordinal to represent this <code>Version</code> */
private final short ordinal;

public static final int HIGHEST_VERSION = 50;
public static final int HIGHEST_VERSION = 55;

private static final Version[] VALUES = new Version[HIGHEST_VERSION + 1];

Expand Down Expand Up @@ -180,7 +180,12 @@ public final class Version implements Comparable<Version> {
public static final Version GFE_90 =
new Version("GFE", "9.0", (byte) 9, (byte) 0, (byte) 0, (byte) 0, GFE_90_ORDINAL);

private static final byte GFE_91_ORDINAL = 50;
private static final byte GEODE_110_ORDINAL = 50;

public static final Version GEODE_110 =
new Version("GEODE", "1.1.0", (byte) 9, (byte) 0, (byte) 1, (byte) 0, GEODE_110_ORDINAL);

private static final byte GFE_91_ORDINAL = 55;

public static final Version GFE_91 =
new Version("GFE", "9.1", (byte) 9, (byte) 1, (byte) 0, (byte) 0, GFE_91_ORDINAL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3886,6 +3886,10 @@ public void removeRegionListener(RegionListener l) {
this.regionListeners.remove(l);
}

public Set<RegionListener> getRegionListeners() {
return Collections.unmodifiableSet(this.regionListeners);
}

@SuppressWarnings("unchecked")
public <T extends CacheService> T getService(Class<T> clazz) {
return (T) services.get(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,14 @@ private static void initializeAllCommands() {
gfe90Commands.put(MessageType.QUERY_WITH_PARAMETERS, QueryWithParametersGeode10.getCommand());
gfe90Commands.put(MessageType.QUERY, QueryGeode10.getCommand());
}
{
Map<Integer, Command> geode110Commands = new HashMap<Integer, Command>();
geode110Commands.putAll(ALL_COMMANDS.get(Version.GFE_90));
ALL_COMMANDS.put(Version.GEODE_110, geode110Commands);
}
{
Map<Integer, Command> gfe91Commands = new HashMap<Integer, Command>();
gfe91Commands.putAll(ALL_COMMANDS.get(Version.GFE_90));
gfe91Commands.putAll(ALL_COMMANDS.get(Version.GEODE_110));
ALL_COMMANDS.put(Version.GFE_91, gfe91Commands);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7669,14 +7669,16 @@ public class LocalizedStrings {
"Caught the following exception attempting waitUntilFlushed and will return:");

public static final StringId LuceneService_INDEX_0_NOT_FOUND_IN_REGION_1 =
new StringId(6651, "Lucene index {0} was not found in region {1}.");
public static final StringId LuceneService_DESTROYED_INDEX_0_FROM_REGION_1 =
new StringId(6652, "Destroyed Lucene index {0} from region {1}.");
new StringId(6651, "Lucene index {0} was not found in region {1}");
public static final StringId LuceneService_DESTROYED_INDEX_0_FROM_1_REGION_2 =
new StringId(6652, "Destroyed Lucene index {1} from {0} region {2}");

public static final StringId PoolFactoryImpl_CAUGHT_EXCEPTION_ATTEMPTING_TO_ADD_REMOTE_LOCATOR_0 =
new StringId(6653,
"Caught the following exception attempting to add remote locator {0}. The locator will be ignored.");

public static final StringId LuceneService_NO_INDEXES_WERE_FOUND_IN_REGION_0 =
new StringId(6654, "No Lucene indexes were found in region {0}");
/** Testing strings, messageId 90000-99999 **/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
import javax.xml.xpath.XPathExpressionException;

import org.apache.geode.internal.Assert;
import org.apache.geode.internal.Version;
import org.apache.geode.internal.VersionedDataSerializable;
import org.apache.logging.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import org.apache.geode.DataSerializable;
import org.apache.geode.DataSerializer;
import org.apache.geode.InternalGemFireError;
import org.apache.geode.cache.Cache;
Expand All @@ -54,7 +55,7 @@
*
*
*/
public class XmlEntity implements DataSerializable {
public class XmlEntity implements VersionedDataSerializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = LogService.getLogger();

Expand All @@ -69,6 +70,10 @@ public class XmlEntity implements DataSerializable {

private String namespace = CacheXml.GEODE_NAMESPACE;

private String childPrefix;

private String childNamespace;

/**
* Default constructor for serialization only.
*
Expand Down Expand Up @@ -113,25 +118,56 @@ public XmlEntity(final String parentType, final String parentKey, final String p
// TODO consider parent as nested XmlEntity type.
this.parentType = parentType;
this.type = childType;
initializeSearchString(parentKey, parentValue, this.prefix, childKey, childValue);

// no init();
}

/****
* Construct a new XmlEntity while creating Xml from the cache using the element which has
* attributes matching those given
*
* @param parentType Parent type of the XML element to search for. Should be one of the constants
* from the {@link CacheXml} class. For example, CacheXml.REGION.
*
* @param parentKey Identifier for the parent elements such "name/id"
* @param parentValue Value of the identifier
* @param childPrefix Namespace prefix for the child element such as "lucene"
* @param childNamespace Namespace for the child element such as
* "http://geode.apache.org/schema/lucene"
* @param childType Child type of the XML element to search for within the parent . Should be one
* of the constants from the {@link CacheXml} class. For example, CacheXml.INDEX.
* @param childKey Identifier for the child element such as "name/id"
* @param childValue Value of the child element identifier
*/
public XmlEntity(final String parentType, final String parentKey, final String parentValue,
final String childPrefix, final String childNamespace, final String childType,
final String childKey, final String childValue) {
// Note: Do not invoke init
this.parentType = parentType;
this.type = childType;
this.childPrefix = childPrefix;
this.childNamespace = childNamespace;
initializeSearchString(parentKey, parentValue, childPrefix, childKey, childValue);
}

private void initializeSearchString(final String parentKey, final String parentValue,
final String childPrefix, final String childKey, final String childValue) {
StringBuffer sb = new StringBuffer();
sb.append("//").append(prefix).append(':').append(parentType);
sb.append("//").append(this.prefix).append(':').append(this.parentType);

if (!StringUtils.isBlank(parentKey) && !StringUtils.isBlank(parentValue)) {
sb.append("[@").append(parentKey).append("='").append(parentValue).append("']");
}

sb.append("/").append(prefix).append(':').append(childType);
sb.append("/").append(childPrefix).append(':').append(this.type);

if (!StringUtils.isBlank(childKey) && !StringUtils.isBlank(childValue)) {
sb.append("[@").append(childKey).append("='").append(childValue).append("']");
}
this.searchString = sb.toString();

// no init();
}


/**
* Initialize new instances. Called from {@link #XmlEntity(String, String, String)} and
* {@link XmlEntityBuilder#build()}.
Expand Down Expand Up @@ -312,6 +348,24 @@ public String getPrefix() {
return prefix;
}

/**
* Gets the prefix for the child element.
*
* @return XML element prefix for the child element
*/
public String getChildPrefix() {
return this.childPrefix;
}

/**
* Gets the namespace for the child element.
*
* @return XML element namespace for the child element
*/
public String getChildNamespace() {
return this.childNamespace;
}

@Override
public String toString() {
return "XmlEntity [namespace=" + namespace + ", type=" + this.type + ", attributes="
Expand Down Expand Up @@ -356,6 +410,12 @@ public boolean equals(Object obj) {

@Override
public void toData(DataOutput out) throws IOException {
toDataPre_GFE_9_1_0_0(out);
DataSerializer.writeString(this.childPrefix, out);
DataSerializer.writeString(this.childNamespace, out);
}

public void toDataPre_GFE_9_1_0_0(DataOutput out) throws IOException {
DataSerializer.writeString(this.type, out);
DataSerializer.writeObject(this.attributes, out);
DataSerializer.writeString(this.xmlDefinition, out);
Expand All @@ -366,6 +426,12 @@ public void toData(DataOutput out) throws IOException {

@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
fromDataPre_GFE_9_1_0_0(in);
this.childPrefix = DataSerializer.readString(in);
this.childNamespace = DataSerializer.readString(in);
}

public void fromDataPre_GFE_9_1_0_0(DataInput in) throws IOException, ClassNotFoundException {
this.type = DataSerializer.readString(in);
this.attributes = DataSerializer.readObject(in);
this.xmlDefinition = DataSerializer.readString(in);
Expand All @@ -384,6 +450,11 @@ public static final XmlEntityBuilder builder() {
return new XmlEntityBuilder();
}

@Override
public Version[] getSerializationVersions() {
return new Version[] {Version.GFE_91};
}

/**
* Builder for {@link XmlEntity}. Default values are as described in {@link XmlEntity}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,12 @@ public static void deleteNode(Document doc, XmlEntity xmlEntity) throws Exceptio
*/
public static NodeList getNodes(Document doc, XmlEntity xmlEntity)
throws XPathExpressionException {
return query(doc, xmlEntity.getSearchString(),
new XPathContext(xmlEntity.getPrefix(), xmlEntity.getNamespace()));
XPathContext context = new XPathContext();
context.addNamespace(xmlEntity.getPrefix(), xmlEntity.getNamespace());
if (xmlEntity.getChildPrefix() != null) {
context.addNamespace(xmlEntity.getChildPrefix(), xmlEntity.getChildNamespace());
}
return query(doc, xmlEntity.getSearchString(), context);
}

/**
Expand Down
Loading

0 comments on commit b89427f

Please sign in to comment.