1111import picocli .CommandLine .Option ;
1212
1313import static emissary .server .api .HealthCheckAction .HEALTH ;
14+ import static emissary .server .api .Refresh .INVALIDATE ;
15+ import static emissary .server .api .Refresh .REFRESH ;
1416import static emissary .server .api .Shutdown .SHUTDOWN ;
1517
1618/**
@@ -24,13 +26,21 @@ public abstract class ServiceCommand extends HttpCommand {
2426 public static final String SERVICE_HEALTH_ENDPOINT = "/api/" + HEALTH ;
2527 public static final String SERVICE_SHUTDOWN_ENDPOINT = "/api/" + SHUTDOWN ;
2628 public static final String SERVICE_KILL_ENDPOINT = SERVICE_SHUTDOWN_ENDPOINT + "/force" ;
29+ public static final String SERVICE_INVALIDATE_ENDPOINT = "/api/" + INVALIDATE ;
30+ public static final String SERVICE_REFRESH_ENDPOINT = "/api/" + REFRESH ;
2731
2832 @ Option (names = {"--csrf" }, description = "disable csrf protection\n Default: ${DEFAULT-VALUE}" , arity = "1" )
2933 private boolean csrf = true ;
3034
3135 @ Option (names = {"--stop" }, description = "Shutdown the service\n Default: ${DEFAULT-VALUE}" )
3236 private boolean stop = false ;
3337
38+ @ Option (names = {"--invalidate" }, description = "Invalidate services that are refreshable\n Default: ${DEFAULT-VALUE}" )
39+ private boolean invalidate = false ;
40+
41+ @ Option (names = {"--refresh" }, description = "Force refresh of services\n Default: ${DEFAULT-VALUE}" )
42+ private boolean refresh = false ;
43+
3444 @ Option (names = {"--kill" }, description = "Force the shutdown of the service\n Default: ${DEFAULT-VALUE}" )
3545 private boolean kill = false ;
3646
@@ -48,6 +58,14 @@ public boolean isStop() {
4858 return stop ;
4959 }
5060
61+ public boolean isInvalidate () {
62+ return invalidate ;
63+ }
64+
65+ public boolean isRefresh () {
66+ return invalidate || refresh ;
67+ }
68+
5169 public boolean isKill () {
5270 return kill ;
5371 }
@@ -68,6 +86,10 @@ public String getServiceShutdownEndpoint() {
6886 return isKill () ? SERVICE_KILL_ENDPOINT : SERVICE_SHUTDOWN_ENDPOINT ;
6987 }
7088
89+ public String getServiceRefreshEndpoint () {
90+ return refresh ? SERVICE_REFRESH_ENDPOINT : SERVICE_INVALIDATE_ENDPOINT ;
91+ }
92+
7193 public String getServiceName () {
7294 return getCommandName ();
7395 }
@@ -109,6 +131,8 @@ public void run(CommandLine c) {
109131 pauseService ();
110132 } else if (isUnpause ()) {
111133 unpauseService ();
134+ } else if (isRefresh ()) {
135+ refreshService ();
112136 } else {
113137 throw new EmissaryRuntimeException ("Emissary " + getServiceName () + " is already running" );
114138 }
@@ -151,4 +175,11 @@ protected void unpauseService() {
151175 throw new UnsupportedOperationException ("Unpause not implemented for " + getServiceName ());
152176 }
153177
178+ /**
179+ * A method that refreshes services
180+ */
181+ protected void refreshService () {
182+ throw new UnsupportedOperationException ("Refresh not implemented for " + getServiceName ());
183+ }
184+
154185}
0 commit comments