[sdc] docker file fix for cassandra
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / services / heattotosca / globaltypes / ContrailNetworkRuleGlobalType.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.translator.services.heattotosca.globaltypes;
22
23 import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
24 import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
25 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
26 import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
27 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
28 import org.openecomp.sdc.tosca.datatypes.model.DataType;
29 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
30 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
31 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
32 import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
33 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
34 import org.openecomp.sdc.tosca.services.DataModelUtil;
35 import org.openecomp.sdc.tosca.services.ToscaConstants;
36 import org.openecomp.sdc.translator.services.heattotosca.Constants;
37
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42
43 public class ContrailNetworkRuleGlobalType {
44   /**
45    * Create service template service template.
46    *
47    * @return the service template
48    */
49   public static ServiceTemplate createServiceTemplate() {
50     ServiceTemplate contrailNetworkRuleServiceTemplate = new ServiceTemplate();
51     contrailNetworkRuleServiceTemplate
52         .setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
53     contrailNetworkRuleServiceTemplate.setMetadata(
54         DataModelUtil.createMetadata(Constants.CONTRAIL_NETWORK_RULE_TEMPLATE_NAME, "1.0.0", null));
55     contrailNetworkRuleServiceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
56     contrailNetworkRuleServiceTemplate.setDescription("Contrail Network Rule Global Types");
57     contrailNetworkRuleServiceTemplate.setData_types(createGlobalDataTypes());
58     contrailNetworkRuleServiceTemplate.setNode_types(createGlobalNodeTypes());
59     return contrailNetworkRuleServiceTemplate;
60   }
61
62
63   private static Map<String, DataType> createGlobalDataTypes() {
64     Map<String, DataType> globalDataTypes = new HashMap<>();
65     globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
66         createRulePortPairsDataType());
67     globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE.getDisplayName(), createRuleDataType());
68     globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(),
69         createRuleVirtualNetworkDataType());
70     globalDataTypes.put(ToscaDataType.CONTRAIL_NETWORK_RULE_LIST.getDisplayName(),
71         createPolicyRulesListDataType());
72     return globalDataTypes;
73   }
74
75   private static DataType createRuleDataType() {
76     DataType dataType = new DataType();
77     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
78     dataType.setDescription("policy rule");
79     Map<String, PropertyDefinition> properties = new HashMap<>();
80     properties.put("direction", DataModelUtil
81         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Direction", false, null,
82             null, null, null));
83     properties.put("protocol", DataModelUtil
84         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Protocol", false, null,
85             null, null, null));
86     properties.put("src_ports", DataModelUtil
87         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source ports", false, null,
88             null, DataModelUtil
89                 .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
90                     null, null), null));
91     properties.put("dst_ports", DataModelUtil
92         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination ports", false,
93             null, null, DataModelUtil
94                 .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE_PORT_PAIRS.getDisplayName(),
95                     null, null), null));
96     properties.put("dst_addresses", DataModelUtil
97         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Destination addresses",
98             false, null, null, DataModelUtil.createEntrySchema(
99                 ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(), null, null),
100             null));
101     properties.put("apply_service", DataModelUtil
102         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service to apply", false,
103             null, null, null, null));
104     properties.put("src_addresses", DataModelUtil
105         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Source addresses", false,
106             null, null, DataModelUtil.createEntrySchema(
107                 ToscaDataType.CONTRAIL_NETWORK_RULE_VIRTUAL_NETWORK.getDisplayName(), null, null),
108             null));
109
110     dataType.setProperties(properties);
111     return dataType;
112
113   }
114
115
116   private static DataType createRuleVirtualNetworkDataType() {
117     DataType dataType = new DataType();
118     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
119     dataType.setDescription("source and destination addresses");
120     Map<String, PropertyDefinition> properties = new HashMap<>();
121
122     properties.put("virtual_network", DataModelUtil
123         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Virtual network", false,
124             null, null, null, null));
125
126     dataType.setProperties(properties);
127     return dataType;
128   }
129
130   private static DataType createPolicyRulesListDataType() {
131     DataType dataType = new DataType();
132     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
133     dataType.setDescription("list of policy rules");
134     Map<String, PropertyDefinition> properties = new HashMap<>();
135
136     properties.put("policy_rule", DataModelUtil
137         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Contrail network rule",
138             false, null, null, DataModelUtil
139                 .createEntrySchema(ToscaDataType.CONTRAIL_NETWORK_RULE.getDisplayName(), null,
140                     null), null));
141
142     dataType.setProperties(properties);
143     return dataType;
144   }
145
146
147   private static DataType createRulePortPairsDataType() {
148     DataType dataType = new DataType();
149     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
150     dataType.setDescription("source and destination port pairs");
151     Map<String, PropertyDefinition> properties = new HashMap<>();
152
153     properties.put("start_port", DataModelUtil
154         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Start port", false, null,
155             null, null, null));
156     properties.put("end_port", DataModelUtil
157         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "End port", false, null,
158             null, null, null));
159
160     dataType.setProperties(properties);
161     return dataType;
162   }
163
164   private static Map<String, NodeType> createGlobalNodeTypes() {
165     Map<String, NodeType> globalNodeTypes = new HashMap<>();
166     globalNodeTypes.put(ToscaNodeType.CONTRAIL_NETWORK_RULE.getDisplayName(),
167         createContrailNetworkRuleNodeType());
168     return globalNodeTypes;
169   }
170
171   private static NodeType createContrailNetworkRuleNodeType() {
172     NodeType contrailNetworkRuleNodeType = new NodeType();
173     contrailNetworkRuleNodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
174     contrailNetworkRuleNodeType.setProperties(createContrailNetworkRuleProperties());
175     contrailNetworkRuleNodeType.setAttributes(createContrailNetworkRuleAttributes());
176     contrailNetworkRuleNodeType.setRequirements(createContrailNetworkRuleRequirements());
177     return contrailNetworkRuleNodeType;
178   }
179
180
181   private static Map<String, PropertyDefinition> createContrailNetworkRuleProperties() {
182     Map<String, PropertyDefinition> contrailNetworkRulePropertyDefMap = new HashMap<>();
183     contrailNetworkRulePropertyDefMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
184         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
185             "A symbolic name for this contrail network rule", false, null, null, null, null));
186     contrailNetworkRulePropertyDefMap.put("entries", DataModelUtil
187         .createPropertyDefinition(ToscaDataType.CONTRAIL_NETWORK_RULE_LIST.getDisplayName(),
188             "A symbolic name for this contrail network rule", false, null, null, null, null));
189
190     return contrailNetworkRulePropertyDefMap;
191   }
192
193
194   private static Map<String, AttributeDefinition> createContrailNetworkRuleAttributes() {
195     Map<String, AttributeDefinition> contrailNetworkRuleAttributesDefMap = new HashMap<>();
196     contrailNetworkRuleAttributesDefMap.put("fq_name", DataModelUtil
197         .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "fq_name", null, null,
198             null));
199     contrailNetworkRuleAttributesDefMap.put("tenant_id", DataModelUtil
200         .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "tenant_id", null, null,
201             null));
202     contrailNetworkRuleAttributesDefMap.put("rules", DataModelUtil
203         .createAttributeDefinition(PropertyType.LIST.getDisplayName(), "List of rules", null,
204             DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
205             null));
206     contrailNetworkRuleAttributesDefMap.put("show", DataModelUtil
207         .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes.", null,
208             null, null));
209
210     return contrailNetworkRuleAttributesDefMap;
211   }
212
213   private static List<Map<String, RequirementDefinition>> createContrailNetworkRuleRequirements() {
214     final List<Map<String, RequirementDefinition>> requirements = new ArrayList<>();
215     final Map<String, RequirementDefinition>
216             contrailNetworkRuleRequirementsDefMap = new HashMap<>();
217     RequirementDefinition req = new RequirementDefinition();
218     req.setCapability(ToscaCapabilityType.ATTACHMENT.getDisplayName());
219     req.setOccurrences(new Object[]{0, ToscaConstants.UNBOUNDED});
220     req.setNode(ToscaNodeType.NETWORK.getDisplayName());
221     req.setRelationship(ToscaRelationshipType.ATTACHES_TO.getDisplayName());
222     contrailNetworkRuleRequirementsDefMap.put("network", req);
223     requirements.add(contrailNetworkRuleRequirementsDefMap);
224
225     return requirements;
226   }
227 }