2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.provider.lcm.service;
26 import org.apache.commons.lang.StringUtils;
27 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusInput;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusOutputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
32 import org.onap.appc.domainmodel.lcm.ActionLevel;
33 import org.onap.appc.executor.objects.LCMCommandStatus;
34 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
35 import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
38 * Provide LCM command service for Query action status of a previously issue LCM command
40 public class ActionStatusService extends AbstractBaseService {
45 public ActionStatusService() {
46 super(Action.ActionStatus);
47 logger.debug("ActionStatusService starts");
52 * @param input of the ActionStatusInput which contains the information about the previous LCM command
53 * @return ActionStatusOuputBuilder containing query results
55 public ActionStatusOutputBuilder queryStatus(ActionStatusInput input) {
56 Payload outputPayload = null;
59 ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
61 RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
62 input.getCommonHeader(), actionIdentifiers, input.getPayload(), this.getClass().getName());
63 if (requestHandlerInput != null) {
64 updateToMgmtActionLevel(requestHandlerInput);
66 RequestHandlerOutput reqHandlerOutput = executeAction(requestHandlerInput);
68 outputPayload = new RequestExecutor().getPayload(reqHandlerOutput);
72 logger.info(String.format("ActionStatus execute of '%s' finished with status %s. Reason: %s",
73 actionIdentifiers, status == null ? "null" : status.getCode().toString(),
74 status == null ? "null" : status.getMessage()));
76 ActionStatusOutputBuilder outputBuilder = new ActionStatusOutputBuilder();
77 outputBuilder.setPayload(outputPayload);
78 outputBuilder.setCommonHeader(input.getCommonHeader());
79 outputBuilder.setStatus(status);
86 * - Action in the input
87 * - ActionIdentifier and only has VNF ID
88 * - and payload exists and is not empty string
89 * @param input of the ActionStatusInput from the REST API
91 void validate(ActionStatusInput input) {
92 status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
97 Payload payload = input.getPayload();
98 if (payload == null) {
99 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, "payload");
100 } else if (StringUtils.isEmpty(payload.getValue())) {
101 status = buildStatusForParamName(LCMCommandStatus.INVALID_INPUT_PARAMETER, "payload");
106 * Update request to MGMT action level
107 * @param request of the RequestHandlerInput
109 void updateToMgmtActionLevel(RequestHandlerInput request) {
110 request.getRequestContext().setActionLevel(ActionLevel.MGMT);