Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2015 Red Hat, Inc. Red Hat licenses this file to you under the Apache License, version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package io.fabric8.forge.kubernetes;
 
 import  org.jboss.forge.addon.ui.context.UIContext;
 import  org.jboss.forge.addon.ui.metadata.UICommandMetadata;
 import  org.jboss.forge.addon.ui.util.Categories;
 import  org.jboss.forge.addon.ui.util.Metadata;
 
 import java.util.List;
 import java.util.Map;
 
 import static io.fabric8.kubernetes.api.KubernetesHelper.getStatusText;

Command to print the pod information in kubernetes
 
 public class PodInfo extends AbstractPodCommand {
     String indent = "    ";
 
     private int indentCount = 0;
 
 
     @Override
     public UICommandMetadata getMetadata(UIContext context) {
         return Metadata.from(super.getMetadata(context), getClass())
                 .category(Categories.create())
                 .name( + ": Pod Info")
                 .description("Shows detailed information for the given pod in the kubernetes cloud");
     }
 
     @Override
     protected void executePod(Pod podInfoString podId) {
         ..println("Created: " + podInfo.getMetadata().getCreationTimestamp());
         ..println("Labels: ");
         Map<StringStringlabels = podInfo.getMetadata().getLabels();
         for (Map.Entry<StringStringentry : labels.entrySet()) {
             ..println( + entry.getKey() + " = " + entry.getValue());
         }
         PodStatus currentState = podInfo.getStatus();
         if (currentState != null) {
             printValue("Host"currentState.getHostIP());
             printValue("IP"currentState.getPodIP());
             printValue("Status"getStatusText(currentState));
         }
         PodSpec spec = podInfo.getSpec();
         if (spec != null) {
             List<Containercontainers = spec.getContainers();
             if (notEmpty(containers)) {
                 ..println("Containers:");
                 ++;
                 for (Container container : containers) {
                     printValue("Name"container.getName());
                     printValue("Image"container.getImage());
                     printValue("Working Dir"container.getWorkingDir());
                     printValue("Command"container.getCommand());
 
                     List<ContainerPortports = container.getPorts();
                     if (notEmpty(ports)) {
                         println("Ports:");
                         ++;
                         for (ContainerPort port : ports) {
                             printValue("Name"port.getName());
                             printValue("Protocol"port.getProtocol());
                             printValue("Host Port"port.getHostPort());
                             printValue("Container Port"port.getContainerPort());
                         }
                         --;
                     }
 
                     List<EnvVarenvList = container.getEnv();
                     if (notEmpty(envList)) {
                         println("Environment:");
                         ++;
                         for (EnvVar env : envList) {
                             printValue(env.getName(), env.getValue());
                         }
                        --;
                    }
                    List<VolumeMountvolumeMounts = container.getVolumeMounts();
                    if (notEmpty(volumeMounts)) {
                        println("Volume Mounts:");
                        ++;
                        for (VolumeMount volumeMount : volumeMounts) {
                            printValue("Name"volumeMount.getName());
                            printValue("Mount Path"volumeMount.getMountPath());
                            printValue("Read Only"volumeMount.getReadOnly());
                        }
                        --;
                    }
                }
            }
            List<Volumevolumes = spec.getVolumes();
            if (volumes != null) {
                ..println("Volumes: ");
                for (Volume volume : volumes) {
                    ..println( + volume.getName());
                }
            }
        }
    }
    public static boolean notEmpty(Collection<?> ports) {
        return ports != null && !ports.isEmpty();
    }
    protected void println(String text) {
        println(text);
    }
    protected void printValue(String nameObject value) {
        printValue(namevalue);
    }
    protected void printValue(String nameObject valueint indentCount) {
        if (value != null) {
            String text = name + ": " + value;
            println(indentCounttext);
        }
    }
    protected void println(int indentCountString text) {
        for (int i = 0; i < indentCounti++) {
            ..print();
        }
        ..println(text);
    }
New to GrepCode? Check out our FAQ X