diff options
Diffstat (limited to 'common/src')
12 files changed, 270 insertions, 169 deletions
diff --git a/common/src/main/java/org/onap/so/beans/nsmf/AnPerfReq.java b/common/src/main/java/org/onap/so/beans/nsmf/AnPerfReq.java deleted file mode 100644 index e2c2e999ec..0000000000 --- a/common/src/main/java/org/onap/so/beans/nsmf/AnPerfReq.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.beans.nsmf; - -import com.fasterxml.jackson.annotation.JsonInclude; -import java.io.Serializable; - -@JsonInclude(JsonInclude.Include.NON_NULL) -public class AnPerfReq implements Serializable { - - private static final long serialVersionUID = -7415880702887244040L; - - private PerfReqEmbb perfReqEmbb; - - private PerfReqUrllc perfReqUrllc; - - public PerfReqEmbb getPerfReqEmbb() { - return perfReqEmbb; - } - - public void setPerfReqEmbb(PerfReqEmbb perfReqEmbb) { - this.perfReqEmbb = perfReqEmbb; - } - - public PerfReqUrllc getPerfReqUrllc() { - return perfReqUrllc; - } - - public void setPerfReqUrllc(PerfReqUrllc perfReqUrllc) { - this.perfReqUrllc = perfReqUrllc; - } -} diff --git a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java index eef0396205..14918c7873 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java @@ -31,6 +31,9 @@ import java.util.List; @Data @ToString public class AnSliceProfile implements Serializable { + /* + * Reference 3GPP TS 28.541 V16.5.0, Section 6.3.4. + */ private static final long serialVersionUID = -3057342171549542794L; @@ -44,7 +47,7 @@ public class AnSliceProfile implements Serializable { private List<String> pLMNIdList; @JsonProperty(value = "perfReq", required = true) - private AnPerfReq perfReq; + private PerfReq perfReq; @JsonInclude(JsonInclude.Include.NON_DEFAULT) @JsonProperty(value = "maxNumberofUEs") diff --git a/common/src/main/java/org/onap/so/beans/nsmf/CnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/CnSliceProfile.java index 3bd155d512..1fa84eee59 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/CnSliceProfile.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/CnSliceProfile.java @@ -21,100 +21,40 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import java.io.Serializable; import java.util.List; @JsonInclude(JsonInclude.Include.NON_NULL) -public class CnSliceProfile { +@Data +public class CnSliceProfile implements Serializable { + private static final long serialVersionUID = 6627071735572539536L; + + @JsonProperty(value = "sNSSAIList", required = true) private List<String> snssaiList; private String sliceProfileId; + @JsonProperty(value = "pLMNIdList", required = true) private List<String> plmnIdList; + @JsonProperty(value = "perfReq", required = true) private PerfReq perfReq; - @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonProperty(value = "maxNumberofUEs") private int maxNumberofUEs; + @JsonProperty(value = "coverageAreaTAList") private List<String> coverageAreaTAList; - @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonProperty(value = "latency") private int latency; + @JsonProperty(value = "uEMobilityLevel") private UeMobilityLevel ueMobilityLevel; + @JsonProperty(value = "resourceSharingLevel") private ResourceSharingLevel resourceSharingLevel; - - public String getSliceProfileId() { - return sliceProfileId; - } - - public void setSliceProfileId(String sliceProfileId) { - this.sliceProfileId = sliceProfileId; - } - - public List<String> getPlmnIdList() { - return plmnIdList; - } - - public void setPlmnIdList(List<String> plmnIdList) { - this.plmnIdList = plmnIdList; - } - - public PerfReq getPerfReq() { - return perfReq; - } - - public void setPerfReq(PerfReq perfReq) { - this.perfReq = perfReq; - } - - public int getMaxNumberofUEs() { - return maxNumberofUEs; - } - - public void setMaxNumberofUEs(int maxNumberofUEs) { - this.maxNumberofUEs = maxNumberofUEs; - } - - public List<String> getCoverageAreaTAList() { - return coverageAreaTAList; - } - - public void setCoverageAreaTAList(List<String> coverageAreaTAList) { - this.coverageAreaTAList = coverageAreaTAList; - } - - public int getLatency() { - return latency; - } - - public void setLatency(int latency) { - this.latency = latency; - } - - public UeMobilityLevel getUeMobilityLevel() { - return ueMobilityLevel; - } - - public void setUeMobilityLevel(UeMobilityLevel ueMobilityLevel) { - this.ueMobilityLevel = ueMobilityLevel; - } - - public ResourceSharingLevel getResourceSharingLevel() { - return resourceSharingLevel; - } - - public void setResourceSharingLevel(ResourceSharingLevel resourceSharingLevel) { - this.resourceSharingLevel = resourceSharingLevel; - } - - public List<String> getSnssaiList() { - return snssaiList; - } - - public void setSnssaiList(List<String> snssaiList) { - this.snssaiList = snssaiList; - } } diff --git a/common/src/main/java/org/onap/so/beans/nsmf/PerfReq.java b/common/src/main/java/org/onap/so/beans/nsmf/PerfReq.java index c67f193a02..6697c8d8a0 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/PerfReq.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/PerfReq.java @@ -21,10 +21,13 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.annotation.JsonInclude; +import java.io.Serializable; import java.util.List; @JsonInclude(JsonInclude.Include.NON_NULL) -public class PerfReq { +public class PerfReq implements Serializable { + + private static final long serialVersionUID = 8463835350563510267L; private List<PerfReqEmbb> perfReqEmbbList; diff --git a/common/src/main/java/org/onap/so/beans/nsmf/PerfReqEmbb.java b/common/src/main/java/org/onap/so/beans/nsmf/PerfReqEmbb.java index f6e945e368..1db009cdb9 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/PerfReqEmbb.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/PerfReqEmbb.java @@ -25,6 +25,9 @@ import java.io.Serializable; @JsonInclude(JsonInclude.Include.NON_NULL) public class PerfReqEmbb implements Serializable { + /* + * Reference 3GPP TS 28.541 V16.5.0, Section 6.4.1. + */ private static final long serialVersionUID = 8886635511695277599L; diff --git a/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java b/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java new file mode 100644 index 0000000000..9b6df0fa9e --- /dev/null +++ b/common/src/main/java/org/onap/so/beans/nsmf/SliceProfileAdapter.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Huawei Technologies Co., Ltd. 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.beans.nsmf; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.ToString; +import org.springframework.beans.BeanUtils; +import java.io.Serializable; +import java.util.Arrays; + +@Data +@ToString +public class SliceProfileAdapter implements Serializable { + + private static final long serialVersionUID = -6412175980642584804L; + + @JsonProperty(value = "sliceProfileId") + private String sliceProfileId; + + @JsonProperty(value = "sNSSAI") + private String sNSSAIList = ""; + + @JsonProperty(value = "pLMNIdList") + private String pLMNIdList = ""; + + @JsonProperty(value = "maxNumberofUEs") + private long maxNumberofUEs; + + @JsonProperty(value = "coverageAreaTAList") + private String coverageAreaTAList = ""; + + @JsonProperty(value = "latency") + private int latency; + + @JsonProperty(value = "uEMobilityLevel") + private String uEMobilityLevel; + + @JsonProperty(value = "resourceSharingLevel") + private String resourceSharingLevel; + + @JsonProperty(value = "maxBandwidth") + private String bandwidth; + + @JsonProperty(value = "sST") + private String sST; + + @JsonProperty(value = "activityFactor") + private String activityFactor; + + @JsonProperty(value = "survivalTime") + private String survivalTime; + + public AnSliceProfile trans2AnProfile() { + AnSliceProfile anSliceProfile = new AnSliceProfile(); + BeanUtils.copyProperties(this, anSliceProfile); + anSliceProfile.setSNSSAIList(Arrays.asList(this.sNSSAIList.split("\\|"))); + anSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|"))); + + String[] areas = this.coverageAreaTAList.split("\\|"); + Integer[] areasRes = new Integer[areas.length]; + for (int i = 0; i < areas.length; i++) { + areasRes[i] = str2Code(areas[i]); + } + anSliceProfile.setCoverageAreaTAList(Arrays.asList(areasRes)); + anSliceProfile.setUEMobilityLevel(UeMobilityLevel.fromString(this.uEMobilityLevel)); + anSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel)); + PerfReq perfReq = new PerfReq(); + // todo + anSliceProfile.setPerfReq(perfReq); + return anSliceProfile; + } + + private Integer str2Code(String area) { + return area.hashCode() >> 16; + } + + public CnSliceProfile trans2CnProfile() { + CnSliceProfile cnSliceProfile = new CnSliceProfile(); + BeanUtils.copyProperties(this, cnSliceProfile); + cnSliceProfile.setSnssaiList(Arrays.asList(this.sNSSAIList.split("\\|"))); + cnSliceProfile.setCoverageAreaTAList(Arrays.asList(this.coverageAreaTAList.split("\\|"))); + cnSliceProfile.setPlmnIdList(Arrays.asList(this.pLMNIdList.split("\\|"))); + cnSliceProfile.setResourceSharingLevel(ResourceSharingLevel.fromString(this.resourceSharingLevel)); + PerfReq perfReq = new PerfReq(); + // todo + cnSliceProfile.setPerfReq(perfReq); + return cnSliceProfile; + } + + public TnSliceProfile trans2TnProfile() { + TnSliceProfile tnSliceProfile = new TnSliceProfile(); + BeanUtils.copyProperties(this, tnSliceProfile); + tnSliceProfile.setSNSSAIList(Arrays.asList(this.sNSSAIList.split("\\|"))); + tnSliceProfile.setPLMNIdList(Arrays.asList(this.pLMNIdList.split("\\|"))); + return tnSliceProfile; + } +} diff --git a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java index e97aa704eb..bfd4627b47 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/SliceTaskParamsAdapter.java @@ -19,6 +19,7 @@ */ package org.onap.so.beans.nsmf; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.JsonObject; import lombok.*; @@ -56,15 +57,15 @@ public class SliceTaskParamsAdapter implements Serializable { private TemplateInfo NSTInfo = new TemplateInfo(); - private SliceTaskInfo<TnSliceProfile> tnBHSliceTaskInfo = new SliceTaskInfo<>(); + private SliceTaskInfo<SliceProfileAdapter> tnBHSliceTaskInfo = new SliceTaskInfo<>(); - private SliceTaskInfo<TnSliceProfile> tnMHSliceTaskInfo = new SliceTaskInfo<>(); + private SliceTaskInfo<SliceProfileAdapter> tnMHSliceTaskInfo = new SliceTaskInfo<>(); - private SliceTaskInfo<TnSliceProfile> tnFHSliceTaskInfo = new SliceTaskInfo<>(); + private SliceTaskInfo<SliceProfileAdapter> tnFHSliceTaskInfo = new SliceTaskInfo<>(); - private SliceTaskInfo<CnSliceProfile> cnSliceTaskInfo = new SliceTaskInfo<>(); + private SliceTaskInfo<SliceProfileAdapter> cnSliceTaskInfo = new SliceTaskInfo<>(); - private SliceTaskInfo<AnSliceProfile> anSliceTaskInfo = new SliceTaskInfo<>(); + private SliceTaskInfo<SliceProfileAdapter> anSliceTaskInfo = new SliceTaskInfo<>(); @SuppressWarnings("unchecked") public void convertFromJson(String jsonString) throws IOException { @@ -80,24 +81,24 @@ public class SliceTaskParamsAdapter implements Serializable { this.setServiceProfile(replaceHeader(paramMap, "ServiceProfile.")); - TnSliceProfile tnBHSliceProfile = mapper.readValue( - mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.BH.")), TnSliceProfile.class); + SliceProfileAdapter tnBHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.BH.")), SliceProfileAdapter.class); this.tnBHSliceTaskInfo.setSliceProfile(tnBHSliceProfile); - TnSliceProfile tnMHSliceProfile = mapper.readValue( - mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.MH.")), TnSliceProfile.class); + SliceProfileAdapter tnMHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.MH.")), SliceProfileAdapter.class); this.tnMHSliceTaskInfo.setSliceProfile(tnMHSliceProfile); - TnSliceProfile tnFHSliceProfile = mapper.readValue( - mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.FH.")), TnSliceProfile.class); + SliceProfileAdapter tnFHSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.TN.FH.")), SliceProfileAdapter.class); this.tnFHSliceTaskInfo.setSliceProfile(tnFHSliceProfile); - CnSliceProfile cnSliceProfile = mapper.readValue( - mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.CN.")), CnSliceProfile.class); + SliceProfileAdapter cnSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.CN.")), SliceProfileAdapter.class); this.cnSliceTaskInfo.setSliceProfile(cnSliceProfile); - AnSliceProfile anSliceProfile = mapper.readValue( - mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.AN.")), AnSliceProfile.class); + SliceProfileAdapter anSliceProfile = mapper.readValue( + mapper.writeValueAsString(replaceHeader(paramMap, "SliceProfile.AN.")), SliceProfileAdapter.class); this.anSliceTaskInfo.setSliceProfile(anSliceProfile); this.tnBHSliceTaskInfo.setSuggestNssiId(paramMap.get("TN.BH.SuggestNSSIId")); @@ -148,33 +149,31 @@ public class SliceTaskParamsAdapter implements Serializable { for (Map.Entry<String, Object> entry : serviceProfile.entrySet()) { jsonObject.addProperty("ServiceProfile." + entry.getKey(), entry.getValue().toString()); } - Map<String, Object> sliceProfileAn = bean2Map(anSliceTaskInfo.getSliceProfile()); - for (Map.Entry<String, Object> entry : sliceProfileAn.entrySet()) { - jsonObject.addProperty("SliceProfile.AN." + entry.getKey(), entry.getValue().toString()); + String value = entry.getValue() == null ? "" : entry.getValue().toString(); + jsonObject.addProperty("SliceProfile.AN." + entry.getKey(), value); } - Map<String, Object> sliceProfileCn = bean2Map(cnSliceTaskInfo.getSliceProfile()); for (Map.Entry<String, Object> entry : sliceProfileCn.entrySet()) { - jsonObject.addProperty("SliceProfile.CN." + entry.getKey(), entry.getValue().toString()); + String value = entry.getValue() == null ? "" : entry.getValue().toString(); + jsonObject.addProperty("SliceProfile.CN." + entry.getKey(), value); } - Map<String, Object> sliceProfileTnBH = bean2Map(tnBHSliceTaskInfo.getSliceProfile()); for (Map.Entry<String, Object> entry : sliceProfileTnBH.entrySet()) { - jsonObject.addProperty("SliceProfile.TN.BH." + entry.getKey(), entry.getValue().toString()); + String value = entry.getValue() == null ? "" : entry.getValue().toString(); + jsonObject.addProperty("SliceProfile.TN.BH." + entry.getKey(), value); } - Map<String, Object> sliceProfileTnMH = bean2Map(tnMHSliceTaskInfo.getSliceProfile()); for (Map.Entry<String, Object> entry : sliceProfileTnMH.entrySet()) { - jsonObject.addProperty("SliceProfile.TN.MH." + entry.getKey(), entry.getValue().toString()); + String value = entry.getValue() == null ? "" : entry.getValue().toString(); + jsonObject.addProperty("SliceProfile.TN.MH." + entry.getKey(), value); } - Map<String, Object> sliceProfileTnFH = bean2Map(tnFHSliceTaskInfo.getSliceProfile()); for (Map.Entry<String, Object> entry : sliceProfileTnFH.entrySet()) { - jsonObject.addProperty("SliceProfile.TN.FH." + entry.getKey(), entry.getValue().toString()); + String value = entry.getValue() == null ? "" : entry.getValue().toString(); + jsonObject.addProperty("SliceProfile.TN.FH." + entry.getKey(), value); } - jsonObject.addProperty("TN.BH.SuggestNSSIId", tnBHSliceTaskInfo.getSuggestNssiId()); jsonObject.addProperty("TN.BH.SuggestNSSIName", tnBHSliceTaskInfo.getSuggestNssiName()); jsonObject.addProperty("TN.BH.progress", tnBHSliceTaskInfo.getProgress()); @@ -182,7 +181,6 @@ public class SliceTaskParamsAdapter implements Serializable { jsonObject.addProperty("TN.BH.statusDescription", tnBHSliceTaskInfo.getStatusDescription()); jsonObject.addProperty("TN.BH.ScriptName", tnBHSliceTaskInfo.getScriptName()); - jsonObject.addProperty("TN.MH.SuggestNSSIId", tnMHSliceTaskInfo.getSuggestNssiId()); jsonObject.addProperty("TN.MH.SuggestNSSIName", tnMHSliceTaskInfo.getSuggestNssiName()); jsonObject.addProperty("TN.MH.progress", tnMHSliceTaskInfo.getProgress()); @@ -190,7 +188,6 @@ public class SliceTaskParamsAdapter implements Serializable { jsonObject.addProperty("TN.MH.statusDescription", tnMHSliceTaskInfo.getStatusDescription()); jsonObject.addProperty("TN.MH.ScriptName", tnMHSliceTaskInfo.getScriptName()); - jsonObject.addProperty("TN.FH.SuggestNSSIId", tnFHSliceTaskInfo.getSuggestNssiId()); jsonObject.addProperty("TN.FH.SuggestNSSIName", tnFHSliceTaskInfo.getSuggestNssiName()); jsonObject.addProperty("TN.FH.progress", tnFHSliceTaskInfo.getProgress()); @@ -198,7 +195,6 @@ public class SliceTaskParamsAdapter implements Serializable { jsonObject.addProperty("TN.FH.statusDescription", tnFHSliceTaskInfo.getStatusDescription()); jsonObject.addProperty("TN.FH.ScriptName", tnFHSliceTaskInfo.getScriptName()); - jsonObject.addProperty("CN.SuggestNSSIId", cnSliceTaskInfo.getSuggestNssiId()); jsonObject.addProperty("CN.SuggestNSSIName", cnSliceTaskInfo.getSuggestNssiName()); jsonObject.addProperty("CN.progress", cnSliceTaskInfo.getProgress()); @@ -206,7 +202,6 @@ public class SliceTaskParamsAdapter implements Serializable { jsonObject.addProperty("CN.statusDescription", cnSliceTaskInfo.getStatusDescription()); jsonObject.addProperty("CN.ScriptName", cnSliceTaskInfo.getScriptName()); - jsonObject.addProperty("AN.SuggestNSSIId", anSliceTaskInfo.getSuggestNssiId()); jsonObject.addProperty("AN.SuggestNSSIName", anSliceTaskInfo.getSuggestNssiName()); jsonObject.addProperty("AN.progress", anSliceTaskInfo.getProgress()); @@ -219,7 +214,7 @@ public class SliceTaskParamsAdapter implements Serializable { /** * change T t to {@link Map} - * + * * @param t input * @param <T> Object * @return {@link Map} @@ -234,9 +229,18 @@ public class SliceTaskParamsAdapter implements Serializable { Field[] fields = t.getClass().getDeclaredFields(); for (Field field : fields) { String name = field.getName(); - Method method = t.getClass().getMethod("get" + name); + String key = name; + if (name == null || "".equals(name) || "serialVersionUID".equalsIgnoreCase(name)) { + continue; + } + JsonProperty annotation = field.getAnnotation(JsonProperty.class); + if (annotation != null && !annotation.value().equals(JsonProperty.USE_DEFAULT_NAME)) { + key = annotation.value(); + } + + Method method = t.getClass().getMethod("get" + name.substring(0, 1).toUpperCase() + name.substring(1)); Object value = method.invoke(t); - resMap.put(name, value); + resMap.put(key, value); } } catch (Exception e) { @@ -247,7 +251,7 @@ public class SliceTaskParamsAdapter implements Serializable { /** * replace of slice profile - * + * * @param paramMap params map * @param header starts of key * @return Map diff --git a/common/src/main/java/org/onap/so/beans/nsmf/TnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/TnSliceProfile.java index ccd6001957..3f0da1bf21 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/TnSliceProfile.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/TnSliceProfile.java @@ -21,16 +21,28 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import java.io.Serializable; +import java.util.List; @JsonInclude(JsonInclude.Include.NON_NULL) @Data -public class TnSliceProfile { +public class TnSliceProfile implements Serializable { + + private static final long serialVersionUID = 3767943556195823439L; private String sliceProfileId; + @JsonProperty(value = "maxBandwidth") private String bandwidth; @JsonInclude(JsonInclude.Include.NON_DEFAULT) private int latency; + + @JsonProperty(value = "sNSSAIList", required = true) + private List<String> sNSSAIList; + + @JsonProperty(value = "pLMNIdList", required = true) + private List<String> pLMNIdList; } diff --git a/common/src/main/java/org/onap/so/client/RestClient.java b/common/src/main/java/org/onap/so/client/RestClient.java index ece1333f83..9fce328b1d 100644 --- a/common/src/main/java/org/onap/so/client/RestClient.java +++ b/common/src/main/java/org/onap/so/client/RestClient.java @@ -34,10 +34,12 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; +import java.util.concurrent.TimeUnit; import java.util.function.Predicate; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation.Builder; +import javax.ws.rs.client.ResponseProcessingException; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.GenericType; import javax.ws.rs.core.MediaType; @@ -187,7 +189,7 @@ public abstract class RestClient { } protected Client getClient() { - return ClientBuilder.newBuilder().build(); + return ClientBuilder.newBuilder().readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build(); } protected abstract ONAPComponentsList getTargetEntity(); @@ -201,7 +203,6 @@ public abstract class RestClient { metricLogClientFilter = new SOMetricLogClientFilter(); mdcSetup.setTargetEntity(getTargetEntity()); client.register(metricLogClientFilter); - if (!path.isPresent()) { webTarget = client.target(host.toString()); } else { @@ -225,6 +226,9 @@ public abstract class RestClient { result.add(e -> { return e.getCause() instanceof ConnectException; }); + result.add(e -> { + return e.getCause() instanceof ResponseProcessingException; + }); return result; } diff --git a/common/src/main/java/org/onap/so/client/RestClientSSL.java b/common/src/main/java/org/onap/so/client/RestClientSSL.java index 1e8953892e..8956e20a5a 100644 --- a/common/src/main/java/org/onap/so/client/RestClientSSL.java +++ b/common/src/main/java/org/onap/so/client/RestClientSSL.java @@ -24,6 +24,7 @@ import java.net.URI; import java.security.KeyStore; import java.security.NoSuchAlgorithmException; import java.util.Optional; +import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -56,7 +57,8 @@ public abstract class RestClientSSL extends RestClient { } } // Use default SSL context - client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()).build(); + client = ClientBuilder.newBuilder().sslContext(SSLContext.getDefault()) + .readTimeout(props.getReadTimeout(), TimeUnit.MILLISECONDS).build(); logger.info("RestClientSSL using default SSL context!"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); diff --git a/common/src/main/java/org/onap/so/client/RestProperties.java b/common/src/main/java/org/onap/so/client/RestProperties.java index 9e4e99cb4e..36da424f93 100644 --- a/common/src/main/java/org/onap/so/client/RestProperties.java +++ b/common/src/main/java/org/onap/so/client/RestProperties.java @@ -40,4 +40,13 @@ public interface RestProperties { public default boolean mapNotFoundToEmpty() { return false; } + + /** + * Time in milliseconds + * + * @return + */ + public default Long getReadTimeout() { + return Long.valueOf(60000); + } } diff --git a/common/src/test/java/org/onap/so/client/RestClientTest.java b/common/src/test/java/org/onap/so/client/RestClientTest.java index cd00a9e4de..c6e282c14a 100644 --- a/common/src/test/java/org/onap/so/client/RestClientTest.java +++ b/common/src/test/java/org/onap/so/client/RestClientTest.java @@ -21,6 +21,8 @@ package org.onap.so.client; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.spy; @@ -28,7 +30,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.net.MalformedURLException; import java.net.SocketTimeoutException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Map; +import java.util.Optional; import javax.ws.rs.NotFoundException; +import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilderException; @@ -37,21 +45,24 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; -import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.logging.filter.base.ONAPComponents; +import org.onap.logging.filter.base.ONAPComponentsList; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import com.github.tomakehurst.wiremock.junit.WireMockRule; @RunWith(MockitoJUnitRunner.class) public class RestClientTest { private final HttpClientFactory httpClientFactory = new HttpClientFactory(); - @Mock - private RestProperties props; @Rule public ExpectedException thrown = ExpectedException.none(); + @Rule + public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.options().dynamicPort()); + @Test public void retries() throws Exception { RestClient spy = buildSpy(); @@ -80,6 +91,50 @@ public class RestClientTest { } + @Test + public void timeoutTest() throws URISyntaxException { + wireMockRule.stubFor(get("/chunked/delayed") + .willReturn(aResponse().withStatus(200).withBody("Hello world!").withChunkedDribbleDelay(2, 300))); + + + RestProperties props = new RestProperties() { + + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(String.format("http://localhost:%s", wireMockRule.port())); + } + + @Override + public String getSystemName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Long getReadTimeout() { + return Long.valueOf(100); + } + }; + RestClient client = new RestClient(props, Optional.of(new URI("/chunked/delayed"))) { + + @Override + protected void initializeHeaderMap(Map<String, String> headerMap) { + // TODO Auto-generated method stub + + } + + @Override + protected ONAPComponentsList getTargetEntity() { + return ONAPComponents.EXTERNAL; + } + + }; + + thrown.expect(ProcessingException.class); + client.get(); + + } + private RestClient buildSpy() throws MalformedURLException, IllegalArgumentException, UriBuilderException { RestClient client = httpClientFactory.newJsonClient(UriBuilder.fromUri("http://localhost/test").build().toURL(), ONAPComponents.BPMN); |