blob: e9bd71a28423812660e49a704b7b8c18cad7fb6e [file] [log] [blame]
Thomas Vachuska1eff3a62016-05-03 01:07:24 -07001/*
2 * Copyright 2016 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onlab.warden;
18
19import org.eclipse.jetty.server.Server;
20import org.eclipse.jetty.servlet.ServletHandler;
21import org.eclipse.jetty.util.log.Logger;
22
23/**
24 * Main program for executing scenario test warden.
25 */
26public final class Main {
27
28 // Public construction forbidden
29 private Main(String[] args) {
30 }
31
32 /**
33 * Main entry point for the cell warden.
34 *
35 * @param args command-line arguments
36 */
37 public static void main(String[] args) {
38 Main main = new Main(args);
39 main.run();
40 }
41
42 // Runs the warden processing
43 private void run() {
44 startWebServer();
45 }
46
47 // Initiates a web-server.
48 private static void startWebServer() {
49 WardenServlet.warden = new Warden();
50 org.eclipse.jetty.util.log.Log.setLog(new NullLogger());
51 Server server = new Server(4321);
52 ServletHandler handler = new ServletHandler();
53 server.setHandler(handler);
54 handler.addServletWithMapping(WardenServlet.class, "/*");
55 try {
56 server.start();
57 } catch (Exception e) {
58 print("Warden already active...");
59 }
60 }
61
62 private static void print(String s) {
63 System.out.println(s);
64 }
65
66 // Logger to quiet Jetty down
67 private static class NullLogger implements Logger {
68 @Override
69 public String getName() {
70 return "quiet";
71 }
72
73 @Override
74 public void warn(String msg, Object... args) {
75 }
76
77 @Override
78 public void warn(Throwable thrown) {
79 }
80
81 @Override
82 public void warn(String msg, Throwable thrown) {
83 }
84
85 @Override
86 public void info(String msg, Object... args) {
87 }
88
89 @Override
90 public void info(Throwable thrown) {
91 }
92
93 @Override
94 public void info(String msg, Throwable thrown) {
95 }
96
97 @Override
98 public boolean isDebugEnabled() {
99 return false;
100 }
101
102 @Override
103 public void setDebugEnabled(boolean enabled) {
104 }
105
106 @Override
107 public void debug(String msg, Object... args) {
108 }
109
110 @Override
111 public void debug(Throwable thrown) {
112 }
113
114 @Override
115 public void debug(String msg, Throwable thrown) {
116 }
117
118 @Override
119 public Logger getLogger(String name) {
120 return this;
121 }
122
123 @Override
124 public void ignore(Throwable ignored) {
125 }
126 }
127
128}