use of org.onosproject.k8snetworking.api.Constants.CLI_PORTS_LENGTH in project onos by opennetworkinglab.
the class K8sServiceListCommand method doExecute.
@Override
protected void doExecute() {
K8sServiceService service = get(K8sServiceService.class);
List<io.fabric8.kubernetes.api.model.Service> services = Lists.newArrayList(service.services());
services.sort(Comparator.comparing(s -> s.getMetadata().getName()));
String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_IP_ADDRESS_LENGTH, CLI_PORTS_LENGTH));
if (outputJson()) {
print("%s", json(services));
} else {
print(format, "Name", "Cluster IP", "Ports");
for (io.fabric8.kubernetes.api.model.Service svc : services) {
List<String> portWithProtocol = Lists.newArrayList();
svc.getSpec().getPorts().forEach(p -> portWithProtocol.add(p.getPort() + PORT_PROTOCOL_SEPARATOR + p.getProtocol()));
print(format, StringUtils.substring(svc.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(svc.getSpec().getClusterIP(), 0, CLI_IP_ADDRESS_LENGTH - CLI_MARGIN_LENGTH), portWithProtocol.isEmpty() ? "" : portWithProtocol);
}
}
}
use of org.onosproject.k8snetworking.api.Constants.CLI_PORTS_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