/
ListBatchRuntimeConfiguration.java
117 lines (100 loc) · 4.33 KB
/
ListBatchRuntimeConfiguration.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
/*
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.batch;
import com.sun.enterprise.config.serverbeans.Config;
import com.sun.enterprise.config.serverbeans.Domain;
import com.sun.enterprise.util.ColumnFormatter;
import org.glassfish.api.ActionReport;
import org.glassfish.api.I18n;
import org.glassfish.api.admin.*;
import org.glassfish.batch.spi.impl.BatchRuntimeConfiguration;
import org.glassfish.batch.spi.impl.BatchRuntimeHelper;
import org.glassfish.config.support.CommandTarget;
import org.glassfish.config.support.TargetType;
import org.glassfish.hk2.api.PerLookup;
import org.glassfish.internal.api.Target;
import org.jvnet.hk2.annotations.Service;
import jakarta.inject.Inject;
import java.util.*;
/**
* Command to list batch jobs info
*
* @author Mahesh Kannan
*
*/
@Service(name="list-batch-runtime-configuration")
@PerLookup
@CommandLock(CommandLock.LockType.NONE)
@I18n("list.batch.runtime.configuration")
@ExecuteOn(value = {RuntimeType.DAS})
@TargetType(value = {CommandTarget.DAS, CommandTarget.STANDALONE_INSTANCE, CommandTarget.CLUSTER})
@RestEndpoints({
@RestEndpoint(configBean = Domain.class,
opType = RestEndpoint.OpType.GET,
path = "list-batch-runtime-configuration",
description = "List Batch Runtime Configuration")
})
public class ListBatchRuntimeConfiguration
extends AbstractListCommand {
private static final String DATA_SOURCE_NAME = "dataSourceLookupName";
private static final String EXECUTOR_SERVICE_NAME = "executorServiceLookupName";
@Inject
protected Target targetUtil;
@Inject
BatchRuntimeHelper helper;
@Override
protected void executeCommand(AdminCommandContext context, Properties extraProps) {
Config config = targetUtil.getConfig(target);
if (config == null) {
context.getActionReport().setMessage("No such config named: " + target);
context.getActionReport().setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
BatchRuntimeConfiguration batchRuntimeConfiguration = config.getExtensionByType(BatchRuntimeConfiguration.class);
Map<String, Object> map = new HashMap<>();
map.put(DATA_SOURCE_NAME, batchRuntimeConfiguration.getDataSourceLookupName());
map.put(EXECUTOR_SERVICE_NAME, batchRuntimeConfiguration.getExecutorServiceLookupName());
extraProps.put("listBatchRuntimeConfiguration", map);
ColumnFormatter columnFormatter = new ColumnFormatter(getDisplayHeaders());
Object[] data = new Object[getOutputHeaders().length];
for (int index=0; index<getOutputHeaders().length; index++) {
switch (getOutputHeaders()[index]) {
case DATA_SOURCE_NAME:
String val = batchRuntimeConfiguration.getDataSourceLookupName();
data[index] = (val == null || val.trim().length() == 0)
? BatchRuntimeHelper.getDefaultDataSourceLookupNameForTarget(target) : val;
break;
case EXECUTOR_SERVICE_NAME:
data[index] = batchRuntimeConfiguration.getExecutorServiceLookupName();
break;
default:
throw new IllegalArgumentException("Unknown header: " + getOutputHeaders()[index]);
}
}
columnFormatter.addRow(data);
context.getActionReport().setMessage(columnFormatter.toString());
}
@Override
protected final String[] getAllHeaders() {
return new String[] {
DATA_SOURCE_NAME, EXECUTOR_SERVICE_NAME
};
}
@Override
protected final String[] getDefaultHeaders() {
return getAllHeaders();
}
}