summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java26
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java5
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java10
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java140
5 files changed, 106 insertions, 77 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java
index fe105a7637..d824696147 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Constants.java
@@ -49,4 +49,6 @@ public class Constants {
public final static String VNF_REQUEST_SCOPE = "vnf";
public final static String SERVICE_INSTANCE_PATH = "/serviceInstances";
public final static String SERVICE_INSTANTIATION_PATH = "/serviceInstantiation";
+ public final static String ORCHESTRATION_REQUESTS_PATH = "/orchestrationRequests";
+
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
index 753e712d71..c9f32d9705 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java
@@ -23,12 +23,14 @@ package org.onap.so.apihandlerinfra;
import java.io.IOException;
import java.io.StringWriter;
+import java.net.URL;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Optional;
import java.util.StringTokenizer;
import javax.ws.rs.core.MultivaluedMap;
@@ -65,6 +67,7 @@ import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
import org.onap.so.exceptions.ValidationException;
+import org.onap.so.logger.LogConstants;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
@@ -80,6 +83,7 @@ import org.onap.so.serviceinstancebeans.RequestParameters;
import org.onap.so.serviceinstancebeans.Service;
import org.onap.so.serviceinstancebeans.ServiceException;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
@@ -266,6 +270,7 @@ public class MsoRequest {
aq.setRequestId (requestId);
aq.setRequestAction(action.toString());
aq.setAction(action.toString());
+ aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
@@ -386,6 +391,7 @@ public class MsoRequest {
aq.setRequestId (requestId);
aq.setRequestAction(action.name());
aq.setAction(action.name());
+ aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
@@ -429,6 +435,7 @@ public class MsoRequest {
request.setRequestBody(requestJSON);
Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis());
request.setEndTime(endTimeStamp);
+ request.setRequestUrl(MDC.get(LogConstants.HTTP_URL));
requestsDbClient.save(request);
} catch (Exception e) {
msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
@@ -742,4 +749,23 @@ public class MsoRequest {
return vnfType;
}
+
+ public Optional<URL> buildSelfLinkUrl(String url, String requestId) {
+ Optional<URL> selfLinkUrl = Optional.empty();
+ String version = "";
+ try {
+ URL aUrl = new URL(url);
+ String aPath = aUrl.getPath();
+ if (aPath.indexOf("/v") == -1) {
+ version = aPath.substring(aPath.indexOf("/V"), aPath.indexOf("/V")+4);
+ } else {
+ version = aPath.substring(aPath.indexOf("/v"), aPath.indexOf("/v")+4);
+ }
+ String selfLinkPath = Constants.ORCHESTRATION_REQUESTS_PATH.concat(version).concat(requestId);
+ selfLinkUrl = Optional.of(new URL(aUrl.getProtocol(), aUrl.getHost(), aUrl.getPort(), selfLinkPath));
+ } catch (Exception e) {
+ selfLinkUrl = Optional.empty(); // ignore
+ }
+ return selfLinkUrl;
+ }
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
index 50d2639b2d..0c0b70b6dd 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
@@ -270,6 +270,7 @@ public class OrchestrationRequests {
request.setRequestId(iar.getRequestId());
request.setRequestScope(iar.getRequestScope());
request.setRequestType(iar.getRequestAction());
+ String rollbackStatusMessage = iar.getRollbackStatusMessage();
InstanceReferences ir = new InstanceReferences();
if(iar.getNetworkId() != null)
@@ -342,6 +343,10 @@ public class OrchestrationRequests {
if(iar.getProgress() != null){
status.setPercentProgress(iar.getProgress().intValue());
}
+
+ if(rollbackStatusMessage != null){
+ status.setRollbackStatusMessage(rollbackStatusMessage);
+ }
request.setRequestStatus(status);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index e2b12349c1..cb66209fc9 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -95,6 +95,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
+import java.net.URL;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
@@ -111,7 +112,7 @@ public class ServiceInstances {
private static String NAME = "name";
private static String VALUE = "value";
private static final String SAVE_TO_DB = "save instance to db";
-
+
@Autowired
private Environment env;
@@ -873,6 +874,13 @@ public class ServiceInstances {
try {
ObjectMapper mapper = new ObjectMapper();
jsonResponse = mapper.readValue(camundaResp.getResponse(), ServiceInstancesResponse.class);
+ jsonResponse.getRequestReferences().setRequestId(requestId);
+ Optional<URL> selfLinkUrl = msoRequest.buildSelfLinkUrl(currentActiveReq.getRequestUrl(), requestId);
+ if(selfLinkUrl.isPresent()){
+ jsonResponse.getRequestReferences().setRequestSelfLink(selfLinkUrl.get());
+ } else {
+ jsonResponse.getRequestReferences().setRequestSelfLink(null);
+ }
} catch (IOException e) {
msoLogger.error(e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, MsoLogger.ErrorCode.SchemaError).errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build();
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java
index 804eb696cb..8a4d561fbd 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/SDCClientHelper.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,6 +20,9 @@
package org.onap.so.apihandlerinfra.tenantisolation.helpers;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
import java.util.UUID;
import javax.ws.rs.core.Response;
@@ -32,13 +35,11 @@ import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
+import org.onap.so.client.HttpClient;
import org.onap.so.logger.MessageEnum;
import org.onap.so.logger.MsoLogger;
-import org.onap.so.rest.APIResponse;
-import org.onap.so.rest.RESTClient;
-import org.onap.so.rest.RESTConfig;
-import org.onap.so.rest.RESTException;
import org.onap.so.utils.CryptoUtils;
+import org.onap.so.utils.TargetEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -47,12 +48,12 @@ public class SDCClientHelper {
private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.APIH, SDCClientHelper.class);
private static final String SDC_CONTENT_TYPE = "application/json";
- private static final String SDC_ACCEPT_TYPE = "application/json";
+ private static final String SDC_ACCEPT_TYPE = "application/json";
private static String PARTIAL_SDC_URI = "/sdc/v1/catalog/services/";
-
+
private static String MESSAGE_UNDEFINED_ERROR = "Undefined Error Message!";
- private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC.";
-
+ private static String MESSAGE_UNEXPECTED_FORMAT = "Unexpected response format from SDC.";
+
@Value("${mso.sdc.endpoint}")
private String sdcEndpoint;
@Value("${mso.sdc.activate.userid}")
@@ -63,23 +64,23 @@ public class SDCClientHelper {
private String sdcClientAuth;
@Value("${mso.msoKey}")
private String msoKey;
-
+
/**
* Send POST request to SDC for operational activation
* @param serviceModelVersionI - String
* @param operationalEnvironmentId - String
- * @param workloadContext - String
+ * @param workloadContext - String
* @return sdcResponseJsonObj - JSONObject object
- * @throws JSONException
- */
+ * @throws JSONException
+ */
public JSONObject postActivateOperationalEnvironment(String serviceModelVersionId, String operationalEnvironmentId, String workloadContext) throws ApiException {
JSONObject sdcResponseJsonObj = new JSONObject();
-
+
try {
- String url = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
+ String urlString = this.buildUriBuilder(serviceModelVersionId, operationalEnvironmentId);
String jsonPayload = this.buildJsonWorkloadContext(workloadContext);
String basicAuthCred = getBasicAuth();
-
+
if ( basicAuthCred == null || "".equals(basicAuthCred) ) {
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build();
ValidateException validateException = new ValidateException.Builder(" SDC credentials 'mso.sdc.client.auth' not setup in properties file!",
@@ -87,148 +88,135 @@ public class SDCClientHelper {
throw validateException;
}
-
- RESTConfig config = new RESTConfig(url);
- RESTClient client = setRestClient(config);
- client.addAuthorizationHeader(basicAuthCred);
-
- APIResponse apiResponse = setHttpPostResponse(client, jsonPayload);
- int statusCode = apiResponse.getStatusCode();
-
- String responseData = apiResponse.getResponseBodyAsString();
+
+ URL url = new URL(urlString);
+
+ HttpClient httpClient = new HttpClient(url, "application/json", TargetEntity.SDC);
+ httpClient.addBasicAuthHeader(sdcClientAuth, msoKey);
+
+ Response apiResponse = setHttpPostResponse(httpClient, jsonPayload);
+ int statusCode = apiResponse.getStatus();;
+
+ String responseData = apiResponse.readEntity(String.class);
sdcResponseJsonObj = enhanceJsonResponse(new JSONObject(responseData), statusCode);
-
+
} catch (Exception ex) {
msoLogger.debug("calling SDC Exception message: " + ex.getMessage());
String errorMessage = " Encountered Error while calling SDC POST Activate. " + ex.getMessage();
msoLogger.debug(errorMessage);
- sdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
- sdcResponseJsonObj.put("messageId", "");
+ sdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ sdcResponseJsonObj.put("messageId", "");
sdcResponseJsonObj.put("message", errorMessage);
}
return sdcResponseJsonObj;
}
-
- /**
- * set RESTClient
- * @param config - RESTConfig object
- * @return client - RestClient object
- */
- public RESTClient setRestClient(RESTConfig config) throws Exception {
- RESTClient client = new RESTClient(config).addHeader("X-ECOMP-InstanceID", sdcActivateInstanceId)
- .addHeader("X-ECOMP-RequestID", UUID.randomUUID().toString())
- .addHeader("Content-Type", SDCClientHelper.SDC_CONTENT_TYPE)
- .addHeader("Accept", SDCClientHelper.SDC_ACCEPT_TYPE)
- .addHeader("USER_ID", sdcActivateUserId);
- return client;
- }
-
+
/**
- * set HttpPostResponse
+ * set HttpPostResponse
* @param config - RESTConfig object
* @param jsonPayload - String
* @return client - RestClient object
- */
- public APIResponse setHttpPostResponse(RESTClient client, String jsonPayload) throws ApiException {
+ */
+ public Response setHttpPostResponse(HttpClient client, String jsonPayload) throws ApiException {
try {
- return client.httpPost(jsonPayload);
- }catch(RESTException ex){
+ return client.post(jsonPayload);
+ }catch(Exception ex){
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_GENERAL_EXCEPTION, MsoLogger.ErrorCode.BusinessProcesssError).build();
ValidateException validateException = new ValidateException.Builder("Bad request could not post payload",
HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(ex).errorInfo(errorLoggerInfo).build();
throw validateException;
}
- }
-
+ }
+
/**
- * enhance Response
+ * enhance Response
* @param sdcResponseJsonObj - JSONObject object
* @param statusCode - int
* @return enhancedAsdcResponseJsonObj - JSONObject object
- */
+ */
public JSONObject enhanceJsonResponse(JSONObject sdcResponseJsonObj, int statusCode) throws JSONException {
JSONObject enhancedAsdcResponseJsonObj = new JSONObject();
String message = "";
- String messageId = "";
-
+ String messageId = "";
+
if (statusCode == Response.Status.ACCEPTED.getStatusCode()) { // Accepted
- enhancedAsdcResponseJsonObj.put("distributionId", sdcResponseJsonObj.get("distributionId"));
+ enhancedAsdcResponseJsonObj.put("distributionId", sdcResponseJsonObj.get("distributionId"));
enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode));
enhancedAsdcResponseJsonObj.put("messageId", "");
- enhancedAsdcResponseJsonObj.put("message", "Success");
-
+ enhancedAsdcResponseJsonObj.put("message", "Success");
+
} else { // error
if (sdcResponseJsonObj.has("requestError") ) {
JSONObject requestErrorObj = sdcResponseJsonObj.getJSONObject("requestError");
if (sdcResponseJsonObj.getJSONObject("requestError").has("serviceException") ) {
message = requestErrorObj.getJSONObject("serviceException").getString("text");
messageId = requestErrorObj.getJSONObject("serviceException").getString("messageId");
- }
+ }
if (sdcResponseJsonObj.getJSONObject("requestError").has("policyException") ) {
message = requestErrorObj.getJSONObject("policyException").getString("text");
messageId = requestErrorObj.getJSONObject("policyException").getString("messageId");
}
- enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode));
+ enhancedAsdcResponseJsonObj.put("statusCode", Integer.toString(statusCode));
enhancedAsdcResponseJsonObj.put("messageId", messageId);
enhancedAsdcResponseJsonObj.put("message", message);
- } else {
+ } else {
// unexpected format
- enhancedAsdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
+ enhancedAsdcResponseJsonObj.put("statusCode", String.valueOf(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
enhancedAsdcResponseJsonObj.put("messageId", MESSAGE_UNDEFINED_ERROR);
enhancedAsdcResponseJsonObj.put("message", MESSAGE_UNEXPECTED_FORMAT);
}
}
return enhancedAsdcResponseJsonObj;
-
+
}
-
+
/**
- * Build Uri
+ * Build Uri
* @param serviceModelVersionId - String
* @param operationalEnvironmentId - String
* @return uriBuilder - String
- */
+ */
public String buildUriBuilder(String serviceModelVersionId, String operationalEnvironmentId) {
String path = serviceModelVersionId + "/distribution/" + operationalEnvironmentId +"/activate";
UriBuilder uriBuilder = UriBuilder.fromPath(sdcEndpoint + SDCClientHelper.PARTIAL_SDC_URI)
.path(path);
return uriBuilder.build().toString();
}
-
+
/**
- * Build JSON context
+ * Build JSON context
* @param workloadContext - String
* @return String json
- * @throws JSONException
- */
+ * @throws JSONException
+ */
public String buildJsonWorkloadContext(String workloadContext) throws JSONException {
return new JSONObject().put("workloadContext", workloadContext).toString();
-
+
}
-
+
/**
- * decrypt value
+ * decrypt value
* @param toDecrypt - String
* @param msokey - String
* @return result - String
- */
+ */
public synchronized String decrypt(String toDecrypt, String msokey){
String result = null;
try {
result = CryptoUtils.decrypt(toDecrypt, msokey);
-
+
}
catch (Exception e) {
msoLogger.debug("Failed to decrypt credentials: " + toDecrypt, e);
}
return result;
}
-
+
private String getBasicAuth() {
return decrypt(sdcClientAuth, msoKey);
}