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.nemo.user.tenantmanager.TenantManage;
\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.common.rev151010.ConnectionType;
\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.user.intent.objects.Connection;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.definitions.ConnectionDefinition;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.EndNode;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.connection.instance.Property;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.definitions.PropertyDefinition;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.nemo.object.rev151010.property.instance.PropertyValues;
\r
21 import java.util.List;
\r
22 import java.util.Map;
\r
25 * Created by z00293636 on 2015/8/31.
\r
27 public class UpdateConnection {
\r
28 private TenantManage tenantManage;
\r
29 private GetDefinitions getDefinitions;
\r
31 public UpdateConnection(DataBroker dataBroker, TenantManage tenantManage){
\r
32 this.tenantManage = tenantManage;
\r
33 getDefinitions = new GetDefinitions(dataBroker);
\r
36 public String ConnectionHandling(UserId userId, Connection connection){
\r
37 String errorInfo = null;
\r
38 errorInfo =checkDefinition(connection);
\r
39 if (errorInfo != null){
\r
43 errorInfo = checkInstance(userId,connection);
\r
44 if (errorInfo != null){
\r
48 tenantManage.setConnection(userId,connection.getConnectionId(),connection);
\r
54 private String checkInstance(UserId userId, Connection connection){
\r
55 if (tenantManage.getConnection(userId)!=null){
\r
56 if (tenantManage.getConnection(userId).containsKey(connection.getConnectionId())){
\r
57 Connection connExist = tenantManage.getConnection(userId).get(connection.getConnectionId());
\r
58 if (!connExist.getConnectionName().equals(connection.getConnectionName())){
\r
59 return "The connection name should not be changed.";
\r
61 if (!connExist.getConnectionType().equals(connection.getConnectionType())){
\r
62 return "The connection type should not be changed.";
\r
64 if (!connExist.getEndNode().equals(connection.getEndNode())){
\r
65 return "The connection end node should not be changed.";
\r
70 if (tenantManage.getConnectionDataStore(userId)!=null){
\r
71 if (tenantManage.getConnectionDataStore(userId).containsKey(connection.getConnectionId())){
\r
72 Connection connExist = tenantManage.getConnectionDataStore(userId).get(connection.getConnectionId());
\r
73 if (!connExist.getConnectionName().equals(connection.getConnectionName())){
\r
74 return "The connection name should not be changed.";
\r
76 if (!connExist.getConnectionType().equals(connection.getConnectionType())){
\r
77 return "The connection type should not be changed.";
\r
79 if (!connExist.getEndNode().equals(connection.getEndNode())){
\r
80 return "The connection end node should not be changed.";
\r
85 if (connection.getEndNode()!=null){
\r
86 List<EndNode> endNodeList = connection.getEndNode();
\r
87 for (EndNode endNode : endNodeList){
\r
88 Boolean endNodeExist = false;
\r
89 if (tenantManage.getNode(userId)!=null){
\r
90 if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){
\r
91 endNodeExist = true;
\r
94 if (tenantManage.getNodeDataStore(userId)!=null){
\r
95 if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){
\r
96 endNodeExist = true;
\r
100 return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;";
\r
107 private String checkDefinition(Connection connection){
\r
108 String errorInfo = null;
\r
109 Map<ConnectionType, ConnectionDefinition> connectionDefinitionMap = getDefinitions.getConnectionDefinition();
\r
110 if (connectionDefinitionMap.isEmpty()){
\r
111 return "This type of connection has not been defined.";
\r
114 if (connectionDefinitionMap.containsKey(connection.getConnectionType())){
\r
115 List<Property> connectionProperties = connection.getProperty();
\r
116 List<PropertyDefinition> propertyDefinitions = connectionDefinitionMap.get(connection.getConnectionType()).getPropertyDefinition();
\r
117 if (connectionProperties != null && propertyDefinitions ==null)
\r
119 errorInfo = "There are no properties for this type of connection.";
\r
121 else if (connectionProperties != null && propertyDefinitions != null)
\r
123 errorInfo = checkProperty(connection.getProperty(), propertyDefinitions);
\r
127 return "This type of connection has not been defined.";
\r
133 private String checkProperty(List<Property> connectionProperty, List<PropertyDefinition> propertyDefinitionList ){
\r
134 String errorInfo = null;
\r
135 for (Property property : connectionProperty)
\r
137 Boolean properyHasDefine = false;
\r
138 if (errorInfo != null)
\r
144 for (PropertyDefinition propertyDefinition : propertyDefinitionList)
\r
146 if (property.getPropertyName().equals(propertyDefinition.getPropertyName()))
\r
148 properyHasDefine = true;
\r
149 PropertyValues propertyValues = property.getPropertyValues();
\r
150 PropertyDefinition.PropertyValueType propertyValueType = propertyDefinition.getPropertyValueType();
\r
152 if (propertyValues != null && propertyValueType != null)
\r
154 if (propertyDefinition.getIsReadOnly()!=null
\r
155 && PropertyDefinition.IsReadOnly.ReadOnly == propertyDefinition.getIsReadOnly())
\r
157 if (propertyDefinition.getIsRequired().getIntValue() == 1)
\r
159 errorInfo = "The property value type of " + property.getPropertyName().toString() + " is read only.";
\r
165 if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)) {
\r
166 errorInfo = "The property value type of " + property.getPropertyName().toString() + " should be string.";
\r
169 if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)) {
\r
170 errorInfo = "The property value type of" + property.getPropertyName().toString() + " should be integer.";
\r
173 if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)) {
\r
174 errorInfo = "The property value type of" + property.getPropertyName().toString() + " should be range.";
\r
181 if (!properyHasDefine) {
\r
182 errorInfo = "This type of property" + property.getPropertyName().toString() + " has not been defined.";
\r
187 if (errorInfo == null)
\r
189 Boolean requiredProperty = false;
\r
190 for (PropertyDefinition propertyDefinition : propertyDefinitionList)
\r
192 if (propertyDefinition.getIsRequired()!=null)
\r
194 if (propertyDefinition.getIsRequired().getIntValue() == 0)
\r
196 for (Property property : connectionProperty)
\r
198 if (property.getPropertyName().equals(propertyDefinition.getPropertyName()))
\r
200 requiredProperty = true;
\r
203 if (!requiredProperty)
\r
205 errorInfo = "The required property" + propertyDefinition.getPropertyName().toString() + "is not included in the intent.";
\r