Skip to content

Commit 66e81c6

Browse files
authored
Merge pull request #25669 from avpinchuk/detach
Fixes processing of the detached admin commands
2 parents 21c6be6 + 2d2eb69 commit 66e81c6

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/resources/TemplateExecCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected final Response executeSseCommand(ParameterMap params) {
136136
.getCommandInvocation(null, commandName, new RestActionReporter(), null, notify, detach).parameters(params);
137137
final ResponseBuilder builder = Response.status(HTTP_OK);
138138
final AsyncAdminCommandInvoker<Response> invoker = detach
139-
? new DetachedSseAdminCommandInvoker(new RestActionReporter(), invocation, builder)
139+
? new DetachedSseAdminCommandInvoker(invocation, builder)
140140
: new SseAdminCommandInvoker(invocation, builder);
141141
return invoker.start();
142142
}

nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/resources/admin/CommandResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ private Response executeSseCommand(CommandName commandName, Payload.Inbound inbo
331331
builder.cookie(getJSessionCookie(jSessionId));
332332
}
333333
final AsyncAdminCommandInvoker<Response> invoker = detach
334-
? new DetachedSseAdminCommandInvoker(new PropsFileActionReporter(), invocation, builder)
334+
? new DetachedSseAdminCommandInvoker(invocation, builder)
335335
: new SseAdminCommandInvoker(invocation, builder);
336336
return invoker.start();
337337
}

nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/DetachedSseAdminCommandInvoker.java

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818

1919
import com.sun.enterprise.v3.admin.AdminCommandJob;
2020
import com.sun.enterprise.v3.admin.AsyncAdminCommandInvoker;
21-
import com.sun.enterprise.v3.common.ActionReporter;
21+
import com.sun.enterprise.v3.common.PropsFileActionReporter;
2222

2323
import jakarta.ws.rs.core.Response;
2424
import jakarta.ws.rs.core.Response.ResponseBuilder;
2525

2626
import java.lang.System.Logger;
2727

2828
import org.glassfish.api.ActionReport;
29-
import org.glassfish.api.ActionReport.ExitCode;
29+
import org.glassfish.api.admin.AdminCommandState;
3030
import org.glassfish.api.admin.CommandInvocation;
31+
import org.glassfish.api.admin.Job;
3132

3233
import static java.lang.System.Logger.Level.TRACE;
3334

@@ -38,12 +39,10 @@
3839
public class DetachedSseAdminCommandInvoker extends AsyncAdminCommandInvoker<Response> {
3940
private static final Logger LOG = System.getLogger(DetachedSseAdminCommandInvoker.class.getName());
4041

41-
private final ActionReporter report;
4242
private final ResponseBuilder builder;
4343

44-
public DetachedSseAdminCommandInvoker(ActionReporter idReport, CommandInvocation<AdminCommandJob> invocation, ResponseBuilder builder) {
44+
public DetachedSseAdminCommandInvoker(CommandInvocation<AdminCommandJob> invocation, ResponseBuilder builder) {
4545
super(invocation);
46-
this.report = idReport;
4746
this.builder = builder;
4847
}
4948

@@ -54,8 +53,6 @@ public DetachedSseAdminCommandInvoker(ActionReporter idReport, CommandInvocation
5453
@Override
5554
public Response start() {
5655
final AdminCommandJob job = getJob();
57-
report.setMessage(job.getId());
58-
report.setActionExitCode(ExitCode.SUCCESS);
5956
final Response response = createResponse(job);
6057
LOG.log(TRACE, "Job parameters: {0}, this: {1}", job.getParameters(), this);
6158
startJob();
@@ -64,10 +61,51 @@ public Response start() {
6461
}
6562

6663
private Response createResponse(AdminCommandJob job) {
67-
try (SseEventOutput eventOutput = new SseEventOutput(job)) {
64+
try (SseEventOutput eventOutput = new SseEventOutput(new DetachedAdminCommandState(job))) {
6865
LOG.log(TRACE, "Writing the job id. {0}", this);
6966
eventOutput.write();
7067
return builder.entity(eventOutput).build();
7168
}
7269
}
70+
71+
private static final class DetachedAdminCommandState implements AdminCommandState {
72+
73+
private final String id;
74+
private final String name;
75+
private final State state;
76+
77+
DetachedAdminCommandState(Job job) {
78+
this.id = job.getId();
79+
this.name = job.getName();
80+
this.state = job.getState();
81+
}
82+
83+
@Override
84+
public String getId() {
85+
return id;
86+
}
87+
88+
@Override
89+
public String getName() {
90+
return name;
91+
}
92+
93+
@Override
94+
public State getState() {
95+
return state;
96+
}
97+
98+
@Override
99+
public ActionReport getActionReport() {
100+
ActionReport actionReport = new PropsFileActionReporter();
101+
actionReport.setActionDescription(name + " command");
102+
actionReport.setActionExitCode(ActionReport.ExitCode.SUCCESS);
103+
return actionReport;
104+
}
105+
106+
@Override
107+
public boolean isOutboundPayloadEmpty() {
108+
return true;
109+
}
110+
}
73111
}

nucleus/admin/rest/rest-service/src/main/java/org/glassfish/admin/rest/utils/SseEventOutput.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.io.IOException;
2222
import java.lang.System.Logger;
2323

24-
import org.glassfish.api.admin.Job;
24+
import org.glassfish.api.admin.AdminCommandState;
2525
import org.glassfish.api.admin.ProgressEvent;
2626
import org.glassfish.jersey.media.sse.EventOutput;
2727
import org.glassfish.jersey.media.sse.OutboundEvent;
@@ -31,15 +31,15 @@
3131
import static org.glassfish.api.admin.AdminCommandState.EVENT_STATE_CHANGED;
3232

3333
/**
34-
* A special {@link EventOutput} for sending Server Side Events related to the {@link Job}.
34+
* A special {@link EventOutput} for sending Server Side Events related to the {@link AdminCommandState}.
3535
*/
3636
public class SseEventOutput extends EventOutput {
3737
private static final Logger LOG = System.getLogger(SseEventOutput.class.getName());
3838

39-
private final Job job;
39+
private final AdminCommandState state;
4040

41-
SseEventOutput(Job job) {
42-
this.job = job;
41+
SseEventOutput(AdminCommandState state) {
42+
this.state = state;
4343
}
4444

4545
void write(String eventName, ProgressEvent event) {
@@ -50,7 +50,7 @@ void write(String eventName, ProgressEvent event) {
5050

5151
void write() {
5252
if (!isClosed()) {
53-
writeJson(EVENT_STATE_CHANGED, job);
53+
writeJson(EVENT_STATE_CHANGED, state);
5454
}
5555
}
5656

0 commit comments

Comments
 (0)