Skip to content

Commit

Permalink
Implementing issue apache#2167 : Create a new REST API (nav, doc upda…
Browse files Browse the repository at this point in the history
…te and DELETE metadata element service)
  • Loading branch information
mattcasters committed Mar 9, 2023
1 parent 9b37b80 commit ff4670c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/hop-user-manual/modules/ROOT/nav.adoc
Expand Up @@ -441,6 +441,7 @@ under the License.
** xref:hop-server/rest-api.adoc[REST api]
** xref:hop-server/web-service.adoc[Web Service]
* xref:hop-tools/index.adoc[Hop Tools]
* xref:hop-rest/index.adoc[Hop REST Web Application]
** xref:hop-tools/hop-conf/hop-conf.adoc[hop-conf]
** xref:hop-tools/hop-encrypt.adoc[hop-encrypt]
** xref:hop-tools/hop-gui.adoc[hop-gui]
Expand Down
53 changes: 50 additions & 3 deletions docs/hop-user-manual/modules/ROOT/pages/hop-rest/index.adoc
Expand Up @@ -24,12 +24,38 @@ under the License.

== Description

The Hop REST web application is deployed as a WAR file `hop-rest-<version>.war`. You can put this archive in the `webapps` folder of your favorite server (e.g. Apache Tomcat). We suggest that you rename it to `hop.war` or that you unzip it in a `hop` folder.
The Hop REST web application is deployed as a WAR file `hop-rest-<version>.war`.
You can put this archive in the `webapps` folder of your favorite server (e.g. Apache Tomcat).
We suggest that you rename it to `hop.war` or that you unzip it in a `hop` folder.

== The base URL

When deployed under a `webapps/hop` folder you will get the services, detailed below, under the base URL of `/hop/api/v1/`.

== Configuration

When the web application starts it will look for an environment variable called `HOP_REST_CONFIG_FOLDER` to determine where it will look for a file called `hop-rest.properties`.
This file can contain the following properties to determine the configuration of the application:

[cols="1,2"]
|===
|Property|Description

|`logLevel`
|The logging level to use, one of `NOTHING`, `ERROR`, `MINIMAL`,
`BASIC`, `DETAILED`, `DEBUG`, or `ROWLEVEL`.

|`metadataExportFile`
|The metadata to use for the web application in the form of a single JSON 'export' file. Use the GUI tools menu or `sh hop-conf.sh --export-metadata` to export metadata to a single file.

|`environmentName`
|In case the `projects` plugin is available it will enable this environment and the underlying project (to be configured on the system, point to a configuration with `HOP_CONFIG_FOLDER`) before starting the application.

|`projectName`
|In case the `projects` plugin is available it will enable this project (to be configured on the system, point to a configuration with `HOP_CONFIG_FOLDER`) before starting the application.

|===

== Metadata services

The metadata services are deployed under sub-path `metadata/`.
Expand Down Expand Up @@ -130,6 +156,29 @@ The metadata services are deployed under sub-path `metadata/`.

|===

=== Delete a metadata element

[cols="1,2"]
|===
|Type
|`DELETE`

|Path
|`metadata/{key}/{name}`

|Arguments
|`key` : the key of the metadata type to save. `name` : the name of the metadata element to delete.

|Produces
|`application/json`

|Example call
|`curl -X DELETE http://localhost:8080/hop/api/v1/metadata/pipeline-run-configuration/Flink/`

|Output
|`Flink`

|===

== Plugins services

Expand Down Expand Up @@ -226,8 +275,6 @@ The body to post can contain the following options (see also: the example above)
* `variables`: a map with variables (or parameters) with their names and values
* `bodyContent`: this will be set as a variable using the body content variable option in the Web Service metadata.



== Execution Information Location services

The execution information location services are deployed under sub-path `location/`.
Expand Down
Expand Up @@ -20,6 +20,7 @@

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
Expand Down Expand Up @@ -128,4 +129,30 @@ public Response saveElement(@PathParam("key") String key, String metadataJson)
return getServerError("Error saving element of type " + key, e, true);
}
}

/**
* Save a metadata element
*
* @param key The key of the type of metadata to delete
* @param elementName The name of the element to delete
* @return
* @throws HopException
*/
@DELETE
@Path("/{key}/{elementName}")
@Produces(MediaType.APPLICATION_JSON)
public Response deleteElement(
@PathParam("key") String key, @PathParam("elementName") String elementName)
throws HopException {
try {
IHopMetadataProvider provider = hop.getMetadataProvider();
Class<IHopMetadata> metadataClass = provider.getMetadataClassForKey(key);
IHopMetadataSerializer<IHopMetadata> serializer = provider.getSerializer(metadataClass);
serializer.delete(elementName);
return Response.ok().entity(elementName).build();
} catch (Exception e) {
return getServerError(
"Error deleting element of type " + key + " with name " + elementName, e, true);
}
}
}

0 comments on commit ff4670c

Please sign in to comment.