Search in sources :

Example 71 with Container

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container 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 72 with Container

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_13_R2.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_13_R2.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_13_R2.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_13_R2.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 73 with Container

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_16_R2.Container) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R2.nbt.NbtTagCompound) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_16_R2.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 74 with Container

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_16_R3.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 75 with Container

use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Container in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_14_R1.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_14_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_14_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_14_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)45 Container (net.minecraft.server.v1_12_R1.Container)9 Container (net.minecraft.server.v1_16_R3.Container)9 Container (org.flyte.api.v1.Container)9 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)8 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)8 Container (net.minecraft.server.v1_11_R1.Container)8 Container (net.minecraft.server.v1_14_R1.Container)8 Container (net.minecraft.server.v1_15_R1.Container)8 Container (net.minecraft.server.v1_16_R1.Container)8 Container (net.minecraft.server.v1_16_R2.Container)8 Container (net.minecraft.server.v1_8_R3.Container)8 Container (net.minecraft.server.v1_13_R1.Container)7 Container (net.minecraft.server.v1_13_R2.Container)6 Container (net.minecraft.server.v1_10_R1.Container)5 EntityPlayer (net.minecraft.server.v1_8_R3.EntityPlayer)5 SelfContainer (io.github.bananapuncher714.crafters.implementation.v1_11_R1.ContainerManager_v1_11_R1.SelfContainer)4 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)4 EntityPlayer (net.minecraft.server.v1_11_R1.EntityPlayer)4 EntityPlayer (net.minecraft.server.v1_12_R1.EntityPlayer)4