Search in sources :

Example 81 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project openhab-addons by openhab.

the class HomieImplementationTest method retrieveAttributes.

@SuppressWarnings("null")
@Test
public void retrieveAttributes() throws InterruptedException, ExecutionException {
    assertThat(connection.hasSubscribers(), is(false));
    Node node = new Node(DEVICE_TOPIC, "testnode", ThingChannelConstants.testHomieThing, callback, new NodeAttributes());
    Property property = spy(new Property(DEVICE_TOPIC + "/testnode", node, "temperature", callback, new PropertyAttributes()));
    // Create a scheduler
    ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(4);
    property.subscribe(connection, scheduler, 500).get();
    assertThat(property.attributes.settable, is(true));
    assertThat(property.attributes.retained, is(true));
    assertThat(property.attributes.name, is("Testprop"));
    assertThat(property.attributes.unit, is("°C"));
    assertThat(property.attributes.datatype, is(DataTypeEnum.float_));
    waitForAssert(() -> assertThat(property.attributes.format, is("-100:100")));
    verify(property, timeout(500).atLeastOnce()).attributesReceived();
    // Receive property value
    ChannelState channelState = spy(property.getChannelState());
    PropertyHelper.setChannelState(property, channelState);
    property.startChannel(connection, scheduler, 500).get();
    verify(channelState).start(any(), any(), anyInt());
    verify(channelState, timeout(500)).processMessage(any(), any());
    verify(callback).updateChannelState(any(), any());
    assertThat(property.getChannelState().getCache().getChannelState(), is(new DecimalType(10)));
    property.stop().get();
    assertThat(connection.hasSubscribers(), is(false));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ChannelState(org.openhab.binding.mqtt.generic.ChannelState) PropertyAttributes(org.openhab.binding.mqtt.homie.internal.homie300.PropertyAttributes) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) NodeAttributes(org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes) DecimalType(org.openhab.core.library.types.DecimalType) Property(org.openhab.binding.mqtt.homie.internal.homie300.Property) Test(org.junit.jupiter.api.Test) JavaOSGiTest(org.openhab.core.test.java.JavaOSGiTest)

Example 82 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project openhab-addons by openhab.

the class HomieImplementationTest method createSpyProperty.

// Inject a spy'ed property
public Property createSpyProperty(InvocationOnMock invocation) {
    final Node node = (Node) invocation.getMock();
    final String id = (String) invocation.getArguments()[0];
    return spy(node.createProperty(id, spy(new PropertyAttributes())));
}
Also used : PropertyAttributes(org.openhab.binding.mqtt.homie.internal.homie300.PropertyAttributes) Node(org.openhab.binding.mqtt.homie.internal.homie300.Node)

Example 83 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project openhab-addons by openhab.

the class HomieImplementationTest method createSpyNode.

// Inject a spy'ed node
public Node createSpyNode(InvocationOnMock invocation) {
    final Device device = (Device) invocation.getMock();
    final String id = (String) invocation.getArguments()[0];
    // Create the node
    Node node = spy(device.createNode(id, spy(new NodeAttributes())));
    // Intercept creating a property in the next call and inject a spy'ed property.
    doAnswer(this::createSpyProperty).when(node).createProperty(any());
    return node;
}
Also used : Device(org.openhab.binding.mqtt.homie.internal.homie300.Device) Node(org.openhab.binding.mqtt.homie.internal.homie300.Node) NodeAttributes(org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)

Example 84 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project yakc by manusa.

the class TopNodes method main.

