Search in sources :

Example 1 with WebSocketTopic

use of org.yamcs.api.WebSocketTopic in project yamcs by yamcs.

the class HttpServer method addApi.

public void addApi(Api<Context> api) {
    apis.add(api);
    for (MethodDescriptor method : api.getDescriptorForType().getMethods()) {
        RpcDescriptor descriptor = protobufRegistry.getRpc(method.getFullName());
        if (descriptor == null) {
            throw new UnsupportedOperationException("Unable to find rpc definition: " + method.getFullName());
        }
        if (WEBSOCKET_ROUTE.equals(descriptor.getHttpRoute())) {
            topics.add(new Topic(api, descriptor.getWebSocketTopic(), descriptor));
            for (WebSocketTopic topic : descriptor.getAdditionalWebSocketTopics()) {
                topics.add(new Topic(api, topic, descriptor));
            }
        } else {
            routes.add(new Route(api, descriptor.getHttpRoute(), descriptor, metricRegistry));
            for (HttpRoute route : descriptor.getAdditionalHttpRoutes()) {
                routes.add(new Route(api, route, descriptor, metricRegistry));
            }
        }
    }
    // Regenerate JSON converters with type support (needed for the "Any" type)
    TypeRegistry.Builder typeRegistryb = TypeRegistry.newBuilder();
    typeRegistryb.add(CancelOptions.getDescriptor());
    typeRegistryb.add(Reply.getDescriptor());
    apis.forEach(a -> typeRegistryb.add(a.getDescriptorForType().getFile().getMessageTypes()));
    TypeRegistry typeRegistry = typeRegistryb.build();
    jsonParser = JsonFormat.parser().usingTypeRegistry(typeRegistry);
    jsonPrinter = JsonFormat.printer().usingTypeRegistry(typeRegistry);
    // Sort in a way that increases chances of a good URI match
    Collections.sort(routes);
}
Also used : HttpRoute(org.yamcs.api.HttpRoute) WebSocketTopic(org.yamcs.api.WebSocketTopic) WebSocketTopic(org.yamcs.api.WebSocketTopic) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) TypeRegistry(com.google.protobuf.util.JsonFormat.TypeRegistry) HttpRoute(org.yamcs.api.HttpRoute)

Example 2 with WebSocketTopic

use of org.yamcs.api.WebSocketTopic in project yamcs by yamcs.

the class ProtobufRegistry method importDefinitions.

public void importDefinitions(InputStream in) throws IOException {
    if (in == null) {
        throw new NullPointerException("input stream cannot be null");
    }
    FileDescriptorSet proto = FileDescriptorSet.parseFrom(in, extensionRegistry);
    // Index all messages by fully-qualified protobuf name
    for (FileDescriptorProto file : proto.getFileList()) {
        scanComments(file);
        String javaPackage = file.getOptions().getJavaPackage();
        javaPackages.put(file.getName(), javaPackage);
        for (DescriptorProto messageType : file.getMessageTypeList()) {
            String qname = file.getPackage() + "." + messageType.getName();
            messageTypes.put(qname, messageType);
        }
    }
    // Index RPCs
    for (FileDescriptorProto file : proto.getFileList()) {
        for (ServiceDescriptorProto service : file.getServiceList()) {
            for (MethodDescriptorProto method : service.getMethodList()) {
                MethodOptions options = method.getOptions();
                String serviceName = service.getName();
                String methodName = method.getName();
                DescriptorProto inputType = messageTypes.get(method.getInputType().substring(1));
                DescriptorProto outputType = messageTypes.get(method.getOutputType().substring(1));
                if (options.hasExtension(AnnotationsProto.route)) {
                    HttpRoute route = options.getExtension(AnnotationsProto.route);
                    RpcDescriptor descriptor = new RpcDescriptor(serviceName, methodName, inputType, outputType, route);
                    String qname = String.join(".", file.getPackage(), serviceName, methodName);
                    rpcs.put(qname, descriptor);
                } else if (options.hasExtension(AnnotationsProto.websocket)) {
                    WebSocketTopic topic = options.getExtension(AnnotationsProto.websocket);
                    RpcDescriptor descriptor = new RpcDescriptor(serviceName, methodName, inputType, outputType, topic);
                    String qname = String.join(".", file.getPackage(), serviceName, methodName);
                    rpcs.put(qname, descriptor);
                }
            }
        }
    }
}
Also used : HttpRoute(org.yamcs.api.HttpRoute) FileDescriptorSet(com.google.protobuf.DescriptorProtos.FileDescriptorSet) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) WebSocketTopic(org.yamcs.api.WebSocketTopic) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) DescriptorProto(com.google.protobuf.DescriptorProtos.DescriptorProto) MethodOptions(com.google.protobuf.DescriptorProtos.MethodOptions) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto)

Aggregations

HttpRoute (org.yamcs.api.HttpRoute)2 WebSocketTopic (org.yamcs.api.WebSocketTopic)2 DescriptorProto (com.google.protobuf.DescriptorProtos.DescriptorProto)1 FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)1 FileDescriptorSet (com.google.protobuf.DescriptorProtos.FileDescriptorSet)1 MethodDescriptorProto (com.google.protobuf.DescriptorProtos.MethodDescriptorProto)1 MethodOptions (com.google.protobuf.DescriptorProtos.MethodOptions)1 ServiceDescriptorProto (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto)1 MethodDescriptor (com.google.protobuf.Descriptors.MethodDescriptor)1 TypeRegistry (com.google.protobuf.util.JsonFormat.TypeRegistry)1