fef0f81afd299df8123e8d532f8fa391fc9cfe44
[ccsdk/sli/plugins.git] / sshapi-call-node / provider / src / main / java / org / onap / ccsdk / sli / plugins / sshapicall / model / RetryPolicy.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * * Copyright (C) 2017 AT&T Intellectual Property.
6  * ================================================================================
7  * Copyright (C) 2018 Samsung Electronics. All rights
8  *                      reserved.
9  * ================================================================================
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  * 
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.ccsdk.sli.plugins.sshapicall.model;
25
26 public class RetryPolicy {
27     private String[] hostnames;
28     private Integer maximumRetries;  
29
30     public Integer getMaximumRetries() {
31         return maximumRetries;
32     }
33     
34     public String getNextHostName(String uri) throws RetryException {
35         Integer position = null;
36
37         for (int i = 0; i < hostnames.length; i++) {
38             if (uri.contains(hostnames[i])) {
39                 position = i;
40                 break;
41             }
42         }
43
44         if(position == null){
45             throw new RetryException("No match found for the provided uri[" + uri + "] " +
46                     "so the next host name could not be retreived");
47         }
48         position++;
49
50         if (position > hostnames.length - 1) {
51             position = 0;
52         }
53         return hostnames[position];
54     }
55
56     public RetryPolicy(String[] hostnames, Integer maximumRetries){
57         this.hostnames = hostnames;
58         this.maximumRetries = maximumRetries;
59     }
60     
61
62 }