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.updateintent;
\r
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
11 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
\r
12 import org.opendaylight.nemo.user.tenantmanager.TenantManage;
\r
13 import org.opendaylight.nemo.user.vnspacemanager.instancecheck.FlowInstanceCheck;
\r
14 import org.opendaylight.nemo.user.vnspacemanager.syntaxcheck.FlowDefinitionCheck;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.UserId;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.Users;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.Objects;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.Flow;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowBuilder;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.user.intent.objects.FlowKey;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.User;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.intent.rev151010.users.UserKey;
\r
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
\r
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
26 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
\r
27 import com.google.common.util.concurrent.CheckedFuture;
\r
28 import com.google.common.util.concurrent.FutureCallback;
\r
29 import com.google.common.util.concurrent.Futures;
\r
30 import org.slf4j.Logger;
\r
31 import org.slf4j.LoggerFactory;
\r
33 * Created by z00293636 on 2015/8/31.
\r
35 public class UpdateFlow {
\r
37 private DataBroker dataBroker;
\r
38 private TenantManage tenantManage;
\r
39 private FlowDefinitionCheck flowDefinitionCheck;
\r
40 private FlowInstanceCheck flowInstanceCheck;
\r
41 private static final Logger LOG = LoggerFactory.getLogger(UpdateFlow.class);
\r
43 public UpdateFlow(DataBroker dataBroker, TenantManage tenantManage)
\r
45 this.dataBroker = dataBroker;
\r
46 this.tenantManage = tenantManage;
\r
47 flowDefinitionCheck = new FlowDefinitionCheck(dataBroker);
\r
48 flowInstanceCheck = new FlowInstanceCheck(tenantManage);
\r
51 public String FlowHandling(UserId userId, Flow flow)
\r
53 String errorDefinition = flowDefinitionCheck.CheckDefinition(flow);
\r
54 String errorInstance = flowInstanceCheck.checkFlowInstance(userId,flow);
\r
56 if (errorDefinition != null)
\r
58 return errorDefinition;
\r
60 if (errorInstance != null)
\r
62 return errorInstance;
\r
66 WriteTransaction t = dataBroker.newWriteOnlyTransaction();
\r
67 if (userId!=null && flow!=null)
\r
69 // FlowBuilder flowBuilder = new FlowBuilder();
\r
70 // flowBuilder.setFlowId(flow.getFlowId());
\r
71 // flowBuilder.setFlowName(flow.getFlowName());
\r
72 // flowBuilder.setMatchItem(flow.getMatchItem());
\r
73 // flowBuilder.setProperty(flow.getProperty());
\r
75 // Flow flow1 = flowBuilder.build();
\r
76 Flow flow1 = new FlowBuilder(flow).build();
\r
77 FlowKey flowKey = new FlowKey(flow.getFlowId());
\r
79 UserKey userKey = new UserKey(userId);
\r
81 InstanceIdentifier<Flow> flowid = InstanceIdentifier.builder(Users.class).child(User.class, userKey).child(Objects.class).child(Flow.class,flowKey).build();
\r
82 t.put(LogicalDatastoreType.CONFIGURATION, flowid, flow1,true);
\r
83 CheckedFuture<Void, TransactionCommitFailedException> f = t.submit();
\r
84 Futures.addCallback(f, new FutureCallback<Void>() {
\r
86 public void onFailure(Throwable t) {
\r
87 LOG.error("Could not write endpoint base container", t);
\r
91 public void onSuccess(Void result) {
\r