BUG-6650: ep-ip/sgt, update/rename models and yangs for sxp-ise-adapter
[groupbasedpolicy.git] / sxp-mapper / src / main / java / org / opendaylight / groupbasedpolicy / sxp / mapper / impl / SxpEndpointAugmentorImpl.java
1 /*
2  * Copyright (c) 2016 Cisco 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.groupbasedpolicy.sxp.mapper.impl;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.collect.Iterables;
13 import java.util.AbstractMap;
14 import java.util.Collection;
15 import java.util.Map.Entry;
16 import org.opendaylight.groupbasedpolicy.api.EndpointAugmentor;
17 import org.opendaylight.groupbasedpolicy.sxp.mapper.api.ReadableByKey;
18 import org.opendaylight.groupbasedpolicy.sxp.mapper.impl.dao.EpPolicyTemplateValueKey;
19 import org.opendaylight.groupbasedpolicy.sxp.mapper.impl.dao.EpPolicyTemplateValueKeyFactory;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.address.endpoints.AddressEndpoint;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.endpoints.containment.endpoints.ContainmentEndpoint;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.AddressEndpointReg;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.base_endpoint.rev160427.register.endpoint.input.ContainmentEndpointReg;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.AddressEndpointWithLocation;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.renderer.rev151103.renderers.renderer.renderer.policy.configuration.endpoints.ContainmentEndpointWithLocation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.AddressEndpointWithLocationAug;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.AddressEndpointWithLocationAugBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.groupbasedpolicy.sxp.mapper.model.rev160302.sxp.mapper.EndpointPolicyTemplateBySgt;
29 import org.opendaylight.yangtools.yang.binding.Augmentation;
30
31 public class SxpEndpointAugmentorImpl implements EndpointAugmentor {
32
33     private final ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> epPolicyTemplateDao;
34     private final EpPolicyTemplateValueKeyFactory epPolicyTemplateKeyFactory;
35
36     public SxpEndpointAugmentorImpl(final ReadableByKey<EpPolicyTemplateValueKey, EndpointPolicyTemplateBySgt> epPolicyTemplateDao,
37                                    final EpPolicyTemplateValueKeyFactory epPolicyTemplateKeyFactory) {
38         this.epPolicyTemplateKeyFactory = Preconditions.checkNotNull(epPolicyTemplateKeyFactory, "epPolicyTemplateKeyFactory can not be null");
39         this.epPolicyTemplateDao = Preconditions.checkNotNull(epPolicyTemplateDao, "epPolicyTemplateDao can not be null");
40     }
41
42     @Override
43     public Entry<Class<? extends Augmentation<AddressEndpoint>>, Augmentation<AddressEndpoint>> buildAddressEndpointAugmentation(
44             AddressEndpointReg input) {
45         return null;
46     }
47
48     @Override
49     public Entry<Class<? extends Augmentation<ContainmentEndpoint>>, Augmentation<ContainmentEndpoint>> buildContainmentEndpointAugmentation(
50             ContainmentEndpointReg input) {
51         return null;
52     }
53
54     @Override
55     public Entry<Class<? extends Augmentation<AddressEndpointWithLocation>>, Augmentation<AddressEndpointWithLocation>> buildAddressEndpointWithLocationAugmentation(
56             AddressEndpoint input) {
57         final EpPolicyTemplateValueKey templateValueKey = epPolicyTemplateKeyFactory.createKey(
58                 input.getTenant(), input.getEndpointGroup(), input.getCondition());
59
60         final Collection<EndpointPolicyTemplateBySgt> epPolicyTemplates = epPolicyTemplateDao.readBy(templateValueKey);
61         final Entry<Class<? extends Augmentation<AddressEndpointWithLocation>>, Augmentation<AddressEndpointWithLocation>> entry;
62
63         if (epPolicyTemplates.isEmpty()) {
64             entry = null;
65         } else {
66             //TODO: cover case when multiple templates found
67             final Augmentation<AddressEndpointWithLocation> addressEndpointWithLocationAug =
68                     new AddressEndpointWithLocationAugBuilder()
69                             .setSgt(Iterables.getFirst(epPolicyTemplates, null).getSgt())
70                             .build();
71             entry = new AbstractMap.SimpleEntry<>(AddressEndpointWithLocationAug.class, addressEndpointWithLocationAug);
72         }
73
74         return entry;
75     }
76
77     @Override
78     public Entry<Class<? extends Augmentation<ContainmentEndpointWithLocation>>, Augmentation<ContainmentEndpointWithLocation>> buildContainmentEndpointWithLocationAugmentation(
79             ContainmentEndpoint input) {
80         return null;
81     }
82
83 }