aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/FinalResult.java
blob: 473b102e7d5e7098b9a874b4b21251beb5fef949 (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
/*-
 * ============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;

public enum FinalResult {
    /**
     * The Control Loop Policy successfully completed its Operations.
     */
    FINAL_SUCCESS("Final_Success"),
    /**
     * The Control Loop Policy was an Open Loop and is finished.
     */
    FINAL_OPENLOOP("Final_OpenLoop"),
    /**
     * The Control Loop Policy failed in its last Operation Policy. 
     * NOTE: Previous Operation Policies may have been successful.
     */
    FINAL_FAILURE("Final_Failure"),
    /**
     * The Control Loop Policy failed because the overall timeout was met.
     */
    FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"),
    /**
     * The Control Loop Policy failed because an Operation Policy met its retry limit.
     */
    FINAL_FAILURE_RETRIES("Final_Failure_Retries"),
    /**
     * The Control Loop Policy failed due to an exception.
     */
    FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), 
    /**
     *  The Control Loop Policy failed due to guard denied.
     */
    FINAL_FAILURE_GUARD("Final_Failure_Guard")
    ;
    
    String result;
    
    private FinalResult(String result) {
        this.result = result;
    }
    
    /**
     * Converts to a result object.
     * 
     * @param result input string
     * @return result object
     */
    public static FinalResult toResult(String result) {
        if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
            return FINAL_SUCCESS;
        }
        if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) {
            return FINAL_OPENLOOP;
        }
        if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) {
            return FINAL_FAILURE;
        }
        if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) {
            return FINAL_FAILURE_TIMEOUT;
        }
        if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) {
            return FINAL_FAILURE_RETRIES;
        }
        if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) {
            return FINAL_FAILURE_EXCEPTION;
        }
        if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) {
            return FINAL_FAILURE_GUARD;
        }
        return null;
    }
    
    /**
     * Check if the result really is a result.
     * 
     * @param result string
     * @param finalResult result object
     * @return true if a result
     */
    public static boolean isResult(String result, FinalResult finalResult) {
        FinalResult toResult = FinalResult.toResult(result);
        if (toResult == null) {
            return false;
        }
        return toResult.equals(finalResult);
    }

}