Skip to content

Commit

Permalink
chore(quarkus): remove improper uses of blocking annotation (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Apr 5, 2024
1 parent 4408d16 commit 8f59816
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 54 deletions.
2 changes: 0 additions & 2 deletions src/main/java/io/cryostat/discovery/Discovery.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;
import io.smallrye.common.annotation.Blocking;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;
import io.vertx.mutiny.core.eventbus.EventBus;
Expand Down Expand Up @@ -386,7 +385,6 @@ static class RefreshPluginJob implements Job {

@Override
@Transactional
@Blocking
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE")
public void execute(JobExecutionContext context) throws JobExecutionException {
DiscoveryPlugin plugin = null;
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/io/cryostat/events/S3TemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import io.cryostat.ws.Notification;

import io.quarkus.runtime.StartupEvent;
import io.smallrye.common.annotation.Blocking;
import io.vertx.core.eventbus.EventBus;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
Expand Down Expand Up @@ -99,7 +98,6 @@ void onStart(@Observes StartupEvent evt) {
}

@Override
@Blocking
public Optional<IConstrainedMap<EventOptionID>> getEvents(
String templateName, TemplateType unused) throws FlightRecorderException {
try (var stream = getModel(templateName)) {
Expand All @@ -115,7 +113,6 @@ public Optional<IConstrainedMap<EventOptionID>> getEvents(
}

@Override
@Blocking
public List<Template> getTemplates() throws FlightRecorderException {
return getObjects().stream()
.map(
Expand All @@ -132,7 +129,6 @@ public List<Template> getTemplates() throws FlightRecorderException {
}

@Override
@Blocking
public Optional<Document> getXml(String templateName, TemplateType unused)
throws FlightRecorderException {
try (var stream = getModel(templateName)) {
Expand All @@ -145,13 +141,11 @@ public Optional<Document> getXml(String templateName, TemplateType unused)
}
}

@Blocking
private List<S3Object> getObjects() {
var builder = ListObjectsV2Request.builder().bucket(bucket);
return storage.listObjectsV2(builder.build()).contents();
}

@Blocking
private Template convertObject(S3Object object) throws InvalidEventTemplateException {
var req = GetObjectTaggingRequest.builder().bucket(bucket).key(object.key()).build();
var tagging = storage.getObjectTagging(req);
Expand Down Expand Up @@ -193,13 +187,11 @@ private Template convertObject(S3Object object) throws InvalidEventTemplateExcep
return new Template(label, description, provider, TemplateType.CUSTOM);
}

@Blocking
private InputStream getModel(String name) {
var req = GetObjectRequest.builder().bucket(bucket).key(name).build();
return storage.getObject(req);
}

@Blocking
private XMLModel parseXml(InputStream inputStream) throws IOException, ParseException {
try (inputStream) {
var model = EventConfiguration.createModel(inputStream);
Expand All @@ -215,7 +207,6 @@ private XMLModel parseXml(InputStream inputStream) throws IOException, ParseExce
}
}

@Blocking
@Override
public Template addTemplate(InputStream stream)
throws InvalidXmlException, InvalidEventTemplateException, IOException {
Expand Down Expand Up @@ -267,7 +258,6 @@ public Template addTemplate(InputStream stream)
}
}

@Blocking
@Override
public void deleteTemplate(String templateName) {
try {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/io/cryostat/events/TargetTemplateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.cryostat.targets.Target;
import io.cryostat.targets.TargetConnectionManager;

import io.smallrye.common.annotation.Blocking;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jsoup.nodes.Document;
Expand All @@ -53,7 +52,6 @@ private TargetTemplateService(TargetConnectionManager connectionManager, Target
}

@Override
@Blocking
public List<Template> getTemplates() throws FlightRecorderException {
return connectionManager.executeConnectedTask(
target,
Expand All @@ -64,7 +62,6 @@ public List<Template> getTemplates() throws FlightRecorderException {
}

@Override
@Blocking
public Optional<Document> getXml(String templateName, TemplateType unused)
throws FlightRecorderException {
return connectionManager.executeConnectedTask(
Expand All @@ -73,7 +70,6 @@ public Optional<Document> getXml(String templateName, TemplateType unused)
}

@Override
@Blocking
public Optional<IConstrainedMap<EventOptionID>> getEvents(
String templateName, TemplateType unused) throws FlightRecorderException {
return connectionManager.executeConnectedTask(
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/cryostat/recordings/ActiveRecording.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import io.cryostat.ws.Notification;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import io.smallrye.common.annotation.Blocking;
import io.vertx.mutiny.core.eventbus.EventBus;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
Expand Down Expand Up @@ -182,7 +181,6 @@ public void postPersist(ActiveRecording activeRecording) {
}

@PreUpdate
@Blocking
public void preUpdate(ActiveRecording activeRecording) throws Exception {
if (RecordingState.STOPPED.equals(activeRecording.state)) {
try {
Expand Down Expand Up @@ -233,7 +231,6 @@ public void postUpdate(ActiveRecording activeRecording) {
}

@PreRemove
@Blocking
public void preRemove(ActiveRecording activeRecording) throws Exception {
try {
activeRecording.target.activeRecordings.remove(activeRecording);
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/io/cryostat/recordings/RecordingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
import io.cryostat.ws.Notification;

import io.quarkus.runtime.StartupEvent;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import io.vertx.ext.web.handler.HttpException;
import io.vertx.mutiny.core.eventbus.EventBus;
Expand Down Expand Up @@ -193,7 +192,6 @@ void onStart(@Observes StartupEvent evt) {
}
}

@Blocking
public ActiveRecording startRecording(
Target target,
IConstrainedMap<String> recordingOptions,
Expand Down Expand Up @@ -241,7 +239,6 @@ public ActiveRecording startRecording(
return recording;
}

@Blocking
public ActiveRecording createSnapshot(Target target, JFRConnection connection)
throws Exception {
IRecordingDescriptor desc = connection.getService().getSnapshotRecording();
Expand Down Expand Up @@ -299,7 +296,6 @@ public ActiveRecording createSnapshot(Target target, JFRConnection connection)
return recording;
}

@Blocking
private boolean snapshotIsReadable(Target target, InputStream snapshot) throws IOException {
if (!connectionManager.markConnectionInUse(target)) {
throw new IOException(
Expand Down Expand Up @@ -360,7 +356,6 @@ public Pair<String, TemplateType> parseEventSpecifier(String eventSpecifier) {
throw new BadRequestException(eventSpecifier);
}

@Blocking
private IConstrainedMap<EventOptionID> enableAllEvents(Target target) throws Exception {
return connectionManager.executeConnectedTask(
target,
Expand All @@ -377,7 +372,6 @@ private IConstrainedMap<EventOptionID> enableAllEvents(Target target) throws Exc
});
}

@Blocking
private IConstrainedMap<EventOptionID> enableEvents(Target target, Template eventTemplate)
throws Exception {
if (EventTemplates.ALL_EVENTS_TEMPLATE.equals(eventTemplate)) {
Expand All @@ -400,7 +394,6 @@ private IConstrainedMap<EventOptionID> enableEvents(Target target, Template even
}
}

@Blocking
public Template getPreferredTemplate(
Target target, String templateName, TemplateType templateType) throws Exception {
Objects.requireNonNull(target);
Expand Down Expand Up @@ -491,12 +484,10 @@ private RecordingState mapState(IRecordingDescriptor desc) {
}
}

@Blocking
public List<S3Object> listArchivedRecordingObjects() {
return listArchivedRecordingObjects(null);
}

@Blocking
public List<S3Object> listArchivedRecordingObjects(String jvmId) {
var builder = ListObjectsV2Request.builder().bucket(archiveBucket);
if (StringUtils.isNotBlank(jvmId)) {
Expand All @@ -520,7 +511,6 @@ public String saveRecording(ActiveRecording recording, Instant expiry) throws Ex
return saveRecording(recording, null, expiry);
}

@Blocking
public String saveRecording(ActiveRecording recording, String savename, Instant expiry)
throws Exception {
// AWS object key name guidelines advise characters to avoid (% so we should not pass url
Expand Down Expand Up @@ -650,7 +640,6 @@ public Optional<Metadata> getArchivedRecordingMetadata(String jvmId, String file
return getArchivedRecordingMetadata(archivedRecordingKey(jvmId, filename));
}

@Blocking
public Optional<Metadata> getArchivedRecordingMetadata(String storageKey) {
try {
return Optional.of(
Expand Down Expand Up @@ -708,7 +697,6 @@ public InputStream getArchivedRecordingStream(String jvmId, String recordingName
return getArchivedRecordingStream(encodedKey(jvmId, recordingName));
}

@Blocking
public InputStream getArchivedRecordingStream(String encodedKey) {
String key = new String(base64Url.decode(encodedKey), StandardCharsets.UTF_8);

Expand All @@ -735,7 +723,6 @@ public String reportUrl(String jvmId, String filename) {
return String.format("/api/v3/reports/%s", encodedKey(jvmId, filename));
}

@Blocking
private int retryRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOException {
int attempts = 30;
int read = 0;
Expand All @@ -758,7 +745,6 @@ private int retryRead(ReadableByteChannel channel, ByteBuffer buffer) throws IOE
}

/* Archived Recording Helpers */
@Blocking
public void deleteArchivedRecording(String jvmId, String filename) {
storage.deleteObject(
DeleteObjectRequest.builder()
Expand Down Expand Up @@ -850,7 +836,6 @@ private Metadata taggingToMetadata(List<Tag> tagSet) {
return new Metadata(labels, expiry);
}

@Blocking
public Uni<String> uploadToJFRDatasource(long targetEntityId, long remoteId) throws Exception {
Target target = Target.getTargetById(targetEntityId);
Objects.requireNonNull(target, "Target from targetId not found");
Expand All @@ -870,7 +855,6 @@ public Uni<String> uploadToJFRDatasource(long targetEntityId, long remoteId) thr
return uploadToJFRDatasource(recordingPath);
}

@Blocking
public Uni<String> uploadToJFRDatasource(Pair<String, String> key) throws Exception {
Objects.requireNonNull(key);
Objects.requireNonNull(key.getKey());
Expand Down Expand Up @@ -923,7 +907,6 @@ private Uni<String> uploadToJFRDatasource(Path recordingPath)
});
}

@Blocking
Optional<Path> getRecordingCopyPath(
JFRConnection connection, Target target, String recordingName) throws Exception {
return connection.getService().getAvailableRecordings().stream()
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/cryostat/reports/ReportsServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import io.vertx.ext.web.handler.HttpException;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -57,7 +56,6 @@ class ReportsServiceImpl implements ReportsService {
@Inject InterruptibleReportGenerator reportGenerator;
@Inject Logger logger;

@Blocking
@Override
public Uni<Map<String, AnalysisResult>> reportFor(
ActiveRecording recording, Predicate<IRule> predicate) {
Expand Down Expand Up @@ -90,7 +88,6 @@ public Uni<Map<String, AnalysisResult>> reportFor(
return Uni.createFrom().future(future);
}

@Blocking
@Override
public Uni<Map<String, AnalysisResult>> reportFor(
String jvmId, String filename, Predicate<IRule> predicate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import jakarta.annotation.Priority;
import jakarta.decorator.Decorator;
Expand Down Expand Up @@ -75,7 +74,6 @@ class StorageCachingReportsService implements ReportsService {

@Inject Logger logger;

@Blocking
@Override
public Uni<Map<String, AnalysisResult>> reportFor(
ActiveRecording recording, Predicate<IRule> predicate) {
Expand All @@ -84,7 +82,6 @@ public Uni<Map<String, AnalysisResult>> reportFor(
return delegate.reportFor(recording, predicate);
}

@Blocking
@Override
public Uni<Map<String, AnalysisResult>> reportFor(
String jvmId, String filename, Predicate<IRule> predicate) {
Expand Down
15 changes: 3 additions & 12 deletions src/main/java/io/cryostat/targets/TargetConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import com.github.benmanes.caffeine.cache.Scheduler;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.quarkus.vertx.ConsumeEvent;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.unchecked.Unchecked;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -151,25 +150,21 @@ void onMessage(TargetDiscovery event) {
}
}

@Blocking
@ConsumeEvent(Credential.CREDENTIALS_STORED)
@ConsumeEvent(value = Credential.CREDENTIALS_STORED, blocking = true)
void onCredentialsStored(Credential credential) {
handleCredentialChange(credential);
}

@Blocking
@ConsumeEvent(Credential.CREDENTIALS_UPDATED)
@ConsumeEvent(value = Credential.CREDENTIALS_UPDATED, blocking = true)
void onCredentialsUpdated(Credential credential) {
handleCredentialChange(credential);
}

@Blocking
@ConsumeEvent(Credential.CREDENTIALS_DELETED)
@ConsumeEvent(value = Credential.CREDENTIALS_DELETED, blocking = true)
void onCredentialsDeleted(Credential credential) {
handleCredentialChange(credential);
}

@Blocking
void handleCredentialChange(Credential credential) {
for (var entry : connections.asMap().entrySet()) {
URI key = entry.getKey();
Expand All @@ -187,7 +182,6 @@ void handleCredentialChange(Credential credential) {
}
}

@Blocking
public <T> Uni<T> executeConnectedTaskUni(Target target, ConnectedTask<T> task) {
return Uni.createFrom()
.completionStage(connections.get(target.connectUrl))
Expand All @@ -211,12 +205,10 @@ public <T> Uni<T> executeConnectedTaskUni(Target target, ConnectedTask<T> task)
.expireIn(failedTimeout.plusMillis(System.currentTimeMillis()).toMillis());
}

@Blocking
public <T> T executeConnectedTask(Target target, ConnectedTask<T> task) {
return executeConnectedTaskUni(target, task).await().atMost(failedTimeout);
}

@Blocking
public <T> Uni<T> executeDirect(
Target target, Optional<Credential> credentials, ConnectedTask<T> task) {
return Uni.createFrom()
Expand Down Expand Up @@ -315,7 +307,6 @@ JFRConnection connect(URI connectUrl) throws Exception {
return connect(connectUrl, credentials);
}

@Blocking
JFRConnection connect(URI connectUrl, Optional<Credential> credentials) throws Exception {
TargetConnectionOpened evt = new TargetConnectionOpened(connectUrl.toString());
evt.begin();
Expand Down

0 comments on commit 8f59816

Please sign in to comment.