90514eea23d1bdee3307544c8fac84927241df0f
[vnfsdk/refrepo.git] /
1 /**
2  * Copyright 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 package org.onap.vnfsdk.marketplace.onboarding.onboardmanager;
17
18 import org.onap.vnfsdk.marketplace.common.FileUtil;
19 import org.onap.vnfsdk.marketplace.db.resource.PackageManager;
20 import org.onap.vnfsdk.marketplace.entity.EnumResult;
21 import org.onap.vnfsdk.marketplace.onboarding.entity.OnBoradingRequest;
22 import org.onap.vnfsdk.marketplace.onboarding.hooks.functiontest.FunctionTestHook;
23 import org.onap.vnfsdk.marketplace.onboarding.hooks.validatelifecycle.LifecycleTestHook;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public final class OnBoardingHandler
28 {
29     private static final Logger logger = LoggerFactory.getLogger(OnBoardingHandler.class);
30
31     public void handleOnBoardingReq(OnBoradingRequest onBoradingReq) 
32     {               
33         //Handle Package Life cycle/Validation
34         //------------------------------------
35         LifecycleTestHook oLifecycleTestHook = new LifecycleTestHook();
36         int iLifeCycleResponse = oLifecycleTestHook.exec(onBoradingReq);        
37         if(EnumResult.SUCCESS.getIndex() != iLifeCycleResponse)
38         {
39             logger.error("Onboarding falied for Package Id during Lifecycle Test:" + onBoradingReq.getCsarId());
40         } 
41         
42         //Handle Package FunctionTest
43         //-------------------------
44         FunctionTestHook oFunctionTestHook = new FunctionTestHook();
45         int iFuncTestResponse = oFunctionTestHook.exec(onBoradingReq);          
46         if(EnumResult.SUCCESS.getIndex() != iFuncTestResponse)
47         {
48             logger.error("Onboarding falied for Package Id during Function Test:" + onBoradingReq.getCsarId());
49             return;
50         }      
51         
52         FileUtil.deleteDirectory(onBoradingReq.getPackagePath());    
53         try 
54         {
55             PackageManager.getInstance().updateDwonloadCount(onBoradingReq.getCsarId());
56         } 
57         catch (Exception e) 
58         {
59             logger.error("Download count udate failed for Package:" + onBoradingReq.getPackagePath() ,e);
60         }
61     }
62
63 }