Adjust to odlparent 3 Checkstyle settings
[genius.git] / resourcemanager / resourcemanager-impl / src / main / java / org / opendaylight / genius / resourcemanager / ResourceManagerUtils.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.resourcemanager;
9
10 import com.google.common.net.InetAddresses;
11 import java.net.InetAddress;
12 import java.net.UnknownHostException;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdPools;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 final class ResourceManagerUtils {
21     private static final Logger LOG = LoggerFactory.getLogger(ResourceManagerUtils.class);
22
23     private static Integer localHostAddress;
24
25     private ResourceManagerUtils() {
26     }
27
28     protected static InstanceIdentifier<IdPool> getIdPoolInstance(String poolName) {
29         InstanceIdentifier.InstanceIdentifierBuilder<IdPool> idPoolBuilder = InstanceIdentifier.builder(IdPools.class)
30                 .child(IdPool.class, new IdPoolKey(poolName));
31         return idPoolBuilder.build();
32     }
33
34     protected static String getLocalPoolName(String poolName) {
35         if (localHostAddress == null) {
36             try {
37                 localHostAddress = InetAddresses.coerceToInteger(InetAddress.getLocalHost());
38             } catch (UnknownHostException e) {
39                 LOG.error("Cannot build the local pool name: ", e);
40             }
41         }
42         return poolName + "." + localHostAddress;
43     }
44 }