2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.simulators;
24 import java.io.IOException;
26 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
27 import org.onap.policy.common.utils.network.NetworkUtil;
30 public static final String AAISIM_SERVER_NAME = "aaiSim";
31 public static final String SOSIM_SERVER_NAME = "soSim";
32 public static final String VFCSIM_SERVER_NAME = "vfcSim";
33 public static final String GUARDSIM_SERVER_NAME = "guardSim";
34 public static final String SDNCSIM_SERVER_NAME = "sdncSim";
36 public static final int AAISIM_SERVER_PORT = 6666;
37 public static final int SOSIM_SERVER_PORT = 6667;
38 public static final int VFCSIM_SERVER_PORT = 6668;
39 public static final int GUARDSIM_SERVER_PORT = 6669;
40 public static final int SDNCSIM_SERVER_PORT = 6670;
42 private static final String CANNOT_CONNECT = "cannot connect to port ";
43 private static final String LOCALHOST = "localhost";
46 // Prevent instantiation of thic class
50 * Build an A&AI simulator.
52 * @return the simulator
53 * @throws InterruptedException if a thread is interrupted
54 * @throws IOException if an IO errror occurs
56 public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
57 final HttpServletServer testServer =
58 HttpServletServer.factory.build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true);
59 testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName());
60 testServer.waitedStart(5000);
61 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
62 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
68 * Build an SDNC simulator.
70 * @return the simulator
71 * @throws InterruptedException if a thread is interrupted
72 * @throws IOException if an IO errror occurs
74 public static HttpServletServer buildSdncSim() throws InterruptedException, IOException {
75 final HttpServletServer testServer =
76 HttpServletServer.factory.build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true);
77 testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName());
78 testServer.waitedStart(5000);
79 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
80 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
87 * Build an SO simulator.
89 * @return the simulator
90 * @throws InterruptedException if a thread is interrupted
91 * @throws IOException if an IO errror occurs
93 public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
94 final HttpServletServer testServer =
95 HttpServletServer.factory.build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true);
96 testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName());
97 testServer.waitedStart(5000);
98 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
99 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
105 * Build a VFC simulator.
107 * @return the simulator
108 * @throws InterruptedException if a thread is interrupted
109 * @throws IOException if an IO errror occurs
111 public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
112 final HttpServletServer testServer =
113 HttpServletServer.factory.build(VFCSIM_SERVER_NAME,LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true);
114 testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName());
115 testServer.waitedStart(5000);
116 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
117 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
123 * Build a guard simulator.
125 * @return the simulator
126 * @throws InterruptedException if a thread is interrupted
127 * @throws IOException if an IO errror occurs
129 public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
130 HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST,
131 GUARDSIM_SERVER_PORT, "/", false, true);
132 testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
133 testServer.waitedStart(5000);
134 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
135 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());