2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung Electronics. All rights reserved.
6 * ================================================================================
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.
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),
51 INVALID_RESPONSE(601),
52 INVALID_RESPONSE_FILE(600),
56 CHECK_CTX_FOR_CMD_SUCCESS(250),
57 COMMAND_EXEC_FAILED_STATUS(670),
65 private final Set<Integer> initCodes = new HashSet<>(Arrays.asList(100, 101));
66 private final Set<Integer> finalCodes = new HashSet<>(Arrays.asList(200, 500));
67 private final ArrayList<Set<Integer>> codeSets = new ArrayList<>(Arrays.asList(initCodes, finalCodes));
68 private final Set<String> messageSet = new HashSet<>(Arrays.asList("PENDING", "FINISHED", "TERMINATED"));
69 private final int value;
71 SaltstackResultCodes(int value) {
77 public int getValue() {
81 public boolean checkValidCode(int type, int code) {
82 return codeSets.get(type).contains(code);
85 public String getValidCodes(int type) {
86 StringBuilder sb = new StringBuilder("[ ");
87 codeSets.get(type).stream().forEach(s -> sb.append(s).append(","));
88 return sb.append("]").toString();
91 public boolean checkValidMessage(String message) {
92 return messageSet.contains(message);
95 public String getValidMessages() {
96 StringBuilder sb = new StringBuilder("[ ");
97 messageSet.stream().forEach(s -> sb.append(s).append(","));
98 return sb.append("]").toString();