diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-common')
17 files changed, 171 insertions, 178 deletions
diff --git a/mso-api-handlers/mso-api-handler-common/pom.xml b/mso-api-handlers/mso-api-handler-common/pom.xml index 8d221c033a..d35db00478 100644 --- a/mso-api-handlers/mso-api-handler-common/pom.xml +++ b/mso-api-handlers/mso-api-handler-common/pom.xml @@ -5,7 +5,7 @@ <parent> <groupId>org.onap.so</groupId> <artifactId>mso-api-handlers</artifactId> - <version>1.3.0-SNAPSHOT</version> + <version>1.4.0-SNAPSHOT</version> </parent> @@ -18,6 +18,8 @@ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <swagger-version>1.3.0</swagger-version> <jax-rs-version>1.1.1</jax-rs-version> + <json4s-jackson-version>3.6.0</json4s-jackson-version> + <json4s-core-version>3.6.0</json4s-core-version> <reflections-version>0.9.9-RC1</reflections-version> <paranamer-version>2.5.2</paranamer-version> <scannotation-version>1.0.3</scannotation-version> @@ -62,19 +64,18 @@ <dependency> <groupId>org.json4s</groupId> <artifactId>json4s-jackson_2.12</artifactId> + <version>${json4s-jackson-version}</version> </dependency> <dependency> <groupId>org.json4s</groupId> <artifactId>json4s-core_2.12</artifactId> + <version>${json4s-core-version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> - <artifactId>javax.servlet-api</artifactId> - </dependency> - <dependency> - <groupId>org.javassist</groupId> - <artifactId>javassist</artifactId> - </dependency> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java index 9099b48f11..829f8ce30c 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/camundabeans/CamundaVIDRequest.java @@ -109,6 +109,9 @@ public class CamundaVIDRequest { @JsonProperty(CommonConstants.REQUEST_URI) private CamundaInput requestUri; + + @JsonProperty(CommonConstants.INSTANCE_GROUP_ID) + private CamundaInput instanceGroupId; @JsonProperty(CommonConstants.CAMUNDA_SERVICE_INPUT) public CamundaInput getServiceInput() { @@ -326,6 +329,14 @@ public class CamundaVIDRequest { public void setRecipeParams(CamundaInput recipeParams) { this.recipeParams = recipeParams; } + @JsonProperty(CommonConstants.INSTANCE_GROUP_ID) + public void setInstanceGroupId(CamundaInput instanceGroupIdInput) { + this.instanceGroupId = instanceGroupIdInput; + } + @JsonProperty(CommonConstants.INSTANCE_GROUP_ID) + public CamundaInput getInstanceGroupId() { + return instanceGroupId; + } @Override public String toString() { @@ -335,4 +346,6 @@ public class CamundaVIDRequest { return "CamundaRequest"; } + + } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java index 3ebad8b02c..34cfe18508 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaClient.java @@ -86,7 +86,7 @@ public class CamundaClient extends RequestClient{ if(props!=null){ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH); if(encryptedCredentials != null){ - String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY); + String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP)); if(userCredentials != null){ post.addHeader("Authorization", "Basic " + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes()))); } @@ -108,7 +108,7 @@ public class CamundaClient extends RequestClient{ if(props!=null){ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH); if(encryptedCredentials != null){ - String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY); + String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP)); if(userCredentials != null){ post.addHeader("Authorization", "Basic " + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes()))); } @@ -129,7 +129,8 @@ public class CamundaClient extends RequestClient{ msoLogger.debug(CAMUNDA_URL_MESAGE+ url); String jsonReq = wrapVIDRequest(parameterObject.getRequestId(), parameterObject.isBaseVfModule(), parameterObject.getRecipeTimeout(), parameterObject.getRequestAction(), parameterObject.getServiceInstanceId(), parameterObject.getCorrelationId(), parameterObject.getVnfId(), parameterObject.getVfModuleId(), parameterObject.getVolumeGroupId(), parameterObject.getNetworkId(), parameterObject.getConfigurationId(), - parameterObject.getServiceType(), parameterObject.getVnfType(), parameterObject.getVfModuleType(), parameterObject.getNetworkType(), parameterObject.getRequestDetails(), parameterObject.getApiVersion(), parameterObject.isaLaCarte(), parameterObject.getRequestUri(), parameterObject.getRecipeParamXsd()); + parameterObject.getServiceType(), parameterObject.getVnfType(), parameterObject.getVfModuleType(), parameterObject.getNetworkType(), parameterObject.getRequestDetails(), parameterObject.getApiVersion(), parameterObject.isaLaCarte(), parameterObject.getRequestUri(), parameterObject.getRecipeParamXsd(), + parameterObject.getInstanceGroupId()); StringEntity input = new StringEntity(jsonReq); input.setContentType(CommonConstants.CONTENT_TYPE_JSON); @@ -141,7 +142,7 @@ public class CamundaClient extends RequestClient{ if(props!=null){ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH); if(encryptedCredentials != null){ - String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY); + String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP)); if(userCredentials != null){ post.addHeader("Authorization", "Basic " + new String(DatatypeConverter.printBase64Binary(userCredentials.getBytes()))); } @@ -200,7 +201,8 @@ public class CamundaClient extends RequestClient{ int recipeTimeout, String requestAction, String serviceInstanceId, String correlationId, String vnfId, String vfModuleId, String volumeGroupId, String networkId, String configurationId, String serviceType, String vnfType, String vfModuleType, String networkType, - String requestDetails, String apiVersion, boolean aLaCarte, String requestUri, String paramXsd){ + String requestDetails, String apiVersion, boolean aLaCarte, String requestUri, String paramXsd, + String instanceGroupId){ String jsonReq = null; try{ @@ -226,6 +228,7 @@ public class CamundaClient extends RequestClient{ CamundaInput apiVersionInput = new CamundaInput(); CamundaInput requestUriInput = new CamundaInput(); CamundaInput recipeParamsInput = new CamundaInput(); + CamundaInput instanceGroupIdInput = new CamundaInput(); //host.setValue(parseURL()); requestIdInput.setValue(StringUtils.defaultString(requestId)); @@ -247,6 +250,7 @@ public class CamundaClient extends RequestClient{ apiVersionInput.setValue(StringUtils.defaultString(apiVersion)); requestUriInput.setValue(StringUtils.defaultString(requestUri)); recipeParamsInput.setValue(paramXsd); + instanceGroupIdInput.setValue(StringUtils.defaultString(instanceGroupId)); serviceInput.setValue(requestDetails); camundaRequest.setServiceInput(serviceInput); @@ -271,6 +275,7 @@ public class CamundaClient extends RequestClient{ camundaRequest.setApiVersion(apiVersionInput); camundaRequest.setRequestUri(requestUriInput); camundaRequest.setRecipeParams(recipeParamsInput); + camundaRequest.setInstanceGroupId(instanceGroupIdInput); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true); diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaTaskClient.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaTaskClient.java index 166a5c4d10..bb0a4b0172 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaTaskClient.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CamundaTaskClient.java @@ -49,7 +49,7 @@ public class CamundaTaskClient extends RequestClient{ if(props!=null){ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH); if(encryptedCredentials != null){ - String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY); + String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP)); if(userCredentials != null){ post.addHeader("Authorization", "Basic " + DatatypeConverter .printBase64Binary(userCredentials.getBytes())); @@ -80,7 +80,7 @@ public class CamundaTaskClient extends RequestClient{ if(props!=null){ encryptedCredentials = props.getProperty(CommonConstants.CAMUNDA_AUTH); if(encryptedCredentials != null){ - String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, CommonConstants.ENCRYPTION_KEY); + String userCredentials = getEncryptedPropValue(encryptedCredentials, CommonConstants.DEFAULT_BPEL_AUTH, props.getProperty(CommonConstants.ENCRYPTION_KEY_PROP)); if(userCredentials != null){ get.addHeader("Authorization", "Basic " + new String(DatatypeConverter .printBase64Binary(userCredentials.getBytes()))); diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java index 400ce567ba..b75ad9e415 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/CommonConstants.java @@ -24,7 +24,7 @@ package org.onap.so.apihandler.common; public final class CommonConstants { public static final String DEFAULT_BPEL_AUTH = "admin:admin"; - public static final String ENCRYPTION_KEY = "aa3871669d893c7fb8abbcda31b88b4f"; + public static final String ENCRYPTION_KEY_PROP = "org.onap.so.adapters.network.encryptionKey"; public static final String REQUEST_ID_HEADER = "mso-request-id"; public static final String REQUEST_TIMEOUT_HEADER = "mso-service-request-timeout"; @@ -79,6 +79,7 @@ public final class CommonConstants { public static final String X_MINOR_VERSION = "X-MinorVersion"; public static final String X_PATCH_VERSION = "X-PatchVersion"; public static final String X_LATEST_VERSION = "X-LatestVersion"; + public static final String INSTANCE_GROUP_ID = "instanceGroupId"; private CommonConstants () { // prevent creating an instance of this class diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java index 89db934985..1d18e2b02c 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/RequestClientParameter.java @@ -43,6 +43,7 @@ public class RequestClientParameter { private boolean aLaCarte; private String recipeParamXsd; private String requestUri; + private String instanceGroupId; private RequestClientParameter(Builder builder) { requestId = builder.requestId; @@ -65,6 +66,7 @@ public class RequestClientParameter { apiVersion = builder.apiVersion; aLaCarte = builder.aLaCarte; requestUri = builder.requestUri; + instanceGroupId = builder.instanceGroupId; } @@ -147,6 +149,10 @@ public class RequestClientParameter { public String getRequestUri() { return requestUri; } + + public String getInstanceGroupId() { + return instanceGroupId; + } public static class Builder { private String requestId; @@ -169,6 +175,7 @@ public class RequestClientParameter { private boolean aLaCarte = false; private String recipeParamXsd; private String requestUri; + private String instanceGroupId; public Builder setRequestId(String requestId) { this.requestId = requestId; @@ -269,10 +276,16 @@ public class RequestClientParameter { this.requestUri = requestUri; return this; } + + public Builder setInstanceGroupId(String instanceGroupId) { + this.instanceGroupId = instanceGroupId; + return this; + } public RequestClientParameter build(){ return new RequestClientParameter(this); } + } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/XMLValidator.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/XMLValidator.java index 3c72e479c7..414ac8b3cc 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/XMLValidator.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandler/common/XMLValidator.java @@ -33,7 +33,7 @@ import javax.xml.validation.Validator; import org.apache.commons.io.IOUtils; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoAlarmLogger; + import org.onap.so.logger.MsoLogger; import org.xml.sax.SAXException; @@ -55,7 +55,7 @@ public class XMLValidator { private Schema schema; private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH, XMLValidator.class); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger (); + public XMLValidator (String xsdFile){ @@ -94,7 +94,7 @@ public class XMLValidator { } catch (Exception e) { msoLogger.error (MessageEnum.APIH_CANNOT_READ_SCHEMA, "", "", MsoLogger.ErrorCode.SchemaError, "APIH cannot read schema file", e); - alarmLogger.sendAlarm ("MsoConfigurationError", MsoAlarmLogger.CRITICAL, "Unable to read the schema file"); + return "ErrorDetails: " + "Unable to read the schema file"; } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java index 3a35c23a86..03d68f88e8 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/Action.java @@ -44,5 +44,7 @@ public enum Action { scaleInstance, deactivateAndCloudDelete, scaleOut, - recreateInstance + recreateInstance, + addMembers, + removeMembers } diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java index dc52bfcc6b..fdf6b80e1c 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiException.java @@ -23,7 +23,7 @@ package org.onap.so.apihandlerinfra.exceptions; import java.util.List; -import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; + import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; public abstract class ApiException extends Exception{ @@ -34,7 +34,7 @@ public abstract class ApiException extends Exception{ private int httpResponseCode; private String messageID; private ErrorLoggerInfo errorLoggerInfo; - private AlarmLoggerInfo alarmLoggerInfo; + private List<String> variables; public ApiException(Builder builder){ @@ -44,7 +44,6 @@ public abstract class ApiException extends Exception{ this.messageID = builder.messageID; this.variables = builder.variables; this.errorLoggerInfo = builder.errorLoggerInfo; - this.alarmLoggerInfo = builder.alarmLoggerInfo; this.variables = builder.variables; } @@ -64,9 +63,6 @@ public abstract class ApiException extends Exception{ return errorLoggerInfo; } - public AlarmLoggerInfo getAlarmLoggerInfo() { - return alarmLoggerInfo; - } public List<String> getVariables() { return variables; @@ -78,7 +74,7 @@ public abstract class ApiException extends Exception{ private int httpResponseCode; private String messageID; private ErrorLoggerInfo errorLoggerInfo = null; - private AlarmLoggerInfo alarmLoggerInfo = null; + private List<String> variables = null; public Builder(String message, int httpResponseCode, String messageID) { @@ -112,11 +108,6 @@ public abstract class ApiException extends Exception{ return (T) this; } - public T alarmInfo(AlarmLoggerInfo alarmLoggerInfo){ - this.alarmLoggerInfo = alarmLoggerInfo; - return (T) this; - } - public T variables(List<String> variables) { this.variables = variables; return (T) this; diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java index 7c49eeadcc..ef19852cd1 100644 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapper.java @@ -36,10 +36,10 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; -import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; + import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoAlarmLogger; + import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.RequestError; import org.onap.so.serviceinstancebeans.ServiceException; @@ -53,7 +53,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class ApiExceptionMapper implements ExceptionMapper<ApiException> { private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, ApiExceptionMapper.class); - private static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); + private final JAXBContext context; private final Marshaller marshaller; @@ -81,14 +81,14 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> { String messageId = exception.getMessageID(); List<String> variables = exception.getVariables(); ErrorLoggerInfo errorLoggerInfo = exception.getErrorLoggerInfo(); - AlarmLoggerInfo alarmLoggerInfo = exception.getAlarmLoggerInfo(); + if (errorText.length() > 1999) { errorText = errorText.substring(0, 1999); } - writeErrorLog(exception, errorText, errorLoggerInfo, alarmLoggerInfo); + List<MediaType> typeList = Optional.ofNullable(headers.getAcceptableMediaTypes()).orElse(new ArrayList<>()); List<String> typeListString = typeList.stream().map(item -> item.toString()).collect(Collectors.toList()); @@ -139,14 +139,12 @@ public class ApiExceptionMapper implements ExceptionMapper<ApiException> { return requestErrorStr; } - protected void writeErrorLog(Exception e, String errorText, ErrorLoggerInfo errorLogInfo, AlarmLoggerInfo alarmLogInfo) { + protected void writeErrorLog(Exception e, String errorText, ErrorLoggerInfo errorLogInfo) { if( e!= null) logger.error(e); if(errorLogInfo != null) logger.error(errorLogInfo.getLoggerMessageType().toString(), errorLogInfo.getErrorSource(), errorLogInfo.getTargetEntity(), errorLogInfo.getTargetServiceName(), errorLogInfo.getErrorCode(), errorText); - if(alarmLogInfo != null){ - alarmLogger.sendAlarm(alarmLogInfo.getAlarm(),alarmLogInfo.getState(),alarmLogInfo.getDetail()); - } + } public ObjectMapper createObjectMapper(){ diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ContactCamundaException.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ContactCamundaException.java new file mode 100644 index 0000000000..e1ec46a9c1 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/exceptions/ContactCamundaException.java @@ -0,0 +1,43 @@ +/*- + * ============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.onap.so.apihandlerinfra.exceptions; + +public class ContactCamundaException extends ApiException { + + private static final String contactCamundaErrorMessage = "Unable to get process-instance history from Camunda for requestId: %s due to error: %s"; + + private ContactCamundaException(Builder builder) { + super(builder); + } + + public static class Builder extends ApiException.Builder<Builder>{ + + + public Builder(String requestId, String error, int httpResponseCode, String messageID) { + super(contactCamundaErrorMessage.format(contactCamundaErrorMessage, requestId, error),httpResponseCode,messageID); + } + + public ContactCamundaException build() { + return new ContactCamundaException(this); + } + } + +} diff --git a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/logging/AlarmLoggerInfo.java b/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/logging/AlarmLoggerInfo.java deleted file mode 100644 index 2746da4f2d..0000000000 --- a/mso-api-handlers/mso-api-handler-common/src/main/java/org/onap/so/apihandlerinfra/logging/AlarmLoggerInfo.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============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.onap.so.apihandlerinfra.logging; - -import java.io.Serializable; - -public class AlarmLoggerInfo implements Serializable{ - /** - * - */ - private static final long serialVersionUID = -6730979289437576112L; - private String alarm; - private int state; - private String detail; - - - private AlarmLoggerInfo(String alarm, int state, String detail){ - this.alarm = alarm; - this.state = state; - this.detail = detail; - } - - public int getState() { - return state; - } - - public String getAlarm() { - return alarm; - } - - public String getDetail() { - return detail; - } - - public static class Builder{ - private String alarm = ""; - private int state; - private String detail = ""; - - public Builder(String alarm, int state, String detail){ - this.alarm = alarm; - this.state = state; - this.detail = detail; - } - - public Builder alarm(String alarm){ - this.alarm = alarm; - return this; - } - - public Builder state(int state){ - this.state = state; - return this; - } - - public Builder detail(String detail){ - this.detail = detail; - return this; - } - - public AlarmLoggerInfo build(){ - return new AlarmLoggerInfo(alarm, state, detail); - } - - } -} diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java index 7a4b587fd2..7a03ce0542 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaClientTest.java @@ -23,8 +23,11 @@ package org.onap.so.apihandler.common; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import java.io.IOException; import java.nio.file.Files; @@ -38,15 +41,13 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHttpResponse; import org.apache.http.message.BasicStatusLine; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.so.apihandler.common.CamundaClient; -import org.onap.so.apihandler.common.CommonConstants; -import org.onap.so.apihandler.common.RequestClient; -import org.onap.so.apihandler.common.RequestClientFactory; import org.springframework.mock.env.MockEnvironment; import com.fasterxml.jackson.core.JsonGenerationException; @@ -64,6 +65,7 @@ public class CamundaClientTest{ @Mock private HttpClient mockHttpClient; + private static final String AUTHORIZATION_HEADER_NAME = "Authorization"; @Before public void setUp() { @@ -79,6 +81,7 @@ public class CamundaClientTest{ HttpResponse mockResponse = createResponse(200, responseBody); mockHttpClient = Mockito.mock(HttpClient.class); + ArgumentCaptor<HttpPost> httpPostCaptor = ArgumentCaptor.forClass(HttpPost.class); Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class))) .thenReturn(mockResponse); @@ -87,6 +90,8 @@ public class CamundaClientTest{ MockEnvironment environment = new MockEnvironment(); environment.setProperty("mso.camundaUR", "yourValue1"); + environment.setProperty("mso.camundaAuth", "E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE"); + environment.setProperty("org.onap.so.adapters.network.encryptionKey", "aa3871669d893c7fb8abbcda31b88b4f"); RequestClientFactory reqClientFactory = new RequestClientFactory(); @@ -107,6 +112,9 @@ public class CamundaClientTest{ response = requestClient.post(null, "reqId", null, null, null, null); assertEquals(requestClient.getType(), CommonConstants.CAMUNDA); assertEquals(statusCode, HttpStatus.SC_OK); + verify(mockHttpClient,times(2)).execute(httpPostCaptor.capture()); + assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue()); } private HttpResponse createResponse(int respStatus, @@ -132,35 +140,36 @@ public class CamundaClientTest{ @Test public void wrapVIDRequestTest() throws IOException{ - CamundaClient testClient = new CamundaClient(); - testClient.setUrl("/mso/async/services/CreateGenericALaCarteServiceInstance"); - - String requestId = "f7ce78bb-423b-11e7-93f8-0050569a796"; - boolean isBaseVfModule = true; - int recipeTimeout = 10000; - String requestAction = "createInstance"; - String serviceInstanceId = "12345679"; - String correlationId = "12345679"; - String vnfId = "234567891"; - String vfModuleId = "345678912"; - String volumeGroupId = "456789123"; - String networkId = "567891234"; - String configurationId = "678912345"; - String serviceType = "testService"; - String vnfType = "testVnf"; - String vfModuleType = "vfModuleType"; - String networkType = "networkType"; - String requestDetails = "{requestDetails: }"; - String apiVersion = "6"; - boolean aLaCarte = true; - String requestUri = "v7/serviceInstances/assign"; - - String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction, serviceInstanceId, correlationId, - vnfId, vfModuleId, volumeGroupId, networkId, configurationId, serviceType, - vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, ""); - String expected = inputStream("/WrappedVIDRequest.json"); - - assertEquals(expected, testResult); + CamundaClient testClient = new CamundaClient(); + testClient.setUrl("/mso/async/services/CreateGenericALaCarteServiceInstance"); + + String requestId = "f7ce78bb-423b-11e7-93f8-0050569a796"; + boolean isBaseVfModule = true; + int recipeTimeout = 10000; + String requestAction = "createInstance"; + String serviceInstanceId = "12345679"; + String correlationId = "12345679"; + String vnfId = "234567891"; + String vfModuleId = "345678912"; + String volumeGroupId = "456789123"; + String networkId = "567891234"; + String configurationId = "678912345"; + String serviceType = "testService"; + String vnfType = "testVnf"; + String vfModuleType = "vfModuleType"; + String networkType = "networkType"; + String requestDetails = "{requestDetails: }"; + String apiVersion = "6"; + boolean aLaCarte = true; + String requestUri = "v7/serviceInstances/assign"; + String instanceGroupId = "ff305d54-75b4-431b-adb2-eb6b9e5ff000"; + + String testResult = testClient.wrapVIDRequest(requestId, isBaseVfModule, recipeTimeout, requestAction, serviceInstanceId, correlationId, + vnfId, vfModuleId, volumeGroupId, networkId, configurationId, serviceType, + vnfType, vfModuleType, networkType, requestDetails, apiVersion, aLaCarte, requestUri, "", instanceGroupId); + String expected = inputStream("/WrappedVIDRequest.json"); + + assertEquals(expected, testResult); } @Test diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java index 69772ee7e6..2ba0e4a173 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandler/common/CamundaTaskClientTest.java @@ -21,7 +21,7 @@ package org.onap.so.apihandler.common; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -35,15 +35,13 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.so.apihandler.common.CamundaTaskClient; -import org.onap.so.apihandler.common.CommonConstants; -import org.onap.so.apihandler.common.RequestClientParameter; +import org.mockito.junit.MockitoJUnitRunner; import org.springframework.core.env.Environment; @RunWith(MockitoJUnitRunner.class) @@ -63,7 +61,8 @@ public class CamundaTaskClientTest { @Before public void init() { - when(env.getProperty(eq(CommonConstants.CAMUNDA_AUTH))).thenReturn(""); + when(env.getProperty(eq(CommonConstants.CAMUNDA_AUTH))).thenReturn("E8E19DD16CC90D2E458E8FF9A884CC0452F8F3EB8E321F96038DE38D5C1B0B02DFAE00B88E2CF6E2A4101AB2C011FC161212EE"); + when(env.getProperty(eq(CommonConstants.ENCRYPTION_KEY_PROP))).thenReturn("aa3871669d893c7fb8abbcda31b88b4f"); testedObject = new CamundaTaskClient(); httpClientMock = mock(HttpClient.class); testedObject.setClient(httpClientMock); @@ -88,6 +87,7 @@ public class CamundaTaskClientTest { testedObject.post(JSON_REQUEST); verify(httpClientMock).execute(httpPostCaptor.capture()); assertThat(httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpPostCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue()); } @Test @@ -106,6 +106,7 @@ public class CamundaTaskClientTest { testedObject.get(); verify(httpClientMock).execute(httpGetCaptor.capture()); assertThat(httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)).isNotEmpty(); + Assert.assertEquals("Basic YXBpaEJwbW46Y2FtdW5kYS1SMTUxMiE=",httpGetCaptor.getValue().getHeaders(AUTHORIZATION_HEADER_NAME)[0].getValue()); } @Test(expected = UnsupportedOperationException.class) diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java index bd3728c599..1be521952a 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/ApiExceptionTest.java @@ -26,10 +26,10 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.exceptions.*; -import org.onap.so.apihandlerinfra.logging.AlarmLoggerInfo; + import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.logger.MessageEnum; -import org.onap.so.logger.MsoAlarmLogger; + import org.onap.so.logger.MsoLogger; import java.io.IOException; @@ -101,15 +101,13 @@ public class ApiExceptionTest { @Test - public void testValidateException() throws ApiException { - AlarmLoggerInfo testLog = new AlarmLoggerInfo.Builder("MsoConfigurationError", MsoAlarmLogger.CRITICAL, - Messages.errors.get(ErrorNumbers.NO_COMMUNICATION_TO_SDNC_ADAPTER)).build(); + public void testValidateException() throws ApiException { thrown.expect(ValidateException.class); thrown.expectMessage("Test Message"); thrown.expect(hasProperty("httpResponseCode", is(HttpStatus.SC_NOT_FOUND))); thrown.expect(hasProperty("messageID", is(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR))); - thrown.expect(hasProperty("alarmLoggerInfo", sameBeanAs(testLog))); - ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).alarmInfo(testLog).build(); + + ValidateException testException = new ValidateException.Builder("Test Message", HttpStatus.SC_NOT_FOUND,ErrorNumbers.SVC_BAD_PARAMETER).messageID(ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build(); throw testException; } diff --git a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java index e666df34f9..1962f00d52 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java +++ b/mso-api-handlers/mso-api-handler-common/src/test/java/org/onap/so/apihandlerinfra/exceptions/ApiExceptionMapperTest.java @@ -25,14 +25,15 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringStartsWith.startsWith; import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyObject; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyObject; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; + import java.io.IOException; import java.io.Writer; import java.util.Arrays; @@ -48,10 +49,11 @@ import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.ApiExceptionMapper; @@ -147,14 +149,14 @@ public class ApiExceptionMapperTest { BPMNFailureException bpmnException = new BPMNFailureException.Builder("Test Message", HttpStatus.SC_NOT_FOUND, ErrorNumbers.SVC_BAD_PARAMETER).build(); when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_XML_TYPE.withCharset("UTF-8"))); mapperSpy.toResponse(bpmnException); - verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), any(List.class), eq(MediaType.APPLICATION_XML_TYPE)); + verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_XML_TYPE)); when(headers.getAcceptableMediaTypes()).thenReturn(Arrays.asList(MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8"))); mapperSpy = Mockito.spy(mapper); mapperSpy.toResponse(bpmnException); - verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), any(List.class), eq(MediaType.APPLICATION_JSON_TYPE)); + verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE)); when(headers.getAcceptableMediaTypes()).thenReturn(null); mapperSpy = Mockito.spy(mapper); mapperSpy.toResponse(bpmnException); - verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class), any(List.class), eq(MediaType.APPLICATION_JSON_TYPE)); + verify(mapperSpy, times(1)).buildServiceErrorResponse(any(String.class), any(String.class),ArgumentMatchers.isNull(), eq(MediaType.APPLICATION_JSON_TYPE)); } } diff --git a/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json index c4c7b030f9..4c716c2ae3 100644 --- a/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json +++ b/mso-api-handlers/mso-api-handler-common/src/test/resources/CamundaClientTest/WrappedVIDRequest.json @@ -1 +1 @@ -{"variables":{"bpmnRequest":{"value":"{requestDetails: }","type":"String"},"requestId":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"mso-request-id":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"isBaseVfModule":{"value":true,"type":"Boolean"},"recipeTimeout":{"value":10000,"type":"Integer"},"requestAction":{"value":"createInstance","type":"String"},"serviceInstanceId":{"value":"12345679","type":"String"},"correlationId":{"value":"12345679","type":"String"},"vnfId":{"value":"234567891","type":"String"},"vfModuleId":{"value":"345678912","type":"String"},"volumeGroupId":{"value":"456789123","type":"String"},"networkId":{"value":"567891234","type":"String"},"configurationId":{"value":"678912345","type":"String"},"serviceType":{"value":"testService","type":"String"},"vnfType":{"value":"testVnf","type":"String"},"vfModuleType":{"value":"vfModuleType","type":"String"},"networkType":{"value":"networkType","type":"String"},"recipeParams":{"value":"","type":"String"},"host":{"value":null,"type":"String"},"apiVersion":{"value":"6","type":"String"},"aLaCarte":{"value":true,"type":"Boolean"},"requestUri":{"value":"v7/serviceInstances/assign","type":"String"}}}
\ No newline at end of file +{"variables":{"bpmnRequest":{"value":"{requestDetails: }","type":"String"},"requestId":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"mso-request-id":{"value":"f7ce78bb-423b-11e7-93f8-0050569a796","type":"String"},"isBaseVfModule":{"value":true,"type":"Boolean"},"recipeTimeout":{"value":10000,"type":"Integer"},"requestAction":{"value":"createInstance","type":"String"},"serviceInstanceId":{"value":"12345679","type":"String"},"correlationId":{"value":"12345679","type":"String"},"vnfId":{"value":"234567891","type":"String"},"vfModuleId":{"value":"345678912","type":"String"},"volumeGroupId":{"value":"456789123","type":"String"},"networkId":{"value":"567891234","type":"String"},"configurationId":{"value":"678912345","type":"String"},"serviceType":{"value":"testService","type":"String"},"vnfType":{"value":"testVnf","type":"String"},"vfModuleType":{"value":"vfModuleType","type":"String"},"networkType":{"value":"networkType","type":"String"},"recipeParams":{"value":"","type":"String"},"host":{"value":null,"type":"String"},"apiVersion":{"value":"6","type":"String"},"aLaCarte":{"value":true,"type":"Boolean"},"requestUri":{"value":"v7/serviceInstances/assign","type":"String"},"instanceGroupId":{"value":"ff305d54-75b4-431b-adb2-eb6b9e5ff000","type":"String"}}}
\ No newline at end of file |