aboutsummaryrefslogtreecommitdiffstats
path: root/policy-core/src/main/java/org/openecomp/policy/drools/core/PolicyContainer.java
blob: ae7cd6227148439a452b23549e04afbc4b76a62f (plain)
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
/*-
 * ============LICENSE_START=======================================================
 * policy-core
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.policy.drools.core;

import java.io.IOException;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.kie.api.KieBase;
import org.kie.api.KieServices;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.Message;
import org.kie.api.builder.ReleaseId;
import org.kie.api.builder.Results;
import org.kie.api.runtime.Environment;
import org.kie.api.runtime.EnvironmentName;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.KieSessionConfiguration;

import bitronix.tm.Configuration;
import bitronix.tm.TransactionManagerServices;
import bitronix.tm.resource.jdbc.PoolingDataSource;

import org.openecomp.policy.common.ia.IntegrityAudit;
import org.openecomp.policy.common.ia.IntegrityAuditProperties;
import org.openecomp.policy.drools.properties.Startable;
import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
import org.openecomp.policy.common.logging.flexlogger.Logger;
import org.openecomp.policy.common.logging.eelf.MessageCodes;
import org.openecomp.policy.common.logging.eelf.PolicyLogger;
import org.openecomp.policy.common.logging.flexlogger.PropertyUtil;

/**
 * This class is a wrapper around 'KieContainer', which adds the ability
 * to automatically create and track KieSession instances.
 */
public class PolicyContainer implements Startable
{
	// get an instance of logger 
  private static Logger  logger = FlexLogger.getLogger(PolicyContainer.class);	
  // 'KieServices' singleton
  static private KieServices kieServices = KieServices.Factory.get();

  // set of all 'PolicyContainer' instances
  static private HashSet<PolicyContainer> containers =
	new HashSet<PolicyContainer>();

  // maps feature objects to per-PolicyContainer data
  private ConcurrentHashMap<Object, Object> adjuncts =
	new ConcurrentHashMap<Object, Object>();

  // 'KieContainer' associated with this 'PolicyContainer'
  private KieContainer kieContainer;

  // indicates whether the PolicyContainer is 'started'
  // (started = sessions created, threads running)
  private volatile boolean isStarted = false;

  // maps session name into the associated 'PolicySession' instance
  private HashMap<String, PolicySession> sessions =
	new HashMap<String, PolicySession>();

  // if not null, this is a 'KieScanner' looking for updates
  private KieScanner scanner = null;
  
  // indicates whether the scanner has been started
  // (it can block for a long time)
  private boolean scannerStarted = false;

  // Used to set relative pathing to config files for unit test environment
  public static boolean isUnitTesting = false;

  /**
   * uses 'groupId', 'artifactId' and 'version', and fetches the associated
   * artifact and remaining dependencies from the Maven repository to create
   * the 'PolicyContainer' and associated 'KieContainer'.
   *
   * An exception occurs if the creation of the 'KieContainer' fails.
   *
   * @param groupId the 'groupId' associated with the artifact
   * @param artifactId the artifact name
   * @param version a comma-separated list of possible versions
   */
  public PolicyContainer(String groupId, String artifactId, String version)
  {
	this(kieServices.newReleaseId(groupId, artifactId, version));
  }

  /**
   * uses the 'groupId', 'artifactId' and 'version' information in 'ReleaseId',
   * and fetches the associated artifact and remaining dependencies from the
   * Maven repository to create the 'PolicyContainer' and associated
   * 'KieContainer'.
   *
   * An exception occurs if the creation of the 'KieContainer' fails.
   *
   * @param releaseId indicates the artifact that is to be installed in this
   *	container
   */
  public PolicyContainer(ReleaseId releaseId)
  {
	if (releaseId.getVersion().contains(","))
	  {
		// this is actually a comma-separated list of release ids
		releaseId = loadArtifact(releaseId.getGroupId(),
								 releaseId.getArtifactId(),
								 releaseId.getVersion());
	  }
	else
	  {
		kieContainer = kieServices.newKieContainer(releaseId);
	  }
	synchronized(containers)
	  {
		if(releaseId != null){
		   logger.info("Add a new kieContainer in containers: releaseId: " + releaseId.toString());
		}else{
		   logger.warn("input releaseId is null");
		}
		containers.add(this);
	  }
	startScanner(releaseId);
  }

