use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class GatewaySenderCreateFunction method execute.
@Override
public void execute(FunctionContext context) {
ResultSender<Object> resultSender = context.getResultSender();
Cache cache = CacheFactory.getAnyInstance();
String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
GatewaySenderFunctionArgs gatewaySenderCreateArgs = (GatewaySenderFunctionArgs) context.getArguments();
try {
GatewaySender createdGatewaySender = createGatewaySender(cache, gatewaySenderCreateArgs);
XmlEntity xmlEntity = new XmlEntity(CacheXml.GATEWAY_SENDER, "id", gatewaySenderCreateArgs.getId());
resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format(CliStrings.CREATE_GATEWAYSENDER__MSG__GATEWAYSENDER_0_CREATED_ON_1, new Object[] { createdGatewaySender.getId(), memberNameOrId })));
} catch (GatewaySenderException e) {
resultSender.lastResult(handleException(memberNameOrId, e.getMessage(), e));
} catch (Exception e) {
String exceptionMsg = e.getMessage();
if (exceptionMsg == null) {
exceptionMsg = CliUtil.stackTraceAsString(e);
}
resultSender.lastResult(handleException(memberNameOrId, exceptionMsg, e));
}
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeNewNamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element with a
* <code>name</code> attribute, <code>region</code>. It should be added after other
* <code>region</code> elements.
*
* @throws Exception
* @throws XPathExpressionException
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeNewNamed() throws Exception {
final String xPath = "/cache:cache/cache:region[@name='r3']";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeNewNamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("region").withAttribute("name", "r3").withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final List<Node> childNodes = getElementNodes(config.getFirstChild().getChildNodes());
assertEquals("r2", childNodes.get(4).getAttributes().getNamedItem("name").getNodeValue());
assertEquals("r3", childNodes.get(5).getAttributes().getNamedItem("name").getNodeValue());
assertEquals("test:cache", childNodes.get(6).getNodeName());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeReplaceNamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element with a
* <code>name</code> attribute, <code>region</code>. It should replace existing
* <code>region</code> element with same <code>name</code>.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeReplaceNamed() 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.testAddNewNodeReplaceNamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(0, element.getChildNodes().getLength());
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("region").withAttribute("name", "r1").withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(0, element.getChildNodes().getLength());
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeReplaceUnnamedExtension.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with an {@link Extension} that does not
* have a name or id attribute, <code>test:cache</code>. It should replace the existing
* <code>test:cache</code> element.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeReplaceUnnamedExtension() throws Exception {
final String xPath = "/cache:cache/test:cache";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals("1", XmlUtils.getAttribute(element, "value"));
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
final org.w3c.dom.Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeReplaceUnnamedExtension.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals("2", XmlUtils.getAttribute(element, "value"));
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("cache").withNamespace(TEST_PREFIX, TEST_NAMESPACE).withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals("2", XmlUtils.getAttribute(element, "value"));
assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
}
use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.
the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeNewUnnamed.
/**
* Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element that does
* not have a name or id attribute, <code>jndi-bindings</code>. It should be added between
* <code>pdx</code> and <code>region</code> elements.
*
* @throws Exception
* @since GemFire 8.1
*/
@Test
public void testAddNewNodeNewUnnamed() throws Exception {
final String xPath = "/cache:cache/cache:jndi-bindings";
NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(0, nodes.getLength());
final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeNewUnnamed.xml")));
nodes = XmlUtils.query(changes, xPath, xPathContext);
assertEquals(1, nodes.getLength());
Element element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final XmlEntity xmlEntity = XmlEntity.builder().withType("jndi-bindings").withConfig(changes).build();
XmlUtils.addNewNode(config, xmlEntity);
nodes = XmlUtils.query(config, xPath, xPathContext);
assertEquals(1, nodes.getLength());
element = (Element) nodes.item(0);
assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
final List<Node> childElements = getElementNodes(config.getFirstChild().getChildNodes());
assertEquals("pdx", childElements.get(2).getNodeName());
assertEquals("jndi-bindings", childElements.get(3).getNodeName());
assertEquals("region", childElements.get(4).getNodeName());
}
Aggregations