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.openecomp.appc.requesthandler.impl;
27 import com.att.eelf.i18n.EELFResourceManager;
28 import org.apache.commons.lang.ObjectUtils;
29 import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
30 import org.openecomp.appc.domainmodel.lcm.VNFContext;
31 import org.openecomp.appc.domainmodel.lcm.VNFOperation;
32 import org.openecomp.appc.executor.UnstableVNFException;
33 import org.openecomp.appc.i18n.Msg;
34 import org.openecomp.appc.lifecyclemanager.LifecycleManager;
35 import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
36 import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
37 import org.openecomp.appc.logging.LoggingConstants;
38 import org.openecomp.appc.logging.LoggingUtils;
39 import org.openecomp.appc.requesthandler.LCMStateManager;
40 import org.openecomp.appc.requesthandler.exceptions.*;
41 import org.openecomp.appc.workingstatemanager.WorkingStateManager;
44 public class RequestValidatorImpl extends AbstractRequestValidatorImpl {
46 private WorkingStateManager workingStateManager;
47 private LCMStateManager lcmStateManager;
49 public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
50 this.lifecyclemanager = lifecyclemanager;
53 public void setWorkingStateManager(WorkingStateManager workingStateManager) {
54 this.workingStateManager = workingStateManager;
57 public void setLcmStateManager(LCMStateManager lcmStateManager) {
58 this.lcmStateManager = lcmStateManager;
61 public RequestValidatorImpl() {
65 public void validateRequest(RuntimeContext runtimeContext)
66 throws VNFNotFoundException, RequestExpiredException, UnstableVNFException, InvalidInputException,
67 DuplicateRequestException, NoTransitionDefinedException, LifecycleException, WorkflowNotFoundException,
68 DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException {
69 if (logger.isTraceEnabled()){
70 logger.trace("Entering to validateRequest with RequestHandlerInput = "+ ObjectUtils.toString(runtimeContext));
72 if(!lcmStateManager.isLCMOperationEnabled()) {
73 LoggingUtils.logErrorMessage(
74 LoggingConstants.TargetNames.REQUEST_VALIDATOR,
75 EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED),
76 this.getClass().getCanonicalName());
77 throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled");
81 validateInput(runtimeContext.getRequestContext());
82 checkVNFWorkingState(runtimeContext);
83 String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
84 VNFContext vnfContext = queryAAI(vnfId);
85 runtimeContext.setVnfContext(vnfContext);
87 queryLCM(runtimeContext.getVnfContext().getStatus(), runtimeContext.getRequestContext().getAction());
88 VNFOperation operation = runtimeContext.getRequestContext().getAction();
89 if(!operation.isBuiltIn()) {
90 // for built-in operations skip WF presence check
91 queryWFM(vnfContext, runtimeContext.getRequestContext());
96 private String queryLCM(String orchestrationStatus, VNFOperation action) throws LifecycleException, NoTransitionDefinedException {
97 if (logger.isTraceEnabled()) {
98 logger.trace("Entering to queryLCM with Orchestration Status = "+ ObjectUtils.toString(orchestrationStatus)+
99 ", command = "+ ObjectUtils.toString(action));
102 String nextState = lifecyclemanager.getNextState(null, orchestrationStatus, action.name());
103 if (logger.isDebugEnabled()) {
104 logger.trace("Exiting from queryLCM with (LCMResponse = "+ ObjectUtils.toString(nextState)+")");
110 private void checkVNFWorkingState(RuntimeContext runtimeContext) throws UnstableVNFException {
112 if (logger.isTraceEnabled()) {
113 logger.trace("Entering to checkVNFWorkingState with RequestHandlerInput = "+ ObjectUtils.toString(runtimeContext.getRequestContext()));
115 boolean forceFlag = runtimeContext.getRequestContext().getCommonHeader().getFlags() != null && runtimeContext.getRequestContext().getCommonHeader().getFlags().isForce();
116 String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
118 if (logger.isDebugEnabled()) {
119 logger.debug("forceFlag = " + forceFlag);
121 boolean isVNFStable = workingStateManager.isVNFStable(vnfId);
122 if (!isVNFStable && !forceFlag) {
123 if (logger.isDebugEnabled()) {
124 logger.debug("VNF is not stable for VNF ID = " + vnfId);
126 throw new UnstableVNFException("VNF is not stable for vnfID = " + vnfId);