Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / sdno / tasks / SDNOHealthCheckTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.sdno.tasks;
24
25 import java.util.Map;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
31 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.client.orchestration.SDNOHealthCheckResources;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class SDNOHealthCheckTasks {
41     private static final Logger logger = LoggerFactory.getLogger(SDNOHealthCheckTasks.class);
42     @Autowired
43     private ExceptionBuilder exceptionUtil;
44     @Autowired
45     private ExtractPojosForBB extractPojosForBB;
46     @Autowired
47     private SDNOHealthCheckResources sdnoHealthCheckResources;
48
49     public void sdnoHealthCheck(BuildingBlockExecution execution) {
50         boolean response = false;
51         try {
52             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
53             RequestContext requestContext = gBBInput.getRequestContext();
54
55             GenericVnf vnf = null;
56             Map<ResourceKey, String> lookupMap = execution.getLookupMap();
57             for (Map.Entry<ResourceKey, String> entry : lookupMap.entrySet()) {
58                 if (entry.getKey().equals(ResourceKey.GENERIC_VNF_ID)) {
59                     vnf = extractPojosForBB.extractByKey(execution, entry.getKey());
60                 }
61             }
62
63             response = sdnoHealthCheckResources.healthCheck(vnf, requestContext);
64         } catch (Exception ex) {
65             logger.error("Exception occurred", ex);
66             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex.getMessage());
67         }
68
69         if (!response) {
70             logger.error("SDNO Health Check failed");
71             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "SDNO Health Check failed");
72         }
73     }
74 }