import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
private final ExecutorService executor =
Context.taskWrapping(Executors.newFixedThreadPool(1, new AcmThreadFactory()));
+ private static final Logger LOGGER =
+ LoggerFactory.getLogger(CommissioningProvider.class);
+
private CommissioningResponse createCommissioningResponse(UUID compositionId,
ToscaServiceTemplate serviceTemplate) {
var response = new CommissioningResponse();
*/
@Transactional
public CommissioningResponse createAutomationCompositionDefinition(ToscaServiceTemplate serviceTemplate) {
-
var acmDefinition = acDefinitionProvider.createAutomationCompositionDefinition(serviceTemplate,
acRuntimeParameterGroup.getAcmParameters().getToscaElementName(),
acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName());
serviceTemplate = acmDefinition.getServiceTemplate();
+ LOGGER.info("Create request received for ID: {}", acmDefinition.getCompositionId());
return createCommissioningResponse(acmDefinition.getCompositionId(), serviceTemplate);
}
*/
@Transactional
public CommissioningResponse updateCompositionDefinition(UUID compositionId, ToscaServiceTemplate serviceTemplate) {
+ LOGGER.info("Update request received for ID: {}", compositionId);
if (verifyIfInstanceExists(compositionId)) {
throw new PfModelRuntimeException(Status.BAD_REQUEST,
"There are ACM instances, Update of ACM Definition not allowed");
acDefinitionProvider.updateServiceTemplate(compositionId, serviceTemplate,
acRuntimeParameterGroup.getAcmParameters().getToscaElementName(),
acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName());
-
return createCommissioningResponse(compositionId, serviceTemplate);
}
*/
@Transactional
public CommissioningResponse deleteAutomationCompositionDefinition(UUID compositionId) {
+ LOGGER.info("Delete request received for ID: {}", compositionId);
if (verifyIfInstanceExists(compositionId)) {
throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Delete instances, to commission automation composition definitions");
@Transactional(readOnly = true)
public ToscaServiceTemplates getAutomationCompositionDefinitions(String acName, String acVersion,
@NonNull Pageable pageable) {
+ LOGGER.info("Get automation compositions request received for name: {} "
+ + "and version: {}", acName, acVersion);
var result = new ToscaServiceTemplates();
result.setServiceTemplates(acDefinitionProvider.getServiceTemplateList(acName, acVersion, pageable));
return result;
*/
@Transactional(readOnly = true)
public AutomationCompositionDefinition getAutomationCompositionDefinition(UUID compositionId) {
-
+ LOGGER.info("Get automation composition definition request received for ID: {}", compositionId);
return acDefinitionProvider.getAcDefinition(compositionId);
}
}
private void prime(AutomationCompositionDefinition acmDefinition) {
+ LOGGER.info("Prime request received for ID: {}", acmDefinition.getCompositionId());
var preparation = participantPrimePublisher.prepareParticipantPriming(acmDefinition);
acDefinitionProvider.updateAcDefinition(acmDefinition,
acRuntimeParameterGroup.getAcmParameters().getToscaCompositionName());
}
private void deprime(AutomationCompositionDefinition acmDefinition) {
+ LOGGER.info("Deprime request received for ID: {}", acmDefinition.getCompositionId());
acmDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
var participantIds = new HashSet<UUID>();
for (var elementState : acmDefinition.getElementStateMap().values()) {
--- /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.config;
+
+import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * Interceptor Config.
+ */
+@Profile("Logging")
+@Configuration
+public class InterceptorConfig {
+
+ /**
+ * Create WebMvcConfigurer to add EndPointInterceptor.
+ *
+ * @param endPointInterceptor the end-point Interceptor
+ * @return the WebMvcConfigurer
+ */
+ @Bean
+ public WebMvcConfigurer getWebMvcConfigurer(EndPointInterceptor endPointInterceptor) {
+ return new WebMvcConfigurer() {
+ @Override
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(endPointInterceptor);
+ }
+ };
+ }
+}
*/
public InstantiationResponse createAutomationComposition(UUID compositionId,
AutomationComposition automationComposition) {
+ LOGGER.info("Create instance request received for compositionId {}", compositionId);
AutomationCompositionProvider.validateInstanceEndpoint(compositionId, automationComposition);
automationCompositionProvider.validateNameVersion(automationComposition.getKey().asIdentifier());
var acDefinition = acDefinitionProvider.getAcDefinition(compositionId);
AcDefinitionProvider.checkPrimedComposition(acDefinition);
if (DeployState.UNDEPLOYED.equals(acToUpdate.getDeployState())) {
+ LOGGER.info("Updating undeployed instance with id {}", instanceId);
acToUpdate.setElements(automationComposition.getElements());
acToUpdate.setName(automationComposition.getName());
acToUpdate.setVersion(automationComposition.getVersion());
AutomationCompositionDefinition acDefinition) {
// save copy in case of a rollback
automationCompositionProvider.copyAcElementsBeforeUpdate(acToBeUpdated);
+ LOGGER.info("Updating deployed instance with id {}", automationComposition.getInstanceId());
// Iterate and update the element property values
for (var element : automationComposition.getElements().entrySet()) {
private InstantiationResponse migrateAutomationComposition(
AutomationComposition automationComposition, AutomationComposition acToBeUpdated,
AutomationCompositionDefinition acDefinition) {
-
+ LOGGER.info("Migrating instance with id {}", automationComposition.getInstanceId());
if (!DeployState.DEPLOYED.equals(acToBeUpdated.getDeployState())) {
throw new PfModelRuntimeException(Status.BAD_REQUEST,
"Not allowed to migrate in the state " + acToBeUpdated.getDeployState());
AutomationCompositionDefinition acDefinition) {
acToBeUpdated.setPrecheck(true);
+ LOGGER.info("Running migrate precheck for id: {}", automationComposition.getInstanceId());
var copyAc = new AutomationComposition(acToBeUpdated);
var acDefinitionTarget = acDefinitionProvider.getAcDefinition(automationComposition.getCompositionTargetId());
AcDefinitionProvider.checkPrimedComposition(acDefinitionTarget);
public InstantiationResponse deleteAutomationComposition(UUID compositionId, UUID instanceId) {
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
var acDefinition = getAcDefinition(compositionId, automationComposition);
+ LOGGER.info("Delete automation composition request received for name: {} and version: {}",
+ automationComposition.getName(), automationComposition.getVersion());
var result = acInstanceStateResolver.resolve(DeployOrder.DELETE,
null, null,
automationComposition.getDeployState(), automationComposition.getLockState(),
* @param instanceId The UUID of the automation composition instance
*/
public void rollback(UUID compositionId, UUID instanceId) {
+ LOGGER.info("Rollback automation composition request received for CompositionID: {} and InstanceID: {}",
+ compositionId, instanceId);
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
AutomationCompositionProvider.validateInstanceEndpoint(compositionId, automationComposition);
final String instanceIds, final String stateChangeResults, final String deployStates,
final Pageable pageable) {
+ LOGGER.info("Get automation compositions request received with filters");
List<String> acIds = new ArrayList<>();
if (instanceIds != null) {
Arrays.stream(instanceIds.split(",")).forEach(acId -> acIds.add(acId.trim()));
--- /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.main.utils;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Profile;
+import org.springframework.stereotype.Component;
+import org.springframework.web.servlet.HandlerInterceptor;
+
+/**
+ * EndPoint Interceptor.
+ */
+@Slf4j
+@Profile("Logging")
+@Component
+public class EndPointInterceptor implements HandlerInterceptor {
+
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
+ throws Exception {
+ log.info(request.getMethod() + " " + request.getRequestURI());
+ return true;
+ }
+}
* @return A list of available participants
*/
public List<ParticipantInformation> getAllParticipants(final Pageable pageable) {
+ LOGGER.info("Get request received for all participants");
var participants = this.participantProvider.getParticipants();
return participants.stream().map(participant -> createParticipantInformation(participant, pageable)).toList();
}
* @return The participant
*/
public ParticipantInformation getParticipantById(final UUID participantId, final Pageable pageable) {
+ LOGGER.info("Get participant by participantID request received: {}", participantId);
var participant = this.participantProvider.getParticipantById(participantId);
return createParticipantInformation(participant, pageable);
}
"Participant Not Found with ID: " + participantId);
}
supervisionParticipantHandler.handleRestart(participantId, null);
- LOGGER.debug("Restarting participant with ID: {}", participantId);
+ LOGGER.debug("Sync participant cache request received with ID: {}", participantId);
}
*/
public void restartAllParticipants() {
supervisionParticipantHandler.handleRestartOfAllParticipants();
- LOGGER.debug("Restarting all participants");
+ LOGGER.debug("Sync participant cache request received for all participants");
}
}
* @param acDefinition the AutomationCompositionDefinition
*/
public void deploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Deployment request received for instanceID: {}", automationComposition.getInstanceId());
if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
&& DeployState.DEPLOYING.equals(automationComposition.getDeployState())
&& automationComposition.getElements().size() > 1) {
* @param acDefinition the AutomationCompositionDefinition
*/
public void undeploy(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Undeployment request received for instanceID: {}", automationComposition.getInstanceId());
if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
&& DeployState.UNDEPLOYING.equals(automationComposition.getDeployState())
&& automationComposition.getElements().size() > 1) {
var startPhase = ParticipantUtils.getFirstStartPhase(automationComposition, acDefinition.getServiceTemplate());
automationComposition.setPhase(startPhase);
automationCompositionProvider.updateAutomationComposition(automationComposition);
- executor.execute(
- () -> automationCompositionStateChangePublisher.send(
- automationComposition, startPhase, true, acDefinition.getRevisionId()));
+ executor.execute(() -> automationCompositionStateChangePublisher.send(automationComposition,
+ startPhase, true, acDefinition.getRevisionId()));
}
/**
* @param acDefinition the AutomationCompositionDefinition
*/
public void unlock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Unlock request received for instanceID: {}", automationComposition.getInstanceId());
if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
&& LockState.UNLOCKING.equals(automationComposition.getLockState())
&& automationComposition.getElements().size() > 1) {
automationComposition.setPhase(startPhase);
automationCompositionProvider.updateAutomationComposition(automationComposition);
executor.execute(
- () -> automationCompositionStateChangePublisher.send(
- automationComposition, startPhase, true, acDefinition.getRevisionId()));
+ () -> automationCompositionStateChangePublisher.send(automationComposition,
+ startPhase, true, acDefinition.getRevisionId()));
}
/**
* @param acDefinition the AutomationCompositionDefinition
*/
public void prepare(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Prepare pre-deploy request received for instanceID: {}", automationComposition.getInstanceId());
AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE, SubState.PREPARING);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
var stage = ParticipantUtils.getFirstStage(automationComposition, acDefinition.getServiceTemplate());
* @param acDefinition the AutomationCompositionDefinition
*/
public void review(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Prepare post-deploy request received for instanceID: {}", automationComposition.getInstanceId());
AcmUtils.setCascadedState(automationComposition, DeployState.DEPLOYED, LockState.LOCKED, SubState.REVIEWING);
automationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
automationCompositionProvider.updateAutomationComposition(automationComposition);
* @param acDefinition the AutomationCompositionDefinition
*/
public void lock(AutomationComposition automationComposition, AutomationCompositionDefinition acDefinition) {
+ LOGGER.info("Lock request received for instanceID: {}", automationComposition.getInstanceId());
if (StateChangeResult.FAILED.equals(automationComposition.getStateChangeResult())
&& LockState.LOCKING.equals(automationComposition.getLockState())
&& automationComposition.getElements().size() > 1) {
automationComposition.setPhase(startPhase);
automationCompositionProvider.updateAutomationComposition(automationComposition);
executor.execute(
- () -> automationCompositionStateChangePublisher.send(
- automationComposition, startPhase, true, acDefinition.getRevisionId()));
+ () -> automationCompositionStateChangePublisher.send(automationComposition,
+ startPhase, true, acDefinition.getRevisionId()));
}
/**
--- /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.config;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+public class InterceptorConfigTest {
+
+ @Test
+ public void testGetWebMvcConfigurerAddsInterceptor() {
+ InterceptorConfig config = new InterceptorConfig();
+ EndPointInterceptor interceptor = mock(EndPointInterceptor.class);
+ InterceptorRegistry registry = mock(InterceptorRegistry.class);
+
+ when(registry.addInterceptor(interceptor)).thenReturn(null);
+
+ WebMvcConfigurer webMvcConfigurer = config.getWebMvcConfigurer(interceptor);
+ webMvcConfigurer.addInterceptors(registry);
+
+ verify(registry, times(1)).addInterceptor(interceptor);
+ }
+}
--- /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.util;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.main.utils.EndPointInterceptor;
+
+public class EndPointInterceptorTest {
+
+ @Test
+ public void testPreHandleReturnsTrueAndLogs() throws Exception {
+ EndPointInterceptor interceptor = new EndPointInterceptor();
+ HttpServletRequest request = mock(HttpServletRequest.class);
+ HttpServletResponse response = mock(HttpServletResponse.class);
+
+ when(request.getMethod()).thenReturn("GET");
+ when(request.getRequestURI()).thenReturn("/test/uri");
+
+ boolean result = interceptor.preHandle(request, response, new Object());
+
+ assertTrue(result);
+
+ verify(request).getMethod();
+ verify(request).getRequestURI();
+ }
+}
\ No newline at end of file