/** * @return Deserialized metrics. */ public ClusterMetrics metrics() { return ClusterMetricsSnapshot.deserialize(metrics, 0); }
/** * Constructor. * * @param creatorNodeId Creator node. * @param metrics Metrics. */ public TcpDiscoveryClientMetricsUpdateMessage(UUID creatorNodeId, ClusterMetrics metrics) { super(creatorNodeId); this.metrics = ClusterMetricsSnapshot.serialize(metrics); }
ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setLastUpdateTime(U.currentTimeMillis()); metrics.setMaximumActiveJobs(buf.getInt()); metrics.setCurrentActiveJobs(buf.getInt()); metrics.setAverageActiveJobs(buf.getFloat()); metrics.setMaximumWaitingJobs(buf.getInt()); metrics.setCurrentWaitingJobs(buf.getInt()); metrics.setAverageWaitingJobs(buf.getFloat()); metrics.setMaximumRejectedJobs(buf.getInt()); metrics.setCurrentRejectedJobs(buf.getInt()); metrics.setAverageRejectedJobs(buf.getFloat()); metrics.setMaximumCancelledJobs(buf.getInt()); metrics.setCurrentCancelledJobs(buf.getInt()); metrics.setAverageCancelledJobs(buf.getFloat()); metrics.setTotalRejectedJobs(buf.getInt()); metrics.setTotalCancelledJobs(buf.getInt()); metrics.setTotalExecutedJobs(buf.getInt()); metrics.setMaximumJobWaitTime(buf.getLong()); metrics.setCurrentJobWaitTime(buf.getLong()); metrics.setAverageJobWaitTime(buf.getDouble()); metrics.setMaximumJobExecuteTime(buf.getLong()); metrics.setCurrentJobExecuteTime(buf.getLong()); metrics.setAverageJobExecuteTime(buf.getDouble()); metrics.setTotalExecutedTasks(buf.getInt()); metrics.setCurrentIdleTime(buf.getLong()); metrics.setTotalIdleTime(buf.getLong()); metrics.setAvailableProcessors(buf.getInt());
/** * @param waitingJobs Waiting jobs count. * @param activeJobs Active jobs count. * @return Metrics adapter. */ private ClusterMetricsSnapshot createMetrics(int waitingJobs, int activeJobs) { ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(waitingJobs); metrics.setCurrentActiveJobs(activeJobs); return metrics; }
/** */ @Test public void testMetricsSize() { byte[] data = new byte[ClusterMetricsSnapshot.METRICS_SIZE]; // Test serialization. int off = ClusterMetricsSnapshot.serialize(data, 0, createMetrics()); assert off == ClusterMetricsSnapshot.METRICS_SIZE; // Test deserialization. ClusterMetrics res = ClusterMetricsSnapshot.deserialize(data, 0); assert res != null; }
/** * Creates test node with specified attributes. * * @param mac Node mac addresses. * @param pid Node PID. * @return Node. */ private GridTestNode getNode(String mac, int pid) { ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setHeapMemoryMaximum(1024L * 1024 * 1024); metrics.setHeapMemoryInitialized(1024L * 1024 * 1024); GridTestNode node = new GridTestNode(UUID.randomUUID(), metrics); node.addAttribute(ATTR_MACS, mac); node.addAttribute(ATTR_JVM_PID, pid); return node; } }
/** {@inheritDoc} */ @Override protected GridSpiTestContext initSpiContext() throws Exception { GridSpiTestContext ctx = super.initSpiContext(); GridTestNode locNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(locNode); ctx.setLocalNode(locNode); GridTestNode rmtNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(rmtNode); rmtNode.setAttribute(U.spiAttribute(getSpi(), WAIT_JOBS_THRESHOLD_NODE_ATTR), getWaitJobsThreshold()); ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(2); rmtNode.setMetrics(metrics); ctx.addNode(rmtNode); return ctx; }
/** {@inheritDoc} */ @Override public final ClusterMetrics metrics() { guard(); try { if (nodes().isEmpty()) throw U.convertException(U.emptyTopologyException()); return new ClusterMetricsSnapshot(this); } finally { unguard(); } }
/** */ @Test public void testSerialization() { byte[] data = new byte[ClusterMetricsSnapshot.METRICS_SIZE]; ClusterMetrics metrics1 = createMetrics(); // Test serialization. int off = ClusterMetricsSnapshot.serialize(data, 0, metrics1); assert off == ClusterMetricsSnapshot.METRICS_SIZE; // Test deserialization. ClusterMetrics metrics2 = ClusterMetricsSnapshot.deserialize(data, 0); assert metrics2 != null; assert isMetricsEquals(metrics1, metrics2); }
/** {@inheritDoc} */ @Override protected GridSpiTestContext initSpiContext() throws Exception { GridSpiTestContext ctx = super.initSpiContext(); GridTestNode locNode = new GridTestNode(UUID.randomUUID()); ctx.setLocalNode(locNode); rmtNode1 = new GridTestNode(UUID.randomUUID()); rmtNode2 = new GridTestNode(UUID.randomUUID()); addSpiDependency(locNode); addSpiDependency(rmtNode1); addSpiDependency(rmtNode2); ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(2); rmtNode1.setMetrics(metrics); rmtNode2.setMetrics(metrics); ctx.addNode(rmtNode1); ctx.addNode(rmtNode2); return ctx; }
/** {@inheritDoc} */ @Override public final ClusterMetrics metrics() { guard(); try { if (nodes().isEmpty()) throw U.convertException(U.emptyTopologyException()); return new ClusterMetricsSnapshot(this); } finally { unguard(); } }
ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setAvailableProcessors(1); metrics.setAverageActiveJobs(2); metrics.setAverageCancelledJobs(3); metrics.setAverageJobExecuteTime(4); metrics.setAverageJobWaitTime(5); metrics.setAverageRejectedJobs(6); metrics.setAverageWaitingJobs(7); metrics.setCurrentActiveJobs(8); metrics.setCurrentCancelledJobs(9); metrics.setCurrentIdleTime(10); metrics.setCurrentIdleTime(11); metrics.setCurrentJobExecuteTime(12); metrics.setCurrentJobWaitTime(13); metrics.setCurrentRejectedJobs(14); metrics.setCurrentWaitingJobs(15); metrics.setCurrentDaemonThreadCount(16); metrics.setHeapMemoryCommitted(17); metrics.setHeapMemoryInitialized(18); metrics.setHeapMemoryMaximum(19); metrics.setHeapMemoryUsed(20); metrics.setLastUpdateTime(21); metrics.setMaximumActiveJobs(22); metrics.setMaximumCancelledJobs(23); metrics.setMaximumJobExecuteTime(24); metrics.setMaximumJobWaitTime(25); metrics.setMaximumRejectedJobs(26); metrics.setMaximumWaitingJobs(27);
/** * @param metrics Metrics. * @param cacheMetrics Cache metrics. */ ClusterNodeMetrics(ClusterMetrics metrics, Map<Integer, CacheMetrics> cacheMetrics) { this.metrics = ClusterMetricsSnapshot.serialize(metrics); this.cacheMetrics = cacheMetrics; }
/** * Gets metrics map. * * @return Metrics map. */ public ClusterMetrics metrics() { return ClusterMetricsSnapshot.deserialize(metrics, 0); }
/** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { super.beforeTest(); rmtNode = new GridTestNode(UUID.randomUUID()); addSpiDependency(rmtNode); rmtNode.setAttribute(U.spiAttribute(getSpi(), WAIT_JOBS_THRESHOLD_NODE_ATTR), getWaitJobsThreshold()); ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setCurrentWaitingJobs(2); rmtNode.setMetrics(metrics); getSpiContext().addNode(rmtNode); getSpi().setStealingEnabled(true); }
ClusterMetricsSnapshot metrics = new ClusterMetricsSnapshot(); metrics.setLastUpdateTime(U.currentTimeMillis()); metrics.setMaximumActiveJobs(buf.getInt()); metrics.setCurrentActiveJobs(buf.getInt()); metrics.setAverageActiveJobs(buf.getFloat()); metrics.setMaximumWaitingJobs(buf.getInt()); metrics.setCurrentWaitingJobs(buf.getInt()); metrics.setAverageWaitingJobs(buf.getFloat()); metrics.setMaximumRejectedJobs(buf.getInt()); metrics.setCurrentRejectedJobs(buf.getInt()); metrics.setAverageRejectedJobs(buf.getFloat()); metrics.setMaximumCancelledJobs(buf.getInt()); metrics.setCurrentCancelledJobs(buf.getInt()); metrics.setAverageCancelledJobs(buf.getFloat()); metrics.setTotalRejectedJobs(buf.getInt()); metrics.setTotalCancelledJobs(buf.getInt()); metrics.setTotalExecutedJobs(buf.getInt()); metrics.setMaximumJobWaitTime(buf.getLong()); metrics.setCurrentJobWaitTime(buf.getLong()); metrics.setAverageJobWaitTime(buf.getDouble()); metrics.setMaximumJobExecuteTime(buf.getLong()); metrics.setCurrentJobExecuteTime(buf.getLong()); metrics.setAverageJobExecuteTime(buf.getDouble()); metrics.setTotalExecutedTasks(buf.getInt()); metrics.setCurrentIdleTime(buf.getLong()); metrics.setTotalIdleTime(buf.getLong()); metrics.setAvailableProcessors(buf.getInt());
/** * @param metrics Metrics. */ public MetricsSet(ClusterMetrics metrics) { assert metrics != null; this.metrics = ClusterMetricsSnapshot.serialize(metrics); }
@Override public T2<UUID, ClusterMetrics> apply(byte[] bytes) { UUID nodeId = new UUID(U.bytesToLong(bytes, 0), U.bytesToLong(bytes, 8)); return new T2<>(nodeId, ClusterMetricsSnapshot.deserialize(bytes, 16)); } });
/** * Serializes node metrics into byte array. * * @param metrics Node metrics to serialize. * @return New offset. */ public static byte[] serialize(ClusterMetrics metrics) { byte[] buf = new byte[METRICS_SIZE]; serialize(buf, 0, metrics); return buf; }
/** * Checks compatibility with old serialized metrics. */ @Test public void testMetricsCompatibility() { ClusterMetrics metrics = ClusterMetricsSnapshot.deserialize(METRICS_V1, 0); assert metrics != null; }