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