package com.lanyuanxiaoyao.service.configuration.entity.flink;

import org.eclipse.collections.api.list.ImmutableList;

/**
 * Flink taskmanager
 *
 * @author lanyuanxiaoyao
 * @date 2023-05-04
 */
public final class FlinkTaskManager {
    private String id;
    private String path;
    private Integer dataPort;
    private Integer jmxPort;
    private Long timeSinceLastHeartbeat;
    private Integer slotsNumber;
    private Integer freeSlots;
    private Resource totalResource;
    private Resource freeResource;
    private Resource hardware;
    private MemoryConfiguration memoryConfiguration;
    private Metrics metrics;

    public String getId() {
        return id;
    }

    public String getPath() {
        return path;
    }

    public Integer getDataPort() {
        return dataPort;
    }

    public Integer getJmxPort() {
        return jmxPort;
    }

    public Long getTimeSinceLastHeartbeat() {
        return timeSinceLastHeartbeat;
    }

    public Integer getSlotsNumber() {
        return slotsNumber;
    }

    public Integer getFreeSlots() {
        return freeSlots;
    }

    public Resource getTotalResource() {
        return totalResource;
    }

    public Resource getFreeResource() {
        return freeResource;
    }

    public Resource getHardware() {
        return hardware;
    }

    public MemoryConfiguration getMemoryConfiguration() {
        return memoryConfiguration;
    }

    public Metrics getMetrics() {
        return metrics;
    }

    @Override
    public String toString() {
        return "FlinkTaskManager{" +
                "id='" + id + '\'' +
                ", path='" + path + '\'' +
                ", dataPort=" + dataPort +
                ", jmxPort=" + jmxPort +
                ", timeSinceLastHeartbeat=" + timeSinceLastHeartbeat +
                ", slotsNumber=" + slotsNumber +
                ", freeSlots=" + freeSlots +
                ", totalResource=" + totalResource +
                ", freeResource=" + freeResource +
                ", hardware=" + hardware +
                ", memoryConfiguration=" + memoryConfiguration +
                ", metrics=" + metrics +
                '}';
    }

    public static final class Resource {
        private Double cpuCores;
        private Long taskHeapMemory;
        private Long taskOffHeapMemory;
        private Long managedMemory;
        private Long networkMemory;
        private Long physicalMemory;
        private Long freeMemory;

        public Double getCpuCores() {
            return cpuCores;
        }

        public Long getTaskHeapMemory() {
            return taskHeapMemory;
        }

        public Long getTaskOffHeapMemory() {
            return taskOffHeapMemory;
        }

        public Long getManagedMemory() {
            return managedMemory;
        }

        public Long getNetworkMemory() {
            return networkMemory;
        }

        public Long getPhysicalMemory() {
            return physicalMemory;
        }

        public Long getFreeMemory() {
            return freeMemory;
        }

        @Override
        public String toString() {
            return "Resource{" +
                    "cpuCores=" + cpuCores +
                    ", taskHeapMemory=" + taskHeapMemory +
                    ", taskOffHeapMemory=" + taskOffHeapMemory +
                    ", managedMemory=" + managedMemory +
                    ", networkMemory=" + networkMemory +
                    ", physicalMemory=" + physicalMemory +
                    ", freeMemory=" + freeMemory +
                    '}';
        }
    }

    public static final class MemoryConfiguration {
        private Long frameworkHeap;
        private Long taskHeap;
        private Long frameworkOffHeap;
        private Long taskOffHeap;
        private Long networkMemory;
        private Long managedMemory;
        private Long jvmMetaspace;
        private Long jvmOverhead;
        private Long totalFlinkMemory;
        private Long totalProcessMemory;

        public Long getFrameworkHeap() {
            return frameworkHeap;
        }

        public Long getTaskHeap() {
            return taskHeap;
        }

        public Long getFrameworkOffHeap() {
            return frameworkOffHeap;
        }

        public Long getTaskOffHeap() {
            return taskOffHeap;
        }

        public Long getNetworkMemory() {
            return networkMemory;
        }

        public Long getManagedMemory() {
            return managedMemory;
        }

        public Long getJvmMetaspace() {
            return jvmMetaspace;
        }

        public Long getJvmOverhead() {
            return jvmOverhead;
        }

        public Long getTotalFlinkMemory() {
            return totalFlinkMemory;
        }

        public Long getTotalProcessMemory() {
            return totalProcessMemory;
        }

        @Override
        public String toString() {
            return "MemoryConfiguration{" +
                    "frameworkHeap=" + frameworkHeap +
                    ", taskHeap=" + taskHeap +
                    ", frameworkOffHeap=" + frameworkOffHeap +
                    ", taskOffHeap=" + taskOffHeap +
                    ", networkMemory=" + networkMemory +
                    ", managedMemory=" + managedMemory +
                    ", jvmMetaspace=" + jvmMetaspace +
                    ", jvmOverhead=" + jvmOverhead +
                    ", totalFlinkMemory=" + totalFlinkMemory +
                    ", totalProcessMemory=" + totalProcessMemory +
                    '}';
        }
    }

