2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;
\r
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
11 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;
\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
\r
20 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
\r
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
\r
24 import com.google.common.util.concurrent.CheckedFuture;
\r
25 import com.google.common.util.concurrent.FutureCallback;
\r
26 import com.google.common.util.concurrent.Futures;
\r
27 import org.slf4j.Logger;
\r
28 import org.slf4j.LoggerFactory;
\r
30 import java.util.List;
\r
33 * Created by z00293636 on 2015/9/2.
\r
35 public class DeleteFlow {
\r
37 private DataBroker dataBroker;
\r
38 private TenantManage tenantManage;
\r
39 private static final Logger LOG = LoggerFactory.getLogger(DeleteFlow.class);
\r
41 public DeleteFlow(DataBroker dataBroker, TenantManage tenantManage)
\r
43 this.dataBroker = dataBroker;
\r
44 this.tenantManage = tenantManage;
\r
47 public String DeleteFlowHandling(UserId userId, FlowId flowId)
\r
49 Boolean FlowInsExist = false;
\r
50 tenantManage.fetchVNSpace(userId);
\r
51 String errorInfo = null;
\r
52 User user = tenantManage.getUser();
\r
56 if (user.getObjects() != null)
\r
58 if (user.getObjects().getFlow() != null)
\r
60 List<Flow> flowList = tenantManage.getUser().getObjects().getFlow();
\r
61 for (Flow flow : flowList)
\r
63 if (flow.getFlowId().equals(flowId))
\r
65 FlowInsExist = true;
\r
72 DeleteFlowInstance(userId,flowId);
\r
76 errorInfo = "The flow instance" +flowId.toString()+"is not exist. Could not be deleted.";
\r
81 errorInfo = "There are no flow instances in the data store.";
\r
87 errorInfo = "There are no user in the data store.";
\r
92 private void DeleteFlowInstance(UserId userId, FlowId flowId)
\r
94 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
\r
95 UserKey userKey = new UserKey(userId);
\r
96 FlowKey flowKey = new FlowKey(flowId);
\r
98 InstanceIdentifier<Flow> flowid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).child(Objects.class).child(Flow.class,flowKey).build();
\r
99 t.delete(LogicalDatastoreType.CONFIGURATION, flowid);
\r
100 CheckedFuture<Void, TransactionCommitFailedException> f = t.submit();
\r
101 Futures.addCallback(f, new FutureCallback<Void>() {
\r
103 public void onFailure(Throwable t) {
\r
104 LOG.error("Could not write endpoint base container", t);
\r
108 public void onSuccess(Void result) {
\r