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());
}
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());
}
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());
}
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();
}
}
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());
}
Aggregations