|
1 | 1 | package org.epics.archiverappliance.common; |
2 | 2 |
|
| 3 | +import com.hazelcast.projection.Projection; |
| 4 | +import com.hazelcast.query.Predicates; |
| 5 | +import org.epics.archiverappliance.config.ConfigService; |
| 6 | +import org.epics.archiverappliance.config.PVNames; |
| 7 | +import org.epics.archiverappliance.config.PVTypeInfo; |
| 8 | + |
3 | 9 | import java.io.IOException; |
4 | 10 | import java.io.Serializable; |
5 | 11 | import java.util.Arrays; |
|
8 | 14 | import java.util.Map; |
9 | 15 | import java.util.stream.Collectors; |
10 | 16 |
|
11 | | -import javax.servlet.http.HttpServletRequest; |
12 | | - |
13 | | -import org.epics.archiverappliance.config.ConfigService; |
14 | | -import org.epics.archiverappliance.config.PVNames; |
15 | | -import org.epics.archiverappliance.config.PVTypeInfo; |
16 | | -import org.epics.archiverappliance.mgmt.bpl.PVsMatchingParameter; |
17 | | - |
18 | | -import com.hazelcast.projection.Projection; |
19 | | -import com.hazelcast.query.Predicates; |
20 | | - |
21 | 17 | /* |
22 | 18 | * Use a Hz query to determine the PV's that are being archived in this cluster. |
23 | 19 | */ |
24 | 20 | public class ArchivedPVsInList { |
25 | 21 |
|
26 | | - private static record OnlyFields ( String pvName, String[] archiveFields ) implements Serializable {}; |
| 22 | + private static record OnlyFields(String pvName, String[] archiveFields) implements Serializable {} |
| 23 | + ; |
| 24 | + |
27 | 25 | private static class FieldsProjection implements Projection<Map.Entry<String, PVTypeInfo>, OnlyFields> { |
28 | 26 | @Override |
29 | 27 | public OnlyFields transform(Map.Entry<String, PVTypeInfo> entry) { |
30 | 28 | String pvName = entry.getKey(); |
31 | 29 | PVTypeInfo value = entry.getValue(); |
32 | | - return new OnlyFields(pvName, value.getArchiveFields()) ; |
| 30 | + return new OnlyFields(pvName, value.getArchiveFields()); |
33 | 31 | } |
34 | 32 | } |
35 | 33 |
|
36 | | - public static List<String> getArchivedPVs(List<String> pvNames, ConfigService configService) throws IOException { |
37 | | - record PVNameParts(String pvName, String plainPVName, boolean isField, String fieldName){}; |
38 | | - LinkedList<PVNameParts> pvnps = new LinkedList<>(); |
39 | | - for(String pvName : pvNames) { |
40 | | - boolean isField = PVNames.isFieldOrFieldModifier(pvName); |
41 | | - String plainPVName = PVNames.channelNamePVName(pvName); |
42 | | - String fieldName = PVNames.getFieldName(pvName); |
43 | | - String realName = configService.getRealNameForAlias(plainPVName); |
44 | | - if(realName != null) { |
45 | | - plainPVName = realName; |
46 | | - } |
47 | | - pvnps.add(new PVNameParts(pvName, plainPVName, isField, fieldName)); |
48 | | - } |
| 34 | + public static List<String> getArchivedPVs(List<String> pvNames, ConfigService configService) throws IOException { |
| 35 | + record PVNameParts(String pvName, String plainPVName, boolean isField, String fieldName) {} |
| 36 | + ; |
| 37 | + LinkedList<PVNameParts> pvnps = new LinkedList<>(); |
| 38 | + for (String pvName : pvNames) { |
| 39 | + boolean isField = PVNames.isFieldOrFieldModifier(pvName); |
| 40 | + String plainPVName = PVNames.channelNamePVName(pvName); |
| 41 | + String fieldName = PVNames.getFieldName(pvName); |
| 42 | + String realName = configService.getRealNameForAlias(plainPVName); |
| 43 | + if (realName != null) { |
| 44 | + plainPVName = realName; |
| 45 | + } |
| 46 | + pvnps.add(new PVNameParts(pvName, plainPVName, isField, fieldName)); |
| 47 | + } |
| 48 | + |
| 49 | + Map<String, String[]> pvFieldsForPVNames = configService |
| 50 | + .queryPVTypeInfos( |
| 51 | + Predicates.in( |
| 52 | + "__key", |
| 53 | + pvnps.stream() |
| 54 | + .map((x) -> x.pvName) |
| 55 | + .collect(Collectors.toList()) |
| 56 | + .toArray(new String[0])), |
| 57 | + new FieldsProjection()) |
| 58 | + .stream() |
| 59 | + .collect(Collectors.toMap(OnlyFields::pvName, OnlyFields::archiveFields)); |
49 | 60 |
|
50 | | - Map<String, String[]> pvFieldsForPVNames = configService.queryPVTypeInfos( |
51 | | - Predicates.in("__key", pvnps.stream().map((x) -> x.pvName).collect(Collectors.toList()).toArray(new String[0])), |
52 | | - new FieldsProjection()) |
53 | | - .stream().collect(Collectors.toMap(OnlyFields::pvName, OnlyFields::archiveFields)); |
| 61 | + Map<String, String[]> pvFieldsForPlainPVNames = configService |
| 62 | + .queryPVTypeInfos( |
| 63 | + Predicates.in( |
| 64 | + "__key", |
| 65 | + pvnps.stream() |
| 66 | + .map((x) -> x.plainPVName) |
| 67 | + .collect(Collectors.toList()) |
| 68 | + .toArray(new String[0])), |
| 69 | + new FieldsProjection()) |
| 70 | + .stream() |
| 71 | + .collect(Collectors.toMap(OnlyFields::pvName, OnlyFields::archiveFields)); |
54 | 72 |
|
55 | | - Map<String, String[]> pvFieldsForPlainPVNames = configService.queryPVTypeInfos( |
56 | | - Predicates.in("__key", pvnps.stream().map((x) -> x.plainPVName).collect(Collectors.toList()).toArray(new String[0])), |
57 | | - new FieldsProjection()) |
58 | | - .stream().collect(Collectors.toMap(OnlyFields::pvName, OnlyFields::archiveFields)); |
59 | | - |
60 | | - String[] emptyFields = new String[0]; |
61 | | - LinkedList<String> archivedPVs = new LinkedList<String>(); |
62 | | - for(PVNameParts pvnp : pvnps) { |
63 | | - if(pvnp.isField) { |
64 | | - if(pvFieldsForPVNames.containsKey(pvnp.pvName) |
65 | | - || Arrays.asList(pvFieldsForPVNames.getOrDefault(pvnp.pvName, emptyFields)).contains(pvnp.fieldName) |
66 | | - || pvFieldsForPlainPVNames.containsKey(pvnp.pvName) |
67 | | - || Arrays.asList(pvFieldsForPlainPVNames.getOrDefault(pvnp.pvName, emptyFields)).contains(pvnp.fieldName) |
68 | | - ) { |
69 | | - archivedPVs.add(pvnp.pvName); |
70 | | - } |
71 | | - } else { |
72 | | - if(pvFieldsForPVNames.containsKey(pvnp.pvName) |
73 | | - || pvFieldsForPlainPVNames.containsKey(pvnp.pvName) |
74 | | - ) { |
75 | | - archivedPVs.add(pvnp.pvName); |
76 | | - } |
77 | | - } |
78 | | - } |
79 | | - return archivedPVs; |
80 | | - } |
81 | | - |
| 73 | + String[] emptyFields = new String[0]; |
| 74 | + LinkedList<String> archivedPVs = new LinkedList<String>(); |
| 75 | + for (PVNameParts pvnp : pvnps) { |
| 76 | + if (pvnp.isField) { |
| 77 | + if (pvFieldsForPVNames.containsKey(pvnp.pvName) |
| 78 | + || Arrays.asList(pvFieldsForPVNames.getOrDefault(pvnp.pvName, emptyFields)) |
| 79 | + .contains(pvnp.fieldName) |
| 80 | + || pvFieldsForPlainPVNames.containsKey(pvnp.pvName) |
| 81 | + || Arrays.asList(pvFieldsForPlainPVNames.getOrDefault(pvnp.pvName, emptyFields)) |
| 82 | + .contains(pvnp.fieldName)) { |
| 83 | + archivedPVs.add(pvnp.pvName); |
| 84 | + } |
| 85 | + } else { |
| 86 | + if (pvFieldsForPVNames.containsKey(pvnp.pvName) || pvFieldsForPlainPVNames.containsKey(pvnp.pvName)) { |
| 87 | + archivedPVs.add(pvnp.pvName); |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + return archivedPVs; |
| 92 | + } |
82 | 93 | } |
0 commit comments