2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Bell Canada.
7 * Modifications Copyright (C) 2023-2024 Nordix Foundation.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.drools.lifecycle;
25 import java.util.Collections;
26 import lombok.NonNull;
27 import lombok.ToString;
28 import org.onap.policy.models.pdp.concepts.PdpStateChange;
29 import org.onap.policy.models.pdp.enums.PdpResponseStatus;
30 import org.onap.policy.models.pdp.enums.PdpState;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
34 * Lifecycle Active State.
37 public class LifecycleStateActive extends LifecycleStateRunning {
38 protected LifecycleStateActive(LifecycleFsm manager) {
43 public PdpState state() {
44 return PdpState.ACTIVE;
48 protected boolean stateChangeToActive(@NonNull PdpStateChange change) {
49 return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS, null));
53 protected boolean stateChangeToPassive(@NonNull PdpStateChange change) {
54 undeployPolicies(Collections.emptyList());
55 fsm.transitionToAction(new LifecycleStatePassive(fsm));
56 return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS, null));
60 protected boolean deployPolicy(@NonNull PolicyTypeController controller, @NonNull ToscaPolicy policy) {
61 if (!controller.deploy(policy)) {
65 fsm.deployedPolicyAction(policy);
70 protected boolean undeployPolicy(@NonNull PolicyTypeController controller, @NonNull ToscaPolicy policy) {
71 controller.undeploy(policy);
72 fsm.undeployedPolicyAction(policy);