Search in sources :

Example 11 with Service

use of org.apache.knox.gateway.services.Service in project knox by apache.

the class RemoteRegistryClientServiceFactory method createService.

@Override
protected Service createService(GatewayServices gatewayServices, ServiceType serviceType, GatewayConfig gatewayConfig, Map<String, String> options, String implementation) throws ServiceLifecycleException {
    Service service = null;
    if (shouldCreateService(implementation)) {
        service = RemoteConfigurationRegistryClientServiceFactory.newInstance(gatewayConfig);
        // it should be the 'default' alias service
        final AliasService localAliasService = (AliasService) aliasServiceFactory.create(gatewayServices, ServiceType.ALIAS_SERVICE, gatewayConfig, options, "");
        localAliasService.init(gatewayConfig, options);
        ((RemoteConfigurationRegistryClientService) service).setAliasService(localAliasService);
    }
    return service;
}
Also used : AliasService(org.apache.knox.gateway.services.security.AliasService) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) ZooKeeperClientService(org.apache.knox.gateway.service.config.remote.zk.ZooKeeperClientService) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) AliasService(org.apache.knox.gateway.services.security.AliasService) Service(org.apache.knox.gateway.services.Service)

Example 12 with Service

use of org.apache.knox.gateway.services.Service in project knox by apache.

the class TopologyServiceFactory method createService.

@Override
protected Service createService(GatewayServices gatewayServices, ServiceType serviceType, GatewayConfig gatewayConfig, Map<String, String> options, String implementation) throws ServiceLifecycleException {
    Service service = null;
    if (shouldCreateService(implementation)) {
        service = new DefaultTopologyService();
        ((DefaultTopologyService) service).setAliasService(getAliasService(gatewayServices));
    }
    return service;
}
Also used : DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService) Service(org.apache.knox.gateway.services.Service) DefaultTopologyService(org.apache.knox.gateway.services.topology.impl.DefaultTopologyService)

Example 13 with Service

use of org.apache.knox.gateway.services.Service in project knox by apache.

the class TokenStateServiceFactory method createService.

@Override
protected Service createService(GatewayServices gatewayServices, ServiceType serviceType, GatewayConfig gatewayConfig, Map<String, String> options, String implementation) throws ServiceLifecycleException {
    Service service = null;
    if (shouldCreateService(implementation)) {
        if (matchesImplementation(implementation, DefaultTokenStateService.class)) {
            service = new DefaultTokenStateService();
        } else if (matchesImplementation(implementation, AliasBasedTokenStateService.class, true)) {
            service = new AliasBasedTokenStateService();
            ((AliasBasedTokenStateService) service).setAliasService(getAliasService(gatewayServices));
        } else if (matchesImplementation(implementation, JournalBasedTokenStateService.class)) {
            service = new JournalBasedTokenStateService();
        } else if (matchesImplementation(implementation, ZookeeperTokenStateService.class)) {
            service = new ZookeeperTokenStateService(gatewayServices);
        } else if (matchesImplementation(implementation, JDBCTokenStateService.class)) {
            try {
                service = new JDBCTokenStateService();
                ((JDBCTokenStateService) service).setAliasService(getAliasService(gatewayServices));
                service.init(gatewayConfig, options);
            } catch (ServiceLifecycleException e) {
                LOG.errorInitializingService(implementation, e.getMessage(), e);
                service = new AliasBasedTokenStateService();
                ((AliasBasedTokenStateService) service).setAliasService(getAliasService(gatewayServices));
            }
        }
        logServiceUsage(isEmptyDefaultImplementation(implementation) ? AliasBasedTokenStateService.class.getName() : implementation, serviceType);
    }
    return service;
}
Also used : DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) JDBCTokenStateService(org.apache.knox.gateway.services.token.impl.JDBCTokenStateService) DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) ZookeeperTokenStateService(org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService) JournalBasedTokenStateService(org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService) Service(org.apache.knox.gateway.services.Service) JDBCTokenStateService(org.apache.knox.gateway.services.token.impl.JDBCTokenStateService) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) JournalBasedTokenStateService(org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService) ZookeeperTokenStateService(org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService)

Example 14 with Service

use of org.apache.knox.gateway.services.Service in project knox by apache.

