Changed to unmaintained
[appc.git] / appc-adapters / appc-ansible-adapter / appc-ansible-adapter-bundle / src / main / java / org / onap / appc / adapter / ansible / model / AnsibleResultCodes.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.adapter.ansible.model;
25
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashSet;
29 import java.util.Set;
30
31 /**
32  * enum of the various codes that APP-C uses to resolve different
33  * status of response from Ansible Server
34  **/
35
36 public enum AnsibleResultCodes {
37
38     // @formatter:off
39     SUCCESS(400),
40     KEYSTORE_EXCEPTION(622),
41     CERTIFICATE_ERROR(610),
42     IO_EXCEPTION(611),
43     HOST_UNKNOWN(625),
44     USER_UNAUTHORIZED(613),
45     UNKNOWN_EXCEPTION(699),
46     SSL_EXCEPTION(697),
47     INVALID_PAYLOAD(698),
48     INVALID_RESPONSE(601),
49     PENDING(100),
50     REJECTED(101),
51     FINAL_SUCCESS(200),
52     REQ_FAILURE(401),
53     MESSAGE(1),
54     CODE(0),
55     INITRESPONSE(0),
56     FINALRESPONSE(1);
57     // @formatter:on
58
59     private final Set<Integer> initCodes = new HashSet<>(Arrays.asList(100, 101));
60     private final Set<Integer> finalCodes = new HashSet<>(Arrays.asList(200, 500));
61     private final ArrayList<Set<Integer>> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes));
62     private final Set<String> messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED"));
63     private final int value;
64
65     AnsibleResultCodes(int value) {
66         this.value = value;
67     };
68
69     public int getValue() {
70         return value;
71     }
72
73     public boolean checkValidCode(int type, int code) {
74         return codeSets.get(type).contains(code);
75     }
76
77     public String getValidCodes(int type) {
78         StringBuilder sb = new StringBuilder("[ ");
79         codeSets.get(type).stream().forEach(s -> sb.append(s).append(","));
80         return sb.append("]").toString();
81     }
82
83     public boolean checkValidMessage(String message) {
84         return messageSet.contains(message);
85     }
86
87     public String getValidMessages() {
88         StringBuilder sb = new StringBuilder("[ ");
89         messageSet.stream().forEach(s -> sb.append(s).append(","));
90         return sb.append("]").toString();
91     }
92 }