Search in sources :

Example 1 with LinkIndex

use of org.apache.geode.management.internal.web.domain.LinkIndex in project geode by apache.

the class RestHttpOperationInvokerJUnitTest method setUp.

@Before
public void setUp() throws Exception {
    final Link listLibraries = new Link("list-libraries", toUri("http://host.domain.com/service/v1/libraries"));
    final Link getLibrary = new Link("get-library", toUri("http://host.domain.com/service/v1/libraries/{name}"));
    final Link listBooks = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books"));
    final Link listBooksByAuthor = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}"));
    final Link listBooksByAuthorAndCategory = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}"));
    final Link listBooksByAuthorAndYear = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{year}"));
    final Link listBooksByAuthorCategoryAndYear = new Link("list-books", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}/{year}"));
    final Link addBook = new Link("add-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books"), HttpMethod.POST);
    final Link getBookByIsbn = new Link("get-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}"));
    final Link getBookByTitle = new Link("get-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{title}"));
    final Link removeBook = new Link("remove-book", toUri("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}"), HttpMethod.DELETE);
    linkIndex = new LinkIndex();
    linkIndex.addAll(listLibraries, getLibrary, listBooks, listBooksByAuthor, listBooksByAuthorAndCategory, listBooksByAuthorAndYear, listBooksByAuthorCategoryAndYear, addBook, getBookByIsbn, getBookByTitle, removeBook);
    assertEquals(11, linkIndex.size());
    operationInvoker = new RestHttpOperationInvoker(linkIndex);
    assertSame(linkIndex, operationInvoker.getLinkIndex());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) Link(org.apache.geode.management.internal.web.domain.Link) Before(org.junit.Before)

Example 2 with LinkIndex

use of org.apache.geode.management.internal.web.domain.LinkIndex in project geode by apache.

the class ShellCommandsControllerJUnitTest method testIndex.

@Test
public void testIndex() {
    List<String> commands = getCliCommands();
    assertNotNull(commands);
    assertFalse(commands.isEmpty());
    LinkIndex linkIndex = controller.index("https");
    assertNotNull(linkIndex);
    assertFalse(linkIndex.isEmpty());
    List<String> linkCommands = new ArrayList<>(linkIndex.size());
    for (Link link : linkIndex) {
        linkCommands.add(link.getRelation());
    }
    assertEquals(linkIndex.size(), linkCommands.size());
    List<String> missingLinkCommands = new ArrayList<>(commands);
    missingLinkCommands.removeAll(linkCommands);
    assertTrue(String.format("The GemFire Management REST API Link Index is missing Link(s) for the following command(s): %1$s", missingLinkCommands), missingLinkCommands.isEmpty());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) ArrayList(java.util.ArrayList) Link(org.apache.geode.management.internal.web.domain.Link) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 3 with LinkIndex

use of org.apache.geode.management.internal.web.domain.LinkIndex in project geode by apache.

the class QueryNamesOverHttpDUnitTest method testQueryNameOverHttp.

@Test
public void testQueryNameOverHttp() throws Exception {
    LinkIndex links = new LinkIndex();
    links.add(new Link("mbean-query", new URI("http://localhost:" + locatorRule.getHttpPort() + "/gemfire/v1/mbean/query"), HttpMethod.POST));
    RestHttpOperationInvoker invoker = new RestHttpOperationInvoker(links, mock(Gfsh.class), new HashMap<>());
    ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,*");
    QueryExp query = Query.eq(Query.attr("Name"), Query.value("mock"));
    Set<ObjectName> names = invoker.queryNames(objectName, query);
    assertTrue(names.isEmpty());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) QueryExp(javax.management.QueryExp) URI(java.net.URI) Link(org.apache.geode.management.internal.web.domain.Link) ObjectName(javax.management.ObjectName) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with LinkIndex

use of org.apache.geode.management.internal.web.domain.LinkIndex in project geode by apache.

the class ShellCommands method httpConnect.

