Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkpoint #432

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import io.xh.hoist.BaseController
import io.xh.hoist.security.Access

@Access(['HOIST_ADMIN_READER'])
class DistributedObjectAdminController extends BaseController {
def distributedObjectAdminService
class ClusterObjectsAdminController extends BaseController {
def clusterObjectsService

def getDistributedObjectsReport() {
renderJSON(distributedObjectAdminService.getDistributedObjectsReport())
def getClusterObjectsReport() {
renderJSON(clusterObjectsService.getClusterObjectsReport())
}

@Access(['HOIST_ADMIN'])
def clearHibernateCaches() {
def req = parseRequestJSON()
distributedObjectAdminService.clearHibernateCaches(req.names)
clusterObjectsService.clearHibernateCaches(req.names)
renderJSON([success: true])
}

@Access(['HOIST_ADMIN'])
def clearAllHibernateCaches() {
distributedObjectAdminService.clearHibernateCaches()
clusterObjectsService.clearHibernateCaches()
renderJSON([success: true])
}
}
81 changes: 81 additions & 0 deletions grails-app/services/io/xh/hoist/admin/ClusterObjectsService.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | [email protected])
*
* Copyright © 2025 Extremely Heavy Industries Inc.
*/
package io.xh.hoist.admin

import com.hazelcast.cache.impl.CacheProxy
import com.hazelcast.executor.impl.ExecutorServiceProxy
import io.xh.hoist.AdminStats
import io.xh.hoist.BaseService
import io.xh.hoist.cluster.ClusterRequest

import static io.xh.hoist.util.Utils.appContext
import static java.lang.System.currentTimeMillis

class ClusterObjectsService extends BaseService {
def grailsApplication

ClusterObjectsReport getClusterObjectsReport() {
def startTimestamp = currentTimeMillis(),
info = clusterService
.submitToAllInstances(new ListClusterObjects())
.collectMany { it.value.value }

return new ClusterObjectsReport(
info: info,
startTimestamp: startTimestamp,
endTimestamp: currentTimeMillis()
)
}

/**
* Clear all Hibernate caches, or a specific list of caches by name.
*/
void clearHibernateCaches(List<String> names = null) {
def caches = clusterService.distributedObjects.findAll {it instanceof CacheProxy}
names ?= caches*.name
names.each { name ->
def obj = caches.find { it.name == name }
if (obj) {
obj.clear()
logInfo('Cleared ' + name)
} else {
logWarn('Cannot find cache', name)
}
}
}

//--------------------
// Implementation
//--------------------
private List<ClusterObjectInfo> listClusterObjects() {
// Services and their AdminStat implementing resources
Map<String, BaseService> svcs = grailsApplication.mainContext.getBeansOfType(BaseService.class, false, false)
def hoistObjs = svcs.collectMany { _, svc ->
[
new ClusterObjectInfo(name: svc.class.name, type: 'Service', target: svc),
*svc.resources
.findAll { k, v -> v instanceof AdminStats }
.collect { k, v -> new ClusterObjectInfo(name: svc.hzName(k), target: v) }
]
}

// Hazelcast built-ins
def hzObjs = clusterService
.hzInstance
.distributedObjects
.findAll { !(it instanceof ExecutorServiceProxy) }
.collect { new ClusterObjectInfo(target: new HzAdminStats(it)) }

return (hzObjs + hoistObjs) as List<ClusterObjectInfo>
}

static class ListClusterObjects extends ClusterRequest<List<ClusterObjectInfo>> {
List<ClusterObjectInfo> doCall() {
appContext.clusterObjectsService.listClusterObjects()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package io.xh.hoist.admin

import io.xh.hoist.BaseService
import io.xh.hoist.exception.DataNotAvailableException
import io.xh.hoist.util.DateTimeUtils
import org.apache.tomcat.jdbc.pool.DataSource as PooledDataSource
import org.apache.tomcat.jdbc.pool.PoolConfiguration
import org.springframework.boot.jdbc.DataSourceUnwrapper
Expand Down Expand Up @@ -37,7 +36,7 @@ class ConnectionPoolMonitoringService extends BaseService {
createTimer(
name: 'takeSnapshot',
runFn: this.&takeSnapshot,
interval: {enabled ? config.snapshotInterval * DateTimeUtils.SECONDS: -1}
interval: {enabled ? config.snapshotInterval * SECONDS: -1}
)
}

Expand Down

This file was deleted.

Loading