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.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
23 import java.io.PrintWriter;
24 import java.io.StringWriter;
27 import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed;
28 import org.openecomp.mso.client.aai.AAIObjectType;
29 import org.openecomp.mso.client.aai.AAIResourcesClient;
30 import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
31 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
32 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
33 import org.openecomp.mso.client.aai.entities.uri.Depth;
34 import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
35 import org.openecomp.mso.logger.MsoLogger;
37 public class AAIClientHelper {
39 private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
41 public AAIClientHelper() {
45 public AAIClientHelper(String serviceName, String requestId) {
47 MsoLogger.setServiceName (serviceName);
48 MsoLogger.setLogContext(requestId, "");
52 * Get managing ECOMP Environment Info from A&AI
53 * @param id = operationalEnvironmentId
54 * @return AAIResultWrapper object
56 public AAIResultWrapper getAaiOperationalEnvironment(String id) throws Exception {
58 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id);
59 uri.depth(Depth.ZERO); //Do not return relationships if any
60 AAIResourcesClient aaiClient = this.getClient();
61 AAIResultWrapper result = aaiClient.get(uri);
66 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
72 * Update managing ECOMP Environment Info from A&AI
73 * @param id = operationalEnvironmentId
74 * @param AAIOperationalEnvironment object
76 public void updateAaiOperationalEnvironment(String id, AAIOperationalEnvironment aaiRequest) throws Exception {
78 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id);
79 AAIResourcesClient aaiClient = this.getClient();
80 aaiClient.update(uri, aaiRequest);
84 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
89 public void updateAaiOperationalEnvironment(String operationalEnvironmentId, Map<String, String> payload) throws Exception {
91 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironmentId);
92 AAIResourcesClient aaiClient = this.getClient();
93 aaiClient.update(uri, payload);
97 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
102 * Create an Operational Environment object in A&AI
103 * @param AAIOperationalEnvironment object
105 public void createOperationalEnvironment(AAIOperationalEnvironment operationalEnvironment) throws Exception {
107 AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironment.getOperationalEnvironmentId());
108 AAIResourcesClient aaiClient = this.getClient();
109 aaiClient.create(uri, operationalEnvironment);
111 catch(Exception ex) {
113 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
118 * Create a relationship between ECOMP managing and VNF Operational Environments
119 * @param managingEcompOperationalEnvironmentId
120 * @param vnfOperationalEnvironmentId
123 public void createRelationship(String managingEcompOperationalEnvironmentId, String vnfOperationalEnvironmentId) throws Exception {
125 AAIResourceUri ecompEnvUri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, managingEcompOperationalEnvironmentId);
126 AAIResourceUri vnfEnvUri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, vnfOperationalEnvironmentId);
127 AAIResourcesClient aaiClient = this.getClient();
128 aaiClient.connect(vnfEnvUri, ecompEnvUri);
130 catch(Exception ex) {
132 throw new AAIClientCallFailed("Call to A&AI failed!", ex);
136 private void logStackTrace(Exception e) {
137 StringWriter sw = new StringWriter();
138 e.printStackTrace(new PrintWriter(sw));
139 msoLogger.debug(sw.toString());
142 protected AAIResourcesClient getClient() {
143 return new AAIResourcesClient();