61e0be4d623880ce0467844d47614e4b81aaa66a
[vfc/nfvo/resmanagement.git] /
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.resmanagement.service.group.impl;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.Logger;
24 import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil;
25 import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant;
26 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement;
27 import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Vim;
28 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
29
30 /**
31  *
32  * iResource delete service implementation.<br>
33  * <p>
34  * </p>
35  *
36  * @author
37  * @version     VFC 1.0  Sep 10, 2016
38  */
39 public class IResourceDelServiceImpl {
40
41     private static final Logger LOGGER = LogManager.getLogger(IResourceDelServiceImpl.class);
42
43     /**
44      *
45      * Delete iResource.<br>
46      *
47      * @param vimId
48      * @param iResMap
49      * @param vim
50      * @return
51      * @throws ServiceException
52      * @since  VFC 1.0
53      */
54     public int deleteIRes(String vimId, Map<String, InterfaceResManagement> iResMap, Vim vim) throws ServiceException {
55         Map<String, Object> map = new HashMap<>(10);
56         map.put(ParamConstant.PARAM_VIMID, vimId);
57
58         checkIResDelResult(vimId, iResMap);
59         return vim.delete(vimId);
60     }
61
62     private void checkIResDelResult(String vimId, Map<String, InterfaceResManagement> iResMap) throws ServiceException {
63         for(String keyName : iResMap.keySet()) {
64             if(iResMap.get(keyName).deleteResByVimId(vimId) < 0) {
65                 LOGGER.error("function=checkIResDelResult; msg=delete {} failed,", keyName);
66                 throw new ServiceException(
67                         ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.delete.fail")
68                                 + keyName);
69             }
70             LOGGER.warn("function=checkIResDelResult; msg=delete {} success", keyName);
71         }
72
73     }
74
75 }