2 * Copyright 2017 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vnfsdk.marketplace.onboarding.onboardmanager;
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;
27 /* Call Flow: PackageWrapper(package upload) --> OnBoardingHandler (package on boarding) */
28 public final class OnBoardingHandler {
30 private static final Logger logger = LoggerFactory.getLogger(OnBoardingHandler.class);
32 public void handleOnBoardingReq(OnBoradingRequest onBoardingReq) {
34 // Step 0: Input validation
35 // ------------------------------
36 if (null == onBoardingReq) {
37 logger.error("Invalid input:Onboarding request is null");
41 if ((null == onBoardingReq.getPackagePath()) || (null == onBoardingReq.getPackageName())) {
42 logger.error("Package path or name is invalid");
46 if (null == onBoardingReq.getCsarId()) {
47 logger.error("CsarId is invalid - null");
51 // Step 1:Handle Package Life cycle/Validation
52 // ------------------------------------
53 LifecycleTestHook oLifecycleTestHook = new LifecycleTestHook();
54 int iLifeCycleResponse = oLifecycleTestHook.exec(onBoardingReq);
55 if (EnumResult.SUCCESS.getIndex() != iLifeCycleResponse) {
56 logger.error("Onboarding failed for Package Id during Lifecycle Test:{}" , onBoardingReq.getCsarId());
57 // Note: We need to continue even if life cycle test fails as this
58 // test is not mandatory
61 // Step 2: Handle Package FunctionTest
62 // -------------------------
63 FunctionTestHook oFunctionTestHook = new FunctionTestHook();
64 int iFuncTestResponse = oFunctionTestHook.exec(onBoardingReq);
65 if (EnumResult.SUCCESS.getIndex() != iFuncTestResponse) {
66 logger.error("Onboarding failed for Package Id during Function Test:{}" , onBoardingReq.getCsarId());
67 // Note: We need to continue even if function test fails as this
68 // test is not mandatory
71 FileUtil.deleteDirectory(onBoardingReq.getPackagePath());
73 PackageManager.getInstance().updateDownloadCount(onBoardingReq.getCsarId());
74 } catch (Exception e) {
75 logger.error("Download count update failed for Package:{}" , onBoardingReq.getPackagePath(), e);