Search in sources :

Example 26 with XmlEntity

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));
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) Cache(org.apache.geode.cache.Cache)

Example 27 with XmlEntity

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());
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 28 with XmlEntity

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());
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 29 with XmlEntity

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());
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InputStreamReader(java.io.InputStreamReader) Document(org.w3c.dom.Document) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with XmlEntity

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());
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

XmlEntity (org.apache.geode.management.internal.configuration.domain.XmlEntity)46 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)25 DistributedMember (org.apache.geode.distributed.DistributedMember)18 Cache (org.apache.geode.cache.Cache)17 Result (org.apache.geode.management.cli.Result)17 CliCommand (org.springframework.shell.core.annotation.CliCommand)16 CliMetaData (org.apache.geode.management.cli.CliMetaData)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 InternalCache (org.apache.geode.internal.cache.InternalCache)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)11 Test (org.junit.Test)10 InputStreamReader (java.io.InputStreamReader)9 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)9 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 Document (org.w3c.dom.Document)9 Element (org.w3c.dom.Element)9 NodeList (org.w3c.dom.NodeList)9 ConverterHint (org.apache.geode.management.cli.ConverterHint)7