diff options
author | 2018-08-24 10:21:03 +0200 | |
---|---|---|
committer | 2018-08-24 13:03:56 +0200 | |
commit | 652faeb8067158ea4726c30ee8b2a902df3ba20a (patch) | |
tree | 6c9d88b7df98e510054cf6f5407e683ce3b3c61d /vid-app-common/src/main/java/org/onap/vid/mso | |
parent | 5adc0b0ee92d1e39ddaacd27e67a327dd5988f11 (diff) |
Replace SO client
Make SO client use Generic Rest Client
Change-Id: I8d0fdf4683f577e0c968f5175dbf42a42c041357
Issue-ID: VID-267
Signed-off-by: Piotr Darosz <piotr.darosz@nokia.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/mso')
5 files changed, 313 insertions, 160 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java index a2e32bab..00db464a 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoBusinessLogicImpl.java @@ -1,3 +1,23 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso; import com.fasterxml.jackson.annotation.JsonCreator; @@ -266,13 +286,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQ); String path = p + "/" + requestId; - RestObject<String> restObjStr = new RestObject<>(); - String str = new String(); - restObjStr.set(str); - - msoClientInterface.getOrchestrationRequest(str, "", path, restObjStr); - - return MsoUtil.wrapResponse(restObjStr); + return msoClientInterface.getOrchestrationRequest(path); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); @@ -289,13 +303,7 @@ public class MsoBusinessLogicImpl implements MsoBusinessLogic { String p = SystemProperties.getProperty(MsoProperties.MSO_REST_API_GET_ORC_REQS); String path = p + filterString; - RestObject<String> restObjStr = new RestObject<>(); - String str = new String(); - restObjStr.set(str); - - msoClientInterface.getOrchestrationRequest(str, "", path, restObjStr); - - return MsoUtil.wrapResponse(restObjStr); + return msoClientInterface.getOrchestrationRequest(path); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java index a5fb7602..3cba12f6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoInterface.java @@ -1,5 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso; +import io.joshworks.restclient.http.HttpResponse; +import io.joshworks.restclient.http.mapper.ObjectMapper; +import lombok.SneakyThrows; +import org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider; import org.onap.vid.changeManagement.RequestDetailsWrapper; import org.onap.vid.mso.rest.RequestDetails; @@ -62,7 +86,7 @@ public interface MsoInterface { MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint); - void getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject); + MsoResponseWrapper getOrchestrationRequest(String endpoint); MsoResponseWrapper getOrchestrationRequestsForDashboard(String t , String sourceId , String endpoint , RestObject restObject); @@ -87,5 +111,28 @@ public interface MsoInterface { MsoResponseWrapper removeRelationshipFromServiceInstance(RequestDetails requestDetails, String endpoint); MsoResponseWrapper addRelationshipToServiceInstance(RequestDetails requestDetails, String addRelationshipsPath); + + <T> HttpResponse<T> get(String path, Class<T> responseClass); + + <T> HttpResponse<T> post(String path, RequestDetailsWrapper<?> requestDetailsWrapper, + Class<T> responseClass); + + static ObjectMapper objectMapper() { + return new ObjectMapper() { + CustomJacksonJaxBJsonProvider mapper = new CustomJacksonJaxBJsonProvider(); + + @SneakyThrows + @Override + public <T> T readValue(String s, Class<T> aClass) { + return mapper.getMapper().readValue(s, aClass); + } + + @SneakyThrows + @Override + public String writeValue(Object o) { + return mapper.getMapper().writeValueAsString(o); + } + }; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java index 5a73a048..2372e7fb 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java @@ -1,9 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import io.joshworks.restclient.http.HttpResponse; @JsonPropertyOrder({ "status", @@ -29,6 +50,12 @@ public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface { this.raw = msoResponse.getRaw(); } + public MsoResponseWrapper2(HttpResponse<T> msoResponse) { + this.status = msoResponse.getStatus(); + this.entity = msoResponse.getBody(); + this.raw = msoResponse.getBody().toString(); + } + public MsoResponseWrapper2( @JsonProperty(value = "status", required = true) int status, @JsonProperty(value = "entity", required = true) T entity) { diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java index d2ccd0bd..722a1c4c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoUtil.java @@ -3,13 +3,14 @@ * VID * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. 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. @@ -22,6 +23,8 @@ package org.onap.vid.mso; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import io.joshworks.restclient.http.HttpResponse; +import org.apache.commons.lang3.ObjectUtils; import org.glassfish.jersey.client.ClientResponse; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; @@ -88,8 +91,17 @@ public class MsoUtil { } MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, status ); return (w); - } - + } + + public static <T> MsoResponseWrapper wrapResponse (HttpResponse<T> rs) { + MsoResponseWrapper w = new MsoResponseWrapper(); + w.setStatus (rs.getStatus()); + if(rs.getRawBody() != null) { + w.setEntity(ObjectUtils.toString(rs.getBody())); + } + return w; + } + /** * Convert pojo to string. * diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java index ae1b7a2a..9cac3e4e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MsoRestClientNew.java @@ -1,46 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018 Nokia. 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.onap.vid.mso.rest; +import com.google.common.collect.ImmutableMap; +import io.joshworks.restclient.http.HttpResponse; +import java.util.HashMap; +import java.util.Map; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import org.apache.commons.codec.binary.Base64; +import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.changeManagement.MsoRequestDetails; import org.onap.vid.changeManagement.RequestDetailsWrapper; +import org.onap.vid.client.SyncRestClient; import org.onap.vid.model.RequestReferencesContainer; import org.onap.vid.mso.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; +import org.onap.vid.utils.Logging; /** * Created by pickjonathan on 21/06/2017. */ -public class MsoRestClientNew extends RestMsoImplementation implements MsoInterface { +public class MsoRestClientNew implements MsoInterface { /** * The Constant dateFormat. */ + public static final String X_FROM_APP_ID = "X-FromAppId"; final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); private static final String START = " start"; - private final String ORIGINAL_REQUEST_ID = "originalRequestId"; + private final SyncRestClient client; + private final String baseUrl; + private final Map<String, String> commonHeaders; /** * The logger. */ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoRestClientNew.class); + public MsoRestClientNew(SyncRestClient client, String baseUrl) { + this.client = client; + this.baseUrl = baseUrl; + this.commonHeaders = initCommonHeaders(); + } + @Override public MsoResponseWrapper createSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createSvcInstance "; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override public MsoResponseWrapper createE2eSvcInstance(Object requestDetails, String endpoint) { String methodName = "createE2eSvcInstance "; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override @@ -48,8 +90,9 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf String methodName = "createVnf"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override @@ -57,160 +100,119 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf String methodName = "createNwInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override public MsoResponseWrapper createVolumeGroupInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createVolumeGroupInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override public MsoResponseWrapper createVfModuleInstance(RequestDetails requestDetails, String endpoint) { String methodName = "createVfModuleInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return createInstance(requestDetails, endpoint); + return createInstance(requestDetails, path); } @Override public MsoResponseWrapper createConfigurationInstance(org.onap.vid.mso.rest.RequestDetailsWrapper requestDetailsWrapper, String endpoint) { String methodName = "createConfigurationInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - return createInstance(requestDetailsWrapper, endpoint); + String path = baseUrl + endpoint; + + return createInstance(requestDetailsWrapper, path); } @Override public MsoResponseWrapper deleteE2eSvcInstance(Object requestDetails, String endpoint) { String methodName = "deleteE2eSvcInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - - return deleteInstance(requestDetails, endpoint); + String path = baseUrl + endpoint; + return deleteInstance(requestDetails, path); } @Override public MsoResponseWrapper deleteSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteSvcInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - - return deleteInstance(requestDetails, endpoint); + String path = baseUrl + endpoint; + return deleteInstance(requestDetails, path); } @Override public MsoResponseWrapper unassignSvcInstance(RequestDetails requestDetails, String endpoint) { String methodName = "unassignSvcInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - - RestObject<String> msoResponse = PostForObject(requestDetails, "", endpoint, String.class); - return MsoUtil.wrapResponse(msoResponse); + HttpResponse<String> response = client.post(endpoint, commonHeaders, requestDetails, String.class); + return MsoUtil.wrapResponse(response); } @Override public MsoResponseWrapper deleteVnf(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVnf"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return deleteInstance(requestDetails, endpoint); + return deleteInstance(requestDetails, path); } @Override public MsoResponseWrapper deleteVfModule(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVfModule"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return deleteInstance(requestDetails, endpoint); + return deleteInstance(requestDetails, path); } @Override public MsoResponseWrapper deleteVolumeGroupInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteVolumeGroupInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return deleteInstance(requestDetails, endpoint); + return deleteInstance(requestDetails, path); } @Override public MsoResponseWrapper deleteNwInstance(RequestDetails requestDetails, String endpoint) { String methodName = "deleteNwInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; - return deleteInstance(requestDetails, endpoint); + return deleteInstance(requestDetails, path); } @Override - public void getOrchestrationRequest(String t, String sourceId, String endpoint, RestObject restObject) { - Get(t, sourceId, endpoint, restObject); - } + public MsoResponseWrapper getOrchestrationRequest(String endpoint) { + String path = baseUrl + endpoint; - public void getManualTasks(String t, String sourceId, String endpoint, RestObject restObject) { - Get(t, sourceId, endpoint, restObject); + HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class); + return MsoUtil.wrapResponse(response); } - public MsoResponseWrapper createInstance(Object request, String path) { - String methodName = "createInstance"; - logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); - - try { - RestObject<String> restObjStr = new RestObject<String>(); - - String str = new String(); - - restObjStr.set(str); - - Post(str, request, "", path, restObjStr); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr); + public MsoResponseWrapper getManualTasks(String endpoint) { + String path = baseUrl + endpoint; - return w; - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - throw e; - } + HttpResponse<String> response = client.get(path, commonHeaders, new HashMap<>(), String.class); + return MsoUtil.wrapResponse(response); } - /** - * Delete instance. - * - * @param request the request - * @param path the path - * @return the mso response wrapper - * @throws Exception the exception - */ - public MsoResponseWrapper deleteInstance(Object request, String path) { - String methodName = "deleteInstance"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - - try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]"); - - RestObject<String> restObjStr = new RestObject<String>(); - String str = new String(); - restObjStr.set(str); - Delete(str, request, "", path, restObjStr); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr); - - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); - return w; - - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - throw e; - } - - } - - public MsoResponseWrapper getOrchestrationRequestsForDashboard(String t, String sourceId, String endpoint, RestObject restObject) { + public MsoResponseWrapper getOrchestrationRequestsForDashboard(String t, String sourceId, String path, RestObject restObject) { String methodName = "getOrchestrationRequestsForDashboard"; logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); try { - getOrchestrationRequest(t, sourceId, endpoint, restObject); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObject); + MsoResponseWrapper w = getOrchestrationRequest(path); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); return w; @@ -227,11 +229,12 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); try { - getManualTasks(t, sourceId, endpoint, restObject); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObject); + String path = baseUrl + endpoint; + + MsoResponseWrapper w =getManualTasks(path); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); - return MsoUtil.wrapResponse(restObject); + return w; } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); @@ -245,9 +248,10 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf String methodName = "completeManualTask"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Complete "); try { + String path = baseUrl + endpoint; - Post(t, requestDetails, sourceId, endpoint, restObject); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObject); + HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class); + MsoResponseWrapper w = MsoUtil.wrapResponse(response); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); return w; @@ -263,7 +267,8 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf public MsoResponseWrapper replaceVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String endpoint) { String methodName = "replaceVnf"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); - return replaceInstance(requestDetails, endpoint); + String path = baseUrl + endpoint; + return replaceInstance(requestDetails, path); } @Override @@ -271,25 +276,23 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf String methodName = "deleteConfiguration"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + pmc_endpoint; - return deleteInstance(requestDetailsWrapper, pmc_endpoint); + return deleteInstance(requestDetailsWrapper, path); } @Override - public MsoResponseWrapper setConfigurationActiveStatus(RequestDetails request, String path) { + public MsoResponseWrapper setConfigurationActiveStatus(RequestDetails request, String endpoint) { String methodName = "setConfigurationActiveStatus"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling change configuration active status, path =[" + path + "]"); - - RestObject<String> restObjStr = new RestObject<String>(); - String str = new String(); - restObjStr.set(str); - Post(str, request, "", path, restObjStr); - MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(restObjStr); + String path = baseUrl + endpoint; - return msoResponseWrapperObject; + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + + methodName + " calling change configuration active status, path =[" + path + "]"); + HttpResponse<String> response = client.post(path, commonHeaders, request, String.class); + return MsoUtil.wrapResponse(response); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); @@ -298,20 +301,16 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf } @Override - public MsoResponseWrapper setPortOnConfigurationStatus(RequestDetails request, String path) { + public MsoResponseWrapper setPortOnConfigurationStatus(RequestDetails request, String endpoint) { String methodName = "setPortOnConfigurationStatus"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); try { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling change port configuration status, path =[" + path + "]"); - - RestObject<String> restObjStr = new RestObject<String>(); - String str = new String(); - restObjStr.set(str); - Post(str, request, "", path, restObjStr); - MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(restObjStr); - - return msoResponseWrapperObject; + String path = baseUrl + endpoint; + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + + methodName + " calling change port configuration status, path =[" + path + "]"); + HttpResponse<String> response = client.post(path, commonHeaders, request, String.class); + return MsoUtil.wrapResponse(response); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); @@ -321,8 +320,9 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf @Override public MsoResponseWrapperInterface changeManagementUpdate(RequestDetailsWrapper requestDetails, String endpoint) { - RestObject<RequestReferencesContainer> msoResponse = PostForObject(requestDetails, "", endpoint, RequestReferencesContainer.class); - return new MsoResponseWrapper2<>(msoResponse); + String path = baseUrl + endpoint; + HttpResponse<RequestReferencesContainer> response = client.post(path, commonHeaders, requestDetails, RequestReferencesContainer.class); + return MsoUtil.wrapResponse(response); } public MsoResponseWrapper replaceInstance(org.onap.vid.changeManagement.RequestDetails request, String path) { @@ -330,17 +330,10 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); try { - - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Replace VNF, path =[" + path + "]"); - RestObject<String> restObjStr = new RestObject<String>(); - String str = new String(); - restObjStr.set(str); - RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - requestDetailsWrapper.requestDetails = new MsoRequestDetails(request); - - Post(str, requestDetailsWrapper, "", path, restObjStr); - MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(restObjStr); + + HttpResponse<String> response = client.post(path, commonHeaders, request, String.class); + MsoResponseWrapper msoResponseWrapperObject = MsoUtil.wrapResponse(response); int status = msoResponseWrapperObject.getStatus(); if (status == 202) { logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + @@ -365,9 +358,11 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf public MsoResponseWrapper updateVnf(org.onap.vid.changeManagement.RequestDetails requestDetails, String endpoint) { String methodName = "updateVnf"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + String path = baseUrl + endpoint; + RequestDetailsWrapper wrapper = new RequestDetailsWrapper(); wrapper.requestDetails = new MsoRequestDetails(requestDetails); - return updateInstance(requestDetails, endpoint); + return updateInstance(requestDetails, path); } public MsoResponseWrapper updateInstance(org.onap.vid.changeManagement.RequestDetails request, String path) { @@ -376,13 +371,9 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf try { logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]"); - RestObject<String> restObjStr = new RestObject<String>(); - String str = new String(); - restObjStr.set(str); - RequestDetailsWrapper requestDetailsWrapper = new RequestDetailsWrapper(); - requestDetailsWrapper.requestDetails = new MsoRequestDetails(request); - Put(str, requestDetailsWrapper, "", path, restObjStr); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObjStr); + + HttpResponse<String> response = client.post(path, commonHeaders, request, String.class); + MsoResponseWrapper w = MsoUtil.wrapResponse(response); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); return w; @@ -399,10 +390,9 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf String methodName = "activateServiceInstance"; logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start "); try { - - Post(t, requestDetails, sourceId, endpoint, restObject); - MsoResponseWrapper w = MsoUtil.wrapResponse(restObject); - + String path = baseUrl + endpoint; + HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class); + MsoResponseWrapper w = MsoUtil.wrapResponse(response); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w =" + w.getResponse()); } catch (Exception e) { @@ -419,13 +409,9 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf try { logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Remove relationship from service instance, path =[" + endpoint + "]"); - - RestObject<String> restObjStr = new RestObject<String>(); - String str = ""; - restObjStr.set(str); - Post(str, requestDetails, "", endpoint, restObjStr); - - return MsoUtil.wrapResponse(restObjStr); + String path = baseUrl + endpoint; + HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class); + return MsoUtil.wrapResponse(response); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); @@ -440,16 +426,89 @@ public class MsoRestClientNew extends RestMsoImplementation implements MsoInterf try { logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Add relationship to service instance, path =[" + addRelationshipsPath + "]"); + String path = baseUrl + addRelationshipsPath; - RestObject<String> restObjStr = new RestObject<>(); - restObjStr.set(""); - Post("", requestDetails, "", addRelationshipsPath, restObjStr); - - return MsoUtil.wrapResponse(restObjStr); + HttpResponse<String> response = client.post(path, commonHeaders, requestDetails, String.class); + return MsoUtil.wrapResponse(response); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); throw e; } } + + @Override + public <T> HttpResponse<T> get(String path, Class<T> responseClass) { + return client.get(path, commonHeaders, new HashMap<>(), responseClass); + } + + @Override + public <T> HttpResponse<T> post(String path, RequestDetailsWrapper<?> requestDetailsWrapper, + Class<T> responseClass) { + return client.post(path, commonHeaders, requestDetailsWrapper, responseClass); + } + + + private MsoResponseWrapper createInstance(Object request, String endpoint) { + String methodName = "createInstance"; + logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START); + + try { + HttpResponse<String> response = client.post(endpoint, commonHeaders, request, String.class); + return MsoUtil.wrapResponse(response); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + throw e; + } + } + + /** + * Delete instance. + * + * @param request the request + * @param path the path + * @return the mso response wrapper + * @throws Exception the exception + */ + private MsoResponseWrapper deleteInstance(Object request, String path) { + String methodName = "deleteInstance"; + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START); + + try { + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " calling Delete, path =[" + path + "]"); + + HttpResponse<String> response = client.delete(path, commonHeaders, String.class); + MsoResponseWrapper w = MsoUtil.wrapResponse(response); + + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " w=" + w.getResponse()); + return w; + + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + throw e; + } + + } + + private Map<String, String> initCommonHeaders() { + String username = SystemProperties.getProperty(MsoProperties.MSO_USER_NAME); + String password = SystemProperties.getProperty(MsoProperties.MSO_PASSWORD); + String decrypted_password = Password.deobfuscate(password); + + String authString = username + ":" + decrypted_password; + + byte[] authEncBytes = Base64.encodeBase64(authString.getBytes()); + String authStringEnc = new String(authEncBytes); + + Map<String, String> map = new HashMap<>(); + map.put(HttpHeaders.AUTHORIZATION, "Basic " + authStringEnc); + map.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + map.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + map.put(X_FROM_APP_ID, SystemProperties.getProperty(SystemProperties.APP_DISPLAY_NAME)); + map.put(SystemProperties.ECOMP_REQUEST_ID, Logging.extractOrGenerateRequestId()); + return ImmutableMap.copyOf(map); + } + }
\ No newline at end of file |