Search in sources :

Example 6 with Quantity

use of io.kubernetes.client.custom.Quantity in project heron by twitter.

the class V1ControllerTest method testCreatePersistentVolumeClaims.

@Test
public void testCreatePersistentVolumeClaims() {
    final String topologyName = "topology-name";
    final String volumeNameOne = "volume-name-one";
    final String volumeNameTwo = "volume-name-two";
    final String volumeNameStatic = "volume-name-static";
    final String claimNameOne = "OnDemand";
    final String claimNameTwo = "claim-name-two";
    final String claimNameStatic = "OnDEmaND";
    final String storageClassName = "storage-class-name";
    final String sizeLimit = "555Gi";
    final String accessModesList = "ReadWriteOnce,ReadOnlyMany,ReadWriteMany";
    final String accessModes = "ReadOnlyMany";
    final String volumeMode = "VolumeMode";
    final String path = "/path/to/mount/";
    final String subPath = "/sub/path/to/mount/";
    final Map<String, Map<VolumeConfigKeys, String>> mapPVCOpts = ImmutableMap.of(volumeNameOne, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.claimName, claimNameOne);
            put(VolumeConfigKeys.storageClassName, storageClassName);
            put(VolumeConfigKeys.sizeLimit, sizeLimit);
            put(VolumeConfigKeys.accessModes, accessModesList);
            put(VolumeConfigKeys.volumeMode, volumeMode);
            put(VolumeConfigKeys.path, path);
        }
    }, volumeNameTwo, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.claimName, claimNameTwo);
            put(VolumeConfigKeys.storageClassName, storageClassName);
            put(VolumeConfigKeys.sizeLimit, sizeLimit);
            put(VolumeConfigKeys.accessModes, accessModes);
            put(VolumeConfigKeys.volumeMode, volumeMode);
            put(VolumeConfigKeys.path, path);
            put(VolumeConfigKeys.subPath, subPath);
        }
    }, volumeNameStatic, new HashMap<VolumeConfigKeys, String>() {

        {
            put(VolumeConfigKeys.claimName, claimNameStatic);
            put(VolumeConfigKeys.sizeLimit, sizeLimit);
            put(VolumeConfigKeys.accessModes, accessModes);
            put(VolumeConfigKeys.volumeMode, volumeMode);
            put(VolumeConfigKeys.path, path);
            put(VolumeConfigKeys.subPath, subPath);
        }
    });
    final V1PersistentVolumeClaim claimOne = new V1PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeNameOne).withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName)).endMetadata().withNewSpec().withStorageClassName(storageClassName).withAccessModes(Arrays.asList(accessModesList.split(","))).withVolumeMode(volumeMode).withNewResources().addToRequests("storage", new Quantity(sizeLimit)).endResources().endSpec().build();
    final V1PersistentVolumeClaim claimStatic = new V1PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeNameStatic).withLabels(V1Controller.getPersistentVolumeClaimLabels(topologyName)).endMetadata().withNewSpec().withStorageClassName("").withAccessModes(Collections.singletonList(accessModes)).withVolumeMode(volumeMode).withNewResources().addToRequests("storage", new Quantity(sizeLimit)).endResources().endSpec().build();
    final List<V1PersistentVolumeClaim> expectedClaims = new LinkedList<>(Arrays.asList(claimOne, claimStatic));
    final List<V1PersistentVolumeClaim> actualClaims = v1ControllerWithPodTemplate.createPersistentVolumeClaims(mapPVCOpts);
    Assert.assertTrue(expectedClaims.containsAll(actualClaims));
}
Also used : VolumeConfigKeys(org.apache.heron.scheduler.kubernetes.KubernetesConstants.VolumeConfigKeys) V1PersistentVolumeClaim(io.kubernetes.client.openapi.models.V1PersistentVolumeClaim) Quantity(io.kubernetes.client.custom.Quantity) Matchers.anyString(org.mockito.Matchers.anyString) HashMap(java.util.HashMap) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) V1PersistentVolumeClaimBuilder(io.kubernetes.client.openapi.models.V1PersistentVolumeClaimBuilder) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 7 with Quantity

use of io.kubernetes.client.custom.Quantity in project heron by twitter.

the class V1ControllerTest method testConfigureContainerResourcesCLI.

