当前位置: 首页>>代码示例>>Java>>正文


Java Pod类代码示例

本文整理汇总了Java中io.fabric8.kubernetes.api.model.Pod的典型用法代码示例。如果您正苦于以下问题:Java Pod类的具体用法?Java Pod怎么用?Java Pod使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Pod类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了Pod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fetchPods

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private void fetchPods(KubernetesClient dockerClient) throws ParseException {
    final Map<String, KubernetesNode> dockerNodeMap = nodes.stream().distinct().collect(toMap(KubernetesNode::getName, node -> node));

    final List<Pod> pods = dockerClient.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)
            .withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)
            .list().getItems();

    LOG.info("Running pods " + pods.size());

    for (Pod pod : pods) {
        final KubernetesPod kubernetesPod = new KubernetesPod(pod);
        final KubernetesNode kubernetesNode = dockerNodeMap.get(kubernetesPod.getNodeName());
        if (kubernetesNode != null) {
            kubernetesNode.add(kubernetesPod);
        }
    }
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:18,代码来源:KubernetesCluster.java

示例2: unregisteredAfterTimeout

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private KubernetesAgentInstances unregisteredAfterTimeout(PluginSettings settings, Agents knownAgents) throws Exception {
    Period period = settings.getAutoRegisterPeriod();
    KubernetesAgentInstances unregisteredInstances = new KubernetesAgentInstances();
    KubernetesClient client = factory.kubernetes(settings);

    for (String instanceName : instances.keySet()) {
        if (knownAgents.containsAgentWithId(instanceName)) {
            continue;
        }
        Pod pod = client.pods().inNamespace(Constants.KUBERNETES_NAMESPACE_KEY).withName(instanceName).get();
        Date createdAt = getSimpleDateFormat().parse(pod.getMetadata().getCreationTimestamp());
        DateTime dateTimeCreated = new DateTime(createdAt);

        if (clock.now().isAfter(dateTimeCreated.plus(period))) {
            unregisteredInstances.register(kubernetesInstanceFactory.fromKubernetesPod(pod));
        }
    }
    return unregisteredInstances;
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:20,代码来源:KubernetesAgentInstances.java

示例3: setUp

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    initMocks(this);
    when(factory.kubernetes(any(PluginSettings.class))).thenReturn(mockedClient);
    when(mockedClient.pods()).thenReturn(mockedOperation);
    when(mockedOperation.inNamespace(KUBERNETES_NAMESPACE_KEY)).thenReturn(mockedNamespaceOperation);
    when(mockedNamespaceOperation.create(any(Pod.class))).thenAnswer(new Answer<Pod>() {
        @Override
        public Pod answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Pod) args[0];
        }
    });

    agentInstances = new KubernetesAgentInstances(factory);
    properties.put("foo", "bar");
    properties.put("Image", "gocdcontrib/ubuntu-docker-elastic-agent");
    instance = agentInstances.create(new CreateAgentRequest(UUID.randomUUID().toString(), properties, environment, new JobIdentifier(100L)), createSettings(), null);
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:20,代码来源:ShouldAssignWorkRequestExecutorTest.java

示例4: setUp

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    initMocks(this);
    when(factory.kubernetes(any(PluginSettings.class))).thenReturn(mockedClient);
    when(mockedClient.pods()).thenReturn(mockedOperation);
    when(mockedOperation.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(mockedNamespaceOperation);

    when(mockedNamespaceOperation.create(any(Pod.class))).thenAnswer(new Answer<Pod>() {
        @Override
        public Pod answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            return (Pod) args[0];
        }
    });

    when(mockedNamespaceOperation.withName(anyString())).thenReturn(podResource);
    when(podResource.get()).thenReturn(mockedPod);

    objectMetadata = new ObjectMeta();
    objectMetadata.setCreationTimestamp(getSimpleDateFormat().format(new Date()));

    when(mockedPod.getMetadata()).thenReturn(objectMetadata);
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:24,代码来源:ServerPingRequestExecutorTest.java

