2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  21 package org.onap.policy.controlloop.policy.builder;
 
  25 import org.onap.policy.aai.Pnf;
 
  26 import org.onap.policy.controlloop.policy.ControlLoop;
 
  27 import org.onap.policy.controlloop.policy.OperationsAccumulateParams;
 
  28 import org.onap.policy.controlloop.policy.Policy;
 
  29 import org.onap.policy.controlloop.policy.PolicyParam;
 
  30 import org.onap.policy.controlloop.policy.PolicyResult;
 
  31 import org.onap.policy.controlloop.policy.Target;
 
  32 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
 
  33 import org.onap.policy.sdc.Resource;
 
  34 import org.onap.policy.sdc.Service;
 
  36 public interface ControlLoopPolicyBuilder {
 
  39      * Adds one or more services to the ControlLoop.
 
  41      * @param services service to add
 
  42      * @return builder object
 
  43      * @throws BuilderException builder exception
 
  45     public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
 
  50      * @param services to remove
 
  51      * @return builder object
 
  52      * @throws BuilderException builder exception
 
  54     public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
 
  57      * Remove all the services.
 
  59      * @return builder object
 
  60      * @throws BuilderException builder exception
 
  62     public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
 
  65      * Adds one or more resources to the ControlLoop.
 
  67      * @return builder object
 
  68      * @throws BuilderException builder exception
 
  70     public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
 
  73      * Remove the resources.
 
  75      * @param resources resources to be removed
 
  77      * @throws BuilderException builder exception
 
  79     public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
 
  82      * Remove all resources.
 
  85      * @throws BuilderException builder exception
 
  87     public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
 
  92      * @param pnf input pnf
 
  93      * @return builder object
 
  94      * @throws BuilderException builder exception
 
  96     public ControlLoopPolicyBuilder setPNF(Pnf pnf) throws BuilderException;
 
 102      * @throws BuilderException builder exception
 
 104     public ControlLoopPolicyBuilder removePNF() throws BuilderException;
 
 109      * @param abatement whether abatement is possible
 
 111      * @throws BuilderException builder exception
 
 113     public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
 
 117      * Sets the overall timeout value for the Control Loop. If any operational policies have retries
 
 118      * and timeouts, then this overall timeout value should exceed all those values.
 
 120      * @param timeout timeout value
 
 121      * @return control loop policy builder
 
 122      * @throws BuilderException builder exception
 
 124     public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
 
 127      * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
 
 132     public Integer calculateTimeout();
 
 135      * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
 
 139      * @param policy Policy parameters object
 
 140      * @return Policy object
 
 141      * @throws BuilderException builder exception
 
 143     public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;
 
 146      * Changes the trigger policy to point to another existing Policy.
 
 149      * @return ControlLoop object
 
 150      * @throws BuilderException build exception
 
 152     public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;
 
 157      * @return true or false
 
 159     public boolean isOpenLoop();
 
 162      * Get the trigger policy.
 
 164      * @return the policy object
 
 165      * @throws BuilderException if there is a builder exception
 
 167     public Policy getTriggerPolicy() throws BuilderException;
 
 170      * Simply returns a copy of the ControlLoop information.
 
 173      * @return ControlLoop
 
 175     public ControlLoop getControlLoop();
 
 178      * Creates a policy that is chained to the result of another Policy.
 
 180      * @param policyParam policy parameters object
 
 181      * @param results results
 
 182      * @return Policy that was set
 
 183      * @throws BuilderException builder exception
 
 185     public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results)
 
 186             throws BuilderException;
 
 190      * Sets the policy result(s) to an existing Operational Policy.
 
 192      * @param policyResultId result ID
 
 194      * @param results results
 
 195      * @return Policy that was set
 
 196      * @throws BuilderException builder exception
 
 198     public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
 
 199             throws BuilderException;
 
 202      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
 
 203      * that point to this policy, any policies that have results pointing to this policy will have
 
 204      * their result reset to the appropriate default FINAL_* result.
 
 207      * @param policyID id for the policy
 
 208      * @return true if removed else false
 
 209      * @throws BuilderException builder exception
 
 211     public boolean removePolicy(String policyID) throws BuilderException;
 
 214      * Resets a policy's results to defualt FINAL_* codes.
 
 216      * @return Policy object
 
 217      * @throws BuilderException - Policy does not exist
 
 219     public Policy resetPolicyResults(String policyID) throws BuilderException;
 
 222      * Removes all existing Operational Policies and reverts back to an Open Loop.
 
 224      * @return Policy builder object
 
 226     public ControlLoopPolicyBuilder removeAllPolicies();
 
 229      * Adds an operationsAccumulateParams to an existing operational policy.
 
 232      * @throws BuilderException - Policy does not exist
 
 234     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
 
 235             throws BuilderException;
 
 238      * This will compile and build the YAML specification for the Control Loop Policy. Please
 
 239      * iterate the Results object for details. The Results object will contains warnings and errors.
 
 240      * If the specification compiled successfully, you will be able to retrieve the YAML.
 
 244     public Results buildSpecification();
 
 247      * The Factory is used to build a ControlLoopPolicyBuilder implementation.
 
 249      * @author pameladragosh
 
 252     public static class Factory {
 
 254             // Private Constructor.
 
 258          * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
 
 259          * create an OpenLoop, or if you want to interactively build a Closed Loop.
 
 261          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 262          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 263          * @return ControlLoopPolicyBuilder object
 
 265         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
 
 266             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
 
 270          * Build a Control Loop for a resource and services associated with the resource.
 
 272          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 273          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 274          * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
 
 275          *        available use resourceName to distinguish.
 
 276          * @param services - Zero or more services associated with this resource. Should come from
 
 277          *        ASDC, but if not available use serviceName to distinguish.
 
 278          * @return ControlLoopPolicyBuilder object
 
 279          * @throws BuilderException builder exception
 
 281         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
 
 282                 Resource resource, Service... services) throws BuilderException {
 
 283             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
 
 287          * Build the control loop.
 
 289          * @param controlLoopName control loop id
 
 290          * @param timeout timeout
 
 291          * @param service service
 
 292          * @param resources resources
 
 293          * @return builder object
 
 294          * @throws BuilderException builder exception
 
 296         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
 
 297                 Service service, Resource... resources) throws BuilderException {
 
 298             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
 
 302          * Build control loop.
 
 304          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 305          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 306          * @param pnf - Physical Network Function. Should come from AIC, but if not available use
 
 307          *        well-known name to distinguish. Eg. eNodeB
 
 308          * @return ControlLoopPolicyBuilder object
 
 309          * @throws BuilderException builder exception
 
 311         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
 
 312                 throws BuilderException {
 
 313             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);