aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-03-14 02:07:32 -0400
committerRob Daugherty <rd472p@att.com>2018-03-14 04:08:41 -0400
commit38f720752af4d4aad8c4e467a288d9048659f688 (patch)
treee81066a8b5c77272e30fb57a64999573c4db4d86 /mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers
parentaee3d223f92a6f250f43e17558a2dfd576ff7294 (diff)
AT&T 1712 and 1802 release code
This is code from AT&T's 1712 and 1802 releases. Change-Id: Ie1e85851e94bc66c4d9514a0226c221939531a04 Issue-ID: SO-425 Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java145
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilder.java78
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelper.java216
3 files changed, 439 insertions, 0 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java
new file mode 100644
index 0000000000..c431da66ee
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java
@@ -0,0 +1,145 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Map;
+
+import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed;
+import org.openecomp.mso.client.aai.AAIObjectType;
+import org.openecomp.mso.client.aai.AAIResourcesClient;
+import org.openecomp.mso.client.aai.entities.AAIResultWrapper;
+import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
+import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
+import org.openecomp.mso.client.aai.entities.uri.Depth;
+import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
+import org.openecomp.mso.logger.MsoLogger;
+
+public class AAIClientHelper {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
+
+ public AAIClientHelper() {
+ super();
+ }
+
+ public AAIClientHelper(String serviceName, String requestId) {
+ super();
+ MsoLogger.setServiceName (serviceName);
+ MsoLogger.setLogContext(requestId, "");
+ }
+
+ /**
+ * Get managing ECOMP Environment Info from A&AI
+ * @param id = operationalEnvironmentId
+ * @return AAIResultWrapper object
+ */
+ public AAIResultWrapper getAaiOperationalEnvironment(String id) throws Exception {
+ try {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id);
+ uri.depth(Depth.ZERO); //Do not return relationships if any
+ AAIResourcesClient aaiClient = this.getClient();
+ AAIResultWrapper result = aaiClient.get(uri);
+ return result;
+ }
+ catch(Exception ex) {
+ logStackTrace(ex);
+ throw new AAIClientCallFailed("Call to A&AI failed!", ex);
+ }
+ }
+
+
+ /**
+ * Update managing ECOMP Environment Info from A&AI
+ * @param id = operationalEnvironmentId
+ * @param AAIOperationalEnvironment object
+ */
+ public void updateAaiOperationalEnvironment(String id, AAIOperationalEnvironment aaiRequest) throws Exception {
+ try {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id);
+ AAIResourcesClient aaiClient = this.getClient();
+ aaiClient.update(uri, aaiRequest);
+ }
+ catch(Exception ex) {
+ logStackTrace(ex);
+ throw new AAIClientCallFailed("Call to A&AI failed!", ex);
+ }
+ }
+
+
+ public void updateAaiOperationalEnvironment(String operationalEnvironmentId, Map<String, String> payload) throws Exception {
+ try {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironmentId);
+ AAIResourcesClient aaiClient = this.getClient();
+ aaiClient.update(uri, payload);
+ }
+ catch(Exception ex) {
+ logStackTrace(ex);
+ throw new AAIClientCallFailed("Call to A&AI failed!", ex);
+ }
+ }
+
+ /**
+ * Create an Operational Environment object in A&AI
+ * @param AAIOperationalEnvironment object
+ */
+ public void createOperationalEnvironment(AAIOperationalEnvironment operationalEnvironment) throws Exception {
+ try {
+ AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironment.getOperationalEnvironmentId());
+ AAIResourcesClient aaiClient = this.getClient();
+ aaiClient.create(uri, operationalEnvironment);
+ }
+ catch(Exception ex) {
+ logStackTrace(ex);
+ throw new AAIClientCallFailed("Call to A&AI failed!", ex);
+ }
+ }
+
+ /**
+ * Create a relationship between ECOMP managing and VNF Operational Environments
+ * @param managingEcompOperationalEnvironmentId
+ * @param vnfOperationalEnvironmentId
+ * @throws Exception
+ */
+ public void createRelationship(String managingEcompOperationalEnvironmentId, String vnfOperationalEnvironmentId) throws Exception {
+ try {
+ AAIResourceUri ecompEnvUri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, managingEcompOperationalEnvironmentId);
+ AAIResourceUri vnfEnvUri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, vnfOperationalEnvironmentId);
+ AAIResourcesClient aaiClient = this.getClient();
+ aaiClient.connect(vnfEnvUri, ecompEnvUri);
+ }
+ catch(Exception ex) {
+ logStackTrace(ex);
+ throw new AAIClientCallFailed("Call to A&AI failed!", ex);
+ }
+ }
+
+ private void logStackTrace(Exception e) {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ msoLogger.debug(sw.toString());
+ }
+
+ protected AAIResourcesClient getClient() {
+ return new AAIResourcesClient();
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilder.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilder.java
new file mode 100644
index 0000000000..58b78d7e8b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AAIClientObjectBuilder.java
@@ -0,0 +1,78 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
+
+import org.openecomp.mso.apihandlerinfra.tenantisolation.CloudOrchestrationRequest;
+import org.openecomp.mso.client.aai.objects.AAIOperationalEnvironment;
+
+public class AAIClientObjectBuilder {
+
+ private CloudOrchestrationRequest cloudOrchestrationRequest;
+
+ public AAIClientObjectBuilder(CloudOrchestrationRequest request) {
+ this.cloudOrchestrationRequest = request;
+ }
+
+ /**
+ * Create an AAIOperationalEnvironment object.
+ * @param environmentId
+ * @param environmentName
+ * @param environmentType
+ * @param envrionmentStatus
+ * @param tenantContext
+ * @param workloadContext
+ * @return
+ * @throws JsonProcessingException
+ */
+ @Deprecated
+ public static AAIOperationalEnvironment createAAIOperationalEnvironment(
+ String environmentId,
+ String environmentName,
+ String environmentType,
+ String envrionmentStatus,
+ String tenantContext,
+ String workloadContext) {
+
+ AAIOperationalEnvironment oe = new AAIOperationalEnvironment();
+ oe.setOperationalEnvironmentId(environmentId);
+ oe.setOperationalEnvironmentName(environmentName);
+ oe.setOperationalEnvironmentType(environmentType);
+ oe.setOperationalEnvironmentStatus(envrionmentStatus);
+ oe.setTenantContext(tenantContext);
+ oe.setWorkloadContext(workloadContext);
+
+ return oe;
+ }
+
+
+ public AAIOperationalEnvironment buildAAIOperationalEnvironment(String status) {
+ AAIOperationalEnvironment env = new AAIOperationalEnvironment();
+ env.setOperationalEnvironmentId(this.cloudOrchestrationRequest.getOperationalEnvironmentId());
+ env.setOperationalEnvironmentName(this.cloudOrchestrationRequest.getRequestDetails().getRequestInfo().getInstanceName());
+ env.setOperationalEnvironmentType(this.cloudOrchestrationRequest.getRequestDetails().getRequestParameters().getOperationalEnvironmentType().toString());
+ env.setOperationalEnvironmentStatus(status);
+ env.setTenantContext(this.cloudOrchestrationRequest.getRequestDetails().getRequestParameters().getTenantContext());
+ env.setWorkloadContext(this.cloudOrchestrationRequest.getRequestDetails().getRequestParameters().getWorkloadContext());
+ return env;
+ }
+
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelper.java
new file mode 100644
index 0000000000..2575013609
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/tenantisolation/helpers/AsdcClientHelper.java
@@ -0,0 +1,216 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.apihandlerinfra.tenantisolation.helpers;
+
+import java.util.UUID;
+
+import javax.ws.rs.core.UriBuilder;
+
+import org.json.JSONObject;
+import org.openecomp.mso.apihandlerinfra.tenantisolation.exceptions.AsdcClientCallFailed;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.properties.MsoJavaProperties;
+import org.openecomp.mso.rest.APIResponse;
+import org.openecomp.mso.rest.RESTClient;
+import org.openecomp.mso.rest.RESTConfig;
+
+public class AsdcClientHelper {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH);
+ private String className = this.getClass().getSimpleName();
+ private String methodName = "";
+ private String classMethodMessage = "";
+
+ private JSONObject asdcResponseJsonObj;
+
+ protected MsoJavaProperties properties;
+
+ public static final String ASDC_CONTENT_TYPE = "application/json";
+ public static final String ASDC_ACCEPT_TYPE = "application/json";
+
+ protected String instanceid;
+ protected String userid;
+ protected String asdcEndpoint;
+ protected String basicAuthCred;
+ protected String uri;
+
+ public static String PARTIAL_ASDC_URI = "/sdc/v1/catalog/services/";
+
+ public AsdcClientHelper(MsoJavaProperties properties) {
+ this.properties = properties;
+ setAsdcProperties();
+
+ };
+
+ /**
+ * properties should be set during instantiation of this object
+ */
+ private void setAsdcProperties() {
+ String asdcClientAuth = this.properties.getProperty("mso.asdc.client.auth", null);
+ String msoKey = this.properties.getProperty("mso.msoKey", null);
+ this.basicAuthCred = this.properties.decrypt(asdcClientAuth, msoKey);
+ this.asdcEndpoint = this.properties.getProperty("asdc.endpoint", null);
+ this.userid = this.properties.getProperty("asdc.activate.userid", null);
+ this.instanceid = this.properties.getProperty("asdc.activate.instanceid", null);
+
+ }
+
+ /**
+ * Send POST request to ASDC for operational activation
+ * @param uri - /sdc/v1/catalog/services/{serviceUUID}/distribution/{opEnvId}/activate
+ * @param jsonPayload - json string value of 'workloadContext'.
+ * @return JSONObject
+ */
+ public JSONObject postActivateOperationalEnvironment(String serviceModelVersionId, String operationalEnvironmentId, String workloadContext) {
+
+ try {
+
+ String url = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
+ msoLogger.debug(" ASDC url : " + url);
+ String jsonPayload = this.buildJsonWorkloadContext(workloadContext);
+ msoLogger.debug(" ASDC jsonPayload : " + jsonPayload);
+ asdcResponseJsonObj = new JSONObject();
+
+ if ( basicAuthCred == null || "".equals(basicAuthCred) ) {
+ String errorMessage = " ** ERROR: ASDC credentials 'mso.asdc.client.auth' not setup in properties file!";
+ throw new AsdcClientCallFailed(errorMessage);
+ }
+
+ RESTConfig config = new RESTConfig(url);
+ RESTClient client = setRestClient(config);
+ client.addAuthorizationHeader(basicAuthCred);
+
+ APIResponse apiResponse = setHttpPostResponse(client, jsonPayload);
+ int statusCode = apiResponse.getStatusCode();
+ msoLogger.debug(" ASDC return code : " + statusCode);
+ String responseData = apiResponse.getResponseBodyAsString();
+ msoLogger.debug(" ASDC responseData : " + responseData);
+ asdcResponseJsonObj = enhanceJsonResponse(new JSONObject(responseData), statusCode);
+
+ } catch (Exception ex) {
+ msoLogger.debug("calling ASDC Exception message: " + ex.getMessage());
+ String errorMessage = " Encountered Error while calling ASDC POST Activate. " + ex.getMessage();
+ msoLogger.debug(errorMessage);
+ asdcResponseJsonObj.put("statusCode", "500");
+ asdcResponseJsonObj.put("messageId", "");
+ asdcResponseJsonObj.put("message", errorMessage);
+
+ }
+ return asdcResponseJsonObj;
+
+ }
+
+ /**
+ * set RESTClient
+ * @return RestClient object
+ */
+ public RESTClient setRestClient(RESTConfig config) throws Exception {
+
+ RESTClient client = new RESTClient(config).addHeader("X-ECOMP-InstanceID", instanceid)
+ .addHeader("X-ECOMP-RequestID", UUID.randomUUID().toString())
+ .addHeader("Content-Type", AsdcClientHelper.ASDC_CONTENT_TYPE)
+ .addHeader("Accept", AsdcClientHelper.ASDC_ACCEPT_TYPE)
+ .addHeader("USER_ID", userid);
+ return client;
+
+ }
+
+ public APIResponse setHttpPostResponse(RESTClient client, String jsonPayload) throws Exception {
+ return client.httpPost(jsonPayload);
+
+ }
+
+
+ public JSONObject enhanceJsonResponse(JSONObject asdcResponseJsonObj, int statusCode) {
+
+ if (statusCode == 202) { // Accepted
+ asdcResponseJsonObj.put("statusCode", Integer.toString(statusCode));
+ asdcResponseJsonObj.put("messageId", "");
+ asdcResponseJsonObj.put("message", "Success");
+
+ } else { // error
+ String message = "Undefined Error Message!";
+ String messageId = "";
+ if (asdcResponseJsonObj.has("requestError") ) {
+ JSONObject requestErrorObj = asdcResponseJsonObj.getJSONObject("requestError");
+ if (asdcResponseJsonObj.getJSONObject("requestError").has("serviceException") ) {
+ message = requestErrorObj.getJSONObject("serviceException").getString("text");
+ messageId = requestErrorObj.getJSONObject("serviceException").getString("messageId");
+ }
+ if (asdcResponseJsonObj.getJSONObject("requestError").has("policyException") ) {
+ message = requestErrorObj.getJSONObject("policyException").getString("text");
+ messageId = requestErrorObj.getJSONObject("policyException").getString("messageId");
+ }
+
+ }
+ asdcResponseJsonObj.put("statusCode", Integer.toString(statusCode));
+ asdcResponseJsonObj.put("messageId", messageId);
+ asdcResponseJsonObj.put("message", message);
+ }
+
+ return asdcResponseJsonObj;
+
+ }
+
+ /**
+ * Build Uri
+ * @return String uri
+ */
+ public String buildUriBuilder(String serviceModelVersionId, String operationalEnvironmentId) {
+ String path = serviceModelVersionId + "/distribution/" + operationalEnvironmentId +"/activate";
+ UriBuilder uriBuilder = UriBuilder.fromPath(asdcEndpoint + AsdcClientHelper.PARTIAL_ASDC_URI)
+ .path(path);
+ return uriBuilder.build().toString();
+ }
+
+ /**
+ * Build JSON context
+ * @return String json
+ */
+ public String buildJsonWorkloadContext(String workloadContext) {
+ return new JSONObject().put("workloadContext", workloadContext).toString();
+
+ }
+
+ /**
+ * get asdc instanceId of this object
+ */
+ public String getAsdcInstanceId() {
+ return this.instanceid;
+ }
+
+ /**
+ * get asdc asdcEndpoint of this object
+ */
+ public String getAsdcEndpoint() {
+ return this.asdcEndpoint;
+ }
+
+ /**
+ * get asdc asdcUserId of this object
+ */
+ public String getAsdcUserId() {
+ return this.userid;
+ }
+
+
+
+}