Switch to InstanceIdDataObjectCache
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / HostConfigCache.java
1 /*
2  * Copyright (c) 2017 Mellanox. 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
9 package org.opendaylight.netvirt.neutronvpn;
10
11 import com.google.common.base.Optional;
12 import javax.annotation.Nonnull;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
18 import org.opendaylight.genius.mdsalutil.cache.InstanceIdDataObjectCache;
19 import org.opendaylight.infrautils.caches.CacheProvider;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.Hostconfigs;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.Hostconfig;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.hostconfig.rev150712.hostconfig.attributes.hostconfigs.HostconfigKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 @Singleton
27 public class HostConfigCache extends InstanceIdDataObjectCache<Hostconfig> {
28     @Inject
29     public HostConfigCache(DataBroker dataBroker, CacheProvider cacheProvider) {
30         super(Hostconfig.class, dataBroker, LogicalDatastoreType.OPERATIONAL,
31               InstanceIdentifier.builder(Neutron.class).child(Hostconfigs.class).child(Hostconfig.class).build(),
32               cacheProvider);
33     }
34
35     public Optional<Hostconfig> get(@Nonnull String hostId) throws ReadFailedException {
36         InstanceIdentifier<Hostconfig> hostConfigPath = InstanceIdentifier.builder(Neutron.class)
37                                                  .child(Hostconfigs.class)
38                                                  .child(Hostconfig.class, new HostconfigKey(hostId, "ODL L2"))
39                                                  .build();
40         return get(hostConfigPath);
41     }
42 }