2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.model.aaiTree;
23 import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
24 import static org.onap.vid.aai.util.AAITreeConverter.NETWORK_ROLE;
25 import static org.onap.vid.aai.util.AAITreeConverter.NETWORK_TYPE;
26 import static org.onap.vid.aai.util.AAITreeConverter.PHYSICAL_NETWORK_NAME;
27 import static org.onap.vid.aai.util.AAITreeConverter.SERVICE_INSTANCE;
28 import static org.onap.vid.aai.util.AAITreeConverter.SERVICE_INSTANCE_SERVICE_INSTANCE_ID;
29 import static org.onap.vid.aai.util.AAITreeConverter.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME;
30 import static org.onap.vid.aai.util.AAITreeConverter.TENANT;
31 import static org.onap.vid.aai.util.AAITreeConverter.TENANT_TENANT_NAME;
32 import static org.onap.vid.aai.util.AAITreeConverter.VPN_BINDING;
34 import com.fasterxml.jackson.annotation.JsonInclude;
35 import org.apache.commons.collections.CollectionUtils;
36 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Relationship;
37 import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList;
38 import org.onap.vid.aai.util.AAITreeNodeUtils;
40 @JsonInclude(NON_NULL)
41 public class Network extends Node {
44 private String physicalName;
45 private String serviceName;
46 private String serviceUUID;
47 private String tenantName;
48 private Boolean isBoundToVpn;
49 private RouteTarget routeTarget;
53 private Network(AAITreeNode node) {
55 fillCloudConfigurationProperties(this, node.getCloudConfiguration());
58 public static Network from(AAITreeNode node) {
59 Network network = new Network(node);
60 network.setInstanceType(readValueAsStringFromAdditionalProperties(node, NETWORK_TYPE));
61 network.setRole(readValueAsStringFromAdditionalProperties(node, NETWORK_ROLE));
62 network.setPhysicalName(readValueAsStringFromAdditionalProperties(node, PHYSICAL_NETWORK_NAME));
63 RelationshipList relationshipList = node.getRelationshipList();
64 Relationship serviceInstanceRelationship = AAITreeNodeUtils.findFirstRelationshipByRelatedTo(relationshipList, SERVICE_INSTANCE).orElse(null);
65 if (serviceInstanceRelationship != null) {
66 network.setServiceName(AAITreeNodeUtils.findFirstValue(serviceInstanceRelationship.getRelatedToPropertyList(), SERVICE_INSTANCE_SERVICE_INSTANCE_NAME).orElse(null));
67 network.setServiceUUID(AAITreeNodeUtils.findFirstValue(serviceInstanceRelationship.getRelationDataList(), SERVICE_INSTANCE_SERVICE_INSTANCE_ID).orElse(null));
69 AAITreeNodeUtils.findFirstRelationshipByRelatedTo(relationshipList, TENANT).ifPresent(
70 tenantRelationship -> network.setTenantName(AAITreeNodeUtils.findFirstValue(tenantRelationship.getRelatedToPropertyList(), TENANT_TENANT_NAME).orElse(null))
72 // We are ignoring "is-bound-to-vpn" parameter from additionalProperties because there is a requirement to define vpn binding presence from by related-to: vpn-binding
73 network.setBoundToVpn(AAITreeNodeUtils.findFirstRelationshipByRelatedTo(relationshipList, VPN_BINDING).isPresent());
75 //get the route target
76 node.getChildren().stream()
77 .filter(x->x.getType()== NodeType.VPN_BINDING) // get all VPN_BINDING related to the network
78 .map(x->VpnBindingKt.from(x)) // create VPN_BINDING nodes
79 .filter(x-> CollectionUtils.isNotEmpty(x.getRouteTargets())) // get the RouteTargets that are not empty
80 .findFirst() // get the first one
81 .ifPresent(x->network.setRouteTarget(x.getRouteTargets().get(0))); // If there is a route target - add it to the network
85 public String getRole() {
89 public void setRole(String role) {
93 public String getPhysicalName() {
97 public void setPhysicalName(String physicalName) {
98 this.physicalName = physicalName;
101 public String getServiceName() {
105 public void setServiceName(String serviceName) {
106 this.serviceName = serviceName;
109 public String getServiceUUID() {
113 public void setServiceUUID(String serviceUUID) {
114 this.serviceUUID = serviceUUID;
117 public String getTenantName() {
121 public void setTenantName(String tenantName) {
122 this.tenantName = tenantName;
125 public Boolean isBoundToVpn() {
129 public void setBoundToVpn(Boolean boundToVpn) {
130 isBoundToVpn = boundToVpn;
133 public RouteTarget getRouteTarget() {
137 public void setRouteTarget(RouteTarget routeTarget) {
138 this.routeTarget = routeTarget;