-
Notifications
You must be signed in to change notification settings - Fork 36
/
DefaultConfigService.java
2043 lines (1804 loc) · 82.4 KB
/
DefaultConfigService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*******************************************************************************
* Copyright (c) 2011 The Board of Trustees of the Leland Stanford Junior University
* as Operator of the SLAC National Accelerator Laboratory.
* Copyright (c) 2011 Brookhaven National Laboratory.
* EPICS archiver appliance is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*******************************************************************************/
package org.epics.archiverappliance.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.PlatformLoggingMXBean;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import javax.servlet.ServletContext;
import org.apache.commons.validator.routines.InetAddressValidator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.epics.archiverappliance.StoragePlugin;
import org.epics.archiverappliance.common.ProcessMetrics;
import org.epics.archiverappliance.common.TimeUtils;
import org.epics.archiverappliance.config.PVTypeInfoEvent.ChangeType;
import org.epics.archiverappliance.config.exception.AlreadyRegisteredException;
import org.epics.archiverappliance.config.exception.ConfigException;
import org.epics.archiverappliance.config.persistence.MySQLPersistence;
import org.epics.archiverappliance.config.pubsub.PubSubEvent;
import org.epics.archiverappliance.engine.ArchiveEngine;
import org.epics.archiverappliance.engine.pv.EngineContext;
import org.epics.archiverappliance.etl.common.PBThreeTierETLPVLookup;
import org.epics.archiverappliance.mgmt.MgmtPostStartup;
import org.epics.archiverappliance.mgmt.MgmtRuntimeState;
import org.epics.archiverappliance.mgmt.NonMgmtPostStartup;
import org.epics.archiverappliance.mgmt.bpl.cahdlers.NamesHandler;
import org.epics.archiverappliance.mgmt.policy.ExecutePolicy;
import org.epics.archiverappliance.mgmt.policy.PolicyConfig;
import org.epics.archiverappliance.mgmt.policy.PolicyConfig.SamplingMethod;
import org.epics.archiverappliance.retrieval.RetrievalState;
import org.epics.archiverappliance.retrieval.channelarchiver.XMLRPCClient;
import org.epics.archiverappliance.utils.ui.GetUrlContent;
import org.epics.archiverappliance.utils.ui.JSONDecoder;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.xml.sax.SAXException;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.XmlConfigBuilder;
import com.hazelcast.core.Cluster;
import com.hazelcast.core.EntryEvent;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.core.ITopic;
import com.hazelcast.core.Member;
import com.hazelcast.core.MemberAttributeEvent;
import com.hazelcast.core.MembershipEvent;
import com.hazelcast.core.MembershipListener;
import com.hazelcast.core.Message;
import com.hazelcast.core.MessageListener;
import com.hazelcast.map.listener.EntryAddedListener;
import com.hazelcast.map.listener.EntryRemovedListener;
import com.hazelcast.map.listener.EntryUpdatedListener;
import edu.stanford.slac.archiverappliance.PB.data.PBTypeSystem;
/**
* This is the default config service for the archiver appliance.
* There is a subclass that is used in the junit tests.
*
* @author mshankar
*
*/
public class DefaultConfigService implements ConfigService {
private static Logger logger = Logger.getLogger(DefaultConfigService.class.getName());
private static Logger configlogger = Logger.getLogger("config." + DefaultConfigService.class.getName());
private static Logger clusterLogger = Logger.getLogger("cluster." + DefaultConfigService.class.getName());
public static final String SITE_FOR_UNIT_TESTS_NAME = "org.epics.archiverappliance.config.site";
public static final String SITE_FOR_UNIT_TESTS_VALUE = "tests";
/**
* Add a property in archappl.properties under this key to identify the class that implements the PVNameToKeyMapping for this installation.
*/
public static final String ARCHAPPL_PVNAME_TO_KEY_MAPPING_CLASSNAME = "org.epics.archiverappliance.config.DefaultConfigService.PVName2KeyMappingClassName";
// Configuration state begins here.
protected String myIdentity;
protected ApplianceInfo myApplianceInfo = null;
protected Map<String, ApplianceInfo> appliances = null;
// Persisted state begins here.
protected Map<String, PVTypeInfo> typeInfos = null;
protected Map<String, UserSpecifiedSamplingParams> archivePVRequests = null;
protected Map<String, String> channelArchiverDataServers = null;
protected Map<String, String> aliasNamesToRealNames = null;
// These are not persisted but derived from other info
protected Map<String, ApplianceInfo> pv2appliancemapping = null;
protected Map<String, String> clusterInet2ApplianceIdentity = null;
protected Map<String, List<ChannelArchiverDataServerPVInfo>> pv2ChannelArchiverDataServer = null;
protected ITopic<PubSubEvent> pubSub = null;
protected Map<String, Boolean> namedFlags = null;
// Configuration state ends here.
// Runtime state begins here
protected LinkedList<Runnable> shutdownHooks = new LinkedList<Runnable>();
protected PBThreeTierETLPVLookup etlPVLookup = null;
protected RetrievalState retrievalState = null;
protected MgmtRuntimeState mgmtRuntime = null;;
protected EngineContext engineContext = null;
protected ConcurrentSkipListSet<String> appliancesInCluster = new ConcurrentSkipListSet<String>();
// Runtime state ends here
// This is an optimization; we cache a copy of PVs that are registered for this appliance.
protected ConcurrentSkipListSet<String> pvsForThisAppliance = null;
// Maintain a TRIE index for the pvNames in this appliance.
protected ConcurrentHashMap<String, ConcurrentSkipListSet<String>> parts2PVNamesForThisAppliance = new ConcurrentHashMap<String, ConcurrentSkipListSet<String>>();
protected ConcurrentSkipListSet<String> pausedPVsForThisAppliance = null;
protected ApplianceAggregateInfo applianceAggregateInfo = new ApplianceAggregateInfo();
protected EventBus eventBus = new AsyncEventBus(Executors.newSingleThreadExecutor(new ThreadFactory() { @Override public Thread newThread(Runnable r) { return new Thread(r, "Event bus");}}));
protected Properties archapplproperties = new Properties();
protected PVNameToKeyMapping pvName2KeyConverter = null;
protected ConfigPersistence persistanceLayer;
// State local to DefaultConfigService.
protected WAR_FILE warFile = WAR_FILE.MGMT;
protected STARTUP_SEQUENCE startupState = STARTUP_SEQUENCE.ZEROTH_STATE;
protected ScheduledExecutorService startupExecutor = null;
protected ProcessMetrics processMetrics = new ProcessMetrics();
private HashSet<String> runTimeFields = new HashSet<String>();
// Use a Guava cache to store one and only one ExecutePolicy object that expires after some inactivity.
// The side effect is that it may take this many minutes to update the policy that is cached.
private LoadingCache<String, ExecutePolicy> theExecutionPolicy = CacheBuilder.newBuilder()
.expireAfterWrite(1, TimeUnit.MINUTES)
.removalListener(new RemovalListener<String, ExecutePolicy>() {
@Override
public void onRemoval(RemovalNotification<String, ExecutePolicy> arg) {
arg.getValue().close();
}
})
.build(new CacheLoader<String, ExecutePolicy>() {
public ExecutePolicy load(String key) throws IOException {
logger.info("Updating the cached execute policy");
return new ExecutePolicy(DefaultConfigService.this);
}
});
private ServletContext servletContext;
private long appserverStartEpochSeconds = TimeUtils.getCurrentEpochSeconds();
protected DefaultConfigService() {
// Only the unit tests config service uses this constructor.
}
@Override
public void initialize(ServletContext sce) throws ConfigException {
this.servletContext = sce;
String contextPath = sce.getContextPath();
logger.info("DefaultConfigService was created with a servlet context " + contextPath);
try {
String pathToVersionTxt = sce.getRealPath("ui/comm/version.txt");
logger.debug("The full path to the version.txt is " + pathToVersionTxt);
List<String> lines = Files.readAllLines(Paths.get(pathToVersionTxt), Charset.forName("UTF-8"));
for(String line : lines) {
configlogger.info(line);
}
} catch(Throwable t) {
logger.fatal("Unable to determine appliance version", t);
}
try {
// We first try Java system properties for this appliance's identity
// If a property is not defined, then we check the environment.
// This gives us the ability to cater to unit tests as well as running using buildAndDeploy scripts without touching the server.xml file.
// Probably not the most standard way but suited to this need.
// Finally, we use the local machine's hostname as the myidentity.
myIdentity = System.getProperty(ARCHAPPL_MYIDENTITY);
if(myIdentity == null) {
myIdentity = System.getenv(ARCHAPPL_MYIDENTITY);
if(myIdentity != null) {
logger.info("Obtained my identity from environment variable " + myIdentity);
} else {
logger.info("Using the local machine's hostname " + myIdentity + " as my identity");
myIdentity = InetAddress.getLocalHost().getCanonicalHostName();
}
if(myIdentity == null) {
throw new ConfigException("Unable to determine identity of this appliance");
}
} else {
logger.info("Obtained my identity from Java system properties " + myIdentity);
}
logger.info("My identity is " + myIdentity);
} catch(Exception ex) {
String msg = "Cannot determine this appliance's identity using either the environment variable " + ARCHAPPL_MYIDENTITY + " or the java system property " + ARCHAPPL_MYIDENTITY;
configlogger.fatal(msg);
throw new ConfigException(msg, ex);
}
// Appliances should be local and come straight from persistence.
try {
appliances = AppliancesList.loadAppliancesXML(servletContext);
} catch(Exception ex) {
throw new ConfigException("Exception loading appliances.xml", ex);
}
myApplianceInfo = appliances.get(myIdentity);
if(myApplianceInfo == null) throw new ConfigException("Unable to determine applianceinfo using identity " + myIdentity);
configlogger.info("My identity is " + myApplianceInfo.getIdentity() + " and my mgmt URL is " + myApplianceInfo.getMgmtURL());
// To make sure we are not starting multiple appliance with the same identity, we make sure that the hostnames match
try {
String machineHostName = InetAddress.getLocalHost().getCanonicalHostName();
String[] myAddrParts = myApplianceInfo.getClusterInetPort().split(":");
String myHostNameFromInfo = myAddrParts[0];
if(myHostNameFromInfo.equals("localhost")) {
logger.debug("Using localhost for the cluster inet port. If you are indeed running a cluster, the cluster members will not join the cluster.");
} else if (myHostNameFromInfo.equals(machineHostName)) {
logger.debug("Hostname from config and hostname from InetAddress match exactly; we are correctly configured " + machineHostName);
} else if(InetAddressValidator.getInstance().isValid(myHostNameFromInfo)) {
logger.debug("Using ipAddress for cluster config " + myHostNameFromInfo);
} else {
String msg = "The hostname from appliances.xml is " + myHostNameFromInfo + " and from a call to InetAddress.getLocalHost().getCanonicalHostName() (typially FQDN) is " + machineHostName
+ ". These are not identical. They are probably equivalent but to prevent multiple appliances binding to the same identity we enforce this equality.";
configlogger.fatal(msg);
throw new ConfigException(msg);
}
} catch(UnknownHostException ex) {
configlogger.error("Got an UnknownHostException when trying to determine the hostname. This happens when DNS is not set correctly on this machine (for example, when using VM's. See the documentation for InetAddress.getLocalHost().getCanonicalHostName()");
}
try {
String archApplPropertiesFileName = System.getProperty(ARCHAPPL_PROPERTIES_FILENAME);
if(archApplPropertiesFileName == null) {
archApplPropertiesFileName = System.getenv(ARCHAPPL_PROPERTIES_FILENAME);
}
if(archApplPropertiesFileName == null) {
archApplPropertiesFileName = new URL(this.getClass().getClassLoader().getResource(DEFAULT_ARCHAPPL_PROPERTIES_FILENAME).toString()).getPath();
configlogger.info("Loading archappl.properties from the webapp classpath " + archApplPropertiesFileName);
} else {
configlogger.info("Loading archappl.properties using the environment/JVM property from " + archApplPropertiesFileName);
}
try(InputStream is = new FileInputStream(new File(archApplPropertiesFileName))) {
archapplproperties.load(is);
configlogger.info("Done loading installation specific properties file from " + archApplPropertiesFileName);
} catch(Exception ex) {
throw new ConfigException("Exception loading installation specific properties file " + archApplPropertiesFileName, ex);
}
} catch(ConfigException cex) {
throw cex;
} catch(Exception ex) {
configlogger.fatal("Exception loading the appliance properties file", ex);
}
switch(contextPath) {
case "/mgmt":
warFile = WAR_FILE.MGMT;
this.mgmtRuntime = new MgmtRuntimeState(this);
break;
case "/engine":
warFile = WAR_FILE.ENGINE;
this.engineContext=new EngineContext(this);
break;
case "/retrieval":
warFile = WAR_FILE.RETRIEVAL;
this.retrievalState = new RetrievalState(this);
break;
case "/etl":
this.etlPVLookup = new PBThreeTierETLPVLookup(this);
warFile = WAR_FILE.ETL;
break;
default:
logger.error("We seem to have introduced a new component into the system " + contextPath);
}
String pvName2KeyMappingClass = this.getInstallationProperties().getProperty(ARCHAPPL_PVNAME_TO_KEY_MAPPING_CLASSNAME);
if(pvName2KeyMappingClass == null || pvName2KeyMappingClass.equals("") || pvName2KeyMappingClass.length() < 1) {
logger.info("Using the default key mapping class");
pvName2KeyConverter = new ConvertPVNameToKey();
pvName2KeyConverter.initialize(this);
} else {
try {
logger.info("Using " + pvName2KeyMappingClass + " as the name to key mapping class");
pvName2KeyConverter = (PVNameToKeyMapping) Class.forName(pvName2KeyMappingClass).newInstance();
pvName2KeyConverter.initialize(this);
} catch(Exception ex) {
logger.fatal("Cannot initialize pv name to key mapping class " + pvName2KeyMappingClass, ex);
throw new ConfigException("Cannot initialize pv name to key mapping class " + pvName2KeyMappingClass, ex);
}
}
String runtimeFieldsListStr = this.getInstallationProperties().getProperty("org.epics.archiverappliance.config.RuntimeKeys");
if(runtimeFieldsListStr != null && !runtimeFieldsListStr.isEmpty()) {
logger.debug("Got runtime fields from the properties file " + runtimeFieldsListStr);
String[] runTimeFieldsArr = runtimeFieldsListStr.split(",");
for(String rf : runTimeFieldsArr) {
this.runTimeFields.add(rf.trim());
}
}
startupExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setName("Startup executor");
return t;
}
});
this.addShutdownHook(new Runnable() {
@Override
public void run() {
logger.info("Shutting down startup scheduled executor...");
startupExecutor.shutdown();
}
});
this.startupState = STARTUP_SEQUENCE.READY_TO_JOIN_APPLIANCE;
if(this.warFile == WAR_FILE.MGMT) {
logger.info("Scheduling webappReady's for the mgmt webapp ");
MgmtPostStartup mgmtPostStartup = new MgmtPostStartup(this);
ScheduledFuture<?> postStartupFuture = startupExecutor.scheduleAtFixedRate(mgmtPostStartup, 10, 20, TimeUnit.SECONDS);
mgmtPostStartup.setCancellingFuture(postStartupFuture);
} else {
logger.info("Scheduling webappReady's for the non-mgmt webapp " + this.warFile.toString());
NonMgmtPostStartup nonMgmtPostStartup = new NonMgmtPostStartup(this, this.warFile.toString());
ScheduledFuture<?> postStartupFuture = startupExecutor.scheduleAtFixedRate(nonMgmtPostStartup, 10, 20, TimeUnit.SECONDS);
nonMgmtPostStartup.setCancellingFuture(postStartupFuture);
}
// Measure some JMX metrics once a minute
startupExecutor.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
processMetrics.takeMeasurement();
}
}, 60, 60, TimeUnit.SECONDS);
}
/* (non-Javadoc)
* @see org.epics.archiverappliance.config.ConfigService#postStartup()
*/
@Override
public void postStartup() throws ConfigException {
if(this.startupState != STARTUP_SEQUENCE.READY_TO_JOIN_APPLIANCE) {
configlogger.info("Webapp is not in correct state for postStartup " + this.getWarFile().toString() + ". It is in " + this.startupState.toString());
return;
}
this.startupState = STARTUP_SEQUENCE.POST_STARTUP_RUNNING;
configlogger.info("Post startup for " + this.getWarFile().toString());
// Inherit logging from log4j configuration.
try {
PlatformLoggingMXBean logging = ManagementFactory.getPlatformMXBean(PlatformLoggingMXBean.class);
if(logging != null) {
java.util.logging.Logger.getLogger("com.hazelcast");
if(clusterLogger.isDebugEnabled()) {
logging.setLoggerLevel("com.hazelcast", java.util.logging.Level.FINE.toString());
} else if(clusterLogger.isInfoEnabled()) {
logging.setLoggerLevel("com.hazelcast", java.util.logging.Level.INFO.toString());
} else {
logger.info("Setting clustering logging based on log levels for cluster." + getClass().getName());
logging.setLoggerLevel("com.hazelcast", java.util.logging.Level.SEVERE.toString());
}
}
Logger hzMain = Logger.getLogger("com.hazelcast");
if(clusterLogger.isDebugEnabled()) {
hzMain.setLevel(Level.DEBUG);
} else if(clusterLogger.isInfoEnabled()) {
hzMain.setLevel(Level.INFO);
} else {
logger.info("Setting clustering logging based on log levels for cluster." + getClass().getName());
hzMain.setLevel(Level.FATAL);
}
} catch(Exception ex) {
logger.error("Exception setting logging JVM levels ", ex);
}
// Add this to the system props before doing anything with Hz
System.getProperties().put("hazelcast.logging.type", "log4j");
HazelcastInstance hzinstance = null;
// Set the thread count to control how may threads this library spawns.
Properties hzThreadCounts = new Properties();
if(System.getenv().containsKey("ARCHAPPL_ALL_APPS_ON_ONE_JVM")) {
logger.info("Reducing the generic clustering thread counts.");
hzThreadCounts.put("hazelcast.clientengine.thread.count", "2");
hzThreadCounts.put("hazelcast.operation.generic.thread.count", "2");
hzThreadCounts.put("hazelcast.operation.thread.count", "2");
}
if(this.warFile == WAR_FILE.MGMT) {
// The management webapps are the head honchos in the cluster. We set them up differently
configlogger.debug("Initializing the MGMT webapp's clustering");
// If we have a hazelcast.xml in the servlet classpath, the XmlConfigBuilder picks that up.
// If not we use the default config found in hazelcast.jar
// We then alter this config to suit our purposes.
Config config = new XmlConfigBuilder().build();
try {
if(this.getClass().getResource("hazelcast.xml") == null) {
logger.info("We override the default cluster config by disabling multicast discovery etc.");
// We do not use multicast as it is not supported on all networks.
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
// We use TCPIP to discover the members in the cluster.
// This is part of the config that comes from appliance.xml
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
// Clear any tcpip config that comes from the default config
// This gets rid of the localhost in the default that prevents clusters from forming..
// If we need localhost, we'll add it back later.
config.getNetworkConfig().getJoin().getTcpIpConfig().clear();
// Enable interfaces; we seem to need this after 2.4 for clients to work correctly in a multi-homed environment.
// We'll add the actual interface later below
config.getNetworkConfig().getInterfaces().setEnabled(true);
config.getNetworkConfig().getInterfaces().clear();
// We don't really use the authentication provided by the tool; however, we set it to some default
config.getGroupConfig().setName("archappl");
config.getGroupConfig().setPassword("archappl");
// Backup count is 1 by default; we set it explicitly however...
config.getMapConfig("default").setBackupCount(1);
config.setProperty("hazelcast.logging.type", "log4j");
} else {
logger.debug("There is a hazelcast.xml in the classpath; skipping default configuration in the code.");
}
} catch(Exception ex) {
throw new ConfigException("Exception configuring cluster", ex);
}
config.setInstanceName(myIdentity);
if(!hzThreadCounts.isEmpty()) {
logger.info("Reducing the generic clustering thread counts.");
config.getProperties().putAll(hzThreadCounts);
}
try {
String[] myAddrParts = myApplianceInfo.getClusterInetPort().split(":");
String myHostName = myAddrParts[0];
InetAddress myInetAddr = InetAddress.getByName(myHostName);
if(!myHostName.equals("localhost") && myInetAddr.isLoopbackAddress()) {
logger.info("Address for this appliance -- " + myInetAddr.toString() + " is a loopback address. Changing this to 127.0.0.1 to clustering happy");
myInetAddr = InetAddress.getByName("127.0.0.1");
}
int myClusterPort = Integer.parseInt(myAddrParts[1]);
logger.debug("We do not let the port auto increment for the MGMT webap");
config.getNetworkConfig().setPortAutoIncrement(false);
config.getNetworkConfig().setPort(myClusterPort);
config.getNetworkConfig().getInterfaces().addInterface(myInetAddr.getHostAddress());
configlogger.info("Setting my cluster port base to " + myClusterPort + " and using interface " + myInetAddr.getHostAddress());
for(ApplianceInfo applInfo : appliances.values()) {
if(applInfo.getIdentity().equals(myIdentity) && this.warFile == WAR_FILE.MGMT) {
logger.debug("Not adding myself to the discovery process when I am the mgmt webapp");
} else {
String[] addressparts = applInfo.getClusterInetPort().split(":");
String inetaddrpart = addressparts[0];
try {
InetAddress inetaddr = InetAddress.getByName(inetaddrpart);
if(!inetaddrpart.equals("localhost") && inetaddr.isLoopbackAddress()) {
logger.info("Address for appliance " + applInfo.getIdentity() + " - "+ inetaddr.toString() + " is a loopback address. Changing this to 127.0.0.1 to clustering happy");
inetaddr = InetAddress.getByName("127.0.0.1");
}
int clusterPort = Integer.parseInt(addressparts[1]);
logger.info("Adding " + applInfo.getIdentity() + " from appliances.xml to the cluster discovery using cluster inetport " + inetaddr.toString() + ":" + clusterPort);
config.getNetworkConfig().getJoin().getTcpIpConfig().addMember(inetaddr.getHostAddress() + ":" + clusterPort);
} catch(UnknownHostException ex) {
configlogger.info("Cannnot resolve the IP address for appliance " + inetaddrpart + ". Skipping adding this appliance to the cliuster.");
}
}
}
hzinstance = Hazelcast.newHazelcastInstance(config);
} catch(Exception ex) {
throw new ConfigException("Exception adding member to cluster", ex);
}
} else {
// All other webapps are "native" clients.
try {
configlogger.debug("Initializing a non-mgmt webapp's clustering");
ClientConfig clientConfig = new ClientConfig();
clientConfig.getGroupConfig().setName("archappl");
clientConfig.getGroupConfig().setPassword("archappl");
clientConfig.setExecutorPoolSize(4);
// Non mgmt client can only connect to their MGMT webapp.
String[] myAddrParts = myApplianceInfo.getClusterInetPort().split(":");
String myHostName = myAddrParts[0];
InetAddress myInetAddr = InetAddress.getByName(myHostName);
if(!myHostName.equals("localhost") && myInetAddr.isLoopbackAddress()) {
logger.info("Address for this appliance -- " + myInetAddr.toString() + " is a loopback address. Changing this to 127.0.0.1 to clustering happy");
myInetAddr = InetAddress.getByName("127.0.0.1");
}
int myClusterPort = Integer.parseInt(myAddrParts[1]);
configlogger.debug(this.warFile + " connecting as a native client to " + myInetAddr.getHostAddress() + ":" + myClusterPort);
clientConfig.getNetworkConfig().addAddress(myInetAddr.getHostAddress() + ":" + myClusterPort);
clientConfig.setProperty("hazelcast.logging.type", "log4j");
if(!hzThreadCounts.isEmpty()) {
logger.info("Reducing the generic clustering thread counts.");
clientConfig.getProperties().putAll(hzThreadCounts);
}
if(!clusterLogger.isDebugEnabled()) {
// The client code logs some SEVERE exceptions on shutdown when deploying on the same Tomcat container.
// These exceptions are confusing; ideally, we would not have to set the log levels like so.
Logger.getLogger("com.hazelcast.client.spi.impl.ClusterListenerThread").setLevel(Level.OFF);
Logger.getLogger("com.hazelcast.client.spi.ClientPartitionService").setLevel(Level.OFF);
}
hzinstance = HazelcastClient.newHazelcastClient(clientConfig);
} catch(Exception ex) {
throw new ConfigException("Exception adding client to cluster", ex);
}
}
pv2appliancemapping = hzinstance.getMap("pv2appliancemapping");
namedFlags = hzinstance.getMap("namedflags");
typeInfos = hzinstance.getMap("typeinfo");
archivePVRequests = hzinstance.getMap("archivePVRequests");
channelArchiverDataServers = hzinstance.getMap("channelArchiverDataServers");
clusterInet2ApplianceIdentity = hzinstance.getMap("clusterInet2ApplianceIdentity");
aliasNamesToRealNames = hzinstance.getMap("aliasNamesToRealNames");
pv2ChannelArchiverDataServer = hzinstance.getMap("pv2ChannelArchiverDataServer");
pubSub = hzinstance.getTopic("pubSub");
final HazelcastInstance shutdownHzInstance = hzinstance;
shutdownHooks.add(0, new Runnable() {
@Override
public void run() {
logger.debug("Shutting down clustering instance in webapp " + warFile.toString());
shutdownHzInstance.shutdown();
}
});
if(this.warFile == WAR_FILE.MGMT) {
Cluster cluster = hzinstance.getCluster();
String localInetPort = getMemberKey(cluster.getLocalMember());
clusterInet2ApplianceIdentity.put(localInetPort, myIdentity);
logger.debug("Adding myself " + myIdentity + " as having inetport " + localInetPort);
hzinstance.getMap("clusterInet2ApplianceIdentity").addEntryListener(new EntryAddedListener<Object, Object>() {
@Override
public void entryAdded(EntryEvent<Object, Object> event) {
String appliden = (String) event.getValue();
appliancesInCluster.add(appliden);
logger.info("Adding appliance " + appliden + " to the list of active appliances as inetport " + ((String) event.getKey()));
}
}, true);
hzinstance.getMap("clusterInet2ApplianceIdentity").addEntryListener(new EntryRemovedListener<Object, Object>() {
@Override
public void entryRemoved(EntryEvent<Object, Object> event) {
String appliden = (String) event.getValue();
appliancesInCluster.remove(appliden);
logger.info("Removing appliance " + appliden + " from the list of active appliancesas inetport " + ((String) event.getKey()));
}
}, true);
logger.debug("Establishing a cluster membership listener to detect when appliances drop off the cluster");
cluster.addMembershipListener(new MembershipListener(){
public void memberAdded(MembershipEvent membersipEvent) {
Member member = membersipEvent.getMember();
String inetPort = getMemberKey(member);
if(clusterInet2ApplianceIdentity.containsKey(inetPort)) {
String appliden = clusterInet2ApplianceIdentity.get(inetPort);
appliancesInCluster.add(appliden);
configlogger.info("Adding newly started appliance " + appliden + " to the list of active appliances for inetport " + inetPort);
} else {
logger.debug("Skipping adding appliance using inetport " + inetPort + " to the list of active instances as we do not have a mapping to its identity");
}
}
public void memberRemoved(MembershipEvent membersipEvent) {
Member member = membersipEvent.getMember();
String inetPort = getMemberKey(member);
if(clusterInet2ApplianceIdentity.containsKey(inetPort)) {
String appliden = clusterInet2ApplianceIdentity.get(inetPort);
appliancesInCluster.remove(appliden);
configlogger.info("Removing appliance " + appliden + " from the list of active appliances");
} else {
configlogger.debug("Received member removed event for " + inetPort);
}
}
@Override
public void memberAttributeChanged(MemberAttributeEvent membersipEvent) {
Member member = membersipEvent.getMember();
String inetPort = getMemberKey(member);
configlogger.debug("Received membership attribute changed event for " + inetPort);
}
});
logger.debug("Adding the current members in the cluster after establishing the cluster membership listener");
for (Member member : cluster.getMembers()) {
String mbrInetPort = getMemberKey(member);
logger.debug("Found member " + mbrInetPort);
if(clusterInet2ApplianceIdentity.containsKey(mbrInetPort)) {
String appliden = clusterInet2ApplianceIdentity.get(mbrInetPort);
appliancesInCluster.add(appliden);
logger.info("Adding appliance " + appliden + " to the list of active appliances for inetport " + mbrInetPort);
} else {
logger.debug("Skipping adding appliance using inetport " + mbrInetPort + " to the list of active instances as we do not have a mapping to its identity");
}
}
logger.info("Established subscription(s) for appliance availability");
if(this.getInstallationProperties().containsKey(ARCHAPPL_NAMEDFLAGS_PROPERTIES_FILE_PROPERTY)) {
String namedFlagsFileName = (String) this.getInstallationProperties().get(ARCHAPPL_NAMEDFLAGS_PROPERTIES_FILE_PROPERTY);
configlogger.info("Loading named flags from file " + namedFlagsFileName);
File namedFlagsFile = new File(namedFlagsFileName);
if(!namedFlagsFile.exists()) {
configlogger.error("File containing named flags " + namedFlagsFileName + " specified but not present");
} else {
Properties namedFlagsFromFile = new Properties();
try(FileInputStream is = new FileInputStream(namedFlagsFile)) {
namedFlagsFromFile.load(is);
for(Object namedFlagFromFile : namedFlagsFromFile.keySet()) {
try {
String namedFlagFromFileStr = (String) namedFlagFromFile;
Boolean namedFlagFromFileValue = Boolean.parseBoolean((String)namedFlagsFromFile.get(namedFlagFromFileStr));
logger.debug("Setting named flag " + namedFlagFromFileStr + " to " + namedFlagFromFileValue);
this.namedFlags.put(namedFlagFromFileStr, namedFlagFromFileValue);
} catch(Exception ex) {
logger.error("Exception loading named flag from file" + namedFlagsFileName, ex);
}
}
} catch(Exception ex) {
configlogger.error("Exception loading named flags from " + namedFlagsFileName, ex);
}
}
}
}
if(this.warFile == WAR_FILE.ENGINE) {
// It can take a while for the engine to start up.
// We probably want to do this in the background so that the appliance as a whole starts up quickly and we get retrieval up and running quickly.
this.startupExecutor.schedule(new Runnable() {
@Override
public void run() {
try {
logger.debug("Starting up the engine's channels on startup.");
archivePVSonStartup();
logger.debug("Done starting up the engine's channels in startup.");
} catch(Throwable t) {
configlogger.fatal("Exception starting up the engine channels on startup", t);
}
}
}, 1, TimeUnit.SECONDS);
} else if(this.warFile == WAR_FILE.ETL) {
this.etlPVLookup.postStartup();
} else if(this.warFile == WAR_FILE.MGMT) {
pvsForThisAppliance = new ConcurrentSkipListSet<String>();
pausedPVsForThisAppliance = new ConcurrentSkipListSet<String>();
initializePersistenceLayer();
loadTypeInfosFromPersistence();
loadAliasesFromPersistence();
loadArchiveRequestsFromPersistence();
loadExternalServersFromPersistence();
registerForNewExternalServers(hzinstance.getMap("channelArchiverDataServers"));
// Cache the aggregate of all the PVs that are registered to this appliance.
logger.debug("Building a local aggregate of PV infos that are registered to this appliance");
for(String pvName : getPVsForThisAppliance()) {
if(!pvsForThisAppliance.contains(pvName)) {
applianceAggregateInfo.addInfoForPV(pvName, this.getTypeInfoForPV(pvName), this);
}
}
}
// Register for changes to the typeinfo map.
logger.info("Registering for changes to typeinfos");
hzinstance.getMap("typeinfo").addEntryListener(new EntryAddedListener<Object, Object>() {
@Override
public void entryAdded(EntryEvent<Object, Object> entryEvent) {
logger.debug("Received entryAdded for pvTypeInfo");
PVTypeInfo typeInfo = (PVTypeInfo) entryEvent.getValue();
String pvName = typeInfo.getPvName();
eventBus.post(new PVTypeInfoEvent(pvName, typeInfo, ChangeType.TYPEINFO_ADDED));
if(persistanceLayer != null) {
try {
persistanceLayer.putTypeInfo(pvName, typeInfo);
} catch(Exception ex) {
logger.error("Exception persisting pvTypeInfo for pv " + pvName, ex);
}
}
}
}, true);
hzinstance.getMap("typeinfo").addEntryListener(new EntryRemovedListener<Object, Object>() {
@Override
public void entryRemoved(EntryEvent<Object, Object> entryEvent) {
PVTypeInfo typeInfo =(PVTypeInfo) entryEvent.getOldValue();
String pvName = typeInfo.getPvName();
logger.info("Received entryRemoved for pvTypeInfo " + pvName);
eventBus.post(new PVTypeInfoEvent(pvName, typeInfo, ChangeType.TYPEINFO_DELETED));
if(persistanceLayer != null) {
try {
persistanceLayer.deleteTypeInfo(pvName);
} catch(Exception ex) {
logger.error("Exception deleting pvTypeInfo for pv " + pvName, ex);
}
}
}
}, true);
hzinstance.getMap("typeinfo").addEntryListener(new EntryUpdatedListener<Object, Object>() {
@Override
public void entryUpdated(EntryEvent<Object, Object> entryEvent) {
PVTypeInfo typeInfo =(PVTypeInfo) entryEvent.getValue();
String pvName = typeInfo.getPvName();
eventBus.post(new PVTypeInfoEvent(pvName, typeInfo, ChangeType.TYPEINFO_MODIFIED));
logger.debug("Received entryUpdated for pvTypeInfo");
if(persistanceLayer != null) {
try {
persistanceLayer.putTypeInfo(pvName, typeInfo);
} catch(Exception ex) {
logger.error("Exception persisting pvTypeInfo for pv " + pvName, ex);
}
}
}
}, true);
eventBus.register(this);
pubSub.addMessageListener(new MessageListener<PubSubEvent>() {
@Override
public void onMessage(Message<PubSubEvent> pubSubEventMsg) {
PubSubEvent pubSubEvent = pubSubEventMsg.getMessageObject();
if(pubSubEvent.getDestination() != null) {
if(pubSubEvent.getDestination().equals("ALL")
|| (pubSubEvent.getDestination().startsWith(myIdentity) && pubSubEvent.getDestination().endsWith(DefaultConfigService.this.warFile.toString()))
) {
// We publish messages from hazelcast into this VM only if the intened WAR file is us.
logger.debug("Publishing event into this JVM " + pubSubEvent.generateEventDescription());
// In this case, we set the source as being the cluster to prevent republishing back into the cluster.
pubSubEvent.markSourceAsCluster();
eventBus.post(pubSubEvent);
} else {
logger.debug("Skipping publishing event into this JVM " + pubSubEvent.generateEventDescription() + " as destination is not me " + DefaultConfigService.this.warFile.toString());
}
} else {
logger.debug("Skipping publishing event with null destination");
}
}
});
logger.info("Done registering for changes to typeinfos");
this.startupState = STARTUP_SEQUENCE.STARTUP_COMPLETE;
configlogger.info("Start complete for webapp " + this.warFile);
}
@Override
public STARTUP_SEQUENCE getStartupState() {
return this.startupState;
}
@Subscribe public void updatePVSForThisAppliance(PVTypeInfoEvent event) {
if(logger.isDebugEnabled()) logger.debug("Received pvTypeInfo change event for pv " + event.getPvName());
PVTypeInfo typeInfo = event.getTypeInfo();
String pvName = typeInfo.getPvName();
if(typeInfo.getApplianceIdentity().equals(myApplianceInfo.getIdentity())) {
if(event.getChangeType() == ChangeType.TYPEINFO_DELETED) {
if(pvsForThisAppliance != null) {
if(pvsForThisAppliance.contains(pvName)) {
logger.debug("Removing pv " + pvName + " from the locally cached copy of pvs for this appliance");
pvsForThisAppliance.remove(pvName);
pausedPVsForThisAppliance.remove(pvName);
// For now, we do not anticipate many PVs being deleted from the cache to worry about keeping applianceAggregateInfo upto date...
// This may change later...
String[] parts = this.pvName2KeyConverter.breakIntoParts(pvName);
for(String part : parts) {
parts2PVNamesForThisAppliance.get(part).remove(pvName);
}
}
}
} else {
if(pvsForThisAppliance != null) {
if(!pvsForThisAppliance.contains(pvName)) {
logger.debug("Adding pv " + pvName + " to the locally cached copy of pvs for this appliance");
pvsForThisAppliance.add(pvName);
if(typeInfo.isPaused()) {
pausedPVsForThisAppliance.add(typeInfo.getPvName());
}
String[] parts = this.pvName2KeyConverter.breakIntoParts(pvName);
for(String part : parts) {
if(!parts2PVNamesForThisAppliance.containsKey(part)) {
parts2PVNamesForThisAppliance.put(part, new ConcurrentSkipListSet<String>());
}
parts2PVNamesForThisAppliance.get(part).add(pvName);
}
applianceAggregateInfo.addInfoForPV(pvName, typeInfo, this);
} else {
if(typeInfo.isPaused()) {
pausedPVsForThisAppliance.add(typeInfo.getPvName());
} else {
pausedPVsForThisAppliance.remove(typeInfo.getPvName());
}
}
}
}
}
}
@Subscribe public void publishEventIntoCluster(PubSubEvent pubSubEvent) {
if(pubSubEvent.isSourceCluster()) {
logger.debug("Skipping publishing events from the cluster back into the cluster " + pubSubEvent.generateEventDescription());
return;
}
if(pubSubEvent.getDestination().startsWith(myIdentity) && pubSubEvent.getDestination().endsWith(this.warFile.toString())) {
logger.debug(this.warFile + " - Skipping publishing event " + pubSubEvent.generateEventDescription() + " meant for myself " + this.warFile.toString());
} else {
pubSubEvent.setSource(myIdentity);
logger.debug(this.warFile + " - Publishing event from local event bus onto cluster " + pubSubEvent.generateEventDescription());
pubSub.publish(pubSubEvent);
}
}
/**
* Get the PVs that belong to this appliance and start archiving them
* Needless to day, this gets done only in the engine.
*/
private void archivePVSonStartup() {
configlogger.debug("Start archiving PVs from persistence.");
int secondsToBuffer = PVTypeInfo.getSecondsToBuffer(this);
// To prevent broadcast storms, we pause for pausePerGroup seconds for every pausePerGroup PVs
int currentPVCount = 0;
int pausePerGroupPVCount = 2000;
int pausePerGroupPauseTimeInSeconds = 2;
for(String pvName : this.getPVsForThisAppliance()) {
try {
PVTypeInfo typeInfo = typeInfos.get(pvName);
if(typeInfo == null) {
logger.error("On restart, cannot find typeinfo for pv " + pvName + ". Not archiving");
continue;
}
if(typeInfo.isPaused()) {
logger.debug("Skipping archiving paused PV " + pvName + " on startup");
continue;
}
ArchDBRTypes dbrType = typeInfo.getDBRType();
float samplingPeriod = typeInfo.getSamplingPeriod();
SamplingMethod samplingMethod = typeInfo.getSamplingMethod();
StoragePlugin firstDest = StoragePluginURLParser.parseStoragePlugin(typeInfo.getDataStores()[0], this);
Timestamp lastKnownTimestamp = typeInfo.determineLastKnownEventFromStores(this);
if(logger.isDebugEnabled()) logger.debug("Last known timestamp from ETL stores is for pv " + pvName + " is "+ TimeUtils.convertToHumanReadableString(lastKnownTimestamp));
ArchiveEngine.archivePV(pvName, samplingPeriod, samplingMethod, secondsToBuffer, firstDest, this, dbrType,lastKnownTimestamp, typeInfo.getControllingPV(), typeInfo.getArchiveFields(), typeInfo.getHostName(), typeInfo.isUsePVAccess(), typeInfo.isUseDBEProperties());
currentPVCount++;
if(currentPVCount % pausePerGroupPVCount == 0) {
logger.debug("Sleeping for " + pausePerGroupPauseTimeInSeconds + " to prevent CA search storms");
Thread.sleep(pausePerGroupPauseTimeInSeconds*1000);
}
} catch(Throwable t) {
logger.error("Exception starting up archiving of PV " + pvName + ". Moving on to the next pv.", t);
}
}
configlogger.debug("Started " + currentPVCount + " PVs from persistence.");
}
@Override
public boolean isStartupComplete() {
return startupState == STARTUP_SEQUENCE.STARTUP_COMPLETE;
}
@Override
public Properties getInstallationProperties() {
return archapplproperties;
}
@Override
public Collection<ApplianceInfo> getAppliancesInCluster() {
ArrayList<ApplianceInfo> sortedAppliances = new ArrayList<ApplianceInfo>();
for(ApplianceInfo info : appliances.values()) {
if(appliancesInCluster.contains(info.getIdentity())) {
sortedAppliances.add(info);
} else {
logger.debug("Skipping appliance that is in the persistence but not in the cluster" + info.getIdentity());
}
}
Collections.sort(sortedAppliances, new Comparator<ApplianceInfo>() {
@Override
public int compare(ApplianceInfo o1, ApplianceInfo o2) {
return o1.getIdentity().compareTo(o2.getIdentity());
}
});
return sortedAppliances;
}
@Override
public ApplianceInfo getMyApplianceInfo() {
return myApplianceInfo;
}
@Override
public ApplianceInfo getAppliance(String identity) {
return appliances.get(identity);
}
@Override
public Collection<String> getAllPVs() {
List<PVApplianceCombo> sortedCombos = getSortedPVApplianceCombo();
ArrayList<String> allPVs = new ArrayList<String>();
for(PVApplianceCombo combo : sortedCombos) {
allPVs.add(combo.pvName);
}
return allPVs;
}
@Override
public ApplianceInfo getApplianceForPV(String pvName) {
ApplianceInfo applianceInfo = pv2appliancemapping.get(pvName);
if(applianceInfo == null && this.persistanceLayer != null) {
try {
PVTypeInfo typeInfo = this.persistanceLayer.getTypeInfo(pvName);
if(typeInfo != null) {
applianceInfo = this.getAppliance(typeInfo.getApplianceIdentity());
}
} catch(IOException ex) {
logger.error("Exception lookin up appliance for pv in persistence", ex);
}
}
return applianceInfo;
}
@Override
public Iterable<String> getPVsForAppliance(ApplianceInfo info) {
String identity = info.getIdentity();
List<PVApplianceCombo> sortedCombos = getSortedPVApplianceCombo();
ArrayList<String> pvsForAppliance = new ArrayList<String>();
for(PVApplianceCombo combo : sortedCombos) {
if(combo.applianceIdentity.equals(identity)) {
pvsForAppliance.add(combo.pvName);
}
}