a9598eb67f43539c3ebceb3bf89482dd8e42c938
[sdc.git] /
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     private String heatResource;
54
55     static {
56         stringToHeatResourceTypeMap = new HashMap<>();
57
58         for (HeatResourcesTypes type : HeatResourcesTypes.values()) {
59             stringToHeatResourceTypeMap.put(type.heatResource, type);
60         }
61     }
62
63     HeatResourcesTypes(String heatResource) {
64         this.heatResource = heatResource;
65     }
66
67     public static HeatResourcesTypes findByHeatResource(String heatResource) {
68         return stringToHeatResourceTypeMap.get(heatResource);
69     }
70
71     public static boolean isResourceTypeValid(String resourceType) {
72         return Objects.nonNull(findByHeatResource(resourceType));
73     }
74
75     /**
76      * Is resource expected to be exposed boolean.
77      *
78      * @param resourceType the resource type
79      * @return the boolean
80      */
81     public static boolean isResourceExpectedToBeExposed(String resourceType) {
82         //todo - check
83         return (resourceType.equals(NOVA_SERVER_GROUP_RESOURCE_TYPE.getHeatResource())
84                 || resourceType.equals(CONTRAIL_VIRTUAL_NETWORK_RESOURCE_TYPE.getHeatResource())
85                 || resourceType.equals(NEUTRON_NET_RESOURCE_TYPE.getHeatResource())
86                 || resourceType.equals(CINDER_VOLUME_RESOURCE_TYPE.getHeatResource())
87                 || resourceType.equals(NEUTRON_SECURITY_GROUP_RESOURCE_TYPE.getHeatResource())
88         );
89     }
90
91     /**
92      * Gets list for resource type.
93      *
94      * @param types the types
95      * @return the list for resource type
96      */
97     public static Map<HeatResourcesTypes, List<String>> getListForResourceType(
98             HeatResourcesTypes... types) {
99         Map<HeatResourcesTypes, List<String>> result = new HashMap<>();
100
101         for (HeatResourcesTypes type : types) {
102             result.put(type, new ArrayList<>());
103         }
104
105         return result;
106     }
107
108     public String getHeatResource() {
109         return heatResource;
110     }
111 }