  /**
   * Load an artifact into a new KieContainer. This method handles the
   * case where the 'version' is actually a comma-separated list of
   * versions.
   *
   * @param groupId the 'groupId' associated with the artifact
   * @param artifactId the artifact name
   * @param version a comma-separated list of possible versions
   */
  private ReleaseId loadArtifact
	(String groupId, String artifactId, String version)
  {
	String[] versions = version.split(",");
	if (versions.length > 1)
	  {
		logger.info("Multiple KieContainer versions are specified: "
						  + version);
	  }

	// indicates a 'newKieContainer' call failed
	RuntimeException exception = null;

	// set prior to every 'newKieContainer' invocation
	// (if we are able to create the container, it will be the last
	// one that was successful)
	ReleaseId releaseId = null;
	for (String ver : versions)
	  {
		try
		  {
			// Create a 'ReleaseId' object describing the artifact, and
			// create a 'KieContainer' based upon it.
			logger.info("Create new KieContainer start, version = "
							  + ver + " ...");

			releaseId = kieServices.newReleaseId(groupId, artifactId, ver);
			kieContainer = kieServices.newKieContainer(releaseId);

			// clear any exception, and break out of the loop
			exception = null;
			break;
		  }
		catch (RuntimeException e)
		  {
			exception = e;
		  }
	  }
	if (exception != null)
	  {
		// all of the 'newKieContainer' invocations failed -- throw the
		// most recent exception
		throw(exception);
	  }
	return(releaseId);
  }

  /**
   * @return the name of the container, which is the String equivalent of
   * the 'ReleaseId'. It has the form:
   *
   *	(groupId + ":" + artifactId + ":" + version)
   *
   * Note that the name changes after a successful call to 'updateToVersion',
   * although typically only the 'version' part changes.
   */
  public String getName()
  {
	return(kieContainer.getReleaseId().toString());
  }

  /**
   * @return the associated 'KieContainer' instance
   */
  public KieContainer getKieContainer()
  {
	return(kieContainer);
  }

  /**
   * @return the 'ClassLoader' associated with the 'KieContainer' instance
   */
  public ClassLoader getClassLoader()
  {
	return(kieContainer.getClassLoader());
  }

  /**
   * @return the Maven GroupId of the top-level artifact wrapped
   *	by the container.
   */
  public String getGroupId()
  {
	return(kieContainer.getReleaseId().getGroupId());
  }

  /**
   * @return the Maven ArtifactId of the top-level artifact wrapped
   *	by the container.
   */
  public String getArtifactId()
  {
	return(kieContainer.getReleaseId().getArtifactId());
  }

  /**
   * @return the version of the top-level artifact wrapped by the
   *	container (this may change as updates occur)
   */
  public String getVersion()
  {
	return(kieContainer.getReleaseId().getVersion());
  }

  /**
   * Fetch the named 'PolicySession'.
   *
   * @param name the name of the KieSession (which is also the name of
   *	the associated PolicySession)
   * @return a PolicySession if found, 'null' if not
   */
  public PolicySession getPolicySession(String name)
  {
	return(sessions.get(name));
  }

  /**
   * Internal method to create a PolicySession, possibly restoring it
   * from persistent storage.
   *
   * @param name of the KieSession and PolicySession
   * @param kieBaseName name of the associated 'KieBase' instance
   * @return a new or existing PolicySession, or 'null' if not found
   */
  private PolicySession activatePolicySession(String name, String kieBaseName)
  {
	synchronized(sessions)
	  {
		logger.info("activatePolicySession:name :" + name);
		PolicySession session = sessions.get(name);
		if (session == null)
		  {
			KieSession kieSession = null;

			// loop through all of the features, and give each one
			// a chance to create the 'KieSession'
			for (FeatureAPI feature : FeatureAPI.impl.getList())
			  {
				if ((kieSession = feature.activatePolicySession
					 (this, name, kieBaseName)) != null)
				  break;
			  }

			// if none of the features created the session, create one now
			if (kieSession == null)
			  {
				kieSession = kieContainer.newKieSession(name);
			  }

			if (kieSession != null)
			  {
				// creation of 'KieSession' was successful - build
				// a PolicySession
				session = new PolicySession(name, this, kieSession);
				sessions.put(name, session);
				logger.info("activatePolicySession:new session was added in sessions with name " + name);
			  }
		  }
		logger.info("activatePolicySession:session - "
						  + (session == null ? "null" : session.getFullName())
						  + " is returned.");
		return(session);
	  }
  }

