Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcao13 committed Aug 4, 2023
1 parent db095f6 commit 2cb8658
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions smoketest/compose/jfr-datasource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ services:
jfr-datasource:
image: quay.io/cryostat/jfr-datasource:latest
restart: unless-stopped
ports:
- "8080:8080"
expose:
- "8080"
4 changes: 2 additions & 2 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public static boolean deleteByName(String name) {
return delete("name", name) > 0;
}

public static boolean deleteFromTarget(Target target, String name) {
public static boolean deleteFromTarget(Target target, String recordingName) {
ActiveRecording recordingToDelete =
find("target = ?1 and name = ?2", target, name).firstResult();
find("target = ?1 and name = ?2", target, recordingName).firstResult();
if (recordingToDelete != null) {
recordingToDelete.delete();
return true;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -489,10 +489,11 @@ private Tagging createMetadataTagging(Metadata metadata) {

// jfr-datasource handling
@Blocking
public Response doPost(long targetEntityId, long remoteId, URL uploadUrl) throws Exception {
Target target = Target.findById(targetEntityId);
public Response uploadToJFRDatasource(long targetEntityId, long remoteId, URL uploadUrl)
throws Exception {
Target target = Target.getTargetById(targetEntityId);
Objects.requireNonNull(target, "Target from targetId not found");
ActiveRecording recording = ActiveRecording.findById(remoteId);
ActiveRecording recording = target.getRecordingById(remoteId);
Objects.requireNonNull(recording, "ActiveRecording from remoteId not found");
Path recordingPath =
connectionManager.executeConnectedTask(
Expand Down Expand Up @@ -535,8 +536,7 @@ public Response doPost(long targetEntityId, long remoteId, URL uploadUrl) throws
return Response.serverError().build();
})
.await()
.indefinitely(); // The timeout in from the webClient request should be
// sufficient
.indefinitely(); // The timeout from the request should be sufficient
} finally {
fs.deleteIfExists(recordingPath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/cryostat/recordings/Recordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ public Response uploadToGrafana(@RestPath long targetId, @RestPath long remoteId
ConfigProperties.GRAFANA_DATASOURCE_URL, uploadUrl.toString()));
}

return recordingHelper.doPost(targetId, remoteId, uploadUrl);
return recordingHelper.uploadToJFRDatasource(targetId, remoteId, uploadUrl);
} catch (MalformedURLException e) {
throw new NotImplementedException(e);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/cryostat/targets/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public String targetId() {
return this.connectUrl.toString();
}

public static Target getTargetById(long targetId) {
return Target.find("id", targetId).singleResult();
}

public static Target getTargetByConnectUrl(URI connectUrl) {
return find("connectUrl", connectUrl).singleResult();
}
Expand All @@ -108,6 +112,13 @@ public static boolean deleteByConnectUrl(URI connectUrl) {
return delete("connectUrl", connectUrl) > 0;
}

public ActiveRecording getRecordingById(long remoteId) {
return activeRecordings.stream()
.filter(rec -> rec.remoteId == remoteId)
.findFirst()
.orElse(null);
}

public static class Annotations {
public Map<String, String> platform;
public Map<String, String> cryostat;
Expand Down

0 comments on commit 2cb8658

Please sign in to comment.