Change the way of fetching data from datastore and write user's intents into datastor...
[nemo.git] / nemo-impl / src / main / java / org / opendaylight / nemo / user / vnspacemanager / structurestyle / deleteintent / DeleteFlow.java
index 84d304f693de4bf59ede62aae68dfc651b6926e5..33651134cfbf49d611dbd4f7f7addc82a447e254 100644 (file)
@@ -9,91 +9,60 @@ package org.opendaylight.nemo.user.vnspacemanager.structurestyle.deleteintent;
 \r
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
 import org.opendaylight.nemo.user.tenantmanager.TenantManage;\r
+import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOConstants;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.FlowId;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;\r
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;\r
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;\r
-import com.google.common.util.concurrent.CheckedFuture;\r
-import com.google.common.util.concurrent.FutureCallback;\r
-import com.google.common.util.concurrent.Futures;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.List;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.operations.Operation;\r
 \r
 /**\r
  * Created by z00293636 on 2015/9/2.\r
  */\r
 public class DeleteFlow {\r
-\r
-    private DataBroker dataBroker;\r
     private TenantManage tenantManage;\r
-    private static final Logger LOG = LoggerFactory.getLogger(DeleteFlow.class);\r
 \r
     public DeleteFlow(DataBroker dataBroker, TenantManage tenantManage){\r
-        this.dataBroker = dataBroker;\r
         this.tenantManage = tenantManage;\r
     }\r
 \r
     public String DeleteFlowHandling(UserId userId, FlowId flowId){\r
-        Boolean FlowInsExist = false;\r
-        tenantManage.fetchVNSpace(userId);\r
-        String errorInfo = null;\r
-        User user = tenantManage.getUser();\r
+        Boolean flowExist = false;\r
 \r
-        if (user != null){\r
-            if (user.getObjects() != null){\r
-                if (user.getObjects().getFlow() != null){\r
-                    List<Flow> flowList = tenantManage.getUser().getObjects().getFlow();\r
-                    for (Flow flow : flowList){\r
-                        if (flow.getFlowId().equals(flowId)){\r
-                            FlowInsExist = true;\r
-                            break;\r
-                        }\r
-                    }\r
-                    if (FlowInsExist) {\r
-                        DeleteFlowInstance(userId,flowId);\r
-                    }\r
-                    else{\r
-                        errorInfo = "The flow instance " +flowId.getValue()+" is not exist. Could not be deleted.";\r
-                    }\r
-                }\r
-                else{\r
-                    errorInfo = "There are no flow instances in the data store.";\r
-                }\r
+        if (tenantManage.getFlow(userId)!=null){\r
+            if (tenantManage.getFlow(userId).containsKey(flowId)){\r
+                flowExist = true;\r
+                tenantManage.getFlow(userId).remove(flowId);\r
+                tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,flowId.getValue()));\r
             }\r
         }\r
-        else{\r
-            errorInfo = "There are no user in the data store.";\r
+        if (tenantManage.getFlowDataStore(userId)!=null){\r
+            if (tenantManage.getFlowDataStore(userId).containsKey(flowId)){\r
+                flowExist = true;\r
+                tenantManage.setUserDeleteIntent(userId, NEMOConstants.flow, flowId.getValue());\r
+                tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,flowId.getValue()));\r
+            }\r
         }\r
-        return errorInfo;\r
-    }\r
 \r
-    private void DeleteFlowInstance(UserId userId, FlowId flowId){\r
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();\r
-        UserKey userKey = new UserKey(userId);\r
-        FlowKey flowKey = new FlowKey(flowId);\r
-\r
-        InstanceIdentifier<Flow> flowid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).child(Objects.class).child(Flow.class,flowKey).build();\r
-        t.delete(LogicalDatastoreType.CONFIGURATION, flowid);\r
-        CheckedFuture<Void, TransactionCommitFailedException> f = t.submit();\r
-        Futures.addCallback(f, new FutureCallback<Void>() {\r
-            @Override\r
-            public void onFailure(Throwable t) {\r
-                LOG.error("Could not write endpoint base container", t);\r
+        if (!flowExist){\r
+            return "The flow instance " +flowId.getValue()+" is not exist.";\r
+        }\r
+        else {\r
+            if (tenantManage.getOperation(userId)!=null){\r
+                for (Operation operation : tenantManage.getOperation(userId).values()){\r
+                    if (operation.getTargetObject().getValue().equals(flowId.getValue())){\r
+                        tenantManage.getOperation(userId).remove(operation.getOperationId());\r
+                        tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,operation.getOperationId().getValue()));\r
+                    }\r
+                }\r
             }\r
-\r
-            @Override\r
-            public void onSuccess(Void result) {\r
+            if (tenantManage.getOperationDataStore(userId)!=null){\r
+                for (Operation operation : tenantManage.getOperationDataStore(userId).values()){\r
+                    if (operation.getTargetObject().getValue().equals(flowId.getValue())){\r
+                        tenantManage.setUserDeleteIntent(userId, NEMOConstants.operation, operation.getOperationId().getValue());\r
+                        tenantManage.getUserNameIdMap(userId).remove(tenantManage.getName(userId,operation.getOperationId().getValue()));\r
+                    }\r
+                }\r
             }\r
-        });\r
+        }\r
+        return null;\r
     }\r
 }\r