1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*-
* ============LICENSE_START=======================================================
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.vid.aai.util;
import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE;
import java.util.Map;
import javax.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.onap.vid.model.ModelUtil;
import org.onap.vid.model.aaiTree.AAITreeNode;
import org.onap.vid.model.aaiTree.CollectionResource;
import org.onap.vid.model.aaiTree.Network;
import org.onap.vid.model.aaiTree.Node;
import org.onap.vid.model.aaiTree.NodeType;
import org.onap.vid.model.aaiTree.ServiceInstance;
import org.onap.vid.model.aaiTree.Vnf;
import org.onap.vid.model.aaiTree.VnfGroup;
import org.onap.vid.model.aaiTree.Vrf;
import org.onap.vid.mso.model.ModelInfo;
import org.springframework.stereotype.Component;
@Component
public class AAITreeConverter {
public static final String VNF_TYPE = "vnf-type";
public static final String NETWORK_TYPE = "network-type";
public static final String NETWORK_ROLE = "network-role";
public static final String PHYSICAL_NETWORK_NAME = "physical-network-name";
public static final String SERVICE_INSTANCE = "service-instance";
public static final String TENANT = "tenant";
public static final String VPN_BINDING = "vpn-binding";
public static final String IS_BASE_VF_MODULE = "is-base-vf-module";
public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_NAME = "service-instance.service-instance-name";
public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
public static final String TENANT_TENANT_NAME = "tenant.tenant-name";
private final ModelUtil modelUtil;
@Inject
public AAITreeConverter(ModelUtil modelUtil) {
this.modelUtil = modelUtil;
}
public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType, String instanceRole, String instanceType) {
ServiceInstance serviceInstance = new ServiceInstance();
serviceInstance.setInstanceId(rootNode.getId());
serviceInstance.setInstanceName(rootNode.getName());
serviceInstance.setOrchStatus(rootNode.getOrchestrationStatus());
serviceInstance.setGlobalSubscriberId(globalCustomerId);
serviceInstance.setSubscriptionServiceType(serviceType);
serviceInstance.setIsALaCarte(StringUtils.equals(instantiationType, A_LA_CARTE));
serviceInstance.setModelInfo(createModelInfo(rootNode));
//set children: vnf, network,group
rootNode.getChildren().forEach(child -> {
if (child.getType() == NodeType.GENERIC_VNF) {
serviceInstance.getVnfs().put(child.getUniqueNodeKey(), Vnf.from(child));
} else if (child.getType() == NodeType.NETWORK) {
serviceInstance.getNetworks().put(child.getUniqueNodeKey(), Network.from(child));
} else if (child.getType() == NodeType.INSTANCE_GROUP) {
serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), new VnfGroup(child));
} else if (child.getType() == NodeType.COLLECTION_RESOURCE) {
serviceInstance.getCollectionResources().put(child.getUniqueNodeKey(), new CollectionResource(child));
} else if (isChildVrf(instanceType, instanceRole, child)){
serviceInstance.getVrfs().put(child.getUniqueNodeKey(), Vrf.from(child));
}
});
serviceInstance.setExistingVNFCounterMap(
getExistingCounterMap(serviceInstance.getVnfs())
);
serviceInstance.setExistingNetworksCounterMap(
getExistingCounterMap(serviceInstance.getNetworks())
);
serviceInstance.setExistingVnfGroupCounterMap(
getExistingCounterMap(serviceInstance.getVnfGroups())
);
serviceInstance.setExistingVRFCounterMap(
getExistingCounterMap(serviceInstance.getVrfs())
);
return serviceInstance;
}
protected boolean isChildVrf(String instanceType, String serviceRole, AAITreeNode child) {
return child.getType() == NodeType.CONFIGURATION && StringUtils.equalsIgnoreCase(instanceType, "BONDING") && StringUtils.equalsIgnoreCase(serviceRole, "INFRASTRUCTURE-VPN");
}
private <T extends Node> Map<String, Long> getExistingCounterMap(Map<String, T> nodeList) {
return modelUtil.getExistingCounterMap(nodeList, Node::getModelInfo);
}
private static ModelInfo createModelInfo(AAITreeNode aaiNode) {
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelType(aaiNode.getType().getModelType());
modelInfo.setModelName(aaiNode.getModelName());
modelInfo.setModelVersion(aaiNode.getModelVersion());
modelInfo.setModelVersionId(aaiNode.getModelVersionId());
modelInfo.setModelInvariantId(aaiNode.getModelInvariantId());
modelInfo.setModelCustomizationId(aaiNode.getModelCustomizationId());
return modelInfo;
}
}
|