import java.util.UUID;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
-import org.hibernate.exception.ConstraintViolationException;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.document.concepts.DocMessage;
import org.onap.policy.clamp.models.acm.messages.kafka.participant.AutomationCompositionDeployAck;
try {
var result = messageJobRepository.save(job);
return Optional.of(result.getJobId());
- } catch (ConstraintViolationException ex) {
+ } catch (RuntimeException ex) {
// already exist a job with this identificationId
LOGGER.warn(ex.getMessage());
}
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.acm.runtime.main.parameters.AcRuntimeParameterGroup;
+import org.onap.policy.clamp.acm.runtime.supervision.AcmThreadFactory;
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantPrimePublisher;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
private final ParticipantPrimePublisher participantPrimePublisher;
private final AcRuntimeParameterGroup acRuntimeParameterGroup;
- private final ExecutorService executor = Context.taskWrapping(Executors.newFixedThreadPool(1));
+ private final ExecutorService executor =
+ Context.taskWrapping(Executors.newFixedThreadPool(1, new AcmThreadFactory()));
private CommissioningResponse createCommissioningResponse(UUID compositionId,
ToscaServiceTemplate serviceTemplate) {
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import java.util.concurrent.ThreadFactory;
+import lombok.NonNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AcmThreadFactory implements ThreadFactory {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AcmThreadFactory.class);
+
+ protected void uncaughtException(Thread t, Throwable e) {
+ LOGGER.error("Uncaught Exception: {}", e.getMessage(), e);
+ }
+
+ @Override
+ public Thread newThread(@NonNull Runnable r) {
+ final var thread = new Thread(r);
+ thread.setUncaughtExceptionHandler(this::uncaughtException);
+ return thread;
+ }
+}
private final MessageProvider messageProvider;
private final EncryptionUtils encryptionUtils;
- private final ExecutorService executor = Context.taskWrapping(Executors.newFixedThreadPool(1));
+ private final ExecutorService executor =
+ Context.taskWrapping(Executors.newFixedThreadPool(1, new AcmThreadFactory()));
/**
* Handle Deploy an AutomationComposition instance.
private final SupervisionParticipantScanner participantScanner;
private final ThreadPoolExecutor executor =
- new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
+ new ThreadPoolExecutor(1, 1, 0L,
+ TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new AcmThreadFactory());
@Scheduled(
fixedRateString = "${runtime.participantParameters.heartBeatMs}",
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2025 OpenInfra Foundation Europe. 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.acm.runtime.supervision;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+import org.junit.jupiter.api.Test;
+
+class AcmThreadFactoryTest {
+
+ @Test
+ void test() throws InterruptedException {
+ var threadFactory = spy(new AcmThreadFactory());
+ var thread = threadFactory.newThread(new Thread(() -> {
+ throw new RuntimeException("Error");
+ }));
+ thread.start();
+ thread.join();
+ verify(threadFactory).uncaughtException(any(), any());
+ }
+}