2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.sli.adaptors.saltstack.model;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.HashSet;
33 * enum of the various codes that APP-C uses to resolve different
34 * status of response from Saltstack Server
37 public enum SaltstackResultCodes {
41 KEYSTORE_EXCEPTION(622),
42 CERTIFICATE_ERROR(610),
45 USER_UNAUTHORIZED(613),
46 UNKNOWN_EXCEPTION(699),
47 OPERATION_TIMEOUT(659),
50 INVALID_RESPONSE(601),
51 INVALID_RESPONSE_FILE(600),
55 CHECK_CTX_FOR_CMD_SUCCESS(250),
56 COMMAND_EXEC_FAILED_STATUS(670),
64 private final Set<Integer> initCodes = new HashSet<>(Arrays.asList(100, 101));
65 private final Set<Integer> finalCodes = new HashSet<>(Arrays.asList(200, 500));
66 private final ArrayList<Set<Integer>> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes));
67 private final Set<String> messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED"));
68 private final int value;
70 SaltstackResultCodes(int value) {
76 public int getValue() {
80 public boolean checkValidCode(int type, int code) {
81 return codeSets.get(type).contains(code);
84 public String getValidCodes(int type) {
85 StringBuilder sb = new StringBuilder("[ ");
86 codeSets.get(type).stream().forEach(s -> sb.append(s).append(","));
87 return sb.append("]").toString();
90 public boolean checkValidMessage(String message) {
91 return messageSet.contains(message);
94 public String getValidMessages() {
95 StringBuilder sb = new StringBuilder("[ ");
96 messageSet.stream().forEach(s -> sb.append(s).append(","));
97 return sb.append("]").toString();