public static void main(String[] args) {
    try (KubernetesClient kc = new KubernetesClient()) {
        final Node node = kc.create(CoreV1Api.class).listNode().stream().findFirst().orElseThrow(() -> new IllegalStateException("No nodes found in cluster"));
        final Map<String, String> nodeAllocatable = node.getStatus().getAllocatable();
        final double allocatableCpu = Resource.CPU.get(nodeAllocatable);
        final double allocatableMemory = Resource.MEMORY.get(nodeAllocatable);
        final double allocatablePods = Resource.PODS.get(nodeAllocatable);
        System.out.printf("Node %s allocatable resources, cpu: %s, memory: %s, pods %s%n", node.getMetadata().getName(), allocatableCpu, bytesToHumanReadable(allocatableMemory), (int) allocatablePods);
        System.out.printf(LOG_FORMAT, "POD (CONTAINER)", "CPU / LIMIT", "MEM / LIMIT");
        logSeparator();
        double totalCpu = 0D;
        double totalCpuLimit = 0D;
        double totalMemory = 0D;
        double totalMemoryLimit = 0D;
        final List<PodContainer> containers = kc.create(CoreV1Api.class).listPodForAllNamespaces(new ListPodForAllNamespaces().fieldSelector("spec.nodeName=" + node.getMetadata().getName())).stream().flatMap(p -> p.getSpec().getContainers().stream().map(c -> new PodContainer(p, c))).collect(Collectors.toList());
        for (PodContainer c : containers) {
            final Map<String, String> containerRequests = c.container.getResources().getRequests();
            final double cpu = Resource.CPU.get(containerRequests);
            final double memory = Resource.MEMORY.get(containerRequests);
            final Map<String, String> containerLimits = c.container.getResources().getLimits();
            final double cpuLimit = Resource.CPU.get(containerLimits);
            final double memoryLimit = Resource.MEMORY.get(containerLimits);
            System.out.printf(LOG_FORMAT, String.format("%s (%s)", c.pod.getMetadata().getName(), c.container.getName()), cpu + " / " + cpuLimit, bytesToHumanReadable(memory) + " / " + bytesToHumanReadable(memoryLimit));
            totalCpu += cpu;
            totalMemory += memory;
            totalCpuLimit += cpuLimit;
            totalMemoryLimit += memoryLimit;
        }
        logSeparator();
        System.out.printf(LOG_FORMAT, "TOTAL", totalCpu + " / " + totalCpuLimit, bytesToHumanReadable(totalMemory) + " / " + bytesToHumanReadable(totalMemoryLimit));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) CoreV1Api(com.marcnuri.yakc.api.core.v1.CoreV1Api) List(java.util.List) Locale(java.util.Locale) ListPodForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces) Map(java.util.Map) Container(com.marcnuri.yakc.model.io.k8s.api.core.v1.Container) Optional(java.util.Optional) KubernetesClient(com.marcnuri.yakc.KubernetesClient) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Pod(com.marcnuri.yakc.model.io.k8s.api.core.v1.Pod) KubernetesClient(com.marcnuri.yakc.KubernetesClient) Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) ListPodForAllNamespaces(com.marcnuri.yakc.api.core.v1.CoreV1Api.ListPodForAllNamespaces)

Example 85 with Node

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Node in project yakc by manusa.

the class MetricsV1beta1ApiIT method readNodeMetrics.

@Test
@DisplayName("readNodeMetrics, cluster contains at least a Node with some metrics")
void readNodeMetrics() throws IOException, InterruptedException {
    // Given
    final String node = KC.create(CoreV1Api.class).listNode().stream().findFirst().map(Node::getMetadata).map(ObjectMeta::getName).orElseThrow(() -> new AssertionError("No nodes found"));
    // When
    final NodeMetrics result = getWithRetry(() -> KC.create(MetricsV1beta1Api.class).readNodeMetrics(node).get());
    // Then
    assertThat(result).hasFieldOrPropertyWithValue("metadata.name", node).hasFieldOrProperty("usage.cpu").hasFieldOrProperty("usage.memory").hasFieldOrProperty("window").extracting(NodeMetrics::getTimestamp).isNotNull();
}
Also used : Node(com.marcnuri.yakc.model.io.k8s.api.core.v1.Node) NodeMetrics(com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.NodeMetrics) MetricsV1beta1Api(com.marcnuri.yakc.api.metrics.v1beta1.MetricsV1beta1Api) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)52 Test (org.junit.Test)27 CommonEntityData (org.openstreetmap.osmosis.core.domain.v0_6.CommonEntityData)26 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)21 Date (java.util.Date)18 NodeContainer (org.openstreetmap.osmosis.core.container.v0_6.NodeContainer)17 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)16 Node (org.flyte.api.v1.Node)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)14 OsmUser (org.openstreetmap.osmosis.core.domain.v0_6.OsmUser)14 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)13 TaskNode (org.flyte.api.v1.TaskNode)10 Bound (org.openstreetmap.osmosis.core.domain.v0_6.Bound)10 List (java.util.List)9 Map (java.util.Map)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 EntityContainer (org.openstreetmap.osmosis.core.container.v0_6.EntityContainer)9 Node (ch.ethz.globis.phtree.v16.Node)8