Search in sources :

Example 1 with NetworkSettings

use of org.eclipse.che.plugin.docker.client.json.NetworkSettings in project che by eclipse.

the class DockerInstanceRuntimeInfo method getProperties.

@Override
public Map<String, String> getProperties() {
    Map<String, String> md = new LinkedHashMap<>();
    md.put("id", info.getId());
    md.put("created", info.getCreated());
    md.put("image", info.getImage());
    md.put("path", info.getPath());
    md.put("appArmorProfile", info.getAppArmorProfile());
    md.put("driver", info.getDriver());
    md.put("execDriver", info.getExecDriver());
    md.put("hostnamePath", info.getHostnamePath());
    md.put("hostsPath", info.getHostsPath());
    md.put("mountLabel", info.getMountLabel());
    md.put("name", info.getName());
    md.put("processLabel", info.getProcessLabel());
    md.put("volumesRW", String.valueOf(info.getVolumesRW()));
    md.put("resolvConfPath", info.getResolvConfPath());
    md.put("args", Arrays.toString(info.getArgs()));
    md.put("volumes", String.valueOf(info.getVolumes()));
    md.put("restartCount", String.valueOf(info.getRestartCount()));
    md.put("logPath", String.valueOf(info.getLogPath()));
    ContainerConfig config = info.getConfig();
    if (config != null) {
        md.put("config.domainName", config.getDomainName());
        md.put("config.hostname", config.getHostname());
        md.put("config.image", config.getImage());
        md.put("config.user", config.getUser());
        md.put("config.workingDir", config.getWorkingDir());
        md.put("config.cmd", Arrays.toString(config.getCmd()));
        md.put("config.volumes", String.valueOf(config.getVolumes()));
        md.put("config.entrypoint", Arrays.toString(config.getEntrypoint()));
        md.put("config.exposedPorts", String.valueOf(config.getExposedPorts()));
        md.put("config.macAddress", config.getMacAddress());
        md.put("config.securityOpts", Arrays.toString(config.getSecurityOpts()));
        md.put("config.env", Arrays.toString(config.getEnv()));
        md.put("config.attachStderr", Boolean.toString(config.isAttachStderr()));
        md.put("config.attachStdin", Boolean.toString(config.isAttachStdin()));
        md.put("config.attachStdout", Boolean.toString(config.isAttachStdout()));
        md.put("config.networkDisabled", Boolean.toString(config.isNetworkDisabled()));
        md.put("config.openStdin", Boolean.toString(config.isOpenStdin()));
        md.put("config.stdinOnce", Boolean.toString(config.isStdinOnce()));
        md.put("config.tty", Boolean.toString(config.isTty()));
        md.put("config.labels", String.valueOf(config.getLabels()));
    }
    ContainerState state = info.getState();
    if (state != null) {
        md.put("state.startedAt", state.getStartedAt());
        md.put("state.exitCode", Integer.toString(state.getExitCode()));
        md.put("state.pid", Integer.toString(state.getPid()));
        md.put("state.running", Boolean.toString(state.isRunning()));
        md.put("state.finishedAt", state.getFinishedAt());
        md.put("state.paused", Boolean.toString(state.isPaused()));
        md.put("state.restarting", Boolean.toString(state.isRestarting()));
        md.put("state.dead", String.valueOf(state.isDead()));
        md.put("state.OOMKilled", String.valueOf(state.isOOMKilled()));
        md.put("state.error", state.getError());
    }
    NetworkSettings networkSettings = info.getNetworkSettings();
    if (networkSettings != null) {
        md.put("network.bridge", networkSettings.getBridge());
        md.put("network.gateway", networkSettings.getGateway());
        md.put("network.ipAddress", networkSettings.getIpAddress());
        md.put("network.ipPrefixLen", Integer.toString(networkSettings.getIpPrefixLen()));
        md.put("network.portMappings", Arrays.toString(networkSettings.getPortMapping()));
        md.put("network.macAddress", networkSettings.getMacAddress());
        md.put("network.ports", String.valueOf(networkSettings.getPorts()));
        md.put("network.linkLocalIPv6PrefixLen", String.valueOf(networkSettings.getLinkLocalIPv6PrefixLen()));
        md.put("network.globalIPv6Address", networkSettings.getGlobalIPv6Address());
        md.put("network.globalIPv6PrefixLen", String.valueOf(networkSettings.getGlobalIPv6PrefixLen()));
        md.put("network.iPv6Gateway", networkSettings.getIpV6Gateway());
        md.put("network.linkLocalIPv6Address", networkSettings.getLinkLocalIPv6Address());
    }
    HostConfig hostConfig = info.getHostConfig();
    if (hostConfig != null) {
        md.put("hostConfig.cgroupParent", hostConfig.getCgroupParent());
        md.put("hostConfig.containerIDFile", hostConfig.getContainerIDFile());
        md.put("hostConfig.cpusetCpus", hostConfig.getCpusetCpus());
        md.put("hostConfig.ipcMode", hostConfig.getIpcMode());
        md.put("hostConfig.memory", Long.toString(hostConfig.getMemory()));
        md.put("hostConfig.networkMode", hostConfig.getNetworkMode());
        md.put("hostConfig.pidMode", hostConfig.getPidMode());
        md.put("hostConfig.binds", Arrays.toString(hostConfig.getBinds()));
        md.put("hostConfig.capAdd", Arrays.toString(hostConfig.getCapAdd()));
        md.put("hostConfig.capDrop", Arrays.toString(hostConfig.getCapDrop()));
        md.put("hostConfig.cpuShares", String.valueOf(hostConfig.getCpuShares()));
        md.put("hostConfig.devices", Arrays.toString(hostConfig.getDevices()));
        md.put("hostConfig.dns", Arrays.toString(hostConfig.getDns()));
        md.put("hostConfig.dnsSearch", Arrays.toString(hostConfig.getDnsSearch()));
        md.put("hostConfig.extraHosts", Arrays.toString(hostConfig.getExtraHosts()));
        md.put("hostConfig.links", Arrays.toString(hostConfig.getLinks()));
        md.put("hostConfig.logConfig", String.valueOf(hostConfig.getLogConfig()));
        md.put("hostConfig.lxcConf", Arrays.toString(hostConfig.getLxcConf()));
        md.put("hostConfig.memorySwap", String.valueOf(hostConfig.getMemorySwap()));
        md.put("hostConfig.portBindings", String.valueOf(hostConfig.getPortBindings()));
        md.put("hostConfig.restartPolicy", String.valueOf(hostConfig.getRestartPolicy()));
        md.put("hostConfig.ulimits", Arrays.toString(hostConfig.getUlimits()));
        md.put("hostConfig.volumesFrom", Arrays.toString(hostConfig.getVolumesFrom()));
        md.put("hostConfig.pidsLimit", Long.toString(hostConfig.getPidsLimit()));
    }
    return md;
}
Also used : ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) NetworkSettings(org.eclipse.che.plugin.docker.client.json.NetworkSettings) HostConfig(org.eclipse.che.plugin.docker.client.json.HostConfig) ContainerState(org.eclipse.che.plugin.docker.client.json.ContainerState) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with NetworkSettings

