2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.genius.idmanager.jobs;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.ArrayList;
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.genius.idmanager.IdLocalPool;
18 import org.opendaylight.genius.idmanager.IdUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPool;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.IdPoolKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class LocalPoolCreateJob implements Callable<List<ListenableFuture<Void>>> {
28 private static final Logger LOG = LoggerFactory.getLogger(LocalPoolCreateJob.class);
30 private final IdLocalPool idLocalPool;
31 private final DataBroker broker;
32 private final String parentPoolName;
33 private final int blockSize;
34 private final IdUtils idUtils;
36 public LocalPoolCreateJob(IdLocalPool idLocalPool, DataBroker broker,
37 String parentPoolName, int blockSize, IdUtils idUtils) {
38 this.idLocalPool = idLocalPool;
40 this.parentPoolName = parentPoolName;
41 this.blockSize = blockSize;
42 this.idUtils = idUtils;
46 public List<ListenableFuture<Void>> call() throws Exception {
47 String localPoolName = idLocalPool.getPoolName();
48 if (LOG.isDebugEnabled()) {
49 LOG.debug("Started localPoolCreateJob for {}", localPoolName);
51 InstanceIdentifier<IdPool> localPoolInstanceIdentifier = idUtils.getIdPoolInstance(localPoolName);
52 IdPoolBuilder idPool = new IdPoolBuilder().setKey(new IdPoolKey(localPoolName)).setBlockSize(blockSize)
53 .setParentPoolName(parentPoolName).setPoolName(localPoolName);
54 idLocalPool.getAvailableIds().refreshDataStore(idPool);
55 idLocalPool.getReleasedIds().refreshDataStore(idPool);
56 WriteTransaction tx = broker.newWriteOnlyTransaction();
57 tx.put(LogicalDatastoreType.CONFIGURATION, localPoolInstanceIdentifier, idPool.build(), true);
59 ArrayList<ListenableFuture<Void>> futures = new ArrayList<>();
60 futures.add(tx.submit());