diff options
12 files changed, 33 insertions, 102 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java index 9156732d..d8f6d966 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/configuration/AaiHttpClientConfig.java @@ -28,11 +28,11 @@ import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiGetServiceInstanceC import org.onap.dcaegen2.services.prh.adapter.aai.api.get.AaiHttpGetClient; import org.onap.dcaegen2.services.prh.adapter.aai.api.patch.AaiHttpPatchClient; import org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFactory; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.utils.PrhModelAwareGsonBuilder; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; @@ -47,7 +47,7 @@ public class AaiHttpClientConfig { private CbsConfiguration cbsConfiguration; @Bean - public AaiHttpClient<AaiModel, HttpResponse> getPatchClientFactory() { + public AaiHttpClient<ConsumerDmaapModel, HttpResponse> getPatchClientFactory() { return createLazyConfigClient( (config, client) -> new AaiHttpPatchClient(config, new AaiJsonBodyBuilderImpl(), client)); } @@ -64,7 +64,7 @@ public class AaiHttpClientConfig { } @Bean - public AaiHttpClient<AaiModel, AaiPnfResultModel> getGetClient() { + public AaiHttpClient<ConsumerDmaapModel, AaiPnfResultModel> getGetClient() { return createLazyConfigClient( (config, client) -> new AaiHttpGetClient(config, client) .map(httpResponse -> { diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java index e0764fd2..fd7f11c0 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiProducerTaskImpl.java @@ -21,7 +21,6 @@ package org.onap.dcaegen2.services.prh.tasks; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException; @@ -43,10 +42,10 @@ public class AaiProducerTaskImpl implements AaiProducerTask { private static final Logger LOGGER = LoggerFactory.getLogger(AaiProducerTaskImpl.class); - private final AaiHttpClient<AaiModel, HttpResponse> aaiHttpPatchClient; + private final AaiHttpClient<ConsumerDmaapModel, HttpResponse> aaiHttpPatchClient; @Autowired - public AaiProducerTaskImpl(final AaiHttpClient<AaiModel, HttpResponse> aaiHttpPatchClient) { + public AaiProducerTaskImpl(final AaiHttpClient<ConsumerDmaapModel, HttpResponse> aaiHttpPatchClient) { this.aaiHttpPatchClient = aaiHttpPatchClient; } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java index 0bcb1dea..b4ab10f0 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTask.java @@ -20,10 +20,10 @@ package org.onap.dcaegen2.services.prh.tasks; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import reactor.core.publisher.Mono; @FunctionalInterface public interface AaiQueryTask { - Mono<Boolean> execute(final AaiModel aaiModel); + Mono<Boolean> execute(final ConsumerDmaapModel aaiModel); } diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java index 46f9d3d9..9489a501 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImpl.java @@ -24,11 +24,11 @@ import java.util.List; import java.util.Optional; import java.util.stream.Stream; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.adapter.aai.model.ImmutableAaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.Relationship; import org.onap.dcaegen2.services.prh.model.RelationshipData; import org.onap.dcaegen2.services.prh.model.RelationshipDict; @@ -44,19 +44,19 @@ public class AaiQueryTaskImpl implements AaiQueryTask { static final String SERVICE_TYPE = "service-subscription.service-type"; static final String SERVICE_INSTANCE_ID = "service-instance.service-instance-id"; - private final AaiHttpClient<AaiModel, AaiPnfResultModel> getPnfModelClient; + private final AaiHttpClient<ConsumerDmaapModel, AaiPnfResultModel> getPnfModelClient; private final AaiHttpClient<AaiServiceInstanceQueryModel, AaiServiceInstanceResultModel> getServiceClient; @Autowired public AaiQueryTaskImpl( - final AaiHttpClient<AaiModel, AaiPnfResultModel> getPnfModelClient, + final AaiHttpClient<ConsumerDmaapModel, AaiPnfResultModel> getPnfModelClient, final AaiHttpClient<AaiServiceInstanceQueryModel, AaiServiceInstanceResultModel> getServiceClient) { this.getPnfModelClient = getPnfModelClient; this.getServiceClient = getServiceClient; } @Override - public Mono<Boolean> execute(AaiModel aaiModel) { + public Mono<Boolean> execute(ConsumerDmaapModel aaiModel) { return getPnfModelClient .getAaiResponse(aaiModel) .flatMap(this::checkIfPnfHasRelationToService) diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java index f2d562dc..b2702a9d 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/AaiQueryTaskImplTest.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.prh.tasks; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; import java.util.Collections; import java.util.List; @@ -33,10 +34,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiServiceInstanceQueryModel; import org.onap.dcaegen2.services.prh.model.AaiPnfResultModel; import org.onap.dcaegen2.services.prh.model.AaiServiceInstanceResultModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.prh.model.ImmutableRelationshipData; import org.onap.dcaegen2.services.prh.model.Relationship; import org.onap.dcaegen2.services.prh.model.RelationshipData; @@ -46,7 +47,7 @@ import reactor.core.publisher.Mono; @ExtendWith(MockitoExtension.class) class AaiQueryTaskImplTest { @Mock - private AaiHttpClient<AaiModel, AaiPnfResultModel> getPnfModelClient; + private AaiHttpClient<ConsumerDmaapModel, AaiPnfResultModel> getPnfModelClient; @Mock private AaiHttpClient<AaiServiceInstanceQueryModel, AaiServiceInstanceResultModel> getServiceClient; @@ -67,7 +68,7 @@ class AaiQueryTaskImplTest { private AaiQueryTask sut; - private final AaiModel aaiModel = () -> "SomePNF"; + private final ConsumerDmaapModel aaiModel = mock(ConsumerDmaapModel.class); @BeforeEach void setUp() { @@ -199,7 +200,7 @@ class AaiQueryTaskImplTest { Assertions.assertTrue(task::block); } - private void configurePnfClient(final AaiModel aaiModel, final AaiPnfResultModel pnfResultModel) { + private void configurePnfClient(final ConsumerDmaapModel aaiModel, final AaiPnfResultModel pnfResultModel) { given(getPnfModelClient.getAaiResponse(aaiModel)).willReturn(Mono.just(pnfResultModel)); } } diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java index f97c57be..122a6097 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/get/AaiHttpGetClient.java @@ -25,14 +25,14 @@ import static org.onap.dcaegen2.services.prh.adapter.aai.main.AaiHttpClientFacto import io.vavr.collection.HashMap; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; import reactor.core.publisher.Mono; -public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpResponse> { +public final class AaiHttpGetClient implements AaiHttpClient<ConsumerDmaapModel, HttpResponse> { private final RxHttpClient httpClient; private final AaiClientConfiguration configuration; @@ -44,7 +44,7 @@ public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpRespo } @Override - public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) { + public Mono<HttpResponse> getAaiResponse(ConsumerDmaapModel aaiModel) { return httpClient.call(ImmutableHttpRequest.builder() .method(HttpMethod.GET) .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java index fdeb5e3c..efae2d54 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/api/patch/AaiHttpPatchClient.java @@ -26,8 +26,8 @@ import io.vavr.collection.HashMap; import io.vavr.collection.Map; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiHttpClient; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; -import org.onap.dcaegen2.services.prh.adapter.aai.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest; @@ -35,28 +35,28 @@ import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; import reactor.core.publisher.Mono; -public final class AaiHttpPatchClient implements AaiHttpClient<AaiModel, HttpResponse> { +public final class AaiHttpPatchClient implements AaiHttpClient<ConsumerDmaapModel, HttpResponse> { private final static Map<String, String> CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json"); private RxHttpClient httpClient; private final AaiClientConfiguration configuration; - private final JsonBodyBuilder jsonBodyBuilder; + private final AaiJsonBodyBuilderImpl jsonBodyBuilder; - public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, + public AaiHttpPatchClient(final AaiClientConfiguration configuration, AaiJsonBodyBuilderImpl jsonBodyBuilder, RxHttpClient httpClient) { this.configuration = configuration; this.jsonBodyBuilder = jsonBodyBuilder; this.httpClient = httpClient; } - public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) { + public Mono<HttpResponse> getAaiResponse(ConsumerDmaapModel aaiModel) { final Map<String, String> headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders())); String jsonBody = jsonBodyBuilder.createJsonBody(aaiModel); return httpClient.call(ImmutableHttpRequest.builder() - .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) + .url(configuration.pnfUrl() + "/" + aaiModel.getCorrelationId()) .customHeaders(headers) .diagnosticContext(createRequestDiagnosticContext()) .body(RequestBody.fromString(jsonBody)) diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java deleted file mode 100644 index f0353d74..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/AaiModel.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 2019 NOKIA 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.dcaegen2.services.prh.adapter.aai.model; - -@FunctionalInterface -public interface AaiModel { - - String getCorrelationId(); -} diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java deleted file mode 100644 index db8839ea..00000000 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/adapter/aai/model/JsonBodyBuilder.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * DCAEGEN2-SERVICES-SDK - * ================================================================================ - * Copyright (C) 2019 NOKIA 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.dcaegen2.services.prh.adapter.aai.model; - -@FunctionalInterface -public interface JsonBodyBuilder<T> { - - /** - * Method for serialization object by GSON. - * - * @param t - object which will be serialized - * @return string from serialization - */ - - String createJsonBody(T t); -}
\ No newline at end of file diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java index c53da879..43e4ebbe 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/AaiJsonBodyBuilderImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ - * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * Copyright (C) 2019 NOKIA 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. @@ -23,19 +23,12 @@ package org.onap.dcaegen2.services.prh.model; import com.google.gson.GsonBuilder; import com.google.gson.TypeAdapterFactory; import java.util.ServiceLoader; -import org.onap.dcaegen2.services.prh.adapter.aai.model.JsonBodyBuilder; import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel.Builder; import org.springframework.util.StringUtils; -public class AaiJsonBodyBuilderImpl implements JsonBodyBuilder<ConsumerDmaapModel> { +public class AaiJsonBodyBuilderImpl { - /** - * Method for serialization object by GSON. - * - * @param consumerDmaapModel - object which will be serialized - * @return string from serialization - */ public String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { GsonBuilder gsonBuilder = new GsonBuilder(); ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); diff --git a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java index d813116d..9ed36823 100644 --- a/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java +++ b/prh-commons/src/main/java/org/onap/dcaegen2/services/prh/model/ConsumerDmaapModel.java @@ -24,7 +24,6 @@ import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; import org.immutables.gson.Gson; import org.immutables.value.Value; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; import org.springframework.lang.Nullable; /** @@ -33,7 +32,7 @@ import org.springframework.lang.Nullable; @Value.Immutable @Gson.TypeAdapters(fieldNamingStrategy = true) -public interface ConsumerDmaapModel extends AaiModel { +public interface ConsumerDmaapModel { @SerializedName(value = "correlationId", alternate = "correlationId") String getCorrelationId(); diff --git a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java index d717e245..fd9523a9 100644 --- a/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java +++ b/prh-commons/src/test/java/org/onap/dcaegen2/services/prh/adapter/aai/AbstractHttpClientTest.java @@ -22,16 +22,16 @@ package org.onap.dcaegen2.services.prh.adapter.aai; import static org.mockito.Mockito.mock; import org.onap.dcaegen2.services.prh.adapter.aai.api.AaiClientConfiguration; -import org.onap.dcaegen2.services.prh.adapter.aai.model.AaiModel; -import org.onap.dcaegen2.services.prh.adapter.aai.model.JsonBodyBuilder; +import org.onap.dcaegen2.services.prh.model.AaiJsonBodyBuilderImpl; +import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse; import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient; public class AbstractHttpClientTest { - protected final AaiModel aaiModel = () -> "test-id"; + protected final ConsumerDmaapModel aaiModel = mock(ConsumerDmaapModel.class); protected final RxHttpClient httpClient = mock(RxHttpClient.class); - protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class); + protected final AaiJsonBodyBuilderImpl bodyBuilder = mock(AaiJsonBodyBuilderImpl.class); protected final HttpResponse response = mock(HttpResponse.class); |