Skip to content

Commit b58f404

Browse files
committed
Finishing touches: HTTP DELETE with body possbile if wired 'manually'
1 parent fe4775c commit b58f404

File tree

4 files changed

+31
-765
lines changed

4 files changed

+31
-765
lines changed

app/save-and-restore/app/pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@
4141
<version>${jgit.version}</version>
4242
</dependency>
4343

44-
45-
<dependency>
46-
<groupId>com.sun.jersey</groupId>
47-
<artifactId>jersey-core</artifactId>
48-
<version>1.19</version>
49-
</dependency>
50-
<dependency>
51-
<groupId>com.sun.jersey</groupId>
52-
<artifactId>jersey-client</artifactId>
53-
<version>1.19</version>
54-
</dependency>
55-
5644
<dependency>
5745
<groupId>com.fasterxml.jackson.jaxrs</groupId>
5846
<artifactId>jackson-jaxrs-json-provider</artifactId>

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/client/SaveAndRestoreClientImpl.java

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public List<Node> getChildNodes(String uniqueNodeId) throws SaveAndRestoreClient
129129

130130
/**
131131
* {@inheritDoc}
132+
*
132133
* @param parentsUniqueId Unique id of the parent {@link Node} for the new {@link Node}
133134
* @param node A {@link Node} object that should be created (=persisted).
134135
* @return {@inheritDoc}
@@ -178,31 +179,30 @@ public Node updateNode(Node nodeToUpdate, boolean customTimeForMigration) {
178179

179180
/**
180181
* {@inheritDoc}
182+
*
181183
* @param nodeIds List of unique {@link Node} ids.
182184
*/
183185
@Override
184186
public void deleteNodes(List<String> nodeIds) {
185-
// Native HttpClient does not support body in DELETE, so need to delete one by one...
186-
nodeIds.forEach(id -> {
187-
try {
188-
HttpRequest request = HttpRequest.newBuilder()
189-
.uri(URI.create(Preferences.jmasarServiceUrl + "/node/" + id))
190-
.DELETE()
191-
.header("Content-Type", CONTENT_TYPE_JSON)
192-
.header("Authorization", getBasicAuthenticationHeader())
193-
.build();
194-
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
195-
if (response.statusCode() != 200) {
196-
throw new SaveAndRestoreClientException("Failed to delete node " + id + ", " + response.body());
197-
}
198-
} catch (Exception e) {
199-
throw new RuntimeException(e);
187+
try {
188+
HttpRequest request = HttpRequest.newBuilder()
189+
.uri(URI.create(Preferences.jmasarServiceUrl + "/node"))
190+
.method("DELETE", HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(nodeIds)))
191+
.header("Content-Type", CONTENT_TYPE_JSON)
192+
.header("Authorization", getBasicAuthenticationHeader())
193+
.build();
194+
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
195+
if (response.statusCode() != 200) {
196+
throw new SaveAndRestoreClientException("Failed to delete nodes: " + response.body());
200197
}
201-
});
198+
} catch (Exception e) {
199+
throw new RuntimeException(e);
200+
}
202201
}
203202

204203
/**
205204
* {@inheritDoc}
205+
*
206206
* @return {@inheritDoc}
207207
*/
208208
@Override
@@ -213,6 +213,7 @@ public List<Tag> getAllTags() {
213213

214214
/**
215215
* {@inheritDoc}
216+
*
216217
* @param sourceNodeIds List of unique {@link Node} ids.
217218
* @param targetNodeId The unique id of the parent {@link Node} to which the source {@link Node}s are moved.
218219
* @return
@@ -281,8 +282,9 @@ public ConfigurationData getConfigurationData(String nodeId) {
281282

282283
/**
283284
* {@inheritDoc}
284-
* @param parentNodeId Non-null and non-empty unique id of an existing parent {@link Node},
285-
* which must be of type {@link org.phoebus.applications.saveandrestore.model.NodeType#FOLDER}.
285+
*
286+
* @param parentNodeId Non-null and non-empty unique id of an existing parent {@link Node},
287+
* which must be of type {@link org.phoebus.applications.saveandrestore.model.NodeType#FOLDER}.
286288
* @param configuration {@link ConfigurationData} object
287289
* @return
288290
*/
@@ -307,6 +309,7 @@ public Configuration createConfiguration(String parentNodeId, Configuration conf
307309

308310
/**
309311
* {@inheritDoc}
312+
*
310313
* @param configuration
311314
* @return
312315
*/
@@ -337,8 +340,9 @@ public SnapshotData getSnapshotData(String uniqueId) {
337340

338341
/**
339342
* {@inheritDoc}
343+
*
340344
* @param parentNodeId The unique id of the configuration {@link Node} associated with the {@link Snapshot}
341-
* @param snapshot The {@link Snapshot} data object.
345+
* @param snapshot The {@link Snapshot} data object.
342346
* @return {@inheritDoc}
343347
*/
344348
@Override
@@ -381,7 +385,8 @@ public Snapshot updateSnapshot(Snapshot snapshot) {
381385

382386
/**
383387
* {@inheritDoc}
384-
* @param parentNodeId The parent {@link Node} for the new {@link CompositeSnapshot}
388+
*
389+
* @param parentNodeId The parent {@link Node} for the new {@link CompositeSnapshot}
385390
* @param compositeSnapshot The data object
386391
* @return A {@link CompositeSnapshot} as persisted by the service.
387392
*/
@@ -490,6 +495,7 @@ public Filter saveFilter(Filter filter) {
490495

491496
/**
492497
* {@inheritDoc}
498+
*
493499
* @return {@inheritDoc}
494500
*/
495501
@Override
@@ -549,10 +555,10 @@ public List<Node> addTag(TagData tagData) {
549555
public List<Node> deleteTag(TagData tagData) {
550556
try {
551557
HttpRequest request = HttpRequest.newBuilder()
552-
.uri(URI.create(Preferences.jmasarServiceUrl + "/delete-tags"))
558+
.uri(URI.create(Preferences.jmasarServiceUrl + "/tags"))
553559
.header("Content-Type", CONTENT_TYPE_JSON)
554560
.header("Authorization", getBasicAuthenticationHeader())
555-
.POST(HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(tagData)))
561+
.method("DELETE", HttpRequest.BodyPublishers.ofString(OBJECT_MAPPER.writeValueAsString(tagData)))
556562
.build();
557563
HttpResponse<String> response = CLIENT.send(request, HttpResponse.BodyHandlers.ofString());
558564
if (response.statusCode() != 200) {
@@ -593,6 +599,7 @@ public UserData authenticate(String userName, String password) {
593599

594600
/**
595601
* {@inheritDoc}
602+
*
596603
* @param snapshotItems A {@link List} of {@link SnapshotItem}s
597604
* @return {@inheritDoc}
598605
*/
@@ -618,6 +625,7 @@ public List<RestoreResult> restore(List<SnapshotItem> snapshotItems) {
618625

619626
/**
620627
* {@inheritDoc}
628+
*
621629
* @param snapshotNodeId Unique id of a snapshot
622630
* @return {@inheritDoc}
623631
*/
@@ -643,6 +651,7 @@ public List<RestoreResult> restore(String snapshotNodeId) {
643651

644652
/**
645653
* {@inheritDoc}
654+
*
646655
* @param configurationNodeId The unique id of the {@link Configuration} for which to take the snapshot
647656
* @return {@inheritDoc}
648657
*/

0 commit comments

Comments
 (0)