add junit coverage for HeatBridgeUtils
[so.git] / adapters / mso-openstack-adapters / src / main / java / org / onap / so / heatbridge / utils / HeatBridgeUtils.java
1 /*
2  * Copyright (C) 2018 Bell Canada. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11  * specific language governing permissions and limitations under the License.
12  */
13
14 package org.onap.so.heatbridge.utils;
15
16 import com.google.common.base.Preconditions;
17 import com.google.common.base.Strings;
18 import java.util.Optional;
19 import javax.annotation.Nonnull;
20
21 public class HeatBridgeUtils {
22
23     private HeatBridgeUtils() {
24         throw new IllegalStateException("Trying to instantiate a utility class.");
25     }
26
27     /**
28      * IaaS naming convention for compute/p-interface to openstack/physical-network name mapping
29      */
30     private static final String OS_SIDE_SHARED_SRIOV_PREFIX = "shared-";
31     private static final String OS_SIDE_DEDICATED_SRIOV_PREFIX = "dedicated-";
32     private static final String COMPUTE_SIDE_SHARED_SRIOV_PREFIX = "sriov-s-";
33     private static final String COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX = "sriov-d-";
34
35     public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) {
36         Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName),
37                 "Physical network name is null or " + "empty!");
38         if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) {
39             return Optional.of(
40                     physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX));
41         } else if (physicalNetworkName.contains(OS_SIDE_SHARED_SRIOV_PREFIX)) {
42             return Optional
43                     .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX));
44         }
45         return Optional.empty();
46     }
47 }