use of org.eclipse.che.plugin.docker.client.json.NetworkSettings in project che by eclipse.

the class OpenShiftConnector method createContainerInfo.

/**
     * Collects the relevant information from a Service, an ImageInfo, and a Pod into
     * a docker ContainerInfo JSON object. The returned object is what would be returned
     * by executing {@code docker inspect <container>}, with fields filled as available.
     * @param svc
     * @param imageInfo
     * @param pod
     * @param containerId
     * @return
     */
private ContainerInfo createContainerInfo(Service svc, ImageInfo imageInfo, Pod pod, String containerId) {
    // In Che on OpenShift, we only have one container per pod.
    Container container = pod.getSpec().getContainers().get(0);
    ContainerConfig imageContainerConfig = imageInfo.getContainerConfig();
    // HostConfig
    HostConfig hostConfig = new HostConfig();
    hostConfig.setBinds(new String[0]);
    hostConfig.setMemory(imageInfo.getConfig().getMemory());
    // Env vars
    List<String> imageEnv = Arrays.asList(imageContainerConfig.getEnv());
    List<String> containerEnv = container.getEnv().stream().map(e -> String.format("%s=%s", e.getName(), e.getValue())).collect(Collectors.toList());
    String[] env = Stream.concat(imageEnv.stream(), containerEnv.stream()).toArray(String[]::new);
    // Exposed Ports
    Map<String, List<PortBinding>> ports = getCheServicePorts(svc);
    Map<String, Map<String, String>> exposedPorts = new HashMap<>();
    for (String key : ports.keySet()) {
        exposedPorts.put(key, Collections.emptyMap());
    }
    // Labels
    Map<String, String> annotations = KubernetesLabelConverter.namesToLabels(svc.getMetadata().getAnnotations());
    Map<String, String> containerLabels = imageInfo.getConfig().getLabels();
    Map<String, String> labels = Stream.concat(annotations.entrySet().stream(), containerLabels.entrySet().stream()).filter(e -> e.getKey().startsWith(KubernetesLabelConverter.getCheServerLabelPrefix())).collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
    // ContainerConfig
    ContainerConfig config = imageContainerConfig;
    config.setHostname(svc.getMetadata().getName());
    config.setEnv(env);
    config.setExposedPorts(exposedPorts);
    config.setLabels(labels);
    config.setImage(container.getImage());
    // NetworkSettings
    NetworkSettings networkSettings = new NetworkSettings();
    networkSettings.setIpAddress(svc.getSpec().getClusterIP());
    networkSettings.setGateway(svc.getSpec().getClusterIP());
    networkSettings.setPorts(ports);
    // Make final ContainerInfo
    ContainerInfo info = new ContainerInfo();
    info.setId(containerId);
    info.setConfig(config);
    info.setNetworkSettings(networkSettings);
    info.setHostConfig(hostConfig);
    info.setImage(imageInfo.getConfig().getImage());
    return info;
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) Arrays(java.util.Arrays) RemoveContainerParams(org.eclipse.che.plugin.docker.client.params.RemoveContainerParams) HostConfig(org.eclipse.che.plugin.docker.client.json.HostConfig) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) LoggerFactory(org.slf4j.LoggerFactory) MessageProcessor(org.eclipse.che.plugin.docker.client.MessageProcessor) IpamConfig(org.eclipse.che.plugin.docker.client.json.network.IpamConfig) KubernetesContainer(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ContainerListEntry(org.eclipse.che.plugin.docker.client.json.ContainerListEntry) DefaultOpenShiftClient(io.fabric8.openshift.client.DefaultOpenShiftClient) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) DockerRegistryAuthResolver(org.eclipse.che.plugin.docker.client.DockerRegistryAuthResolver) Filters(org.eclipse.che.plugin.docker.client.json.Filters) Map(java.util.Map) NetworkSettings(org.eclipse.che.plugin.docker.client.json.NetworkSettings) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) DockerConnectionFactory(org.eclipse.che.plugin.docker.client.connection.DockerConnectionFactory) ImageStreamTag(io.fabric8.openshift.api.model.ImageStreamTag) ImageInfo(org.eclipse.che.plugin.docker.client.json.ImageInfo) InspectImageParams(org.eclipse.che.plugin.docker.client.params.InspectImageParams) Set(java.util.Set) OpenShiftException(org.eclipse.che.plugin.openshift.client.exception.OpenShiftException) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) Collectors(java.util.stream.Collectors) GetNetworksParams(org.eclipse.che.plugin.docker.client.params.network.GetNetworksParams) KubernetesService(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesService) ConnectContainerToNetworkParams(org.eclipse.che.plugin.docker.client.params.network.ConnectContainerToNetworkParams) List(java.util.List) Network(org.eclipse.che.plugin.docker.client.json.network.Network) Stream(java.util.stream.Stream) CommitParams(org.eclipse.che.plugin.docker.client.params.CommitParams) ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) GetEventsParams(org.eclipse.che.plugin.docker.client.params.GetEventsParams) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) ImageConfig(org.eclipse.che.plugin.docker.client.json.ImageConfig) TagParams(org.eclipse.che.plugin.docker.client.params.TagParams) CreateContainerParams(org.eclipse.che.plugin.docker.client.params.CreateContainerParams) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) DockerApiVersionPathPrefixProvider(org.eclipse.che.plugin.docker.client.DockerApiVersionPathPrefixProvider) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) Ipam(org.eclipse.che.plugin.docker.client.json.network.Ipam) PullParams(org.eclipse.che.plugin.docker.client.params.PullParams) DockerConnectorConfiguration(org.eclipse.che.plugin.docker.client.DockerConnectorConfiguration) ImageNotFoundException(org.eclipse.che.plugin.docker.client.exception.ImageNotFoundException) Container(io.fabric8.kubernetes.api.model.Container) PutResourceParams(org.eclipse.che.plugin.docker.client.params.PutResourceParams) StopContainerParams(org.eclipse.che.plugin.docker.client.params.StopContainerParams) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) ContainerCreated(org.eclipse.che.plugin.docker.client.json.ContainerCreated) Singleton(javax.inject.Singleton) StartContainerParams(org.eclipse.che.plugin.docker.client.params.StartContainerParams) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RemoveImageParams(org.eclipse.che.plugin.docker.client.params.RemoveImageParams) InspectNetworkParams(org.eclipse.che.plugin.docker.client.params.network.InspectNetworkParams) ProgressMonitor(org.eclipse.che.plugin.docker.client.ProgressMonitor) KubernetesEnvVar(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesEnvVar) CreateNetworkParams(org.eclipse.che.plugin.docker.client.params.network.CreateNetworkParams) PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) PortBinding(org.eclipse.che.plugin.docker.client.json.PortBinding) PodSpec(io.fabric8.kubernetes.api.model.PodSpec) Named(javax.inject.Named) ContainerInfo(org.eclipse.che.plugin.docker.client.json.ContainerInfo) Service(io.fabric8.kubernetes.api.model.Service) DisconnectContainerFromNetworkParams(org.eclipse.che.plugin.docker.client.params.network.DisconnectContainerFromNetworkParams) KillContainerParams(org.eclipse.che.plugin.docker.client.params.KillContainerParams) Volume(io.fabric8.kubernetes.api.model.Volume) ImageStream(io.fabric8.openshift.api.model.ImageStream) Probe(io.fabric8.kubernetes.api.model.Probe) GetResourceParams(org.eclipse.che.plugin.docker.client.params.GetResourceParams) Logger(org.slf4j.Logger) Pod(io.fabric8.kubernetes.api.model.Pod) IOException(java.io.IOException) Event(org.eclipse.che.plugin.docker.client.json.Event) KubernetesLabelConverter(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesLabelConverter) RemoveNetworkParams(org.eclipse.che.plugin.docker.client.params.RemoveNetworkParams) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) NetworkCreated(org.eclipse.che.plugin.docker.client.json.NetworkCreated) ContainerInNetwork(org.eclipse.che.plugin.docker.client.json.network.ContainerInNetwork) PodList(io.fabric8.kubernetes.api.model.PodList) DockerConnector(org.eclipse.che.plugin.docker.client.DockerConnector) KubernetesStringUtils(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesStringUtils) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ContainerConfig(org.eclipse.che.plugin.docker.client.json.ContainerConfig) KubernetesContainer(org.eclipse.che.plugin.openshift.client.kubernetes.KubernetesContainer) Container(io.fabric8.kubernetes.api.model.Container) NetworkSettings(org.eclipse.che.plugin.docker.client.json.NetworkSettings) HostConfig(org.eclipse.che.plugin.docker.client.json.HostConfig) ContainerInfo(org.eclipse.che.plugin.docker.client.json.ContainerInfo) List(java.util.List) ServiceList(io.fabric8.kubernetes.api.model.ServiceList) ArrayList(java.util.ArrayList) PodList(io.fabric8.kubernetes.api.model.PodList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ContainerConfig (org.eclipse.che.plugin.docker.client.json.ContainerConfig)2 HostConfig (org.eclipse.che.plugin.docker.client.json.HostConfig)2 NetworkSettings (org.eclipse.che.plugin.docker.client.json.NetworkSettings)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)1 PodSpecBuilder (io.fabric8.kubernetes.api.model.PodSpecBuilder)1 Probe (io.fabric8.kubernetes.api.model.Probe)1 ProbeBuilder (io.fabric8.kubernetes.api.model.ProbeBuilder)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)1 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)1