Change nexus values to properties
[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.impl.objects.CommandRequest;
30 import org.openecomp.appc.executor.impl.objects.LCMCommandRequest;
31 import org.openecomp.appc.executor.impl.objects.LCMReadOnlyCommandRequest;
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 import com.att.eelf.configuration.EELFLogger;
39 import com.att.eelf.configuration.EELFManager;
40
41 public class LCMReadonlyCommandTask extends CommandTask<LCMReadOnlyCommandRequest>  {
42
43     private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class);
44
45     public LCMReadonlyCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager){
46
47         setRequestHandler(requestHandler);
48         setWorkflowManager(workflowManager);
49     }
50
51
52     @Override
53     public void onRequestCompletion(CommandRequest request, CommandResponse response) {
54         super.onRequestCompletion(request, response, true);
55     }
56
57     @Override
58     public void run() {
59         LCMReadOnlyCommandRequest request = (LCMReadOnlyCommandRequest)getCommandRequest();
60         final CommonHeader commonHeader = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader();
61         final boolean forceFlag = commonHeader.getFlags().isForce();
62         UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId());
63         String requestIdentifierString = requestIdentifier.toIdentifierString();
64         final String vnfId = request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId();
65         try {
66             requestHandler.onRequestExecutionStart(vnfId,true, requestIdentifierString, forceFlag);
67             super.execute();
68         } catch (UnstableVNFException e) {
69             logger.error(e.getMessage(), e);
70             Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
71             Params params = new Params().addParam("vnfId",vnfId);
72             fillStatus(status, LCMCommandStatus.UNSTABLE_VNF_FAILURE, params);
73         }catch (Exception e) {
74             logger.error("Error during runing LCMReadonlyCommandTask.", e);
75             Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
76             String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
77             Params params = new Params().addParam("errorMsg",errorMsg);
78             fillStatus(status, LCMCommandStatus.UNEXPECTED_FAILURE, params);
79         }
80     }
81 }