  /**
   * This creates a 'PolicySession' instance within this 'PolicyContainer',
   * and ties it to the specified 'KieSession'. 'name' must not currently
   * exist within the 'PolicyContainer', and the 'KieBase' object associated
   * with 'KieSession' must belong to the 'KieContainer'. This method provides
   * a way for 'KieSession' instances that are created programmatically to fit
   * into this framework.
   *
   * @param name the name for the new 'PolicySession'
   * @param kieSession a 'KieSession' instance, that will be included in
   *	this infrastructure
   * @return the new 'PolicySession'
   * @throws IllegalArgumentException if 'kieSession' does not reside within
   *	this container
   * @throws IllegalStateException if a 'PolicySession' already exists
   *	with this name
   */
  public PolicySession adoptKieSession(String name, KieSession kieSession)
	throws IllegalArgumentException, IllegalStateException
  {

	if(name == null){
		logger.warn("adoptKieSession:input name is null");
	}else if(kieSession == null){
		logger.warn("adoptKieSession:input kieSession is null");
	}else {
		logger.info("adoptKieSession:name: " + name + " kieSession: " + kieSession);
	}
	// fetch KieBase, and verify it belongs to this KieContainer
	boolean match = false;
	KieBase kieBase = kieSession.getKieBase();
	logger.info("adoptKieSession:kieBase: " + kieBase);
	for (String kieBaseName : kieContainer.getKieBaseNames())
	  {
		logger.info("adoptKieSession:kieBaseName: " + kieBaseName);
		if (kieBase == kieContainer.getKieBase(kieBaseName))
		  {
			match = true;
			break;
		  }
	  }
	logger.info("adoptKieSession:match " + match);
	// if we don't have a match yet, the last chance is to look at the
	// default KieBase, if it exists
	if (!match && kieBase != kieContainer.getKieBase())
	  {
		throw(new IllegalArgumentException
			  ("KieSession '" + name + "' does not reside within container "
			   + getName()));
	  }

	synchronized (sessions)
	  {
		if (sessions.get(name) != null)
		  {
			throw(new IllegalStateException
				  ("PolicySession '" + name + "' already exists"));
		  }

		// create the new 'PolicySession', add it to the table,
		// and return the object to the caller
		logger.info("adoptKieSession:create a new policySession with name " + name);
		PolicySession policySession =
		  new PolicySession(name, this, kieSession);
		sessions.put(name, policySession);
		return(policySession);
	  }
  }

  /**
   * This call 'KieContainer.updateToVersion()', and returns the associated
   * response as a String. If successful, the name of this 'PolicyContainer'
   * changes to match the new version.
   *
   * @param newVersion this is the version to update to (the 'groupId'
   *	and 'artifactId' remain the same)
   * @return the list of messages associated with the update (not sure if
   *	this can be 'null', or how to determine success/failure)
   */
  public String updateToVersion(String newVersion)
  {
	ReleaseId releaseId = kieContainer.getReleaseId();
	Results results = this.updateToVersion
	  (kieServices.newReleaseId(releaseId.getGroupId(),
								releaseId.getArtifactId(),
								newVersion));

	List<Message> messages = (results == null ? null : results.getMessages());
	return(messages == null ? null : messages.toString());
  }

  /**
   * This calls 'KieContainer.updateToVersion()', and returns the associated
   * response. If successful, the name of this 'PolicyContainer' changes to
   * match the new version.
   *
   * @param releaseId the new artifact (usually new version) to be installed
   * @return the 'Results' parameter from 'KieContainer.updateToVersion'
   */
  public Results updateToVersion(ReleaseId releaseId)
  {
    if(releaseId == null){
	   logger.warn("updateToVersion:input releaseId is null");
    }else {
       logger.info("updateToVersion:releaseId " + releaseId.toString());
    }
	return(kieContainer.updateToVersion(releaseId));
  }

  /**
   * @return all existing 'PolicyContainer' instances
   */
  public static Collection<PolicyContainer> getPolicyContainers()
  {
	synchronized(containers)
	  {
		return(new HashSet<PolicyContainer>(containers));
	  }
  }

  /**
   * @return all of the 'PolicySession' instances
   */
  public Collection<PolicySession> getPolicySessions()
  {
	// KLUDGE WARNING: this is a temporary workaround -- if there are
	// no features, we don't have persistence, and 'activate' is never
	// called. In this case, make sure the container is started.
	if (FeatureAPI.impl.getList().size() == 0)
	  {
		start();
	  }

	// return current set of PolicySessions
	synchronized(sessions)
	  {
		return(new HashSet<PolicySession>(sessions.values()));
	  }
  }

