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.requesthandler.impl;
27 import com.att.eelf.i18n.EELFResourceManager;
28 import org.onap.appc.domainmodel.lcm.ActionIdentifiers;
29 import org.onap.appc.domainmodel.lcm.RequestContext;
30 import org.onap.appc.domainmodel.lcm.RuntimeContext;
31 import org.onap.appc.exceptions.InvalidInputException;
32 import org.onap.appc.i18n.Msg;
33 import org.onap.appc.logging.LoggingConstants;
34 import org.onap.appc.logging.LoggingUtils;
35 import org.onap.appc.requesthandler.exceptions.DuplicateRequestException;
36 import org.onap.appc.requesthandler.exceptions.LCMOperationsDisabledException;
37 import org.onap.appc.requesthandler.exceptions.RequestExpiredException;
38 import org.onap.appc.util.JsonUtil;
40 import java.io.IOException;
44 * * This class validates the LCM-Requests that don't need communication with the VNF.
46 public class LocalRequestValidatorImpl extends AbstractRequestValidatorImpl {
48 public void validateRequest(RuntimeContext runtimeContext) throws LCMOperationsDisabledException,
49 DuplicateRequestException, RequestExpiredException, InvalidInputException {
51 if (!lcmStateManager.isLCMOperationEnabled()) {
52 LoggingUtils.logErrorMessage(
53 LoggingConstants.TargetNames.REQUEST_VALIDATOR,
54 EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED),
55 this.getClass().getCanonicalName());
56 throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled");
59 validateInput(runtimeContext);
63 public void validateInput(RuntimeContext runtimeContext) throws DuplicateRequestException,
64 RequestExpiredException, InvalidInputException {
65 RequestContext requestContext = runtimeContext.getRequestContext();
66 super.validateInput(runtimeContext);
67 switch (requestContext.getAction()) {
69 validateActionStatusPayload(requestContext.getPayload());
70 validateActionStatusActionIdentifiers(requestContext.getActionIdentifiers());
73 logger.warn(String.format("Action %s not supported!", requestContext.getAction()));
77 private void validateActionStatusPayload(String payload) throws InvalidInputException {
78 Map<String, String> map;
80 map = JsonUtil.convertJsonStringToFlatMap(payload);
81 } catch (IOException e) {
82 logger.error(String.format("Error encountered when converting JSON payload '%s' to map", payload), e);
83 throw new InvalidInputException("Search criteria cannot be determined from Payload due to format issue");
85 if ((map == null) || !map.containsKey("request-id")) {
86 throw new InvalidInputException("request-id is absent in the Payload");
90 private void validateActionStatusActionIdentifiers(ActionIdentifiers identifiers) throws InvalidInputException {
91 if (identifiers == null || identifiers.getVnfId() == null) {
92 throw new InvalidInputException("VNF-Id is absent in Action Identifiers");