aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/ControlLoopPolicyBuilder.java
blob: 533e19b72990878382190dd0ddd5c718583647d9 (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
/*-
 * ============LICENSE_START=======================================================
 * policy-yaml
 * ================================================================================
 * Copyright (C) 2017-2018 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.onap.policy.controlloop.policy.builder;

import org.onap.policy.aai.Pnf;
import org.onap.policy.controlloop.policy.ControlLoop;
import org.onap.policy.controlloop.policy.OperationsAccumulateParams;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyParam;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.Service;

public interface ControlLoopPolicyBuilder {

    /**
     * Adds one or more services to the ControlLoop.
     * 
     * @param services service to add
     * @return builder object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;

    /**
     * Remove service.
     * 
     * @param services to remove
     * @return builder object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;

    /**
     * Remove all the services.
     * 
     * @return builder object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;

    /**
     * Adds one or more resources to the ControlLoop.
     * 
     * @return builder object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;

    /**
     * Remove the resources.
     * 
     * @param resources resources to be removed
     * @return object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;

    /**
     * Remove all resources.
     * 
     * @return object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;

    /**
     * Set the PNF.
     * 
     * @param pnf input pnf
     * @return builder object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;

    /**
     * Remove PNF.
     * 
     * @return the object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder removePNF() throws BuilderException;

    /**
     * Set the abatement.
     * 
     * @param abatement whether abatement is possible
     * @return object
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;


    /**
     * Sets the overall timeout value for the Control Loop. If any operational policies have retries
     * and timeouts, then this overall timeout value should exceed all those values.
     * 
     * @param timeout timeout value
     * @return control loop policy builder
     * @throws BuilderException builder exception
     */
    public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;

    /**
     * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
     * 
     * 
     * @return Integer
     */
    public Integer calculateTimeout();

    /**
     * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
     * Platform.
     * 
     * 
     * @param policy Policy parameters object
     * @return Policy object
     * @throws BuilderException builder exception
     */
    public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;

    /**
     * Changes the trigger policy to point to another existing Policy.
     * 
     * @param id the id
     * @return ControlLoop object
     * @throws BuilderException build exception
     */
    public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;

    /**
     * Is an open loop.
     * 
     * @return true or false
     */
    public boolean isOpenLoop();

    /**
     * Get the trigger policy.
     * 
     * @return the policy object
     * @throws BuilderException if there is a builder exception
     */
    public Policy getTriggerPolicy() throws BuilderException;

    /**
     * Simply returns a copy of the ControlLoop information.
     * 
     * 
     * @return ControlLoop
     */
    public ControlLoop getControlLoop();

    /**
     * Creates a policy that is chained to the result of another Policy.
     * 
     * @param policyParam policy parameters object
     * @param results results
     * @return Policy that was set
     * @throws BuilderException builder exception
     */
    public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results)
            throws BuilderException;


    /**
     * Sets the policy result(s) to an existing Operational Policy.
     * 
     * @param policyResultId result ID
     * @param policyId id
     * @param results results
     * @return Policy that was set
     * @throws BuilderException builder exception
     */
    public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
            throws BuilderException;

    /**
     * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
     * that point to this policy, any policies that have results pointing to this policy will have
     * their result reset to the appropriate default FINAL_* result.
     * 
     * 
     * @param policyID id for the policy
     * @return true if removed else false
     * @throws BuilderException builder exception
     */
    public boolean removePolicy(String policyID) throws BuilderException;

    /**
     * Resets a policy's results to defualt FINAL_* codes.
     * 
     * @return Policy object
     * @throws BuilderException - Policy does not exist
     */
    public Policy resetPolicyResults(String policyID) throws BuilderException;

    /**
     * Removes all existing Operational Policies and reverts back to an Open Loop.
     * 
     * @return Policy builder object
     */
    public ControlLoopPolicyBuilder removeAllPolicies();

    /**
     * Adds an operationsAccumulateParams to an existing operational policy.
     * 
     * @return Policy
     * @throws BuilderException - Policy does not exist
     */
    public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
            throws BuilderException;

    /**
     * This will compile and build the YAML specification for the Control Loop Policy. Please
     * iterate the Results object for details. The Results object will contains warnings and errors.
     * If the specification compiled successfully, you will be able to retrieve the YAML.
     * 
     * @return Results
     */
    public Results buildSpecification();

    /**
     * The Factory is used to build a ControlLoopPolicyBuilder implementation.
     * 
     * @author pameladragosh
     *
     */
    public static class Factory {
        private Factory() {
            // Private Constructor.
        }

        /**
         * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
         * create an OpenLoop, or if you want to interactively build a Closed Loop.
         * 
         * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
         * @param timeout - Overall timeout for the Closed Loop to execute.
         * @return ControlLoopPolicyBuilder object
         */
        public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
            return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
        }

        /**
         * Build a Control Loop for a resource and services associated with the resource.
         * 
         * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
         * @param timeout - Overall timeout for the Closed Loop to execute.
         * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
         *        available use resourceName to distinguish.
         * @param services - Zero or more services associated with this resource. Should come from
         *        ASDC, but if not available use serviceName to distinguish.
         * @return ControlLoopPolicyBuilder object
         * @throws BuilderException builder exception
         */
        public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
                Resource resource, Service... services) throws BuilderException {
            return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
        }

        /**
         * Build the control loop.
         * 
         * @param controlLoopName control loop id
         * @param timeout timeout
         * @param service service
         * @param resources resources
         * @return builder object
         * @throws BuilderException builder exception
         */
        public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
                Service service, Resource... resources) throws BuilderException {
            return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
        }

        /**
         * Build control loop.
         * 
         * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
         * @param timeout - Overall timeout for the Closed Loop to execute.
         * @param pnf - Physical Network Function. Should come from AIC, but if not available use
         *        well-known name to distinguish. Eg. eNodeB
         * @return ControlLoopPolicyBuilder object
         * @throws BuilderException builder exception
         */
        public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
                throws BuilderException {
            return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);
        }
    }

}