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.ConnectionId;
\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.Connection;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.ConnectionKey;
\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 DeleteConnection {
\r
37 private DataBroker dataBroker;
\r
38 private TenantManage tenantManage;
\r
39 private static final Logger LOG = LoggerFactory.getLogger(DeleteConnection.class);
\r
41 public DeleteConnection(DataBroker dataBroker, TenantManage tenantManage)
\r
43 this.dataBroker = dataBroker;
\r
44 this.tenantManage = tenantManage;
\r
47 public String DeleteConnectionHandling(UserId userId, ConnectionId connectionId)
\r
49 Boolean ConnInstanceExist = false;
\r
50 String errorInfo = null;
\r
52 tenantManage.fetchVNSpace(userId);
\r
53 User user = tenantManage.getUser();
\r
57 if (user.getObjects() != null)
\r
59 if (user.getObjects().getConnection() != null)
\r
61 List<Connection> connectionList = tenantManage.getUser().getObjects().getConnection();
\r
63 for (Connection connection : connectionList)
\r
65 if (connection.getConnectionId().equals(connectionId))
\r
67 ConnInstanceExist = true;
\r
72 if (ConnInstanceExist)
\r
74 DeleteConnInstance(userId, connectionId);
\r
78 errorInfo = "The connection instance"+connectionId.toString()+ "is not exit. Could not be deleted.";
\r
84 errorInfo = "There are no connection instances in data store.";
\r
90 errorInfo = "There are no connection instances in data store.";
\r
96 private void DeleteConnInstance(UserId userId, ConnectionId connectionId)
\r
98 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
\r
99 UserKey userKey = new UserKey(userId);
\r
100 ConnectionKey connectionKey = new ConnectionKey(connectionId);
\r
102 InstanceIdentifier<Connection> connectionid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).child(Objects.class).child(Connection.class,connectionKey).build();
\r
103 t.delete(LogicalDatastoreType.CONFIGURATION, connectionid);
\r
104 CheckedFuture<Void, TransactionCommitFailedException> f = t.submit();
\r
105 Futures.addCallback(f, new FutureCallback<Void>() {
\r
107 public void onFailure(Throwable t) {
\r
108 LOG.error("Could not write endpoint base container", t);
\r
112 public void onSuccess(Void result) {
\r