86b174a85218cd4eaf1a942cbb6cd624bfacf412
[policy/engine.git] / ECOMP-ControlloopPolicy / src / main / java / org / openecomp / policy / controlloop / policy / FinalResult.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.policy.controlloop.policy;
22
23 public enum FinalResult {
24         /**
25          * The Control Loop Policy successfully completed its Operations.
26          */
27         FINAL_SUCCESS("Final_Success"),
28         /**
29          * The Control Loop Policy was an Open Loop and is finished.
30          */
31         FINAL_OPENLOOP("Final_OpenLoop"),
32         /**
33          * The Control Loop Policy failed in its last Operation Policy. NOTE: Previous Operation Policies may have been successful.
34          */
35         FINAL_FAILURE("Final_Failure"),
36         /**
37          * The Control Loop Policy failed because the overall timeout was met.
38          */
39         FINAL_FAILURE_TIMEOUT("Final_Failure_Timeout"),
40         /**
41          * The Control Loop Policy failed because an Operation Policy met its retry limit.
42          */
43         FINAL_FAILURE_RETRIES("Final_Failure_Retries"),
44         /**
45          * The Control Loop Policy failed due to an exception.
46          */
47         FINAL_FAILURE_EXCEPTION("Final_Failure_Exception"), 
48         /**
49          *  The Control Loop Policy failed due to guard denied
50          */
51         FINAL_FAILURE_GUARD("Final_Failure_Guard")
52         ;
53         
54         String result;
55         
56         private FinalResult(String result) {
57                 this.result = result;
58         }
59         
60         public static FinalResult       toResult(String result) {
61                 if (result.equalsIgnoreCase(FINAL_SUCCESS.toString())) {
62                         return FINAL_SUCCESS;
63                 }
64                 if (result.equalsIgnoreCase(FINAL_OPENLOOP.toString())) {
65                         return FINAL_OPENLOOP;
66                 }
67                 if (result.equalsIgnoreCase(FINAL_FAILURE.toString())) {
68                         return FINAL_FAILURE;
69                 }
70                 if (result.equalsIgnoreCase(FINAL_FAILURE_TIMEOUT.toString())) {
71                         return FINAL_FAILURE_TIMEOUT;
72                 }
73                 if (result.equalsIgnoreCase(FINAL_FAILURE_RETRIES.toString())) {
74                         return FINAL_FAILURE_RETRIES;
75                 }
76                 if (result.equalsIgnoreCase(FINAL_FAILURE_EXCEPTION.toString())) {
77                         return FINAL_FAILURE_EXCEPTION;
78                 }
79                 if (result.equalsIgnoreCase(FINAL_FAILURE_GUARD.toString())) {
80                         return FINAL_FAILURE_GUARD;
81                 }
82                 return null;
83         }
84         
85         public static boolean isResult(String result, FinalResult finalResult) {
86                 FinalResult toResult = FinalResult.toResult(result);
87                 if (toResult == null) {
88                         return false;
89                 }
90                 return (toResult.equals(finalResult));
91         }
92
93 }