  /**
   * This method will start a 'KieScanner' (if not currently running),
   * provided that the ReleaseId version is 'LATEST' or 'RELEASE',
   * or refers to a SNAPSHOT version.
   *
   * @param releaseId the release id used to create the container
   */
  public synchronized void startScanner(ReleaseId releaseId)
  {
	String version = releaseId.getVersion();
	if (scannerStarted == false && scanner == null && version != null
		&& (version.equals("LATEST") || version.equals("RELEASE")
			|| version.endsWith("-SNAPSHOT")))
	  {
		// create the scanner, and poll at 60 second intervals
		try
		  {
			scannerStarted = true;

			// start this in a separate thread -- it can block for a long time
			new Thread("Scanner Starter " + getName())
			{
			  public void run()
			  {
				scanner = kieServices.newKieScanner(kieContainer);
				scanner.start(60000L);
			  }
			}.start();
		  }
		catch (Exception e)
		  {
			// sometimes the scanner initialization fails for some reason
			logger.error(MessageCodes.EXCEPTION_ERROR, e, "main", "startServer");
		  }
	  }
  }

  /**
   * Insert a fact into a specific named session
   *
   * @param name this is the session name
   * @param object this is the fact to be inserted into the session
   * @return 'true' if the named session was found, 'false' if not
   */
  public boolean insert(String name, Object object)
  {
	// TODO: Should the definition of 'name' be expanded to include an
	// alternate entry point as well? For example, 'name.entryPoint' (or
	// something other than '.' if that is a problem).
	synchronized (sessions)
	  {
		PolicySession session = sessions.get(name);
		if (session != null)
		  {
			session.getKieSession().insert(object);
			return(true);
		  }
	  }
	return(false);
  }

  /**
   * Insert a fact into all sessions associated with this container
   *
   * @param object this is the fact to be inserted into the sessions
   * @return 'true' if the fact was inserted into at least one session,
   *	'false' if not
   */
  public boolean insertAll(Object object)
  {
	boolean rval = false;
	synchronized (sessions)
	  {
		for (PolicySession session : sessions.values())
		  {
			session.getKieSession().insert(object);
			rval = true;
		  }
	  }
	return(rval);
  }

  /*************************/
  /* 'Startable' interface */
  /*************************/

  /**
   * {@inheritDoc}
   */
  public synchronized boolean start()
  {
	if (!isStarted)
	  {
		// This will create all 'PolicySession' instances specified in the
		// 'kmodule.xml' file that don't exist yet
		for (String kieBaseName : kieContainer.getKieBaseNames())
		  {
			for (String kieSessionName :
				   kieContainer.getKieSessionNamesInKieBase(kieBaseName))
			  {
				// if the 'PolicySession' does not currently exist, this method
				// call will attempt to create it
				PolicySession session =
				  activatePolicySession(kieSessionName, kieBaseName);
				if (session != null)
				  {
					session.startThread();
				  }
			  }
		  }
		isStarted = true;
	  }
	return(true);
  }

  /**
   * {@inheritDoc}
   */
  public synchronized boolean stop()
  {
	if (isStarted)
	  {
		Collection<PolicySession> localSessions;

		synchronized (sessions)
		  {
			// local set containing all of the sessions
			localSessions = new HashSet<PolicySession>(sessions.values());

			// clear the 'name->session' map in 'PolicyContainer'
			sessions.clear();
		  }
		for (PolicySession session : localSessions)
		  {
			// stop session thread
			session.stopThread();

			// free KieSession resources
			session.getKieSession().dispose();

			// notify features
			for (FeatureAPI feature : FeatureAPI.impl.getList())
			  {
				feature.disposeKieSession(session);
			  }
		  }
		isStarted = false;
	  }
	return(true);
  }

  /**
   * {@inheritDoc}
   */
  public synchronized void shutdown()
  {
	// Note that this method does not call 'destroy' on the 'KieSession'
	// instances, which would remove any associated information in persistent
	// storage. Should it do this?

	stop();
	synchronized(containers)
	  {
		containers.remove(this);
	  }

	// How do we free the resources associated with the KieContainer?
	// Is garbage collection sufficient?
  }

  /**
   * {@inheritDoc}
   */
  public boolean isAlive()
  {
	return(isStarted);
  }

