Second part of onap rename
[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.LinkedList;
38 import java.util.List;
39 import java.util.Set;
40
41 public class VMRequestValidatorImpl extends AbstractRequestValidatorImpl {
42
43     @Override
44     public void validateRequest(RuntimeContext runtimeContext) throws VNFNotFoundException, RequestExpiredException, InvalidInputException, WorkflowNotFoundException, DGWorkflowNotFoundException, MissingVNFDataInAAIException, LCMOperationsDisabledException, DuplicateRequestException {
45         if(!lcmStateManager.isLCMOperationEnabled()) {
46             LoggingUtils.logErrorMessage(
47                     LoggingConstants.TargetNames.REQUEST_VALIDATOR,
48                     EELFResourceManager.format(Msg.LCM_OPERATIONS_DISABLED),
49                     this.getClass().getCanonicalName());
50             throw new LCMOperationsDisabledException("APPC LCM operations have been administratively disabled");
51         }
52
53         getAAIservice();
54         super.validateInput(runtimeContext.getRequestContext());
55         String vnfId = runtimeContext.getRequestContext().getActionIdentifiers().getVnfId();
56
57         VNFContext vnfContext = queryAAI(vnfId);
58         runtimeContext.setVnfContext(vnfContext);
59
60         VNFOperation operation = runtimeContext.getRequestContext().getAction();
61         if(supportedVMLevelAction().contains(operation)) {
62             queryWFM(vnfContext, runtimeContext.getRequestContext());
63         }
64         else{
65             throw new LCMOperationsDisabledException("Action "+ operation.name() + " is not supported on VM level");
66         }
67     }
68
69     public Set<VNFOperation> supportedVMLevelAction(){
70         Set<VNFOperation> vnfOperations = new HashSet<>();
71         vnfOperations.add(VNFOperation.Start);
72         vnfOperations.add(VNFOperation.Stop);
73         vnfOperations.add(VNFOperation.Restart);
74         vnfOperations.add(VNFOperation.Rebuild);
75         vnfOperations.add(VNFOperation.Terminate);
76         vnfOperations.add(VNFOperation.Migrate);
77         vnfOperations.add(VNFOperation.Evacuate);
78         vnfOperations.add(VNFOperation.Snapshot);
79         return vnfOperations;
80     }
81
82
83 }