示例5: onRequest

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all failing pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .filter(p -> FAILED_PHASE.equalsIgnoreCase(p.getStatus().getPhase()))
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No failing pods found in namespace " + namespace);
        } else {
            return newResponse("The failing pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:23,代码来源:GetFailingPods.java

示例6: onRequest

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No pods found in namespace " + namespace);
        } else {
            return newResponse("The available pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetPods.java

示例7: getLinesWithFoundPatternsInLogs

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static String[] getLinesWithFoundPatternsInLogs(Pod pod, Pattern... patterns) throws IOException {
	String found[] = new String[patterns.length];

	// TODO: use a method that don't require whole log in memory
	StringReader stringReader = new StringReader(OpenShiftUtils.getInstance().getRuntimeLog(pod));

	try (BufferedReader br = new BufferedReader(stringReader)) {
		br.lines().forEach(line -> {
			for (int i = 0; i < patterns.length; ++i) {
				Pattern pattern = patterns[i];
				if (pattern.matcher(line).find()) {
					LOGGER.info("Found pattern {} on line '{}'", pattern, cleanLine(line));
					found[i] = line;
				}
			}
		});
	}

	return found;
}
 
开发者ID:syndesisio,项目名称:syndesis-qe,代码行数:21,代码来源:LogCheckerUtils.java

示例8: assertLogsContainsOrNot

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static void assertLogsContainsOrNot(Collection<Pod> pods, String[] shouldFinds, String[] shouldNotFinds) throws IOException {
	Pattern patterns[] = new Pattern[shouldFinds.length + shouldNotFinds.length];

	for (int i = 0; i < shouldFinds.length; ++i) {
		patterns[i] = Pattern.compile(shouldFinds[i]);
	}

	for (int i = 0; i < shouldNotFinds.length; ++i) {
		patterns[shouldFinds.length + i] = Pattern.compile(shouldNotFinds[i]);
	}

	boolean found[] = findPatternsInLogs(pods, patterns);

	for (int i = 0; i < patterns.length; ++i) {
		if (i < shouldFinds.length) {
			Assertions.assertThat(found[i]).as("Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(true);
		} else {
			Assertions.assertThat(found[i]).as("Found pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(false);
		}
	}
}
 
开发者ID:syndesisio,项目名称:syndesis-qe,代码行数:22,代码来源:LogCheckerUtils.java

示例9: getPodsByName

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private KubernetesPod getPodsByName(String namespace, String name) throws VmidcException {
    KubernetesPod resultPod = null;

    try {
        Pod pod = getKubernetesClient().pods().inNamespace(namespace).withName(name).get();

        if (pod != null) {
            resultPod = new KubernetesPod(pod.getMetadata().getName(), pod.getMetadata().getNamespace(), pod.getMetadata().getUid(),
                    pod.getSpec().getNodeName());
        }

    } catch (KubernetesClientException e) {
        throw new VmidcException("Failed to get Pods");
    }

    return resultPod;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:18,代码来源:KubernetesPodApi.java

示例10: testGetPodsbyLabel_WhenK8sReturnsPodWithMatchingId_ReturnsPod

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@Test
public void testGetPodsbyLabel_WhenK8sReturnsPodWithMatchingId_ReturnsPod() throws Exception {
    // Arrange.
    String name = UUID.randomUUID().toString();
    String namespace = UUID.randomUUID().toString();
    String uid = UUID.randomUUID().toString();
    Pod pod = newPod(uid, namespace, name, UUID.randomUUID().toString());
    mockPodsByName(namespace, name, pod);

    // Act.
    KubernetesPod result = this.service.getPodById(uid, namespace, name);

    // Assert.
    assertNotNull("The result should not be null.", result);
    assertPodFields(pod, result);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:KubernetesPodApiTest.java

示例11: newPod

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private Pod newPod(String uid, String namespace, String name, String node) {
    Pod pod = new Pod();

    ObjectMeta objMeta = new ObjectMeta();
    objMeta.setName(name);
    objMeta.setNamespace(namespace);
    objMeta.setUid(uid);

    PodSpec spec = new PodSpec();
    spec.setNodeName(node);

    pod.setMetadata(objMeta);
    pod.setSpec(spec);

    return pod;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:KubernetesPodApiTest.java

示例12: testGetPodsbyLabel_WhenK8sReturnsPods

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
private void testGetPodsbyLabel_WhenK8sReturnsPods(int podCount) throws Exception {
    // Arrange.
    String label = UUID.randomUUID().toString();

    List<Pod> pods = new ArrayList<>();

    for(int i = 0; i < podCount; i++) {
        pods.add(newPod(UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString()));
    }

    mockPodsByLabel(label, pods);

    // Act.
    List<KubernetesPod> result = this.service.getPodsByLabel(label);

    // Assert.
    assertNotNull("The result should not be null.", result);
    assertPodsList(pods, result);

}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:21,代码来源:KubernetesPodApiTest.java

示例13: startNewInstance

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
@NotNull
@Override
public CloudInstance startNewInstance(@NotNull CloudImage cloudImage, @NotNull CloudInstanceUserData cloudInstanceUserData) throws QuotaException {
    final KubeCloudImage kubeCloudImage = (KubeCloudImage) cloudImage;
    BuildAgentPodTemplateProvider podTemplateProvider = myPodTemplateProviders.get(kubeCloudImage.getPodSpecMode());
    try {
        final Pod podTemplate = podTemplateProvider.getPodTemplate(cloudInstanceUserData, kubeCloudImage, myKubeClientParams);
        final Pod newPod = myApiConnector.createPod(podTemplate);
        myCurrentError = null;
        final KubeCloudInstance newInstance = new CachingKubeCloudInstance(new KubeCloudInstanceImpl(kubeCloudImage, newPod, myApiConnector), myCache);
        kubeCloudImage.populateInstances();
        return newInstance;
    } catch (KubeCloudException | KubernetesClientException ex){
        myCurrentError = new CloudErrorInfo("Failed to start pod", ex.getMessage(), ex);
        throw ex;
    }
}
 
开发者ID:JetBrains,项目名称:teamcity-kubernetes-plugin,代码行数:18,代码来源:KubeCloudClient.java

示例14: getLinesWithFoundPatternsInLogs

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
public static String[] getLinesWithFoundPatternsInLogs(Pod pod, Pattern... patterns) throws IOException {
	String found[] = new String[patterns.length];

	// TODO: use a method that don't require whole log in memory
	StringReader stringReader = new StringReader(OpenshiftUtil.getInstance().getRuntimeLog(pod));

	try (BufferedReader br = new BufferedReader(stringReader)) {
		br.lines().forEach(line -> {
			for (int i = 0; i < patterns.length; ++i) {
				Pattern pattern = patterns[i];
				if (pattern.matcher(line).find()) {
					LOGGER.info("Found pattern {} on line '{}'", pattern, LogCleaner.cleanLine(line));
					found[i] = line;
				}
			}
		});
	}

	return found;
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:21,代码来源:LogCheckerUtils.java

示例15: assertLogsContainsOrNot

import io.fabric8.kubernetes.api.model.Pod; //导入依赖的package包/类
/**
 * Asserts logs contain (or not) given Pair&lt;issue-id, pattern>, and report the assert as &lt;issue> Didn't find pattern|Found pattern &lt;pattern>
 * @param pods
 * @param shouldFinds Pair&lt;issue-id, pattern>...
 * @param shouldNotFinds Pair&lt;issue-id, pattern>...
 * @throws IOException
 */
public static void assertLogsContainsOrNot(Collection<Pod> pods, Tuple.Pair<String, String>[] shouldFinds, Tuple.Pair<String, String>[] shouldNotFinds) throws IOException {
	Pattern patterns[] = new Pattern[shouldFinds.length + shouldNotFinds.length];

	for (int i = 0; i < shouldFinds.length; ++i) {
		patterns[i] = Pattern.compile(shouldFinds[i].getSecond());
	}

	for (int i = 0; i < shouldNotFinds.length; ++i) {
		patterns[shouldFinds.length + i] = Pattern.compile(shouldNotFinds[i].getSecond());
	}

	boolean found[] = findPatternsInLogs(pods, patterns);

	for (int i = 0; i < patterns.length; ++i) {
		if (i < shouldFinds.length) {
			Assertions.assertThat(found[i]).as(shouldFinds[i].getFirst() + " Didn't find pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(true);
		} else {
			Assertions.assertThat(found[i]).as(shouldNotFinds[i - shouldFinds.length].getFirst() + " Found pattern '" + patterns[i].toString() + "' in pod " + formatPodLists(pods) + "logs").isEqualTo(false);
		}
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:29,代码来源:LogCheckerUtils.java


注:本文中的io.fabric8.kubernetes.api.model.Pod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。