57b679246bbaa5fa294239e304a19a72a9126ce4
[appc.git] / appc-adapters / appc-ansible-adapter / appc-ansible-adapter-bundle / src / main / java / org / openecomp / appc / adapter / ansible / model / AnsibleResultCodes.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.adapter.ansible.model;
24
25
26 import java.util.*;
27
28 /**
29  * enum of the various codes that APP-C uses to resolve different
30  *  status of response from Ansible Server
31  **/
32
33 public enum AnsibleResultCodes{
34
35     SUCCESS(400),
36     KEYSTORE_EXCEPTION(622),
37     CERTIFICATE_ERROR(610),
38     IO_EXCEPTION (611),
39     HOST_UNKNOWN(625),
40     USER_UNAUTHORIZED(613),
41     UNKNOWN_EXCEPTION(699),
42     SSL_EXCEPTION(697),
43     INVALID_PAYLOAD(698),
44     INVALID_RESPONSE(601),
45     PENDING(100),
46     REJECTED(101),
47     FINAL_SUCCESS(200),
48     REQ_FAILURE(401),
49     MESSAGE(1),
50     CODE(0),
51     INITRESPONSE(0),
52     FINALRESPONSE(1); 
53     
54     private final Set<Integer> InitCodes = new HashSet<Integer>(Arrays.asList(100, 101));
55     private final Set<Integer> FinalCodes = new HashSet<Integer>(Arrays.asList(200, 500));
56     private final ArrayList<Set<Integer>>CodeSets = new ArrayList<Set<Integer>>(Arrays.asList(InitCodes, FinalCodes));
57     
58     private  final Set<String> MessageSet = new HashSet<String>(Arrays.asList("PENDING", "FINISHED", "TERMINATED"));
59
60     private final int value;
61     
62     AnsibleResultCodes(int value){
63         this.value = value;
64     };
65
66
67     public int getValue(){
68         return this.value;
69     }
70
71
72     public boolean checkValidCode(int Type, int Code){
73         Set<Integer>CodeSet = CodeSets.get(Type);
74         if (CodeSet.contains(Code)){
75             return true;
76         }
77         else{
78             return false;
79         }
80     }
81
82
83     public String getValidCodes(int Type){
84         Set<Integer>CodeSet = CodeSets.get(Type);
85         
86         Iterator iter = CodeSet.iterator();
87         String ValidCodes = "[ ";
88         while(iter.hasNext()){
89             ValidCodes = ValidCodes +  iter.next().toString() + ",";
90         }
91
92         ValidCodes = ValidCodes + "]";
93         return ValidCodes;
94     }
95
96
97     public boolean checkValidMessage(String Message){
98         if (MessageSet.contains(Message)){
99             return true;
100         }
101         else{
102             return false;
103         }
104     }
105
106
107
108     public String getValidMessages(){
109         Iterator iter = MessageSet.iterator();
110         String ValidMessage = "[ ";
111         while(iter.hasNext()){
112             ValidMessage = ValidMessage +  iter.next() + ",";
113         }
114
115         ValidMessage = ValidMessage + "]";
116         return ValidMessage;
117     }
118
119
120 };