use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class LuceneIndexCommands method destroyIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_DESTROY_INDEX, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public Result destroyIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_DESTROY_INDEX__REGION_HELP) final String regionPath) {
if (StringUtils.isBlank(regionPath) || regionPath.equals(Region.SEPARATOR)) {
return ResultBuilder.createInfoResult(CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__REGION_CANNOT_BE_EMPTY));
}
if (indexName != null && StringUtils.isEmpty(indexName)) {
return ResultBuilder.createInfoResult(CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__INDEX_CANNOT_BE_EMPTY));
}
this.securityService.authorizeRegionManage(regionPath);
Result result;
try {
List<CliFunctionResult> accumulatedResults = new ArrayList<>();
final XmlEntity xmlEntity = executeDestroyIndexFunction(accumulatedResults, indexName, regionPath);
result = getDestroyIndexResult(accumulatedResults, indexName, regionPath);
if (xmlEntity != null) {
persistClusterConfiguration(result, () -> {
// Delete the xml entity to remove the index(es) in all groups
getSharedConfiguration().deleteXmlEntity(xmlEntity, null);
});
}
} catch (FunctionInvocationTargetException ignore) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, LuceneCliStrings.LUCENE_DESTROY_INDEX));
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (IllegalArgumentException e) {
result = ResultBuilder.createInfoResult(e.getMessage());
} catch (Throwable t) {
t.printStackTrace();
SystemFailure.checkFailure();
getCache().getLogger().warning(LuceneCliStrings.LUCENE_DESTROY_INDEX__EXCEPTION_MESSAGE, t);
result = ResultBuilder.createGemFireErrorResult(t.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class LuceneIndexCommands method createIndex.
@CliCommand(value = LuceneCliStrings.LUCENE_CREATE_INDEX, help = LuceneCliStrings.LUCENE_CREATE_INDEX__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_DATA })
public // TODO : Add optionContext for indexName
Result createIndex(@CliOption(key = LuceneCliStrings.LUCENE__INDEX_NAME, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__NAME__HELP) final String indexName, @CliOption(key = LuceneCliStrings.LUCENE__REGION_PATH, mandatory = true, optionContext = ConverterHint.REGION_PATH, help = LuceneCliStrings.LUCENE_CREATE_INDEX__REGION_HELP) final String regionPath, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, mandatory = true, help = LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD_HELP) final String[] fields, @CliOption(key = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER, help = LuceneCliStrings.LUCENE_CREATE_INDEX__ANALYZER_HELP) final String[] analyzers) {
Result result;
XmlEntity xmlEntity = null;
this.securityService.authorizeRegionManage(regionPath);
try {
final InternalCache cache = getCache();
// trim fields for any leading trailing spaces.
String[] trimmedFields = Arrays.stream(fields).map(field -> field.trim()).toArray(size -> new String[size]);
LuceneIndexInfo indexInfo = new LuceneIndexInfo(indexName, regionPath, trimmedFields, analyzers);
final ResultCollector<?, ?> rc = this.executeFunctionOnAllMembers(createIndexFunction, indexInfo);
final List<CliFunctionResult> funcResults = (List<CliFunctionResult>) rc.getResult();
final TabularResultData tabularResult = ResultBuilder.createTabularResultData();
for (final CliFunctionResult cliFunctionResult : funcResults) {
tabularResult.accumulate("Member", cliFunctionResult.getMemberIdOrName());
if (cliFunctionResult.isSuccessful()) {
tabularResult.accumulate("Status", "Successfully created lucene index");
// if (xmlEntity == null) {
// xmlEntity = cliFunctionResult.getXmlEntity();
// }
} else {
tabularResult.accumulate("Status", "Failed: " + cliFunctionResult.getMessage());
}
}
result = ResultBuilder.buildResult(tabularResult);
} catch (IllegalArgumentException iae) {
LogWrapper.getInstance().info(iae.getMessage());
result = ResultBuilder.createUserErrorResult(iae.getMessage());
} catch (CommandResultException crex) {
result = crex.getResult();
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class LuceneIndexCommands method executeDestroyIndexFunction.
private XmlEntity executeDestroyIndexFunction(List<CliFunctionResult> accumulatedResults, String indexName, String regionPath) {
// Destroy has three cases:
//
// - no members define the region
// In this case, send the request to all members to handle the case where the index has been
// created, but not the region
//
// - all members define the region
// In this case, send the request to one of the region members to destroy the index on all
// member
//
// - some members define the region; some don't
// In this case, send the request to one of the region members to destroy the index in all the
// region members. Then send the function to the remaining members to handle the case where
// the index has been created, but not the region
XmlEntity xmlEntity = null;
InternalCache cache = getCache();
Set<DistributedMember> regionMembers = getRegionMembers(cache, regionPath);
Set<DistributedMember> normalMembers = getNormalMembers(cache);
LuceneDestroyIndexInfo indexInfo = new LuceneDestroyIndexInfo(indexName, regionPath);
ResultCollector<?, ?> rc;
if (regionMembers.isEmpty()) {
// Attempt to destroy the proxy index on all members
indexInfo.setDefinedDestroyOnly(true);
rc = executeFunction(destroyIndexFunction, indexInfo, normalMembers);
accumulatedResults.addAll((List<CliFunctionResult>) rc.getResult());
} else {
// Attempt to destroy the index on a region member
indexInfo.setDefinedDestroyOnly(false);
Set<DistributedMember> singleMember = new HashSet<>();
singleMember.add(regionMembers.iterator().next());
rc = executeFunction(destroyIndexFunction, indexInfo, singleMember);
List<CliFunctionResult> cliFunctionResults = (List<CliFunctionResult>) rc.getResult();
CliFunctionResult cliFunctionResult = cliFunctionResults.get(0);
xmlEntity = cliFunctionResult.getXmlEntity();
for (DistributedMember regionMember : regionMembers) {
accumulatedResults.add(new CliFunctionResult(regionMember.getId(), cliFunctionResult.isSuccessful(), cliFunctionResult.getMessage()));
}
// If that succeeds, destroy the proxy index(es) on all other members if necessary
if (cliFunctionResult.isSuccessful()) {
normalMembers.removeAll(regionMembers);
if (!normalMembers.isEmpty()) {
indexInfo.setDefinedDestroyOnly(true);
rc = executeFunction(destroyIndexFunction, indexInfo, normalMembers);
accumulatedResults.addAll((List<CliFunctionResult>) rc.getResult());
}
} else {
// @todo Should dummy results be added to the accumulatedResults for the non-region
// members in the failed case
}
}
return xmlEntity;
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testDeleteNodeUnnamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element that does
* not have a name or id attribute, <code>pdx</code>. It should remove the existing
* <code>pdx</code> element.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testDeleteNodeUnnamed() throws Exception {
final String xPath = "/cache:cache/cache:pdx";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals("foo", XmlUtils.getAttribute(element, "disk-store-name"));
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testDeleteNodeUnnamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final XmlEntity xmlEntity = XmlEntity.builder().withType("pdx").withConfig(changes).build();
XmlUtils.deleteNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testDeleteNodeNamed.
/**
* Tests {@link XmlUtils#deleteNode(Document, XmlEntity)} with {@link CacheXml} element with a
* <code>name</code> attribute, <code>region</code>. It should remove existing <code>region</code>
* element with same <code>name</code>.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testDeleteNodeNamed() throws Exception {
final String xPath = "/cache:cache/cache:region[@name='r1']";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals(1, getElementNodes(element.getChildNodes()).size());
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testDeleteNodeNamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final XmlEntity xmlEntity = XmlEntity.builder().withType("region").withAttribute("name", "r1").withConfig(changes).build();
XmlUtils.deleteNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
}
Aggregations