Search in sources :

Example 6 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeReplaceUnnamed.

/**
   * Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with {@link CacheXml} element that does
   * not have a name or id attribute, <code>pdx</code>. It should replace <code>pdx</code> element.
   * 
   * @throws Exception
   * @since GemFire 8.1
   */
@Test
public void testAddNewNodeReplaceUnnamed() 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.testAddNewNodeReplaceUnnamed.xml")));
    nodes = XmlUtils.query(changes, xPath, xPathContext);
    assertEquals(1, nodes.getLength());
    element = (Element) nodes.item(0);
    assertEquals("bar", XmlUtils.getAttribute(element, "disk-store-name"));
    assertEquals(CacheXml.GEODE_NAMESPACE, element.getNamespaceURI());
    final XmlEntity xmlEntity = XmlEntity.builder().withType("pdx").withConfig(changes).build();
    XmlUtils.addNewNode(config, xmlEntity);
    nodes = XmlUtils.query(config, xPath, xPathContext);
    assertEquals(1, nodes.getLength());
    element = (Element) nodes.item(0);
    assertEquals("bar", XmlUtils.getAttribute(element, "disk-store-name"));
    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 7 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class XmlUtilsAddNewNodeJUnitTest method testAddNewNodeNewUnnamedExtension.

/**
   * Tests {@link XmlUtils#addNewNode(Document, XmlEntity)} with an {@link Extension} that does not
   * have a name or id attribute. It should be added to the end of the config xml. Attempts a name
   * collision with test:region, it should not collide with the similarly named cache:region
   * element.
   * 
   * @throws Exception
   * @since GemFire 8.1
   */
@Test
public void testAddNewNodeNewUnnamedExtension() throws Exception {
    final String xPath = "/cache:cache/test:region";
    NodeList nodes = XmlUtils.query(config, xPath, xPathContext);
    assertEquals(0, nodes.getLength());
    final Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testAddNewNodeNewUnnamedExtension.xml")));
    nodes = XmlUtils.query(changes, xPath, xPathContext);
    assertEquals(1, nodes.getLength());
    Element element = (Element) nodes.item(0);
    assertEquals(TEST_NAMESPACE, element.getNamespaceURI());
    assertEquals("test:region", element.getNodeName());
    final XmlEntity xmlEntity = XmlEntity.builder().withType("region").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(TEST_NAMESPACE, element.getNamespaceURI());
    assertEquals("test:region", element.getNodeName());
    final List<Node> childElements = getElementNodes(config.getFirstChild().getChildNodes());
    assertEquals("test:cache", childElements.get(5).getNodeName());
    assertEquals("test:region", childElements.get(6).getNodeName());
    assertEquals(7, childElements.size());
}
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 8 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class XmlUtilsAddNewNodeJUnitTest method testDeleteNodeUnnamedExtension.

/**
   * 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 remove the existing
   * <code>test:cache</code> element.
   * 
   * @throws Exception
   * @since GemFire 8.1
   */
@Test
public void testDeleteNodeUnnamedExtension() 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 Document changes = XmlUtils.createDocumentFromReader(new InputStreamReader(this.getClass().getResourceAsStream("XmlUtilsAddNewNodeJUnitTest.testDeleteNodeUnnamedExtension.xml")));
    nodes = XmlUtils.query(changes, xPath, xPathContext);
    assertEquals(0, nodes.getLength());
    final XmlEntity xmlEntity = XmlEntity.builder().withType("cache").withNamespace(TEST_PREFIX, TEST_NAMESPACE).withConfig(changes).build();
    XmlUtils.deleteNode(config, xmlEntity);
    nodes = XmlUtils.query(config, xPath, xPathContext);
    assertEquals(0, nodes.getLength());
}
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 9 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class CreateMockCacheExtensionFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CacheFactory.getAnyInstance();
    if (!(cache instanceof Extensible)) {
        throw new FunctionException("Not extensible cache.");
    }
    final String value = (String) ((Object[]) context.getArguments())[0];
    @SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
    final MockCacheExtension extension = new MockCacheExtension(value);
    extension.beforeCreate(extensible, cache);
    extension.onCreate(extensible, extensible);
    final XmlEntity xmlEntity = XmlEntity.builder().withType(ELEMENT_CACHE).withNamespace(PREFIX, NAMESPACE).build();
    final ResultSender<Object> resultSender = context.getResultSender();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock cache extension created on \"{0}\"", new Object[] { memberNameOrId })));
}
Also used : XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Extensible(org.apache.geode.internal.cache.extension.Extensible) FunctionException(org.apache.geode.cache.execute.FunctionException) Cache(org.apache.geode.cache.Cache)

Example 10 with XmlEntity

use of org.apache.geode.management.internal.configuration.domain.XmlEntity in project geode by apache.

the class CreateMockRegionExtensionFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CacheFactory.getAnyInstance();
    final Region<?, ?> region = cache.getRegion((String) ((Object[]) context.getArguments())[0]);
    if (!(region instanceof Extensible)) {
        throw new FunctionException("Not extensible region.");
    }
    final String value = (String) ((Object[]) context.getArguments())[1];
    @SuppressWarnings("unchecked") final Extensible<Region<?, ?>> extensible = (Extensible<Region<?, ?>>) region;
    final MockRegionExtension extension = new MockRegionExtension(value);
    extension.beforeCreate(extensible, cache);
    extension.onCreate(extensible, extensible);
    XmlEntity xmlEntity = new XmlEntity(CacheXml.REGION, "name", region.getName());
    final ResultSender<Object> resultSender = context.getResultSender();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    resultSender.lastResult(new CliFunctionResult(memberNameOrId, xmlEntity, CliStrings.format("Mock region extension \"{0}\" created on \"{1}\"", new Object[] { region.getFullPath(), memberNameOrId })));
}
Also used : Extensible(org.apache.geode.internal.cache.extension.Extensible) FunctionException(org.apache.geode.cache.execute.FunctionException) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache)

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