the class ServiceDiscoveryFactory method injectGatewayServices.

private static void injectGatewayServices(final ServiceDiscovery serviceDiscovery, Service... gatewayServices) {
    if (serviceDiscovery != null && ArrayUtils.isNotEmpty(gatewayServices)) {
        try {
            for (Field field : serviceDiscovery.getClass().getDeclaredFields()) {
                if (field.getDeclaredAnnotation(GatewayService.class) != null) {
                    for (Service gatewayService : gatewayServices) {
                        if (gatewayService != null && field.getType().isAssignableFrom(gatewayService.getClass())) {
                            field.setAccessible(true);
                            field.set(serviceDiscovery, gatewayService);
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Error while injecting Gateway Services in service discoveries", e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Service(org.apache.knox.gateway.services.Service)

Example 15 with Service

use of org.apache.knox.gateway.services.Service in project knox by apache.

the class SimpleDescriptorHandler method performDiscovery.

private static ServiceDiscovery.Cluster performDiscovery(GatewayConfig config, SimpleDescriptor desc, Service... gatewayServices) {
    DefaultServiceDiscoveryConfig sdc = new DefaultServiceDiscoveryConfig(desc.getDiscoveryAddress());
    sdc.setCluster(desc.getCluster());
    sdc.setUser(desc.getDiscoveryUser());
    sdc.setPasswordAlias(desc.getDiscoveryPasswordAlias());
    // Use the discovery type from the descriptor. If it's unspecified, employ the default type.
    String discoveryType = desc.getDiscoveryType();
    if (discoveryType == null) {
        discoveryType = DEFAULT_DISCOVERY_TYPE;
    }
    // Use the cached discovery object for the required type, if it has already been loaded
    ServiceDiscovery sd = discoveryInstances.get(discoveryType);
    if (sd == null) {
        sd = ServiceDiscoveryFactory.get(discoveryType, config, gatewayServices);
        if (sd == null) {
            throw new IllegalArgumentException("Unsupported service discovery type: " + discoveryType);
        }
        discoveryInstances.put(discoveryType, sd);
    }
    final Collection<String> includedServices = desc.getServices().stream().map(service -> service.getName()).collect(Collectors.toSet());
    return sd.discover(config, sdc, desc.getCluster(), includedServices);
}
Also used : ServiceType(org.apache.knox.gateway.services.ServiceType) GatewayServices(org.apache.knox.gateway.services.GatewayServices) AliasService(org.apache.knox.gateway.services.security.AliasService) DefaultServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.DefaultServiceDiscoveryConfig) MessagesFactory(org.apache.knox.gateway.i18n.messages.MessagesFactory) URISyntaxException(java.net.URISyntaxException) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) HashMap(java.util.HashMap) ServiceDiscoveryFactory(org.apache.knox.gateway.topology.discovery.ServiceDiscoveryFactory) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) Locale(java.util.Locale) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) Topology(org.apache.knox.gateway.topology.Topology) URI(java.net.URI) OutputStream(java.io.OutputStream) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) Collection(java.util.Collection) Set(java.util.Set) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery) IOException(java.io.IOException) MasterService(org.apache.knox.gateway.services.security.MasterService) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Stream(java.util.stream.Stream) KeystoreService(org.apache.knox.gateway.services.security.KeystoreService) Entry(java.util.Map.Entry) TopologyService(org.apache.knox.gateway.services.topology.TopologyService) Service(org.apache.knox.gateway.services.Service) Collections(java.util.Collections) InputStream(java.io.InputStream) DefaultServiceDiscoveryConfig(org.apache.knox.gateway.topology.discovery.DefaultServiceDiscoveryConfig) ServiceDiscovery(org.apache.knox.gateway.topology.discovery.ServiceDiscovery)

Aggregations

Service (org.apache.knox.gateway.services.Service)15 AliasService (org.apache.knox.gateway.services.security.AliasService)5 KeystoreService (org.apache.knox.gateway.services.security.KeystoreService)3 MasterService (org.apache.knox.gateway.services.security.MasterService)3 Field (java.lang.reflect.Field)2 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)2 RemoteConfigurationRegistryClientService (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService)2 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 ArrayList (java.util.ArrayList)1