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;
42 import java.util.concurrent.TimeoutException;
45 * Processor to handle maintenance mode OAM API.
47 public class OamMmodeProcessor extends BaseProcessor {
51 * @param eelfLogger for logging
52 * @param configurationHelper for property reading
53 * @param stateHelper for APP-C OAM state checking
54 * @param asyncTaskHelper for scheduling async task
55 * @param operationHelper for operational helper
57 public OamMmodeProcessor(EELFLogger eelfLogger,
58 ConfigurationHelper configurationHelper,
59 StateHelper stateHelper,
60 AsyncTaskHelper asyncTaskHelper,
61 OperationHelper operationHelper) {
62 super(eelfLogger, configurationHelper, stateHelper, asyncTaskHelper, operationHelper);
64 rpc = AppcOam.RPC.maintenance_mode;
65 auditMsg = Msg.OAM_OPERATION_ENTERING_MAINTENANCE_MODE;
69 protected void preProcess(final Object requestInput)
70 throws InvalidInputException, InvalidStateException, APPCException, InterruptedException, TimeoutException {
71 super.preProcess(requestInput);
73 //Close the gate so that no more new LCM request will be excepted.
74 LCMStateManager lcmStateManager = operationHelper.getService(LCMStateManager.class);
75 lcmStateManager.disableLCMOperations();
79 protected void scheduleAsyncTask() {
80 runnable = new MyRunnable(this);
81 super.scheduleAsyncTask();
86 * For maintenance mode we want a longer delay before initial execution of {@link BaseActionRunnable}
87 * so that any accepted LCM actions have time to git scheduled in the Dispatcher.
90 protected long getInitialDelayMillis(){
91 //wait ten seconds before
96 * This runnable does the async handling for the maintenance mode REST API, and will be scheduled to run
97 * until terminating condition reaches.
99 * <p>The runnable will continue run if: <br>
100 * - the runnable is not canceled outside <br>
101 * - the in progress LCM request count is not zero<br>
102 * <p> When LCM request count reaches to zero, this runnable will: <br>
103 * - post message through operationHelper <br>
104 * - set APP-C OAM state to maintenance mode <br>
105 * - audit log the state <br>
106 * - terminate this runnable itself <br>
108 class MyRunnable extends BaseActionRunnable {
109 private int inprogressRequestCount;
111 MyRunnable(BaseProcessor parent) {
114 actionName = "OAM Maintenance mode";
115 auditMsg = Msg.OAM_OPERATION_MAINTENANCE_MODE;
116 finalState = AppcOamStates.MaintenanceMode;
121 // always return true, so that we can check the LCM request count
126 boolean checkState() {
127 logDebug(String.format("Executing %s task", actionName));
130 boolean hasError = false;
132 inprogressRequestCount = getInprogressLCMRequestCount();
133 if (inprogressRequestCount > 0) {
134 // if there are still LCM request in progress, keep waiting
138 setStatus(OAMCommandStatus.SUCCESS);
139 } catch (Exception e) {
144 postAction(hasError ? AppcOamStates.Error : finalState);
149 * Get in progress LCM request count through RequestHandler.
150 * @return thecount of in progress LCM request
151 * @throws APPCException if RequestHandler throws it.
153 private int getInprogressLCMRequestCount() throws APPCException {
154 RequestHandler requestHandler = operationHelper.getService(RequestHandler.class);
156 if (requestHandler == null) {
160 return requestHandler.getInprogressRequestCount();
165 logDebug("The application '%s' has '%s' outstanding LCM request to complete" +
166 " before coming to a complete maintenance_mode.",
167 configurationHelper.getAppcName(), inprogressRequestCount);