Let's try this again...

Hi Gabor-

As Jens pointed out, there are 2 REST APIs available in Apache Geode (and by 
extension, VMware Tanzu GemFire).

There is the Developer REST API (see 
doc<https://geode.apache.org/docs/guide/112/rest_apps/book_intro.html> [1]) 
used by applications (clients) to perform REST-like interactions (over HTTP) 
with a GemFire/Geode cluster.

Then, there is the Management REST API (a.k.a. Admin REST API).  As Jens 
pointed out, this is the REST API (interface) used by Gfsh to communicate with 
the Manager when issuing Gfsh remote commands (e.g. `create region`) over HTTP 
(i.e. `gfsh> connect --use-http ...`).

The Developer and Admin REST APIs are NOT the same API and are intended for 
very different purposes. The later (i.e. Admin REST API) is also not (yet) 
public (or publicly known).  The REST API used by SDG's 
@EnableClusterConfiguration annotation is in fact the Admin REST API.

In Apache Geode 1.12, this Admin REST API is in fact exposed via the "gemfire" 
URL context.

By way of example, when I start a cluster using Gfsh with Apache Geode 1.12, 
like so...

````
$ echo $GEMFIRE
/Users/jblum/pivdev/apache-geode-1.12.0


$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  /
 / /__/ / ____/  _____/ / /    / /
/______/_/      /______/_/    /_/    1.12.0

Monitor and Manage Apache Geode

gfsh>start locator --name=LocatorOne --log-level=config
Starting a Geode Locator in /Users/jblum/pivdev/lab/LocatorOne...
.........
Locator in /Users/jblum/pivdev/lab/LocatorOne on 10.99.199.24[10334] as 
LocatorOne is currently online.
Process ID: 80007
Uptime: 11 seconds
Geode Version: 1.12.0
Java Version: 1.8.0_241
Log File: /Users/jblum/pivdev/lab/LocatorOne/LocatorOne.log
JVM Arguments: -Dgemfire.enable-cluster-configuration=true 
-Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire.log-level=config 
-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true 
-Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: 
/Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-core-1.12.0.jar:/Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-dependencies.jar

Successfully connected to: JMX Manager [host=10.99.199.24, port=1099]

Cluster configuration service is up and running.



gfsh>start server --name=ServerOne --log-level=config
Starting a Geode Server in /Users/jblum/pivdev/lab/ServerOne...
......
Server in /Users/jblum/pivdev/lab/ServerOne on 10.99.199.24[40404] as ServerOne 
is currently online.
Process ID: 80038
Uptime: 4 seconds
Geode Version: 1.12.0
Java Version: 1.8.0_241
Log File: /Users/jblum/pivdev/lab/ServerOne/ServerOne.log
JVM Arguments: -Dgemfire.default.locators=10.99.199.24[10334] 
-Dgemfire.start-dev-rest-api=false -Dgemfire.use-cluster-configuration=true 
-Dgemfire.log-level=config -XX:OnOutOfMemoryError=kill -KILL %p 
-Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true 
-Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: 
/Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-core-1.12.0.jar:/Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-dependencies.jar



gfsh>list members
Member Count : 2

   Name    | Id
---------- | ------------------------------------------------------------------
LocatorOne | 10.99.199.24(LocatorOne:80007:locator)<ec><v0>:41000 [Coordinator]
ServerOne  | 10.99.199.24(ServerOne:80038)<v1>:41001



gfsh>list regions
No Regions Found

````

Then, when I look in the log file for the Locator/Manager, I see...

````
$ less LocatorOne/LocatorOne.log

[info 2020/09/08 12:48:22.244 PDT <main> tid=0x1]
---------------------------------------------------------------------------

  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with this
  work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  License for the specific language governing permissions and limitations
  under the License.

---------------------------------------------------------------------------
Build-Date: 2020-03-27 11:09:15 -0700
Build-Id: echobravo 0
Build-Java-Vendor: AdoptOpenJDK
Build-Java-Version: 1.8.0_242
Build-Platform: Mac OS X 10.14.6 x86_64
Product-Name: Apache Geode
Product-Version: 1.12.0
Source-Date: 2020-03-26 14:00:52 -0700
Source-Repository: release/1.12.0
Source-Revision: 57f17bfa7589b41aea6c05ea8bcddba40285c228
Running on: 10.99.199.24/10.99.199.24, 8 cpu(s), x86_64 Mac OS X 10.13.6
Communications version: 115
Process ID: 80007
User: jblum
Current dir: /Users/jblum/pivdev/lab/LocatorOne
Home dir: /Users/jblum
Command Line Parameters:
  -Dgemfire.enable-cluster-configuration=true
  -Dgemfire.load-cluster-configuration-from-dir=false
  -Dgemfire.log-level=config
  -Dgemfire.launcher.registerSignalHandlers=true
  -Djava.awt.headless=true
  -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class Path:
  /Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-core-1.12.0.jar
  /Users/jblum/pivdev/apache-geode-1.12.0/lib/geode-dependencies.jar

...
..
.

[info 2020/09/08 12:48:25.686 PDT <main> tid=0x1] Initializing region 
_ConfigurationRegion

[info 2020/09/08 12:48:25.688 PDT <main> tid=0x1] Region /_ConfigurationRegion 
was created on this member with the persistent id 
/10.99.199.24:/Users/jblum/pivdev/lab/LocatorOne/ConfigDiskDir_LocatorOne 
created at timestamp 1599594505686 version 0 diskStoreId 
2de2cd3007294280-a97a21f42817cf3a name LocatorOne.

[info 2020/09/08 12:48:25.689 PDT <main> tid=0x1] Initialization of region 
_ConfigurationRegion completed

[info 2020/09/08 12:48:25.706 PDT <main> tid=0x1] Cluster configuration service 
start up completed successfully and is now running ....

[info 2020/09/08 12:48:25.711 PDT <main> tid=0x1] 
GEODE_HOME:/Users/jblum/pivdev/apache-geode-1.12.0

[info 2020/09/08 12:48:25.712 PDT <main> tid=0x1] Located war: 
geode-web-management at location: 
file:/Users/jblum/pivdev/apache-geode-1.12.0/tools/Extensions/geode-web-management-1.12.0.war

[info 2020/09/08 12:48:25.713 PDT <main> tid=0x1] Geode Property 
enable-management-rest-service=true Geode Management Rest Service is enabled.

[info 2020/09/08 12:48:25.757 PDT <main> tid=0x1] Adding webapp /management

[info 2020/09/08 12:48:25.757 PDT <main> tid=0x1] Attempting to start HTTP 
service on port (7070) at bind-address (0.0.0.0)...

[info 2020/09/08 12:48:27.069 PDT <main> tid=0x1] Initializing Servlet 
'management'

...
..
.


[info 2020/09/08 12:48:31.880 PDT <locator request thread 1> tid=0x23] 
GEODE_HOME:/Users/jblum/pivdev/apache-geode-1.12.0

[info 2020/09/08 12:48:31.881 PDT <locator request thread 1> tid=0x23] Located 
war: geode-web at location: 
file:/Users/jblum/pivdev/apache-geode-1.12.0/tools/Extensions/geode-web-1.12.0.war

[info 2020/09/08 12:48:31.881 PDT <locator request thread 1> tid=0x23] 
GEODE_HOME:/Users/jblum/pivdev/apache-geode-1.12.0

[info 2020/09/08 12:48:31.882 PDT <locator request thread 1> tid=0x23] Located 
war: geode-pulse at location: 
file:/Users/jblum/pivdev/apache-geode-1.12.0/tools/Pulse/geode-pulse-1.12.0.war

[info 2020/09/08 12:48:31.883 PDT <locator request thread 1> tid=0x23] Adding 
webapp /gemfire

[info 2020/09/08 12:48:32.161 PDT <locator request thread 1> tid=0x23] 
Initializing Servlet 'geode-mgmt'

[info 2020/09/08 12:48:32.474 PDT <locator request thread 1> tid=0x23] 
Initializing ExecutorService 'asyncTaskExecutor'

[info 2020/09/08 12:48:32.674 PDT <locator request thread 1> tid=0x23] 
Completed initialization in 513 ms

[info 2020/09/08 12:48:32.676 PDT <locator request thread 1> tid=0x23] Adding 
webapp /geode-mgmt

[info 2020/09/08 12:48:32.906 PDT <locator request thread 1> tid=0x23] 
Initializing Servlet 'geode-mgmt'

[info 2020/09/08 12:48:33.331 PDT <locator request thread 1> tid=0x23] 
Initializing ExecutorService 'asyncTaskExecutor'

[info 2020/09/08 12:48:33.514 PDT <locator request thread 1> tid=0x23] 
Completed initialization in 608 ms

[info 2020/09/08 12:48:33.516 PDT <locator request thread 1> tid=0x23] Adding 
webapp /pulse

...

````

Specifically...


[info 2020/09/08 12:48:31.883 PDT <locator request thread 1> tid=0x23] Adding 
webapp /gemfire

This would be the Admin REST API Webapp context (i.e. "/gemfire") being added 
to the embedded HTTP service (Tomcat) when the Locator/Manager starts up.

I have test SBDG app very similar to yours that pushes cluster configuration 
metadata (and specifically, a Region schema object definition) to the cluster 
when the Spring Boot app runs.

It creates a "/Customers" Region.

After running the app, in Gfsh I see...


````
gfsh>list regions
List of regions
---------------
Customers



gfsh>describe region --name=/Customers
Name            : Customers
Data Policy     : partition
Hosting Members : ServerOne

Non-Default Attributes Shared By Hosting Members

 Type  |    Name     | Value
------ | ----------- | ---------
Region | size        | 16
       | data-policy | PARTITION



gfsh>query --query="SELECT customer.name FROM /Customers customer"
Result : true
Limit  : 100
Rows   : 16

Result
----------
Play Doe
Cookie Doe
Fro Doe
Lan Doe
Sour Doe
Pie Doe
Jon Doe
Jane Doe
Bob Doe
...

````

This clearly suggests the "/gemfire" Webapp context is available for the Admin 
REST API.  Of course, it would be remiss if I did not also have Integration 
Test<https://github.com/spring-projects/spring-data-geode/blob/master/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java>
 [2] in the SDG test suite that would cover this exact scenario.

Finally, we do see in the Geode codebase itself, the registration of the Admin 
REST API at the "/gemfire" Webapp context, 
here<https://github.com/apache/geode/blob/rel/v1.12.0/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java#L215>
 [3].

This makes DATAGEODE-366<https://jira.spring.io/browse/DATAGEODE-366> [4] a 
moot point.

Anyway, hope this helps and if you have more questions, just respond to this 
thread.

Regards,

John B.



[1] https://geode.apache.org/docs/guide/112/rest_apps/book_intro.html
[2] 
https://github.com/spring-projects/spring-data-geode/blob/master/spring-data-geode/src/test/java/org/springframework/data/gemfire/config/annotation/EnableClusterConfigurationIntegrationTests.java
[3] 
https://github.com/apache/geode/blob/rel/v1.12.0/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java#L215
[4] https://jira.spring.io/browse/DATAGEODE-366


________________________________
From: Gábor Kendelényi <gabor.kendele...@ericsson.com>
Sent: Monday, September 7, 2020 6:32 AM
To: John Blum (Pivotal) <jb...@pivotal.io>
Subject: Geode REST API - Question


Hi John,



I’m sorry if this is not the best channel to contact you with my Geode 
problem/question but I’m not that confident in my Java + Geode knowledge to 
post a question like this on Stack Overflow.

I hope you have some spare time to help me out with this issue. I have read one 
of your 
post<https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_59459852_started-2Dgeode-2Dspring-2Dboot-2Dand-2Dsave-2Dto-2Dremote-2Dregion-2Dbut-2Dfailed-2Dto-2Dstart-2Dbean-2Dgem&d=DwMFAw&c=lnl9vOaLMzsy2niBC8-h_K-7QJuNJEsFrzdndhuJ3Sw&r=fQ_QMlhH-KZeo9O7jPfIHA&m=x9CrZ1_lTKqF2aCFkYelstUGBjO7W7FRLh_2ATm8EEQ&s=mQvoCFsfviRIOB7b7-JW5XRUPTN2VV1Ip1jAwWryad8&e=>
 many times but I’m still missing something.



Task

Basically my task is to integrate Geode into our test Kubernetes cluster and 
Spring Boot application.



Geode

On the Geode side I have enabled the REST API by setting the 
“-Dgemfire.start-dev-rest-api” property true.

It’s working properly.

bash-4.4# curl -i -X GET http://localhost:7070/gemfire-api/v1

HTTP/1.1 200 OK

Date: Mon, 07 Sep 2020 12:39:43 GMT

Location: http://localhost:7070/gemfire-api/v1



Spring Boot App

On the App side I’m using the below annotations in order I could do the region 
creation part through the client:

@ClientCacheApplication(useHttp=true)

@EnableClusterConfiguration

@EnableEntityDefinedRegions





Problem

When I check the application log during start app I can see that the client is 
trying to use a slightly different URL for the RegionCreation POST request:

org.springframework.context.ApplicationContextException: Failed to start bean 
'gemfireClusterSchemaObjectInitializer'; nested exception is 
org.springframework.web.client.HttpClientErrorException$NotFound: 404 Not 
Found: [HTTP ERROR 404 Not Found

URI: /gemfire/v1/regions

STATUS: 404

MESSAGE: Not Found

SERVLET: null

]





So instead of “/gemfire-api/v1” it’s trying to access the “/gemfire/v1” url.



Could you help me figure out why is that? Is this a bug?



Regards, Gábor

Reply via email to