2  * ============LICENSE_START=======================================================
 
   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
 
  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.PolicyResult;
 
  30 import org.onap.policy.controlloop.policy.Target;
 
  31 import org.onap.policy.controlloop.policy.builder.impl.ControlLoopPolicyBuilderImpl;
 
  32 import org.onap.policy.sdc.Resource;
 
  33 import org.onap.policy.sdc.Service;
 
  35 public interface ControlLoopPolicyBuilder {
 
  38      * Adds one or more services to the ControlLoop
 
  43      * @throws BuilderException
 
  45     public ControlLoopPolicyBuilder addService(Service... services) throws BuilderException;
 
  50      * @throws BuilderException
 
  52     public ControlLoopPolicyBuilder removeService(Service... services) throws BuilderException;
 
  56      * @throws BuilderException
 
  58     public ControlLoopPolicyBuilder removeAllServices() throws BuilderException;
 
  61      * Adds one or more resources to the ControlLoop
 
  66      * @throws BuilderException
 
  68     public ControlLoopPolicyBuilder addResource(Resource... resources) throws BuilderException;
 
  73      * @throws BuilderException
 
  75     public ControlLoopPolicyBuilder removeResource(Resource... resources) throws BuilderException;
 
  79      * @throws BuilderException
 
  81     public ControlLoopPolicyBuilder removeAllResources() throws BuilderException;
 
  86      * @throws BuilderException
 
  88     public ControlLoopPolicyBuilder setPNF(PNF pnf) throws BuilderException;
 
  92      * @throws BuilderException
 
  94     public ControlLoopPolicyBuilder removePNF() throws BuilderException;
 
  99      *  @throws BuilderException
 
 101     public ControlLoopPolicyBuilder setAbatement(Boolean abatement) throws BuilderException;
 
 105      * Sets the overall timeout value for the Control Loop. If any operational policies have retries and timeouts,
 
 106      * then this overall timeout value should exceed all those values.
 
 110      * @throws BuilderException
 
 112     public ControlLoopPolicyBuilder setTimeout(Integer timeout) throws BuilderException;
 
 115      * Scans the operational policies and calculate an minimum overall timeout for the Control Loop.
 
 120     public Integer calculateTimeout();
 
 123      * Sets the initial trigger policy when a DCAE Closed Loop Event arrives in the ONAP Policy Platform.
 
 134      * @throws BuilderException
 
 136     public Policy setTriggerPolicy(String name, String description, String actor, Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout) throws BuilderException;
 
 140      * Changes the trigger policy to point to another existing Policy.
 
 144      * @return ControlLoop
 
 145      * @throws BuilderException
 
 147     public ControlLoop  setTriggerPolicy(String id) throws BuilderException;
 
 152     public boolean  isOpenLoop();
 
 156      * @throws BuilderException
 
 158     public Policy   getTriggerPolicy() throws BuilderException;
 
 161      * Simply returns a copy of the ControlLoop information.
 
 164      * @return ControlLoop
 
 166     public ControlLoop  getControlLoop();
 
 169      * Creates a policy that is chained to the result of another Policy.
 
 182      * @throws BuilderException
 
 184     public Policy setPolicyForPolicyResult(String name, String description, String actor,
 
 185             Target target, String recipe, Map<String, String> payload, Integer retries, Integer timeout, String policyID, PolicyResult... results) throws BuilderException;
 
 189      * Sets the policy result(s) to an existing Operational Policy.
 
 192      * @param policyResultID
 
 196      * @throws BuilderException
 
 198     public Policy setPolicyForPolicyResult(String policyResultID, String policyID, PolicyResult... results) throws BuilderException;
 
 201      * Removes an Operational Policy. Be mindful that if any other Operational Policies have results that point to this policy, any
 
 202      * policies that have results pointing to this policy will have their result reset to the appropriate default FINAL_* result.
 
 207      * @throws BuilderException
 
 209     public boolean removePolicy(String policyID) throws BuilderException;
 
 212      * Resets a policy's results to defualt FINAL_* codes.
 
 216      * @throws BuilderException - Policy does not exist
 
 218     public Policy   resetPolicyResults(String policyID) throws BuilderException;
 
 221      * Removes all existing Operational Policies and reverts back to an Open Loop.
 
 225     public ControlLoopPolicyBuilder removeAllPolicies();
 
 228      * Adds an operationsAccumulateParams to an existing operational policy
 
 231      * @throws BuilderException - Policy does not exist
 
 233     public Policy addOperationsAccumulateParams(String policyID, OperationsAccumulateParams operationsAccumulateParams) throws BuilderException;
 
 236      * This will compile and build the YAML specification for the Control Loop Policy. Please iterate the Results object for details.
 
 237      * The Results object will contains warnings and errors. If the specification compiled successfully, you will be able to retrieve the
 
 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 create an OpenLoop, or if you 
 
 257          * 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 available use resourceName to distinguish.
 
 273          * @param services - Zero or more services associated with this resource. Should come from ASDC, but if not available use serviceName to distinguish.
 
 274          * @return ControlLoopPolicyBuilder object
 
 275          * @throws BuilderException
 
 277         public static ControlLoopPolicyBuilder  buildControlLoop (String controlLoopName, Integer timeout, Resource resource, Service... services) throws BuilderException {
 
 278             return  new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, resource, services);
 
 282          * @param controlLoopName
 
 287          * @throws BuilderException
 
 289         public static ControlLoopPolicyBuilder  buildControlLoop (String controlLoopName, Integer timeout, Service service, Resource... resources) throws BuilderException {
 
 290             return  new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, service, resources);
 
 294          * @param controlLoopName - Per Closed Loop AID v1.0, unique string for the closed loop.
 
 295          * @param timeout - Overall timeout for the Closed Loop to execute.
 
 296          * @param pnf - Physical Network Function. Should come from AIC, but if not available use well-known name to distinguish. Eg. eNodeB
 
 297          * @return ControlLoopPolicyBuilder object
 
 298          * @throws BuilderException
 
 300         public static ControlLoopPolicyBuilder  buildControlLoop (String controlLoopName, Integer timeout, PNF pnf) throws BuilderException {
 
 301             return new ControlLoopPolicyBuilderImpl(controlLoopName, timeout, pnf);