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 List<EndNode> endNodeList = connection.getEndNode();
\r
86 for (EndNode endNode : endNodeList){
\r
87 Boolean endNodeExist = false;
\r
88 if (tenantManage.getNode(userId)!=null){
\r
89 if (tenantManage.getNode(userId).containsKey(endNode.getNodeId())){
\r
90 endNodeExist = true;
\r
93 if (tenantManage.getNodeDataStore(userId)!=null){
\r
94 if (tenantManage.getNodeDataStore(userId).containsKey(endNode.getNodeId())){
\r
95 endNodeExist = true;
\r
99 return "The endnode "+ endNode.getNodeId().getValue() +" is not exist;";
\r
105 private String checkDefinition(Connection connection){
\r
106 String errorInfo = null;
\r
107 Map<ConnectionType, ConnectionDefinition> connectionDefinitionMap = getDefinitions.getConnectionDefinition();
\r
108 if (connectionDefinitionMap.isEmpty()){
\r
109 return "This type of connection has not been defined.";
\r
112 if (connectionDefinitionMap.containsKey(connection.getConnectionType())){
\r
113 List<Property> connectionProperties = connection.getProperty();
\r
114 List<PropertyDefinition> propertyDefinitions = connectionDefinitionMap.get(connection.getConnectionType()).getPropertyDefinition();
\r
115 if (connectionProperties != null && propertyDefinitions ==null)
\r
117 errorInfo = "There are no properties for this type of connection.";
\r
119 else if (connectionProperties != null && propertyDefinitions != null)
\r
121 errorInfo = checkProperty(connection.getProperty(), propertyDefinitions);
\r
125 return "This type of connection has not been defined.";
\r
131 private String checkProperty(List<Property> connectionProperty, List<PropertyDefinition> propertyDefinitionList ){
\r
132 String errorInfo = null;
\r
133 for (Property property : connectionProperty)
\r
135 Boolean properyHasDefine = false;
\r
136 if (errorInfo != null)
\r
142 for (PropertyDefinition propertyDefinition : propertyDefinitionList)
\r
144 if (property.getPropertyName().equals(propertyDefinition.getPropertyName()))
\r
146 properyHasDefine = true;
\r
147 PropertyValues propertyValues = property.getPropertyValues();
\r
148 PropertyDefinition.PropertyValueType propertyValueType = propertyDefinition.getPropertyValueType();
\r
150 if (propertyValues != null && propertyValueType != null)
\r
152 if (propertyDefinition.getIsReadOnly()!=null
\r
153 && PropertyDefinition.IsReadOnly.ReadOnly == propertyDefinition.getIsReadOnly())
\r
155 if (propertyDefinition.getIsRequired().getIntValue() == 1)
\r
157 errorInfo = "The property value type of " + property.getPropertyName().toString() + " is read only.";
\r
163 if (propertyValueType.getIntValue() == 0 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() != null && propertyValues.getRangeValue() == null)) {
\r
164 errorInfo = "The property value type of " + property.getPropertyName().toString() + " should be string.";
\r
167 if (propertyValueType.getIntValue() == 1 && !(propertyValues.getIntValue() != null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() == null)) {
\r
168 errorInfo = "The property value type of" + property.getPropertyName().toString() + " should be integer.";
\r
171 if (propertyValueType.getIntValue() == 2 && !(propertyValues.getIntValue() == null && propertyValues.getStringValue() == null && propertyValues.getRangeValue() != null)) {
\r
172 errorInfo = "The property value type of" + property.getPropertyName().toString() + " should be range.";
\r
179 if (!properyHasDefine) {
\r
180 errorInfo = "This type of property" + property.getPropertyName().toString() + " has not been defined.";
\r
185 if (errorInfo == null)
\r
187 Boolean requiredProperty = false;
\r
188 for (PropertyDefinition propertyDefinition : propertyDefinitionList)
\r
190 if (propertyDefinition.getIsRequired()!=null)
\r
192 if (propertyDefinition.getIsRequired().getIntValue() == 0)
\r
194 for (Property property : connectionProperty)
\r
196 if (property.getPropertyName().equals(propertyDefinition.getPropertyName()))
\r
198 requiredProperty = true;
\r
201 if (!requiredProperty)
\r
203 errorInfo = "The required property" + propertyDefinition.getPropertyName().toString() + "is not included in the intent.";
\r