2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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.openflowplugin.impl.services.sal;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import java.util.stream.Collectors;
16 import org.opendaylight.openflowplugin.impl.util.BarrierUtil;
17 import org.opendaylight.openflowplugin.impl.util.GroupUtil;
18 import org.opendaylight.openflowplugin.impl.util.PathUtil;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.SendBarrier;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroup;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.Group;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatch;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groups.service.rev160315.RemoveGroupsBatchOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public final class RemoveGroupsBatchImpl implements RemoveGroupsBatch {
35 private static final Logger LOG = LoggerFactory.getLogger(RemoveGroupsBatchImpl.class);
37 private final RemoveGroup removeGroup;
38 private final SendBarrier sendBarrier;
40 public RemoveGroupsBatchImpl(final RemoveGroup removeGroup, final SendBarrier sendBarrier) {
41 this.removeGroup = requireNonNull(removeGroup);
42 this.sendBarrier = requireNonNull(sendBarrier);
46 public ListenableFuture<RpcResult<RemoveGroupsBatchOutput>> invoke(final RemoveGroupsBatchInput input) {
47 final var groups = input.nonnullBatchRemoveGroups().values();
48 if (LOG.isTraceEnabled()) {
49 LOG.trace("Removing groups @ {} : {}", PathUtil.extractNodeId(input.getNode()), groups.size());
52 final var resultsLot = groups.stream()
53 .map(addGroup -> removeGroup.invoke(new RemoveGroupInputBuilder(addGroup)
54 .setGroupRef(createGroupRef(input.getNode(), addGroup))
55 .setNode(input.getNode())
57 .collect(Collectors.toList());
59 final var commonResult = Futures.transform(Futures.allAsList(resultsLot),
60 GroupUtil.createCumulatingFunction(groups), MoreExecutors.directExecutor());
62 final var removeGroupsBulkFuture = Futures.transform(commonResult, GroupUtil.GROUP_REMOVE_TRANSFORM,
63 MoreExecutors.directExecutor());
65 return input.getBarrierAfter()
66 ? BarrierUtil.chainBarrier(removeGroupsBulkFuture, input.getNode(), sendBarrier,
67 GroupUtil.GROUP_REMOVE_COMPOSING_TRANSFORM)
68 : removeGroupsBulkFuture;
71 private static GroupRef createGroupRef(final NodeRef nodeRef, final Group batchGroup) {
72 return GroupUtil.buildGroupPath((InstanceIdentifier<Node>) nodeRef.getValue(), batchGroup.getGroupId());