Skip to content

Commit

Permalink
add doPutMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Mar 7, 2024
1 parent e3a364b commit 41b80d9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/io/cryostat/graphql/ActiveRecordings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
Expand Down Expand Up @@ -44,6 +45,7 @@
import jdk.jfr.RecordingState;
import org.eclipse.microprofile.graphql.Description;
import org.eclipse.microprofile.graphql.GraphQLApi;
import org.eclipse.microprofile.graphql.Mutation;
import org.eclipse.microprofile.graphql.NonNull;
import org.eclipse.microprofile.graphql.Source;

Expand Down Expand Up @@ -119,6 +121,27 @@ public RecordingOptions asOptions() {
}
}

@Mutation
@Description("Create a new Flight Recorder Snapshot on the specified Target")
public Uni<ActiveRecording> doPutMetadata(Long recordingId, MetadataInput metadataInput) {
return Uni.createFrom().item(() -> {
Map<String, String> labels = metadataInput.getLabels(); // Assuming MetadataInput is a class you have for GraphQL input
return recordingHelper.updateRecordingMetadata(recordingId, labels);
});
}

public static class MetadataInput {
private Map<String, String> labels;

public Map<String, String> getLabels() {
return labels;
}

public void setLabels(Map<String, String> labels) {
this.labels = labels;
}
}

@SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
public static class ActiveRecordingsFilter implements Predicate<ActiveRecording> {
public @Nullable String name;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ public static ActiveRecording getByName(String name) {
return find("name", name).singleResult();
}

public void setMetadata(Metadata metadatatadata) {
this.metadata = metadata;
}


@Transactional
public static boolean deleteFromTarget(Target target, String recordingName) {
Optional<ActiveRecording> recording =
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.ServerErrorException;
import jdk.jfr.RecordingState;
import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -928,6 +929,20 @@ private Metadata taggingToMetadata(List<Tag> tagSet) {
return new Metadata(labels, expiry);
}

public ActiveRecording updateRecordingMetadata(Long recordingId, Map<String, String> newLabels) {
// Retrieve the ActiveRecording by ID
ActiveRecording recording = ActiveRecording.findById(recordingId);
if (recording == null) {
throw new NotFoundException("Recording not found for ID: " + recordingId);
}

Metadata updatedMetadata = new Metadata(newLabels);
recording.setMetadata(updatedMetadata);
recording.persist();

return recording;
}

@Blocking
public Uni<String> uploadToJFRDatasource(long targetEntityId, long remoteId) throws Exception {
Target target = Target.getTargetById(targetEntityId);
Expand Down

0 comments on commit 41b80d9

Please sign in to comment.