author | Stephen Talley <stephen.talley@oracle.com> |
Wed, 08 Dec 2010 14:11:58 -0500 | |
changeset 616 | b61fe1d9f00b |
parent 603 | 71a20acea802 |
child 620 | faf036da4417 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
2 |
* CDDL HEADER START |
0 | 3 |
* |
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
23 |
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 24 |
*/ |
25 |
||
26 |
package org.opensolaris.os.vp.client.swing; |
|
27 |
||
28 |
import java.io.*; |
|
29 |
import java.net.*; |
|
30 |
import java.util.*; |
|
31 |
import java.util.logging.*; |
|
32 |
import org.opensolaris.os.uds.*; |
|
33 |
import org.opensolaris.os.vp.client.common.*; |
|
459
abb4563e4968
14804 panels should know about/recover from from lost connections to server
Stephen Talley <stephen.talley@sun.com>
parents:
396
diff
changeset
|
34 |
import org.opensolaris.os.vp.panel.common.*; |
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
35 |
import org.opensolaris.os.vp.panel.common.action.*; |
40
d1412af1ae5b
3215 ActionAbortedException is used too broadly
Stephen Talley <stephen.talley@sun.com>
parents:
13
diff
changeset
|
36 |
import org.opensolaris.os.vp.panel.common.control.*; |
220
696985231edf
6899 --topless/-t option should be changed to --undecorated
Stephen Talley <stephen.talley@sun.com>
parents:
219
diff
changeset
|
37 |
import org.opensolaris.os.vp.util.cli.*; |
219
57841c113efe
6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents:
217
diff
changeset
|
38 |
import org.opensolaris.os.vp.util.misc.*; |
591
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
39 |
import org.opensolaris.os.vp.util.misc.finder.Finder; |
0 | 40 |
|
41 |
/** |
|
389
374730420407
13348 the App class should not be run as a daemon thread
Stephen Talley <stephen.talley@sun.com>
parents:
381
diff
changeset
|
42 |
* The {@code App} class is a thread that listens for UDS connections from other |
374730420407
13348 the App class should not be run as a daemon thread
Stephen Talley <stephen.talley@sun.com>
parents:
381
diff
changeset
|
43 |
* processes. Multiple addresses of panels to display, one per |
0 | 44 |
* newline-terminated lines, may be sent through these connections. |
45 |
*/ |
|
42
0870a1fd0ef2
3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
46 |
public class App extends Thread implements AppConstants { |
0 | 47 |
// |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
48 |
// Inner classes |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
49 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
50 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
51 |
public static class CommandLineOptionsBean { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
52 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
53 |
// Instance data |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
54 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
55 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
56 |
private String host = RadLoginManager.LOCAL_HOST; |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
57 |
private String user = RadLoginManager.LOCAL_USER; |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
58 |
private String role; |
285
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
59 |
private String address = null; |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
60 |
private boolean newJVM; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
61 |
private HelpFormatter help; |
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
62 |
private Properties properties = new Properties(); |
285
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
63 |
private boolean inParam = false; |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
64 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
65 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
66 |
// Constructors |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
67 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
68 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
69 |
public CommandLineOptionsBean(HelpFormatter help) { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
70 |
this.help = help; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
71 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
72 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
73 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
74 |
// CommandLineOptionsBean methods |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
75 |
// |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
76 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
77 |
public String getAddress() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
78 |
return address; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
79 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
80 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
81 |
public String getHost() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
82 |
return host; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
83 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
84 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
85 |
public boolean getNewjvm() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
86 |
return newJVM; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
87 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
88 |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
89 |
public Properties getProperties() { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
90 |
return properties; |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
91 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
92 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
93 |
public String getRole() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
94 |
return role; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
95 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
96 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
97 |
public String getUser() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
98 |
return user; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
99 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
100 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
101 |
public void setAddress(String address) { |
285
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
102 |
boolean absolute = address.startsWith("/"); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
103 |
if (this.address == null) { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
104 |
if (!absolute) { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
105 |
// Assume non-relative path is a standalone shortcut |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
106 |
address = String.format("/%s/%s", |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
107 |
Control.encode(AppRootControl.ID, null), address); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
108 |
} |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
109 |
this.address = address; |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
110 |
} else { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
111 |
/* |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
112 |
* If the address has already been set, we accumulate |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
113 |
* additional operands as query parameters or subsequent |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
114 |
* path elements. |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
115 |
*/ |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
116 |
if (absolute) { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
117 |
this.address = this.address + address; |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
118 |
inParam = false; |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
119 |
} else { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
120 |
try { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
121 |
/* |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
122 |
* Ideally we'd use Control.encode, but mapping |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
123 |
* from our input to what it requires would be |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
124 |
* much less straightforward than what follows. |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
125 |
*/ |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
126 |
String[] parts = address.split("=", 2); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
127 |
StringBuffer b = new StringBuffer(this.address); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
128 |
b.append(inParam ? "&" : "?"); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
129 |
b.append(URLEncoder.encode(parts[0], Control.ENCODING)); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
130 |
b.append('='); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
131 |
if (parts.length > 1) |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
132 |
b.append(URLEncoder.encode(parts[1], |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
133 |
Control.ENCODING)); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
134 |
this.address = b.toString(); |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
135 |
inParam = true; |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
136 |
} catch (UnsupportedEncodingException ex) { |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
137 |
} |
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
138 |
} |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
139 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
140 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
141 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
142 |
public void setHelp() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
143 |
System.out.println(help.getHelp()); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
144 |
System.exit(0); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
145 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
146 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
147 |
public void setHost(String host) { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
148 |
this.host = host; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
149 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
150 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
151 |
public void setNewjvm() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
152 |
newJVM = true; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
153 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
154 |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
155 |
public void setProperty(String property) { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
156 |
String value; |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
157 |
int index = property.indexOf("="); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
158 |
if (index == -1) { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
159 |
value = ""; |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
160 |
} else { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
161 |
value = property.substring(index + 1); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
162 |
property = property.substring(0, index - 1); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
163 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
164 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
165 |
properties.setProperty(property, value); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
166 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
167 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
168 |
public void setRole(String role) { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
169 |
this.role = role; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
170 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
171 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
172 |
public void setUser(String user) { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
173 |
this.user = user; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
174 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
175 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
176 |
public void setVersion() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
177 |
showVersion(); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
178 |
System.exit(0); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
179 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
180 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
181 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
182 |
// |
0 | 183 |
// Static data |
184 |
// |
|
185 |
||
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
186 |
private static final String ARG_NONOPT_ADDRESS = "address"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
187 |
private static final String ARG_SHORT_HOST = "h"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
188 |
private static final String ARG_LONG_HOST = "host"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
189 |
private static final String ARG_SHORT_NEWJVM = "j"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
190 |
private static final String ARG_LONG_NEWJVM = "newjvm"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
191 |
private static final String ARG_SHORT_USER = "u"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
192 |
private static final String ARG_LONG_USER = "user"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
193 |
private static final String ARG_SHORT_ROLE = "r"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
194 |
private static final String ARG_LONG_ROLE = "role"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
195 |
private static final String ARG_SHORT_VERSION = "v"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
196 |
private static final String ARG_LONG_VERSION = "version"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
197 |
private static final String ARG_SHORT_HELP = "?"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
198 |
private static final String ARG_LONG_HELP = "help"; |
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
199 |
private static final String ARG_SHORT_PROPERTY = "D"; |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
200 |
private static final String ARG_LONG_PROPERTY = "property"; |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
201 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
202 |
private static final String COMMAND_NAME = "vp"; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
203 |
private static final String COMMAND_DESC = |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
204 |
Finder.getString("cli.description"); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
205 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
206 |
private static OptionChoiceGroup options; |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
207 |
static { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
208 |
OptionElement addressOption = new NoOptOptionElement( |
285
12385adc74f4
8576 command line parser doesn't accept optargs that look like arguments
David Powell <David.Powell@sun.com>
parents:
284
diff
changeset
|
209 |
true, ARG_NONOPT_ADDRESS, Finder.getString("cli.arg.address"), -1); |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
210 |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
211 |
OptionElement propOption = new OptionElement(ARG_SHORT_PROPERTY, |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
212 |
ARG_LONG_PROPERTY, false, "property", ""); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
213 |
propOption.setDocumented(false); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
214 |
propOption.setUseLimit(-1); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
215 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
216 |
OptionElement hostOption = new OptionElement(ARG_SHORT_HOST, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
217 |
ARG_LONG_HOST, false, "host", Finder.getString("cli.arg.host")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
218 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
219 |
OptionElement newJVMOption = new OptionElement(ARG_SHORT_NEWJVM, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
220 |
ARG_LONG_NEWJVM, false, Finder.getString("cli.arg.newjvm")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
221 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
222 |
OptionElement userOption = new OptionElement(ARG_SHORT_USER, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
223 |
ARG_LONG_USER, false, "user", Finder.getString("cli.arg.user")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
224 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
225 |
OptionElement roleOption = new OptionElement(ARG_SHORT_ROLE, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
226 |
ARG_LONG_ROLE, false, "role", Finder.getString("cli.arg.role")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
227 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
228 |
OptionElement versionOption = new OptionElement(ARG_SHORT_VERSION, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
229 |
ARG_LONG_VERSION, false, Finder.getString("cli.arg.version")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
230 |
|
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
231 |
OptionElement helpOption = new OptionElement(ARG_SHORT_HELP, |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
232 |
ARG_LONG_HELP, false, Finder.getString("cli.arg.help")); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
233 |
|
220
696985231edf
6899 --topless/-t option should be changed to --undecorated
Stephen Talley <stephen.talley@sun.com>
parents:
219
diff
changeset
|
234 |
OptionListGroup mainGroup = new OptionListGroup(false, |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
235 |
propOption, hostOption, userOption, roleOption, newJVMOption, |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
236 |
addressOption); |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
237 |
|
217
b5a0a305991e
6773 panel registration has vestigial dependencies on categories
Stephen Talley <stephen.talley@sun.com>
parents:
213
diff
changeset
|
238 |
options = new OptionChoiceGroup(true, mainGroup, versionOption, |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
239 |
helpOption); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
240 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
241 |
|
0 | 242 |
public static final String URI_SCHEME = "vp"; |
243 |
public static final String URI_USER_ROLE_SEPARATOR = ":"; |
|
244 |
||
245 |
public static final String VP_USER_DIR = |
|
246 |
System.getProperty("user.home") + File.separator + ".vp"; |
|
247 |
||
248 |
static { |
|
249 |
// Set up client logging |
|
250 |
String fileName = VP_USER_DIR + File.separator + "log"; |
|
251 |
||
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
252 |
// Root Logger |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
253 |
Logger log = Logger.getLogger(""); |
0 | 254 |
|
255 |
try { |
|
256 |
File parent = new File(fileName).getParentFile(); |
|
257 |
if (!parent.exists()) { |
|
258 |
if (!parent.mkdirs()) { |
|
259 |
throw new IOException( |
|
260 |
"could not create directory: " + |
|
261 |
parent.getAbsolutePath()); |
|
262 |
} |
|
263 |
} |
|
264 |
||
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
265 |
Handler fHandler = new FileHandler(fileName); |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
266 |
fHandler.setFormatter(new SimpleFormatter()); |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
267 |
log.addHandler(fHandler); |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
268 |
|
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
269 |
// Don't output to the console by default |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
270 |
for (Handler cHandler : log.getHandlers()) { |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
271 |
if (cHandler instanceof ConsoleHandler) { |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
272 |
log.removeHandler(cHandler); |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
273 |
} |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
274 |
} |
0 | 275 |
} catch (IOException e) { |
591
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
276 |
Logger.getLogger(App.class.getName()).log(Level.WARNING, |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
277 |
"unable to create log file: " + fileName); |
0 | 278 |
} |
279 |
} |
|
280 |
||
281 |
public static final File TRUSTSTORE_FILE = |
|
282 |
new File(VP_USER_DIR, "truststore"); |
|
283 |
||
284 |
public static final File VP_UDS; |
|
285 |
static { |
|
286 |
String hostName = NetUtil.getHostName(); |
|
287 |
if (hostName == null) { |
|
288 |
hostName = "localhost"; |
|
289 |
} |
|
290 |
||
291 |
// May be null or malformed if not an X client |
|
292 |
String display = System.getenv("DISPLAY"); |
|
293 |
||
294 |
if (display != null && !display.matches(".*:\\d+(\\.\\d)?$")) { |
|
295 |
String error = "invalid DISPLAY environment variable: " + display; |
|
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
296 |
Logger.getLogger(App.class.getName()).log(Level.WARNING, error); |
0 | 297 |
display = null; |
298 |
} |
|
299 |
||
300 |
if (display == null) { |
|
301 |
display = ":0.0"; |
|
302 |
} else { |
|
303 |
if (display.matches(".*:\\d+$")) { |
|
304 |
display += ".0"; |
|
305 |
} |
|
306 |
||
307 |
if (display.startsWith(hostName)) { |
|
308 |
display = display.substring(hostName.length()); |
|
309 |
} |
|
310 |
} |
|
311 |
||
312 |
String name = String.format(".uds-%s-%s", hostName, display); |
|
313 |
||
314 |
VP_UDS = new File(VP_USER_DIR, name); |
|
315 |
} |
|
316 |
||
317 |
public static final String VP_USER_PREFS = |
|
318 |
VP_USER_DIR + File.separator + "vp.init"; |
|
319 |
||
320 |
private static final Preferences prefs = new Preferences(VP_USER_PREFS); |
|
321 |
||
322 |
// |
|
323 |
// Instance data |
|
324 |
// |
|
325 |
||
326 |
private UDSocketServer server; |
|
314
8decc90a3ec6
9416 more fully featured FMRI type (fix lint)
David Powell <David.Powell@sun.com>
parents:
300
diff
changeset
|
327 |
private final List<AppInstance> instances = new ArrayList<AppInstance>(); |
0 | 328 |
private ConnectionManager connManager = new ConnectionManager(); |
603
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
329 |
private LoginHistoryManager loginHistoryManager = |
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
330 |
new LoginHistoryManager(connManager, new File(VP_USER_DIR, "history")); |
0 | 331 |
|
332 |
// |
|
333 |
// Constructors |
|
334 |
// |
|
335 |
||
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
336 |
public App() { |
43
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
337 |
addVersionToThreadName(this); |
0 | 338 |
} |
339 |
||
340 |
// |
|
341 |
// Runnable methods |
|
342 |
// |
|
343 |
||
344 |
@Override |
|
345 |
public void run() { |
|
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
346 |
Logger log = Logger.getLogger(getClass().getName()); |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
347 |
|
0 | 348 |
// Start singleton application instance... |
349 |
try { |
|
350 |
server = UnixDomainSocket.bind(VP_UDS, 0600); |
|
351 |
||
352 |
while (true) { |
|
353 |
final UDSocket socket = server.accept(); |
|
354 |
String peerUser = socket.getPeerUser(); |
|
355 |
||
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
356 |
if (!RadLoginManager.LOCAL_USER.equals(peerUser)) { |
0 | 357 |
String error = String.format( |
358 |
"user %s attempted to connect as %s", peerUser, |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
359 |
RadLoginManager.LOCAL_USER); |
0 | 360 |
log.log(Level.WARNING, error); |
361 |
} else { |
|
362 |
// Spawn on a separate thread so as not to block other |
|
363 |
// incoming to conections -- not so much because we |
|
364 |
// anticipate a lot of traffic, but because we can't |
|
365 |
// guarantee that some poorly-behaved client won't keep its |
|
366 |
// connection open indefinitely. |
|
367 |
new Thread() { |
|
368 |
@Override |
|
369 |
public void run() { |
|
370 |
readFully(socket); |
|
371 |
} |
|
372 |
}.start(); |
|
373 |
} |
|
374 |
} |
|
375 |
} catch (UDSNotSupportedException e) { |
|
376 |
// Bummer |
|
377 |
return; |
|
378 |
} catch (IOException e) { |
|
379 |
// Major bummer |
|
380 |
log.log(Level.SEVERE, "error creating daemon", e); |
|
381 |
return; |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
// |
|
386 |
// App methods |
|
387 |
// |
|
388 |
||
389 |
public void abortableExit() throws ActionAbortedException { |
|
390 |
synchronized (instances) { |
|
391 |
for (int i = instances.size() - 1; i >= 0; i--) { |
|
392 |
// Throws ActionAbortedException |
|
356
379b8150bb93
11379 apache: unable to cancel app with bad data in outstanding changes
Stephen Talley <stephen.talley@sun.com>
parents:
344
diff
changeset
|
393 |
instances.get(i).closeInstance(false); |
0 | 394 |
} |
395 |
} |
|
396 |
exit(); |
|
397 |
} |
|
398 |
||
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
399 |
public void exit(int exitCode) { |
0 | 400 |
try { |
401 |
if (server != null) { |
|
402 |
server.close(); |
|
403 |
} |
|
404 |
} catch (IOException ignore) { |
|
405 |
} |
|
406 |
||
407 |
try { |
|
408 |
prefs.store(); |
|
409 |
} catch (IOException e) { |
|
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
410 |
Logger.getLogger(getClass().getName()).log(Level.WARNING, |
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
411 |
"could not write preferences", e); |
0 | 412 |
} |
413 |
||
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
414 |
System.exit(exitCode); |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
415 |
} |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
416 |
|
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
417 |
public void exit() { |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
418 |
exit(0); |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
419 |
} |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
420 |
|
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
421 |
private void exitIfNoIntances(int exitCode) { |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
422 |
if (instances.isEmpty()) { |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
423 |
exit(exitCode); |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
424 |
} |
0 | 425 |
} |
426 |
||
427 |
public ConnectionManager getConnectionManager() { |
|
428 |
return connManager; |
|
429 |
} |
|
430 |
||
603
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
431 |
public LoginHistoryManager getLoginHistoryManager() { |
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
432 |
return loginHistoryManager; |
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
433 |
} |
71a20acea802
17449 AppLoginHistory's factory method ignores its argument at times
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
601
diff
changeset
|
434 |
|
0 | 435 |
protected Preferences getPreferences() { |
436 |
return prefs; |
|
437 |
} |
|
438 |
||
439 |
protected void instanceClosed(AppInstance instance) { |
|
440 |
synchronized (instances) { |
|
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
441 |
if (instances.remove(instance)) { |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
442 |
exitIfNoIntances(0); |
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
443 |
} |
0 | 444 |
} |
445 |
} |
|
446 |
||
381
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
447 |
protected void instanceCreated(AppInstance instance) { |
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
448 |
synchronized (instances) { |
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
449 |
instances.add(instance); |
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
450 |
} |
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
451 |
} |
2bae201e9d41
svcs: clicking "Close" kills all panel instances, not just that one
Stephen Talley <stephen.talley@sun.com>
parents:
376
diff
changeset
|
452 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
453 |
public void newInstance(Properties properties, URI uri) { |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
454 |
String hostVal = uri.getHost(); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
455 |
String roleVal = null; |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
456 |
String userVal = uri.getUserInfo(); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
457 |
int i = userVal.indexOf(URI_USER_ROLE_SEPARATOR); |
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
458 |
if (i != -1) { |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
459 |
roleVal = userVal.substring(i + 1); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
460 |
userVal = userVal.substring(0, i); |
0 | 461 |
} |
323
497a785649eb
10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents:
317
diff
changeset
|
462 |
|
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
463 |
AppInstance instance = null; |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
464 |
boolean success = false; |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
465 |
|
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
466 |
try { |
600
c16a7e34499d
17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents:
591
diff
changeset
|
467 |
StringLoginProperty host = new StringLoginProperty(hostVal, false); |
616
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
468 |
host.setEditableOnError(true); |
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
469 |
|
600
c16a7e34499d
17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents:
591
diff
changeset
|
470 |
StringLoginProperty user = new StringLoginProperty(userVal, false); |
616
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
471 |
user.setEditableOnError(true); |
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
472 |
|
600
c16a7e34499d
17304 - Implement password type
Shadrack Kilemba <Shadrack.Kilemba@Oracle.COM>
parents:
591
diff
changeset
|
473 |
StringLoginProperty role = new StringLoginProperty(roleVal, false); |
616
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
474 |
role.setEditableOnError(true); |
b61fe1d9f00b
17577 vp should be more forgiving of bad command-line login requests
Stephen Talley <stephen.talley@oracle.com>
parents:
603
diff
changeset
|
475 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
476 |
LoginRequest request = new LoginRequest(host, user, role); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
477 |
|
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
478 |
instance = new AppInstance(this, properties, request); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
479 |
|
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
480 |
SimpleNavigable[] path = Navigator.toArray(uri.getPath()); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
481 |
instance.getNavigator().goToAsyncAndWait(true, null, path); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
482 |
success = true; |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
483 |
|
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
484 |
// User is aware of this because he explicitly caused it |
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
485 |
} catch (ActionAbortedException e) { |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
486 |
|
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
487 |
// User has been advised of this by RadLoginManager |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
488 |
} catch (ActionFailedException e) { |
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
489 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
490 |
// User has been advised of this by SwingNavigator |
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
491 |
} catch (NavigationException e) { |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
492 |
|
581
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
493 |
// Unexpected error - write to log |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
494 |
} catch (RuntimeException e) { |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
495 |
Logger log = Logger.getLogger(getClass().getName()); |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
496 |
log.log(Level.SEVERE, "could not launch: " + uri, e); |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
497 |
|
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
498 |
// Unexpected error - write to log |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
499 |
} catch (Error e) { |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
500 |
Logger log = Logger.getLogger(getClass().getName()); |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
501 |
log.log(Level.SEVERE, "could not launch: " + uri, e); |
c1b6248742a7
12303 ServiceSwingPanelDescriptor subclasses blow up if they don't refresh()
Stephen Talley <stephen.talley@oracle.com>
parents:
513
diff
changeset
|
502 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
503 |
} finally { |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
504 |
if (!success && instance != null && |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
505 |
// Partial navigation failures aren't deal-breakers |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
506 |
!NavigationUtil.isPanelStarted(instance.getNavigator())) { |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
507 |
|
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
508 |
instance.close(); |
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
509 |
} |
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
510 |
} |
323
497a785649eb
10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents:
317
diff
changeset
|
511 |
} |
497a785649eb
10071 apply new design to SMF panel
David Powell <David.Powell@sun.com>
parents:
317
diff
changeset
|
512 |
|
0 | 513 |
public void readFully(UDSocket socket) { |
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
514 |
BufferedReader reader = null; |
513
691122ca7b6f
15669 - Client should configure root Logger, use distinct Loggers
Dan Labrecque <Dan.Labrecque@oracle.com>
parents:
473
diff
changeset
|
515 |
Logger log = Logger.getLogger(getClass().getName()); |
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
516 |
|
0 | 517 |
try { |
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
518 |
reader = new BufferedReader( |
0 | 519 |
new InputStreamReader(socket.getInputStream())); |
520 |
||
521 |
String line; |
|
522 |
while ((line = reader.readLine()) != null) { |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
523 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
524 |
// Format of each line is "<uri>[ <properties>]" |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
525 |
String[] parts = line.split("\\s+"); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
526 |
URI uri = new URI(parts[0]); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
527 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
528 |
Properties properties = null; |
284
255095584c55
8351 need way to build without building javadoc
David Powell <David.Powell@sun.com>
parents:
279
diff
changeset
|
529 |
if (parts.length > 1) { |
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
530 |
String decodedProps = URLDecoder.decode(parts[1], |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
531 |
Control.ENCODING); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
532 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
533 |
StringReader propReader = new StringReader(decodedProps); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
534 |
properties = new Properties(); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
535 |
properties.load(propReader); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
536 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
537 |
|
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
538 |
newInstance(properties, uri); |
0 | 539 |
} |
540 |
||
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
541 |
} catch (IllegalArgumentException e) { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
542 |
log.log(Level.SEVERE, "malformed Unicode escape sequence", e); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
543 |
|
0 | 544 |
} catch (IOException e) { |
545 |
log.log(Level.SEVERE, "I/O error", e); |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
546 |
|
0 | 547 |
} catch (URISyntaxException e) { |
548 |
log.log(Level.WARNING, "remote request with invalid URI", e); |
|
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
549 |
|
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
550 |
} finally { |
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
551 |
IOUtil.closeIgnore(reader); |
0 | 552 |
} |
553 |
} |
|
554 |
||
459
abb4563e4968
14804 panels should know about/recover from from lost connections to server
Stephen Talley <stephen.talley@sun.com>
parents:
396
diff
changeset
|
555 |
// |
0 | 556 |
// Static methods |
557 |
// |
|
558 |
||
43
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
559 |
private static void addVersionToThreadName(Thread thread) { |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
560 |
// Add useful information to a thread dump |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
561 |
String name = String.format( |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
562 |
"%s (app version %s)", thread.getName(), VERSION); |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
563 |
|
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
564 |
thread.setName(name); |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
565 |
} |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
566 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
567 |
public static void showVersion() { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
568 |
System.out.println(Finder.getString("cli.error.version", VERSION)); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
569 |
} |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
570 |
|
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
571 |
public static URI createURI(String host, String user, String role, |
0 | 572 |
String address) throws URISyntaxException { |
573 |
||
574 |
if (role != null) { |
|
575 |
user += URI_USER_ROLE_SEPARATOR + role; |
|
576 |
} |
|
577 |
||
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
578 |
return new URI(URI_SCHEME, user, host, -1, address, null, null); |
0 | 579 |
} |
580 |
||
581 |
public static void main(String args[]) { |
|
43
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
582 |
addVersionToThreadName(Thread.currentThread()); |
e7573475aac8
3242 add version to thread name to improve debuggability of bugs with thread dumps
Stephen Talley <stephen.talley@sun.com>
parents:
42
diff
changeset
|
583 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
584 |
CommandLineParser parser = new PosixCommandLineParser(); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
585 |
UsageFormatter usage = new UsageFormatter( |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
586 |
COMMAND_NAME, options, parser.getOptionFormatter()); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
587 |
HelpFormatter help = new HelpFormatter(COMMAND_DESC, usage); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
588 |
CommandLineOptionsBean bean = new CommandLineOptionsBean(help); |
0 | 589 |
|
42
0870a1fd0ef2
3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
590 |
if (System.getProperty("vpanels.debug.version") != null) { |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
591 |
showVersion(); |
42
0870a1fd0ef2
3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
592 |
} |
0870a1fd0ef2
3235 vp needs to be able to report a version to assist with testing
Stephen Talley <stephen.talley@sun.com>
parents:
40
diff
changeset
|
593 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
594 |
try { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
595 |
// Populate bean |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
596 |
CommandLineProcessor.process(args, options, parser, bean); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
597 |
} |
0 | 598 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
599 |
catch (Exception e) { |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
600 |
CommandUtil.exit(e, usage); |
0 | 601 |
} |
602 |
||
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
603 |
String address = bean.getAddress(); |
0 | 604 |
URI uri = null; |
605 |
try { |
|
300
7f3357de9250
8810 incomplete support for port specification
David Powell <David.Powell@sun.com>
parents:
285
diff
changeset
|
606 |
uri = createURI(bean.getHost(), bean.getUser(), bean.getRole(), |
473
18f221b572ce
14914 all local logins should use AF_UNIX connections
Stephen Talley <stephen.talley@oracle.com>
parents:
459
diff
changeset
|
607 |
address); |
0 | 608 |
} catch (URISyntaxException e) { |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
609 |
System.err.println(Finder.getString("cli.error.uri", e.getInput())); |
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
610 |
System.exit(1); |
0 | 611 |
} |
612 |
||
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
613 |
Properties properties = bean.getProperties(); |
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
614 |
if (!bean.getNewjvm()) { |
0 | 615 |
// Check for running instance |
616 |
try { |
|
617 |
UDSocket socket = UnixDomainSocket.connect(VP_UDS); |
|
618 |
||
619 |
// Send arguments to running instance... |
|
620 |
PrintWriter out = new PrintWriter(socket.getOutputStream()); |
|
279
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
621 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
622 |
// Format of each line is "<uri>[ <properties>]" |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
623 |
out.print(uri); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
624 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
625 |
try { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
626 |
if (properties != null) { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
627 |
StringWriter propWriter = new StringWriter(); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
628 |
properties.store(propWriter, null); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
629 |
String props = propWriter.toString(); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
630 |
String encodedProps = URLEncoder.encode(props, |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
631 |
Control.ENCODING); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
632 |
out.print(' '); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
633 |
out.print(encodedProps); |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
634 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
635 |
} catch (IOException e) { |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
636 |
// Unlikely |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
637 |
} |
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
638 |
|
b82f64a1f586
8129 smf/sharemgr/sysid: breadcrumbs should be shown until UI redesign is implemented
Stephen Talley <stephen.talley@sun.com>
parents:
243
diff
changeset
|
639 |
out.println(); |
0 | 640 |
out.close(); |
641 |
System.exit(0); |
|
642 |
} catch (UDSNotSupportedException e) { |
|
643 |
// UDS not supported on this platform |
|
644 |
} catch (IOException e) { |
|
645 |
// We are the only running instance |
|
646 |
} |
|
647 |
} |
|
648 |
||
591
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
649 |
try { |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
650 |
URL policy = Finder.getResource("panel.policy"); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
651 |
if (policy == null) { |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
652 |
throw new IOException("panel.policy not found"); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
653 |
} |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
654 |
PanelClassLoader.loadPermissions(policy); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
655 |
} catch (IOException e) { |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
656 |
Logger.getLogger(App.class.getName()).log(Level.SEVERE, |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
657 |
"unable to read panel.policy", e); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
658 |
String message = Finder.getString("init.error.security.io"); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
659 |
System.err.println(message); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
660 |
System.exit(1); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
661 |
} catch (PermissionParseException e) { |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
662 |
Logger.getLogger(App.class.getName()).log(Level.SEVERE, |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
663 |
"unable to parse panel.policy", e); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
664 |
String message = Finder.getString("init.error.security.parse"); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
665 |
System.err.println(message); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
666 |
System.exit(1); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
667 |
} |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
668 |
|
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
669 |
System.setSecurityManager(new SecurityManager()); |
7c5752b99fd6
12473 panels should probably be run in a sandbox
Stephen Talley <stephen.talley@oracle.com>
parents:
581
diff
changeset
|
670 |
|
366
610ee2561491
10344 need to reload panel when server changes
Stephen Talley <stephen.talley@sun.com>
parents:
365
diff
changeset
|
671 |
App app = new App(); |
376
da611bd28519
12085 vp should still try to start panel even if some parts of address are invalid
Stephen Talley <stephen.talley@sun.com>
parents:
373
diff
changeset
|
672 |
app.newInstance(properties, uri); |
601
9d4e3e0ee603
7947 vp should fail if unable to connect to requested host
Stephen Talley <stephen.talley@oracle.com>
parents:
600
diff
changeset
|
673 |
app.exitIfNoIntances(1); |
0 | 674 |
|
78
6336fcea8db0
2521 Formalize CLI option parsing and document CLI syntax
Stephen Talley <stephen.talley@sun.com>
parents:
43
diff
changeset
|
675 |
if (!bean.getNewjvm()) { |
0 | 676 |
// Start daemon thread listening for connections |
677 |
app.start(); |
|
678 |
} |
|
679 |
} |
|
680 |
} |