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.simulator.client.main;
26 import org.apache.commons.io.filefilter.WildcardFileFilter;
27 import org.onap.appc.simulator.client.RequestHandler;
28 import org.onap.appc.simulator.client.impl.JsonRequestHandler;
31 import java.nio.file.Path;
32 import java.nio.file.Paths;
33 import java.util.ArrayList;
34 import java.util.Arrays;
35 import java.util.List;
36 import java.util.Properties;
38 public class ClientRunner {
40 public static void main(String ... args) throws Exception {
41 String folder = args[0];
43 folder = System.getProperty("user.dir");
45 System.out.println("== THR#" +Thread.currentThread().getId()+ " Reading files under the folder : " + folder);
47 String inputType = args[1];
48 if (inputType != null && !inputType.matches("JSON")) {
49 throw new RuntimeException("### ERROR ### - Unsupported file type <" + inputType + "> was provided");
52 Properties properties = getProperties(folder);
53 RequestHandler reqHandler = new JsonRequestHandler(properties);
54 List<File> sources = getJsonFiles(folder);
55 File log = new File(folder + "/output.txt");
57 for (File source: sources) {
58 reqHandler.proceedFile(source, log);
59 System.out.println("== THR#" +Thread.currentThread().getId()+ " File <" + source.getName() + "> processed.");
62 System.out.println("DONE with " + filesNum + " files under the folder : " + folder);
64 System.out.println("Shutdown ...");
65 reqHandler.shutdown(Boolean.parseBoolean(properties.getProperty("client.force.shutdown")));
69 private static Properties getProperties(String folder) {
70 Properties prop = new Properties();
72 InputStream conf = null;
74 conf = new FileInputStream(folder + "client-simulator.properties");
75 } catch (FileNotFoundException e) {
81 } catch (IOException e) {
86 prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
87 } catch (Exception e) {
88 throw new RuntimeException("### ERROR ### - Could not load properties to test");
94 private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
95 Path dir = Paths.get(folder);
96 FileFilter fileFilter = new WildcardFileFilter("*.json");
97 return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));