Merge "Remove unused class StreamHelper"
[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.RuntimeContext;
28 import org.openecomp.appc.executor.UnstableVNFException;
29 import org.openecomp.appc.executor.objects.CommandResponse;
30 import org.openecomp.appc.executor.objects.LCMCommandStatus;
31 import org.openecomp.appc.executor.objects.Params;
32 import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
33 import org.openecomp.appc.requesthandler.RequestHandler;
34 import org.openecomp.appc.workflow.WorkFlowManager;
35
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(RuntimeContext commandRequest, RequestHandler requestHandler,
44             WorkFlowManager workflowManager) {
45         super(commandRequest, requestHandler, workflowManager);
46     }
47
48     @Override
49     public void onRequestCompletion(CommandResponse response) {
50         super.onRequestCompletion(response, true);
51     }
52
53     @Override
54     public void run() {
55         RuntimeContext request = commandRequest;
56         final CommonHeader commonHeader = request.getRequestContext().getCommonHeader();
57         final boolean forceFlag = commonHeader.getFlags().isForce();
58         UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId());
59         String requestIdentifierString = requestIdentifier.toIdentifierString();
60         final String vnfId = request.getVnfContext().getId();
61         try {
62             requestHandler.onRequestExecutionStart(vnfId,true, requestIdentifierString, forceFlag);
63             super.execute();
64         } catch (UnstableVNFException e) {
65             logger.error(e.getMessage(), e);
66             Params params = new Params().addParam("vnfId",vnfId);
67             request.getResponseContext().setStatus(LCMCommandStatus.UNSTABLE_VNF_FAILURE.toStatus(params));
68         }catch (Exception e) {
69             logger.error("Error during runing LCMReadonlyCommandTask.", e);
70             String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
71             Params params = new Params().addParam("errorMsg",errorMsg);
72             request.getResponseContext().setStatus(LCMCommandStatus.UNEXPECTED_FAILURE.toStatus(params));
73         }
74     }
75 }