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;
24 public enum FinalResult {
26 * The Control Loop Policy successfully completed its Operations.
28 FINAL_SUCCESS("Final_Success"),
30 * The Control Loop Policy was an Open Loop and is finished.
32 FINAL_OPENLOOP("Final_OpenLoop"),
34 * The Control Loop Policy failed in its last Operation Policy.
35 * NOTE: Previous Operation Policies may have been successful.
37 FINAL_FAILURE("Final_Failure"),
39 * The Control Loop Policy failed because the overall timeout was met.
41 FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"),
43 * The Control Loop Policy failed because an Operation Policy met its retry limit.
45 FINAL_FAILURE_RETRIES("Final_Failure_Retries"),
47 * The Control Loop Policy failed due to an exception.
49 FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"),
51 * The Control Loop Policy failed due to guard denied.
53 FINAL_FAILURE_GUARD("Final_Failure_Guard")
58 private FinalResult(String result) {
63 * Converts to a result object.
65 * @param result input string
66 * @return result object
68 public static FinalResult toResult(String result) {
69 if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
72 if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) {
73 return FINAL_OPENLOOP;
75 if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) {
78 if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) {
79 return FINAL_FAILURE_TIMEOUT;
81 if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) {
82 return FINAL_FAILURE_RETRIES;
84 if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) {
85 return FINAL_FAILURE_EXCEPTION;
87 if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) {
88 return FINAL_FAILURE_GUARD;
94 * Check if the result really is a result.
96 * @param result string
97 * @param finalResult result object
98 * @return true if a result
100 public static boolean isResult(String result, FinalResult finalResult) {
101 FinalResult toResult = FinalResult.toResult(result);
102 if (toResult == null) {
105 return toResult.equals(finalResult);