push addional code
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / services / heattotosca / globaltypes / ContrailAbstractSubstituteGlobalType.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.ToscaDataType;
24 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
25 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
26 import org.openecomp.sdc.tosca.datatypes.model.DataType;
27 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
28 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
29 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
30 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
31 import org.openecomp.sdc.tosca.services.DataModelUtil;
32 import org.openecomp.sdc.tosca.services.ToscaConstants;
33 import org.openecomp.sdc.translator.services.heattotosca.Constants;
34
35 import java.util.HashMap;
36 import java.util.Map;
37
38
39 public class ContrailAbstractSubstituteGlobalType {
40
41   /**
42    * Create service template service template.
43    *
44    * @return the service template
45    */
46   public static ServiceTemplate createServiceTemplate() {
47     ServiceTemplate serviceTemplate = new ServiceTemplate();
48     serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
49     serviceTemplate.setMetadata(
50         DataModelUtil.createMetadata(Constants
51                 .CONTRAIL_ABSTRACT_SUBSTITUTE_TEMPLATE_NAME, "1.0.0", null));
52     serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
53     serviceTemplate.setDescription("Contrail Abstract Substitute Global Types");
54     serviceTemplate.setData_types(createGlobalDataTypes());
55     serviceTemplate.setNode_types(createGlobalNodeTypes());
56     return serviceTemplate;
57   }
58
59   private static Map<String, NodeType> createGlobalNodeTypes() {
60     Map<String, NodeType> globalNodeTypes = new HashMap<>();
61     globalNodeTypes.put(ToscaNodeType.CONTRAIL_ABSTRACT_SUBSTITUTE.getDisplayName(),
62         createContrailAbstractSubstituteNodeType());
63     return globalNodeTypes;
64   }
65
66   private static NodeType createContrailAbstractSubstituteNodeType() {
67     NodeType nodeType = new NodeType();
68     nodeType.setDerived_from(ToscaNodeType.ABSTRACT_SUBSTITUTE.getDisplayName());
69     nodeType.setProperties(createContrailAbstractSubstituteProperties());
70     nodeType.setAttributes(createContrailAbstractSubstituteAttributes());
71
72     return nodeType;
73   }
74
75   private static Map<String, AttributeDefinition> createContrailAbstractSubstituteAttributes() {
76     Map<String, AttributeDefinition> attributesDefMap = new HashMap<>();
77     attributesDefMap.put("service_instance_name", DataModelUtil
78         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
79             "The name of the service instance", null, null, null));
80     attributesDefMap.put("fq_name", DataModelUtil
81         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
82             "The FQ name of the service instance", null, null, null));
83     attributesDefMap.put("status", DataModelUtil
84         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
85             "Status of the service instance", null, null, null));
86     attributesDefMap.put("service_template_name", DataModelUtil
87         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
88             "Service Template of the Service Instance", null, null, null));
89     attributesDefMap.put("virtual_machines", DataModelUtil
90         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
91             "Service VMs for the Service Instance", null, null, null));
92     attributesDefMap.put("active_vms", DataModelUtil
93         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
94             "Number of service VMs active for this Service Instance", null, null, null));
95     attributesDefMap.put("tenant_id", DataModelUtil
96         .createAttributeDefinition(PropertyType.STRING.getDisplayName(),
97             "Tenant id of the Service Instance", null, null, null));
98     attributesDefMap.put("show", DataModelUtil
99         .createAttributeDefinition(PropertyType.STRING.getDisplayName(), "All attributes", null,
100             null, null));
101
102     return attributesDefMap;
103   }
104
105   private static Map<String, PropertyDefinition> createContrailAbstractSubstituteProperties() {
106     Map<String, PropertyDefinition> props = new HashMap<>();
107     props.put("service_template_name", DataModelUtil
108         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service template name",
109             false, null, null, null, null));
110     props.put("service_mode", DataModelUtil
111         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service mode", true,
112             DataModelUtil
113                 .createValidValuesConstraintsList("transparent", "in-network", "in-network-nat"),
114             null, null, null));
115     props.put("service_type", DataModelUtil
116         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service type", true,
117             DataModelUtil.createValidValuesConstraintsList("firewall", "analyzer", "source-nat",
118                 "loadbalancer"), null, null, null));
119     props.put("image_name", DataModelUtil
120         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Image name", true, null,
121             null, null, null));
122     props.put("flavor", DataModelUtil
123         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "flavor", false, null, null,
124             null, null));
125     props.put("service_interface_type_list", DataModelUtil
126         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of interface types",
127             true, null, null, DataModelUtil
128                 .createEntrySchema(PropertyType.STRING.getDisplayName(), null, DataModelUtil
129                     .createValidValuesConstraintsList("management", "left", "right", "other")),
130             null));
131     props.put("shared_ip_list", DataModelUtil
132         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Shared ips enabled", false,
133             null, null,
134             DataModelUtil.createEntrySchema(PropertyType.BOOLEAN.getDisplayName(), null, null),
135             null));
136     props.put("static_routes_list", DataModelUtil
137         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "Static routes enabled",
138             false, null, null,
139             DataModelUtil.createEntrySchema(PropertyType.BOOLEAN.getDisplayName(), null, null),
140             null));
141     props.put("ordered_interfaces", DataModelUtil
142         .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
143             "Indicates if service interface are ordered", false, null, null, null, false));
144     props.put("availability_zone_enable", DataModelUtil
145         .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
146             "Indicates availability zone is enabled", false, null, null, null, false));
147     props.put("availability_zone", DataModelUtil
148         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
149             "Availability zone to create servers in", false, null, null, null, null));
150     props.put("service_instance_name", DataModelUtil
151         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Service instance name",
152             true, null, null, null, null));
153     props.put("interface_list", DataModelUtil
154         .createPropertyDefinition(PropertyType.LIST.getDisplayName(), "List of interfaces", false,
155             null, null, DataModelUtil
156                 .createEntrySchema(ToscaDataType.CONTRAIL_INTERFACE_DATA.getDisplayName(), null,
157                     null), null));
158     return props;
159   }
160
161
162   private static Map<String, DataType> createGlobalDataTypes() {
163     Map<String, DataType> globalDataTypes = new HashMap<>();
164     globalDataTypes
165         .put(ToscaDataType.CONTRAIL_INTERFACE_DATA.getDisplayName(), createInterfaceDataType());
166     return globalDataTypes;
167   }
168
169   private static DataType createInterfaceDataType() {
170     DataType dataType = new DataType();
171     dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
172     dataType.setDescription("Interface Data");
173     Map<String, PropertyDefinition> propertyDefMap = new HashMap<>();
174     propertyDefMap.put("virtual_network", DataModelUtil
175         .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
176             "Virtual Network for this interface", true, null, null, null, null));
177     propertyDefMap.put("ip_address", DataModelUtil
178         .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "IP for this interface",
179             false, null, null, null, null));
180     propertyDefMap.put("static_routes", DataModelUtil
181         .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
182             "An ordered list of static routes to be added to this interface", false, null, null,
183             DataModelUtil
184                 .createEntrySchema(ToscaDataType.CONTRAIL_STATIC_ROUTE.getDisplayName(), null,
185                     null), null));
186     propertyDefMap.put("allowed_address_pairs", DataModelUtil
187         .createPropertyDefinition(PropertyType.LIST.getDisplayName(),
188             "List of allowed address pair for this interface", false, null, null, DataModelUtil
189                 .createEntrySchema(ToscaDataType.CONTRAIL_ADDRESS_PAIR.getDisplayName(), null,
190                     null), null));
191     dataType.setProperties(propertyDefMap);
192     return dataType;
193   }
194
195
196 }