b645b822227bb751600c378c07b1c7e9af4ea723
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / main / java / org / onap / appc / requesthandler / impl / VMRequestValidatorImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.requesthandler.impl;
26
27 import com.att.eelf.i18n.EELFResourceManager;
28 import org.onap.appc.domainmodel.lcm.RuntimeContext;
29 import org.onap.appc.domainmodel.lcm.VNFContext;
30 import org.onap.appc.domainmodel.lcm.VNFOperation;
31 import org.onap.appc.i18n.Msg;
32 import org.onap.appc.logging.LoggingConstants;
33 import org.onap.appc.logging.LoggingUtils;
34 import org.onap.appc.requesthandler.exceptions.*;
35
36 import java.util.HashSet;
37 import java.util.Set;
38
39 public class VMRequestValidatorImpl extends AbstractRequestValidatorImpl {
40
41     @Override
42     public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, InvalidInputException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException, DuplicateRequestException {
43         if(!lcmStateManager.isLCMOperationEnabled()) {
44             LoggingUtils.logErrorMessage(
45                     LoggingConstants.TargetNames.REQUEST_VALIDATOR,
46                     EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED),
47                     this.getClass().getCanonicalName());
48             throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled");
49         }
50
51         getAAIservice();
52         super.validateInput(runtimeContext.getRequestContext());
53         String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
54
55         VNFContext vnfContext = queryAAI(vnfId);
56         runtimeContext.setVnfContext(vnfContext);
57
58         VNFOperation operation = runtimeContext.getRequestContext().getAction();
59         if(supportedVMLevelAction().contains(operation)) {
60             queryWFM(vnfContext, runtimeContext.getRequestContext());
61         }
62         else{
63             throw new LCMOperationsDisabledException("Action "+ operation.name() + " is not supported on VM level");
64         }
65     }
66
67     public Set<VNFOperation> supportedVMLevelAction(){
68         Set<VNFOperation> vnfOperations = new HashSet<>();
69         vnfOperations.add(VNFOperation.Start);
70         vnfOperations.add(VNFOperation.Stop);
71         vnfOperations.add(VNFOperation.Restart);
72         vnfOperations.add(VNFOperation.Rebuild);
73         vnfOperations.add(VNFOperation.Terminate);
74         vnfOperations.add(VNFOperation.Migrate);
75         vnfOperations.add(VNFOperation.Evacuate);
76         vnfOperations.add(VNFOperation.Snapshot);
77         return vnfOperations;
78     }
79
80
81 }