    public static final class Metrics {
        private Long heapUsed;
        private Long heapCommitted;
        private Long heapMax;
        private Long nonHeapUsed;
        private Long nonHeapCommitted;
        private Long nonHeapMax;
        private Long directCount;
        private Long directUsed;
        private Long directMax;
        private Long mappedCount;
        private Long mappedUsed;
        private Long mappedMax;
        private Long memorySegmentsAvailable;
        private Long memorySegmentsTotal;
        private Long nettyShuffleMemorySegmentsAvailable;
        private Long nettyShuffleMemorySegmentsUsed;
        private Long nettyShuffleMemorySegmentsTotal;
        private Long nettyShuffleMemoryAvailable;
        private Long nettyShuffleMemoryUsed;
        private Long nettyShuffleMemoryTotal;
        private ImmutableList<Garbage> garbageCollectors;

        public Long getHeapUsed() {
            return heapUsed;
        }

        public Long getHeapCommitted() {
            return heapCommitted;
        }

        public Long getHeapMax() {
            return heapMax;
        }

        public Long getNonHeapUsed() {
            return nonHeapUsed;
        }

        public Long getNonHeapCommitted() {
            return nonHeapCommitted;
        }

        public Long getNonHeapMax() {
            return nonHeapMax;
        }

        public Long getDirectCount() {
            return directCount;
        }

        public Long getDirectUsed() {
            return directUsed;
        }

        public Long getDirectMax() {
            return directMax;
        }

        public Long getMappedCount() {
            return mappedCount;
        }

        public Long getMappedUsed() {
            return mappedUsed;
        }

        public Long getMappedMax() {
            return mappedMax;
        }

        public Long getMemorySegmentsAvailable() {
            return memorySegmentsAvailable;
        }

        public Long getMemorySegmentsTotal() {
            return memorySegmentsTotal;
        }

        public Long getNettyShuffleMemorySegmentsAvailable() {
            return nettyShuffleMemorySegmentsAvailable;
        }

        public Long getNettyShuffleMemorySegmentsUsed() {
            return nettyShuffleMemorySegmentsUsed;
        }

        public Long getNettyShuffleMemorySegmentsTotal() {
            return nettyShuffleMemorySegmentsTotal;
        }

        public Long getNettyShuffleMemoryAvailable() {
            return nettyShuffleMemoryAvailable;
        }

        public Long getNettyShuffleMemoryUsed() {
            return nettyShuffleMemoryUsed;
        }

        public Long getNettyShuffleMemoryTotal() {
            return nettyShuffleMemoryTotal;
        }

        public ImmutableList<Garbage> getGarbageCollectors() {
            return garbageCollectors;
        }

        @Override
        public String toString() {
            return "Metrics{" +
                    "heapUsed=" + heapUsed +
                    ", heapCommitted=" + heapCommitted +
                    ", heapMax=" + heapMax +
                    ", nonHeapUsed=" + nonHeapUsed +
                    ", nonHeapCommitted=" + nonHeapCommitted +
                    ", nonHeapMax=" + nonHeapMax +
                    ", directCount=" + directCount +
                    ", directUsed=" + directUsed +
                    ", directMax=" + directMax +
                    ", mappedCount=" + mappedCount +
                    ", mappedUsed=" + mappedUsed +
                    ", mappedMax=" + mappedMax +
                    ", memorySegmentsAvailable=" + memorySegmentsAvailable +
                    ", memorySegmentsTotal=" + memorySegmentsTotal +
                    ", nettyShuffleMemorySegmentsAvailable=" + nettyShuffleMemorySegmentsAvailable +
                    ", nettyShuffleMemorySegmentsUsed=" + nettyShuffleMemorySegmentsUsed +
                    ", nettyShuffleMemorySegmentsTotal=" + nettyShuffleMemorySegmentsTotal +
                    ", nettyShuffleMemoryAvailable=" + nettyShuffleMemoryAvailable +
                    ", nettyShuffleMemoryUsed=" + nettyShuffleMemoryUsed +
                    ", nettyShuffleMemoryTotal=" + nettyShuffleMemoryTotal +
                    ", garbageCollectors=" + garbageCollectors +
                    '}';
        }

        public static final class Garbage {
            private String name;
            private Long count;
            private Long time;

            public String getName() {
                return name;
            }

            public Long getCount() {
                return count;
            }

            public Long getTime() {
                return time;
            }

            @Override
            public String toString() {
                return "Garbage{" +
                        "name='" + name + '\'' +
                        ", count=" + count +
                        ", time=" + time +
                        '}';
            }
        }
    }
}
