Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-lifecycle / src / main / java / org / onap / policy / drools / lifecycle / LifecycleStateActive.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=========================================================
21  */
22
23 package org.onap.policy.drools.lifecycle;
24
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;
32
33 /**
34  * Lifecycle Active State.
35  */
36 @ToString
37 public class LifecycleStateActive extends LifecycleStateRunning {
38     protected LifecycleStateActive(LifecycleFsm manager) {
39         super(manager);
40     }
41
42     @Override
43     public PdpState state() {
44         return PdpState.ACTIVE;
45     }
46
47     @Override
48     protected boolean stateChangeToActive(@NonNull PdpStateChange change) {
49         return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS, null));
50     }
51
52     @Override
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));
57     }
58
59     @Override
60     protected boolean deployPolicy(@NonNull PolicyTypeController controller, @NonNull ToscaPolicy policy) {
61         if (!controller.deploy(policy)) {
62             return false;
63         }
64
65         fsm.deployedPolicyAction(policy);
66         return true;
67     }
68
69     @Override
70     protected boolean undeployPolicy(@NonNull PolicyTypeController controller, @NonNull ToscaPolicy policy) {
71         controller.undeploy(policy);
72         fsm.undeployedPolicyAction(policy);
73         return true;
74     }
75 }