227170189e94fd8f63cc29293d1c00097db2ee2b
[netvirt.git] / dhcpservice / impl / src / main / java / org / opendaylight / netvirt / dhcpservice / jobs / DhcpAllocationPoolAddJob.java
1 /*
2  * Copyright (c) 2017 Hewlett Packard Enterprise, Co. 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 package org.opendaylight.netvirt.dhcpservice.jobs;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collections;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
15 import org.opendaylight.genius.mdsalutil.NwConstants;
16 import org.opendaylight.netvirt.dhcpservice.DhcpServiceUtils;
17
18 public class DhcpAllocationPoolAddJob implements Callable<List<ListenableFuture<Void>>> {
19
20     private final ManagedNewTransactionRunner txRunner;
21     private final String interfaceName;
22
23     public DhcpAllocationPoolAddJob(ManagedNewTransactionRunner txRunner, String interfaceName) {
24         this.txRunner = txRunner;
25         this.interfaceName = interfaceName;
26     }
27
28     @Override
29     public List<ListenableFuture<Void>> call() {
30         return installDhcpEntries();
31     }
32
33     private List<ListenableFuture<Void>> installDhcpEntries() {
34         return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(
35             tx -> DhcpServiceUtils.bindDhcpService(interfaceName, NwConstants.DHCP_TABLE, tx)));
36     }
37
38 }