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.exceptions.InvalidInputException;
30 import org.openecomp.appc.exceptions.InvalidStateException;
31 import org.openecomp.appc.i18n.Msg;
32 import org.openecomp.appc.oam.AppcOam;
33 import org.openecomp.appc.oam.OAMCommandStatus;
34 import org.openecomp.appc.oam.util.AsyncTaskHelper;
35 import org.openecomp.appc.oam.util.ConfigurationHelper;
36 import org.openecomp.appc.oam.util.OperationHelper;
37 import org.openecomp.appc.oam.util.StateHelper;
38 import org.openecomp.appc.requesthandler.LCMStateManager;
39 import org.openecomp.appc.requesthandler.RequestHandler;
40 import org.openecomp.appc.statemachine.impl.readers.AppcOamStates;
43 * Processor to handle maintenance mode OAM API.
45 public class OamMmodeProcessor extends BaseProcessor {
49 * @param eelfLogger for logging
50 * @param configurationHelper for property reading
51 * @param stateHelper for APP-C OAM state checking
52 * @param asyncTaskHelper for scheduling async task
53 * @param operationHelper for operational helper
55 public OamMmodeProcessor(EELFLogger eelfLogger,
56 ConfigurationHelper configurationHelper,
57 StateHelper stateHelper,
58 AsyncTaskHelper asyncTaskHelper,
59 OperationHelper operationHelper) {
60 super(eelfLogger, configurationHelper, stateHelper, asyncTaskHelper, operationHelper);
62 rpc = AppcOam.RPC.maintenance_mode;
63 auditMsg = Msg.OAM_OPERATION_ENTERING_MAINTENANCE_MODE;
67 protected void preProcess(final Object requestInput)
68 throws InvalidInputException, InvalidStateException, APPCException {
69 super.preProcess(requestInput);
71 //Close the gate so that no more new LCM request will be excepted.
72 LCMStateManager lcmStateManager = operationHelper.getService(LCMStateManager.class);
73 lcmStateManager.disableLCMOperations();
77 protected void scheduleAsyncTask() {
78 runnable = new MyRunnable(this);
79 super.scheduleAsyncTask();
83 * This runnable does the async handling for the maintenance mode REST API, and will be scheduled to run
84 * until terminating condition reaches.
86 * <p>The runnable will conintue run if: <br>
87 * - the runnable is not canceled outside <br>
88 * - the in progress LCM request count is not zero<br>
89 * <p> When LCM request count reaches to zero, this runnable will: <br>
90 * - post message through operatonHelper <br>
91 * - set APP-C OAM state to maintenance mode <br>
92 * - audit log the state <br>
93 * - terminate this runnable itself <br>
95 class MyRunnable extends BaseActionRunnable {
96 private int inprogressRequestCount;
98 MyRunnable(BaseProcessor parent) {
101 actionName = "OAM Maintanence mode";
102 auditMsg = Msg.OAM_OPERATION_MAINTENANCE_MODE;
103 finalState = AppcOamStates.MaintenanceMode;
108 // always return true, so that we can check the LCM request count
113 boolean checkState() {
114 logDebug(String.format("Executing %s task", actionName));
116 if (!myParent.isSameAsyncTask()) {
117 // cancel myself if I am not the current backgroundOamTask
118 myParent.cancelAsyncTask();
119 logDebug(String.format("Finished %s task due to task removed", actionName));
123 boolean hasError = false;
125 inprogressRequestCount = getInprogressLCMRequestCount();
126 if (inprogressRequestCount > 0) {
127 // if there are still LCM request in progress, keep waiting
131 setStatus(OAMCommandStatus.SUCCESS);
132 } catch (Throwable t) {
137 postAction(hasError ? AppcOamStates.Error : finalState);
142 * Get in progress LCM request count through RequestHandler.
143 * @return thecount of in progress LCM request
144 * @throws APPCException if RequestHandler throws it.
146 private int getInprogressLCMRequestCount() throws APPCException {
147 RequestHandler requestHandler = operationHelper.getService(RequestHandler.class);
149 if (requestHandler == null) {
153 return requestHandler.getInprogressRequestCount();
158 logDebug("The application '%s' has '%s' outstanding LCM request to complete" +
159 " before coming to a complete maintenance_mode.",
160 configurationHelper.getAppcName(), inprogressRequestCount);