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