private Result httpConnect(Map<String, String> sslConfigProps, boolean useSsl, String url, String userName, String passwordToUse) {
    Gfsh gfsh = getGfsh();
    try {
        Map<String, String> securityProperties = new HashMap<String, String>();
        // at this point, if userName is not empty, password should not be empty either
        if (userName != null && userName.length() > 0) {
            securityProperties.put("security-username", userName);
            securityProperties.put("security-password", passwordToUse);
        }
        if (useSsl) {
            configureHttpsURLConnection(sslConfigProps);
            if (url.startsWith("http:")) {
                url = url.replace("http:", "https:");
            }
        }
        Iterator<String> it = sslConfigProps.keySet().iterator();
        while (it.hasNext()) {
            String secKey = it.next();
            securityProperties.put(secKey, sslConfigProps.get(secKey));
        }
        // This is so that SSL termination results in https URLs being returned
        String query = (url.startsWith("https")) ? "?scheme=https" : "";
        LogWrapper.getInstance().warning(String.format("Sending HTTP request for Link Index at (%1$s)...", url.concat("/index").concat(query)));
        LinkIndex linkIndex = new SimpleHttpRequester(gfsh, CONNECT_LOCATOR_TIMEOUT_MS, securityProperties).exchange(url.concat("/index").concat(query), LinkIndex.class);
        LogWrapper.getInstance().warning(String.format("Received Link Index (%1$s)", linkIndex.toString()));
        HttpOperationInvoker operationInvoker = new RestHttpOperationInvoker(linkIndex, gfsh, url, securityProperties);
        Initializer.init(operationInvoker);
        gfsh.setOperationInvoker(operationInvoker);
        LogWrapper.getInstance().info(CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));
        return ResultBuilder.createInfoResult(CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, operationInvoker.toString()));
    } catch (Exception e) {
        // all other exceptions, just logs it and returns a connection error
        if (!(e instanceof SecurityException) && !(e instanceof AuthenticationFailedException)) {
            return handleExcpetion(e, null);
        }
        // connection error
        if (userName != null) {
            return handleExcpetion(e, null);
        }
        // otherwise, prompt for username and password and retry the conenction
        try {
            userName = gfsh.readText(CliStrings.CONNECT__USERNAME + ": ");
            passwordToUse = gfsh.readPassword(CliStrings.CONNECT__PASSWORD + ": ");
            return httpConnect(sslConfigProps, useSsl, url, userName, passwordToUse);
        } catch (IOException ioe) {
            return handleExcpetion(ioe, null);
        }
    } finally {
        Gfsh.redirectInternalJavaLoggers();
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) IOException(java.io.IOException) AuthenticationFailedException(org.apache.geode.security.AuthenticationFailedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) HttpOperationInvoker(org.apache.geode.management.internal.web.shell.HttpOperationInvoker) RestHttpOperationInvoker(org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker) SimpleHttpRequester(org.apache.geode.management.internal.web.http.support.SimpleHttpRequester) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh)

Example 5 with LinkIndex

use of org.apache.geode.management.internal.web.domain.LinkIndex in project geode by apache.

the class ShellCommandsControllerJUnitTest method testUniqueIndex.

@Test
public void testUniqueIndex() {
    LinkIndex linkIndex = controller.index("https");
    List<String> conflicts = new ArrayList<>();
    Map<String, String> uriRelationMapping = new HashMap<>(linkIndex.size());
    for (Link link : linkIndex) {
        if (uriRelationMapping.containsKey(link.toHttpRequestLine())) {
            conflicts.add(String.format("REST API endpoint (%1$s) for (%2$s) conflicts with the REST API endpoint for (%3$s)", link.toHttpRequestLine(), link.getRelation(), uriRelationMapping.get(link.toHttpRequestLine())));
        } else {
            uriRelationMapping.put(link.toHttpRequestLine(), link.getRelation());
        }
    }
    assertTrue(String.format("Conflicts: %1$s!", conflicts), conflicts.isEmpty());
}
Also used : LinkIndex(org.apache.geode.management.internal.web.domain.LinkIndex) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Link(org.apache.geode.management.internal.web.domain.Link) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

LinkIndex (org.apache.geode.management.internal.web.domain.LinkIndex)7 Link (org.apache.geode.management.internal.web.domain.Link)5 Test (org.junit.Test)5 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)2 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)2 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 LinkedHashMap (java.util.LinkedHashMap)1 ObjectName (javax.management.ObjectName)1 QueryExp (javax.management.QueryExp)1 SimpleHttpRequester (org.apache.geode.management.internal.web.http.support.SimpleHttpRequester)1 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)1 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 Before (org.junit.Before)1