1 package org.onap.vid.asdc.parser;
3 import org.apache.commons.collections.MapUtils;
4 import org.apache.commons.lang3.StringUtils;
5 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
6 import org.onap.sdc.toscaparser.api.NodeTemplate;
7 import org.onap.vid.model.ServiceModel;
8 import org.onap.vid.model.VidNotions;
9 import org.onap.vid.properties.Features;
10 import org.togglz.core.manager.FeatureManager;
12 import static org.apache.commons.lang3.StringUtils.equalsAnyIgnoreCase;
13 import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase;
15 public class VidNotionsBuilder {
17 private final FeatureManager featureManager;
19 public VidNotionsBuilder(FeatureManager featureManager) {
20 this.featureManager = featureManager;
23 public VidNotions buildVidNotions(ISdcCsarHelper csarHelper, ServiceModel serviceModel) {
24 final VidNotions.InstantiationUI instantiationUI = suggestInstantiationUI(csarHelper);
26 return new VidNotions(instantiationUI, suggestModelCategory(csarHelper), suggestViewEditUI(csarHelper, serviceModel));
29 //UI route a-la-carte services to old UI only if InstantiationUI is LEGACY
30 //So any other value for InstantiationUI other than LEGACY make UI to route
31 //a-la-carte services to new UI
32 VidNotions.InstantiationUI suggestInstantiationUI(ISdcCsarHelper csarHelper) {
33 if(featureManager.isActive(Features.FLAG_EXP_ANY_ALACARTE_NEW_INSTANTIATION_UI) && isALaCarte(csarHelper)) {
34 return VidNotions.InstantiationUI.ANY_ALACARTE_NEW_UI;
36 if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) {
37 return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING;
39 if (featureManager.isActive(Features.FLAG_5G_IN_NEW_INSTANTIATION_UI)) {
40 if (isUuidExactlyHardCoded1ffce89fef3f(csarHelper)) {
41 return VidNotions.InstantiationUI.SERVICE_UUID_IS_1ffce89f_ef3f_4cbb_8b37_82134590c5de;
42 } else if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)) {
43 return VidNotions.InstantiationUI.NETWORK_WITH_PROPERTY_NETWORK_TECHNOLOGY_EQUALS_STANDARD_SRIOV_OR_OVS;
44 } else if (isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) {
45 return VidNotions.InstantiationUI.SERVICE_WITH_FABRIC_CONFIGURATION;
49 return VidNotions.InstantiationUI.LEGACY;
53 VidNotions.ModelCategory suggestModelCategory(ISdcCsarHelper csarHelper) {
54 if (isALaCarte(csarHelper) && hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(csarHelper)){
55 return VidNotions.ModelCategory.IS_5G_PROVIDER_NETWORK_MODEL;
56 } else if(isALaCarte(csarHelper) && hasFabricConfiguration(csarHelper)) {
57 return VidNotions.ModelCategory.IS_5G_FABRIC_CONFIGURATION_MODEL;
59 return VidNotions.ModelCategory.OTHER;
63 VidNotions.InstantiationUI suggestViewEditUI(ISdcCsarHelper csarHelper, ServiceModel serviceModel) {
64 if (!featureManager.isActive(Features.FLAG_ASYNC_INSTANTIATION)){
65 return VidNotions.InstantiationUI.LEGACY;
67 if (featureManager.isActive(Features.FLAG_1902_VNF_GROUPING) && isGrouping(csarHelper)) {
68 return VidNotions.InstantiationUI.SERVICE_WITH_VNF_GROUPING;
71 if (featureManager.isActive(Features.FLAG_1902_NEW_VIEW_EDIT)) {
72 if (isMacro(serviceModel) && !isMacroExcludedFromAsyncFlow(serviceModel)) {
73 return VidNotions.InstantiationUI.MACRO_SERVICE;
75 VidNotions.InstantiationUI instantiationUISuggestion = suggestInstantiationUI(csarHelper);
76 if (instantiationUISuggestion!=VidNotions.InstantiationUI.LEGACY) {
77 return instantiationUISuggestion;
81 return VidNotions.InstantiationUI.LEGACY;
84 private boolean isMacro(ServiceModel serviceModel) {
85 return ToscaParserImpl2.Constants.MACRO.equals(serviceModel.getService().getInstantiationType());
88 private boolean isUuidExactlyHardCoded1ffce89fef3f(ISdcCsarHelper csarHelper) {
89 return equalsIgnoreCase(
90 csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.UUID), "95eb2c44-bff2-4e8b-ad5d-8266870b7717");
93 private boolean hasAnyNetworkWithPropertyNetworkTechnologyEqualsStandardSriovOrOvs(ISdcCsarHelper csarHelper) {
94 return hasAnyNetworkWithPropertyEqualsToAnyOf(csarHelper, "network_technology","Standard-SR-IOV","OVS") ;
97 boolean hasFabricConfiguration(ISdcCsarHelper csarHelper) {
98 return csarHelper.getServiceNodeTemplates().stream()
99 .flatMap(nodeTemplate -> csarHelper.getNodeTemplateChildren(nodeTemplate).stream())
100 .anyMatch(child -> child.getType().equals(ToscaParserImpl2.Constants.FABRIC_CONFIGURATION_TYPE));
103 boolean hasAnyNetworkWithPropertyEqualsToAnyOf(ISdcCsarHelper csarHelper, String propertyName, String... propertyValues) {
105 .getServiceVlList().stream()
106 .map(NodeTemplate::getProperties)
107 .flatMap(props -> props.entrySet().stream())
108 .filter(prop -> equalsIgnoreCase(prop.getKey(), propertyName))
109 // getValue().getValue() because value is Entry, where it's inner value is what we're looking for
110 .anyMatch(prop -> equalsAnyIgnoreCase(prop.getValue().getValue().toString(), propertyValues));
113 boolean isALaCarte(ISdcCsarHelper csarHelper) {
114 final String instantiationType = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.INSTANTIATION_TYPE);
115 return StringUtils.equalsIgnoreCase(instantiationType, ToscaParserImpl2.Constants.A_LA_CARTE);
118 boolean isMacroExcludedFromAsyncFlow(ServiceModel serviceModel) {
119 return (MapUtils.isNotEmpty(serviceModel.getPnfs()) ||
120 MapUtils.isNotEmpty(serviceModel.getCollectionResource()) ||
121 (MapUtils.isNotEmpty(serviceModel.getNetworks()) && !featureManager.isActive(Features.FLAG_NETWORK_TO_ASYNC_INSTANTIATION)));
126 private boolean isGrouping(ISdcCsarHelper csarHelper) {
127 final String serviceRole = csarHelper.getServiceMetadata().getValue(ToscaParserImpl2.Constants.SERVICE_ROLE);
128 return StringUtils.equalsIgnoreCase(serviceRole, ToscaParserImpl2.Constants.GROUPING);