Merge "Workflow Recipe Lookup"
[so.git] / common / src / main / java / org / onap / so / client / aai / AAIObjectType.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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.onap.so.client.aai;
22
23 import java.io.Serializable;
24 import java.net.URL;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.Set;
28 import java.util.regex.Pattern;
29
30 import org.onap.aai.annotations.Metadata;
31 import org.onap.aai.domain.yang.AggregateRoute;
32 import org.onap.aai.domain.yang.AllottedResource;
33 import org.onap.aai.domain.yang.CloudRegion;
34 import org.onap.aai.domain.yang.Collection;
35 import org.onap.aai.domain.yang.Complex;
36 import org.onap.aai.domain.yang.Configuration;
37 import org.onap.aai.domain.yang.Connector;
38 import org.onap.aai.domain.yang.Customer;
39 import org.onap.aai.domain.yang.Device;
40 import org.onap.aai.domain.yang.EsrSystemInfoList;
41 import org.onap.aai.domain.yang.EsrVnfm;
42 import org.onap.aai.domain.yang.EsrVnfmList;
43 import org.onap.aai.domain.yang.ExtAaiNetwork;
44 import org.onap.aai.domain.yang.Flavor;
45 import org.onap.aai.domain.yang.GenericVnf;
46 import org.onap.aai.domain.yang.Image;
47 import org.onap.aai.domain.yang.InstanceGroup;
48 import org.onap.aai.domain.yang.L3Network;
49 import org.onap.aai.domain.yang.LInterface;
50 import org.onap.aai.domain.yang.LineOfBusiness;
51 import org.onap.aai.domain.yang.ModelVer;
52 import org.onap.aai.domain.yang.NetworkPolicy;
53 import org.onap.aai.domain.yang.NetworkTechnology;
54 import org.onap.aai.domain.yang.OperationalEnvironment;
55 import org.onap.aai.domain.yang.OwningEntity;
56 import org.onap.aai.domain.yang.PInterface;
57 import org.onap.aai.domain.yang.PhysicalLink;
58 import org.onap.aai.domain.yang.Platform;
59 import org.onap.aai.domain.yang.Pnf;
60 import org.onap.aai.domain.yang.PortGroup;
61 import org.onap.aai.domain.yang.Project;
62 import org.onap.aai.domain.yang.Pserver;
63 import org.onap.aai.domain.yang.RouteTableReference;
64 import org.onap.aai.domain.yang.ServiceInstance;
65 import org.onap.aai.domain.yang.ServiceSubscription;
66 import org.onap.aai.domain.yang.SpPartner;
67 import org.onap.aai.domain.yang.SriovPf;
68 import org.onap.aai.domain.yang.Subnet;
69 import org.onap.aai.domain.yang.Tenant;
70 import org.onap.aai.domain.yang.TunnelXconnect;
71 import org.onap.aai.domain.yang.Vce;
72 import org.onap.aai.domain.yang.VfModule;
73 import org.onap.aai.domain.yang.VlanTag;
74 import org.onap.aai.domain.yang.Vnfc;
75 import org.onap.aai.domain.yang.VolumeGroup;
76 import org.onap.aai.domain.yang.VpnBinding;
77 import org.onap.aai.domain.yang.Vserver;
78 import org.onap.so.client.graphinventory.GraphInventoryObjectType;
79 import org.onap.so.constants.Defaults;
80 import org.reflections.Reflections;
81 import org.reflections.scanners.SubTypesScanner;
82 import org.reflections.util.ClasspathHelper;
83 import org.reflections.util.ConfigurationBuilder;
84
85 import com.google.common.base.CaseFormat;
86
87 public class AAIObjectType implements GraphInventoryObjectType, Serializable {
88
89         private static final long serialVersionUID = -2877184776691514600L;
90         private static Map<String, AAIObjectType> map = new HashMap<>();
91
92         public static final AAIObjectType DEFAULT_CLOUD_REGION = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/{cloud-region-id}", "default-cloud-region");
93         public static final AAIObjectType CUSTOMER = new AAIObjectType(AAINamespaceConstants.BUSINESS, Customer.class);
94         public static final AAIObjectType GENERIC_QUERY = new AAIObjectType("/search", "/generic-query", "generic-query");
95         public static final AAIObjectType BULK_PROCESS = new AAIObjectType("/bulkprocess", "", "bulkprocess");
96         public static final AAIObjectType SINGLE_TRANSACTION = new AAIObjectType("/bulk/single-transaction", "", "single-transaction");
97         public static final AAIObjectType GENERIC_VNF = new AAIObjectType(AAINamespaceConstants.NETWORK, GenericVnf.class);
98         public static final AAIObjectType GENERIC_VNFS = new AAIObjectType(AAINamespaceConstants.NETWORK, "/generic-vnfs", "generic-vnfs");
99         public static final AAIObjectType VF_MODULE = new AAIObjectType(AAIObjectType.GENERIC_VNF.uriTemplate(), VfModule.class);
100         public static final AAIObjectType L3_NETWORK = new AAIObjectType(AAINamespaceConstants.NETWORK, L3Network.class);
101         public static final AAIObjectType NETWORK_POLICY = new AAIObjectType(AAINamespaceConstants.NETWORK, NetworkPolicy.class);
102         public static final AAIObjectType NODES_QUERY = new AAIObjectType("/search", "/nodes-query", "nodes-query");
103         public static final AAIObjectType CUSTOM_QUERY = new AAIObjectType("/query", "", "query");
104         public static final AAIObjectType ROUTE_TABLE_REFERENCE = new AAIObjectType(AAINamespaceConstants.NETWORK, RouteTableReference.class);
105         public static final AAIObjectType DEFAULT_TENANT = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE + "/cloud-regions/cloud-region/" + Defaults.CLOUD_OWNER + "/AAIAIC25", "/tenants/tenant/{tenant-id}", "default-tenant");
106         public static final AAIObjectType VCE = new AAIObjectType(AAINamespaceConstants.NETWORK, Vce.class);
107         public static final AAIObjectType PORT_GROUP = new AAIObjectType(AAIObjectType.VCE.uriTemplate(), PortGroup.class);
108         public static final AAIObjectType VPN_BINDING = new AAIObjectType(AAINamespaceConstants.NETWORK, VpnBinding.class);
109         public static final AAIObjectType CONFIGURATION = new AAIObjectType(AAINamespaceConstants.NETWORK, Configuration.class);
110         public static final AAIObjectType PSERVER = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Pserver.class);
111         public static final AAIObjectType SERVICE_SUBSCRIPTION = new AAIObjectType(AAIObjectType.CUSTOMER.uriTemplate(), ServiceSubscription.class);
112         public static final AAIObjectType SERVICE_INSTANCE = new AAIObjectType(AAIObjectType.SERVICE_SUBSCRIPTION.uriTemplate(), ServiceInstance.class);
113         public static final AAIObjectType PROJECT = new AAIObjectType(AAINamespaceConstants.BUSINESS, Project.class);
114         public static final AAIObjectType LINE_OF_BUSINESS = new AAIObjectType(AAINamespaceConstants.BUSINESS, LineOfBusiness.class);
115         public static final AAIObjectType PLATFORM = new AAIObjectType(AAINamespaceConstants.BUSINESS, Platform.class);
116         public static final AAIObjectType OWNING_ENTITY = new AAIObjectType(AAINamespaceConstants.BUSINESS, OwningEntity.class);
117         public static final AAIObjectType ALLOTTED_RESOURCE = new AAIObjectType(AAIObjectType.SERVICE_INSTANCE.uriTemplate(), AllottedResource.class);
118         public static final AAIObjectType PNF = new AAIObjectType(AAINamespaceConstants.NETWORK, Pnf.class);
119         public static final AAIObjectType OPERATIONAL_ENVIRONMENT = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, OperationalEnvironment.class);
120         public static final AAIObjectType CLOUD_REGION = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, CloudRegion.class);
121         public static final AAIObjectType TENANT = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Tenant.class);
122         public static final AAIObjectType VOLUME_GROUP = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), VolumeGroup.class);
123         public static final AAIObjectType VSERVER = new AAIObjectType(AAIObjectType.TENANT.uriTemplate(), Vserver.class);
124         public static final AAIObjectType MODEL_VER = new AAIObjectType(AAINamespaceConstants.SERVICE_DESIGN_AND_CREATION + "/models/model/{model-invariant-id}", ModelVer.class);
125         public static final AAIObjectType TUNNEL_XCONNECT = new AAIObjectType(AAIObjectType.ALLOTTED_RESOURCE.uriTemplate(), TunnelXconnect.class);
126         public static final AAIObjectType P_INTERFACE = new AAIObjectType(AAIObjectType.PSERVER.uriTemplate(), PInterface.class);
127         public static final AAIObjectType SRIOV_PF = new AAIObjectType(AAIObjectType.P_INTERFACE.uriTemplate(), SriovPf.class); 
128         public static final AAIObjectType PHYSICAL_LINK = new AAIObjectType(AAINamespaceConstants.NETWORK, PhysicalLink.class);
129         public static final AAIObjectType INSTANCE_GROUP = new AAIObjectType(AAINamespaceConstants.NETWORK, InstanceGroup.class);
130         public static final AAIObjectType COLLECTION = new AAIObjectType(AAINamespaceConstants.NETWORK, Collection.class);
131         public static final AAIObjectType VNFC = new AAIObjectType(AAINamespaceConstants.NETWORK, Vnfc.class);
132         public static final AAIObjectType VLAN_TAG = new AAIObjectType(AAINamespaceConstants.NETWORK, VlanTag.class);
133         public static final AAIObjectType COMPLEX = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, Complex.class);
134         public static final AAIObjectType CONNECTOR = new AAIObjectType(AAINamespaceConstants.BUSINESS, Connector.class);
135         public static final AAIObjectType NETWORK_TECHNOLOGY = new AAIObjectType(AAINamespaceConstants.CLOUD_INFRASTRUCTURE, NetworkTechnology.class);
136         public static final AAIObjectType SUBNET = new AAIObjectType(AAIObjectType.L3_NETWORK.uriTemplate(), Subnet.class);
137         public static final AAIObjectType SP_PARTNER = new AAIObjectType(AAINamespaceConstants.BUSINESS, SpPartner.class);
138         public static final AAIObjectType DEVICE = new AAIObjectType(AAINamespaceConstants.NETWORK, Device.class);
139         public static final AAIObjectType EXT_AAI_NETWORK = new AAIObjectType(AAINamespaceConstants.NETWORK, ExtAaiNetwork.class);
140         public static final AAIObjectType AGGREGATE_ROUTE = new AAIObjectType(AAINamespaceConstants.NETWORK, AggregateRoute.class);
141         public static final AAIObjectType L_INTERFACE = new AAIObjectType(AAIObjectType.VSERVER.uriTemplate(), LInterface.class);
142         public static final AAIObjectType SUB_L_INTERFACE = new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), "/l-interfaces/l-interface/{sub-interface-name}", "sub-l-interface");
143         public static final AAIObjectType IMAGE = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Image.class);
144         public static final AAIObjectType FLAVOR = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Flavor.class);
145         public static final AAIObjectType UNKNOWN = new AAIObjectType("", "", "unknown");
146         public static final AAIObjectType DSL = new AAIObjectType("/dsl", "", "dsl");
147     public static final AAIObjectType VNFM = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list/esr-vnfm/{vnfm-id}", EsrVnfm.class);
148     public static final AAIObjectType VNFM_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM, "/esr-vnfm-list", "vnfm-list");
149     public static final AAIObjectType VNFM_ESR_SYSTEM_INFO_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list", "/esr-vnfm/{vnfm-id}/esr-system-info-list", "vnfm-esr-system-info-list");
150     public static final AAIObjectType CLOUD_ESR_SYSTEM_INFO_LIST = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), "/esr-system-info-list", "cloud-esr-system-info-list");
151
152
153         private final String uriTemplate;
154         private final String parentUri;
155         private final String partialUri;
156         private final Class<?> aaiObjectClass;
157         private final String name;
158         
159         static {
160                 /* Locate any AAIObjectTypes on the classpath and add them to our map */
161                 java.util.Collection<URL> packages = ClasspathHelper.forPackage("");
162                 Reflections r = new Reflections(new ConfigurationBuilder().setUrls(packages).setScanners(new SubTypesScanner()));
163                 
164                 Set<Class<? extends AAIObjectType>> resources =
165                             r.getSubTypesOf(AAIObjectType.class);
166                 try {
167                         for (Class<? extends AAIObjectType> customTypeClass : resources) {
168                                 AAIObjectType customType;
169                                 customType = customTypeClass.newInstance();
170                         }
171                 } catch (InstantiationException | IllegalAccessException e) {
172                 }
173         }
174         protected AAIObjectType() {
175                 this.parentUri = null;
176                 this.partialUri = null;
177                 this.uriTemplate = null;
178                 this.aaiObjectClass = null;
179                 this.name = null;
180         }
181         protected AAIObjectType(String parentUri, String partialUri, String name) {
182                 this.parentUri = parentUri;
183                 this.partialUri = partialUri;
184                 this.uriTemplate = parentUri + partialUri;
185                 this.aaiObjectClass = null;
186                 this.name = name;
187                 if (!AAIObjectType.map.containsKey(name)) {
188                         AAIObjectType.map.put(name, this);
189                 }
190         }
191
192         protected AAIObjectType(String parentUri, Class<?> aaiObjectClass) {
193                 this.parentUri = parentUri;
194                 this.partialUri = removeParentUri(aaiObjectClass, parentUri);
195                 this.uriTemplate = parentUri + partialUri;
196                 this.aaiObjectClass = aaiObjectClass;
197                 this.name = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, aaiObjectClass.getSimpleName());
198                 if (!AAIObjectType.map.containsKey(name)) {
199                         AAIObjectType.map.put(name, this);
200                 }
201         }
202
203         @Override
204         public String toString() {
205                 return this.uriTemplate();
206         }
207
208         public static AAIObjectType fromTypeName(String name) {
209                 if (map.containsKey(name)) {
210                         return map.get(name);
211                 } else {
212                         return AAIObjectType.UNKNOWN;
213                 }
214         }
215         @Override
216         public String typeName() {
217                 return this.typeName(CaseFormat.LOWER_HYPHEN);
218         }
219         @Override
220         public String typeName(CaseFormat format) {
221                 return CaseFormat.LOWER_HYPHEN.to(format, this.name.replace("default-", ""));
222         }
223
224         @Override
225         public String uriTemplate() {
226                 return this.uriTemplate;
227         }
228
229         @Override
230         public String partialUri() {
231                 return this.partialUri;
232         }
233
234         protected String removeParentUri(Class<?> aaiObjectClass, String parentUri) {
235                 return aaiObjectClass.getAnnotation(Metadata.class).uriTemplate().replaceFirst(Pattern.quote(parentUri), "");
236         }
237 }