@Test
public void testConfigureContainerResourcesCLI() {
    final boolean isExecutor = true;
    final String customLimitMEMStr = "120Gi";
    final String customLimitCPUStr = "5";
    final String customRequestMEMStr = "100Mi";
    final String customRequestCPUStr = "4";
    final Resource resources = new Resource(6, ByteAmount.fromMegabytes(34000), ByteAmount.fromGigabytes(400));
    final Quantity customLimitMEM = Quantity.fromString(customLimitMEMStr);
    final Quantity customLimitCPU = Quantity.fromString(customLimitCPUStr);
    final Quantity customRequestMEM = Quantity.fromString(customRequestMEMStr);
    final Quantity customRequestCPU = Quantity.fromString(customRequestCPUStr);
    final Config config = Config.newBuilder().put(String.format(KubernetesContext.KUBERNETES_RESOURCE_LIMITS_PREFIX + KubernetesConstants.CPU, KubernetesConstants.EXECUTOR_NAME), customLimitCPUStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_LIMITS_PREFIX + KubernetesConstants.MEMORY, KubernetesConstants.EXECUTOR_NAME), customLimitMEMStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_REQUESTS_PREFIX + KubernetesConstants.CPU, KubernetesConstants.EXECUTOR_NAME), customRequestCPUStr).put(String.format(KubernetesContext.KUBERNETES_RESOURCE_REQUESTS_PREFIX + KubernetesConstants.MEMORY, KubernetesConstants.EXECUTOR_NAME), customRequestMEMStr).put(KubernetesContext.KUBERNETES_RESOURCE_REQUEST_MODE, "EQUAL_TO_LIMIT").build();
    final V1Container expected = new V1ContainerBuilder().withNewResources().addToLimits(KubernetesConstants.CPU, customLimitCPU).addToLimits(KubernetesConstants.MEMORY, customLimitMEM).addToRequests(KubernetesConstants.CPU, customRequestCPU).addToRequests(KubernetesConstants.MEMORY, customRequestMEM).endResources().build();
    final V1Container actual = new V1Container();
    v1ControllerWithPodTemplate.configureContainerResources(actual, config, resources, isExecutor);
    Assert.assertEquals("Container Resources are set from CLI.", expected, actual);
}
Also used : V1Container(io.kubernetes.client.openapi.models.V1Container) Config(org.apache.heron.spi.common.Config) Resource(org.apache.heron.spi.packing.Resource) Quantity(io.kubernetes.client.custom.Quantity) V1ContainerBuilder(io.kubernetes.client.openapi.models.V1ContainerBuilder) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with Quantity

use of io.kubernetes.client.custom.Quantity in project java by kubernetes-client.

the class KubectlTop method topNodes.

private List<Pair<ApiType, MetricsType>> topNodes(CoreV1Api api, ApiClient apiClient, String metricName) throws KubectlException, ApiException, IOException {
    V1NodeList nodes = api.listNode(null, null, null, null, null, null, null, null, null, null);
    NodeMetricsList metrics = new Metrics(apiClient).getNodeMetrics();
    List<V1Node> items = nodes.getItems();
    Collections.sort(items, new Comparator<V1Node>() {

        @Override
        public int compare(V1Node arg0, V1Node arg1) {
            Quantity m0 = findNodeMetric(arg0.getMetadata().getName(), metrics).getUsage().get(metricName);
            Quantity m1 = findNodeMetric(arg1.getMetadata().getName(), metrics).getUsage().get(metricName);
            double p0 = findNodePercentage(arg0, m0, metricName);
            double p1 = findNodePercentage(arg1, m1, metricName);
            // sort high to low
            return Double.compare(p0, p1) * -1;
        }
    });
    List<Pair<ApiType, MetricsType>> result = new ArrayList<>();
    for (V1Node node : items) {
        result.add(new ImmutablePair<>((ApiType) node, (MetricsType) findNodeMetric(node, metrics)));
    }
    return result;
}
Also used : V1Node(io.kubernetes.client.openapi.models.V1Node) ArrayList(java.util.ArrayList) Quantity(io.kubernetes.client.custom.Quantity) Metrics(io.kubernetes.client.Metrics) NodeMetrics(io.kubernetes.client.custom.NodeMetrics) PodMetrics(io.kubernetes.client.custom.PodMetrics) ContainerMetrics(io.kubernetes.client.custom.ContainerMetrics) NodeMetricsList(io.kubernetes.client.custom.NodeMetricsList) V1NodeList(io.kubernetes.client.openapi.models.V1NodeList) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

Quantity (io.kubernetes.client.custom.Quantity)8 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 V1ResourceRequirements (io.kubernetes.client.openapi.models.V1ResourceRequirements)3 LinkedList (java.util.LinkedList)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 V1Container (io.kubernetes.client.openapi.models.V1Container)2 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)2 V1PersistentVolumeClaim (io.kubernetes.client.openapi.models.V1PersistentVolumeClaim)2 V1PersistentVolumeClaimBuilder (io.kubernetes.client.openapi.models.V1PersistentVolumeClaimBuilder)2 Config (org.apache.heron.spi.common.Config)2 Resource (org.apache.heron.spi.packing.Resource)2 Metrics (io.kubernetes.client.Metrics)1 ContainerMetrics (io.kubernetes.client.custom.ContainerMetrics)1 NodeMetrics (io.kubernetes.client.custom.NodeMetrics)1 NodeMetricsList (io.kubernetes.client.custom.NodeMetricsList)1