2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.provider.lcm.mock;
26 import org.onap.appc.executor.objects.LCMCommandStatus;
27 import org.onap.appc.requesthandler.objects.RequestHandlerInput;
28 import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
36 * This class is here because LCM resume backend is not implemented.
37 * Hence this class is here to mock the handling response of LCM resume REST API.
39 * When backend is implemented, this file should be removed.
41 public class MockResumeHelper extends AbstractMockHelper {
42 private final String MOCK_RESUME_DIR = "/tmp/lcm/resumetraffic";
43 private final String RESUME = "resume";
45 public RequestHandlerOutput resumeTraffic(RequestHandlerInput input) {
46 if (!mockConditionExists()) {
47 status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
48 "The resume-traffic command is not supported");
49 return setOutputStatus();
52 String vnfId = input.getRequestContext().getActionIdentifiers().getVnfId();
53 String vnfPath = String.format("%s/%s", MOCK_RESUME_DIR, vnfId);
54 if (!isDirectoryExist(vnfPath)) {
55 status = buildStatusForVnfId(LCMCommandStatus.VNF_NOT_FOUND, vnfId);
56 return setOutputStatus();
59 String resumePath = String.format("%s/%s", vnfPath, RESUME);
60 if (isDirectoryExist(resumePath)) {
61 status = buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
62 String.format("VNF %s is already resumed", vnfId));
63 return setOutputStatus();
66 File resumeDir = new File(resumePath);
67 boolean success = resumeDir.mkdir();
69 buildStatusWithoutParams(LCMCommandStatus.ACCEPTED) :
70 buildStatusForErrorMsg(LCMCommandStatus.REJECTED,
71 String.format("Failed to resume traffic VNF %s", vnfId));
73 return setOutputStatus();
76 private boolean mockConditionExists() {
77 return isDirectoryExist(MOCK_RESUME_DIR);
80 private boolean isDirectoryExist(String path) {
81 return Files.isDirectory(Paths.get(path));