Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwexler committed Dec 19, 2024
1 parent 1e9db53 commit 9d5256d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
10 changes: 10 additions & 0 deletions grails-app/controllers/io/xh/hoist/impl/XhController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ class XhController extends BaseController {
renderJSON(ret.formatForClient())
}

def findJsonBlob(String type, String name) {
def ret = jsonBlobService.find(type, name)
renderJSON(ret?.formatForClient())
}

def listJsonBlobs(String type, boolean includeValue) {
def ret = jsonBlobService.list(type)
renderJSON(ret*.formatForClient(includeValue))
Expand All @@ -191,6 +196,11 @@ class XhController extends BaseController {
renderJSON(ret.formatForClient())
}

def createOrUpdateJsonBlob(String type, String name, String update) {
def ret = jsonBlobService.createOrUpdate(type, name, parseObject(update))
renderJSON(ret.formatForClient())
}

def archiveJsonBlob(String token) {
def ret = jsonBlobService.archive(token)
renderJSON(ret.formatForClient())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class MemoryMonitoringService extends BaseService {
private Date _lastInfoLogged
private final String blobOwner = 'xhMemoryMonitoringService'
private final static String blobType = isProduction ? 'xhMemorySnapshots' : "xhMemorySnapshots_$appEnvironment"
private String blobToken

void init() {
createTimer(
Expand Down Expand Up @@ -211,19 +210,14 @@ class MemoryMonitoringService extends BaseService {

private void persistSnapshots() {
try {
if (blobToken) {
jsonBlobService.update(blobToken, [value: snapshots], blobOwner)
} else {
def blob = jsonBlobService.create([
name : clusterService.instanceName,
type : blobType,
value: snapshots
], blobOwner)
blobToken = blob.token
}
jsonBlobService.createOrUpdate(
blobType,
clusterService.instanceName,
[value: snapshots],
blobOwner
)
} catch (Exception e) {
logError('Failed to persist memory snapshots', e)
blobToken = null
}
}

Expand Down
32 changes: 24 additions & 8 deletions grails-app/services/io/xh/hoist/jsonblob/JsonBlobService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class JsonBlobService extends BaseService implements DataBinder {
return ret
}

@ReadOnly
JsonBlob find(String type, String name, String username = username) {
JsonBlob.findByTypeAndNameAndOwnerAndArchivedDate(type, name, username, 0)
}

@ReadOnly
List<JsonBlob> list(String type, String username = username) {
JsonBlob
Expand All @@ -48,15 +53,15 @@ class JsonBlobService extends BaseService implements DataBinder {
@Transactional
JsonBlob update(String token, Map data, String username = username) {
def blob = get(token, username)
if (data) {
data = [*: data, lastUpdatedBy: username]
if (data.containsKey('value')) data.value = serialize(data.value)
if (data.containsKey('meta')) data.meta = serialize(data.meta)
return updateInternal(blob, data, username)
}

bindData(blob, data)
blob.save()
}
return blob
@Transactional
JsonBlob createOrUpdate(String type, String name, Map data, String username = username) {
def blob = find(type, name, username)
return blob ?
updateInternal(blob, data, username) :
create([*: data, type: type, name: name, owner: username], username)
}

@Transactional
Expand All @@ -71,6 +76,17 @@ class JsonBlobService extends BaseService implements DataBinder {
//-------------------------
// Implementation
//-------------------------
private JsonBlob updateInternal(JsonBlob blob, Map data, String username) {
if (!data) return blob
data = [*: data, lastUpdatedBy: username]
if (data.containsKey('value')) data.value = serialize(data.value)
if (data.containsKey('meta')) data.meta = serialize(data.meta)

bindData(blob, data)
blob.save()
return blob
}

private boolean passesAcl(JsonBlob blob, String username) {
return blob.acl == '*' || blob.owner == username
}
Expand Down

0 comments on commit 9d5256d

Please sign in to comment.