Search in sources :

Example 1 with ContainerResource

use of org.infinispan.cli.resources.ContainerResource in project infinispan by infinispan.

the class RestConnection method refreshServerInfo.

@Override
public void refreshServerInfo() throws IOException {
    try {
        ContainerResource container = getActiveContainer();
        String containerName = container.getName();
        Map cacheManagerInfo = parseBody(fetch(() -> client.cacheManager(containerName).info()), Map.class);
        List<Map<String, Object>> definedCaches = (List<Map<String, Object>>) cacheManagerInfo.get("defined_caches");
        availableCaches = new ArrayList<>();
        definedCaches.forEach(m -> availableCaches.add((String) m.get("name")));
        availableCaches.remove(PROTOBUF_METADATA_CACHE_NAME);
        List configurationList = parseBody(fetch(() -> client.cacheManager(containerName).cacheConfigurations()), List.class);
        availableConfigurations = new ArrayList<>(configurationList.size());
        for (Object item : configurationList) {
            availableConfigurations.add(((Map<String, String>) item).get("name"));
        }
        String nodeAddress = (String) cacheManagerInfo.get("node_address");
        String clusterName = (String) cacheManagerInfo.get("cluster_name");
        localSite = (String) cacheManagerInfo.get("local_site");
        sitesView = new ArrayList<>((Collection<String>) cacheManagerInfo.get("sites_view"));
        Collections.sort(sitesView);
        relayNode = cacheManagerInfo.containsKey("relay_node") ? (boolean) cacheManagerInfo.get("relay_node") : false;
        relayNodes = (List<String>) cacheManagerInfo.get("relay_nodes_address");
        clusterMembers = (Collection<String>) cacheManagerInfo.get("cluster_members");
        if (nodeAddress != null) {
            serverInfo = nodeAddress + "@" + clusterName;
        } else {
            ServerConfiguration serverConfiguration = client.getConfiguration().servers().get(0);
            serverInfo = serverConfiguration.host() + ":" + serverConfiguration.port();
        }
    } catch (IllegalStateException e) {
    // Cannot refresh if there is no container selected
    }
}
Also used : ContainerResource(org.infinispan.cli.resources.ContainerResource) ServerConfiguration(org.infinispan.client.rest.configuration.ServerConfiguration) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 2 with ContainerResource

use of org.infinispan.cli.resources.ContainerResource in project infinispan by infinispan.

the class SchemaCompleter method getAvailableItems.

@Override
Collection<String> getAvailableItems(Context context) throws IOException {
    Connection connection = context.getConnection();
    ContainerResource container = connection.getActiveResource().findAncestor(ContainerResource.class);
    return container != null ? connection.getAvailableSchemas(container.getName()) : Collections.emptyList();
}
Also used : ContainerResource(org.infinispan.cli.resources.ContainerResource) Connection(org.infinispan.cli.connection.Connection)

Example 3 with ContainerResource

use of org.infinispan.cli.resources.ContainerResource in project infinispan by infinispan.

the class CounterCompleter method getAvailableItems.

@Override
Collection<String> getAvailableItems(Context context) throws IOException {
    Connection connection = context.getConnection();
    ContainerResource container = connection.getActiveResource().findAncestor(ContainerResource.class);
    return container != null ? connection.getAvailableCounters(container.getName()) : Collections.emptyList();
}
Also used : ContainerResource(org.infinispan.cli.resources.ContainerResource) Connection(org.infinispan.cli.connection.Connection)

Aggregations

ContainerResource (org.infinispan.cli.resources.ContainerResource)3 Connection (org.infinispan.cli.connection.Connection)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 ServerConfiguration (org.infinispan.client.rest.configuration.ServerConfiguration)1