2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
 
   6  * Modifications Copyright (C) 2019 Nordix Foundation.
 
   7  * ================================================================================
 
   8  * Licensed under the Apache License, Version 2.0 (the "License");
 
   9  * you may not use this file except in compliance with the License.
 
  10  * You may obtain a copy of the License at
 
  12  *      http://www.apache.org/licenses/LICENSE-2.0
 
  14  * Unless required by applicable law or agreed to in writing, software
 
  15  * distributed under the License is distributed on an "AS IS" BASIS,
 
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  17  * See the License for the specific language governing permissions and
 
  18  * limitations under the License.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.policy.controlloop.policy.builder;
 
  24 import org.onap.policy.aai.Pnf;
 
  25 import org.onap.policy.controlloop.policy.ControlLoop;
 
  26 import org.onap.policy.controlloop.policy.OperationsAccumulateParams;
 
  27 import org.onap.policy.controlloop.policy.Policy;
 
  28 import org.onap.policy.controlloop.policy.PolicyParam;
 
  29 import org.onap.policy.controlloop.policy.PolicyResult;
 
  30 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
 
  31 import org.onap.policy.sdc.Resource;
 
  32 import org.onap.policy.sdc.Service;
 
  34 public interface ControlLoopPolicyBuilder {
 
  37      * Adds one or more services to the ControlLoop.
 
  39      * @param services service to add
 
  40      * @return builder object
 
  41      * @throws BuilderException builder exception
 
  43     public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
 
  48      * @param services to remove
 
  49      * @return builder object
 
  50      * @throws BuilderException builder exception
 
  52     public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
 
  55      * Remove all the services.
 
  57      * @return builder object
 
  58      * @throws BuilderException builder exception
 
  60     public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
 
  63      * Adds one or more resources to the ControlLoop.
 
  65      * @return builder object
 
  66      * @throws BuilderException builder exception
 
  68     public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
 
  71      * Remove the resources.
 
  73      * @param resources resources to be removed
 
  75      * @throws BuilderException builder exception
 
  77     public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
 
  80      * Remove all resources.
 
  83      * @throws BuilderException builder exception
 
  85     public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
 
  90      * @param pnf input pnf
 
  91      * @return builder object
 
  92      * @throws BuilderException builder exception
 
  94     public ControlLoopPolicyBuilder setPnf(Pnf pnf) throws BuilderException;
 
 100      * @throws BuilderException builder exception
 
 102     public ControlLoopPolicyBuilder removePnf() throws BuilderException;
 
 107      * @param abatement whether abatement is possible
 
 109      * @throws BuilderException builder exception
 
 111     public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
 
 115      * Sets the overall timeout value for the Control Loop. If any operational policies have retries
 
 116      * and timeouts, then this overall timeout value should exceed all those values.
 
 118      * @param timeout timeout value
 
 119      * @return control loop policy builder
 
 120      * @throws BuilderException builder exception
 
 122     public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
 
 125      * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
 
 130     public Integer calculateTimeout();
 
 133      * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy
 
 137      * @param policy Policy parameters object
 
 138      * @return Policy object
 
 139      * @throws BuilderException builder exception
 
 141     public Policy setTriggerPolicy(PolicyParam policy) throws BuilderException;
 
 144      * Changes the trigger policy to point to another existing Policy.
 
 147      * @return ControlLoop object
 
 148      * @throws BuilderException build exception
 
 150     public ControlLoop setExistingTriggerPolicy(String id) throws BuilderException;
 
 155      * @return true or false
 
 157     public boolean isOpenLoop();
 
 160      * Get the trigger policy.
 
 162      * @return the policy object
 
 163      * @throws BuilderException if there is a builder exception
 
 165     public Policy getTriggerPolicy() throws BuilderException;
 
 168      * Simply returns a copy of the ControlLoop information.
 
 171      * @return ControlLoop
 
 173     public ControlLoop getControlLoop();
 
 176      * Creates a policy that is chained to the result of another Policy.
 
 178      * @param policyParam policy parameters object
 
 179      * @param results results
 
 180      * @return Policy that was set
 
 181      * @throws BuilderException builder exception
 
 183     public Policy setPolicyForPolicyResult(PolicyParam policyParam, PolicyResult... results)
 
 184             throws BuilderException;
 
 188      * Sets the policy result(s) to an existing Operational Policy.
 
 190      * @param policyResultId result ID
 
 192      * @param results results
 
 193      * @return Policy that was set
 
 194      * @throws BuilderException builder exception
 
 196     public Policy setPolicyForPolicyResult(String policyResultId, String policyId, PolicyResult... results)
 
 197             throws BuilderException;
 
 200      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results
 
 201      * that point to this policy, any policies that have results pointing to this policy will have
 
 202      * their result reset to the appropriate default FINAL_* result.
 
 205      * @param policyID id for the policy
 
 206      * @return true if removed else false
 
 207      * @throws BuilderException builder exception
 
 209     public boolean removePolicy(String policyID) throws BuilderException;
 
 212      * Resets a policy's results to defualt FINAL_* codes.
 
 214      * @return Policy object
 
 215      * @throws BuilderException - Policy does not exist
 
 217     public Policy resetPolicyResults(String policyID) throws BuilderException;
 
 220      * Removes all existing Operational Policies and reverts back to an Open Loop.
 
 222      * @return Policy builder object
 
 224     public ControlLoopPolicyBuilder removeAllPolicies();
 
 227      * Adds an operationsAccumulateParams to an existing operational policy.
 
 230      * @throws BuilderException - Policy does not exist
 
 232     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams)
 
 233             throws BuilderException;
 
 236      * This will compile and build the YAML specification for the Control Loop Policy. Please
 
 237      * iterate the Results object for details. The Results object will contains warnings and errors.
 
 238      * If the specification compiled successfully, you will be able to retrieve the YAML.
 
 242     public Results buildSpecification();
 
 245      * The Factory is used to build a ControlLoopPolicyBuilder implementation.
 
 247      * @author pameladragosh
 
 250     public static class Factory {
 
 252             // Private Constructor.
 
 256          * Builds a basic Control Loop with an overall timeout. Use this method if you wish to
 
 257          * create an OpenLoop, or if you want to interactively build a Closed Loop.
 
 259          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 260          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 261          * @return ControlLoopPolicyBuilder object
 
 263         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout) {
 
 264             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout);
 
 268          * Build a Control Loop for a resource and services associated with the resource.
 
 270          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 271          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 272          * @param resource - Resource this closed loop is for. Should come from ASDC, but if not
 
 273          *        available use resourceName to distinguish.
 
 274          * @param services - Zero or more services associated with this resource. Should come from
 
 275          *        ASDC, but if not available use serviceName to distinguish.
 
 276          * @return ControlLoopPolicyBuilder object
 
 277          * @throws BuilderException builder exception
 
 279         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
 
 280                 Resource resource, Service... services) throws BuilderException {
 
 281             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
 
 285          * Build the control loop.
 
 287          * @param controlLoopName control loop id
 
 288          * @param timeout timeout
 
 289          * @param service service
 
 290          * @param resources resources
 
 291          * @return builder object
 
 292          * @throws BuilderException builder exception
 
 294         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout,
 
 295                 Service service, Resource... resources) throws BuilderException {
 
 296             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
 
 300          * Build control loop.
 
 302          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 303          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 304          * @param pnf - Physical Network Function. Should come from AIC, but if not available use
 
 305          *        well-known name to distinguish. Eg. eNodeB
 
 306          * @return ControlLoopPolicyBuilder object
 
 307          * @throws BuilderException builder exception
 
 309         public static ControlLoopPolicyBuilder buildControlLoop(String controlLoopName, Integer timeout, Pnf pnf)
 
 310                 throws BuilderException {
 
 311             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);