2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.simulator.client.main;
27 import org.apache.commons.io.filefilter.WildcardFileFilter;
28 import org.onap.appc.simulator.client.RequestHandler;
29 import org.onap.appc.simulator.client.impl.JsonRequestHandler;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.List;
37 import java.util.Properties;
39 public class ClientRunner {
41 public static void main(String ... args) throws Exception {
42 String folder = args[0];
44 folder = System.getProperty("user.dir");
46 System.out.println("== THR#" +Thread.currentThread().getId()+ " Reading files under the folder : " + folder);
48 String inputType = args[1];
49 if (inputType != null && !inputType.matches("JSON")) {
50 throw new RuntimeException("### ERROR ### - Unsupported file type <" + inputType + "> was provided");
53 Properties properties = getProperties(folder);
54 RequestHandler reqHandler = new JsonRequestHandler(properties);
55 List<File> sources = getJsonFiles(folder);
56 File log = new File(folder + "/output.txt");
58 for (File source: sources) {
59 reqHandler.proceedFile(source, log);
60 System.out.println("== THR#" +Thread.currentThread().getId()+ " File <" + source.getName() + "> processed.");
63 System.out.println("DONE with " + filesNum + " files under the folder : " + folder);
65 System.out.println("Shutdown ...");
66 reqHandler.shutdown(Boolean.parseBoolean(properties.getProperty("client.force.shutdown")));
70 private static Properties getProperties(String folder) {
71 Properties prop = new Properties();
73 InputStream conf = null;
75 conf = new FileInputStream(folder + "client-simulator.properties");
76 } catch (FileNotFoundException e) {
82 } catch (IOException e) {
87 prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("client-simulator.properties"));
88 } catch (Exception e) {
89 throw new RuntimeException("### ERROR ### - Could not load properties to test");
95 private static List<File> getJsonFiles(String folder) throws FileNotFoundException {
96 Path dir = Paths.get(folder);
97 FileFilter fileFilter = new WildcardFileFilter("*.json");
98 return new ArrayList<File>(Arrays.asList(dir.toFile().listFiles(fileFilter)));