[SDC-29] Amdocs OnBoard 1707 initial commit.
[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 public enum HeatResourcesTypes {
30   NOVA_SERVER_RESOURCE_TYPE("OS::Nova::Server"),
31   NOVA_SERVER_GROUP_RESOURCE_TYPE("OS::Nova::ServerGroup"),
32   NEUTRON_PORT_RESOURCE_TYPE("OS::Neutron::Port"),
33   CONTRAIL_NETWORK_RULE_RESOURCE_TYPE("OS::Contrail::NetworkPolicy"),
34   CONTRAIL_NETWORK_ATTACH_RULE_RESOURCE_TYPE("OS::Contrail::AttachPolicy"),
35   CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::Contrail::VirtualNetwork"),
36   CINDER_VOLUME_RESOURCE_TYPE("OS::Cinder::Volume"),
37   CINDER_VOLUME_ATTACHMENT_RESOURCE_TYPE("OS::Cinder::VolumeAttachment"),
38   NEUTRON_NET_RESOURCE_TYPE("OS::Neutron::Net"),
39   NEUTRON_SUBNET_RESOURCE_TYPE("OS::Neutron::Subnet"),
40   NEUTRON_SECURITY_GROUP_RESOURCE_TYPE("OS::Neutron::SecurityGroup"),
41   HEAT_SOFTWARE_CONFIG_TYPE("OS::Heat::SoftwareConfig"),
42   HEAT_CLOUD_CONFIG_TYPE("OS::Heat::CloudConfig"),
43   HEAT_MULTIPART_MIME_TYPE("OS::Heat::MultipartMime"),
44   HEAT_CONTRAIL_NETWORK_IPAM_TYPE("OS::Contrail::NetworkIpam"),
45   CONTRAIL_V2_VIRTUAL_NETWORK_RESOURCE_TYPE("OS::ContrailV2::VirtualNetwork"),
46   CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE("OS::ContrailV2::VirtualMachineInterface"),
47   CONTRAIL_SERVICE_TEMPLATE("OS::Contrail::ServiceTemplate"),
48   CONTRAIL_SERVICE_INSTANCE("OS::Contrail::ServiceInstance"),
49   CONTRAIL_V2_NETWORK_RULE_RESOURCE_TYPE("OS::ContrailV2::NetworkPolicy"),
50   RESOURCE_GROUP_RESOURCE_TYPE("OS::Heat::ResourceGroup");
51
52   private static Map<String, HeatResourcesTypes> stringToHeatResourceTypeMap;
53
54   static {
55     stringToHeatResourceTypeMap = new HashMap<>();
56
57     for (HeatResourcesTypes type : HeatResourcesTypes.values()) {
58       stringToHeatResourceTypeMap.put(type.heatResource, type);
59     }
60   }
61
62   private String heatResource;
63
64
65   HeatResourcesTypes(String heatResource) {
66     this.heatResource = heatResource;
67   }
68
69   public static HeatResourcesTypes findByHeatResource(String heatResource) {
70     return stringToHeatResourceTypeMap.get(heatResource);
71   }
72
73   public static boolean isResourceTypeValid(String resourceType) {
74     return Objects.nonNull(findByHeatResource(resourceType));
75   }
76
77   /**
78    * Is resource expected to be exposed boolean.
79    *
80    * @param resourceType the resource type
81    * @return the boolean
82    */
83   public static boolean isResourceExpectedToBeExposed(String resourceType) {
84     //todo - check
85     return (resourceType.equals(NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())
86         || resourceType.equals(CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource())
87         || resourceType.equals(NEUTRON_NET_RESOURCE_TYPE.getHeatResource())
88         || resourceType.equals(CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
89         || resourceType.equals(NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource())
90       );
91   }
92
93   /**
94    * Gets list for resource type.
95    *
96    * @param types the types
97    * @return the list for resource type
98    */
99   public static Map<HeatResourcesTypes, List<String>> getListForResourceType(
100       HeatResourcesTypes... types) {
101     Map<HeatResourcesTypes, List<String>> result = new HashMap<>();
102
103     for (HeatResourcesTypes type : types) {
104       result.put(type, new ArrayList<>());
105     }
106
107     return result;
108   }
109
110   public String getHeatResource() {
111
112     return heatResource;
113   }
114
115   public void setHeatResource(String heatResource) {
116     this.heatResource = heatResource;
117   }
118
119 }