-
Notifications
You must be signed in to change notification settings - Fork 188
/
PageAbout.java
296 lines (242 loc) · 11.5 KB
/
PageAbout.java
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.configuration;
import com.evolveum.midpoint.schema.LabeledString;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.util.LoadableModel;
import com.evolveum.midpoint.web.page.admin.home.PageAdminHome;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.ArrayList;
import java.util.List;
/**
* @author lazyman
*/
@PageDescriptor(url = "/admin/config/about", action = {
@AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL, description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.NS_AUTHORIZATION + "#configAbout",
label = "PageAbout.auth.configAbout.label", description = "PageAbout.auth.configAbout.description")})
public class PageAbout extends PageAdminConfiguration {
private static final Trace LOGGER = TraceManager.getTrace(PageAbout.class);
private static final String DOT_CLASS = PageAbout.class.getName() + ".";
private static final String OPERATION_TEST_REPOSITORY = DOT_CLASS + "testRepository";
private static final String OPERATION_TEST_REPOSITORY_CHECK_ORG_CLOSURE = DOT_CLASS + "testRepositoryCheckOrgClosure";
private static final String OPERATION_GET_REPO_DIAG = DOT_CLASS + "getRepoDiag";
private static final String ID_REVISION = "revision";
private static final String ID_PROPERTY = "property";
private static final String ID_VALUE = "value";
private static final String ID_LIST_SYSTEM_ITEMS = "listSystemItems";
private static final String ID_TEST_REPOSITORY = "testRepository";
private static final String ID_TEST_REPOSITORY_CHECK_ORG_CLOSURE = "testRepositoryCheckOrgClosure";
private static final String ID_TEST_PROVISIONING = "testProvisioning";
private static final String ID_IMPLEMENTATION_SHORT_NAME = "implementationShortName";
private static final String ID_IMPLEMENTATION_DESCRIPTION = "implementationDescription";
private static final String ID_IS_EMBEDDED = "isEmbedded";
private static final String ID_DRIVER_SHORT_NAME = "driverShortName";
private static final String ID_DRIVER_VERSION = "driverVersion";
private static final String ID_REPOSITORY_URL = "repositoryUrl";
private static final String ID_ADDITIONAL_DETAILS = "additionalDetails";
private static final String ID_DETAIL_NAME = "detailName";
private static final String ID_DETAIL_VALUE = "detailValue";
private static final String ID_JVM_PROPERTIES = "jvmProperties";
private static final String[] PROPERTIES = new String[]{"file.separator", "java.class.path",
"java.home", "java.vendor", "java.vendor.url", "java.version", "line.separator", "os.arch",
"os.name", "os.version", "path.separator", "user.dir", "user.home", "user.name"};
private IModel<RepositoryDiag> repoDiagModel;
public PageAbout() {
repoDiagModel = new LoadableModel<RepositoryDiag>(false) {
@Override
protected RepositoryDiag load() {
return loadRepoDiagModel();
}
};
initLayout();
}
private void initLayout() {
Label revision = new Label(ID_REVISION, createStringResource("PageAbout.midPointRevision"));
revision.setRenderBodyOnly(true);
add(revision);
ListView<SystemItem> listSystemItems = new ListView<SystemItem>(ID_LIST_SYSTEM_ITEMS, getItems()) {
@Override
protected void populateItem(ListItem<SystemItem> item) {
SystemItem systemItem = item.getModelObject();
Label property = new Label(ID_PROPERTY, systemItem.getProperty());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_VALUE, systemItem.getValue());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(listSystemItems);
addLabel(ID_IMPLEMENTATION_SHORT_NAME, "implementationShortName");
addLabel(ID_IMPLEMENTATION_DESCRIPTION, "implementationDescription");
addLabel(ID_IS_EMBEDDED, "isEmbedded");
addLabel(ID_DRIVER_SHORT_NAME, "driverShortName");
addLabel(ID_DRIVER_VERSION, "driverVersion");
addLabel(ID_REPOSITORY_URL, "repositoryUrl");
ListView<LabeledString> additionalDetails = new ListView<LabeledString>(ID_ADDITIONAL_DETAILS,
new PropertyModel<List<? extends LabeledString>>(repoDiagModel, "additionalDetails")) {
@Override
protected void populateItem(ListItem<LabeledString> item) {
LabeledString labeledString = item.getModelObject();
Label property = new Label(ID_DETAIL_NAME, labeledString.getLabel());
property.setRenderBodyOnly(true);
item.add(property);
Label value = new Label(ID_DETAIL_VALUE, labeledString.getData());
value.setRenderBodyOnly(true);
item.add(value);
}
};
add(additionalDetails);
Label jvmProperties = new Label(ID_JVM_PROPERTIES, new LoadableModel<String>(false) {
@Override
protected String load() {
try {
RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
return StringUtils.join(arguments, "<br/>");
} catch (Exception ex) {
return PageAbout.this.getString("PageAbout.message.couldntObtainJvmParams");
}
}
});
jvmProperties.setEscapeModelStrings(false);
add(jvmProperties);
initButtons();
}
private void addLabel(String id, String propertyName) {
Label label = new Label(id, new PropertyModel<String>(repoDiagModel, propertyName));
label.setRenderBodyOnly(true);
add(label);
}
private void initButtons() {
AjaxButton testRepository = new AjaxButton(ID_TEST_REPOSITORY,
createStringResource("PageAbout.button.testRepository")) {
@Override
public void onClick(AjaxRequestTarget target) {
testRepositoryPerformed(target);
}
};
add(testRepository);
AjaxButton testRepositoryCheckOrgClosure = new AjaxButton(ID_TEST_REPOSITORY_CHECK_ORG_CLOSURE,
createStringResource("PageAbout.button.testRepositoryCheckOrgClosure")) {
@Override
public void onClick(AjaxRequestTarget target) {
testRepositoryCheckOrgClosurePerformed(target);
}
};
add(testRepositoryCheckOrgClosure);
AjaxButton testProvisioning = new AjaxButton(ID_TEST_PROVISIONING,
createStringResource("PageAbout.button.testProvisioning")) {
@Override
public void onClick(AjaxRequestTarget target) {
testProvisioningPerformed(target);
}
};
add(testProvisioning);
}
private RepositoryDiag loadRepoDiagModel() {
OperationResult result = new OperationResult(OPERATION_GET_REPO_DIAG);
RepositoryDiag diag = null;
try {
Task task = createSimpleTask(OPERATION_GET_REPO_DIAG);
diag = getModelDiagnosticService().getRepositoryDiag(task, result);
result.recordSuccessIfUnknown();
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Couldn't get repo diagnostics", ex);
result.recordFatalError("Couldn't get repo diagnostics.", ex);
}
result.recomputeStatus();
if (!WebMiscUtil.isSuccessOrHandledError(result)) {
showResult(result);
}
return diag;
}
private IModel<List<SystemItem>> getItems() {
return new LoadableModel<List<SystemItem>>(false) {
@Override
protected List<SystemItem> load() {
List<SystemItem> items = new ArrayList<SystemItem>();
for (String property : PROPERTIES) {
items.add(new SystemItem(property, System.getProperty(property)));
}
return items;
}
};
}
private void testRepositoryPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY);
OperationResult result = getModelDiagnosticService().repositorySelfTest(task);
showResult(result);
target.add(getFeedbackPanel());
}
private void testRepositoryCheckOrgClosurePerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY_CHECK_ORG_CLOSURE);
OperationResult result = getModelDiagnosticService().repositoryTestOrgClosureConsistency(task, true);
showResult(result);
target.add(getFeedbackPanel());
}
private void testProvisioningPerformed(AjaxRequestTarget target) {
Task task = createSimpleTask(OPERATION_TEST_REPOSITORY);
OperationResult result = getModelDiagnosticService().provisioningSelfTest(task);
showResult(result);
target.add(getFeedbackPanel());
}
/**
* It's here only because of some IDEs - it's not properly filtering resources during maven build.
* "describe" variable is not replaced.
*
* @return "unknown" instead of "git describe" for current build.
*/
@Deprecated
public String getDescribe() {
return getString("PageAbout.unknownBuildNumber");
}
private static class SystemItem implements Serializable {
private String property;
private String value;
private SystemItem(String property, String value) {
this.property = property;
this.value = value;
}
public String getProperty() {
return property;
}
public String getValue() {
return value;
}
}
}