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.asdc.parser;
23 import org.apache.commons.collections.MapUtils;
24 import org.apache.commons.lang3.StringUtils;
25 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
26 import org.onap.sdc.toscaparser.api.NodeTemplate;
27 import org.onap.vid.model.ServiceModel;
28 import org.onap.vid.model.VidNotions;
29 import org.onap.vid.properties.Features;
30 import org.togglz.core.manager.FeatureManager;
32 import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase;
33 import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
35 public class VidNotionsBuilder {
37 private final FeatureManager featureManager;
39 public VidNotionsBuilder(FeatureManager featureManager) {
40 this.featureManager = featureManager;
43 public VidNotions buildVidNotions(ISdcCsarHelper csarHelper, ServiceModel serviceModel) {
44 final VidNotions.InstantiationUI instantiationUI = suggestInstantiationUI(csarHelper);
46 return new VidNotions(instantiationUI, suggestModelCategory(csarHelper), suggestViewEditUI(csarHelper, serviceModel));
49 //UI route a-la-carte services to old UI only if InstantiationUI is LEGACY
50 //So any other value for InstantiationUI other than LEGACY make UI to route
51 //a-la-carte services to new UI
52 VidNotions.InstantiationUI suggestInstantiationUI(ISdcCsarHelper csarHelper) {
53 if(featureManager.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI) && isALaCarte(csarHelper)) {
54 return VidNotions.InstantiationUI.ANY_ALACARTE_NEW_UI;
56 if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) {
57 return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING;
59 if (featureManager.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)) {
60 if (isUuidExactlyHardCoded1ffce89fef3f(csarHelper)) {
61 return VidNotions.InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de;
62 } else if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)) {
63 return VidNotions.InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS;
64 } else if (isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) {
65 return VidNotions.InstantiationUI.SERVICE_WITH_FABRIC_CONFIGURATION;
69 return VidNotions.InstantiationUI.LEGACY;
73 VidNotions.ModelCategory suggestModelCategory(ISdcCsarHelper csarHelper) {
74 if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)){
75 return VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL;
76 } else if(isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) {
77 return VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL;
79 return VidNotions.ModelCategory.OTHER;
83 VidNotions.InstantiationUI suggestViewEditUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel) {
84 if (!featureManager.isActive(Features.FLAG_ASYNC_INSTANTIATION)){
85 return VidNotions.InstantiationUI.LEGACY;
87 if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) {
88 return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING;
91 if (featureManager.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)) {
92 if (isMacro(serviceModel) && !isMacroExcludedFromAsyncFlow(serviceModel)) {
93 return VidNotions.InstantiationUI.MACRO_SERVICE;
95 VidNotions.InstantiationUI instantiationUISuggestion = suggestInstantiationUI(csarHelper);
96 if (instantiationUISuggestion!=VidNotions.InstantiationUI.LEGACY) {
97 return instantiationUISuggestion;
101 return VidNotions.InstantiationUI.LEGACY;
104 private boolean isMacro(ServiceModel serviceModel) {
105 return ToscaParserImpl2.Constants.MACRO.equals(serviceModel.getService().getInstantiationType());
108 private boolean isUuidExactlyHardCoded1ffce89fef3f(ISdcCsarHelper csarHelper) {
109 return equalsIgnoreCase(
110 csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.UUID), "95eb2c44-bff2-4e8b-ad5d-8266870b7717");
113 private boolean hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(ISdcCsarHelper csarHelper) {
114 return hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV","OVS") ;
117 boolean hasFabricConfiguration(ISdcCsarHelper csarHelper) {
118 return csarHelper.getServiceNodeTemplates().stream()
119 .flatMap(nodeTemplate -> csarHelper.getNodeTemplateChildren(nodeTemplate).stream())
120 .anyMatch(child -> child.getType().equals(ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE));
123 boolean hasAnyNetworkWithPropertyEqualsToAnyOf(ISdcCsarHelper csarHelper, String propertyName, String... propertyValues) {
125 .getServiceVlList().stream()
126 .map(NodeTemplate::getProperties)
127 .flatMap(props -> props.entrySet().stream())
128 .filter(prop -> equalsIgnoreCase(prop.getKey(), propertyName))
129 // getValue().getValue() because value is Entry, where it's inner value is what we're looking for
130 .anyMatch(prop -> equalsAnyIgnoreCase(prop.getValue().getValue().toString(), propertyValues));
133 boolean isALaCarte(ISdcCsarHelper csarHelper) {
134 final String instantiationType = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.INSTANTIATION_TYPE);
135 return StringUtils.equalsIgnoreCase(instantiationType, ToscaParserImpl2.Constants.A_LA_CARTE);
138 boolean isMacroExcludedFromAsyncFlow(ServiceModel serviceModel) {
139 return (MapUtils.isNotEmpty(serviceModel.getPnfs()) ||
140 MapUtils.isNotEmpty(serviceModel.getCollectionResource()) ||
141 (MapUtils.isNotEmpty(serviceModel.getNetworks()) && !featureManager.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)));
146 private boolean isGrouping(ISdcCsarHelper csarHelper) {
147 final String serviceRole = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.SERVICE_ROLE);
148 return StringUtils.equalsIgnoreCase(serviceRole, ToscaParserImpl2.Constants.GROUPING);