summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2020-01-09 15:48:07 +0000
committerGerrit Code Review <gerrit@onap.org>2020-01-09 15:48:07 +0000
commit1a38683847c91ec6f3861b83582ce7441d3050ca (patch)
treec89079dd7847bae0977075e5e3c62557e2ec7331 /vid-app-common/src/main
parent2d701e93373c70e33c2f797d7b2c177cfe96bc2e (diff)
parent6b5dd86a3557e8eed2c4584f5d16df5654cbc57b (diff)
Merge "Fix the format of supplementary file and user params for aLaCarte requests"
Diffstat (limited to 'vid-app-common/src/main')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt47
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java35
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/UserParamsContainer.kt40
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/utils/Logging.java3
5 files changed, 88 insertions, 44 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
index e46a24f78..063ef6e53 100644
--- a/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/job/command/MsoRequestBuilder.kt
@@ -11,11 +11,12 @@ import org.onap.vid.changeManagement.RequestDetailsWrapper
import org.onap.vid.model.serviceInstantiation.*
import org.onap.vid.mso.model.*
import org.onap.vid.mso.model.BaseResourceInstantiationRequestDetails.*
+import org.onap.vid.mso.model.ServiceInstantiationRequestDetails.UserParamNameAndValue
import org.onap.vid.mso.rest.SubscriberInfo
import org.onap.vid.properties.Features
import org.onap.vid.services.AsyncInstantiationBusinessLogic
import org.onap.vid.services.CloudOwnerService
-import org.onap.vid.utils.JACKSON_OBJECT_MAPPER
+import org.onap.vid.services.UserParamsContainer
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import org.togglz.core.manager.FeatureManager
@@ -108,7 +109,7 @@ class MsoRequestBuilder
//cloud configuration
val cloudConfiguration = generateCloudConfiguration(vfModuleDetails.lcpCloudRegionId, vfModuleDetails.tenantId)
- val userParams = aggregateAllInstanceParams(extractActualInstanceParams(vfModuleDetails.instanceParams), vfModuleDetails.supplementaryParams)
+ val userParams = UserParamsContainer(extractActualInstanceParams(vfModuleDetails.instanceParams), vfModuleDetails.supplementaryParams)
//related instance list
val relatedInstanceList = generateRelatedInstances(mapOf(serviceInstanceId to serviceModelInfo, vnfInstanceId to vnfModelInfo))
@@ -118,7 +119,7 @@ class MsoRequestBuilder
relatedInstanceList.add(RelatedInstance(volumeGroupModel, vgInstanceId, vfModuleDetails.volumeGroupInstanceName))
}
- return RequestDetailsWrapper(VfModuleOrVolumeGroupRequestDetails(vfModuleDetails.modelInfo, cloudConfiguration, requestInfo, relatedInstanceList, requestParameters(userParams)))
+ return RequestDetailsWrapper(VfModuleOrVolumeGroupRequestDetails(vfModuleDetails.modelInfo, cloudConfiguration, requestInfo, relatedInstanceList, requestParameters(userParams.toALaCarte())))
}
fun generateVfModuleInstantiationRequest(
@@ -153,8 +154,8 @@ class MsoRequestBuilder
fun generateVolumeGroupInstantiationRequest(vfModuleDetails: VfModule, serviceModelInfo: ModelInfo, serviceInstanceId: String, vnfModelInfo: ModelInfo, vnfInstanceId: String, userId: String, testApi: String?): RequestDetailsWrapper<VolumeGroupRequestDetails> {
val requestInfo = generateRequestInfo(vfModuleDetails.volumeGroupInstanceName, ResourceType.VOLUME_GROUP, vfModuleDetails.isRollbackOnFailure, null, userId)
val cloudConfiguration = generateCloudConfiguration(vfModuleDetails.lcpCloudRegionId, vfModuleDetails.tenantId)
- val userParams = aggregateAllInstanceParams(extractActualInstanceParams(vfModuleDetails.instanceParams), vfModuleDetails.supplementaryParams)
- val requestParameters = RequestParametersVfModuleOrVolumeGroupInstantiation(userParams, vfModuleDetails.isUsePreload, testApi)
+ val userParams = UserParamsContainer(extractActualInstanceParams(vfModuleDetails.instanceParams), vfModuleDetails.supplementaryParams)
+ val requestParameters = RequestParametersVfModuleOrVolumeGroupInstantiation(userParams.toALaCarte(), vfModuleDetails.isUsePreload, testApi)
val relatedInstances = generateRelatedInstances(mapOf(serviceInstanceId to serviceModelInfo, vnfInstanceId to vnfModelInfo))
vfModuleDetails.modelInfo.modelType = "volumeGroup"
@@ -283,39 +284,17 @@ class MsoRequestBuilder
private fun convertVfModuleMapToList(vfModules: Map<String, Map<String, VfModule>>): List<VfModuleMacro> {
return vfModules.values.stream().flatMap { vfModule ->
vfModule.values.stream().map { item ->
- val aggregatedParams = aggregateAllInstanceParams(extractActualInstanceParams(item.instanceParams), item.supplementaryParams)
- val aggregatedParamsConverted = JACKSON_OBJECT_MAPPER.convertValue(aggregatedParams, List::class.java)
+ val userParams = UserParamsContainer(extractActualInstanceParams(item.instanceParams), item.supplementaryParams)
VfModuleMacro(
item.modelInfo,
item.instanceName,
item.volumeGroupInstanceName,
- aggregatedParamsConverted as List<Map<String, String>>)
+ userParams.toMacroPost1806())
}
}.collect(Collectors.toList<VfModuleMacro>())
}
- fun aggregateAllInstanceParams(instanceParams: Map<String, String>?, supplementaryParams: Map<String, String>?): List<UserParamMap<String, String>> {
- var instanceParamsFinal: Map<String, String> = instanceParams ?: emptyMap()
- val supplementaryParamsFinal: Map<String, String> = supplementaryParams ?: emptyMap()
-
- if (!(instanceParamsFinal.isEmpty() && supplementaryParamsFinal.isEmpty())) {
- //remove duplicate keys from instanceParams if exist in supplementaryParams
- instanceParamsFinal = instanceParamsFinal.entries.stream()
- .filter { m -> !supplementaryParamsFinal.containsKey(m.key) }
- .collect(Collectors.toMap({ it.key }, { it.value }))
-
- //aggregate the 2 collections and format them as UserParamMap
- val aggregatedParams = UserParamMap<String, String>()
- aggregatedParams.putAll(instanceParamsFinal)
- aggregatedParams.putAll(supplementaryParamsFinal)
-
- return mutableListOf(aggregatedParams)
- }
-
- return emptyList()
- }
-
//Make sure we always get a one Map from InstanceParams
private fun extractActualInstanceParams(originalInstanceParams: List<MutableMap<String, String>>?): MutableMap<String, String> {
return if (originalInstanceParams.isNullOrEmpty() || originalInstanceParams[0].isNullOrEmpty()) {
@@ -394,14 +373,14 @@ class MsoRequestBuilder
}
}
- private fun generateUserParamList(): List<ServiceInstantiationRequestDetails.UserParamNameAndValue> {
+ private fun generateUserParamList(): List<UserParamNameAndValue> {
return emptyList()
}
fun generateMacroServicePre1806InstantiationRequest(payload: ServiceInstantiation, userId: String): RequestDetailsWrapper<ServiceInstantiationRequestDetails> {
val requestInfo = ServiceInstantiationRequestDetails.RequestInfo(payload.instanceName, payload.productFamilyId, VID_SOURCE, payload.isRollbackOnFailure, userId)
- val userParams = generateUserParamsNameAndValue(payload.instanceParams)
- val requestParameters = ServiceInstantiationRequestDetails.RequestParameters(payload.subscriptionServiceType, false, userParams)
+ val userParams = UserParamsContainer(generateSingleMapFromInstanceParams(payload.instanceParams), emptyList())
+ val requestParameters = ServiceInstantiationRequestDetails.RequestParameters(payload.subscriptionServiceType, false, userParams.toMacroPre1806())
val subscriberInfo = generateSubscriberInfoPre1806(payload)
val project = if (payload.projectName != null) ServiceInstantiationRequestDetails.Project(payload.projectName) else null
val owningEntity = ServiceInstantiationRequestDetails.ServiceInstantiationOwningEntity(payload.owningEntityId, payload.owningEntityName)
@@ -419,8 +398,8 @@ class MsoRequestBuilder
relatedInstanceList))
}
- private fun generateUserParamsNameAndValue(instanceParams: List<Map<String, String>>): List<ServiceInstantiationRequestDetails.UserParamNameAndValue> {
- return instanceParams.getOrElse(0) {emptyMap()}.map{ x-> ServiceInstantiationRequestDetails.UserParamNameAndValue(x.key, x.value)}
+ private fun generateSingleMapFromInstanceParams(instanceParams: List<Map<String, String>>): Map<String, String> {
+ return if (instanceParams.isNullOrEmpty()) emptyMap() else instanceParams[0]
}
private fun generateSubscriberInfoPre1806(payload: ServiceInstantiation): SubscriberInfo {
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java
index 89e25e662..d04e679e6 100644
--- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java
+++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java
@@ -33,6 +33,7 @@ import javax.annotation.Nullable;
import org.onap.vid.job.JobAdapter;
import org.onap.vid.job.JobType;
import org.onap.vid.mso.model.ModelInfo;
+import org.onap.vid.mso.model.ServiceInstantiationRequestDetails.UserParamNameAndValue;
/**
* The Class VfModule.
@@ -42,7 +43,7 @@ public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest
@JsonInclude(NON_NULL) @JsonProperty("volumeGroupName") private final String volumeGroupInstanceName;
@JsonInclude(NON_NULL) @JsonProperty("sdncPreLoad") private Boolean usePreload;
- private Map<String, String> supplementaryParams;
+ private List<UserParamNameAndValue> supplementaryParams;
@JsonInclude(NON_NULL)
private final Boolean retainVolumeGroups;
@@ -58,7 +59,7 @@ public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest
@JsonProperty("legacyRegion") String legacyRegion,
@JsonProperty("tenantId") String tenantId,
@JsonProperty("instanceParams") List<Map<String, String>> instanceParams,
- @JsonProperty("supplementaryFileContent") Map<String, String> supplementaryParams,
+ @JsonProperty("supplementaryFileContent") List<UserParamNameAndValue> supplementaryParams,
@JsonProperty("rollbackOnFailure") boolean rollbackOnFailure,
@JsonProperty("sdncPreLoad") @JsonAlias("usePreload") Boolean usePreload,
@JsonProperty("instanceId") String instanceId,
@@ -86,7 +87,7 @@ public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest
return usePreload;
}
- public Map<String, String> getSupplementaryParams() {
+ public List<UserParamNameAndValue> getSupplementaryParams() {
return supplementaryParams;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java
index e610d6c40..acbf778ea 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/model/ServiceInstantiationRequestDetails.java
@@ -20,15 +20,16 @@
package org.onap.vid.mso.model;
+import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
+import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
-import org.onap.vid.mso.rest.SubscriberInfo;
-
import java.util.List;
import java.util.Map;
-
-import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
-import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL;
+import java.util.Objects;
+import org.onap.vid.mso.rest.SubscriberInfo;
public class ServiceInstantiationRequestDetails {
@@ -122,7 +123,11 @@ public class ServiceInstantiationRequestDetails {
private final String name;
private final String value;
- public UserParamNameAndValue(String name, String value) {
+ @JsonCreator
+ public UserParamNameAndValue(
+ @JsonProperty("name") String name,
+ @JsonProperty("value") String value
+ ) {
this.name = name;
this.value = value;
}
@@ -134,6 +139,24 @@ public class ServiceInstantiationRequestDetails {
public String getValue() {
return value;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof UserParamNameAndValue)) {
+ return false;
+ }
+ UserParamNameAndValue that = (UserParamNameAndValue) o;
+ return Objects.equals(getName(), that.getName()) &&
+ Objects.equals(getValue(), that.getValue());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), getValue());
+ }
}
public static class HomingSolution implements UserParamTypes {
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/UserParamsContainer.kt b/vid-app-common/src/main/java/org/onap/vid/services/UserParamsContainer.kt
new file mode 100644
index 000000000..17cf88e3f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/UserParamsContainer.kt
@@ -0,0 +1,40 @@
+package org.onap.vid.services
+
+import org.onap.vid.mso.model.ServiceInstantiationRequestDetails.UserParamNameAndValue
+import org.onap.vid.mso.model.UserParamTypes
+
+class UserParamsContainer(instanceParams: Map<String, String>?, supplementaryParams: List<UserParamNameAndValue>?) {
+
+ val params:Map<String, String>
+
+ init {
+ params = aggregateAllInstanceParams(instanceParams, supplementaryParams)
+ }
+
+ private fun aggregateAllInstanceParams(
+ instanceParams: Map<String, String>?,
+ supplementaryParams: List<UserParamNameAndValue>?)
+ : Map<String, String> {
+ val instanceParamsSafe: Map<String, String> = instanceParams ?: emptyMap()
+ val supplementaryParamsSafe: Map<String, String> =
+ supplementaryParams?.associate{ it.name to it.value } ?: emptyMap()
+
+ return instanceParamsSafe.plus(supplementaryParamsSafe)
+ }
+
+ fun toALaCarte(): List<UserParamTypes> = toUserParamNameAndValue()
+
+ fun toMacroPre1806() : List<UserParamTypes> = toUserParamNameAndValue()
+
+ fun toMacroPost1806() : List<Map<String, String>> = toListOfMap()
+
+ private fun toUserParamNameAndValue(): List<UserParamNameAndValue> {
+ return params.map{UserParamNameAndValue(it.key, it.value)}.toList()
+ }
+
+ private fun toListOfMap() : List<Map<String, String>> {
+ return listOf(params)
+ }
+}
+
+
diff --git a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
index 43f059d54..f9894d1aa 100644
--- a/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
+++ b/vid-app-common/src/main/java/org/onap/vid/utils/Logging.java
@@ -20,6 +20,7 @@
package org.onap.vid.utils;
+import static java.util.Collections.emptyMap;
import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCause;
import static org.apache.commons.lang3.exception.ExceptionUtils.getThrowableList;
@@ -220,7 +221,7 @@ public class Logging {
<T> T withMDCInternal(Map<String, String> copyOfParentMDC, UncheckedThrowingSupplier<T> supplier) {
try {
- MDC.setContextMap(copyOfParentMDC);
+ MDC.setContextMap(defaultIfNull(copyOfParentMDC, emptyMap()));
return supplier.get();
} finally {
MDC.clear();