use of org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESSES_LENGTH in project onos by opennetworkinglab.
the class K8sEndpointsListCommand method doExecute.
@Override
protected void doExecute() {
K8sEndpointsService service = get(K8sEndpointsService.class);
List<Endpoints> endpointses = Lists.newArrayList(service.endpointses());
endpointses.sort(Comparator.comparing(e -> e.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_IP_ADDRESSES_LENGTH, CLI_PORTS_LENGTH));
if (outputJson()) {
print("%s", json(endpointses));
} else {
print(format, "Name", "IP Addresses", "Ports");
for (Endpoints endpoints : endpointses) {
List<String> ips = Lists.newArrayList();
List<String> portWithProtocol = Lists.newArrayList();
endpoints.getSubsets().forEach(e -> {
e.getAddresses().forEach(a -> ips.add(a.getIp()));
e.getPorts().forEach(p -> portWithProtocol.add(p.getPort() + PORT_PROTOCOL_SEPARATOR + p.getProtocol()));
});
print(format, StringUtils.substring(endpoints.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), ips.isEmpty() ? "" : StringUtils.substring(ips.toString(), 0, CLI_IP_ADDRESSES_LENGTH - CLI_MARGIN_LENGTH), portWithProtocol.isEmpty() ? "" : portWithProtocol);
}
}
}
Aggregations