70ad3719215e092b40175dcdcedb3a57c3aabd0d
[policy/drools-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * policy-core
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.statemanagement;
22
23 import java.util.Observer;
24
25 import javax.validation.constraints.NotNull;
26
27 import org.onap.policy.common.im.AllSeemsWellException;
28 import org.onap.policy.common.im.StandbyStatusException;
29 import org.onap.policy.common.im.StateManagement;
30 import org.onap.policy.drools.properties.Lockable;
31 import org.onap.policy.drools.utils.OrderedService;
32 import org.onap.policy.drools.utils.OrderedServiceImpl;
33
34 /**
35  * This interface provides a way to invoke optional features at various
36  * points in the code. At appropriate points in the
37  * application, the code iterates through this list, invoking these optional
38  * methods. Most of the methods here are notification only -- these tend to
39  * return a 'void' value. In other cases, such as 'activatePolicySession',
40  * may 
41  */
42 public interface StateManagementFeatureAPI extends OrderedService, Lockable
43 {
44         
45         public static final String LOCKED               = StateManagement.LOCKED;
46           public static final String UNLOCKED             = StateManagement.UNLOCKED;
47           public static final String ENABLED              = StateManagement.ENABLED;
48           public static final String DISABLED             = StateManagement.DISABLED;
49           public static final String ENABLE_NOT_FAILED    = StateManagement.ENABLE_NOT_FAILED;
50           public static final String DISABLE_FAILED       = StateManagement.DISABLE_FAILED;
51           public static final String FAILED               = StateManagement.FAILED;
52           public static final String DEPENDENCY           = StateManagement.DEPENDENCY;
53           public static final String DEPENDENCY_FAILED    = StateManagement.DEPENDENCY_FAILED;
54           public static final String DISABLE_DEPENDENCY   = StateManagement.DISABLE_DEPENDENCY;
55           public static final String ENABLE_NO_DEPENDENCY = StateManagement.ENABLE_NO_DEPENDENCY;
56           public static final String NULL_VALUE           = StateManagement.NULL_VALUE;
57           public static final String LOCK                 = StateManagement.LOCK;
58           public static final String UNLOCK               = StateManagement.UNLOCK;
59           public static final String PROMOTE              = StateManagement.PROMOTE;
60           public static final String DEMOTE               = StateManagement.DEMOTE;
61           public static final String HOT_STANDBY          = StateManagement.HOT_STANDBY;
62           public static final String COLD_STANDBY         = StateManagement.COLD_STANDBY;
63           public static final String PROVIDING_SERVICE    = StateManagement.PROVIDING_SERVICE;
64           
65           public static final String ADMIN_STATE     = StateManagement.ADMIN_STATE;
66           public static final String OPERATION_STATE = StateManagement.OPERATION_STATE;
67           public static final String AVAILABLE_STATUS= StateManagement.AVAILABLE_STATUS;
68           public static final String STANDBY_STATUS  = StateManagement.STANDBY_STATUS;
69           
70           static public final Boolean ALLSEEMSWELL = Boolean.TRUE;
71           static public final Boolean ALLNOTWELL = Boolean.FALSE;
72           
73           public static final int SEQ_NUM = 0;
74   /**
75    * 'FeatureAPI.impl.getList()' returns an ordered list of objects
76    * implementing the 'FeatureAPI' interface.
77    */
78   public static OrderedServiceImpl<StateManagementFeatureAPI> impl =
79         new OrderedServiceImpl<>(StateManagementFeatureAPI.class);
80
81   /**
82    * ALL SEEMS/NOT WELL
83    * This interface is used to support the concept of All Seems/Not Well.  It provides
84    * a way for client code to indicate to the DroolsPDPIntegrityMonitor that an event 
85    * has occurred which is disabling (or enabling) for the Drools PDP.  The call is
86    * actually implemented in the common modules IntegrityMonitor where it will cause
87    * the testTransaction to fail if any module has set the value ALLNOTWELL, stopping
88    * the forward progress counter and eventually causing the operational state to 
89    * become disabled.
90    * 
91    * ALLSEEMSWELL is passed to the method when the client is healthy
92    * ALLNOTWELL is passed to the method when the client is disabled
93    * 
94    * @param key - This should be a unique identifier for the entity making the call (e.g., class name)
95    * @param asw - This is the indicator of health. See constants: ALLSEEMSWELL or ALLNOTWELL
96    * @param msg - A message is required.  It should indicate why all is not well or a message indicating
97    * that a component has been restored to health (perhaps indicating the problem that has resolved).
98    * @throws IllegalArgumentException
99    * @throws AllSeemsWellException
100    */
101   public void allSeemsWell(@NotNull String key, @NotNull Boolean asw, @NotNull String msg)
102                   throws IllegalArgumentException, AllSeemsWellException;
103   
104   /**
105    * This method is called to add an Observer to receive notifications of state changes
106    * 
107    * @param stateChangeObserver
108    */
109   public void addObserver(Observer stateChangeObserver);
110
111   /**
112    * This method returns the X.731 Administrative State for this resource
113    * 
114    * @return String (locked, unlocked)
115    */
116   public String getAdminState();
117   
118   /**
119    * This method returns the X.731 Operational State for this resource
120    * 
121    * @return String (enabled, disabled)
122    */
123   public String getOpState();
124   
125   /**
126    * This method returns the X.731 Availability Status for this resource
127    * 
128    * @return String (failed; dependency; dependency,failed)
129    */
130   public String getAvailStatus();
131     
132   /**
133    * This method returns the X.731 Standby Status for this resource
134    * 
135    * @return String (providingservice, hotstandby or coldstandby)
136    */
137   public String getStandbyStatus();
138   
139   /**
140    * This method returns the X.731 Standby Status for the named resource
141    * @param String (resourceName)
142    * @return String (providingservice, hotstandby or coldstandby)
143    */
144   public String getStandbyStatus(String resourceName);
145   
146   /**
147    * This method moves the X.731 Operational State for the named resource
148    * into a value of disabled and the Availability Status to a value of failed.
149    * As a consequence the Standby Status value will take a value of coldstandby.
150    * 
151    * @param String (resourceName)
152    * @throws Exception 
153    */
154   public void disableFailed(String resourceName) throws Exception;
155   
156   /**
157    * This method moves the X.731 Operational State for this resource
158    * into a value of disabled and the Availability Status to a value of failed.
159    * As a consequence the Standby Status value will take a value of coldstandby.
160    * 
161    * @param String (resourceName)
162    * @throws Exception 
163    */
164   public void disableFailed() throws Exception;
165   
166   /**
167    * This method moves the X.731 Standby Status for this resource from hotstandby 
168    * to providingservice. If the current value is coldstandby, no change is made.
169    * If the current value is null, it will move to providingservice assuming the
170    * Operational State is enabled and Administrative State is unlocked.
171    * @throws Exception 
172    * @throws StandbyStatusException 
173    */
174   public void promote() throws StandbyStatusException, Exception;
175   
176   /**
177    * This method moves the X.731 Standby Status for this resource from providingservice 
178    * to hotstandby. If the current value is null, it will move to hotstandby assuming the
179    * Operational State is enabled and Administrative State is unlocked. Else, it will move
180    * to coldstandby
181    * @throws Exception 
182    */
183   public void demote() throws Exception;
184   
185   /**
186    * This method returns the resourceName associated with this instance of the StateManagementFeature 
187    * @return String (resourceName)
188    */
189   public String getResourceName();
190
191   /**
192    * This Lockable method will lock the StateManagement object Admin state
193    * @return true if successfull, false otherwise
194    */
195   @Override
196   public boolean lock();
197   
198   /**
199    * This Lockable method will unlock the StateManagement object Admin state
200    * @return true if successfull, false otherwise
201    */
202   @Override
203   public boolean unlock();
204
205   /**
206    * This Lockable method indicates the Admin state StateManagement object 
207    * @return true if locked, false otherwise
208    */
209   @Override
210   public boolean isLocked();
211 }