Skip to main content
summaryrefslogtreecommitdiffstats
blob: 972b6d3f5f6d1b9fc7421b0e19c7c3144a66a3bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.server.internal.console;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osee.console.admin.Console;
import org.eclipse.osee.console.admin.ConsoleCommand;
import org.eclipse.osee.console.admin.ConsoleParameters;
import org.eclipse.osee.framework.core.server.IApplicationServerManager;
import org.eclipse.osee.framework.core.server.IAuthenticationManager;
import org.eclipse.osee.framework.core.server.OseeServerProperties;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.jdbc.JdbcClientConfig;
import org.eclipse.osee.jdbc.JdbcServerConfig;
import org.eclipse.osee.jdbc.JdbcService;

/**
 * @author Roberto E. Escobar
 */
public class ServerStatsCommand implements ConsoleCommand {

   private final Map<String, JdbcService> jdbcServices = new ConcurrentHashMap<String, JdbcService>();
   private IApplicationServerManager manager;
   private IAuthenticationManager authManager;

   public void setApplicationServerManager(IApplicationServerManager manager) {
      this.manager = manager;
   }

   public void setAuthenticationManager(IAuthenticationManager authManager) {
      this.authManager = authManager;
   }

   public void addJdbcService(JdbcService jdbcService) {
      jdbcServices.put(jdbcService.getId(), jdbcService);
   }

   public void removeJdbcService(JdbcService jdbcService) {
      jdbcServices.remove(jdbcService.getId());
   }

   @Override
   public String getName() {
      return "server_status";
   }

   @Override
   public String getDescription() {
      return "Displays server status information";
   }

   @Override
   public String getUsage() {
      return "";
   }

   @Override
   public Callable<?> createCallable(final Console console, final ConsoleParameters params) {
      return new Callable<Boolean>() {

         @Override
         public Boolean call() throws Exception {
            console.writeln("\n----------------------------------------------");
            console.writeln("                  Server Stats");
            console.writeln("----------------------------------------------");

            console.writeln("Server:[%s]", manager.getServerUri());
            console.writeln("Id: [%s]", manager.getId());
            console.writeln("Running Since: [%s]\n",
               DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(manager.getDateStarted()));

            console.writeln("Code Base Location: [%s]", System.getProperty("user.dir"));
            console.writeln("Binary Data Path: [%s]", OseeServerProperties.getOseeApplicationServerData(null));
            JdbcService jdbcService = getJdbcService("orcs.jdbc.service");
            writeOrcsJdbcServiceInfo(jdbcService);
            console.writeln();

            console.writeln("Authentication Scheme: [%s]", authManager.getProtocol());
            console.writeln("Supported Authentication Schemes: %s", Arrays.deepToString(authManager.getProtocols()));
            console.writeln();

            console.writeln("Supported Versions: %s", Arrays.deepToString(manager.getVersions()));
            console.writeln(Lib.getMemoryInfo());

            logServlets(manager);

            console.writeln("\nServer State: [%s]", manager.isSystemIdle() ? "IDLE" : "BUSY");
            console.writeln("Active Threads: [%s]", manager.getNumberOfActiveThreads());

            IJobManager jobManager = Job.getJobManager();
            console.writeln("Job Manager: [%s]", jobManager.isIdle() ? "IDLE" : "BUSY");

            Job current = jobManager.currentJob();

            console.writeln("Current Job: [%s]", current != null ? current.getName() : "NONE");

            console.write("Current Tasks: ");
            List<String> entries = manager.getCurrentProcesses();
            if (entries.isEmpty()) {
               console.writeln("[NONE]");
            } else {
               console.writeln();
               for (int index = 0; index < entries.size(); index++) {
                  console.writeln("\t[%s] - %s", index, entries.get(index));
               }
            }
            console.writeln();
            writeJdbcStats();
            console.writeln();
            return Boolean.TRUE;
         }

         private void logServlets(IApplicationServerManager manager) {
            console.writeln("Servlets:");
            List<String> contexts = new ArrayList<String>(manager.getRegisteredServlets());
            Collections.sort(contexts);
            if (contexts.size() % 2 == 1) {
               contexts.add("");
            }
            int midPoint = contexts.size() / 2;
            for (int i = 0; i < midPoint; i++) {
               console.writeln("%-40.40s%s", contexts.get(i), contexts.get(i + midPoint));
            }
         }

         private void writeOrcsJdbcServiceInfo(JdbcService jdbcService) {
            if (jdbcService != null) {
               JdbcClientConfig config = jdbcService.getClient().getConfig();
               console.writeln("Datastore Uri: [%s]", config.getDbUri());
               if (jdbcService.hasServer()) {
                  JdbcServerConfig serverConfig = jdbcService.getServerConfig();
                  console.writeln("Datastore Db Path: [%s]", serverConfig.getDbPath());
               }
            } else {
               console.writeln("Datastore: [N/A]");
            }
         }

         private JdbcService getJdbcService(String binding) {
            JdbcService toReturn = null;
            for (JdbcService jdbcService : jdbcServices.values()) {
               if (jdbcService.getBindings().contains(binding)) {
                  toReturn = jdbcService;
                  break;
               }
            }
            return toReturn;
         }

         private void writeJdbcStats() {
            console.writeln("Jdbc Services:");
            boolean isFirst = true;
            for (JdbcService jdbcService : jdbcServices.values()) {
               try {
                  if (!isFirst) {
                     console.writeln("");
                  }
                  console.writeln("\tid: %s", jdbcService.getId());
                  console.writeln("\tbindings: %s", jdbcService.getBindings());
                  console.writeln("\turi: %s", jdbcService.getClient().getConfig().getDbUri());
                  if (jdbcService.hasServer()) {
                     console.writeln("\tdb.file: %s", jdbcService.getServerConfig().getDbPath());
                  }
                  Map<String, String> store = jdbcService.getClient().getStatistics();
                  for (String key : store.keySet()) {
                     String value = store.get(key);
                     console.writeln("\t%s: %s", key, value);
                  }
                  isFirst = false;
               } catch (Exception ex) {
                  console.write(ex);
               }
            }
         }
      };
   }

}

Back to the top