2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.apihandlerinfra.tenantisolation.helpers;
25 import java.io.PrintWriter;
26 import java.io.StringWriter;
28 import javax.ws.rs.NotFoundException;
29 import org.onap.aai.domain.yang.OperationalEnvironment;
30 import org.onap.aaiclient.client.aai.AAIResourcesClient;
31 import org.onap.aaiclient.client.aai.entities.AAIResultWrapper;
32 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
33 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
34 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
35 import org.onap.aaiclient.client.graphinventory.entities.uri.Depth;
36 import org.onap.so.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed;
37 import org.springframework.stereotype.Component;
41 public class AAIClientHelper {
46 * Get managing ECOMP Environment Info from A&AI
48 * @param id = operationalEnvironmentId
49 * @return AAIResultWrapper object
51 public AAIResultWrapper getAaiOperationalEnvironment(String id) {
54 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(id));
55 uri.depth(Depth.ZERO);
56 AAIResourcesClient client = this.getClient();
57 return client.get(uri, NotFoundException.class);
62 * Update managing ECOMP Environment Info from A&AI
64 * @param id = operationalEnvironmentId
65 * @param aaiRequest object
67 public void updateAaiOperationalEnvironment(String id, OperationalEnvironment aaiRequest) {
70 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(id));
71 AAIResourcesClient client = this.getClient();
72 client.update(uri, aaiRequest);
77 public void updateAaiOperationalEnvironment(String operationalEnvironmentId, Map<String, String> payload)
78 throws AAIClientCallFailed {
80 AAIResourceUri uri = AAIUriFactory.createResourceUri(
81 AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(operationalEnvironmentId));
82 AAIResourcesClient aaiClient = this.getClient();
83 aaiClient.update(uri, payload);
84 } catch (Exception ex) {
86 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
91 * Create an Operational Environment object in A&AI
93 * @param operationalEnvironment object
95 public void createOperationalEnvironment(OperationalEnvironment operationalEnvironment) {
97 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
98 .operationalEnvironment(operationalEnvironment.getOperationalEnvironmentId()));
99 AAIResourcesClient client = this.getClient();
100 client.create(uri, operationalEnvironment);
104 * Create a relationship between ECOMP managing and VNF Operational Environments
106 * @param managingEcompOperationalEnvironmentId
107 * @param vnfOperationalEnvironmentId
110 public void createRelationship(String managingEcompOperationalEnvironmentId, String vnfOperationalEnvironmentId) {
112 AAIResourceUri ecompEnvUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure()
113 .operationalEnvironment(managingEcompOperationalEnvironmentId));
114 AAIResourceUri vnfEnvUri = AAIUriFactory.createResourceUri(
115 AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(vnfOperationalEnvironmentId));
116 AAIResourcesClient client = this.getClient();
117 client.connect(vnfEnvUri, ecompEnvUri);
121 private void logStackTrace(Exception e) {
122 StringWriter sw = new StringWriter();
123 e.printStackTrace(new PrintWriter(sw));
126 protected AAIResourcesClient getClient() {
127 return new AAIResourcesClient();