Search in sources :

Example 1 with ServiceEndpoint

use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.

the class ServiceRegistryImpl method unregisterService.

@Override
public ServiceEndpoint unregisterService(String endpointId) {
    ServiceEndpoint serviceEndpoint = serviceEndpoints.remove(endpointId);
    if (serviceEndpoint != null) {
        LOGGER.debug("ServiceEndpoint unregistered: {}", serviceEndpoint);
        List<ServiceReference> serviceReferencesOfEndpoint = serviceReferencesByQualifier.values().stream().flatMap(Collection::stream).filter(sr -> sr.endpointId().equals(endpointId)).collect(Collectors.toList());
        serviceReferencesOfEndpoint.forEach(sr -> {
            computeServiceReferences(sr.qualifier(), sr);
            computeServiceReferences(sr.oldQualifier(), sr);
        });
    }
    return serviceEndpoint;
}
Also used : ServiceReference(io.scalecube.services.ServiceReference) Logger(org.slf4j.Logger) ServiceRegistry(io.scalecube.services.registry.api.ServiceRegistry) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) NonBlockingHashMap(org.jctools.maps.NonBlockingHashMap) List(java.util.List) Map(java.util.Map) ServiceMessage(io.scalecube.services.api.ServiceMessage) Collections(java.util.Collections) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Collection(java.util.Collection) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) ServiceReference(io.scalecube.services.ServiceReference)

Example 2 with ServiceEndpoint

use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.

the class ScalecubeServiceDiscoveryTest method testMetadataCodec.

@ParameterizedTest
@MethodSource("metadataCodecSource")
public void testMetadataCodec(MetadataCodec metadataCodec) {
    ServiceEndpoint serviceEndpoint = ServiceEndpoint.builder().id(UUID.randomUUID().toString()).tags(Collections.singletonMap("K", "V")).contentTypes(Collections.singleton("json")).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action0", Collections.singletonMap("KKK0", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action1", Collections.singletonMap("KKK1", "VVV"), true))))).appendServiceRegistrations(Collections.singletonList(new ServiceRegistration("namespace", Collections.singletonMap("KK", "VV"), Collections.singletonList(new ServiceMethodDefinition("action2", Collections.singletonMap("KKK2", "VVV"), true))))).build();
    ByteBuffer buffer = metadataCodec.serialize(serviceEndpoint);
    ServiceEndpoint serviceEndpoint1 = (ServiceEndpoint) metadataCodec.deserialize(buffer);
    Assertions.assertEquals(serviceEndpoint.id(), serviceEndpoint1.id());
    Assertions.assertEquals(1, serviceEndpoint1.tags().size());
    Assertions.assertEquals(1, serviceEndpoint1.contentTypes().size());
    List<ServiceRegistration> serviceRegistrations = new ArrayList<>(serviceEndpoint1.serviceRegistrations());
    Assertions.assertEquals(3, serviceRegistrations.size());
    for (ServiceRegistration serviceRegistration : serviceRegistrations) {
        Assertions.assertEquals(1, serviceRegistration.methods().size());
        Assertions.assertEquals(1, serviceRegistration.tags().size());
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceMethodDefinition(io.scalecube.services.ServiceMethodDefinition) ByteBuffer(java.nio.ByteBuffer) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) ServiceRegistration(io.scalecube.services.ServiceRegistration) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with ServiceEndpoint

use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.

the class CompositeProfileAuthExample method main.

/**
 * Main program.
 *
 * @param args arguments
 */
public static void main(String[] args) {
    Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(call -> Collections.singletonList(ServiceInfo.fromServiceInstance(new SecuredServiceByCompositeProfileImpl()).authenticator(compositeAuthenticator()).build())).startAwait();
    Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
    ServiceMessage response = caller.call().requestOne(ServiceMessage.builder().qualifier("securedServiceByCompositeProfile/hello").header("userProfile.name", "SEGA").header("userProfile.role", "ADMIN").data("hello world").build(), String.class).block(Duration.ofSeconds(3));
    System.err.println("### Received 'caller' response: " + response.data());
}
Also used : ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceInfo(io.scalecube.services.ServiceInfo) Mono(reactor.core.publisher.Mono) Authenticator(io.scalecube.services.auth.Authenticator) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) Collections(java.util.Collections) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) MonoAuthUtil.deferWithPrincipal(io.scalecube.services.auth.MonoAuthUtil.deferWithPrincipal) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceMessage(io.scalecube.services.api.ServiceMessage) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 4 with ServiceEndpoint

use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.

the class ServiceTransportAuthExample method main.

/**
 * Main program.
 *
 * @param args arguments
 */
public static void main(String[] args) {
    Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(new SecuredServiceByUserProfileImpl()).startAwait();
    Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
    String response = caller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
    System.err.println("### Received 'caller' response: " + response);
}
Also used : ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) Authenticator(io.scalecube.services.auth.Authenticator) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 5 with ServiceEndpoint

use of io.scalecube.services.ServiceEndpoint in project scalecube by scalecube.

the class PrincipalMapperAuthExample method main.

/**
 * Main program.
 *
 * @param args arguments
 */
public static void main(String[] args) {
    Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(ServiceInfo.fromServiceInstance(new SecuredServiceByApiKeyImpl()).principalMapper(PrincipalMapperAuthExample::apiKeyPrincipalMapper).build()).services(ServiceInfo.fromServiceInstance(new SecuredServiceByUserProfileImpl()).principalMapper(PrincipalMapperAuthExample::userProfilePrincipalMapper).build()).startAwait();
    Microservices userProfileCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
    String responseByUserProfile = userProfileCaller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
    System.err.println("### Received 'userProfileCaller' response: " + responseByUserProfile);
    Microservices apiKeyCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
    String responseByApiKey = apiKeyCaller.call().api(SecuredServiceByApiKey.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
    System.err.println("### Received 'apiKeyCaller' response: " + responseByApiKey);
}
Also used : ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceInfo(io.scalecube.services.ServiceInfo) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Authenticator(io.scalecube.services.auth.Authenticator) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) Map(java.util.Map) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Aggregations

ServiceEndpoint (io.scalecube.services.ServiceEndpoint)5 Microservices (io.scalecube.services.Microservices)3 Authenticator (io.scalecube.services.auth.Authenticator)3 CredentialsSupplier (io.scalecube.services.auth.CredentialsSupplier)3 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)3 UnauthorizedException (io.scalecube.services.exceptions.UnauthorizedException)3 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)3 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)3 Duration (java.time.Duration)3 Mono (reactor.core.publisher.Mono)3 ServiceInfo (io.scalecube.services.ServiceInfo)2 ServiceMessage (io.scalecube.services.api.ServiceMessage)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 UUID (java.util.UUID)2 ServiceMethodDefinition (io.scalecube.services.ServiceMethodDefinition)1 ServiceReference (io.scalecube.services.ServiceReference)1 ServiceRegistration (io.scalecube.services.ServiceRegistration)1