NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / utils / ElanEtreeUtils.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.netvirt.elan.utils;
9
10 import java.util.Optional;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.etree.rev160614.EtreeLeafTagName;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.common.Uint32;
20
21 @Singleton
22 public class ElanEtreeUtils {
23     private final DataBroker broker;
24
25     @Inject
26     public ElanEtreeUtils(DataBroker broker) {
27         this.broker = broker;
28     }
29
30     @Nullable
31     public EtreeLeafTagName getEtreeLeafTagByElanTag(long elanTag) {
32         InstanceIdentifier<ElanTagName> elanId = ElanUtils
33                                                      .getElanInfoEntriesOperationalDataPath(Uint32.valueOf(elanTag));
34         Optional<ElanTagName> existingElanInfo = ElanUtils.read(broker,
35                 LogicalDatastoreType.OPERATIONAL, elanId);
36         if (existingElanInfo.isPresent()) {
37             ElanTagName elanTagName = existingElanInfo.get();
38             return elanTagName.augmentation(EtreeLeafTagName.class);
39         }
40         return null;
41     }
42 }