public class KubernetesHelper extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_DOCKER_HOST |
Constructor and Description |
---|
KubernetesHelper() |
Modifier and Type | Method and Description |
---|---|
protected static void |
addObjectsToItemArray(com.fasterxml.jackson.databind.node.ArrayNode itemArray,
Object object) |
static com.fasterxml.jackson.databind.JsonNode |
combineJson(Object... objects)
Combines the JSON objects into a config object
|
static String |
containerNameToPodId(String containerName)
Returns the pod id for the given container id
|
protected static com.fasterxml.jackson.databind.node.JsonNodeFactory |
createNodeFactory() |
static io.fabric8.utils.Filter<Pod> |
createPodAnnotationFilter(Map<String,String> annotationSelector)
Creates a filter on a pod annotations using the given set of attribute values
|
static io.fabric8.utils.Filter<Pod> |
createPodFilter(Map<String,String> labelSelector)
Creates a filter on a pod using the given set of labels
|
static io.fabric8.utils.Filter<Pod> |
createPodFilter(String textFilter)
Creates a filter on a pod using the given text string
|
static io.fabric8.utils.Filter<ReplicationController> |
createReplicationControllerFilter(Map<String,String> labelSelector)
Creates a filter on a replicationController using the given text string
|
static io.fabric8.utils.Filter<ReplicationController> |
createReplicationControllerFilter(String textFilter)
Creates a filter on a replicationController using the given text string
|
static io.fabric8.utils.Filter<Service> |
createServiceFilter(Map<String,String> labelSelector)
Creates a filter on a service using the given text string
|
static io.fabric8.utils.Filter<Service> |
createServiceFilter(String textFilter)
Creates a filter on a service using the given text string
|
static boolean |
filterLabels(Map<String,String> filterLabels,
Map<String,String> labels)
Returns true if the given filterLabels matches the actual labels
|
static boolean |
filterMatchesIdOrLabels(String textFilter,
String id,
Map<String,String> labels)
Returns true if the given textFilter matches either the id or the labels
|
static Port |
findContainerPort(Pod pod,
Integer portNumber)
Returns the port for the given port number on the pod
|
static Port |
findContainerPortByName(Pod pod,
String name)
Returns the port for the given port name
|
static Port |
findContainerPortByNumberOrName(Pod pod,
String numberOrName)
Returns the port for the given port number or name
|
protected static com.fasterxml.jackson.databind.JsonNode |
findOrCreateConfig(Object[] objects) |
protected static Object |
getAdditionalProperty(Map<String,Object> additionalProperties,
String name) |
protected static String |
getAdditionalPropertyText(Map<String,Object> additionalProperties,
String name) |
static int |
getContainerPort(Service service)
Returns the container port number for the given service
|
static List<Container> |
getContainers(ContainerManifest manifest) |
static List<Container> |
getContainers(Pod pod)
Returns all the containers from the given pod
|
static List<Container> |
getContainers(PodState desiredState)
Returns all the manifest containers from the given desiredState
|
static List<Container> |
getContainers(PodTemplate podTemplate) |
static List<Container> |
getContainers(ReplicationController replicationController)
Returns all the containers from the given Replication Controller
|
static List<Container> |
getContainers(ReplicationControllerState desiredState)
Returns all the containers from the given Replication Controller's desiredState
|
static Map<String,ContainerStatus> |
getCurrentContainers(Pod pod)
Returns all the current containers from the given currentState
|
static Map<String,ContainerStatus> |
getCurrentContainers(PodState currentState)
Returns all the current containers from the given currentState
|
static List<Container> |
getCurrentContainers(ReplicationController replicationController)
Returns all the containers from the given Replication Controller
|
static String |
getDockerIp() |
static List<Object> |
getEntities(Config config)
Returns the items inside the config as a list of
Entity objects |
static Object |
getEntity(com.fasterxml.jackson.databind.JsonNode item)
Loads the entity for the given item
|
static String |
getHost(Pod pod)
Returns the host of the pod
|
static String |
getId(Pod entity) |
static String |
getId(ReplicationController entity) |
static String |
getId(Service entity) |
static String |
getName(Service entity) |
static Map<String,Pod> |
getPodMap(Kubernetes kubernetes) |
static Map<String,Pod> |
getPodMap(Kubernetes kubernetes,
String selector) |
static List<Pod> |
getPodsForReplicationController(ReplicationController replicationController,
Iterable<Pod> pods)
Returns the pods for the given replication controller
|
static List<Pod> |
getPodsForService(Service service,
Iterable<Pod> pods)
Returns the pods for the given service
|
static PodState |
getPodState(ReplicationController replicationController) |
static PodState |
getPodState(ReplicationControllerState desiredState) |
static PodStatus |
getPodStatus(Pod pod) |
static String |
getPodStatusText(Pod pod) |
static Integer |
getPort(Service entity) |
static String |
getPortalIP(Service entity) |
static Map<String,ReplicationController> |
getReplicationControllerMap(Kubernetes kubernetes) |
static Map<String,ReplicationController> |
getReplicationControllerMap(Kubernetes kubernetes,
String selector) |
static Map<String,String> |
getSelector(Service entity) |
static Map<String,Service> |
getServiceMap(Kubernetes kubernetes) |
static String |
getServiceURL(Service service)
Returns the URL to access the service; using the service portalIP and port
|
static boolean |
isPodRunning(Pod pod)
Returns true if the pod is running
|
protected static Config |
loadConfig(byte[] data) |
protected static Object |
loadEntity(byte[] json,
String kind,
Object defaultValue) |
static Object |
loadJson(byte[] json)
Returns the given json data as a DTO such as
Pod , ReplicationController or
Service
from the Kubernetes REST API or
JsonNode if it cannot be recognised. |
static Object |
loadJson(File file)
Returns the given json data as a DTO such as
Pod , ReplicationController or
Service
from the Kubernetes REST API or
JsonNode if it cannot be recognised. |
static Object |
loadJson(InputStream in)
Returns the given json data as a DTO such as
Pod , ReplicationController or
Service
from the Kubernetes REST API or
JsonNode if it cannot be recognised. |
static Object |
loadJson(String json) |
static void |
removeEmptyPods(PodList podSchema)
Removes empty pods returned by Kubernetes
|
static String |
resolveDockerHost() |
static void |
saveJson(File json,
Object object)
Saves the json object to the given file
|
static String |
toJson(Object dto) |
static com.fasterxml.jackson.databind.JsonNode |
toJsonNode(Object object)
Converts the DTO to a JsonNode
|
static Map<String,String> |
toLabelsMap(String labels) |
static String |
toLabelsString(Map<String,String> labelMap)
Returns a string for the labels using "," to separate values
|
protected static Integer |
toOptionalNumber(String text)
Returns the number if it can be parsed or null
|
static Map<String,Pod> |
toPodMap(List<Pod> pods)
Returns a map indexed by pod id of the pods
|
static Map<String,Pod> |
toPodMap(PodList podSchema)
Returns a map indexed by pod id of the pods
|
static Map<String,Pod> |
toPodMap(PodList podSchema,
String selector)
Returns a map indexed by pod id of the pods
|
static String |
toPositiveNonZeroText(Integer port)
For positive non-zero values return the text of the number or return blank
|
static Map<String,ReplicationController> |
toReplicationControllerMap(List<ReplicationController> replicationControllers)
Returns a map indexed by replicationController id of the replicationControllers
|
static Map<String,ReplicationController> |
toReplicationControllerMap(ReplicationControllerList replicationControllerSchema)
Returns a map indexed by replicationController id of the replicationControllers
|
static Map<String,Service> |
toServiceMap(List<Service> services)
Returns a map indexed by service id of the services
|
static Map<String,Service> |
toServiceMap(ServiceList serviceSchema)
Returns a map indexed by service id of the services
|
public static final String DEFAULT_DOCKER_HOST
public static String getId(ReplicationController entity)
protected static Object getAdditionalProperty(Map<String,Object> additionalProperties, String name)
protected static String getAdditionalPropertyText(Map<String,Object> additionalProperties, String name)
public static String getDockerIp()
public static String resolveDockerHost()
public static String toJson(Object dto) throws com.fasterxml.jackson.core.JsonProcessingException
com.fasterxml.jackson.core.JsonProcessingException
public static Object loadJson(File file) throws IOException
Pod
, ReplicationController
or
Service
from the Kubernetes REST API or
JsonNode
if it cannot be recognised.IOException
public static Object loadJson(InputStream in) throws IOException
Pod
, ReplicationController
or
Service
from the Kubernetes REST API or
JsonNode
if it cannot be recognised.IOException
public static Object loadJson(String json) throws IOException
IOException
public static Object loadJson(byte[] json) throws IOException
Pod
, ReplicationController
or
Service
from the Kubernetes REST API or
JsonNode
if it cannot be recognised.IOException
protected static Object loadEntity(byte[] json, String kind, Object defaultValue) throws IOException
IOException
protected static Config loadConfig(byte[] data) throws IOException
IOException
public static Object getEntity(com.fasterxml.jackson.databind.JsonNode item) throws IOException
IOException
public static List<Object> getEntities(Config config) throws IOException
Entity
objectsIOException
public static void saveJson(File json, Object object) throws IOException
IOException
public static Map<String,Pod> toPodMap(PodList podSchema)
public static Map<String,Pod> toPodMap(PodList podSchema, String selector)
public static Map<String,Pod> toPodMap(List<Pod> pods)
public static Map<String,Service> toServiceMap(ServiceList serviceSchema)
public static Map<String,Service> toServiceMap(List<Service> services)
public static Map<String,ReplicationController> toReplicationControllerMap(ReplicationControllerList replicationControllerSchema)
public static Map<String,ReplicationController> toReplicationControllerMap(List<ReplicationController> replicationControllers)
public static Map<String,Pod> getPodMap(Kubernetes kubernetes)
public static Map<String,Pod> getPodMap(Kubernetes kubernetes, String selector)
public static Map<String,Service> getServiceMap(Kubernetes kubernetes)
public static Map<String,ReplicationController> getReplicationControllerMap(Kubernetes kubernetes)
public static Map<String,ReplicationController> getReplicationControllerMap(Kubernetes kubernetes, String selector)
public static void removeEmptyPods(PodList podSchema)
public static String containerNameToPodId(String containerName)
public static String toLabelsString(Map<String,String> labelMap)
public static io.fabric8.utils.Filter<Pod> createPodFilter(String textFilter)
public static io.fabric8.utils.Filter<Pod> createPodFilter(Map<String,String> labelSelector)
public static io.fabric8.utils.Filter<Pod> createPodAnnotationFilter(Map<String,String> annotationSelector)
public static io.fabric8.utils.Filter<Service> createServiceFilter(String textFilter)
public static io.fabric8.utils.Filter<Service> createServiceFilter(Map<String,String> labelSelector)
public static io.fabric8.utils.Filter<ReplicationController> createReplicationControllerFilter(String textFilter)
public static io.fabric8.utils.Filter<ReplicationController> createReplicationControllerFilter(Map<String,String> labelSelector)
public static boolean filterMatchesIdOrLabels(String textFilter, String id, Map<String,String> labels)
public static boolean filterLabels(Map<String,String> filterLabels, Map<String,String> labels)
public static String toPositiveNonZeroText(Integer port)
public static List<Container> getContainers(Pod pod)
public static List<Container> getContainers(ReplicationController replicationController)
public static List<Container> getContainers(ReplicationControllerState desiredState)
public static List<Container> getContainers(PodTemplate podTemplate)
public static List<Container> getContainers(ContainerManifest manifest)
public static List<Container> getCurrentContainers(ReplicationController replicationController)
public static List<Container> getContainers(PodState desiredState)
public static Map<String,ContainerStatus> getCurrentContainers(Pod pod)
public static Map<String,ContainerStatus> getCurrentContainers(PodState currentState)
public static int getContainerPort(Service service)
public static com.fasterxml.jackson.databind.JsonNode combineJson(Object... objects) throws IOException
IOException
protected static void addObjectsToItemArray(com.fasterxml.jackson.databind.node.ArrayNode itemArray, Object object) throws IOException
IOException
protected static com.fasterxml.jackson.databind.node.JsonNodeFactory createNodeFactory()
protected static com.fasterxml.jackson.databind.JsonNode findOrCreateConfig(Object[] objects)
public static com.fasterxml.jackson.databind.JsonNode toJsonNode(Object object) throws IOException
IOException
public static String getServiceURL(Service service)
public static Port findContainerPort(Pod pod, Integer portNumber)
public static Port findContainerPortByName(Pod pod, String name)
public static Port findContainerPortByNumberOrName(Pod pod, String numberOrName)
protected static Integer toOptionalNumber(String text)
public static PodState getPodState(ReplicationController replicationController)
public static PodState getPodState(ReplicationControllerState desiredState)
public static boolean isPodRunning(Pod pod)
public static List<Pod> getPodsForReplicationController(ReplicationController replicationController, Iterable<Pod> pods)
Copyright © 2011–2015 Red Hat. All rights reserved.