2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.ansible.model;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.HashSet;
32 * enum of the various codes that APP-C uses to resolve different
33 * status of response from Ansible Server
36 public enum AnsibleResultCodes {
40 KEYSTORE_EXCEPTION(622),
41 CERTIFICATE_ERROR(610),
44 USER_UNAUTHORIZED(613),
45 UNKNOWN_EXCEPTION(699),
48 INVALID_RESPONSE(601),
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;
65 AnsibleResultCodes(int value) {
69 public int getValue() {
73 public boolean checkValidCode(int type, int code) {
74 return codeSets.get(type).contains(code);
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();
83 public boolean checkValidMessage(String message) {
84 return messageSet.contains(message);
87 public String getValidMessages() {
88 StringBuilder sb = new StringBuilder("[ ");
89 messageSet.stream().forEach(s -> sb.append(s).append(","));
90 return sb.append("]").toString();