2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.ccsdk.sli.adaptors.ansible.model;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashSet;
31 * enum of the various codes that APP-C uses to resolve different
32 * status of response from Ansible Server
35 public enum AnsibleResultCodes {
39 KEYSTORE_EXCEPTION(622),
40 CERTIFICATE_ERROR(610),
43 USER_UNAUTHORIZED(613),
44 UNKNOWN_EXCEPTION(699),
47 INVALID_RESPONSE(601),
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;
64 AnsibleResultCodes(int value) {
68 public int getValue() {
72 public boolean checkValidCode(int type, int code) {
73 return codeSets.get(type).contains(code);
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();
82 public boolean checkValidMessage(String message) {
83 return messageSet.contains(message);
86 public String getValidMessages() {
87 StringBuilder sb = new StringBuilder("[ ");
88 messageSet.forEach(s -> sb.append(s).append(","));
89 return sb.append("]").toString();