Search in sources :

Example 1 with RemoteConfigurationRegistryClient

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"));
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) Configuration(org.apache.hadoop.conf.Configuration) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) GatewayConfigImpl(org.apache.knox.gateway.config.impl.GatewayConfigImpl) Test(org.junit.Test)

Example 2 with RemoteConfigurationRegistryClient

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);
        }
    }
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient)

Example 3 with RemoteConfigurationRegistryClient

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
        }
    };
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) Files(java.nio.file.Files) AliasService(org.apache.knox.gateway.services.security.AliasService) GatewayConfig(org.apache.knox.gateway.config.GatewayConfig) Set(java.util.Set) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) HashMap(java.util.HashMap) Function(java.util.function.Function) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) Paths(java.nio.file.Paths) RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryClientService(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService) Map(java.util.Map) ServiceLifecycleException(org.apache.knox.gateway.services.ServiceLifecycleException) Path(java.nio.file.Path) Collections(java.util.Collections) RemoteConfigurationRegistriesAccessor(org.apache.knox.gateway.service.config.remote.config.RemoteConfigurationRegistriesAccessor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 4 with RemoteConfigurationRegistryClient

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;
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient)

Example 5 with RemoteConfigurationRegistryClient

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);
        }
    }
}
Also used : RemoteConfigurationRegistryClient(org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient) RemoteConfigurationRegistryConfig(org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryConfig) ArrayList(java.util.ArrayList)

Aggregations

RemoteConfigurationRegistryClient (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient)9 ArrayList (java.util.ArrayList)3 RemoteConfigurationRegistryClientService (org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService)3 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)2 Test (org.junit.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 PosixFilePermission (java.nio.file.attribute.PosixFilePermission)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 FileUtils (org.apache.commons.io.FileUtils)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1