use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient in project knox by apache.
the class KnoxCLITest method testRemoteConfigurationRegistryClientService.
@Test
public void testRemoteConfigurationRegistryClientService() throws Exception {
outContent.reset();
KnoxCLI cli = new KnoxCLI();
Configuration config = new GatewayConfigImpl();
// Configure a client for the test local filesystem registry implementation
config.set("gateway.remote.config.registry.test_client", "type=LocalFileSystem;address=/test");
cli.setConf(config);
// This is only to get the gateway services initialized
cli.run(new String[] { "version" });
RemoteConfigurationRegistryClientService service = cli.getGatewayServices().getService(GatewayServices.REMOTE_REGISTRY_CLIENT_SERVICE);
assertNotNull(service);
RemoteConfigurationRegistryClient client = service.get("test_client");
assertNotNull(client);
assertNull(service.get("bogus"));
}
use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient in project knox by apache.
the class LocalFileSystemRemoteConfigurationRegistryClientService method init.
@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
List<RemoteConfigurationRegistryConfig> registryConfigurations = RemoteConfigurationRegistriesAccessor.getRemoteRegistryConfigurations(config);
for (RemoteConfigurationRegistryConfig registryConfig : registryConfigurations) {
if (TYPE.equalsIgnoreCase(registryConfig.getRegistryType())) {
RemoteConfigurationRegistryClient registryClient = createClient(registryConfig);
clients.put(registryConfig.getName(), registryClient);
}
}
}
use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient in project knox by apache.
the class LocalFileSystemRemoteConfigurationRegistryClientService method createClient.
private RemoteConfigurationRegistryClient createClient(RemoteConfigurationRegistryConfig config) {
String rootDir = config.getConnectionString();
return new RemoteConfigurationRegistryClient() {
private File root = new File(rootDir);
@Override
public String getAddress() {
return root.getAbsolutePath();
}
@Override
public boolean entryExists(String path) {
return (new File(root, path)).exists();
}
@Override
public List<EntryACL> getACL(String path) {
List<EntryACL> result = new ArrayList<>();
Path resolved = Paths.get(rootDir, path);
try {
Map<String, List<String>> collected = new HashMap<>();
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(resolved);
for (PosixFilePermission perm : perms) {
String[] parsed = perm.toString().split("_");
collected.computeIfAbsent(parsed[0].toLowerCase(), s -> new ArrayList<>()).add(parsed[1].toLowerCase());
}
for (String id : collected.keySet()) {
EntryACL acl = new EntryACL() {
@Override
public String getId() {
return id;
}
@Override
public String getType() {
return "fs";
}
@Override
public Object getPermissions() {
return collected.get(id).toString();
}
@Override
public boolean canRead() {
return true;
}
@Override
public boolean canWrite() {
return true;
}
};
result.add(acl);
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
public List<String> listChildEntries(String path) {
List<String> result = new ArrayList<>();
File entry = new File(root, path);
if (entry.exists() && entry.isDirectory()) {
String[] list = entry.list();
if (list != null) {
result.addAll(Arrays.asList(entry.list()));
}
}
return result;
}
@Override
public String getEntryData(String path) {
return getEntryData(path, "UTF-8");
}
@Override
public String getEntryData(String path, String encoding) {
String result = null;
File entry = new File(root, path);
if (entry.isFile() && entry.exists()) {
try {
result = FileUtils.readFileToString(entry, encoding);
} catch (IOException e) {
e.printStackTrace();
}
}
return result;
}
@Override
public void createEntry(String path) {
createEntry(path, "");
}
@Override
public void createEntry(String path, String data) {
createEntry(path, data, "UTF-8");
}
@Override
public void createEntry(String path, String data, String encoding) {
File entry = new File(root, path);
if (!entry.exists()) {
if (data != null) {
try {
FileUtils.writeStringToFile(entry, data, encoding);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
public int setEntryData(String path, String data) {
setEntryData(path, data, "UTF-8");
return 0;
}
@Override
public int setEntryData(String path, String data, String encoding) {
File entry = new File(root, path);
if (entry.exists()) {
try {
FileUtils.writeStringToFile(entry, data, encoding);
} catch (IOException e) {
e.printStackTrace();
}
}
return 0;
}
@Override
public boolean isAuthenticationConfigured() {
return false;
}
@Override
public void setACL(String path, List<EntryACL> acls) {
//
}
@Override
public void deleteEntry(String path) {
File entry = new File(root, path);
if (entry.exists()) {
entry.delete();
}
}
@Override
public void addChildEntryListener(String path, ChildEntryListener listener) throws Exception {
// N/A
}
@Override
public void addEntryListener(String path, EntryListener listener) throws Exception {
// N/A
}
@Override
public void removeEntryListener(String path) throws Exception {
// N/A
}
};
}
use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient in project knox by apache.
the class DefaultTopologyService method deployDescriptor.
@Override
public boolean deployDescriptor(String name, String content) {
boolean result;
// Whether the remote configuration registry is being employed or not, write the file locally
result = writeConfig(descriptorsDirectory, name, content);
// If the remote configuration registry is being employed, persist it there also
if (remoteMonitor != null) {
RemoteConfigurationRegistryClient client = remoteMonitor.getClient();
if (client != null) {
String entryPath = "/knox/config/descriptors/" + name;
client.createEntry(entryPath, content);
result = (client.getEntryData(entryPath) != null);
}
}
return result;
}
use of org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient in project knox by apache.
the class CuratorClientService method init.
@Override
public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
// Load the remote registry configurations
registryConfigs.addAll(RemoteConfigurationRegistriesAccessor.getRemoteRegistryConfigurations(config));
// Configure registry authentication
RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);
if (registryConfigs.size() > 1) {
// Warn about current limit on number of supported client configurations
log.multipleRemoteRegistryConfigurations();
}
// Create the clients
for (RemoteConfigurationRegistryConfig registryConfig : registryConfigs) {
if (TYPE.equalsIgnoreCase(registryConfig.getRegistryType())) {
RemoteConfigurationRegistryClient registryClient = createClient(registryConfig);
clients.put(registryConfig.getName(), registryClient);
}
}
}
Aggregations