@Test public void testHostnameList() throws ListProviderException { ResourceListQuery query = new ServersListQuery(); Map<String, String> list = serverListProvider.getList(ServersListProvider.LIST_HOSTNAME, query); assertEquals(HOST1, list.get(HOST1)); assertEquals(HOST2, list.get(HOST2)); assertEquals(HOST3, list.get(HOST3)); assertEquals(HOST4, list.get(HOST4)); }
@Override public Map<String, String> getList(String listName, ResourceListQuery query) throws ListProviderException { Map<String, String> list = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE); list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE); list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE); return list; } ServersListQuery serversQuery; try { serversQuery = (ServersListQuery)query; } catch (ClassCastException ex) { serversQuery = new ServersListQuery(query); } Option<String> fHostname = serversQuery.getHostname(); Option<String> fNodeName = serversQuery.getNodeName(); Option<String> fStatus = serversQuery.getStatus(); List<HostRegistration> allServers; try { allServers = serviceRegistry.getHostRegistrations(); } catch (ServiceRegistryException e) { throw new ListProviderException("Not able to get the list of the hosts from the services registry"); } for (HostRegistration server : allServers) { boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vHostname = server.getBaseUrl(); String vNodeName = server.getNodeName(); if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname)) continue; if (fNodeName.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fNodeName.get()), vNodeName)) continue; if (fStatus.isSome()) { switch (StringUtils.trimToEmpty(fStatus.get())) { case SERVER_STATUS_ONLINE: if (!vOnline) continue; break; case SERVER_STATUS_OFFLINE: if (vOnline) continue; break; case SERVER_STATUS_MAINTENANCE: if (!vMaintenance) continue; break; default: break; } } switch (listName) { case LIST_NODE_NAME: if (vNodeName != null) list.put(vNodeName, vNodeName); break; case LIST_HOSTNAME: default: list.put(vHostname, vHostname); break; } } return list; }
ServersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) throws ListProviderException { Map<String, String> list = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE); list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE); list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE); return list; } ServersListQuery serversQuery; try { serversQuery = (ServersListQuery)query; } catch (ClassCastException ex) { serversQuery = new ServersListQuery(query); } Option<String> fHostname = serversQuery.getHostname(); Option<String> fNodeName = serversQuery.getNodeName(); Option<String> fStatus = serversQuery.getStatus(); List<HostRegistration> allServers; try { allServers = serviceRegistry.getHostRegistrations(); } catch (ServiceRegistryException e) { throw new ListProviderException("Not able to get the list of the hosts from the services registry"); } for (HostRegistration server : allServers) { boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vHostname = server.getBaseUrl(); String vNodeName = server.getNodeName(); if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname)) continue; if (fNodeName.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fNodeName.get()), vNodeName)) continue; if (fStatus.isSome()) { switch (StringUtils.trimToEmpty(fStatus.get())) { case SERVER_STATUS_ONLINE: if (!vOnline) continue; break; case SERVER_STATUS_OFFLINE: if (vOnline) continue; break; case SERVER_STATUS_MAINTENANCE: if (!vMaintenance) continue; break; default: break; } } switch (listName) { case LIST_NODE_NAME: if (vNodeName != null) list.put(vNodeName, vNodeName); break; case LIST_HOSTNAME: default: list.put(vHostname, vHostname); break; } } return list; } }
ServersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) throws ListProviderException { Map<String, String> list = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE); list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE); list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE); return list; } ServersListQuery serversQuery; try { serversQuery = (ServersListQuery)query; } catch (ClassCastException ex) { serversQuery = new ServersListQuery(query); } Option<String> fHostname = serversQuery.getHostname(); Option<String> fNodeName = serversQuery.getNodeName(); Option<String> fStatus = serversQuery.getStatus(); List<HostRegistration> allServers; try { allServers = serviceRegistry.getHostRegistrations(); } catch (ServiceRegistryException e) { throw new ListProviderException("Not able to get the list of the hosts from the services registry"); } for (HostRegistration server : allServers) { boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vHostname = server.getBaseUrl(); String vNodeName = server.getNodeName(); if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname)) continue; if (fNodeName.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fNodeName.get()), vNodeName)) continue; if (fStatus.isSome()) { switch (StringUtils.trimToEmpty(fStatus.get())) { case SERVER_STATUS_ONLINE: if (!vOnline) continue; break; case SERVER_STATUS_OFFLINE: if (vOnline) continue; break; case SERVER_STATUS_MAINTENANCE: if (!vMaintenance) continue; break; default: break; } } switch (listName) { case LIST_NODE_NAME: if (vNodeName != null) list.put(vNodeName, vNodeName); break; case LIST_HOSTNAME: default: list.put(vHostname, vHostname); break; } } return list; }  }
ServersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) throws ListProviderException { Map<String, String> list = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE); list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE); list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE); return list; } ServersListQuery serversQuery; try { serversQuery = (ServersListQuery)query; } catch (ClassCastException ex) { serversQuery = new ServersListQuery(query); } Option<String> fHostname = serversQuery.getHostname(); Option<String> fNodeName = serversQuery.getNodeName(); Option<String> fStatus = serversQuery.getStatus(); List<HostRegistration> allServers; try { allServers = serviceRegistry.getHostRegistrations(); } catch (ServiceRegistryException e) { throw new ListProviderException("Not able to get the list of the hosts from the services registry"); } for (HostRegistration server : allServers) { boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vHostname = server.getBaseUrl(); String vNodeName = server.getNodeName(); if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname)) continue; if (fNodeName.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fNodeName.get()), vNodeName)) continue; if (fStatus.isSome()) { switch (StringUtils.trimToEmpty(fStatus.get())) { case SERVER_STATUS_ONLINE: if (!vOnline) continue; break; case SERVER_STATUS_OFFLINE: if (vOnline) continue; break; case SERVER_STATUS_MAINTENANCE: if (!vMaintenance) continue; break; default: break; } } switch (listName) { case LIST_NODE_NAME: if (vNodeName != null) list.put(vNodeName, vNodeName); break; case LIST_HOSTNAME: default: list.put(vHostname, vHostname); break; } } return list; }  @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); void setServiceRegistry(ServiceRegistry serviceRegistry); @Override boolean isTranslatable(String listName); @Override String getDefault(); }
ServersListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) throws ListProviderException { Map<String, String> list = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE); list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE); list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE); return list; } ServersListQuery serversQuery; try { serversQuery = (ServersListQuery)query; } catch (ClassCastException ex) { serversQuery = new ServersListQuery(query); } Option<String> fHostname = serversQuery.getHostname(); Option<String> fNodeName = serversQuery.getNodeName(); Option<String> fStatus = serversQuery.getStatus(); List<HostRegistration> allServers; try { allServers = serviceRegistry.getHostRegistrations(); } catch (ServiceRegistryException e) { throw new ListProviderException("Not able to get the list of the hosts from the services registry"); } for (HostRegistration server : allServers) { boolean vOnline = server.isOnline(); boolean vMaintenance = server.isMaintenanceMode(); String vHostname = server.getBaseUrl(); String vNodeName = server.getNodeName(); if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname)) continue; if (fNodeName.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fNodeName.get()), vNodeName)) continue; if (fStatus.isSome()) { switch (StringUtils.trimToEmpty(fStatus.get())) { case SERVER_STATUS_ONLINE: if (!vOnline) continue; break; case SERVER_STATUS_OFFLINE: if (vOnline) continue; break; case SERVER_STATUS_MAINTENANCE: if (!vMaintenance) continue; break; default: break; } } switch (listName) { case LIST_NODE_NAME: if (vNodeName != null) list.put(vNodeName, vNodeName); break; case LIST_HOSTNAME: default: list.put(vHostname, vHostname); break; } } return list; }  @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); void setServiceRegistry(ServiceRegistry serviceRegistry); @Override boolean isTranslatable(String listName); @Override String getDefault(); static final String LIST_HOSTNAME; static final String LIST_NODE_NAME; static final String LIST_STATUS; static final String SERVER_STATUS_ONLINE; static final String SERVER_STATUS_LABEL_ONLINE; static final String SERVER_STATUS_OFFLINE; static final String SERVER_STATUS_LABEL_OFFLINE; static final String SERVER_STATUS_MAINTENANCE; static final String SERVER_STATUS_LABEL_MAINTENANCE; }