Skip to content

Commit

Permalink
JakartaRS command print readable fail reasons
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
  • Loading branch information
stbischof authored and pkriens committed Sep 4, 2024
1 parent 2de8843 commit 67950f3
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.service.jakartars.runtime.JakartarsServiceRuntime;
import org.osgi.service.jakartars.runtime.dto.ApplicationDTO;
import org.osgi.service.jakartars.runtime.dto.DTOConstants;
import org.osgi.service.jakartars.runtime.dto.ExtensionDTO;
import org.osgi.service.jakartars.runtime.dto.FailedApplicationDTO;
import org.osgi.service.jakartars.runtime.dto.FailedExtensionDTO;
Expand Down Expand Up @@ -48,6 +49,7 @@ void dtos(DTOFormatter formatter) {
.fields("*")
.line()
.fields("*")
.format("failureReason", f -> failedReason(f.failureReason))
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

Expand All @@ -64,6 +66,7 @@ void dtos(DTOFormatter formatter) {
.fields("*")
.line()
.fields("*")
.format("failureReason", f -> failedReason(f.failureReason))
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

Expand All @@ -80,6 +83,7 @@ void dtos(DTOFormatter formatter) {
.fields("*")
.line()
.fields("*")
.format("failureReason", f -> failedReason(f.failureReason))
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

Expand Down Expand Up @@ -143,4 +147,26 @@ private static boolean runtimeHasServiceId(JakartarsServiceRuntime runtime, long
return service_id == runtime.getRuntimeDTO().serviceDTO.id;
}

private String failedReason(int failureReason) {

switch (failureReason) {
case DTOConstants.FAILURE_REASON_UNKNOWN :
return "UNKNOWN";
case DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE :
return "FAILURE_REASON_UNKNOWN";
case DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE :
return "SERVICE_NOT_GETTABLE";
case DTOConstants.FAILURE_REASON_VALIDATION_FAILED :
return "VALIDATION_FAILED";
case DTOConstants.FAILURE_REASON_REQUIRED_EXTENSIONS_UNAVAILABLE :
return "REQUIRED_EXTENSIONS_UNAVAILABLE";
case DTOConstants.FAILURE_REASON_DUPLICATE_NAME :
return "DUPLICATE_NAME";
case DTOConstants.FAILURE_REASON_REQUIRED_APPLICATION_UNAVAILABLE :
return "REQUIRED_APPLICATION_UNAVAILABLE";
default :
return failureReason + "";
}
}

}

0 comments on commit 67950f3

Please sign in to comment.