2 * ============LICENSE_START=======================================================
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
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.openecomp.sdc.translator.services.heattotosca.globaltypes;
24 import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
25 import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
26 import org.openecomp.sdc.tosca.datatypes.ToscaGroupType;
27 import org.openecomp.sdc.tosca.datatypes.ToscaPolicyType;
28 import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
29 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
30 import org.openecomp.sdc.tosca.datatypes.model.CapabilityType;
31 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
32 import org.openecomp.sdc.tosca.datatypes.model.DataType;
33 import org.openecomp.sdc.tosca.datatypes.model.GroupType;
34 import org.openecomp.sdc.tosca.datatypes.model.Import;
35 import org.openecomp.sdc.tosca.datatypes.model.PolicyType;
36 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
37 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
38 import org.openecomp.sdc.tosca.datatypes.model.RelationshipType;
39 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
40 import org.openecomp.sdc.tosca.services.DataModelUtil;
41 import org.openecomp.sdc.tosca.services.ToscaConstants;
42 import org.openecomp.sdc.tosca.services.ToscaUtil;
43 import org.openecomp.sdc.translator.services.heattotosca.Constants;
45 import java.util.ArrayList;
46 import java.util.HashMap;
47 import java.util.List;
50 public class CommonGlobalTypes {
53 * Create service template service template.
55 * @return the service template
57 public static ServiceTemplate createServiceTemplate() {
58 ServiceTemplate serviceTemplate = new ServiceTemplate();
59 serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
60 serviceTemplate.setMetadata(
61 DataModelUtil.createMetadata(Constants.COMMON_GLOBAL_TEMPLATE_NAME, "1.0.0", null));
62 serviceTemplate.setDescription("TOSCA Global Types");
63 serviceTemplate.setData_types(createGlobalDataTypes());
64 serviceTemplate.setGroup_types(createGroupTypes());
65 serviceTemplate.setPolicy_types(createPolicyTypes());
66 serviceTemplate.setRelationship_types(createRelationTypes());
67 serviceTemplate.setCapability_types(createCapabilityTypes());
68 serviceTemplate.setImports(createImportList());
69 return serviceTemplate;
72 private static Map<String, CapabilityType> createCapabilityTypes() {
73 Map<String, CapabilityType> capabilityMap = new HashMap<>();
74 capabilityMap.put(ToscaCapabilityType.METRIC.getDisplayName(), createMetricCapabilityType());
76 .put(ToscaCapabilityType.METRIC_CEILOMETER.getDisplayName(), createMetricCeilometerType());
77 capabilityMap.put(ToscaCapabilityType.METRIC_SNMP_TRAP.getDisplayName(), createMetricSnmpType(
78 "A node type that includes the Metric capability"
79 + " indicates that it can be monitored using snmp trap."));
80 capabilityMap.put(ToscaCapabilityType.METRIC_SNMP_POLLING.getDisplayName(),
82 "A node type that includes the Metric capability indicates"
83 + " that it can be monitored using snmp polling."));
88 private static CapabilityType createMetricSnmpType(String description) {
89 CapabilityType capabilityType = new CapabilityType();
90 capabilityType.setDerived_from(ToscaCapabilityType.METRIC.getDisplayName());
91 capabilityType.setDescription(description);
92 capabilityType.setProperties(createCapabilityMetricSnmpProperties());
94 return capabilityType;
98 private static Map<String, PropertyDefinition> createCapabilityMetricSnmpProperties() {
99 Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
100 propertyDefinitionMap.put("oid", DataModelUtil
101 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Object Id of the metric",
102 true, null, null, null, null));
103 return propertyDefinitionMap;
106 private static CapabilityType createMetricCeilometerType() {
107 CapabilityType capabilityType = new CapabilityType();
108 capabilityType.setDerived_from(ToscaCapabilityType.METRIC.getDisplayName());
109 capabilityType.setDescription(
110 "A node type that includes the Metric capability"
111 + " indicates that it can be monitored using ceilometer.");
112 capabilityType.setProperties(createCapabilityMetricCeilometerProperties());
113 return capabilityType;
117 private static Map<String, PropertyDefinition> createCapabilityMetricCeilometerProperties() {
118 Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
119 propertyDefinitionMap.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
120 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
121 "Ceilometer metric type name to monitor. (The name ceilometer is using)", true, null,
123 return propertyDefinitionMap;
126 private static Map<String, Import> createImportList() {
127 Map<String, Import> importsMap = new HashMap<>();
128 importsMap.put(ToscaConstants.NATIVE_TYPES_SERVICE_TEMPLATE_NAME, GlobalTypesUtil
129 .createServiceTemplateImport(ToscaConstants.NATIVE_TYPES_SERVICE_TEMPLATE_NAME));
134 * Create metric capability type capability type.
136 * @return the capability type
138 public static CapabilityType createMetricCapabilityType() {
139 CapabilityType capabilityType = new CapabilityType();
140 capabilityType.setDerived_from(ToscaCapabilityType.NFV_METRIC.getDisplayName());
141 capabilityType.setDescription(
142 "A node type that includes the Metric capability indicates that it can be monitored.");
143 capabilityType.setProperties(createCapabilityMetricProperties());
144 capabilityType.setAttributes(createCapabilityMetricAttributes());
145 return capabilityType;
148 private static Map<String, AttributeDefinition> createCapabilityMetricAttributes() {
149 Map<String, AttributeDefinition> attributeDefinitionMap = new HashMap<>();
151 attributeDefinitionMap.put("value", DataModelUtil
152 .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "Runtime monitored value",
154 return attributeDefinitionMap;
157 private static Map<String, PropertyDefinition> createCapabilityMetricProperties() {
158 Map<String, PropertyDefinition> propertyDefinitionMap = new HashMap<>();
159 propertyDefinitionMap.put("type", DataModelUtil
160 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
161 "Type of the metric value, for an example, Cumulative, Delta, Gauge and etc.", true,
162 null, null, null, null));
163 propertyDefinitionMap.put("unit", DataModelUtil
164 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Unit of the metric value",
165 true, null, null, null, null));
166 propertyDefinitionMap.put("category", DataModelUtil
167 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
168 "Category of the metric, for an example, compute, disk, network, storage and etc.",
169 false, null, null, null, null));
170 propertyDefinitionMap.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
171 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Description of the metric",
172 false, null, null, null, null));
173 return propertyDefinitionMap;
176 private static Map<String, RelationshipType> createRelationTypes() {
177 Map<String, RelationshipType> globalRelationshipTypes = new HashMap<>();
178 globalRelationshipTypes.put(ToscaRelationshipType.ATTACHES_TO.getDisplayName(),
179 createAttachesToRelationshipType());
180 return globalRelationshipTypes;
183 private static RelationshipType createAttachesToRelationshipType() {
184 RelationshipType attachesToRelationType = new RelationshipType();
185 attachesToRelationType.setDerived_from(ToscaRelationshipType.ROOT.getDisplayName());
186 attachesToRelationType.setDescription("This type represents an attachment relationship");
187 return attachesToRelationType;
190 private static Map<String, PolicyType> createPolicyTypes() {
191 Map<String, PolicyType> globalPolicyTypes = new HashMap<>();
193 .put(ToscaPolicyType.PLACEMENT_ANTILOCATE.getDisplayName(), createAntilocatePolicyType());
195 .put(ToscaPolicyType.PLACEMENT_COLOCATE.getDisplayName(), createColocatePolicyType());
196 globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_AFFINITY.getDisplayName(),
197 createValetAffinityPolicyType());
198 globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_DIVERSITY.getDisplayName(),
199 createValetDiversityPolicyType());
200 globalPolicyTypes.put(ToscaPolicyType.PLACEMENT_VALET_EXCLUSIVITY.getDisplayName(),
201 createValetExclusivityPolicyType());
202 return globalPolicyTypes;
205 private static PolicyType createValetDiversityPolicyType() {
206 PolicyType policyType = new PolicyType();
207 policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
208 policyType.setDescription("Valet Diversity");
209 policyType.setProperties(new HashMap<>());
210 policyType.getProperties().put("level", DataModelUtil
211 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "diversity", false,
212 DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
217 private static PolicyType createValetExclusivityPolicyType() {
218 PolicyType policyType = new PolicyType();
219 policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
220 policyType.setDescription("Valet Exclusivity");
221 policyType.setProperties(addNamePropertyToPolicyType());
222 policyType.setProperties(new HashMap<>());
223 policyType.getProperties().put("level", DataModelUtil
224 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "exclusivity", false,
225 DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
229 private static PolicyType createValetAffinityPolicyType() {
230 PolicyType policyType = new PolicyType();
231 policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
232 policyType.setDescription("Valet Affinity");
233 policyType.setProperties(new HashMap<>());
234 policyType.getProperties().put("level", DataModelUtil
235 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "affinity", false,
236 DataModelUtil.createValidValuesConstraintsList("host", "rack"), null, null, "host"));
242 private static PolicyType createColocatePolicyType() {
243 PolicyType policyType = new PolicyType();
244 policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
245 policyType.setDescription("Keep associated nodes (groups of nodes) based upon affinity value");
246 policyType.setProperties(addNamePropertyToPolicyType());
247 policyType.getProperties().put("affinity", DataModelUtil
248 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "affinity", true,
249 DataModelUtil.createValidValuesConstraintsList("host", "region", "compute"), null, null,
255 private static PolicyType createAntilocatePolicyType() {
256 PolicyType policyType = new PolicyType();
257 policyType.setDerived_from(ToscaPolicyType.PLACEMENT.getDisplayName());
258 policyType.setDescription("My placement policy for separation based upon container type value");
259 policyType.setProperties(addNamePropertyToPolicyType());
260 policyType.getProperties().put("container_type", DataModelUtil
261 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "container type", false,
262 DataModelUtil.createValidValuesConstraintsList("host", "region", "compute"), null, null,
267 private static Map<String, PropertyDefinition> addNamePropertyToPolicyType() {
268 Map<String, PropertyDefinition> policyTypeProperties = new HashMap<>();
269 policyTypeProperties.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
270 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The name of the policy",
271 false, null, null, null, null));
272 return policyTypeProperties;
275 private static Map<String, GroupType> createGroupTypes() {
276 Map<String, GroupType> globalGroupTypes = new HashMap<>();
277 globalGroupTypes.put(ToscaGroupType.HEAT_STACK.getDisplayName(), createHeatStackGroupType());
278 return globalGroupTypes;
281 private static GroupType createHeatStackGroupType() {
282 GroupType heatStackGroupType = new GroupType();
283 heatStackGroupType.setDerived_from(ToscaGroupType.ROOT.getDisplayName());
285 .setDescription("Grouped all heat resources which are in the same heat stack");
286 heatStackGroupType.setProperties(createHeatStackGroupProperties());
288 return heatStackGroupType;
291 private static Map<String, PropertyDefinition> createHeatStackGroupProperties() {
292 Map<String, PropertyDefinition> propertiesDef = new HashMap<>();
293 propertiesDef.put("heat_file", DataModelUtil
294 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
295 "Heat file which associate to this group/heat stack", true, null, null, null, null));
296 propertiesDef.put(Constants.DESCRIPTION_PROPERTY_NAME, DataModelUtil
297 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Heat file description",
298 false, null, null, null, null));
299 return propertiesDef;
304 * Create common service template import import.
308 public static Import createCommonServiceTemplateImport() {
309 Import commonServiceTemplateImport = new Import();
310 commonServiceTemplateImport
311 .setFile(ToscaUtil.getServiceTemplateFileName(Constants.COMMON_GLOBAL_TEMPLATE_NAME));
312 return commonServiceTemplateImport;
315 private static Map<String, DataType> createGlobalDataTypes() {
316 Map<String, DataType> globalDataTypes = new HashMap<>();
317 globalDataTypes.put(ToscaDataType.NETWORK_ALLOCATION_POOL.getDisplayName(),
318 createAllocationPoolDataType());
320 .put(ToscaDataType.NETWORK_HOST_ROUTE.getDisplayName(), createHostRouteDataType());
321 globalDataTypes.put(ToscaDataType.NEUTRON_SUBNET.getDisplayName(), createSubnetDataType());
323 .put(ToscaDataType.NETWORK_ADDRESS_PAIR.getDisplayName(), createAddressPairDataType());
324 globalDataTypes.put(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(),
325 createContrailStaticRouteDataType());
326 globalDataTypes.put(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(),
327 createContrailAddressPairDataType());
328 return globalDataTypes;
331 private static DataType createContrailStaticRouteDataType() {
332 DataType dataType = new DataType();
333 dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
334 dataType.setDescription("static route");
335 Map<String, PropertyDefinition> prop = new HashMap<>();
337 prop.put("prefix", DataModelUtil
338 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Route prefix", false, null,
340 prop.put("next_hop", DataModelUtil
341 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Next hop", false, null,
343 prop.put("next_hop_type", DataModelUtil
344 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Next hop type", false,
345 null, null, null, null));
347 dataType.setProperties(prop);
351 private static DataType createContrailAddressPairDataType() {
352 DataType dataType = new DataType();
353 dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
354 dataType.setDescription("Address Pair");
355 Map<String, PropertyDefinition> prop = new HashMap<>();
357 prop.put("prefix", DataModelUtil
358 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP address prefix", false,
359 null, null, null, null));
360 prop.put("mac_address", DataModelUtil
361 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Mac address", false, null,
363 prop.put("address_mode", DataModelUtil
364 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
365 "Address mode active-active or active-standy", false,
366 DataModelUtil.createValidValuesConstraintsList("active-active", "active-standby"), null,
369 dataType.setProperties(prop);
373 private static DataType createAddressPairDataType() {
374 DataType addressPairDataType = new DataType();
375 addressPairDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
376 addressPairDataType.setDescription("MAC/IP address pairs");
377 Map<String, PropertyDefinition> addressPairProp = new HashMap<>();
379 addressPairProp.put("ip_address", DataModelUtil
380 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP address", false, null,
382 addressPairProp.put("mac_address", DataModelUtil
383 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "MAC address", false, null,
385 addressPairDataType.setProperties(addressPairProp);
387 return addressPairDataType;
390 private static DataType createHostRouteDataType() {
391 DataType hostRouteDataType = new DataType();
392 hostRouteDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
393 hostRouteDataType.setDescription("Host route info for the subnet");
395 Map<String, PropertyDefinition> hostRoutePoolProp = new HashMap<>();
396 hostRoutePoolProp.put("destination", DataModelUtil
397 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
398 "The destination for static route", false, null, null, null, null));
399 hostRoutePoolProp.put("nexthop", DataModelUtil
400 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
401 "The next hop for the destination", false, null, null, null, null));
402 hostRouteDataType.setProperties(hostRoutePoolProp);
404 return hostRouteDataType;
407 private static DataType createAllocationPoolDataType() {
408 DataType allocationPoolDataType = new DataType();
409 allocationPoolDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
410 allocationPoolDataType.setDescription("The start and end addresses for the allocation pool");
412 Map<String, PropertyDefinition> allocationPoolProp = new HashMap<>();
413 allocationPoolProp.put("start", DataModelUtil
414 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
415 "Start address for the allocation pool", false, null, null, null, null));
416 allocationPoolProp.put("end", DataModelUtil
417 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
418 "End address for the allocation pool", false, null, null, null, null));
419 allocationPoolDataType.setProperties(allocationPoolProp);
421 return allocationPoolDataType;
424 private static DataType createSubnetDataType() {
425 DataType subnetDataType = new DataType();
426 subnetDataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
427 subnetDataType.setDescription(
428 "A subnet represents an IP address block that can "
429 + "be used for assigning IP addresses to virtual instances");
431 Map<String, PropertyDefinition> subnetProp = new HashMap<>();
432 subnetProp.put("allocation_pools", DataModelUtil
433 .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
434 "The start and end addresses for the allocation pools", false, null, null, DataModelUtil
435 .createEntrySchema(ToscaDataType.NETWORK_ALLOCATION_POOL.getDisplayName(), null,
437 subnetProp.put("cidr", DataModelUtil
438 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The CIDR", false, null,
440 subnetProp.put("dns_nameservers", DataModelUtil
441 .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
442 "A specified set of DNS name servers to be used", false, null, null,
443 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
444 new ArrayList<String>()));
445 subnetProp.put("enable_dhcp", DataModelUtil
446 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
447 "Set to true if DHCP is enabled and false if DHCP is disabled", false, null, null, null,
449 subnetProp.put("gateway_ip", DataModelUtil
450 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The gateway IP address",
451 false, null, null, null, null));
452 subnetProp.put("host_routes", DataModelUtil
453 .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "The gateway IP address",
454 false, null, null, DataModelUtil
455 .createEntrySchema(ToscaDataType.NETWORK_HOST_ROUTE.getDisplayName(), null, null),
457 subnetProp.put("ip_version", DataModelUtil
458 .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(), "The gateway IP address",
459 false, DataModelUtil.createValidValuesConstraintsList("4", "6"), null, null, 4));
460 subnetProp.put("ipv6_address_mode", DataModelUtil
461 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IPv6 address mode", false,
463 .createValidValuesConstraintsList("dhcpv6-stateful", "dhcpv6-stateless", "slaac"),
465 subnetProp.put("ipv6_ra_mode", DataModelUtil
466 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
467 "IPv6 RA (Router Advertisement) mode", false, DataModelUtil
468 .createValidValuesConstraintsList("dhcpv6-stateful", "dhcpv6-stateless", "slaac"),
470 subnetProp.put(Constants.NAME_PROPERTY_NAME, DataModelUtil
471 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "The name of the subnet",
472 false, null, null, null, null));
473 subnetProp.put("prefixlen", DataModelUtil
474 .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
475 "Prefix length for subnet allocation from subnet pool", false,
476 createPrefixlenConstraint(), null, null, null));
477 subnetProp.put("subnetpool", DataModelUtil
478 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
479 "The name or ID of the subnet pool", false, null, null, null, null));
480 subnetProp.put("tenant_id", DataModelUtil
481 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
482 "The ID of the tenant who owns the network", false, null, null, null, null));
483 subnetProp.put("value_specs", DataModelUtil
484 .createPropertyDefinition(PropertyType.MAP.getDisplayName(),
485 "Extra parameters to include in the request", false, null, null,
486 DataModelUtil.createEntrySchema(PropertyType.STRING.getDisplayName(), null, null),
488 subnetDataType.setProperties(subnetProp);
490 return subnetDataType;
493 private static List<Constraint> createPrefixlenConstraint() {
494 List<Constraint> constraints = new ArrayList<>();
495 Constraint constraint = new Constraint();
496 constraint.setGreater_or_equal(0);
497 constraints.add(constraint);