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.db.catalog.client;
23 import com.google.common.base.Strings;
25 import java.util.ArrayList;
26 import java.util.Iterator;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import javax.annotation.PostConstruct;
30 import javax.persistence.EntityNotFoundException;
31 import javax.ws.rs.core.MediaType;
32 import javax.ws.rs.core.UriBuilder;
33 import org.apache.http.HttpStatus;
34 import org.onap.logging.filter.base.Constants;
35 import org.onap.logging.filter.spring.SpringClientPayloadFilter;
36 import org.onap.so.db.catalog.beans.BBNameSelectionReference;
37 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
38 import org.onap.so.db.catalog.beans.CloudSite;
39 import org.onap.so.db.catalog.beans.CloudifyManager;
40 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
41 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
42 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
43 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
44 import org.onap.so.db.catalog.beans.CvnfcCustomization;
45 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
46 import org.onap.so.db.catalog.beans.HomingInstance;
47 import org.onap.so.db.catalog.beans.InstanceGroup;
48 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
49 import org.onap.so.db.catalog.beans.NetworkRecipe;
50 import org.onap.so.db.catalog.beans.NetworkResource;
51 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
52 import org.onap.so.db.catalog.beans.OrchestrationAction;
53 import org.onap.so.db.catalog.beans.OrchestrationStatus;
54 import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective;
55 import org.onap.so.db.catalog.beans.PnfResource;
56 import org.onap.so.db.catalog.beans.PnfResourceCustomization;
57 import org.onap.so.db.catalog.beans.ProcessingFlags;
58 import org.onap.so.db.catalog.beans.ResourceType;
59 import org.onap.so.db.catalog.beans.Service;
60 import org.onap.so.db.catalog.beans.ServiceRecipe;
61 import org.onap.so.db.catalog.beans.VfModule;
62 import org.onap.so.db.catalog.beans.VfModuleCustomization;
63 import org.onap.so.db.catalog.beans.VnfComponentsRecipe;
64 import org.onap.so.db.catalog.beans.VnfRecipe;
65 import org.onap.so.db.catalog.beans.VnfResource;
66 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
67 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
68 import org.onap.so.db.catalog.beans.Workflow;
69 import org.onap.so.db.catalog.beans.macro.NorthBoundRequest;
70 import org.onap.so.db.catalog.beans.macro.OrchestrationFlow;
71 import org.onap.so.db.catalog.beans.macro.RainyDayHandlerStatus;
72 import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
73 import org.slf4j.Logger;
74 import org.slf4j.LoggerFactory;
75 import org.springframework.beans.factory.annotation.Autowired;
76 import org.springframework.beans.factory.annotation.Value;
77 import org.springframework.core.ParameterizedTypeReference;
78 import org.springframework.http.HttpEntity;
79 import org.springframework.http.HttpHeaders;
80 import org.springframework.http.HttpMethod;
81 import org.springframework.http.client.BufferingClientHttpRequestFactory;
82 import org.springframework.http.client.ClientHttpRequestFactory;
83 import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
84 import org.springframework.stereotype.Component;
85 import org.springframework.web.client.HttpClientErrorException;
86 import org.springframework.web.client.RestTemplate;
87 import org.springframework.web.util.UriComponentsBuilder;
88 import uk.co.blackpepper.bowman.Client;
89 import uk.co.blackpepper.bowman.ClientFactory;
90 import uk.co.blackpepper.bowman.Configuration;
92 @Component("CatalogDbClient")
93 public class CatalogDbClient {
95 private static final Logger logger = LoggerFactory.getLogger(CatalogDbClient.class);
97 private static final String CLOUD_SITE = "/cloudSite";
98 private static final String CLOUDIFY_MANAGER = "/cloudifyManager";
99 private static final String RAINY_DAY_HANDLER_MACRO = "/rainy_day_handler_macro";
100 private static final String NORTHBOUND_REQUEST_REF_LOOKUP = "/northbound_request_ref_lookup";
101 private static final String NETWORK_RESOURCE_CUSTOMIZATION = "/networkResourceCustomization";
102 private static final String NETWORK_RESOURCE = "/networkResource";
103 private static final String COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION =
104 "/collectionResourceInstanceGroupCustomization";
105 private static final String VNFC_INSTANCE_GROUP_CUSTOMIZATION = "/vnfcInstanceGroupCustomization";
106 private static final String ORCHESTRATION_FLOW = "/orchestrationFlow";
107 private static final String ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE =
108 "/orchestrationStatusStateTransitionDirective";
109 private static final String INSTANCE_GROUP = "/instanceGroup";
110 private static final String COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION = "/collectionNetworkResourceCustomization";
111 private static final String BUILDING_BLOCK_DETAIL = "/buildingBlockDetail";
112 private static final String NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION = "/networkCollectionResourceCustomization";
113 private static final String VNF_RESOURCE_CUSTOMIZATION = "/vnfResourceCustomization";
114 private static final String SERVICE = "/service";
115 private static final String EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING = "/externalServiceToInternalService";
116 private static final String VNF_RESOURCE = "/vnfResource";
117 private static final String VNF_RECIPE = "/vnfRecipe";
118 private static final String VFMODULE = "/vfModule";
119 private static final String VFMODULE_CUSTOMIZATION = "/vfModuleCustomization";
120 private static final String VNF_COMPONENTS_RECIPE = "/vnfComponentsRecipe";
121 private static final String SERVICE_RECIPE = "/serviceRecipe";
122 private static final String NETWORK_RECIPE = "/networkRecipe";
123 private static final String PNF_RESOURCE = "/pnfResource";
124 private static final String PNF_RESOURCE_CUSTOMIZATION = "/pnfResourceCustomization";
125 private static final String WORKFLOW = "/workflow";
126 private static final String BB_NAME_SELECTION_REFERENCE = "/bbNameSelectionReference";
127 private static final String PROCESSING_FLAGS = "/processingFlags";
130 private static final String SEARCH = "/search";
131 private static final String URI_SEPARATOR = "/";
133 protected static final String SERVICE_MODEL_UUID = "serviceModelUUID";
134 protected static final String SERVICE_NAME = "serviceName";
135 protected static final String MODEL_UUID = "modelUUID";
136 protected static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
137 protected static final String ACTION = "action";
138 protected static final String MODEL_NAME = "modelName";
139 protected static final String MODEL_VERSION = "modelVersion";
140 protected static final String MODEL_INVARIANT_UUID = "modelInvariantUUID";
141 protected static final String VNF_RESOURCE_MODEL_UUID = "vnfResourceModelUUID";
142 protected static final String PNF_RESOURCE_MODEL_UUID = "pnfResourceModelUUID";
143 protected static final String NF_ROLE = "nfRole";
144 protected static final String VF_MODULE_MODEL_UUID = "vfModuleModelUUID";
145 protected static final String VNF_COMPONENT_TYPE = "vnfComponentType";
146 protected static final String BUILDING_BLOCK_NAME = "buildingBlockName";
147 protected static final String RESOURCE_TYPE = "resourceType";
148 protected static final String ORCHESTRATION_STATUS = "orchestrationStatus";
149 protected static final String TARGET_ACTION = "targetAction";
150 protected static final String REQUEST_SCOPE = "requestScope";
151 protected static final String IS_ALACARTE = "isALaCarte";
152 protected static final String CLOUD_OWNER = "cloudOwner";
153 protected static final String FLOW_NAME = "flowName";
154 protected static final String ERROR_MESSAGE = "errorMessage";
155 protected static final String SERVICE_ROLE = "serviceRole";
156 protected static final String SERVICE_TYPE = "serviceType";
157 protected static final String VNF_TYPE = "vnfType";
158 protected static final String ERROR_CODE = "errorCode";
159 protected static final String WORK_STEP = "workStep";
160 protected static final String CLLI = "clli";
161 protected static final String CLOUD_VERSION = "cloudVersion";
162 protected static final String HOMING_INSTANCE = "/homingInstance";
163 protected static final String ARTIFACT_UUID = "artifactUUID";
164 protected static final String SOURCE = "source";
165 protected static final String RESOURCE_TARGET = "resourceTarget";
166 protected static final String FLAG = "flag";
167 protected static final String OPERATION_NAME = "operationName";
169 private static final String TARGET_ENTITY = "SO:CatalogDB";
170 private static final String ASTERISK = "*";
172 private String findExternalToInternalServiceByServiceName = "/findByServiceName";
173 private String findServiceByModelName = "/findOneByModelName";
174 private String findServiceRecipeByActionAndServiceModelUUID = "/findByActionAndServiceModelUUID";
175 private String findServiceByModelUUID = "/findOneByModelUUID";
176 private String findFirstByModelNameURI = "/findFirstByModelNameOrderByModelVersionDesc";
177 private String findFirstByServiceModelUUIDAndActionURI = "/findFirstByServiceModelUUIDAndAction";
178 private String findFirstByModelVersionAndModelInvariantUUIDURI = "/findFirstByModelVersionAndModelInvariantUUID";
179 private String findByModelInvariantUUIDURI = "/findByModelInvariantUUIDOrderByModelVersionDesc";
180 private String findFirstByModelNameAndAction = "/findFirstByModelNameAndAction";
181 private String findFirstResourceByModelInvariantUUIDAndModelVersion =
182 "/findFirstResourceByModelInvariantUUIDAndModelVersion";
183 private String findByModelInstanceNameAndVnfResources = "/findByModelInstanceNameAndVnfResources";
184 private String findFirstVnfRecipeByNfRoleAndAction = "/findFirstVnfRecipeByNfRoleAndAction";
185 private String findByModelCustomizationUUIDAndVfModuleModelUUID =
186 "/findFirstByModelCustomizationUUIDAndVfModuleModelUUIDOrderByCreatedDesc";
187 private String findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction =
188 "/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction";
189 private String findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
190 "/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction";
191 private String findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
192 "/findByModelInvariantUUIDOrderByModelVersionDesc";
193 private String findFirstVfModuleByModelInvariantUUIDAndModelVersion =
194 "/findFirstVfModuleByModelInvariantUUIDAndModelVersion";
195 private String findOneByBuildingBlockName = "/findOneByBuildingBlockName";
196 private String findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
197 "/findOneByResourceTypeAndOrchestrationStatusAndTargetAction";
198 private String findByAction = "/findByAction";
199 private String findVnfcInstanceGroupCustomizationByModelCustomizationUUID = "/findByModelCustomizationUUID";
200 private String findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
201 "/findByModelCustomizationUUID";
202 private String findOneByActionAndRequestScopeAndIsAlacarte = "/findOneByActionAndRequestScopeAndIsAlacarte";
203 private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner =
204 "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner";
205 private String findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
206 "/findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType";
208 private static final String findRainyDayHandler = "/findRainyDayHandler";
209 private String findByClliAndCloudVersion = "/findByClliAndCloudVersion";
210 private String findServiceByServiceInstanceId = "/findServiceByServiceInstanceId";
211 private String findPnfResourceCustomizationByModelUuid = "/findPnfResourceCustomizationByModelUuid";
212 private String findWorkflowByArtifactUUID = "/findByArtifactUUID";
213 private String findWorkflowByVnfModelUUID = "/findWorkflowByVnfModelUUID";
214 private String findWorkflowByPnfModelUUID = "/findWorkflowByPnfModelUUID";
215 private String findWorkflowBySource = "/findBySource";
216 private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
217 private String findBBNameSelectionReferenceByControllerActorAndScopeAndAction =
218 "/findBBNameSelectionReferenceByControllerActorAndScopeAndAction";
219 private String findWorkflowByResourceTarget = "/findByResourceTarget";
220 private String findProcessingFlagsByFlag = "/findByFlag";
221 private String findWorkflowByOperationName = "/findByOperationName";
223 private String serviceURI;
224 private String vfModuleURI;
225 private String vnfResourceURI;
226 private String networkCollectionResourceCustomizationURI;
227 private String networkResourceCustomizationURI;
228 private String networkResourceURI;
229 private String collectionNetworkResourceCustomizationURI;
230 private String instanceGroupURI;
231 private String cloudifyManagerURI;
232 private String cloudSiteURI;
233 private String homingInstanceURI;
234 private String cvnfcResourceCustomizationURI;
235 private String pnfResourceURI;
236 private String pnfResourceCustomizationURI;
237 private String workflowURI;
239 private final Client<Service> serviceClient;
241 private final Client<NetworkRecipe> networkRecipeClient;
243 private final Client<NetworkResourceCustomization> networkResourceCustomizationClient;
245 private final Client<VnfResource> vnfResourceClient;
247 private final Client<VnfResourceCustomization> vnfResourceCustomizationClient;
249 private final Client<VnfRecipe> vnfRecipeClient;
251 private final Client<VfModuleCustomization> vfModuleCustomizationClient;
253 private final Client<VfModule> vfModuleClient;
255 private final Client<VnfComponentsRecipe> vnfComponentsRecipeClient;
257 private final Client<OrchestrationFlow> orchestrationClient;
259 private final Client<NorthBoundRequest> northBoundRequestClient;
261 private final Client<RainyDayHandlerStatus> rainyDayHandlerStatusClient;
263 private final Client<BuildingBlockDetail> buildingBlockDetailClient;
265 private final Client<OrchestrationStatusStateTransitionDirective> orchestrationStatusStateTransitionDirectiveClient;
267 private final Client<VnfcInstanceGroupCustomization> vnfcInstanceGroupCustomizationClient;
269 private final Client<CollectionResourceInstanceGroupCustomization> collectionResourceInstanceGroupCustomizationClient;
271 private final Client<InstanceGroup> instanceGroupClient;
273 private final Client<NetworkCollectionResourceCustomization> networkCollectionResourceCustomizationClient;
275 private final Client<CollectionNetworkResourceCustomization> collectionNetworkResourceCustomizationClient;
277 private final Client<ServiceRecipe> serviceRecipeClient;
279 private final Client<ExternalServiceToInternalService> externalServiceToInternalServiceClient;
281 private final Client<CloudSite> cloudSiteClient;
283 private final Client<HomingInstance> homingInstanceClient;
285 private final Client<CloudifyManager> cloudifyManagerClient;
287 private final Client<ControllerSelectionReference> controllerSelectionReferenceClient;
289 private final Client<PnfResource> pnfResourceClient;
291 private final Client<PnfResourceCustomization> pnfResourceCustomizationClient;
293 private final Client<Workflow> workflowClient;
295 private final Client<BBNameSelectionReference> bbNameSelectionReferenceClient;
297 private final Client<ProcessingFlags> processingFlagsClient;
299 @Value("${mso.catalog.db.spring.endpoint:#{null}}")
300 private String endpoint;
302 @Value("${mso.db.auth:#{null}}")
303 private String msoAdaptersAuth;
306 RestTemplate restTemplate;
310 findExternalToInternalServiceByServiceName = endpoint + EXTERNAL_SERVICE_TO_INTERNAL_MODEL_MAPPING + SEARCH
311 + findExternalToInternalServiceByServiceName;
312 findServiceByModelName = endpoint + SERVICE + SEARCH + findServiceByModelName;
313 findServiceRecipeByActionAndServiceModelUUID =
314 endpoint + SERVICE_RECIPE + SEARCH + findServiceRecipeByActionAndServiceModelUUID;
315 findServiceByModelUUID = endpoint + SERVICE + SEARCH + findServiceByModelUUID;
316 findFirstByModelNameURI = endpoint + SERVICE + SEARCH + findFirstByModelNameURI;
317 findFirstByModelVersionAndModelInvariantUUIDURI =
318 endpoint + SERVICE + SEARCH + findFirstByModelVersionAndModelInvariantUUIDURI;
319 findByModelInvariantUUIDURI = endpoint + SERVICE + SEARCH + findByModelInvariantUUIDURI;
320 findFirstByServiceModelUUIDAndActionURI =
321 endpoint + SERVICE_RECIPE + SEARCH + findFirstByServiceModelUUIDAndActionURI;
322 findFirstByModelNameAndAction = endpoint + NETWORK_RECIPE + SEARCH + findFirstByModelNameAndAction;
323 findFirstResourceByModelInvariantUUIDAndModelVersion =
324 endpoint + VNF_RESOURCE + SEARCH + findFirstResourceByModelInvariantUUIDAndModelVersion;
325 findByModelInstanceNameAndVnfResources =
326 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findByModelInstanceNameAndVnfResources;
327 findFirstVnfRecipeByNfRoleAndAction = endpoint + VNF_RECIPE + SEARCH + findFirstVnfRecipeByNfRoleAndAction;
328 findByModelCustomizationUUIDAndVfModuleModelUUID =
329 endpoint + VFMODULE_CUSTOMIZATION + SEARCH + findByModelCustomizationUUIDAndVfModuleModelUUID;
330 findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction = endpoint + VNF_COMPONENTS_RECIPE
331 + SEARCH + findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction;
332 findFirstVnfComponentsRecipeByVnfComponentTypeAndAction =
333 endpoint + VNF_COMPONENTS_RECIPE + SEARCH + findFirstVnfComponentsRecipeByVnfComponentTypeAndAction;
334 findVfModuleByModelInvariantUUIDOrderByModelVersionDesc =
335 endpoint + VFMODULE + SEARCH + findVfModuleByModelInvariantUUIDOrderByModelVersionDesc;
336 findFirstVfModuleByModelInvariantUUIDAndModelVersion =
337 endpoint + VFMODULE + SEARCH + findFirstVfModuleByModelInvariantUUIDAndModelVersion;
338 findOneByBuildingBlockName = endpoint + BUILDING_BLOCK_DETAIL + SEARCH + findOneByBuildingBlockName;
339 findOneByResourceTypeAndOrchestrationStatusAndTargetAction =
340 endpoint + ORCHESTRATION_STATUS_STATE_TRANSITION_DIRECTIVE + SEARCH
341 + findOneByResourceTypeAndOrchestrationStatusAndTargetAction;
342 findByAction = endpoint + ORCHESTRATION_FLOW + SEARCH + findByAction;
343 findVnfcInstanceGroupCustomizationByModelCustomizationUUID = endpoint + VNFC_INSTANCE_GROUP_CUSTOMIZATION
344 + SEARCH + findVnfcInstanceGroupCustomizationByModelCustomizationUUID;
345 findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID =
346 endpoint + COLLECTION_RESOURCE_INSTANCE_GROUP_CUSTOMIZATION + SEARCH
347 + findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID;
348 findOneByActionAndRequestScopeAndIsAlacarte =
349 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH + findOneByActionAndRequestScopeAndIsAlacarte;
350 findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner = endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
351 + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwner;
352 findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType =
353 endpoint + NORTHBOUND_REQUEST_REF_LOOKUP + SEARCH
354 + findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType;
355 findByClliAndCloudVersion = endpoint + CLOUD_SITE + SEARCH + findByClliAndCloudVersion;
357 findPnfResourceCustomizationByModelUuid =
358 endpoint + PNF_RESOURCE_CUSTOMIZATION + SEARCH + findPnfResourceCustomizationByModelUuid;
360 findWorkflowByArtifactUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByArtifactUUID;
361 findWorkflowByVnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByVnfModelUUID;
362 findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID;
363 findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
364 findWorkflowByResourceTarget = endpoint + WORKFLOW + SEARCH + findWorkflowByResourceTarget;
366 findVnfResourceCustomizationByModelUuid =
367 endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid;
369 findBBNameSelectionReferenceByControllerActorAndScopeAndAction = endpoint + BB_NAME_SELECTION_REFERENCE + SEARCH
370 + findBBNameSelectionReferenceByControllerActorAndScopeAndAction;
372 findProcessingFlagsByFlag = endpoint + PROCESSING_FLAGS + SEARCH + findProcessingFlagsByFlag;
373 findWorkflowByOperationName = endpoint + WORKFLOW + SEARCH + findWorkflowByOperationName;
375 serviceURI = endpoint + SERVICE + URI_SEPARATOR;
376 vfModuleURI = endpoint + VFMODULE + URI_SEPARATOR;
377 vnfResourceURI = endpoint + VNF_RESOURCE + URI_SEPARATOR;
378 networkCollectionResourceCustomizationURI =
379 endpoint + NETWORK_COLLECTION_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
380 networkResourceCustomizationURI = endpoint + NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
381 networkResourceURI = endpoint + NETWORK_RESOURCE + SEARCH;
382 collectionNetworkResourceCustomizationURI =
383 endpoint + COLLECTION_NETWORK_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
384 instanceGroupURI = endpoint + INSTANCE_GROUP + URI_SEPARATOR;
385 cloudifyManagerURI = endpoint + CLOUDIFY_MANAGER + URI_SEPARATOR;
386 cloudSiteURI = endpoint + CLOUD_SITE + URI_SEPARATOR;
387 homingInstanceURI = endpoint + HOMING_INSTANCE + URI_SEPARATOR;
388 pnfResourceURI = endpoint + PNF_RESOURCE + URI_SEPARATOR;
389 pnfResourceCustomizationURI = endpoint + PNF_RESOURCE_CUSTOMIZATION + URI_SEPARATOR;
390 workflowURI = endpoint + WORKFLOW + URI_SEPARATOR;
394 public CatalogDbClient() {
395 ClientHttpRequestFactory factory =
396 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
398 ClientFactory clientFactory =
399 Configuration.builder().setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> {
400 restTemplate.getInterceptors().add((new SOSpringClientFilter()));
401 restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
403 restTemplate.getInterceptors().add((request, body, execution) -> {
405 request.getHeaders().add(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
406 request.getHeaders().add(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
407 return execution.execute(request, body);
409 }).build().buildClientFactory();
410 serviceClient = clientFactory.create(Service.class);
411 networkRecipeClient = clientFactory.create(NetworkRecipe.class);
412 networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
413 vnfResourceClient = clientFactory.create(VnfResource.class);
414 vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
415 vnfRecipeClient = clientFactory.create(VnfRecipe.class);
416 orchestrationClient = clientFactory.create(OrchestrationFlow.class);
417 vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
418 vfModuleClient = clientFactory.create(VfModule.class);
419 vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
420 northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
421 rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
422 buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
423 orchestrationStatusStateTransitionDirectiveClient =
424 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
425 vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
426 collectionResourceInstanceGroupCustomizationClient =
427 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
428 instanceGroupClient = clientFactory.create(InstanceGroup.class);
429 networkCollectionResourceCustomizationClient =
430 clientFactory.create(NetworkCollectionResourceCustomization.class);
431 collectionNetworkResourceCustomizationClient =
432 clientFactory.create(CollectionNetworkResourceCustomization.class);
433 cloudSiteClient = clientFactory.create(CloudSite.class);
434 homingInstanceClient = clientFactory.create(HomingInstance.class);
435 cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
436 serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
437 controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
438 externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
439 pnfResourceClient = clientFactory.create(PnfResource.class);
440 pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
441 workflowClient = clientFactory.create(Workflow.class);
442 bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class);
443 processingFlagsClient = clientFactory.create(ProcessingFlags.class);
447 public CatalogDbClient(String baseUri, String auth) {
448 ClientHttpRequestFactory factory =
449 new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory());
451 ClientFactory clientFactory = Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory)
452 .setRestTemplateConfigurer(restTemplate -> {
453 restTemplate.getInterceptors().add((new SOSpringClientFilter()));
454 restTemplate.getInterceptors().add((new SpringClientPayloadFilter()));
456 restTemplate.getInterceptors().add((request, body, execution) -> {
458 request.getHeaders().add(HttpHeaders.AUTHORIZATION, auth);
459 request.getHeaders().add(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
460 return execution.execute(request, body);
462 }).build().buildClientFactory();
463 serviceClient = clientFactory.create(Service.class);
464 networkRecipeClient = clientFactory.create(NetworkRecipe.class);
465 networkResourceCustomizationClient = clientFactory.create(NetworkResourceCustomization.class);
466 vnfResourceClient = clientFactory.create(VnfResource.class);
467 vnfResourceCustomizationClient = clientFactory.create(VnfResourceCustomization.class);
468 vnfRecipeClient = clientFactory.create(VnfRecipe.class);
469 orchestrationClient = clientFactory.create(OrchestrationFlow.class);
470 vfModuleCustomizationClient = clientFactory.create(VfModuleCustomization.class);
471 vfModuleClient = clientFactory.create(VfModule.class);
472 vnfComponentsRecipeClient = clientFactory.create(VnfComponentsRecipe.class);
473 northBoundRequestClient = clientFactory.create(NorthBoundRequest.class);
474 rainyDayHandlerStatusClient = clientFactory.create(RainyDayHandlerStatus.class);
475 buildingBlockDetailClient = clientFactory.create(BuildingBlockDetail.class);
476 orchestrationStatusStateTransitionDirectiveClient =
477 clientFactory.create(OrchestrationStatusStateTransitionDirective.class);
478 vnfcInstanceGroupCustomizationClient = clientFactory.create(VnfcInstanceGroupCustomization.class);
479 collectionResourceInstanceGroupCustomizationClient =
480 clientFactory.create(CollectionResourceInstanceGroupCustomization.class);
481 instanceGroupClient = clientFactory.create(InstanceGroup.class);
482 networkCollectionResourceCustomizationClient =
483 clientFactory.create(NetworkCollectionResourceCustomization.class);
484 collectionNetworkResourceCustomizationClient =
485 clientFactory.create(CollectionNetworkResourceCustomization.class);
486 cloudSiteClient = clientFactory.create(CloudSite.class);
487 homingInstanceClient = clientFactory.create(HomingInstance.class);
488 cloudifyManagerClient = clientFactory.create(CloudifyManager.class);
489 serviceRecipeClient = clientFactory.create(ServiceRecipe.class);
490 controllerSelectionReferenceClient = clientFactory.create(ControllerSelectionReference.class);
491 externalServiceToInternalServiceClient = clientFactory.create(ExternalServiceToInternalService.class);
492 pnfResourceClient = clientFactory.create(PnfResource.class);
493 pnfResourceCustomizationClient = clientFactory.create(PnfResourceCustomization.class);
494 workflowClient = clientFactory.create(Workflow.class);
495 bbNameSelectionReferenceClient = clientFactory.create(BBNameSelectionReference.class);
496 processingFlagsClient = clientFactory.create(ProcessingFlags.class);
499 public NetworkCollectionResourceCustomization getNetworkCollectionResourceCustomizationByID(
500 String modelCustomizationUUID) {
501 NetworkCollectionResourceCustomization networkCollectionResourceCustomization =
502 this.getSingleResource(networkCollectionResourceCustomizationClient,
503 getUri(networkCollectionResourceCustomizationURI + modelCustomizationUUID));
504 if (networkCollectionResourceCustomization != null) {
505 networkCollectionResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
507 return networkCollectionResourceCustomization;
510 public Service getServiceByID(String modelUUID) {
511 Service service = getSingleResource(serviceClient, getUri(serviceURI + modelUUID));
512 if (service != null) {
513 service.setModelUUID(modelUUID);
518 public VfModule getVfModuleByModelUUID(String modelUUID) {
519 VfModule vfModule = getSingleResource(vfModuleClient, getUri(vfModuleURI + modelUUID));
520 if (vfModule != null) {
521 vfModule.setModelUUID(modelUUID);
526 public VnfResource getVnfResourceByModelUUID(String modelUUID) {
528 VnfResource vnfResource = this.getSingleResource(vnfResourceClient, getUri(vnfResourceURI + modelUUID));
529 if (vnfResource != null) {
530 vnfResource.setModelUUID(modelUUID);
535 // A VNFResource customization UUID is the same object across services, so we can return anyone from the list
536 // In the future the client should query starting at a service model uuid
537 public VnfResourceCustomization getVnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
538 List<VnfResourceCustomization> vnfResourceCustomization = this.getMultipleResources(
539 vnfResourceCustomizationClient, getUri(endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH
540 + "/findByModelCustomizationUUID" + "?MODEL_CUSTOMIZATION_UUID=" + modelCustomizationUUID));
541 if (vnfResourceCustomization != null && !vnfResourceCustomization.isEmpty()) {
542 return vnfResourceCustomization.get(0);
548 public List<VnfResourceCustomization> getVnfResourceCustomizationByModelUuid(String modelUuid) {
549 return this.getMultipleResources(vnfResourceCustomizationClient,
550 getUri(UriBuilder.fromUri(findVnfResourceCustomizationByModelUuid)
551 .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
554 public PnfResource getPnfResourceByModelUUID(String modelUUID) {
555 PnfResource PnfResource = this.getSingleResource(pnfResourceClient, getUri(pnfResourceURI + modelUUID));
556 if (PnfResource != null) {
557 PnfResource.setModelUUID(modelUUID);
562 public PnfResourceCustomization getPnfResourceCustomizationByModelCustomizationUUID(String modelCustomizationUUID) {
563 PnfResourceCustomization pnfResourceCustomization = getSingleResource(pnfResourceCustomizationClient,
564 getUri(pnfResourceCustomizationURI + modelCustomizationUUID));
565 if (pnfResourceCustomization != null) {
566 pnfResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
568 return pnfResourceCustomization;
571 public List<PnfResourceCustomization> getPnfResourceCustomizationByModelUuid(String modelUuid) {
572 return this.getMultipleResources(pnfResourceCustomizationClient,
573 getUri(UriBuilder.fromUri(findPnfResourceCustomizationByModelUuid)
574 .queryParam("SERVICE_MODEL_UUID", modelUuid).build().toString()));
577 public CollectionNetworkResourceCustomization getCollectionNetworkResourceCustomizationByID(
578 String modelCustomizationUUID) {
579 CollectionNetworkResourceCustomization collectionNetworkResourceCustomization =
580 this.getSingleResource(collectionNetworkResourceCustomizationClient,
581 getUri(UriBuilder.fromUri(collectionNetworkResourceCustomizationURI + modelCustomizationUUID)
582 .build().toString()));
583 if (collectionNetworkResourceCustomization != null) {
584 collectionNetworkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
586 return collectionNetworkResourceCustomization;
589 public InstanceGroup getInstanceGroupByModelUUID(String modelUUID) {
590 InstanceGroup instanceGroup = this.getSingleResource(instanceGroupClient, getUri(instanceGroupURI + modelUUID));
591 if (instanceGroup != null) {
592 instanceGroup.setModelUUID(modelUUID);
594 return instanceGroup;
597 public VfModuleCustomization getVfModuleCustomizationByModelCuztomizationUUID(String modelCustomizationUUID) {
598 return this.getSingleResource(vfModuleCustomizationClient,
599 getUri(endpoint + VFMODULE_CUSTOMIZATION + SEARCH
600 + "/findFirstByModelCustomizationUUIDOrderByCreatedDesc" + "?MODEL_CUSTOMIZATION_UUID="
601 + modelCustomizationUUID));
604 public NetworkResourceCustomization getNetworkResourceCustomizationByModelCustomizationUUID(
605 String modelCustomizationUUID) {
606 NetworkResourceCustomization networkResourceCustomization = this.getSingleResource(
607 networkResourceCustomizationClient, getUri(networkResourceCustomizationURI + modelCustomizationUUID));
608 if (networkResourceCustomization != null) {
609 networkResourceCustomization.setModelCustomizationUUID(modelCustomizationUUID);
611 return networkResourceCustomization;
614 public NetworkResource getNetworkResourceByModelName(String networkType) {
615 if (Strings.isNullOrEmpty(networkType)) {
616 throw new EntityNotFoundException("networkType passed as Null or Empty String");
619 HttpEntity<?> entity = getHttpEntity();
620 return restTemplate.exchange(
621 UriBuilder.fromUri(networkResourceURI + "/findFirstByModelNameOrderByModelVersionDesc")
622 .queryParam("modelName", networkType).build(),
623 HttpMethod.GET, entity, NetworkResource.class).getBody();
624 } catch (HttpClientErrorException e) {
625 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
626 throw new EntityNotFoundException("Unable to find NetworkResource By networkType " + networkType);
634 public BuildingBlockDetail getBuildingBlockDetail(String buildingBlockName) {
635 BuildingBlockDetail buildingBlockDetail =
636 getSingleResource(buildingBlockDetailClient, getUri(UriBuilder.fromUri(findOneByBuildingBlockName)
637 .queryParam(BUILDING_BLOCK_NAME, buildingBlockName).build().toString()));
638 if (buildingBlockDetail != null) {
639 buildingBlockDetail.setBuildingBlockName(buildingBlockName);
641 return buildingBlockDetail;
645 public OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective(
646 ResourceType resourceType, OrchestrationStatus orchestrationStatus, OrchestrationAction targetAction) {
647 return getSingleResource(orchestrationStatusStateTransitionDirectiveClient,
648 UriBuilder.fromUri(findOneByResourceTypeAndOrchestrationStatusAndTargetAction)
649 .queryParam(RESOURCE_TYPE, resourceType.name())
650 .queryParam(ORCHESTRATION_STATUS, orchestrationStatus.name())
651 .queryParam(TARGET_ACTION, targetAction.name()).build());
654 public List<OrchestrationFlow> getOrchestrationFlowByAction(String action) {
655 return this.getMultipleResources(orchestrationClient,
656 UriBuilder.fromUri(findByAction).queryParam(ACTION, action).build());
659 public List<VnfcInstanceGroupCustomization> getVnfcInstanceGroupsByVnfResourceCust(String modelCustomizationUUID) {
660 return this.getMultipleResources(vnfcInstanceGroupCustomizationClient,
661 UriBuilder.fromUri(findVnfcInstanceGroupCustomizationByModelCustomizationUUID)
662 .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
665 public List<CollectionResourceInstanceGroupCustomization> getCollectionResourceInstanceGroupCustomizationByModelCustUUID(
666 String modelCustomizationUUID) {
667 return this.getMultipleResources(collectionResourceInstanceGroupCustomizationClient,
668 UriBuilder.fromUri(findCollectionResourceInstanceGroupCustomizationByModelCustomizationUUID)
669 .queryParam(MODEL_CUSTOMIZATION_UUID, modelCustomizationUUID).build());
672 public VfModuleCustomization getVfModuleCustomizationByModelCustomizationUUIDAndVfModuleModelUUID(
673 String modelCustomizationUUID, String vfModuleModelUUID) {
674 return this.getSingleResource(vfModuleCustomizationClient,
675 getUri(UriBuilder.fromUri(findByModelCustomizationUUIDAndVfModuleModelUUID)
676 .queryParam("MODEL_CUSTOMIZATION_UUID", modelCustomizationUUID)
677 .queryParam("MODEL_UUID", vfModuleModelUUID).build().toString()));
680 public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScope(String requestAction,
681 String resourceName, boolean aLaCarte) {
682 return this.getSingleResource(northBoundRequestClient,
683 UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarte).queryParam(ACTION, requestAction)
684 .queryParam(REQUEST_SCOPE, resourceName).queryParam(IS_ALACARTE, aLaCarte).build());
687 public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwner(String requestAction,
688 String resourceName, boolean aLaCarte, String cloudOwner) {
689 return this.getSingleResource(northBoundRequestClient,
690 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
691 .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
692 .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
693 .queryParam(SERVICE_TYPE, ASTERISK).build().toString()));
696 public NorthBoundRequest getNorthBoundRequestByActionAndIsALaCarteAndRequestScopeAndCloudOwnerAndServiceType(
697 String requestAction, String resourceName, boolean aLaCarte, String cloudOwner, String serviceType) {
698 return this.getSingleResource(northBoundRequestClient,
699 getUri(UriBuilder.fromUri(findOneByActionAndRequestScopeAndIsAlacarteAndCloudOwnerAndServiceType)
700 .queryParam(ACTION, requestAction).queryParam(REQUEST_SCOPE, resourceName)
701 .queryParam(IS_ALACARTE, aLaCarte).queryParam(CLOUD_OWNER, cloudOwner)
702 .queryParam(SERVICE_TYPE, serviceType).build().toString()));
705 public RainyDayHandlerStatus getRainyDayHandlerStatus(String flowName, String serviceType, String vnfType,
706 String errorCode, String workStep, String errorMessage, String serviceRole) {
708 "Get Rainy Day Status - Flow Name {}, Service Type: {} , vnfType {} , errorCode {}, workStep {}, errorMessage {}",
709 flowName, serviceType, vnfType, errorCode, workStep, errorMessage);
710 return this.getSingleResource(rainyDayHandlerStatusClient,
711 UriComponentsBuilder.fromUriString(endpoint + RAINY_DAY_HANDLER_MACRO + SEARCH + findRainyDayHandler)
712 .queryParam(FLOW_NAME, flowName).queryParam(SERVICE_TYPE, serviceType)
713 .queryParam(VNF_TYPE, vnfType).queryParam(ERROR_CODE, errorCode).queryParam(WORK_STEP, workStep)
714 .queryParam(ERROR_MESSAGE, errorMessage).queryParam(SERVICE_ROLE, serviceRole).build().encode()
718 public ServiceRecipe getFirstByServiceModelUUIDAndAction(String modelUUID, String action) {
719 return this.getSingleResource(serviceRecipeClient,
720 getUri(UriBuilder.fromUri(findFirstByServiceModelUUIDAndActionURI)
721 .queryParam(SERVICE_MODEL_UUID, modelUUID).queryParam(ACTION, action).build().toString()));
726 public NetworkRecipe getFirstNetworkRecipeByModelNameAndAction(String modelName, String action) {
727 return this.getSingleResource(networkRecipeClient, UriBuilder.fromUri(findFirstByModelNameAndAction)
728 .queryParam(MODEL_NAME, modelName).queryParam(ACTION, action).build());
731 public ControllerSelectionReference getControllerSelectionReferenceByVnfTypeAndActionCategory(String vnfType,
732 String actionCategory) {
733 return this.getSingleResource(controllerSelectionReferenceClient, UriBuilder.fromUri(endpoint
734 + "/controllerSelectionReference/search/findControllerSelectionReferenceByVnfTypeAndActionCategory")
735 .queryParam("VNF_TYPE", vnfType).queryParam("ACTION_CATEGORY", actionCategory).build());
738 public Service getFirstByModelNameOrderByModelVersionDesc(String modelName) {
739 return this.getSingleResource(serviceClient,
740 UriBuilder.fromUri(findFirstByModelNameURI).queryParam(MODEL_NAME, modelName).build());
743 public BBNameSelectionReference getBBNameSelectionReference(String controllerActor, String scope, String action) {
745 return this.getSingleResource(bbNameSelectionReferenceClient,
746 getUri(UriBuilder.fromUri(findBBNameSelectionReferenceByControllerActorAndScopeAndAction)
747 .queryParam("CONTROLLER_ACTOR", controllerActor).queryParam("SCOPE", scope)
748 .queryParam("ACTION", action).build().toString()));
751 public ExternalServiceToInternalService findExternalToInternalServiceByServiceName(String serviceName) {
752 return this.getSingleResource(externalServiceToInternalServiceClient,
753 getUri(UriBuilder.fromUri(findExternalToInternalServiceByServiceName)
754 .queryParam(SERVICE_NAME, serviceName).build().toString()));
757 public ServiceRecipe findServiceRecipeByActionAndServiceModelUUID(String action, String modelUUID) {
758 return this.getSingleResource(serviceRecipeClient,
759 getUri(UriBuilder.fromUri(findServiceRecipeByActionAndServiceModelUUID).queryParam(ACTION, action)
760 .queryParam(SERVICE_MODEL_UUID, modelUUID).build().toString()));
763 public Service getServiceByModelName(String modelName) {
764 return this.getSingleResource(serviceClient, getUri(
765 UriBuilder.fromUri(findServiceByModelName).queryParam(MODEL_NAME, modelName).build().toString()));
768 public Service getServiceByModelUUID(String modelModelUUID) {
769 return this.getSingleResource(serviceClient, getUri(
770 UriBuilder.fromUri(findServiceByModelUUID).queryParam(MODEL_UUID, modelModelUUID).build().toString()));
773 public VnfResource getFirstVnfResourceByModelInvariantUUIDAndModelVersion(String modelInvariantUUID,
774 String modelVersion) {
775 return this.getSingleResource(vnfResourceClient,
776 getUri(UriBuilder.fromUri(findFirstResourceByModelInvariantUUIDAndModelVersion)
777 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
778 .build().toString()));
782 public VnfResourceCustomization getFirstVnfResourceCustomizationByModelInstanceNameAndVnfResources(
783 String modelInstanceName, VnfResource vnfResource) {
784 return this.getSingleResource(vnfResourceCustomizationClient,
785 getUri(UriBuilder.fromUri(findByModelInstanceNameAndVnfResources)
786 .queryParam("MODEL_INSTANCE_NAME", modelInstanceName)
787 .queryParam("VNF_RESOURCE_MODEL_UUID", vnfResource.getModelUUID()).build().toString()));
790 public VnfRecipe getFirstVnfRecipeByNfRoleAndAction(String nfRole, String action) {
791 return this.getSingleResource(vnfRecipeClient, getUri(UriBuilder.fromUri(findFirstVnfRecipeByNfRoleAndAction)
792 .queryParam(NF_ROLE, nfRole).queryParam(ACTION, action).build().toString()));
795 public VnfComponentsRecipe getFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction(
796 String vfModuleModelUUID, String modelType, String action) {
797 return this.getSingleResource(vnfComponentsRecipeClient,
798 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction)
799 .queryParam(VF_MODULE_MODEL_UUID, vfModuleModelUUID).queryParam(VNF_COMPONENT_TYPE, modelType)
800 .queryParam(ACTION, action).build().toString()));
803 public VnfComponentsRecipe getFirstVnfComponentsRecipeByVnfComponentTypeAndAction(String modelType, String action) {
804 return this.getSingleResource(vnfComponentsRecipeClient,
805 getUri(UriBuilder.fromUri(findFirstVnfComponentsRecipeByVnfComponentTypeAndAction)
806 .queryParam(VNF_COMPONENT_TYPE, modelType).queryParam(ACTION, action).build().toString()));
810 protected URI getUri(String template) {
811 return URI.create(template);
814 public CloudifyManager getCloudifyManager(String id) {
815 return this.getSingleResource(cloudifyManagerClient, getUri(cloudifyManagerURI + id));
818 public CloudSite getCloudSite(String id) {
819 return this.getSingleResource(cloudSiteClient, getUri(cloudSiteURI + id));
822 public CloudSite getCloudSite(String id, String uri) {
823 return this.getSingleResource(cloudSiteClient, getUri(uri + id));
826 // Bring back old version of methind since the caller - OofInfraUtils.java - is not running in a spring context
827 public void postOofHomingCloudSite(CloudSite cloudSite) {
828 this.postSingleResource(cloudSiteClient, cloudSite);
831 public CloudSite postCloudSite(CloudSite cloudSite) {
832 if (cloudSite == null) {
833 throw new EntityNotFoundException("CloudSite passed as null");
836 HttpHeaders headers = getHttpHeaders();
837 HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers);
838 CloudSite updatedCloudSite = restTemplate
839 .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite").build().encode().toString(),
840 HttpMethod.POST, entity, CloudSite.class)
842 return updatedCloudSite;
843 } catch (HttpClientErrorException e) {
844 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
845 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId());
851 public CloudSite updateCloudSite(CloudSite cloudSite) {
852 if (cloudSite == null) {
853 throw new EntityNotFoundException("CloudSite passed as null");
856 HttpHeaders headers = getHttpHeaders();
857 HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers);
858 CloudSite updatedCloudSite = restTemplate
859 .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSite.getId()).build()
860 .encode().toString(), HttpMethod.PUT, entity, CloudSite.class)
862 return updatedCloudSite;
863 } catch (HttpClientErrorException e) {
864 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
865 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId());
871 public void deleteCloudSite(String cloudSiteId) {
872 if (cloudSiteId == null) {
873 throw new EntityNotFoundException("CloudSiteId passed as null");
876 HttpHeaders headers = getHttpHeaders();
877 HttpEntity<String> entity = new HttpEntity<>(null, headers);
878 restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSiteId).build()
879 .encode().toString(), HttpMethod.DELETE, entity, CloudSite.class).getBody();
880 } catch (HttpClientErrorException e) {
881 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
882 throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSiteId);
888 public List<CloudSite> getCloudSites() {
889 return this.getMultipleResources(cloudSiteClient,
890 UriBuilder.fromUri(endpoint + CLOUD_SITE).queryParam("size", "1000").build());
894 public CloudSite getCloudSiteByClliAndAicVersion(String clli, String cloudVersion) {
895 return this.getSingleResource(cloudSiteClient, getUri(UriBuilder.fromUri(findByClliAndCloudVersion)
896 .queryParam(CLLI, clli).queryParam(CLOUD_VERSION, cloudVersion).build().toString()));
899 public HomingInstance getHomingInstance(String serviceInstanceId) {
900 return this.getSingleResource(homingInstanceClient, getUri(homingInstanceURI + serviceInstanceId));
903 public HomingInstance getHomingInstance(String serviceInstanceId, String uri) {
904 return this.getSingleResource(homingInstanceClient, getUri(uri + serviceInstanceId));
907 public void postHomingInstance(HomingInstance homingInstance) {
908 this.postSingleResource(homingInstanceClient, homingInstance);
911 public Service getServiceByModelVersionAndModelInvariantUUID(String modelVersion, String modelInvariantUUID) {
912 return this.getSingleResource(serviceClient,
913 getUri(UriBuilder.fromUri(findFirstByModelVersionAndModelInvariantUUIDURI)
914 .queryParam(MODEL_VERSION, modelVersion).queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID)
915 .build().toString()));
918 public VfModule getVfModuleByModelInvariantUUIDAndModelVersion(String modelInvariantUUID, String modelVersion) {
919 return this.getSingleResource(vfModuleClient,
920 getUri(UriBuilder.fromUri(findFirstVfModuleByModelInvariantUUIDAndModelVersion)
921 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).queryParam(MODEL_VERSION, modelVersion)
922 .build().toString()));
925 public List<Service> getServiceByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
926 return this.getMultipleResources(serviceClient, getUri(UriBuilder.fromUri(findByModelInvariantUUIDURI)
927 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
930 public List<VfModule> getVfModuleByModelInvariantUUIDOrderByModelVersionDesc(String modelInvariantUUID) {
931 return this.getMultipleResources(vfModuleClient,
932 getUri(UriBuilder.fromUri(findVfModuleByModelInvariantUUIDOrderByModelVersionDesc)
933 .queryParam(MODEL_INVARIANT_UUID, modelInvariantUUID).build().toString()));
936 private <T> T getSingleResource(Client<T> client, URI uri) {
937 return client.get(uri);
940 protected <T> List<T> getMultipleResources(Client<T> client, URI uri) {
941 Iterable<T> iterator = client.getAll(uri);
942 List<T> list = new ArrayList<>();
943 Iterator<T> it = iterator.iterator();
944 it.forEachRemaining(list::add);
948 private <T> URI postSingleResource(Client<T> client, T type) {
949 return client.post(type);
952 public List<CvnfcCustomization> getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUUID,
953 String vfModuleCustomizationUUID) {
954 Service service = this.getServiceByID(serviceModelUUID);
955 VnfResourceCustomization vnfResourceCust =
956 findVnfResourceCustomizationInList(vnfCustomizationUUID, service.getVnfCustomizations());
957 VfModuleCustomization vfModuleCust =
958 findVfModuleCustomizationInList(vfModuleCustomizationUUID, vnfResourceCust.getVfModuleCustomizations());
959 return vfModuleCust.getCvnfcCustomization();
962 public VnfResourceCustomization findVnfResourceCustomizationInList(String vnfCustomizationUUID,
963 List<VnfResourceCustomization> vnfResourceCusts) {
964 if (vnfCustomizationUUID == null) {
965 throw new EntityNotFoundException(
966 "a NULL UUID was provided in query to search for VnfResourceCustomization");
968 List<VnfResourceCustomization> filtered =
969 vnfResourceCusts.stream().filter(v -> v.getModelCustomizationUUID() != null)
970 .filter(vnfCustRes -> vnfCustomizationUUID.equals(vnfCustRes.getModelCustomizationUUID()))
971 .collect(Collectors.toList());
972 if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
973 return filtered.get(0);
975 throw new EntityNotFoundException(
976 "Unable to find VnfResourceCustomization ModelCustomizationUUID:" + vnfCustomizationUUID);
979 protected VfModuleCustomization findVfModuleCustomizationInList(String vfModuleCustomizationUUID,
980 List<VfModuleCustomization> vfModuleList) {
981 if (vfModuleCustomizationUUID == null) {
982 throw new EntityNotFoundException("a NULL UUID was provided in query to search for VfModuleCustomization");
984 List<VfModuleCustomization> filtered = vfModuleList.stream().filter(v -> v.getModelCustomizationUUID() != null)
985 .filter(vfModuleCust -> vfModuleCustomizationUUID.equals(vfModuleCust.getModelCustomizationUUID()))
986 .collect(Collectors.toList());
987 if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
988 return filtered.get(0);
990 throw new EntityNotFoundException(
991 "Unable to find VfModuleCustomization ModelCustomizationUUID:" + vfModuleCustomizationUUID);
994 protected CvnfcCustomization findCvnfcCustomizationInAList(String cvnfcCustomizationUuid,
995 List<CvnfcCustomization> cvnfcCustomList) {
996 if (cvnfcCustomizationUuid == null) {
997 throw new EntityNotFoundException("a NULL UUID was provided in query to search for CvnfcCustomization");
999 List<CvnfcCustomization> filtered = cvnfcCustomList.stream().filter(c -> c.getModelCustomizationUUID() != null)
1000 .filter(cvnfc -> cvnfcCustomizationUuid.equals(cvnfc.getModelCustomizationUUID()))
1001 .collect(Collectors.toList());
1002 if (filtered != null && !filtered.isEmpty() && filtered.size() == 1) {
1003 logger.debug("Found CvnfcCustomization: {}", filtered.get(0));
1004 return filtered.get(0);
1006 throw new EntityNotFoundException(
1007 "Unable to find CvnfcCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
1010 public CvnfcConfigurationCustomization getCvnfcCustomization(String serviceModelUUID, String vnfCustomizationUuid,
1011 String vfModuleCustomizationUuid, String cvnfcCustomizationUuid) {
1012 List<CvnfcCustomization> cvnfcCustomization =
1013 getCvnfcCustomization(serviceModelUUID, vnfCustomizationUuid, vfModuleCustomizationUuid);
1014 CvnfcCustomization cvnfc = findCvnfcCustomizationInAList(cvnfcCustomizationUuid, cvnfcCustomization);
1015 List<CvnfcConfigurationCustomization> fabricConfigs = cvnfc.getCvnfcConfigurationCustomization();
1016 fabricConfigs.stream().filter(cvnfcCustom -> cvnfcCustom.getConfigurationResource().getToscaNodeType()
1017 .contains("FabricConfiguration")).collect(Collectors.toList());
1018 if (fabricConfigs != null && !fabricConfigs.isEmpty() && fabricConfigs.size() == 1) {
1019 logger.debug("Found Fabric Configuration: {}", fabricConfigs.get(0));
1020 return fabricConfigs.get(0);
1022 throw new EntityNotFoundException(
1023 "Unable to find CvnfcConfigurationCustomization ModelCustomizationUUID:" + cvnfcCustomizationUuid);
1026 public org.onap.so.rest.catalog.beans.Service getServiceModelInformation(String serviceModelUUID, String depth) {
1027 if (Strings.isNullOrEmpty(serviceModelUUID)) {
1028 throw new EntityNotFoundException("Service Model UUID passed as Null or Empty String");
1031 HttpEntity<?> entity = getHttpEntity();
1032 return restTemplate.exchange(
1033 UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID)
1034 .queryParam("depth", depth).build().encode().toString(),
1035 HttpMethod.GET, entity, org.onap.so.rest.catalog.beans.Service.class).getBody();
1036 } catch (HttpClientErrorException e) {
1037 logger.warn("Entity Not found in DLP", e);
1038 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1039 throw new EntityNotFoundException("Unable to find Service with ServiceModelUUID:" + serviceModelUUID);
1045 public List<org.onap.so.rest.catalog.beans.Service> getServices() {
1047 HttpEntity<?> entity = getHttpEntity();
1050 UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services").build()
1051 .encode().toString(),
1052 HttpMethod.GET, entity,
1053 new ParameterizedTypeReference<List<org.onap.so.rest.catalog.beans.Service>>() {})
1055 } catch (HttpClientErrorException e) {
1056 logger.error("Error Calling catalog database", e);
1061 public org.onap.so.rest.catalog.beans.Vnf getVnfModelInformation(String serviceModelUUID,
1062 String vnfCustomizationUUID, String depth) {
1063 if (Strings.isNullOrEmpty(serviceModelUUID)) {
1064 throw new EntityNotFoundException("Service Model UUID passed as Null or Empty String");
1066 if (Strings.isNullOrEmpty(vnfCustomizationUUID)) {
1067 throw new EntityNotFoundException("Vnf Customization UUID passed as Null or Empty String");
1070 HttpEntity<?> entity = getHttpEntity();
1073 UriComponentsBuilder
1074 .fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID
1075 + "/vnfs/" + vnfCustomizationUUID)
1076 .queryParam("depth", depth).build().encode().toString(),
1077 HttpMethod.GET, entity, org.onap.so.rest.catalog.beans.Vnf.class)
1079 } catch (HttpClientErrorException e) {
1080 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1081 throw new EntityNotFoundException(
1082 "Unable to find Vnf with Vnf Customization UUID:" + vnfCustomizationUUID);
1088 public void updateVnf(String serviceModelUUID, org.onap.so.rest.catalog.beans.Vnf vnf) {
1090 throw new EntityNotFoundException("Vnf passed as null");
1093 HttpHeaders headers = getHttpHeaders();
1094 HttpEntity<org.onap.so.rest.catalog.beans.Vnf> entity = new HttpEntity<>(vnf, headers);
1096 restTemplate.exchange(
1097 UriComponentsBuilder.fromUriString(endpoint + "/ecomp/mso/catalog/v1/services/" + serviceModelUUID
1098 + "/vnfs/" + vnf.getModelCustomizationId()).build().encode().toString(),
1099 HttpMethod.PUT, entity, org.onap.so.rest.catalog.beans.Vnf.class).getBody();
1100 } catch (HttpClientErrorException e) {
1101 if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) {
1102 throw new EntityNotFoundException(
1103 "Unable to find Vnf with Vnf Customization UUID:" + vnf.getModelCustomizationId());
1110 public Workflow findWorkflowByArtifactUUID(String artifactUUID) {
1111 return this.getSingleResource(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByArtifactUUID)
1112 .queryParam(ARTIFACT_UUID, artifactUUID).build().toString()));
1115 public List<Workflow> findWorkflowByVnfModelUUID(String vnfResourceModelUUID) {
1116 return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByVnfModelUUID)
1117 .queryParam(VNF_RESOURCE_MODEL_UUID, vnfResourceModelUUID).build().toString()));
1120 public List<Workflow> findWorkflowByPnfModelUUID(String pnfResourceModelUUID) {
1121 return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByPnfModelUUID)
1122 .queryParam(PNF_RESOURCE_MODEL_UUID, pnfResourceModelUUID).build().toString()));
1125 public List<Workflow> findWorkflowBySource(String source) {
1126 return this.getMultipleResources(workflowClient,
1127 getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
1130 public List<Workflow> findWorkflowByResourceTarget(String resourceTarget) {
1131 return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByResourceTarget)
1132 .queryParam(RESOURCE_TARGET, resourceTarget).build().toString()));
1135 public List<Workflow> findWorkflowByOperationName(String operationName) {
1136 return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByOperationName)
1137 .queryParam(OPERATION_NAME, operationName).build().toString()));
1140 public ProcessingFlags findProcessingFlagsByFlag(String flag) {
1141 return this.getSingleResource(processingFlagsClient,
1142 getUri(UriBuilder.fromUri(findProcessingFlagsByFlag).queryParam(FLAG, flag).build().toString()));
1145 public String getEndpoint() {
1149 public void setEndpoint(String endpoint) {
1150 this.endpoint = endpoint;
1153 private HttpHeaders getHttpHeaders() {
1154 HttpHeaders headers = new HttpHeaders();
1155 headers.set(HttpHeaders.AUTHORIZATION, msoAdaptersAuth);
1156 headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
1157 headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
1158 headers.set(Constants.HttpHeaders.TARGET_ENTITY_HEADER, TARGET_ENTITY);
1162 private HttpEntity<?> getHttpEntity() {
1163 HttpHeaders headers = getHttpHeaders();
1164 return new HttpEntity<>(headers);