d95942197afe9cc7722cd2818cc0624ea5a78f1b
[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  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.executor.impl;
24
25
26 import org.apache.commons.lang3.StringUtils;
27 import org.openecomp.appc.domainmodel.lcm.CommonHeader;
28 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
29 import org.openecomp.appc.executor.UnstableVNFException;
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
37 import com.att.eelf.configuration.EELFLogger;
38 import com.att.eelf.configuration.EELFManager;
39
40 public class LCMReadonlyCommandTask extends CommandTask  {
41
42     private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class);
43
44     public LCMReadonlyCommandTask(RuntimeContext commandRequest, RequestHandler requestHandler,
45             WorkFlowManager workflowManager) {
46         super(commandRequest, requestHandler, workflowManager);
47     }
48
49     @Override
50     public void onRequestCompletion(CommandResponse response) {
51         super.onRequestCompletion(response, true);
52     }
53
54     @Override
55     public void run() {
56         RuntimeContext request = commandRequest;
57         final CommonHeader commonHeader = request.getRequestContext().getCommonHeader();
58         final boolean forceFlag = commonHeader.getFlags().isForce();
59         UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId());
60         String requestIdentifierString = requestIdentifier.toIdentifierString();
61         final String vnfId = request.getVnfContext().getId();
62         try {
63             requestHandler.onRequestExecutionStart(vnfId,true, requestIdentifierString, forceFlag);
64             super.execute();
65         } catch (UnstableVNFException e) {
66             logger.error(e.getMessage(), e);
67             Params params = new Params().addParam("vnfId",vnfId);
68             request.getResponseContext().setStatus(LCMCommandStatus.UNSTABLE_VNF_FAILURE.toStatus(params));
69         }catch (Exception e) {
70             logger.error("Error during runing LCMReadonlyCommandTask.", e);
71             String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
72             Params params = new Params().addParam("errorMsg",errorMsg);
73             request.getResponseContext().setStatus(LCMCommandStatus.UNEXPECTED_FAILURE.toStatus(params));
74         }
75     }
76 }