use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class ClientHttpRequestTest method shouldBeMockable.
@Test
public void shouldBeMockable() throws Exception {
ClientHttpRequest mockClientHttpRequest = mock(ClientHttpRequest.class);
Link mockLink = mock(Link.class);
when(mockClientHttpRequest.getLink()).thenReturn(mockLink);
assertThat(mockClientHttpRequest.getLink()).isSameAs(mockLink);
}
use of org.apache.geode.management.internal.web.domain.Link 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.Link in project geode by apache.
the class AbstractHttpOperationInvoker method getAttribute.
// TODO research the use of Jolokia instead
/**
* Read the attribute identified by name from a remote resource identified by name. The intent of
* this method is to return the value of an attribute on an MBean located in the remote
* MBeanServer.
*
* @param resourceName name/url of the remote resource from which to fetch the attribute value.
* @param attributeName name of the attribute who's value will be fetched.
* @return the value of the named attribute for the named resource (typically an MBean).
* @throws MBeanAccessException if an MBean access error occurs.
* @throws RestApiCallForCommandNotFoundException if the REST API web service endpoint for
* accessing an attribute on an MBean does not exists!
* @see #createHttpRequest(org.apache.geode.management.internal.web.domain.Link)
* @see #findLink(String)
* @see #send(org.apache.geode.management.internal.web.http.ClientHttpRequest, Class)
*/
@Override
public Object getAttribute(final String resourceName, final String attributeName) {
final Link link = findLink(MBEAN_ATTRIBUTE_LINK_RELATION);
if (link != null) {
final ClientHttpRequest request = createHttpRequest(link);
request.addParameterValues("resourceName", resourceName);
request.addParameterValues("attributeName", attributeName);
try {
return IOUtils.deserializeObject(send(request, byte[].class));
} catch (IOException e) {
throw new MBeanAccessException(String.format("De-serializing the result of accessing attribute (%1$s) on MBean (%2$s) failed!", resourceName, attributeName), e);
} catch (ClassNotFoundException e) {
throw new MBeanAccessException(String.format("The Class type of the result when accessing attribute (%1$s) on MBean (%2$s) was not found!", resourceName, attributeName), e);
}
} else {
printSevere("Getting the value of attribute (%1$s) on MBean (%2$s) is currently an unsupported operation!", attributeName, resourceName);
throw new RestApiCallForCommandNotFoundException(MBEAN_ATTRIBUTE_LINK_RELATION);
}
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class AbstractHttpOperationInvoker method queryNames.
/**
* This method searches the MBean server, based on the OperationsInvoker's JMX-based or remoting
* capable MBean server connection, for MBeans matching a specific ObjectName or matching an
* ObjectName pattern along with satisfying criteria from the Query expression.
*
* @param objectName the ObjectName or pattern for which matching MBeans in the target MBean
* server will be returned.
* @param queryExpression the JMX-based query expression used to filter matching MBeans.
* @return a set of ObjectName's matching MBeans in the MBean server matching the ObjectName and
* Query expression criteria.
* @see #createHttpRequest(org.apache.geode.management.internal.web.domain.Link)
* @see #findLink(String)
* @see #send(org.apache.geode.management.internal.web.http.ClientHttpRequest, Class)
* @see javax.management.ObjectName
* @see javax.management.QueryExp
*/
@Override
@SuppressWarnings("unchecked")
public Set<ObjectName> queryNames(final ObjectName objectName, final QueryExp queryExpression) {
final Link link = findLink(MBEAN_QUERY_LINK_RELATION);
if (link != null) {
final ClientHttpRequest request = createHttpRequest(link);
request.setContent(new QueryParameterSource(objectName, queryExpression));
try {
return (Set<ObjectName>) IOUtils.deserializeObject(send(request, byte[].class));
} catch (Exception e) {
throw new MBeanAccessException(String.format("An error occurred while querying for MBean names using ObjectName pattern (%1$s) and Query expression (%2$s)!", objectName, queryExpression), e);
}
} else {
printSevere("Running a query to get the ObjectNames of all MBeans matching the ObjectName pattern (%1$s) and Query expression (%2$s) is currently unsupported!", objectName, queryExpression);
throw new RestApiCallForCommandNotFoundException(MBEAN_QUERY_LINK_RELATION);
}
}
use of org.apache.geode.management.internal.web.domain.Link in project geode by apache.
the class RestHttpOperationInvokerJUnitTest method testFindAndResolveLink.
@Test
public void testFindAndResolveLink() throws Exception {
final Map<String, String> commandOptions = new HashMap<>();
commandOptions.put("name", "BarnesN'Noble");
Link link = getOperationInvoker().findLink(createCommandRequest("list-libraries", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries", toString(link.getHref()));
link = getOperationInvoker().findLink(createCommandRequest("get-library", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}", toString(link.getHref()));
commandOptions.put("author", "J.K.Rowling");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}", toString(link.getHref()));
commandOptions.put("category", "sci-fi");
commandOptions.put("year", "1998");
commandOptions.put("bogus", "data");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{category}/{year}", toString(link.getHref()));
commandOptions.remove("category");
link = getOperationInvoker().findLink(createCommandRequest("list-books", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{author}/{year}", toString(link.getHref()));
commandOptions.put("category", "fantasy");
commandOptions.put("isbn", "0-123456789");
commandOptions.put("title", "Harry Potter");
link = getOperationInvoker().findLink(createCommandRequest("add-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books", toString(link.getHref()));
commandOptions.remove("isbn");
link = getOperationInvoker().findLink(createCommandRequest("get-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{title}", toString(link.getHref()));
link = getOperationInvoker().findLink(createCommandRequest("remove-book", commandOptions));
assertNotNull(link);
assertEquals("http://host.domain.com/service/v1/libraries/{name}/books/{isbn}", toString(link.getHref()));
}
Aggregations