55a1e70868235022aaa8ca3c60ddc693a5da4aef
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : SLI
4  * ================================================================================
5  * Copyright (C) 2021 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  *
19  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.sli.adaptors.ansible.model;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashSet;
28 import java.util.Set;
29
30 /**
31  * enum of the various codes that APP-C uses to resolve different
32  * status of response from Ansible Server
33  **/
34
35 public enum AnsibleResultCodes {
36
37     // @formatter:off
38     SUCCESS(400),
39     KEYSTORE_EXCEPTION(622),
40     CERTIFICATE_ERROR(610),
41     IO_EXCEPTION(611),
42     HOST_UNKNOWN(625),
43     USER_UNAUTHORIZED(613),
44     UNKNOWN_EXCEPTION(699),
45     SSL_EXCEPTION(697),
46     INVALID_PAYLOAD(698),
47     INVALID_RESPONSE(601),
48     PENDING(100),
49     REJECTED(101),
50     FINAL_SUCCESS(200),
51     REQ_FAILURE(401),
52     MESSAGE(1),
53     CODE(0),
54     INITRESPONSE(0),
55     FINALRESPONSE(1);
56     // @formatter:on
57
58     private final Set<Integer> initCodes = new HashSet<>(Arrays.asList(100, 101));
59     private final Set<Integer> finalCodes = new HashSet<>(Arrays.asList(200, 500));
60     private final ArrayList<Set<Integer>> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes));
61     private final Set<String> messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED"));
62     private final int value;
63
64     AnsibleResultCodes(int value) {
65         this.value = value;
66     }
67
68     public int getValue() {
69         return value;
70     }
71
72     public boolean checkValidCode(int type, int code) {
73         return codeSets.get(type).contains(code);
74     }
75
76     public String getValidCodes(int type) {
77         StringBuilder sb = new StringBuilder("[ ");
78         codeSets.get(type).forEach(s -> sb.append(s).append(","));
79         return sb.append("]").toString();
80     }
81
82     public boolean checkValidMessage(String message) {
83         return messageSet.contains(message);
84     }
85
86     public String getValidMessages() {
87         StringBuilder sb = new StringBuilder("[ ");
88         messageSet.forEach(s -> sb.append(s).append(","));
89         return sb.append("]").toString();
90     }
91 }