65b05e21f5a3dbf6626bb3011f85d892847c5850
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / vnfm / tasks / MonitorVnfmNodeTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks;
21
22 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_NODE_STATUS;
23 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.DELETE_VNF_NODE_STATUS;
24 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.VNF_ASSIGNED;
25 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.VNF_CREATED;
26 import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID;
27 import org.onap.aai.domain.yang.GenericVnf;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36
37 /**
38  * 
39  * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
40  *
41  */
42 @Component
43 public class MonitorVnfmNodeTask {
44
45     private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmNodeTask.class);
46
47     private final ExtractPojosForBB extractPojosForBB;
48     private final ExceptionBuilder exceptionUtil;
49
50     @Autowired
51     public MonitorVnfmNodeTask(final ExtractPojosForBB extractPojosForBB, final ExceptionBuilder exceptionUtil) {
52         this.exceptionUtil = exceptionUtil;
53         this.extractPojosForBB = extractPojosForBB;
54     }
55
56     /**
57      * Check the final status of vnf in A&AI
58      * 
59      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
60      */
61     public void getNodeStatus(final BuildingBlockExecution execution) {
62         try {
63             LOGGER.debug("Executing getNodeStatus  ...");
64             final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID);
65             String orchestrationStatus = vnf.getOrchestrationStatus();
66             LOGGER.debug("Orchestration Status in AAI {}", orchestrationStatus);
67             execution.setVariable(CREATE_VNF_NODE_STATUS, VNF_CREATED.equalsIgnoreCase(orchestrationStatus));
68             execution.setVariable(DELETE_VNF_NODE_STATUS, VNF_ASSIGNED.equalsIgnoreCase(orchestrationStatus));
69         } catch (final Exception exception) {
70             LOGGER.error("Unable to get vnf from AAI", exception);
71             exceptionUtil.buildAndThrowWorkflowException(execution, 1220, exception);
72         }
73     }
74
75     /**
76      * Log and throw exception on timeout for job status
77      * 
78      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
79      */
80     public void timeOutLogFailue(final BuildingBlockExecution execution) {
81         final String message = "Node operation time out";
82         LOGGER.error(message);
83         exceptionUtil.buildAndThrowWorkflowException(execution, 1221, message);
84     }
85 }