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;
}
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;
}
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;
}
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);
}
}
}
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);
}
Aggregations