2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.groupbasedpolicy.gbp_ise_adapter.impl;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
17 import org.opendaylight.groupbasedpolicy.util.IidFactory;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroup;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.EndpointGroupBuilder;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Purpose: process given sgt+name - create {@link EndpointGroup} and write it to tenants/tenant/policy/endpoint-group
31 public class SgtToEpgGeneratorImpl implements SgtInfoProcessor {
33 private static final Logger LOG = LoggerFactory.getLogger(SgtToEpgGeneratorImpl.class);
35 private final DataBroker dataBroker;
37 public SgtToEpgGeneratorImpl(final DataBroker dataBroker) {
38 this.dataBroker = dataBroker;
42 public CheckedFuture<Void, TransactionCommitFailedException> processSgtInfo(final TenantId tenantId, final List<SgtInfo> sgtInfos) {
43 final WriteTransaction wTx = dataBroker.newWriteOnlyTransaction();
45 // create and write endpointgroups
46 boolean createParent = true;
47 for (SgtInfo sgtInfo : sgtInfos) {
48 final Integer sgtValue = sgtInfo.getSgt().getValue();
49 final String sgtName = sgtInfo.getName();
50 LOG.trace("processing sgtInfo: {} - {}", sgtValue, sgtName);
52 final EndpointGroupId epgId = new EndpointGroupId(sgtName);
53 final InstanceIdentifier<EndpointGroup> epgPath = IidFactory.endpointGroupIid(tenantId, epgId);
54 final EndpointGroup epg = new EndpointGroupBuilder()
56 .setDescription(new Description("imported from ISE for sgt=" + sgtValue))
57 .setName(new Name(sgtName.replaceAll(" ", "_") + "--" + sgtValue))
59 wTx.put(LogicalDatastoreType.CONFIGURATION, epgPath, epg, createParent);