Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add command helper for JakartaRS #40

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions biz.aQute.gogo.commands.provider/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DynamicImport-Package *
aQute.libg,\
osgi.core,\
org.osgi.service.component,\
org.osgi.service.jakartars,\
org.osgi.service.jaxrs,\
org.osgi.service.http.whiteboard,\
biz.aQute.api.dtos
Expand Down Expand Up @@ -56,4 +57,6 @@ Import-Package: \
org.osgi.service.http.runtime.dto;'resolution:'=optional,\
org.osgi.service.jaxrs.runtime;'resolution:'=optional,\
org.osgi.service.jaxrs.runtime.dto;'resolution:'=optional,\
org.osgi.service.jakartars.runtime;'resolution:'=optional,\
org.osgi.service.jakartars.runtime.dto;'resolution:'=optional,\
*
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void start(BundleContext context) throws Exception {
register(LoggerAdminCommands.class);
register(HTTP.class);
register(JaxRS.class);
register(JakartaRS.class);
}

private void registerConverter(BundleContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package biz.aQute.gogo.commands.provider;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.felix.service.command.Descriptor;
import org.apache.felix.service.command.Parameter;
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.ExtensionDTO;
import org.osgi.service.jakartars.runtime.dto.FailedApplicationDTO;
import org.osgi.service.jakartars.runtime.dto.FailedExtensionDTO;
import org.osgi.service.jakartars.runtime.dto.FailedResourceDTO;
import org.osgi.service.jakartars.runtime.dto.ResourceDTO;
import org.osgi.service.jakartars.runtime.dto.ResourceMethodInfoDTO;
import org.osgi.service.jakartars.runtime.dto.RuntimeDTO;
import org.osgi.util.tracker.ServiceTracker;

import biz.aQute.gogo.commands.dtoformatter.DTOFormatter;

public class JakartaRS {

final ServiceTracker<JakartarsServiceRuntime, JakartarsServiceRuntime> tracker;
final BundleContext context;

public JakartaRS(BundleContext context, DTOFormatter formatter) {
this.context = context;
dtos(formatter);
// dtos(formatter);
tracker = new ServiceTracker<>(context, JakartarsServiceRuntime.class, null);
tracker.open();
}

void dtos(DTOFormatter formatter) {
formatter.build(RuntimeDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] ", dto.serviceDTO.id));

formatter.build(FailedApplicationDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(ApplicationDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(FailedExtensionDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(ExtensionDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(FailedResourceDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(ResourceDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.serviceId, dto.name));

formatter.build(ResourceMethodInfoDTO.class)
.inspect()
.fields("*")
.line()
.fields("*")
.part()
.as(dto -> String.format("[%s] %s", dto.method, dto.path));

}

private List<JakartarsServiceRuntime> serviceRuntimes() {

return Arrays.asList((JakartarsServiceRuntime[]) tracker.getServices());
}

private JakartarsServiceRuntime serviceRuntime() {

return tracker.getService();
}

@Descriptor("Show the RuntimeDTO of the JakartarsServiceRuntime")
public List<org.osgi.service.jakartars.runtime.dto.RuntimeDTO> jakartarsruntimes() throws InterruptedException {

return serviceRuntimes().stream()
.map(JakartarsServiceRuntime::getRuntimeDTO)
.collect(Collectors.toList());
}

@Descriptor("Show the RuntimeDTO of the JakartarsServiceRuntime")
public RuntimeDTO jakartarsruntime(@Descriptor("service.id")
@Parameter(absentValue = "-1", names = "-s")
long service_id) throws InterruptedException {

return runtime(service_id).map(JakartarsServiceRuntime::getRuntimeDTO)
.orElse(null);
}

private Optional<JakartarsServiceRuntime> runtime(long service_id) {

if (service_id < 0) {
return Optional.ofNullable(serviceRuntime());
}
return serviceRuntimes().stream()
.filter(runtime -> runtimeHasServiceId(runtime, service_id))
.findAny();
}

private static boolean runtimeHasServiceId(JakartarsServiceRuntime runtime, long service_id) {

return service_id == runtime.getRuntimeDTO().serviceDTO.id;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private JaxrsServiceRuntime serviceRuntime() {
return tracker.getService();
}

@Descriptor("Show the RuntimeDTO of the HttpServiceRuntime")
@Descriptor("Show the RuntimeDTO of the JaxrsServiceRuntime")
public List<RuntimeDTO> jaxrsruntimes() throws InterruptedException {

return serviceRuntimes().stream()
Expand Down
3 changes: 2 additions & 1 deletion cnf/central.mvn
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ org.osgi:org.osgi.service.coordinator:1.0.2
org.osgi:org.osgi.service.event:1.4.0
org.osgi:org.osgi.service.http.whiteboard:1.1.0
org.osgi:org.osgi.service.http:1.2.1
org.osgi:org.osgi.service.jaxrs:jar:1.0.0
org.osgi:org.osgi.service.jakartars:2.0.0
org.osgi:org.osgi.service.jaxrs:1.0.0
org.osgi:org.osgi.service.jdbc:1.0.0
org.osgi:org.osgi.service.log:1.4.0
org.osgi:org.osgi.service.log:1.3.0
Expand Down
Loading