Skip to content

Commit 74abc92

Browse files
committed
delete: add delete namespace endpoint
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
1 parent 440abb3 commit 74abc92

30 files changed

Lines changed: 367 additions & 342 deletions

.github/workflows/headerchecker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Check for headers
3232
run: |
3333
ok=1
34-
readarray -t files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.all }}')"
34+
readarray -t files <<<"$(jq -r '.[]' <<<'${{ steps.files.outputs.added_modified }}')"
3535
for file in ${files[@]}; do
3636
if [[ ($file == *".java") ]]; then
3737
if ! grep -q Copyright "$file"; then

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
## [Unreleased](https://github.com/MarquezProject/marquez/compare/0.27.0...HEAD)
44

5+
### Added
6+
* Add possibility to soft-delete namespaces [`#2244`](https://github.com/MarquezProject/marquez/pull/2244) [@mobuchowski](https://github.com/mobuchowski)
7+
*Adds the ability to "hide" inactive namespaces. The namespaces are being undeleted when relevant OL event is received.*
8+
9+
### Fixed
10+
* Fix bug where job isn't properly deleted [`#2244`](https://github.com/MarquezProject/marquez/pull/2244) [@mobuchowski](https://github.com/mobuchowski)
11+
*It wasn't possible to delete jobs created from events that had `ParentRunFacet`. Now it's possible.*
12+
13+
514
## [0.27.0](https://github.com/MarquezProject/marquez/compare/0.26.0...0.27.0) - 2022-10-24
615

716
### Added

api/src/main/java/marquez/api/NamespaceResource.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.validation.Valid;
1616
import javax.validation.constraints.Min;
1717
import javax.ws.rs.Consumes;
18+
import javax.ws.rs.DELETE;
1819
import javax.ws.rs.DefaultValue;
1920
import javax.ws.rs.GET;
2021
import javax.ws.rs.PUT;
@@ -77,6 +78,23 @@ public Response list(
7778
return Response.ok(new Namespaces(namespaces)).build();
7879
}
7980

81+
@Timed
82+
@ResponseMetered
83+
@ExceptionMetered
84+
@DELETE
85+
@Path("/namespaces/{namespace}")
86+
@Produces(APPLICATION_JSON)
87+
public Response delete(@PathParam("namespace") NamespaceName name) {
88+
final Namespace namespace =
89+
namespaceService
90+
.findBy(name.getValue())
91+
.orElseThrow(() -> new NamespaceNotFoundException(name));
92+
datasetService.deleteByNamespaceName(namespace.getName().getValue());
93+
jobService.deleteByNamespaceName(namespace.getName().getValue());
94+
namespaceService.delete(namespace.getName().getValue());
95+
return Response.ok(namespace).build();
96+
}
97+
8098
@Value
8199
static class Namespaces {
82100
@NonNull

api/src/main/java/marquez/db/Columns.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private Columns() {}
5555
public static final String DATASET_NAME = "dataset_name";
5656
public static final String FACETS = "facets";
5757
public static final String TAGS = "tags";
58+
public static final String IS_HIDDEN = "is_hidden";
5859

5960
/* NAMESPACE ROW COLUMNS */
6061
public static final String CURRENT_OWNER_NAME = "current_owner_name";
@@ -197,6 +198,14 @@ public static boolean booleanOrDefault(
197198
return results.getBoolean(column);
198199
}
199200

201+
public static boolean booleanOrThrow(final ResultSet results, final String column)
202+
throws SQLException {
203+
if (results.getObject(column) == null) {
204+
throw new IllegalArgumentException();
205+
}
206+
return results.getBoolean(column);
207+
}
208+
200209
public static int intOrThrow(final ResultSet results, final String column) throws SQLException {
201210
if (results.getObject(column) == null) {
202211
throw new IllegalArgumentException();

api/src/main/java/marquez/db/DatasetDao.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,24 @@ DatasetRow upsert(
292292
String name,
293293
String physicalName);
294294

295+
@SqlUpdate(
296+
"""
297+
UPDATE datasets d
298+
SET is_hidden = true
299+
FROM namespaces n
300+
WHERE n.uuid=d.namespace_uuid
301+
AND n.name=:namespaceName
302+
""")
303+
void deleteByNamespaceName(String namespaceName);
304+
295305
@SqlQuery(
296306
"""
297-
UPDATE datasets
298-
SET is_hidden = true
299-
FROM dataset_symlinks, namespaces
300-
WHERE dataset_symlinks.dataset_uuid = datasets.uuid
301-
AND namespaces.uuid = dataset_symlinks.namespace_uuid
302-
AND namespaces.name=:namespaceName AND dataset_symlinks.name=:name
303-
RETURNING *
307+
UPDATE datasets d
308+
SET is_hidden = true
309+
FROM namespaces n
310+
WHERE n.uuid = d.namespace_uuid
311+
AND n.name=:namespaceName AND d.name=:name
312+
RETURNING *
304313
""")
305314
Optional<DatasetRow> delete(String namespaceName, String name);
306315

api/src/main/java/marquez/db/JobDao.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ SELECT run_uuid, JSON_AGG(e.facets) AS facets
8888
""")
8989
void delete(String namespaceName, String name);
9090

91+
@SqlUpdate(
92+
"""
93+
UPDATE jobs
94+
SET is_hidden = true
95+
FROM namespaces n
96+
WHERE jobs.namespace_uuid = n.uuid
97+
AND n.name = :namespaceName
98+
""")
99+
void deleteByNamespaceName(String namespaceName);
100+
91101
default Optional<Job> findWithRun(String namespaceName, String jobName) {
92102
Optional<Job> job = findJobByName(namespaceName, jobName);
93103
job.ifPresent(

api/src/main/java/marquez/db/NamespaceDao.java

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,20 @@ default Namespace upsertNamespaceMeta(
7878
@SqlQuery("SELECT * FROM namespaces ORDER BY name LIMIT :limit OFFSET :offset")
7979
List<Namespace> findAll(int limit, int offset);
8080

81+
@SqlQuery("UPDATE namespaces SET is_hidden=false WHERE name = :name RETURNING *")
82+
NamespaceRow undelete(String name);
83+
84+
@SqlUpdate("UPDATE namespaces SET is_hidden=true WHERE name = :name")
85+
void delete(String name);
86+
8187
default NamespaceRow upsertNamespaceRow(
8288
UUID uuid, Instant now, String name, String currentOwnerName) {
8389
doUpsertNamespaceRow(uuid, now, name, currentOwnerName);
84-
return findNamespaceByName(name).orElseThrow();
90+
NamespaceRow namespaceRow = findNamespaceByName(name).orElseThrow();
91+
if (namespaceRow.getIsHidden()) {
92+
namespaceRow = undelete(namespaceRow.getName());
93+
}
94+
return namespaceRow;
8595
}
8696

8797
/**
@@ -99,40 +109,47 @@ default NamespaceRow upsertNamespaceRow(
99109
* @param currentOwnerName
100110
*/
101111
@SqlUpdate(
102-
"INSERT INTO namespaces ( "
103-
+ "uuid, "
104-
+ "created_at, "
105-
+ "updated_at, "
106-
+ "name, "
107-
+ "current_owner_name "
108-
+ ") VALUES ("
109-
+ ":uuid, "
110-
+ ":now, "
111-
+ ":now, "
112-
+ ":name, "
113-
+ ":currentOwnerName) "
114-
+ "ON CONFLICT(name) DO NOTHING")
112+
"""
113+
INSERT INTO namespaces (
114+
uuid,
115+
created_at,
116+
updated_at,
117+
name,
118+
current_owner_name
119+
) VALUES (
120+
:uuid,
121+
:now,
122+
:now,
123+
:name,
124+
:currentOwnerName)
125+
ON CONFLICT(name) DO NOTHING
126+
""")
115127
void doUpsertNamespaceRow(UUID uuid, Instant now, String name, String currentOwnerName);
116128

117129
@SqlQuery(
118-
"INSERT INTO namespaces ( "
119-
+ "uuid, "
120-
+ "created_at, "
121-
+ "updated_at, "
122-
+ "name, "
123-
+ "current_owner_name, "
124-
+ "description "
125-
+ ") VALUES ("
126-
+ ":uuid, "
127-
+ ":now, "
128-
+ ":now, "
129-
+ ":name, "
130-
+ ":currentOwnerName, "
131-
+ ":description "
132-
+ ") ON CONFLICT(name) DO "
133-
+ "UPDATE SET "
134-
+ "updated_at = EXCLUDED.updated_at "
135-
+ "RETURNING *")
130+
"""
131+
INSERT INTO namespaces (
132+
uuid,
133+
created_at,
134+
updated_at,
135+
name,
136+
current_owner_name,
137+
description,
138+
is_hidden
139+
) VALUES (
140+
:uuid,
141+
:now,
142+
:now,
143+
:name,
144+
:currentOwnerName,
145+
:description,
146+
false
147+
) ON CONFLICT(name) DO
148+
UPDATE SET
149+
updated_at = EXCLUDED.updated_at,
150+
is_hidden = false
151+
RETURNING *
152+
""")
136153
NamespaceRow upsertNamespaceRow(
137154
UUID uuid, Instant now, String name, String currentOwnerName, String description);
138155

api/src/main/java/marquez/db/mappers/NamespaceMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package marquez.db.mappers;
77

8+
import static marquez.db.Columns.booleanOrThrow;
89
import static marquez.db.Columns.stringOrNull;
910
import static marquez.db.Columns.stringOrThrow;
1011
import static marquez.db.Columns.timestampOrThrow;
@@ -28,6 +29,7 @@ public Namespace map(@NonNull ResultSet results, @NonNull StatementContext conte
2829
timestampOrThrow(results, Columns.CREATED_AT),
2930
timestampOrThrow(results, Columns.UPDATED_AT),
3031
OwnerName.of(stringOrThrow(results, Columns.CURRENT_OWNER_NAME)),
31-
stringOrNull(results, Columns.DESCRIPTION));
32+
stringOrNull(results, Columns.DESCRIPTION),
33+
booleanOrThrow(results, Columns.IS_HIDDEN));
3234
}
3335
}

api/src/main/java/marquez/db/mappers/NamespaceRowMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package marquez.db.mappers;
77

8+
import static marquez.db.Columns.booleanOrThrow;
89
import static marquez.db.Columns.stringOrNull;
910
import static marquez.db.Columns.stringOrThrow;
1011
import static marquez.db.Columns.timestampOrThrow;
@@ -28,6 +29,7 @@ public NamespaceRow map(@NonNull ResultSet results, @NonNull StatementContext co
2829
timestampOrThrow(results, Columns.UPDATED_AT),
2930
stringOrThrow(results, Columns.NAME),
3031
stringOrNull(results, Columns.DESCRIPTION),
31-
stringOrThrow(results, Columns.CURRENT_OWNER_NAME));
32+
stringOrThrow(results, Columns.CURRENT_OWNER_NAME),
33+
booleanOrThrow(results, Columns.IS_HIDDEN));
3234
}
3335
}

api/src/main/java/marquez/db/models/NamespaceRow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class NamespaceRow {
2020
@NonNull String name;
2121
@Nullable String description;
2222
@NonNull String currentOwnerName;
23+
@NonNull Boolean isHidden;
2324

2425
public Optional<String> getDescription() {
2526
return Optional.ofNullable(description);

0 commit comments

Comments
 (0)