Skip to content

Commit 8923bb9

Browse files
authored
Merge pull request #131 from jacomago/empty-default-archiver
Allow setting the default archiver to ''
2 parents 41aafb2 + 2bfbb89 commit 8923bb9

File tree

5 files changed

+115
-9
lines changed

5 files changed

+115
-9
lines changed

src/main/java/org/phoebus/channelfinder/processors/AAChannelProcessor.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.core.JsonProcessingException;
66
import com.fasterxml.jackson.core.type.TypeReference;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import org.apache.commons.lang3.StringUtils;
89
import org.phoebus.channelfinder.entity.Channel;
910
import org.phoebus.channelfinder.entity.Property;
1011
import org.springframework.beans.factory.annotation.Value;
@@ -70,10 +71,24 @@ public boolean enabled() {
7071
}
7172

7273
@Override
73-
public String processorName() {
74-
return "Process " + archivePropertyName + " properties on channels";
74+
public String processorInfo() {
75+
Map<String, String> processorProperties = Map.of("archiveProperty", archivePropertyName,
76+
"archiverProperty", archiverPropertyName,
77+
"Archivers", aaURLs.keySet().toString(),
78+
"AutoPauseOn", autoPauseOptions.toString()
79+
);
80+
return "AAChannelProcessor: ProcessProperties " + processorProperties;
7581
}
7682

83+
/**
84+
* Processes a list of channels through the archiver workflow.
85+
* First the status of each pv is checked against the archiver.
86+
* If the pv is not being archived and is not paused then the pv will be submitted to be archived.
87+
* If the pvStatus auto pause is set, then the pv will be auto pause resumed as well.
88+
*
89+
* @param channels List of channels
90+
* @throws JsonProcessingException If processing archiver responses fail.
91+
*/
7792
@Override
7893
public void process(List<Channel> channels) throws JsonProcessingException {
7994
if (channels.isEmpty()) {
@@ -140,6 +155,10 @@ private ArchiveAction pickArchiveAction(String archiveStatus, String pvStatus) {
140155

141156
private Map<ArchiveAction, List<ArchivePV>> getArchiveActions(
142157
Map<String, ArchivePV> archivePVS, String archiverURL) {
158+
if (StringUtils.isEmpty(archiverURL)) {
159+
return Map.of();
160+
}
161+
143162
logger.log(Level.INFO, () -> String.format("Get archiver status in archiver %s", archiverURL));
144163

145164
Map<ArchiveAction, List<ArchivePV>> result = new EnumMap<>(ArchiveAction.class);
@@ -180,7 +199,7 @@ private Map<ArchiveAction, List<ArchivePV>> getArchiveActions(
180199

181200
} catch (JsonProcessingException e) {
182201
// problem collecting policies from AA, so warn and return empty list
183-
logger.log(Level.WARNING, "Could not get AA pv Status list: " + e.getMessage());
202+
logger.log(Level.WARNING, () -> "Could not get AA pv Status list: " + e.getMessage());
184203
return result;
185204
}
186205
}
@@ -257,13 +276,16 @@ private void submitAction(String values, String endpoint, String aaURL) {
257276

258277
private Map<String, List<String>> getAAsPolicies(Map<String, String> aaURLs) {
259278
Map<String, List<String>> result = new HashMap<>();
260-
for (String aaAlias : aaURLs.keySet()) {
261-
result.put(aaAlias, getAAPolicies(aaURLs.get(aaAlias)));
279+
for (Map.Entry<String, String> aa : aaURLs.entrySet()) {
280+
result.put(aa.getKey(), getAAPolicies(aa.getValue()));
262281
}
263282
return result;
264283
}
265284

266285
private List<String> getAAPolicies(String aaURL) {
286+
if (StringUtils.isEmpty(aaURL)) {
287+
return List.of();
288+
}
267289
try {
268290
String response = client.get()
269291
.uri(URI.create(aaURL + POLICY_RESOURCE))

src/main/java/org/phoebus/channelfinder/processors/ChannelProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface ChannelProcessor {
99

1010
boolean enabled();
1111

12-
String processorName();
12+
String processorInfo();
1313

1414
void process(List<Channel> channels) throws JsonProcessingException;
1515

src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public long processorCount() {
5555

5656
@GetMapping("/info")
5757
public List<String> processorInfo() {
58-
return channelProcessorService.getProcessorsNames();
58+
return channelProcessorService.getProcessorsInfo();
5959
}
6060

6161
@PutMapping("/process/all")

src/main/java/org/phoebus/channelfinder/processors/ChannelProcessorService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ long getProcessorCount() {
2525
return channelProcessors.size();
2626
}
2727

28-
List<String> getProcessorsNames() {
29-
return channelProcessors.stream().map(ChannelProcessor::processorName).collect(Collectors.toList());
28+
List<String> getProcessorsInfo() {
29+
return channelProcessors.stream().map(ChannelProcessor::processorInfo).collect(Collectors.toList());
3030
}
3131

3232
/**
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package org.phoebus.channelfinder.processors;
2+
3+
import com.fasterxml.jackson.core.JsonProcessingException;
4+
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import okhttp3.mockwebserver.MockWebServer;
6+
import org.junit.jupiter.api.AfterEach;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.Arguments;
10+
import org.junit.jupiter.params.provider.MethodSource;
11+
import org.phoebus.channelfinder.entity.Channel;
12+
import org.phoebus.channelfinder.entity.Property;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
15+
import org.springframework.test.context.TestPropertySource;
16+
17+
import java.io.IOException;
18+
import java.util.List;
19+
import java.util.stream.Stream;
20+
21+
import static org.phoebus.channelfinder.processors.AAChannelProcessorIT.activeProperty;
22+
import static org.phoebus.channelfinder.processors.AAChannelProcessorIT.archiveProperty;
23+
import static org.phoebus.channelfinder.processors.AAChannelProcessorIT.inactiveProperty;
24+
import static org.phoebus.channelfinder.processors.AAChannelProcessorIT.paramableAAChannelProcessorTest;
25+
26+
@WebMvcTest(AAChannelProcessor.class)
27+
@TestPropertySource(locations = "classpath:application_test.properties", properties = "aa.urls:{'default': '','aa': 'http://localhost:17665'}")
28+
class AAChannelProcessorNoDefaultIT {
29+
protected static Property archiverProperty = new Property("archiver", "owner", "aa");
30+
31+
@Autowired
32+
AAChannelProcessor aaChannelProcessor;
33+
34+
MockWebServer mockArchiverAppliance;
35+
ObjectMapper objectMapper;
36+
37+
private static Stream<Arguments> processNoPauseSource() {
38+
39+
return Stream.of(
40+
Arguments.of(
41+
new Channel("PVNoneActive", "owner", List.of(archiveProperty, activeProperty), List.of()),
42+
"",
43+
"",
44+
""),
45+
Arguments.of(
46+
new Channel("PVNoneActiveArchiver", "owner", List.of(archiveProperty, activeProperty, archiverProperty), List.of()),
47+
"Not being archived",
48+
"archivePV",
49+
"[{\"pv\":\"PVNoneActiveArchiver\"}]")
50+
);
51+
}
52+
53+
@BeforeEach
54+
void setUp() throws IOException {
55+
mockArchiverAppliance = new MockWebServer();
56+
mockArchiverAppliance.start(17665);
57+
58+
objectMapper = new ObjectMapper();
59+
}
60+
61+
@AfterEach
62+
void teardown() throws IOException {
63+
mockArchiverAppliance.shutdown();
64+
}
65+
66+
@ParameterizedTest
67+
@MethodSource("processNoPauseSource")
68+
void testProcessNotArchivedActive(
69+
Channel channel,
70+
String archiveStatus,
71+
String archiverEndpoint,
72+
String submissionBody)
73+
throws JsonProcessingException, InterruptedException {
74+
paramableAAChannelProcessorTest(
75+
mockArchiverAppliance,
76+
objectMapper,
77+
aaChannelProcessor,
78+
channel,
79+
archiveStatus,
80+
archiverEndpoint,
81+
submissionBody
82+
);
83+
}
84+
}

0 commit comments

Comments
 (0)