Skip to content

Refactor Archiver Client for large requests#196

Open
jacomago wants to merge 13 commits intoChannelFinder:masterfrom
jacomago:archclient-large-input
Open

Refactor Archiver Client for large requests#196
jacomago wants to merge 13 commits intoChannelFinder:masterfrom
jacomago:archclient-large-input

Conversation

@jacomago
Copy link
Contributor

Refactored the Archiver Client to make sure it can stream large requests.
Also refactored to make it more easily unit testable, realised all the tests were mostly for the processor rather than on the client.
I added some examples for test cases I generated from a test archiver.
Added some more validation of the responses.

For future I'd like to use openapi definition from the archiver to generate a client, maybe that's a good codathon ticket.

@shroffk
Copy link
Collaborator

shroffk commented Feb 11, 2026

This does sound like a good codeathon task

@jacomago jacomago force-pushed the archclient-large-input branch from f0f092d to 1edb6fe Compare February 11, 2026 16:04
@jacomago jacomago marked this pull request as draft February 12, 2026 07:16
@jacomago jacomago force-pushed the archclient-large-input branch from 1edb6fe to e9679d1 Compare February 12, 2026 15:01
@jacomago jacomago self-assigned this Feb 12, 2026
@jacomago jacomago marked this pull request as ready for review February 12, 2026 16:08
@@ -19,10 +19,12 @@
import org.phoebus.channelfinder.service.model.archiver.aa.ArchiveAction;
import org.phoebus.channelfinder.service.model.archiver.aa.ArchivePVOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit msg Use flux to stream large input does not explain why

private List<String> postSupportArchivers;

private static WebClient webClient() {
final int size = (int) DataSize.ofMegabytes(16).toBytes();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. where we sure this was necessary
  2. is 16 MB appropriate? from memory (having looked at other apps and discussion online) this seems like a lot

List<String> failedPvs = new ArrayList<>();
for (int i = 0; i < response.size(); i++) {
Map<String, String> result = response.get(i);
String pv = (i < pvs.size()) ? pvs.get(i) : "UNKNOWN_PV";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, what are we hedging against here, where response.size > pvs.size?

}

@Test
void testGetStatusesInvalidResponse() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but test naming is a bit inconsistent: for the previous two you only described action, where you here now also describe the consequence

Comment on lines 46 to 52
@@ -47,6 +47,7 @@ public class ArchiverService {
private static final String PV_NAME_KEY = "pvName";
private static final String STATUS_KEY = "status";
private static final String STATUS_OK = "ok";
private static final String STATUS_ARCHIVE_SUBMITTED = "Archive request submitted";
private static final String MGMT_VERSION_KEY = "mgmt_version";
private static final MediaType CONTENT_TYPE = MediaType.APPLICATION_JSON;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mix of different types of entities (info msg vs "enum" str equivalents vs (seemingly unnecessary) rebinding) - should maybe consider future change 🔧

RecordedRequest request = mockWebServer.takeRequest();
if ("test-archiver".equals(archiverAlias)) {
assertEquals("POST", request.getMethod());
assertEquals("//mgmt/bpl/getPVStatus", request.getPath());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two leading slashes correct? Note you did this in multiple places

// Empty archiver tagged
continue;
}
String version = archiverService.getVersion(aa.getValue());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but for this commit you write in body

Now we explicitly configure it instead.

which makes it sound like this is a change that you introduce here in this commit


@Autowired private final ArchiverClient archiverClient = new ArchiverClient();
@Autowired private final ArchiverService archiverService = new ArchiverService();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not claiming I'm a Spring guru, but should Autowired beans be instantiated in config classes?
To me Autowired together with instantiation seems a bit confusing, but maybe I'm missing something?

import java.util.List;
import java.util.Map;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring Boot Test comes with APIs which are easy to use to mock a server, eliminating dependency to okhttp. Olog service test classes can be used for inspiration.

Copy link
Collaborator

@georgweiss georgweiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some Spring Boot related comments....

This was used to distinguish support for getting status via post or query
Now (from an earlier merge) we explicitly configure it instead.
Use bodyToFlux
Add throwing of ArchiverServiceException
Add validation of action response
Add unit test for submitAction and other ArchiverService methods
@jacomago jacomago force-pushed the archclient-large-input branch from e9679d1 to 22427d3 Compare February 13, 2026 17:09
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants