Fix build faliures due to OFPlugin checktyle fixes
[netvirt.git] / sfc / translator / src / main / java / org / opendaylight / netvirt / sfc / translator / NeutronMdsalHelper.java
1 /*
2  * Copyright (c) 2016, 2017 Brocade Communications Systems, Inc. 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.sfc.translator;
10
11 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.SfcFlowClassifiers;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.sfc.flow.classifiers.SfcFlowClassifier;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.flow.classifier.rev160511.sfc.flow.classifiers.attributes.sfc.flow.classifiers.SfcFlowClassifierKey;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairGroups;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.PortPairs;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pair.groups.PortPairGroup;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pair.groups.PortPairGroupKey;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPair;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.sfc.rev160511.sfc.attributes.port.pairs.PortPairKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * Utility functions to read Neutron models (e.g network, subnet, port, sfc flow classifier
34  * port pair, port group, port chain) from md-sal data store.
35  */
36 public class NeutronMdsalHelper {
37     private static final Logger LOG = LoggerFactory.getLogger(NeutronMdsalHelper.class);
38     private static final InstanceIdentifier<SfcFlowClassifiers> FC_IID =
39             InstanceIdentifier.create(Neutron.class).child(SfcFlowClassifiers.class);
40     private static final InstanceIdentifier<Ports> PORTS_IID =
41             InstanceIdentifier.create(Neutron.class).child(Ports.class);
42     private static final InstanceIdentifier<PortPairs> PORT_PAIRS_IID =
43             InstanceIdentifier.create(Neutron.class).child(PortPairs.class);
44     private static final InstanceIdentifier<PortPairGroups> PORT_PAIR_GROUPS_IID =
45             InstanceIdentifier.create(Neutron.class).child(PortPairGroups.class);
46
47     private final DataBroker dataBroker;
48
49     public NeutronMdsalHelper(DataBroker dataBroker) {
50         this.dataBroker = dataBroker;
51     }
52
53     public Port getNeutronPort(Uuid portId) {
54         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
55                 LogicalDatastoreType.CONFIGURATION, getNeutronPortPath(portId)).orNull();
56     }
57
58     public PortPair getNeutronPortPair(Uuid portPairId) {
59         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
60                 LogicalDatastoreType.CONFIGURATION, getNeutronPortPairPath(portPairId)).orNull();
61     }
62
63     public PortPairGroup getNeutronPortPairGroup(Uuid portPairGroupId) {
64         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
65                 LogicalDatastoreType.CONFIGURATION, getNeutronPortPairGroupPath(portPairGroupId)).orNull();
66     }
67
68     public SfcFlowClassifier getNeutronFlowClassifier(Uuid flowClassifierId) {
69         return SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker,
70                 LogicalDatastoreType.CONFIGURATION, getNeutronSfcFlowClassifierPath(flowClassifierId)).orNull();
71     }
72
73     private InstanceIdentifier<Port> getNeutronPortPath(Uuid portId) {
74         return PORTS_IID.builder().child(Port.class, new PortKey(portId)).build();
75     }
76
77     private InstanceIdentifier<PortPair> getNeutronPortPairPath(Uuid portPairId) {
78         return PORT_PAIRS_IID.builder().child(PortPair.class, new PortPairKey(portPairId)).build();
79     }
80
81     private InstanceIdentifier<PortPairGroup> getNeutronPortPairGroupPath(Uuid portPairGroupId) {
82         return PORT_PAIR_GROUPS_IID.builder().child(PortPairGroup.class, new PortPairGroupKey(portPairGroupId)).build();
83     }
84
85     private InstanceIdentifier<SfcFlowClassifier> getNeutronSfcFlowClassifierPath(Uuid portId) {
86         return FC_IID.builder().child(SfcFlowClassifier.class, new SfcFlowClassifierKey(portId)).build();
87     }
88 }