summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorhalil.cakal <halil.cakal@est.tech>2023-08-01 16:35:58 +0100
committerhalil.cakal <halil.cakal@est.tech>2023-08-04 14:41:42 +0100
commit640e0ed06320d594e0ef18557f0051ead853712e (patch)
tree33c0989d420facf4c088e91776ae8489be6ec415 /cps-ncmp-service/src/main/java/org/onap
parent7a049060b9ee2306eb562f75a1cbd0d50eb14f41 (diff)
Subscription Creation: Fixes for code review after demo
- Change missleading subscription details in testware - Change datastore check to comply with CPS enum - Remove redundant CloudConstructionException - Change exception handling in cloud event mappers to avoid loss of information - Remove exception handling from scheduler service as discussed in the meeting Issue-ID: CPS-1732 Change-Id: I9fee2eafd4db97a0eed80e39219463c904f5a980 Signed-off-by: halil.cakal <halil.cakal@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumer.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java3
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java4
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CloudEventConstructionException.java41
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapper.java20
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapper.java11
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java18
9 files changed, 46 insertions, 84 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java
index 176e644bae..e3f529787a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/ResponseTimeoutTask.java
@@ -36,17 +36,10 @@ public class ResponseTimeoutTask implements Runnable {
@Override
public void run() {
-
- try {
- generateAndSendResponse();
- } catch (final Exception exception) {
- log.info("Caught exception in Runnable for ResponseTimeoutTask. StackTrace: {}",
- exception.toString());
- }
-
+ generateTimeoutResponse();
}
- private void generateAndSendResponse() {
+ private void generateTimeoutResponse() {
final String subscriptionClientId = subscriptionEventResponse.getData().getClientId();
final String subscriptionName = subscriptionEventResponse.getData().getSubscriptionName();
final String subscriptionEventId = subscriptionClientId + subscriptionName;
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumer.java
index c80b07cb70..8dfdc3cd4e 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventConsumer.java
@@ -20,6 +20,9 @@
package org.onap.cps.ncmp.api.impl.events.avcsubscription;
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_OPERATIONAL;
+import static org.onap.cps.ncmp.api.impl.operations.DatastoreType.PASSTHROUGH_RUNNING;
+
import io.cloudevents.CloudEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -41,6 +44,7 @@ public class SubscriptionEventConsumer {
private final SubscriptionEventForwarder subscriptionEventForwarder;
private final SubscriptionEventMapper subscriptionEventMapper;
private final SubscriptionPersistence subscriptionPersistence;
+ private final SubscriptionEventCloudMapper subscriptionEventCloudMapper;
@Value("${notification.enabled:true}")
private boolean notificationFeatureEnabled;
@@ -58,11 +62,12 @@ public class SubscriptionEventConsumer {
public void consumeSubscriptionEvent(final ConsumerRecord<String, CloudEvent> subscriptionEventConsumerRecord) {
final CloudEvent cloudEvent = subscriptionEventConsumerRecord.value();
final String eventType = subscriptionEventConsumerRecord.value().getType();
- final SubscriptionEvent subscriptionEvent = SubscriptionEventCloudMapper.toSubscriptionEvent(cloudEvent);
+ final SubscriptionEvent subscriptionEvent = subscriptionEventCloudMapper.toSubscriptionEvent(cloudEvent);
final String eventDatastore = subscriptionEvent.getData().getPredicates().getDatastore();
- if (!(eventDatastore.equals("passthrough-running") || eventDatastore.equals("passthrough-operational"))) {
+ if (!eventDatastore.equals(PASSTHROUGH_RUNNING.getDatastoreName())
+ || eventDatastore.equals(PASSTHROUGH_OPERATIONAL.getDatastoreName())) {
throw new UnsupportedOperationException(
- "passthrough datastores are currently only supported for event subscriptions");
+ "passthrough datastores are currently only supported for event subscriptions");
}
if ("CM".equals(subscriptionEvent.getData().getDataType().getDataCategory())) {
if (subscriptionModelLoaderEnabled) {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java
index 0eda914f23..d3bfe81e82 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventForwarder.java
@@ -61,6 +61,7 @@ public class SubscriptionEventForwarder {
private final IMap<String, Set<String>> forwardedSubscriptionEventCache;
private final SubscriptionEventResponseOutcome subscriptionEventResponseOutcome;
private final SubscriptionEventMapper subscriptionEventMapper;
+ private final SubscriptionEventCloudMapper subscriptionEventCloudMapper;
private final ClientSubscriptionEventMapper clientSubscriptionEventMapper;
private final SubscriptionPersistence subscriptionPersistence;
private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
@@ -132,12 +133,8 @@ public class SubscriptionEventForwarder {
final ResponseTimeoutTask responseTimeoutTask =
new ResponseTimeoutTask(forwardedSubscriptionEventCache, subscriptionEventResponseOutcome,
emptySubscriptionEventResponse);
- try {
- executorService.schedule(responseTimeoutTask, dmiResponseTimeoutInMs, TimeUnit.MILLISECONDS);
- } catch (final RuntimeException ex) {
- log.info("Caught exception in ScheduledExecutorService for ResponseTimeoutTask. StackTrace: {}",
- ex.toString());
- }
+
+ executorService.schedule(responseTimeoutTask, dmiResponseTimeoutInMs, TimeUnit.MILLISECONDS);
}
private void forwardEventToDmis(final Map<String, Map<String, Map<String, String>>> dmiNameCmHandleMap,
@@ -157,7 +154,7 @@ public class SubscriptionEventForwarder {
final String dmiAvcSubscriptionTopic = dmiAvcSubscriptionTopicPrefix + dmiName;
final CloudEvent ncmpSubscriptionCloudEvent =
- SubscriptionEventCloudMapper.toCloudEvent(ncmpSubscriptionEvent, eventKey, eventType);
+ subscriptionEventCloudMapper.toCloudEvent(ncmpSubscriptionEvent, eventKey, eventType);
eventsPublisher.publishCloudEvent(dmiAvcSubscriptionTopic, eventKey, ncmpSubscriptionCloudEvent);
});
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java
index ddb9fd6fcf..b1c0a322dd 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseConsumer.java
@@ -50,6 +50,7 @@ public class SubscriptionEventResponseConsumer {
private final SubscriptionPersistence subscriptionPersistence;
private final SubscriptionEventResponseMapper subscriptionEventResponseMapper;
private final SubscriptionEventResponseOutcome subscriptionEventResponseOutcome;
+ private final SubscriptionEventResponseCloudMapper subscriptionEventResponseCloudMapper;
@Value("${notification.enabled:true}")
private boolean notificationFeatureEnabled;
@@ -69,7 +70,7 @@ public class SubscriptionEventResponseConsumer {
final CloudEvent cloudEvent = subscriptionEventResponseConsumerRecord.value();
final String eventType = subscriptionEventResponseConsumerRecord.value().getType();
final SubscriptionEventResponse subscriptionEventResponse =
- SubscriptionEventResponseCloudMapper.toSubscriptionEventResponse(cloudEvent);
+ subscriptionEventResponseCloudMapper.toSubscriptionEventResponse(cloudEvent);
final String clientId = subscriptionEventResponse.getData().getClientId();
log.info("subscription event response of clientId: {} is received.", clientId);
final String subscriptionName = subscriptionEventResponse.getData().getSubscriptionName();
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java
index 9ed686529d..822ca55091 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/events/avcsubscription/SubscriptionEventResponseOutcome.java
@@ -48,6 +48,8 @@ public class SubscriptionEventResponseOutcome {
private final SubscriptionOutcomeMapper subscriptionOutcomeMapper;
+ private final SubscriptionOutcomeCloudMapper subscriptionOutcomeCloudMapper;
+
@Value("${app.ncmp.avc.subscription-outcome-topic:subscription-response}")
private String subscriptionOutcomeEventTopic;
@@ -63,7 +65,7 @@ public class SubscriptionEventResponseOutcome {
final String subscriptionName = subscriptionEventResponse.getData().getSubscriptionName();
final String subscriptionEventId = subscriptionClientId + subscriptionName;
final CloudEvent subscriptionOutcomeCloudEvent =
- SubscriptionOutcomeCloudMapper.toCloudEvent(subscriptionEventOutcome,
+ subscriptionOutcomeCloudMapper.toCloudEvent(subscriptionEventOutcome,
subscriptionEventId, eventKey);
outcomeEventsPublisher.publishCloudEvent(subscriptionOutcomeEventTopic,
subscriptionEventId, subscriptionOutcomeCloudEvent);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CloudEventConstructionException.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CloudEventConstructionException.java
deleted file mode 100644
index d0be344f2e..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CloudEventConstructionException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2020 Pantheon.tech
- * Modifications Copyright (C) 2020 Bell Canada
- * Modifications Copyright (C) 2020-2023 Nordix Foundation
- * ================================================================================
- * 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.ncmp.api.impl.utils;
-
-import org.onap.cps.spi.exceptions.CpsException;
-
-public class CloudEventConstructionException extends CpsException {
-
- private static final long serialVersionUID = 7747941311132087621L;
-
- /**
- * Constructor.
- *
- * @param message the error message
- * @param details the error details
- * @param cause the error cause
- */
- public CloudEventConstructionException(final String message, final String details, final Throwable cause) {
- super(message, details, cause);
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapper.java
index d0d70cf028..1561edc448 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventCloudMapper.java
@@ -20,6 +20,7 @@
package org.onap.cps.ncmp.api.impl.utils;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.cloudevents.CloudEvent;
import io.cloudevents.core.CloudEventUtils;
@@ -28,16 +29,17 @@ import io.cloudevents.core.data.PojoCloudEventData;
import io.cloudevents.jackson.PojoCloudEventDataMapper;
import java.net.URI;
import java.util.UUID;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.events.avcsubscription1_0_0.client_to_ncmp.SubscriptionEvent;
+import org.springframework.stereotype.Component;
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
+@Component
+@RequiredArgsConstructor
public class SubscriptionEventCloudMapper {
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ private final ObjectMapper objectMapper;
private static String randomId = UUID.randomUUID().toString();
@@ -47,7 +49,7 @@ public class SubscriptionEventCloudMapper {
* @param cloudEvent object.
* @return SubscriptionEvent deserialized.
*/
- public static SubscriptionEvent toSubscriptionEvent(final CloudEvent cloudEvent) {
+ public SubscriptionEvent toSubscriptionEvent(final CloudEvent cloudEvent) {
final PojoCloudEventData<SubscriptionEvent> deserializedCloudEvent = CloudEventUtils
.mapData(cloudEvent, PojoCloudEventDataMapper.from(objectMapper, SubscriptionEvent.class));
if (deserializedCloudEvent == null) {
@@ -67,7 +69,7 @@ public class SubscriptionEventCloudMapper {
* @param eventKey as String.
* @return CloudEvent built.
*/
- public static CloudEvent toCloudEvent(
+ public CloudEvent toCloudEvent(
final org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_dmi.SubscriptionEvent ncmpSubscriptionEvent,
final String eventKey, final String eventType) {
try {
@@ -80,9 +82,9 @@ public class SubscriptionEventCloudMapper {
+ org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_dmi
.SubscriptionEvent.class.getName() + ":1.0.0"))
.withData(objectMapper.writeValueAsBytes(ncmpSubscriptionEvent)).build();
- } catch (final Exception ex) {
- throw new CloudEventConstructionException("The Cloud Event could not be constructed", "Invalid object to "
- + "serialize or required headers is missing", ex);
+ } catch (final JsonProcessingException jsonProcessingException) {
+ log.error("The Cloud Event could not be constructed", jsonProcessingException);
}
+ return null;
}
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapper.java
index 17aba65cf7..e00bb16b93 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionEventResponseCloudMapper.java
@@ -25,16 +25,17 @@ import io.cloudevents.CloudEvent;
import io.cloudevents.core.CloudEventUtils;
import io.cloudevents.core.data.PojoCloudEventData;
import io.cloudevents.jackson.PojoCloudEventDataMapper;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.events.avcsubscription1_0_0.dmi_to_ncmp.SubscriptionEventResponse;
+import org.springframework.stereotype.Component;
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
+@Component
+@RequiredArgsConstructor
public class SubscriptionEventResponseCloudMapper {
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ private final ObjectMapper objectMapper;
/**
* Maps CloudEvent object to SubscriptionEventResponse.
@@ -42,7 +43,7 @@ public class SubscriptionEventResponseCloudMapper {
* @param cloudEvent object
* @return SubscriptionEventResponse deserialized
*/
- public static SubscriptionEventResponse toSubscriptionEventResponse(final CloudEvent cloudEvent) {
+ public SubscriptionEventResponse toSubscriptionEventResponse(final CloudEvent cloudEvent) {
final PojoCloudEventData<SubscriptionEventResponse> deserializedCloudEvent = CloudEventUtils
.mapData(cloudEvent, PojoCloudEventDataMapper.from(objectMapper, SubscriptionEventResponse.class));
if (deserializedCloudEvent == null) {
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java
index b6cb039a9c..9ea4487063 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/SubscriptionOutcomeCloudMapper.java
@@ -20,21 +20,23 @@
package org.onap.cps.ncmp.api.impl.utils;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.cloudevents.CloudEvent;
import io.cloudevents.core.builder.CloudEventBuilder;
import java.net.URI;
import java.util.UUID;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.ncmp.events.avcsubscription1_0_0.ncmp_to_client.SubscriptionEventOutcome;
+import org.springframework.stereotype.Component;
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
+@Component
+@RequiredArgsConstructor
public class SubscriptionOutcomeCloudMapper {
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ private final ObjectMapper objectMapper;
private static String randomId = UUID.randomUUID().toString();
@@ -44,7 +46,7 @@ public class SubscriptionOutcomeCloudMapper {
* @param subscriptionEventOutcome object
* @return CloudEvent
*/
- public static CloudEvent toCloudEvent(final SubscriptionEventOutcome subscriptionEventOutcome,
+ public CloudEvent toCloudEvent(final SubscriptionEventOutcome subscriptionEventOutcome,
final String eventKey, final String eventType) {
try {
return CloudEventBuilder.v1()
@@ -54,9 +56,9 @@ public class SubscriptionOutcomeCloudMapper {
.withExtension("correlationid", eventKey)
.withDataSchema(URI.create("urn:cps:" + SubscriptionEventOutcome.class.getName() + ":1.0.0"))
.withData(objectMapper.writeValueAsBytes(subscriptionEventOutcome)).build();
- } catch (final Exception ex) {
- throw new CloudEventConstructionException("The Cloud Event could not be constructed", "Invalid object to "
- + "serialize or required headers is missing", ex);
+ } catch (final JsonProcessingException jsonProcessingException) {
+ log.error("The Cloud Event could not be constructed", jsonProcessingException);
}
+ return null;
}
}