  /*************************/

  /**
   * This method is similar to 'shutdown', but it also frees any persistence
   * resources as well.
   */
  public synchronized void destroy()
  {
	// we need all KieSession instances running in order to free
	// resources associated with persistence
	start();
	Collection<PolicySession> localSessions;

	synchronized (sessions)
	  {
		// local set containing all of the sessions
		localSessions = new HashSet<PolicySession>(sessions.values());

		// clear the 'name->session' map in 'PolicyContainer'
		sessions.clear();
	  }
	for (PolicySession session : localSessions)
	  {
		// stop session thread
		session.stopThread();

		// free KieSession resources
		session.getKieSession().destroy();

		// notify features
		for (FeatureAPI feature : FeatureAPI.impl.getList())
		  {
			feature.destroyKieSession(session);
		  }
	  }
	isStarted = false;

	synchronized(containers)
	  {
		containers.remove(this);
	  }

	// How do we free the resources associated with the KieContainer?
	// Is garbage collection sufficient?
  }

  /**
   * This method is called when the host goes from the 'standby->active' state.
   */
  static public void activate()
  {
	// start all of the 'PolicyContainer' instances
	for (PolicyContainer container : containers)
	  {
		try
		  {
			container.start();
		  }
		catch (Exception e)
		  {
			e.printStackTrace();
			logger.error(MessageCodes.EXCEPTION_ERROR, e,
							   "activate",
							   "PolicyContainer.start()");
		  }
	  }
  }

  /**
   * This method is called when the host goes from the 'active->standby' state.
   */
  static public void deactivate()
  {
	// deactivate all of the 'PolicyContainer' instances
	for (PolicyContainer container : containers)
	  {
		try
		  {
			container.stop();
		  }
		catch (Exception e)
		  {
			e.printStackTrace();
			logger.error(MessageCodes.EXCEPTION_ERROR, e,
							   "deactivate",
							   "PolicyContainer.stop()");
		  }
	  }
  }

  /**
   * This method does the following:
   *
   *	1) Initializes logging
   *	2) Starts the DroolsPDP Integrity Monitor
   *	3) Initilaizes persistence
   *
   * It no longer reads in properties files, o creates 'PolicyContainer'
   * instances.
   *
   * @param args standard 'main' arguments, which are currently ignored
   */
  public static void globalInit(String args[])
  {
	  
	/*
	 * When JUnit testing, working directory should be
	 * "../policy-management". In test environment, command line argument
	 * should specify the relative path from this directory to the config
	 * directory ("src/test/server/config")
	 */
	String configDir = "config";
	if (isUnitTesting) {
		configDir = "src/test/server/config";
	} 
	System.out.println("PolicyContainer.main: configDir=" + configDir);
	
	logger.info("Calling initlogger");
	
	initlogger(configDir);
	logger.info("initlogger returned");

	// invoke 'globalInit' on all of the features
	for (FeatureAPI feature : FeatureAPI.impl.getList())
	  {
		feature.globalInit(args, configDir);
	  }
  }

  /**
   * Read in the logger properties
   */
  private static void initlogger(String configDir){
		try {
			Properties properties =
					  PropertyUtil.getProperties(configDir + "/policyLogger.properties");			
			try {
				
				PolicyLogger.init(properties);
				
			} catch (Exception e) {
				logger.error(MessageCodes.MISS_PROPERTY_ERROR, e, "initlogger");
			}
		} catch (IOException e1) {
			logger.error(MessageCodes.MISS_PROPERTY_ERROR, e1, "initlogger");
		}
  }
	
  /**
   * Fetch the adjunct object associated with a given feature
   *
   * @param object this is typically the singleton feature object that is
   *	used as a key, but it might also be useful to use nested objects
   *	within the feature as keys.
   * @return a feature-specific object associated with the key, or 'null'
   *	if it is not found.
   */
  public Object getAdjunct(Object object)
  {
	return(adjuncts.get(object));
  }

  /**
   * Store the adjunct object associated with a given feature
   *
   * @param object this is typically the singleton feature object that is
   *	used as a key, but it might also be useful to use nested objects
   *	within the feature as keys.
   * @param value a feature-specific object associated with the key, or 'null'
   *	if the feature-specific object should be removed
   */
  public void setAdjunct(Object object, Object value)
  {
	if (value == null)
	  {
		adjuncts.remove(object);
	  }
	else
	  {
		adjuncts.put(object, value);
	  }
  }
}