# ============LICENSE_START=======================================================
-# Copyright (C) 2022-2023 Nordix Foundation.
+# Copyright (C) 2022-2023,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.
eventProtocolParameters:
eventProtocol: JSON
eventNameFilter: CDSResponseStatusEvent
+metadata:
+ primeTimeoutMs: 200000
+ deprimeTimeoutMs: 100000
public final class ParticipantUtils {
private static final String STAGE_MIGRATE = "migrate";
private static final String STAGE_PREPARE = "prepare";
+ public static final String DEFAULT_TIMEOUT = "maxOperationWaitMs";
+ public static final String PRIME_TIMEOUT = "primeTimeoutMs";
+ public static final String DEPRIME_TIMEOUT = "deprimeTimeoutMs";
+ public static final String DEPLOY_TIMEOUT = "deployTimeoutMs";
+ public static final String UNDEPLOY_TIMEOUT = "undeployTimeoutMs";
+ public static final String UPDATE_TIMEOUT = "updateTimeoutMs";
+ public static final String MIGRATE_TIMEOUT = "migrateTimeoutMs";
+ public static final String DELETE_TIMEOUT = "deleteTimeoutMs";
+
+ public static final Map<DeployState, String> MAP_TIMEOUT = Map.of(DeployState.DEPLOYING, DEPLOY_TIMEOUT,
+ DeployState.UNDEPLOYING, UNDEPLOY_TIMEOUT,
+ DeployState.UPDATING, UPDATE_TIMEOUT,
+ DeployState.MIGRATING, MIGRATE_TIMEOUT,
+ DeployState.DELETING, DELETE_TIMEOUT);
/**
* Get the First StartPhase.
return Set.of(0);
}
+ /**
+ * Get timeout value from properties by name operation, return default value if not present.
+ *
+ * @param properties instance properties
+ * @param name the operation name
+ * @param defaultValue the default value
+ * @return the timeout value
+ */
+ public static long getTimeout(Map<String, Object> properties, String name, long defaultValue) {
+ var objTimeout = properties.get(name);
+ if (objTimeout != null) {
+ return Long.parseLong(objTimeout.toString());
+ }
+ return defaultValue;
+ }
+
+ /**
+ * Get operation name of a composition definition.
+ *
+ * @param state the state of the composition definition
+ * @return the operation name
+ */
+ public static String getOpName(AcTypeState state) {
+ return AcTypeState.PRIMING.equals(state) ? PRIME_TIMEOUT : DEPRIME_TIMEOUT;
+ }
+
+ /**
+ * Get operation name of a AutomationComposition.
+ *
+ * @param deployState the state of the AutomationComposition
+ * @return the operation name
+ */
+ public static String getOpName(DeployState deployState) {
+ return MAP_TIMEOUT.getOrDefault(deployState, DEFAULT_TIMEOUT);
+ }
+
/**
* Finds stage from a map of properties for Migrate.
*
package org.onap.policy.clamp.models.acm.concepts;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Map;
import org.junit.jupiter.api.Test;
result = ParticipantUtils.findStageSetMigrate(map);
assertThat(result).hasSize(2).contains(2).contains(3);
}
+
+ @Test
+ void testGetTimeout() {
+ var result = ParticipantUtils.getTimeout(Map.of(), ParticipantUtils.DEPLOY_TIMEOUT, 1000);
+ assertEquals(1000, result);
+
+ result = ParticipantUtils.getTimeout(Map.of(ParticipantUtils.DEPLOY_TIMEOUT, 20000),
+ ParticipantUtils.DEPLOY_TIMEOUT, 1000);
+ assertEquals(20000, result);
+ }
+
+ @Test
+ void testGetOpName() {
+ var result = ParticipantUtils.getOpName(AcTypeState.PRIMING);
+ assertEquals(ParticipantUtils.PRIME_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(AcTypeState.DEPRIMING);
+ assertEquals(ParticipantUtils.DEPRIME_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.DEPLOYING);
+ assertEquals(ParticipantUtils.DEPLOY_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.UNDEPLOYING);
+ assertEquals(ParticipantUtils.UNDEPLOY_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.UPDATING);
+ assertEquals(ParticipantUtils.UPDATE_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.DELETING);
+ assertEquals(ParticipantUtils.DELETE_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.MIGRATING);
+ assertEquals(ParticipantUtils.MIGRATE_TIMEOUT, result);
+ result = ParticipantUtils.getOpName(DeployState.DEPLOYED);
+ assertEquals(ParticipantUtils.DEFAULT_TIMEOUT, result);
+ }
}
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublisher;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.concepts.SubState;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
saveAndSync(automationComposition, updateSync);
return;
}
+ var name = ParticipantUtils.getOpName(automationComposition.getDeployState());
+ var element = automationComposition.getElements().values().stream()
+ .filter(el -> automationComposition.getDeployState().equals(el.getDeployState())).findFirst();
+ var maxWaitMs = element.map(automationCompositionElement -> ParticipantUtils.getTimeout(
+ automationCompositionElement.getProperties(), name, maxOperationWaitMs)).orElse(maxOperationWaitMs);
var now = TimestampHelper.nowEpochMilli();
var lastMsg = TimestampHelper.toEpochMilli(automationComposition.getLastMsg());
- if ((now - lastMsg) > maxOperationWaitMs) {
+ if ((now - lastMsg) > maxWaitMs) {
LOGGER.debug("Report timeout for the ac instance {}", automationComposition.getInstanceId());
automationComposition.setStateChangeResult(StateChangeResult.TIMEOUT);
updateSync.setUpdated(true);
import org.onap.policy.clamp.acm.runtime.supervision.comm.ParticipantSyncPublisher;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantUtils;
import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.document.concepts.DocMessage;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
LOGGER.debug("The ac definition is in timeout {}", acDefinition.getCompositionId());
return result;
}
- var now = TimestampHelper.nowEpochMilli();
+ var name = ParticipantUtils.getOpName(acDefinition.getState());
+ var maxWaitMs = ParticipantUtils
+ .getTimeout(acDefinition.getServiceTemplate().getMetadata(), name, maxOperationWaitMs);
var lastMsg = TimestampHelper.toEpochMilli(acDefinition.getLastMsg());
- if ((now - lastMsg) > maxOperationWaitMs) {
+ var now = TimestampHelper.nowEpochMilli();
+ if ((now - lastMsg) > maxWaitMs) {
LOGGER.debug("Report timeout for the ac definition {}", acDefinition.getCompositionId());
acDefinition.setStateChangeResult(StateChangeResult.TIMEOUT);
result.setUpdated(true);
private AutomationCompositionDefinition createAutomationCompositionDefinition(AcTypeState acTypeState) {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ serviceTemplate.setMetadata(Map.of("compositionId", COMPOSITION_ID));
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setState(acTypeState);
acDefinition.setStateChangeResult(StateChangeResult.NO_ERROR);
private AutomationCompositionDefinition createAutomationCompositionDefinition(AcTypeState acTypeState,
StateChangeResult stateChangeResult) {
var serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ serviceTemplate.setMetadata(Map.of("compositionId", COMPOSITION_ID));
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setState(acTypeState);
acDefinition.setStateChangeResult(stateChangeResult);
},
"deployState": "UNDEPLOYED",
"lockState": "NONE",
- "description": "Automation composition element for the K8S microservice for PMSH"
+ "description": "Automation composition element for the K8S microservice for PMSH",
+ "deployTimeoutMs": "200000",
+ "undeployTimeoutMs": "150000",
+ "updateTimeoutMs": "200000",
+ "migrateTimeoutMs": "200000",
+ "deleteTimeoutMs": "100000"
},
"709c62b3-8918-41b9-a747-d21eb79c6c21": {
"id": "709c62b3-8918-41b9-a747-d21eb79c6c21",
},
"deployState": "UNDEPLOYED",
"lockState": "NONE",
- "description": "Automation composition element for the http requests of PMSH microservice"
+ "description": "Automation composition element for the http requests of PMSH microservice",
+ "deployTimeoutMs": "200000",
+ "undeployTimeoutMs": "150000",
+ "updateTimeoutMs": "200000",
+ "migrateTimeoutMs": "200000",
+ "deleteTimeoutMs": "100000"
},
"709c62b3-8918-41b9-a747-d21eb79c6c22": {
"id": "709c62b3-8918-41b9-a747-d21eb79c6c22",
},
"deployState": "UNDEPLOYED",
"lockState": "NONE",
- "description": "Automation composition element for the operational policy for Performance Management Subscription Handling"
+ "description": "Automation composition element for the operational policy for Performance Management Subscription Handling",
+ "deployTimeoutMs": "200000",
+ "undeployTimeoutMs": "150000",
+ "updateTimeoutMs": "200000",
+ "migrateTimeoutMs": "200000",
+ "deleteTimeoutMs": "100000"
}
}
}