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.Collections;
15 import java.util.List;
16 import java.util.Optional;
17 import java.util.concurrent.Callable;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
20 import org.opendaylight.genius.idmanager.IdUtils;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.id.pools.id.pool.IdEntries;
23 public class UpdateIdEntryJob implements Callable<List<ListenableFuture<Void>>> {
25 private final String parentPoolName;
26 private final String localPoolName;
27 private final String idKey;
28 private final List<Long> newIdValues;
29 private final DataBroker broker;
30 private final IdUtils idUtils;
32 public UpdateIdEntryJob(String parentPoolName, String localPoolName,
33 String idKey, List<Long> newIdValues, DataBroker broker, IdUtils idUtils) {
34 this.parentPoolName = parentPoolName;
35 this.localPoolName = localPoolName;
37 this.newIdValues = newIdValues;
39 this.idUtils = idUtils;
43 public List<ListenableFuture<Void>> call() throws Exception {
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 tx.submit().checkedGet();
53 Optional.ofNullable(idUtils.releaseIdLatchMap.get(parentPoolName + idKey))
54 .ifPresent(latch -> latch.countDown());
55 return Collections.emptyList();