Search in sources :

Example 6 with CLI_MARGIN_LENGTH

use of org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH in project onos by opennetworkinglab.

the class K8sIngressListCommand method doExecute.

@Override
protected void doExecute() {
    K8sIngressService service = get(K8sIngressService.class);
    List<Ingress> ingresses = Lists.newArrayList(service.ingresses());
    ingresses.sort(Comparator.comparing(p -> p.getMetadata().getName()));
    String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_NAMESPACE_LENGTH, CLI_IP_ADDRESS_LENGTH));
    if (outputJson()) {
        print("%s", json(ingresses));
    } else {
        print(format, "Name", "Namespace", "LB Addresses");
        for (Ingress ingress : ingresses) {
            List<String> lbIps = Lists.newArrayList();
            ingress.getStatus().getLoadBalancer().getIngress().forEach(i -> lbIps.add(i.getIp()));
            print(format, StringUtils.substring(ingress.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(ingress.getMetadata().getNamespace(), 0, CLI_NAMESPACE_LENGTH - CLI_MARGIN_LENGTH), lbIps.isEmpty() ? "" : lbIps);
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Command(org.apache.karaf.shell.api.action.Command) CLI_NAME_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AbstractShellCommand(org.onosproject.cli.AbstractShellCommand) CLI_NAMESPACE_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH) List(java.util.List) CLI_IP_ADDRESS_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESS_LENGTH) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) K8sIngressService(org.onosproject.k8snetworking.api.K8sIngressService) Serialization(io.fabric8.kubernetes.client.utils.Serialization) K8sNetworkingUtil.prettyJson(org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson) Service(org.apache.karaf.shell.api.action.lifecycle.Service) CLI_MARGIN_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH) Comparator(java.util.Comparator) K8sIngressService(org.onosproject.k8snetworking.api.K8sIngressService) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ImmutableList (com.google.common.collect.ImmutableList)6 Lists (com.google.common.collect.Lists)6 Serialization (io.fabric8.kubernetes.client.utils.Serialization)6 IOException (java.io.IOException)6 Comparator (java.util.Comparator)6 List (java.util.List)6 StringUtils (org.apache.commons.lang.StringUtils)6 Command (org.apache.karaf.shell.api.action.Command)6 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)6 CLI_MARGIN_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH)6 CLI_NAME_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH)6 K8sNetworkingUtil.genFormatString (org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)6 K8sNetworkingUtil.prettyJson (org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson)6 Service (org.apache.karaf.shell.api.action.lifecycle.Service)5 CLI_IP_ADDRESS_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_IP_ADDRESS_LENGTH)3 CLI_NAMESPACE_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_NAMESPACE_LENGTH)3 CLI_PORTS_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_PORTS_LENGTH)2