2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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.endpoints.http.server.HttpServletServerFactoryInstance;
28 import org.onap.policy.common.gson.GsonMessageBodyHandler;
29 import org.onap.policy.common.utils.network.NetworkUtil;
32 public static final String AAISIM_SERVER_NAME = "aaiSim";
33 public static final String SOSIM_SERVER_NAME = "soSim";
34 public static final String VFCSIM_SERVER_NAME = "vfcSim";
35 public static final String GUARDSIM_SERVER_NAME = "guardSim";
36 public static final String SDNCSIM_SERVER_NAME = "sdncSim";
38 public static final int AAISIM_SERVER_PORT = 6666;
39 public static final int SOSIM_SERVER_PORT = 6667;
40 public static final int VFCSIM_SERVER_PORT = 6668;
41 public static final int GUARDSIM_SERVER_PORT = 6669;
42 public static final int SDNCSIM_SERVER_PORT = 6670;
44 private static final String CANNOT_CONNECT = "cannot connect to port ";
45 private static final String LOCALHOST = "localhost";
48 // Prevent instantiation of thic class
52 * Build an A&AI simulator.
54 * @return the simulator
55 * @throws InterruptedException if a thread is interrupted
56 * @throws IOException if an IO errror occurs
58 public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
59 final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
60 .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true);
61 testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName());
62 testServer.waitedStart(5000);
63 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
64 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
70 * Build an SDNC simulator.
72 * @return the simulator
73 * @throws InterruptedException if a thread is interrupted
74 * @throws IOException if an IO errror occurs
76 public static HttpServletServer buildSdncSim() throws InterruptedException, IOException {
77 final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
78 .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true);
79 testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName());
80 testServer.waitedStart(5000);
81 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
82 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
89 * Build an SO simulator.
91 * @return the simulator
92 * @throws InterruptedException if a thread is interrupted
93 * @throws IOException if an IO errror occurs
95 public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
96 final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
97 .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true);
98 testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName());
99 testServer.waitedStart(5000);
100 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
101 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
107 * Build a VFC simulator.
109 * @return the simulator
110 * @throws InterruptedException if a thread is interrupted
111 * @throws IOException if an IO errror occurs
113 public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
114 final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
115 .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true);
116 testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName());
117 testServer.waitedStart(5000);
118 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
119 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
125 * Build a guard simulator.
127 * @return the simulator
128 * @throws InterruptedException if a thread is interrupted
129 * @throws IOException if an IO errror occurs
131 public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
132 HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(GUARDSIM_SERVER_NAME,
133 LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true);
134 testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
135 testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
136 testServer.waitedStart(5000);
137 if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
138 throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());