/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.genius.itm.confighelpers;
+import static org.opendaylight.mdsal.binding.util.Datastore.CONFIGURATION;
+
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import java.util.Optional;
import java.util.concurrent.Callable;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.genius.itm.impl.ItmUtils;
import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.Datastore;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfo;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.dc.gateway.ip.list.DcGatewayIp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ItmTepAddWorker implements Callable<List<ListenableFuture<Void>>> {
- private static final Logger logger = LoggerFactory.getLogger(ItmTepAddWorker.class ) ;
- private DataBroker dataBroker;
- private IdManagerService idManagerService;
- private List<DPNTEPsInfo> meshedDpnList;
- private List<DPNTEPsInfo> cfgdDpnList ;
- private IMdsalApiManager mdsalManager;
- private List<HwVtep> cfgdHwVteps;
+public class ItmTepAddWorker implements Callable<List<? extends ListenableFuture<?>>> {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ItmTepAddWorker.class);
- public ItmTepAddWorker(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> hwVtepList, DataBroker broker, IdManagerService idManagerService, IMdsalApiManager mdsalManager) {
+ private final DataBroker dataBroker;
+ private Collection<DPNTEPsInfo> meshedDpnList;
+ private final List<DPNTEPsInfo> cfgdDpnList ;
+ private final IMdsalApiManager mdsalManager;
+ private final List<HwVtep> cfgdHwVteps;
+ private final ItmInternalTunnelAddWorker itmInternalTunnelAddWorker;
+ private final ItmExternalTunnelAddWorker externalTunnelAddWorker;
+ private final ManagedNewTransactionRunner txRunner;
+
+ public ItmTepAddWorker(List<DPNTEPsInfo> cfgdDpnList, List<HwVtep> hwVtepList, DataBroker broker,
+ IMdsalApiManager mdsalManager, ItmInternalTunnelAddWorker itmInternalTunnelAddWorker,
+ ItmExternalTunnelAddWorker externalTunnelAddWorker) {
this.cfgdDpnList = cfgdDpnList ;
this.dataBroker = broker ;
- this.idManagerService = idManagerService;
this.mdsalManager = mdsalManager;
this.cfgdHwVteps = hwVtepList;
- logger.trace("ItmTepAddWorker initialized with DpnList {}",cfgdDpnList );
- logger.trace("ItmTepAddWorker initialized with hwvteplist {}",hwVtepList);
+ this.itmInternalTunnelAddWorker = itmInternalTunnelAddWorker;
+ this.externalTunnelAddWorker = externalTunnelAddWorker;
+ this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
+ LOG.trace("ItmTepAddWorker initialized with DpnList {}",cfgdDpnList);
+ LOG.trace("ItmTepAddWorker initialized with hwvteplist {}",hwVtepList);
}
@Override
- public List<ListenableFuture<Void>> call() throws Exception {
- List<ListenableFuture<Void>> futures = new ArrayList<>() ;
- this.meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
- logger.debug("Invoking Internal Tunnel build method with Configured DpnList {} ; Meshed DpnList {} ",cfgdDpnList, meshedDpnList );
- futures.addAll( ItmInternalTunnelAddWorker.build_all_tunnels(dataBroker, idManagerService,mdsalManager, cfgdDpnList, meshedDpnList) ) ;
+ public List<? extends ListenableFuture<?>> call() {
+ List<ListenableFuture<?>> futures = new ArrayList<>() ;
+ this.meshedDpnList = ItmUtils.getDpnTEPsInfos(dataBroker);
+ LOG.debug("Invoking Internal Tunnel build method with Configured DpnList {} ; Meshed DpnList {} ",
+ cfgdDpnList, meshedDpnList);
+ futures.addAll(itmInternalTunnelAddWorker.buildAllTunnels(mdsalManager, cfgdDpnList, meshedDpnList));
+
// IF EXTERNAL TUNNELS NEEDS TO BE BUILT, DO IT HERE. IT COULD BE TO DC GATEWAY OR TOR SWITCH
- List<DcGatewayIp> dcGatewayIpList = ItmUtils.getDcGatewayIpList(dataBroker);
- if(dcGatewayIpList != null && !dcGatewayIpList.isEmpty()) {
- for (DcGatewayIp dcGatewayIp : dcGatewayIpList) {
- futures.addAll(ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker, idManagerService, cfgdDpnList, dcGatewayIp.getIpAddress(), dcGatewayIp.getTunnnelType()));
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(CONFIGURATION,
+ tx -> {
+ Optional<DcGatewayIpList> optional = tx.read(InstanceIdentifier.builder(DcGatewayIpList.class)
+ .build()).get();
+ if (optional.isPresent()) {
+ optional.get().getDcGatewayIp().values().forEach(dcGatewayIp ->
+ externalTunnelAddWorker.buildTunnelsToExternalEndPoint(cfgdDpnList, dcGatewayIp.getIpAddress(),
+ dcGatewayIp.getTunnnelType(), tx));
+ }
}
- }
+ ));
//futures.addAll(ItmExternalTunnelAddWorker.buildTunnelsToExternalEndPoint(dataBroker,meshedDpnList, extIp) ;
- logger.debug("invoking build hwVtepTunnels with hwVteplist {}", cfgdHwVteps );
- futures.addAll(ItmExternalTunnelAddWorker.buildHwVtepsTunnels(dataBroker, idManagerService,cfgdDpnList,cfgdHwVteps));
- return futures ;
+ LOG.debug("invoking build hwVtepTunnels with hwVteplist {}", cfgdHwVteps);
+ futures.add(txRunner.callWithNewReadWriteTransactionAndSubmit(Datastore.CONFIGURATION,
+ tx -> externalTunnelAddWorker.buildHwVtepsTunnels(cfgdDpnList, cfgdHwVteps, tx)));
+ return futures;
}
@Override
public String toString() {
- return "ItmTepAddWorker { " +
- "Configured Dpn List : " + cfgdDpnList +
- " Meshed Dpn List : " + meshedDpnList + " }" ;
+ return "ItmTepAddWorker { "
+ + "Configured Dpn List : " + cfgdDpnList
+ + " Meshed Dpn List : " + meshedDpnList + " }" ;
}
}