diff options
author | 2025-02-17 08:39:37 +0000 | |
---|---|---|
committer | 2025-02-17 08:39:37 +0000 | |
commit | 8b277f144bc1f0368ddc0e3a825a5172cac25351 (patch) | |
tree | c3b283dd0933d07176ddb929e743f9bdb8ae7ad5 | |
parent | 1a20b5fb2dafdf5c8076fa5996df4d69bbd13625 (diff) | |
parent | d24899542bf4689ab54b1af5e700a2dd41de77fd (diff) |
Merge "Dependency inject Retrofit client for KpiSliceService"
8 files changed, 115 insertions, 34 deletions
diff --git a/server/src/main/java/org/onap/usecaseui/server/config/SDCClientConfig.java b/server/src/main/java/org/onap/usecaseui/server/config/SDCClientConfig.java index 45885212..5b02713d 100644 --- a/server/src/main/java/org/onap/usecaseui/server/config/SDCClientConfig.java +++ b/server/src/main/java/org/onap/usecaseui/server/config/SDCClientConfig.java @@ -18,10 +18,8 @@ package org.onap.usecaseui.server.config; import java.io.IOException; -import org.onap.usecaseui.server.service.intent.IntentSoService; import org.onap.usecaseui.server.service.lcm.domain.sdc.SDCCatalogService; -import org.onap.usecaseui.server.service.lcm.domain.so.SOService; -import org.onap.usecaseui.server.service.slicingdomain.so.SOSliceService; +import org.onap.usecaseui.server.service.lcm.domain.vfc.VfcService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -71,4 +69,9 @@ public class SDCClientConfig { SDCCatalogService sdcCatalogService() { return retrofit().create(SDCCatalogService.class); } + + @Bean + VfcService vfcService() { + return retrofit().create(VfcService.class); + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/config/SOClientConfig.java b/server/src/main/java/org/onap/usecaseui/server/config/SOClientConfig.java index bff43614..62a7e246 100644 --- a/server/src/main/java/org/onap/usecaseui/server/config/SOClientConfig.java +++ b/server/src/main/java/org/onap/usecaseui/server/config/SOClientConfig.java @@ -20,6 +20,7 @@ import java.io.IOException; import org.onap.usecaseui.server.service.intent.IntentSoService; import org.onap.usecaseui.server.service.lcm.domain.so.SOService; +import org.onap.usecaseui.server.service.slicingdomain.kpi.KpiSliceService; import org.onap.usecaseui.server.service.slicingdomain.so.SOSliceService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -81,4 +82,10 @@ public class SOClientConfig { IntentSoService intentSoService() { return retrofit().create(IntentSoService.class); } + + @Bean + // not at all clear whether this service should interface with SO + KpiSliceService kpiSliceService() { + return retrofit().create(KpiSliceService.class); + } } diff --git a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java index 7c80c38b..1f3007d9 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/lcm/domain/sdc/SDCCatalogService.java @@ -25,31 +25,15 @@ import java.util.List; public interface SDCCatalogService { - @Headers({ - "X-ECOMP-InstanceID: 777", - "Authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" - }) @GET("/api/sdc/v1/catalog/services") Call<List<SDCServiceTemplate>> listServices(@Query("category")String category, @Query("distributionStatus") String distributionStatus); - @Headers({ - "X-ECOMP-InstanceID: 777", - "Authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" - }) @GET("/api/sdc/v1/catalog/services/{uuid}/metadata") Call<SDCServiceTemplate> getService(@Path("uuid") String uuid); - @Headers({ - "X-ECOMP-InstanceID: 777", - "Authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" - }) @GET Call<ResponseBody> downloadCsar(@Url String fileUrl); - @Headers({ - "X-ECOMP-InstanceID: 777", - "Authorization: Basic YWFpOktwOGJKNFNYc3pNMFdYbGhhazNlSGxjc2UyZ0F3ODR2YW9HR21KdlV5MlU=" - }) @GET("/api/sdc/v1/catalog/resources") Call<List<Vnf>> listResources(@Query("resourceType") String resourceType); -}
\ No newline at end of file +} diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java index 274db67d..a8f65a9b 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceConvert.java @@ -38,18 +38,11 @@ import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.UserNumbers; import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiPDUSessionEstSR; import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.PDUSessionEstSR; import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; @Service("ResourceMonitorConvertService") -@org.springframework.context.annotation.Configuration -@EnableAspectJAutoProxy public class ResourceMonitorServiceConvert { - private static final Logger logger = LoggerFactory.getLogger(ResourceMonitorServiceConvert.class); - TrafficReqInfo buildTrafficReqInfo(ServiceInfo serviceInfo, String queryTimestamp) { TrafficReqInfo trafficReqInfo = new TrafficReqInfo(); trafficReqInfo.setId(serviceInfo.getServiceId()); diff --git a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java index ddcbf8d5..acc1585d 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImpl.java @@ -24,7 +24,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import jakarta.annotation.Resource; + import lombok.RequiredArgsConstructor; import okhttp3.MediaType; import okhttp3.RequestBody; @@ -53,6 +53,7 @@ import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiPDUSessionEst import org.onap.usecaseui.server.util.nsmf.NsmfCommonUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import retrofit2.Response; @@ -65,7 +66,7 @@ public class ResourceMonitorServiceImpl implements ResourceMonitorService { private final KpiSliceService kpiSliceService; - @Resource(name = "ResourceMonitorConvertService") + @Autowired private ResourceMonitorServiceConvert resourceMonitorServiceConvert; private int kpiHours; diff --git a/server/src/main/java/org/onap/usecaseui/server/service/slicingdomain/kpi/KpiSliceService.java b/server/src/main/java/org/onap/usecaseui/server/service/slicingdomain/kpi/KpiSliceService.java index 9522b45f..9570cca9 100644 --- a/server/src/main/java/org/onap/usecaseui/server/service/slicingdomain/kpi/KpiSliceService.java +++ b/server/src/main/java/org/onap/usecaseui/server/service/slicingdomain/kpi/KpiSliceService.java @@ -23,24 +23,19 @@ import org.onap.usecaseui.server.service.slicingdomain.kpi.bean.KpiPDUSessionEst import okhttp3.RequestBody; import retrofit2.Call; import retrofit2.http.Body; -import retrofit2.http.Headers; import retrofit2.http.POST; public interface KpiSliceService { - @Headers({"Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", "Accept: application/json"}) @POST("/api/datalake/v1/exposure/userNumber") Call<KpiUserNumber> listUserNumber(@Body RequestBody body); - @Headers({"Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", "Accept: application/json"}) @POST("/api/datalake/v1/exposure/totalBandwidth") Call<KpiTotalBandwidth> listTotalBandwidth(@Body RequestBody body); - @Headers({"Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", "Accept: application/json"}) @POST("/api/datalake/v1/exposure/totalTraffic") Call<KpiTotalTraffic> listTotalTraffic(@Body RequestBody body); - @Headers({"Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==", "Accept: application/json"}) @POST("/api/datalake/v1/exposure/pDUSessionEstSR") Call<KpiPDUSessionEstSR> listPDUSessionEstSR(@Body RequestBody body); diff --git a/server/src/test/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImplIntegrationTest.java b/server/src/test/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImplIntegrationTest.java new file mode 100644 index 00000000..701bc39b --- /dev/null +++ b/server/src/test/java/org/onap/usecaseui/server/service/nsmf/impl/ResourceMonitorServiceImplIntegrationTest.java @@ -0,0 +1,90 @@ + +/** + * Copyright 2025 Deutsche Telekom. + * + * 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. + */ + +package org.onap.usecaseui.server.service.nsmf.impl; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult; +import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceInfo; +import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceList; +import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserInfo; +import org.onap.usecaseui.server.bean.nsmf.monitor.ServiceOnlineUserList; +import org.onap.usecaseui.server.config.AAIClientConfig; +import org.onap.usecaseui.server.config.SOClientConfig; +import org.onap.usecaseui.server.controller.lcm.CustomerController; +import org.onap.usecaseui.server.service.lcm.CustomerService; +import org.onap.usecaseui.server.service.lcm.domain.aai.bean.AAICustomer; +import org.onap.usecaseui.server.service.lcm.impl.DefaultCustomerService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpHeaders; +import org.wiremock.spring.EnableWireMock; + +@EnableWireMock +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = { + SOClientConfig.class, ResourceMonitorServiceImpl.class, ResourceMonitorServiceConvert.class +}, properties = { + "spring.main.web-application-type=none", // only temporary + "uui-server.client.so.baseUrl=${wiremock.server.baseUrl}", + "uui-server.client.so.username=InfraPortalClient", + "uui-server.client.so.password=password1", +}) + +public class ResourceMonitorServiceImplIntegrationTest { + + @Autowired + ResourceMonitorServiceImpl resourceMonitorService; + + @Value("${uui-server.client.so.username}") + String username; + + @Value("${uui-server.client.so.password}") + String password; + + @Test + void thatKpiRequestsAreCorrect() { + stubFor( + post("/api/datalake/v1/exposure/userNumber") + .withBasicAuth(username, password) + .withHeader(HttpHeaders.ACCEPT, equalTo("application/json")) + .willReturn( + aResponse().withBodyFile("kpiUserNumberResponse.json"))); + + String timestamp = "1739307776"; + ServiceList serviceList = new ServiceList(); + List<ServiceInfo> serviceInfoList = List.of(new ServiceInfo()); + serviceList.setServiceInfoList(serviceInfoList); + ServiceResult serviceResult = resourceMonitorService.querySlicingOnlineUserNumber(timestamp, serviceList); + assertNotNull(serviceResult); + List<ServiceOnlineUserInfo> onlineUserInfoList = ((ServiceOnlineUserList) serviceResult.getResult_body()).getServiceOnlineUserInfoList(); + assertEquals(1, onlineUserInfoList.size()); + assertEquals("abc", onlineUserInfoList.get(0).getId()); + } +} diff --git a/server/src/test/resources/__files/kpiUserNumberResponse.json b/server/src/test/resources/__files/kpiUserNumberResponse.json new file mode 100644 index 00000000..2b355d4d --- /dev/null +++ b/server/src/test/resources/__files/kpiUserNumberResponse.json @@ -0,0 +1,8 @@ +{ + "request": { + "id": "abc", + "timeStamp": "1739307776", + "hours": 1 + }, + "user_number": 1 +} |