2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.provider.lcm.service;
27 import org.apache.commons.lang.StringUtils;
28 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
29 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusInput;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ActionStatusOutputBuilder;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
33 import org.onap.appc.domainmodel.lcm.ActionLevel;
34 import org.onap.appc.executor.objects.LCMCommandStatus;
35 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
36 import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
39 * Provide LCM command service for Query action status of a previously issue LCM command
41 public class ActionStatusService extends AbstractBaseService {
46 public ActionStatusService() {
47 super(Action.ActionStatus);
48 logger.debug("ActionStatusService starts");
53 * @param input of the ActionStatusInput which contains the information about the previous LCM command
54 * @return ActionStatusOuputBuilder containing query results
56 public ActionStatusOutputBuilder queryStatus(ActionStatusInput input) {
57 Payload outputPayload = null;
60 ActionIdentifiers actionIdentifiers = input.getActionIdentifiers();
62 RequestHandlerInput requestHandlerInput = getRequestHandlerInput(
63 input.getCommonHeader(), actionIdentifiers, input.getPayload(), this.getClass().getName());
64 if (requestHandlerInput != null) {
65 updateToMgmtActionLevel(requestHandlerInput);
67 RequestHandlerOutput reqHandlerOutput = executeAction(requestHandlerInput);
69 outputPayload = new RequestExecutor().getPayload(reqHandlerOutput);
73 logger.info(String.format("ActionStatus execute of '%s' finished with status %s. Reason: %s",
74 actionIdentifiers, status == null ? "null" : status.getCode().toString(),
75 status == null ? "null" : status.getMessage()));
77 ActionStatusOutputBuilder outputBuilder = new ActionStatusOutputBuilder();
78 outputBuilder.setPayload(outputPayload);
79 outputBuilder.setCommonHeader(input.getCommonHeader());
80 outputBuilder.setStatus(status);
87 * - Action in the input
88 * - ActionIdentifier and only has VNF ID
89 * - and payload exists and is not empty string
90 * @param input of the ActionStatusInput from the REST API
92 void validate(ActionStatusInput input) {
93 status = validateVnfId(input.getCommonHeader(), input.getAction(), input.getActionIdentifiers());
98 Payload payload = input.getPayload();
99 if (payload == null) {
100 status = buildStatusForParamName(LCMCommandStatus.MISSING_MANDATORY_PARAMETER, "payload");
101 } else if (StringUtils.isEmpty(payload.getValue())) {
102 status = buildStatusForParamName(LCMCommandStatus.INVALID_INPUT_PARAMETER, "payload");
107 * Update request to MGMT action level
108 * @param request of the RequestHandlerInput
110 void updateToMgmtActionLevel(RequestHandlerInput request) {
111 request.getRequestContext().setActionLevel(ActionLevel.MGMT);