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
9 package org.opendaylight.genius.idmanager.jobs;
11 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.ArrayList;
15 import java.util.List;
16 import java.util.concurrent.Callable;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.genius.idmanager.IdUtils;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries;
22 public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>> {
24 private final String parentPoolName;
25 private final String localPoolName;
26 private final String idKey;
27 private final List<Long> newIdValues;
28 private final DataBroker broker;
29 private final IdUtils idUtils;
31 public UpdateIdEntryJob(String parentPoolName, String localPoolName,
32 String idKey, List<Long> newIdValues, DataBroker broker, IdUtils idUtils) {
33 this.parentPoolName = parentPoolName;
34 this.localPoolName = localPoolName;
36 this.newIdValues = newIdValues;
38 this.idUtils = idUtils;
42 public List<ListenableFuture<Void>> call() throws Exception {
43 List<ListenableFuture<Void>> futures = new ArrayList<>();
44 WriteTransaction tx = broker.newWriteOnlyTransaction();
45 idUtils.updateChildPool(tx, parentPoolName, localPoolName);
46 if (newIdValues != null && !newIdValues.isEmpty()) {
47 IdEntries newIdEntry = idUtils.createIdEntries(idKey, newIdValues);
48 tx.merge(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey), newIdEntry);
50 tx.delete(CONFIGURATION, idUtils.getIdEntriesInstanceIdentifier(parentPoolName, idKey));
52 futures.add(tx.submit());