push addional code
[sdc.git] / openecomp-be / lib / openecomp-heat-lib / src / main / java / org / openecomp / sdc / heat / datatypes / model / HeatResourcesTypes.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.heat.datatypes.model;
22
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Objects;
28
29 /**
30  * The enum Heat resources types.
31  */
32 public enum HeatResourcesTypes {
33   /**
34    * Nova server resource type heat resources types.
35    */
36   NOVA_SERVER_RESOURCE_TYPE("OS::Nova::Server"),
37   /**
38    * Nova server group resource type heat resources types.
39    */
40   NOVA_SERVER_GROUP_RESOURCE_TYPE("OS::Nova::ServerGroup"),
41   /**
42    * Neutron port resource type heat resources types.
43    */
44   NEUTRON_PORT_RESOURCE_TYPE("OS::Neutron::Port"),
45   /**
46    * Contrail network rule resource type heat resources types.
47    */
48   CONTRAIL_NETWORK_RULE_RESOURCE_TYPE("OS::Contrail::NetworkPolicy"),
49   /**
50    * Contrail network attach rule resource type heat resources types.
51    */
52   CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE("OS::Contrail::AttachPolicy"),
53   /**
54    * Contrail virtual network resource type heat resources types.
55    */
56   CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::Contrail::VirtualNetwork"),
57   /**
58    * Cinder volume resource type heat resources types.
59    */
60   CINDER_VOLUME_RESOURCE_TYPE("OS::Cinder::Volume"),
61   /**
62    * Cinder volume attachment resource type heat resources types.
63    */
64   CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE("OS::Cinder::VolumeAttachment"),
65   /**
66    * Neutron net resource type heat resources types.
67    */
68   NEUTRON_NET_RESOURCE_TYPE("OS::Neutron::Net"),
69   /**
70    * Neutron subnet resource type heat resources types.
71    */
72   NEUTRON_SUBNET_RESOURCE_TYPE("OS::Neutron::Subnet"),
73   /**
74    * Neutron security group resource type heat resources types.
75    */
76   NEUTRON_SECURITY_GROUP_RESOURCE_TYPE("OS::Neutron::SecurityGroup"),
77   /**
78    * Heat software config type heat resources types.
79    */
80   HEAT_SOFTWARE_CONFIG_TYPE("OS::Heat::SoftwareConfig"),
81   /**
82    * Heat cloud config type heat resources types.
83    */
84   HEAT_CLOUD_CONFIG_TYPE("OS::Heat::CloudConfig"),
85   /**
86    * Heat multipart mime type heat resources types.
87    */
88   HEAT_MULTIPART_MIME_TYPE("OS::Heat::MultipartMime"),
89   /**
90    * Heat contrail network ipam type heat resources types.
91    */
92   HEAT_CONTRAIL_NETWORK_IPAM_TYPE("OS::Contrail::NetworkIpam"),
93   /**
94    * Contrail v 2 virtual network resource type heat resources types.
95    */
96   CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::ContrailV2::VirtualNetwork"),
97   /**
98    * Contrail v 2 virtual machine interface resource type heat resources types.
99    */
100   CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE("OS::ContrailV2::VirtualMachineInterface"),
101   /**
102    * Contrail service template heat resources types.
103    */
104   CONTRAIL_SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"),
105   /**
106    * Contrail service instance heat resources types.
107    */
108   CONTRAIL_SERVICE_INSTANCE("OS::Contrail::ServiceInstance"),
109   /**
110    * Contrail v 2 network rule resource type heat resources types.
111    */
112   CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE("OS::ContrailV2::NetworkPolicy"),
113   /**
114    * Resource group resource type heat resources types.
115    */
116   RESOURCE_GROUP_RESOURCE_TYPE("OS::Heat::ResourceGroup");
117
118   private static Map<String, HeatResourcesTypes> stringToHeatResourceTypeMap;
119
120   static {
121     stringToHeatResourceTypeMap = new HashMap<>();
122
123     for (HeatResourcesTypes type : HeatResourcesTypes.values()) {
124       stringToHeatResourceTypeMap.put(type.heatResource, type);
125     }
126   }
127
128   private String heatResource;
129
130
131   HeatResourcesTypes(String heatResource) {
132     this.heatResource = heatResource;
133   }
134
135   /**
136    * Find by heat resource heat resources types.
137    *
138    * @param heatResource the heat resource
139    * @return the heat resources types
140    */
141   public static HeatResourcesTypes findByHeatResource(String heatResource) {
142     return stringToHeatResourceTypeMap.get(heatResource);
143   }
144
145   /**
146    * Is resource type valid boolean.
147    *
148    * @param resourceType the resource type
149    * @return the boolean
150    */
151   public static boolean isResourceTypeValid(String resourceType) {
152     return Objects.nonNull(findByHeatResource(resourceType));
153   }
154
155   /**
156    * Is resource expected to be exposed boolean.
157    *
158    * @param resourceType the resource type
159    * @return the boolean
160    */
161   public static boolean isResourceExpectedToBeExposed(String resourceType) {
162     return (resourceType.equals(NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())
163         || resourceType.equals(CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource())
164         || resourceType.equals(NEUTRON_NET_RESOURCE_TYPE.getHeatResource())
165         || resourceType.equals(CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
166         || resourceType.equals(NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource())
167       );
168   }
169
170   /**
171    * Gets list for resource type.
172    *
173    * @param types the types
174    * @return the list for resource type
175    */
176   public static Map<HeatResourcesTypes, List<String>> getListForResourceType(
177       HeatResourcesTypes... types) {
178     Map<HeatResourcesTypes, List<String>> result = new HashMap<>();
179
180     for (HeatResourcesTypes type : types) {
181       result.put(type, new ArrayList<>());
182     }
183
184     return result;
185   }
186
187   /**
188    * Gets heat resource.
189    *
190    * @return the heat resource
191    */
192   public String getHeatResource() {
193
194     return heatResource;
195   }
196
197   /**
198    * Sets heat resource.
199    *
200    * @param heatResource the heat resource
201    */
202   public void setHeatResource(String heatResource) {
203     this.heatResource = heatResource;
204   }
205
206 }