2 * Copyright (c) 2015 NEC Corporation. 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.vtn.manager.internal.routing;
11 import java.util.ArrayList;
12 import java.util.HashSet;
13 import java.util.Iterator;
14 import java.util.List;
17 import org.opendaylight.vtn.manager.VTNException;
19 import org.opendaylight.vtn.manager.internal.FlowRemover;
20 import org.opendaylight.vtn.manager.internal.TxContext;
21 import org.opendaylight.vtn.manager.internal.VTNManagerProvider;
22 import org.opendaylight.vtn.manager.internal.flow.remove.AllFlowRemover;
23 import org.opendaylight.vtn.manager.internal.flow.remove.TenantFlowRemover;
24 import org.opendaylight.vtn.manager.internal.util.pathmap.PathMapUtils;
25 import org.opendaylight.vtn.manager.internal.util.rpc.RpcException;
26 import org.opendaylight.vtn.manager.internal.util.rpc.RpcOutputGenerator;
27 import org.opendaylight.vtn.manager.internal.util.rpc.RpcUtils;
28 import org.opendaylight.vtn.manager.internal.util.tx.CompositeTxTask;
29 import org.opendaylight.vtn.manager.internal.util.vnode.VTenantIdentifier;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.RemovePathMapInput;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.RemovePathMapOutput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.RemovePathMapOutputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.remove.path.map.output.RemovePathMapResult;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.remove.path.map.output.RemovePathMapResultBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.pathmap.rev150328.vtn.path.map.list.VtnPathMap;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.vtn.types.rev150209.VtnUpdateType;
42 * {@code RemovePathMapTask} describes the MD-SAL datastore transaction task
43 * that deletes all the specified path map configurations from the global or
46 * @see #create(RemovePathMapInput)
48 public final class RemovePathMapTask
49 extends CompositeTxTask<VtnUpdateType, RemoveMapTask>
50 implements RpcOutputGenerator<List<VtnUpdateType>, RemovePathMapOutput> {
52 * The identifier for the target VTN.
55 * {@code null} means that the global path map is targeted.
58 private final VTenantIdentifier identifier;
61 * Construct a new task that removes all the given path map configurations
62 * from the global or VTN path map.
64 * @param input A {@link RemovePathMapInput} instance.
65 * @return A {@link RemovePathMapTask} instance associated with the task
66 * that removes the given path map configuration.
67 * @throws RpcException
68 * The given input contains invalid value.
70 public static RemovePathMapTask create(RemovePathMapInput input)
73 throw RpcUtils.getNullInputException();
76 String tname = input.getTenantName();
77 VTenantIdentifier ident = (tname == null)
79 : VTenantIdentifier.create(tname, true);
81 List<Integer> indexList = input.getMapIndex();
82 if (indexList == null || indexList.isEmpty()) {
83 throw PathMapUtils.getNullMapIndexException();
86 Set<Integer> idxSet = new HashSet<>();
87 List<RemoveMapTask> taskList = new ArrayList<>();
88 for (Integer index: indexList) {
89 if (idxSet.add(index)) {
90 InstanceIdentifier<VtnPathMap> path = (ident == null)
91 ? PathMapUtils.getIdentifier(index)
92 : PathMapUtils.getIdentifier(ident, index);
93 taskList.add(new RemoveMapTask(path, index));
97 return new RemovePathMapTask(ident, taskList);
101 * Construct a new instance.
103 * @param ident The identifier for the target VTN.
104 * {@code null} means that the global path map is targeted.
105 * @param tasks A list of tasks that delete path map configuration.
107 private RemovePathMapTask(VTenantIdentifier ident,
108 List<RemoveMapTask> tasks) {
119 protected void onStarted(TxContext ctx) throws VTNException {
120 if (identifier != null) {
121 // Ensure that the target VTN is present.
122 identifier.fetch(ctx.getReadWriteTransaction());
132 public void onSuccess(VTNManagerProvider provider,
133 List<VtnUpdateType> result) {
134 for (VtnUpdateType status: result) {
135 if (status != null) {
136 // REVISIT: Select flow entries affected by the change.
137 FlowRemover remover = (identifier == null)
138 ? new AllFlowRemover()
139 : new TenantFlowRemover(identifier);
140 addBackgroundTask(provider.removeFlows(remover));
146 // RpcOutputGenerator
152 public Class<RemovePathMapOutput> getOutputType() {
153 return RemovePathMapOutput.class;
160 public RemovePathMapOutput createOutput(
161 List<VtnUpdateType> result) {
162 List<RemovePathMapResult> list = new ArrayList<>();
163 Iterator<RemoveMapTask> taskIterator = getSubTasks().iterator();
164 for (VtnUpdateType status: result) {
165 RemoveMapTask task = taskIterator.next();
166 RemovePathMapResult res = new RemovePathMapResultBuilder().
167 setIndex(task.getIndex()).setStatus(status).build();
171 return new RemovePathMapOutputBuilder().
172 setRemovePathMapResult(list).build();