Remove CommandRequest and subclasses
[appc.git] / appc-dispatcher / appc-command-executor / appc-command-executor-core / src / main / java / org / openecomp / appc / executor / impl / LCMReadonlyCommandTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : APP-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.openecomp.appc.executor.impl;
23
24
25 import org.apache.commons.lang3.StringUtils;
26 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
27 import org.openecomp.appc.domainmodel.lcm.Status;
28 import org.openecomp.appc.executor.UnstableVNFException;
29 import org.openecomp.appc.executor.objects.CommandExecutorInput;
30 import org.openecomp.appc.executor.objects.CommandResponse;
31 import org.openecomp.appc.executor.objects.LCMCommandStatus;
32 import org.openecomp.appc.executor.objects.Params;
33 import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
34 import org.openecomp.appc.requesthandler.RequestHandler;
35 import org.openecomp.appc.workflow.WorkFlowManager;
36 import com.att.eelf.configuration.EELFLogger;
37 import com.att.eelf.configuration.EELFManager;
38
39 public class LCMReadonlyCommandTask extends CommandTask  {
40
41     private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class);
42
43     public LCMReadonlyCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager){
44
45         setRequestHandler(requestHandler);
46         setWorkflowManager(workflowManager);
47     }
48
49
50     @Override
51     public void onRequestCompletion(CommandExecutorInput request, CommandResponse response) {
52         super.onRequestCompletion(request, response, true);
53     }
54
55     @Override
56     public void run() {
57         CommandExecutorInput request = getCommandRequest();
58         final CommonHeader commonHeader = request.getRuntimeContext().getRequestContext().getCommonHeader();
59         final boolean forceFlag = commonHeader.getFlags().isForce();
60         UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId());
61         String requestIdentifierString = requestIdentifier.toIdentifierString();
62         final String vnfId = request.getRuntimeContext().getVnfContext().getId();
63         try {
64             requestHandler.onRequestExecutionStart(vnfId,true, requestIdentifierString, forceFlag);
65             super.execute();
66         } catch (UnstableVNFException e) {
67             logger.error(e.getMessage(), e);
68             Params params = new Params().addParam("vnfId",vnfId);
69             request.getRuntimeContext().getResponseContext().setStatus(LCMCommandStatus.UNSTABLE_VNF_FAILURE.toStatus(params));
70         }catch (Exception e) {
71             logger.error("Error during runing LCMReadonlyCommandTask.", e);
72             String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
73             Params params = new Params().addParam("errorMsg",errorMsg);
74             request.getRuntimeContext().getResponseContext().setStatus(LCMCommandStatus.UNEXPECTED_FAILURE.toStatus(params));
75         }
76     }
77 }