diff options
author | Ramesh Murugan Iyer <ramesh.murugan.iyer@est.tech> | 2023-01-23 09:31:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2023-01-23 09:31:50 +0000 |
commit | daf695ffed19108dad7fb228bab879d19c2ffbfa (patch) | |
tree | 2f48ae8116e484fab247fe4099c85089c409d809 /models/src/main/java/org | |
parent | 46964ab900060a560b9b41f7d34ab0e26ac7fd61 (diff) | |
parent | 467f0dbfe26a864a607286aab6d22c96e075bd17 (diff) |
Merge "Refactor AcInstanceState Update on ACM"
Diffstat (limited to 'models/src/main/java/org')
9 files changed, 193 insertions, 132 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java new file mode 100644 index 000000000..659b312d4 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/DeployState.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.policy.clamp.models.acm.concepts; + +public enum DeployState { + DEPLOYED, + DEPLOYING, + UNDEPLOYED, + UNDEPLOYING +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java new file mode 100644 index 000000000..a619cc2f7 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/LockState.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.policy.clamp.models.acm.concepts; + +public enum LockState { + LOCKED, + LOCKING, + UNLOCKED, + UNLOCKING, + NONE +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java index ed83a494a..e47947a02 100644 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AcInstanceStateUpdate.java @@ -24,18 +24,6 @@ import lombok.Data; @Data public class AcInstanceStateUpdate { - private enum DeployOrder { - NONE, - UNDEPLOY, - DEPLOYED - } - - private enum LockOrder { - NONE, - UNLOCK, - LOCK - } - private DeployOrder deployOrder; private LockOrder lockOrder; } diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java deleted file mode 100644 index a87433d4c..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/AutomationCompositionOrderStateResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.policy.clamp.models.acm.messages.rest.instantiation; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.messages.rest.GenericNameVersion; -import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; - - -/** - * Response to Commissioning requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class AutomationCompositionOrderStateResponse extends SimpleResponse { - - private AutomationCompositionOrderedState orderedState = AutomationCompositionOrderedState.UNINITIALISED; - - private List<GenericNameVersion> automationCompositionIdentifierList = new ArrayList<>(); -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java new file mode 100644 index 000000000..6c1572d19 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/DeployOrder.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.policy.clamp.models.acm.messages.rest.instantiation; + +public enum DeployOrder { + NONE, + UNDEPLOY, + DEPLOY +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java deleted file mode 100644 index 0341d5dae..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstancePropertiesResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 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.policy.clamp.models.acm.messages.rest.instantiation; - -import java.util.ArrayList; -import java.util.List; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; - -/** - * Response to Instance Properties requests that affect a change. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class InstancePropertiesResponse extends SimpleResponse { - private List<ToscaConceptIdentifier> affectedInstanceProperties = new ArrayList<>(); -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java deleted file mode 100644 index e6bdaee9d..000000000 --- a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/InstantiationOrderStateResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2021 Nordix Foundation. - * ================================================================================ - * Modifications Copyright (C) 2021 AT&T 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.clamp.models.acm.messages.rest.instantiation; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState; -import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; - -/** - * Response to instantiation OrderState. - */ -@Getter -@Setter -@ToString(callSuper = true) -public class InstantiationOrderStateResponse extends SimpleResponse { - - private AutomationCompositionOrderedState orderedState; -} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java new file mode 100644 index 000000000..6b0a208eb --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/messages/rest/instantiation/LockOrder.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.policy.clamp.models.acm.messages.rest.instantiation; + +public enum LockOrder { + NONE, + UNLOCK, + LOCK +} diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java new file mode 100644 index 000000000..dba64f585 --- /dev/null +++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcInstanceStateResolver.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.policy.clamp.models.acm.persistence.provider; + +import org.onap.policy.clamp.models.acm.concepts.DeployState; +import org.onap.policy.clamp.models.acm.concepts.LockState; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder; +import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder; +import org.onap.policy.clamp.models.acm.utils.StateDefinition; +import org.springframework.stereotype.Component; + +@Component +public class AcInstanceStateResolver { + private final StateDefinition<String> graph; + + private static final String DEPLOYED = DeployState.DEPLOYED.name(); + private static final String UNDEPLOYED = DeployState.UNDEPLOYED.name(); + + private static final String LOCKED = LockState.LOCKED.name(); + private static final String UNLOCKED = LockState.UNLOCKED.name(); + private static final String STATE_LOCKED_NONE = LockState.NONE.name(); + + private static final String DEPLOY_NONE = DeployOrder.NONE.name(); + private static final String LOCK_NONE = LockOrder.NONE.name(); + + // list of results + public static final String DEPLOY = DeployOrder.DEPLOY.name(); + public static final String UNDEPLOY = DeployOrder.UNDEPLOY.name(); + public static final String LOCK = LockOrder.LOCK.name(); + public static final String UNLOCK = LockOrder.UNLOCK.name(); + public static final String NONE = "NONE"; + + /** + * Construct. + */ + public AcInstanceStateResolver() { + this.graph = new StateDefinition<>(4, NONE); + + this.graph.put(new String[] {DEPLOY, LOCK_NONE, UNDEPLOYED, STATE_LOCKED_NONE}, DEPLOY); + this.graph.put(new String[] {UNDEPLOY, LOCK_NONE, DEPLOYED, LOCKED}, UNDEPLOY); + this.graph.put(new String[] {DEPLOY_NONE, UNLOCK, DEPLOYED, LOCKED}, UNLOCK); + this.graph.put(new String[] {DEPLOY_NONE, LOCK, DEPLOYED, UNLOCKED}, LOCK); + } + + /** + * Check if Deploy Order and Lock Order are consistent with current DeployState and LockState. + * + * @param acDeployOrder the Deploy Ordered + * @param acLockOrder the Lock Ordered + * @param acDeployState then current Deploy State + * @param acLockState the current Lock State + * @return the order (DEPLOY/UNDEPLOY/LOCK/UNLOCK) to send to participant or NONE if order is not consistent + */ + public String resolve(DeployOrder acDeployOrder, LockOrder acLockOrder, DeployState acDeployState, + LockState acLockState) { + var deployOrder = acDeployOrder != null ? acDeployOrder : DeployOrder.NONE; + var lockOrder = acLockOrder != null ? acLockOrder : LockOrder.NONE; + + var deployState = acDeployState != null ? acDeployState : DeployState.UNDEPLOYED; + var lockState = acLockState != null ? acLockState : LockState.NONE; + return this.graph + .get(new String[] {deployOrder.name(), lockOrder.name(), deployState.name(), lockState.name()}); + } +} |