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

New ViewService + Fix bug with memory monitoring #428

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for blobs that are not owned by the authenticated user? In the context of views, blobs describing "Global" views with null owners?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I was definitely mirrorring the create semantics, which only allow you to create a blob that you own. Will comment that better.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just misunderstood it - looks good to me :)

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
Loading