Search in sources :

Example 1 with CLI_PHASE_LENGTH

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

the class K8sNamespaceListCommand method doExecute.

@Override
protected void doExecute() {
    K8sNamespaceService service = get(K8sNamespaceService.class);
    List<Namespace> namespaces = Lists.newArrayList(service.namespaces());
    namespaces.sort(Comparator.comparing(n -> n.getMetadata().getName()));
    String format = genFormatString(ImmutableList.of(CLI_NAME_LENGTH, CLI_PHASE_LENGTH, CLI_LABELS_LENGTH));
    if (outputJson()) {
        print("%s", json(namespaces));
    } else {
        print(format, "Name", "Phase", "Labels");
        for (Namespace namespace : namespaces) {
            print(format, StringUtils.substring(namespace.getMetadata().getName(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), namespace.getStatus().getPhase(), namespace.getMetadata() != null && namespace.getMetadata().getLabels() != null && !namespace.getMetadata().getLabels().isEmpty() ? StringUtils.substring(namespace.getMetadata().getLabels().toString(), 0, CLI_LABELS_LENGTH - CLI_MARGIN_LENGTH) : "");
        }
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) K8sNamespaceService(org.onosproject.k8snetworking.api.K8sNamespaceService) 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) List(java.util.List) CLI_PHASE_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_PHASE_LENGTH) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Namespace(io.fabric8.kubernetes.api.model.Namespace) Serialization(io.fabric8.kubernetes.client.utils.Serialization) K8sNetworkingUtil.prettyJson(org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson) CLI_LABELS_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_LABELS_LENGTH) CLI_MARGIN_LENGTH(org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH) Comparator(java.util.Comparator) K8sNamespaceService(org.onosproject.k8snetworking.api.K8sNamespaceService) K8sNetworkingUtil.genFormatString(org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString) Namespace(io.fabric8.kubernetes.api.model.Namespace)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 Serialization (io.fabric8.kubernetes.client.utils.Serialization)1 IOException (java.io.IOException)1 Comparator (java.util.Comparator)1 List (java.util.List)1 StringUtils (org.apache.commons.lang.StringUtils)1 Command (org.apache.karaf.shell.api.action.Command)1 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)1 CLI_LABELS_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_LABELS_LENGTH)1 CLI_MARGIN_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_MARGIN_LENGTH)1 CLI_NAME_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_NAME_LENGTH)1 CLI_PHASE_LENGTH (org.onosproject.k8snetworking.api.Constants.CLI_PHASE_LENGTH)1 K8sNamespaceService (org.onosproject.k8snetworking.api.K8sNamespaceService)1 K8sNetworkingUtil.genFormatString (org.onosproject.k8snetworking.util.K8sNetworkingUtil.genFormatString)1 K8sNetworkingUtil.prettyJson (org.onosproject.k8snetworking.util.K8sNetworkingUtil.prettyJson)1