2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.appc.oam.processor;
27 import com.att.eelf.configuration.EELFLogger;
28 import org.openecomp.appc.exceptions.APPCException;
29 import org.openecomp.appc.i18n.Msg;
30 import org.openecomp.appc.oam.AppcOam;
31 import org.openecomp.appc.oam.util.AsyncTaskHelper;
32 import org.openecomp.appc.oam.util.ConfigurationHelper;
33 import org.openecomp.appc.oam.util.OperationHelper;
34 import org.openecomp.appc.oam.util.StateHelper;
35 import org.openecomp.appc.requesthandler.LCMStateManager;
36 import org.openecomp.appc.statemachine.impl.readers.AppcOamStates;
39 * Processor to handle restart OAM API.
41 public class OamRestartProcessor extends BaseProcessor {
44 * <br> -ToStop: call bundles stop
45 * <br> -Stopped: check if all bundle state reached stopped
46 * <br> -ToStart: call bundles start
47 * <br> -Started: action is full completed
48 * <br> -Error: indication of error, such as timeout reached, bundler operation failure and etc.
50 private enum ActionPhases {
61 * @param eelfLogger for logging
62 * @param configurationHelper for property reading
63 * @param stateHelper for APP-C OAM state checking
64 * @param asyncTaskHelper for scheduling async task
65 * @param operationHelper for operational helper
67 public OamRestartProcessor(EELFLogger eelfLogger,
68 ConfigurationHelper configurationHelper,
69 StateHelper stateHelper,
70 AsyncTaskHelper asyncTaskHelper,
71 OperationHelper operationHelper) {
72 super(eelfLogger, configurationHelper, stateHelper, asyncTaskHelper, operationHelper);
74 rpc = AppcOam.RPC.restart;
75 auditMsg = Msg.OAM_OPERATION_RESTARTING;
79 protected void scheduleAsyncTask() {
80 runnable = new MyRunnable(this);
81 super.scheduleAsyncTask();
85 * This runnable does the async handling for the restart REST API. And it will be scheduled to run one time.
87 * <p>This runnable will the following operations: <br>
88 * - do APP-C OAM bundle stop and then start through BundlerHelper<br>
89 * - and always enable LCM operation handling (which can be disabled through maintenance mode API).<br>
90 * <p>Once above operations are done, the runnale will <br>
91 * - post message through operatonHelper <br>
92 * - set APP-C OAM state to started <br>
93 * - audit log the state <br>
95 class MyRunnable extends BaseActionRunnable {
97 ActionPhases currentPhase = ActionPhases.ToStop;
98 private LCMStateManager lcmStateManager;
100 MyRunnable(BaseProcessor parent) {
103 actionName = "OAM Restart";
104 auditMsg = Msg.OAM_OPERATION_RESTARTED;
105 finalState = AppcOamStates.Started;
109 * Do restart action, include stop then start and always enable LCM operation.
110 * @return true if action is successful, false when aciton is failed or aborted
114 logDebug(String.format("Executing %s task at phase (%s)",
115 actionName, currentPhase == null ? "null" : currentPhase.name()));
117 boolean isBundleOperationCompleted = true;
119 switch (currentPhase) {
121 isBundleOperationCompleted = bundleHelper.bundleOperations(
122 AppcOam.RPC.stop, bundleNameToFuture, myParent.asyncTaskHelper, this);
123 currentPhase = ActionPhases.Stopped;
127 AppcOamStates currentState = stateHelper.getBundlesState();
128 if (currentState == AppcOamStates.Stopped) {
129 currentPhase = ActionPhases.ToStart;
131 logDebug(String.format("%s task is waiting in stopped phase, current state is %s",
132 actionName, currentState));
136 isBundleOperationCompleted = bundleHelper.bundleOperations(
137 AppcOam.RPC.start, bundleNameToFuture, myParent.asyncTaskHelper, this);
138 currentPhase = ActionPhases.Started;
144 // Should not reach log it and return false;
145 logger.error("%s task doAction reached %s phase. not supported. return false.",
146 actionName, currentPhase.name());
147 stateHelper.setState(AppcOamStates.Error);
151 if (isTimeout("restart doAction")
152 || hasBundleOperationFailure()) {
153 currentPhase = ActionPhases.Error;
156 if (isBundleOperationCompleted) {
161 } catch (APPCException e) {
163 stateHelper.setState(AppcOamStates.Error);
170 * With additional to get the LCMStateManager service
171 * @see BaseActionRunnable#checkState()
174 boolean checkState() {
175 switch (currentPhase) {
178 lcmStateManager = operationHelper.getService(LCMStateManager.class);
179 return super.checkState();
180 } catch (APPCException e) {
181 logDebug("LCMStateManager is not available.");
185 // in all the other ActionPhase, we want the run go back to doAction
192 * Final handling. The thread is cancelled.
193 * @param setState boolean to indicate if set OAM state or not
196 void postDoAction(boolean setState) {
197 AppcOamStates newState = null;
199 logDebug("Always enable LCM operation");
200 lcmStateManager.enableLCMOperations();
201 newState = finalState;
203 postAction(newState);
204 super.postDoAction(setState);