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

add possibility to filter by ledger state #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions web/src/main/bvmui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint --no-fix",
"lint:fix": "vue-cli-service lint --fix",
"test": "vue-cli-service test:unit -i"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion web/src/main/bvmui/src/components/Ledger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
},
computed: {
rootClasses() {
return ["bvm-tile", this.ledger.state == "CLOSED" ? "closed" : ""];
return ["bvm-tile", this.ledger.state === "CLOSED" ? "closed" : ""];
},
computedAge() {
const countHours = Math.floor(this.ledger.age / 60);
Expand Down
3 changes: 1 addition & 2 deletions web/src/main/bvmui/src/components/MetadataContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ export default {
const arr = []
arr.push({ title: 'Description', value: this.currentLedger.description })
arr.push({ title: 'Cluster', value: this.currentLedger.clusterName })
arr.push({ title: 'Age', value: this.$library.formatLedgerAge(this.currentLedger.age) })
arr.push({ title: 'Age', value: this.$library.formatTimeFromMinutes(this.currentLedger.age) })
arr.push({ title: 'Created at', value: this.$library.formatDate(this.currentLedger.ctime) })
arr.push({ title: 'State', value: this.currentLedger.state })
arr.push({ title: 'Size', value: this.$library.formatBytes(this.currentLedger.length) })
arr.push({ title: 'LastEntryId', value: this.currentLedger.lastEntryId })
arr.push({ title: 'Password', value: this.currentLedger.password })
arr.push({ title: 'DigestType', value: this.currentLedger.digestType })
arr.push({ title: 'Closed', value: this.currentLedger.closed })
arr.push({ title: 'MetadataFormatVersion', value: this.currentLedger.metadataFormatVersion })
arr.push({ title: 'Ensemble size (bookies)', value: this.currentLedger.ensembleSize })
arr.push({ title: 'Write quorum size (copies)', value: this.currentLedger.ensembleSize })
Expand Down
50 changes: 44 additions & 6 deletions web/src/main/bvmui/src/components/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
<template>
<v-app-bar app clipped-left color="primary">
<v-app-bar-nav-icon v-show="$store.state.showDrawer" class="white--text" @click="toggleDrawer" />
<span class="title ml-3 mr-5 white--text">
<v-app-bar app clipped-left color="primary">
<v-app-bar-nav-icon v-show="$store.state.showDrawer" class="white--text" @click="toggleDrawer" />
<span class="title ml-3 mr-5 white--text">
Bookkeeper
&nbsp;<span class="font-weight-light">Visual Manager</span>
&nbsp;<span v-if="pageTitle" class="title">- {{ pageTitle }}</span>
</span>
</v-app-bar>

<v-spacer />
<v-btn small v-show="lastCacheRefreshStr" @click="refreshCache" :disabled="status !== 'IDLE'" color="primary">
Last refresh: {{ lastCacheRefreshStr }}
<v-icon right>
mdi-cached
</v-icon>
</v-btn>
</v-app-bar>
</template>
<script>
export default {
props: {
pageTitle: String
},
data() {
return {
status: "unknown",
lastCacheRefreshStr: '',
}
},
created() {
this.updateInfo();
},
beforeDestroy() {
if (this.interval) {
clearInterval(this.interval);
}
},
methods: {
toggleDrawer() {
this.$store.commit('toggleDrawer');
},
showDrawer() {
this.$store.getters.showDrawer;
refreshCache() {
this.$request.get("api/cache/refresh").then(
cacheInfo => {
this.status = cacheInfo.status;
this.lastCacheRefreshStr = this.$library.formatTimeDiff(Date.now() - cacheInfo.lastCacheRefresh);
}
);
},
updateInfo() {
this.$request.get("api/cache/info").then(
cacheInfo => {
this.status = cacheInfo.status;
this.lastCacheRefreshStr = this.$library.formatTimeDiff(Date.now() - cacheInfo.lastCacheRefresh);
if (!this.interval) {
this.interval = setInterval(this.updateInfo, 900);
}
}
);
}
}
};
Expand Down
21 changes: 18 additions & 3 deletions web/src/main/bvmui/src/lib/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
removeDoubleQuote(message) {
return message.replace(/['"]+/g, '');
},
formatLedgerAge(ageInMinutes) {
formatTimeFromMinutes(ageInMinutes) {
if (ageInMinutes > 60) {
if (ageInMinutes > 60 * 24) {
return Math.floor(ageInMinutes / (60 * 24)) + " days";
Expand All @@ -41,6 +41,21 @@ export default {
}
return ageInMinutes + " minutes";
},


formatTimeDiff(timeMillis) {
if (timeMillis < 1000) {
return "1 second ago"
}
const seconds = Math.ceil(timeMillis / 1000)
if (seconds === 1) {
return "1 second ago"
}
if (seconds < 60) {
return seconds + " seconds ago"
}
const minutes = Math.ceil(seconds / 60)
if (minutes === 1) {
return "1 minute ago"
}
return minutes + " minutes ago"
},
}
37 changes: 29 additions & 8 deletions web/src/main/bvmui/src/views/Ledgers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,44 @@
flat
hide-details
@keydown.enter="performSearch" />
<v-select
label="State"
class="pr-5"
variant="outlined"
v-model="state"
tile
flat
:items="['ANY', 'OPEN', 'CLOSED', 'IN_RECOVERY']"
@change="performSearch"
/>
<v-text-field
v-model="minLength"
class="pr-5"
label="Min size (bytes)"
label="Min size"
suffix="MB"
tile
type="number"
flat
hide-details
@keydown.enter="performSearch" />
<v-text-field
v-model="maxLength"
class="pr-5"
label="Max size (bytes)"
label="Max size"
type="number"
suffix="MB"
tile
flat
hide-details
@keydown.enter="performSearch" />
<v-text-field
v-model="minAge"
class="pr-5"
label="Older than (minutes)"
label="Older than"
tile
type="number"
flat
suffix="Minutes"
hide-details
@keydown.enter="performSearch" />
<v-btn
Expand Down Expand Up @@ -127,9 +143,10 @@ export default {
search: false,
searchTerm: '',
ledgerIds: '',
state: 'ANY',
minLength: '',
maxLength: '',
minAge: 0,
minAge: '',
showLedgerMetadata: false,
currentLedger: null,
ledgers: [],
Expand Down Expand Up @@ -163,9 +180,12 @@ export default {
if (this.search) {
params.term = this.searchTerm;
params.ledgerIds = this.ledgerIds;
params.minLength = this.minLength;
params.maxLength = this.maxLength;
params.minAge = this.minAge;
if (this.state !== "ANY") {
params.state = this.state;
}
params.minLength = this.minLength > 0 ? Math.ceil(this.minLength * 1024 * 1024) : '';
params.maxLength = this.maxLength > 0 ? Math.ceil(this.maxLength * 1024 * 1024) : '';
params.minAge = !this.minAge ? 0 : this.minAge;
}
if (this.$route.meta.type === "bookie") {
const { bookieId, clusterId } = this.$route.params;
Expand Down Expand Up @@ -209,9 +229,10 @@ export default {
async clearSearch() {
this.searchTerm = '';
this.ledgerIds = '';
this.state = "ANY";
this.minLength = '';
this.maxLength = '';
this.minAge = 0;
this.minAge = '';

this.search = false;
this.closeMetadata();
Expand Down
18 changes: 13 additions & 5 deletions web/src/main/java/org/bkvm/api/resources/LedgersResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public GetLedgersResult getLedgers(@QueryParam("term") String term,
@QueryParam("minLength") String minLength,
@QueryParam("maxLength") String maxLength,
@QueryParam("minAge") String minAge,
@QueryParam("state") String state,
@QueryParam("page") int page,
@QueryParam("size") int size
) throws Exception {
Expand All @@ -85,7 +86,8 @@ public GetLedgersResult getLedgers(@QueryParam("term") String term,
.searchLedgers(term,
bookieId, convertParamInt(clusterId),
searchLedgerIds, convertParamInt(minLength),
convertParamInt(maxLength), convertParamInt(minAge)
convertParamInt(maxLength), convertParamInt(minAge),
state == null || state.trim().equals("") ? null : state
);

List<LedgerBean> allLedgers = new ArrayList<>();
Expand Down Expand Up @@ -140,8 +142,7 @@ private LedgerBean convertLedgerBean(int clusterId, String clusterName, long led
b.setPassword(ledgerMetadata.hasPassword() ? new String(ledgerMetadata.getPassword(), StandardCharsets.UTF_8) : "");
b.setDigestType(ledgerMetadata.getDigestType() + "");
b.setCtime(ledgerMetadata.getCtime());
b.setClosed(ledgerMetadata.isClosed());
b.setState(ledgerMetadata.getState() + "");
b.setState(ledgerMetadata.getState() == null ? LedgerBean.State.UNKNOWN : LedgerBean.State.valueOf(ledgerMetadata.getState().name()));
b.setMetadataFormatVersion(ledgerMetadata.getMetadataFormatVersion());
b.setEnsembles(new HashMap<>(BookkeeperManager.buildEnsembleMap(ledgerMetadata)));
return b;
Expand Down Expand Up @@ -184,6 +185,14 @@ private static List<Long> convertParamLongList(String s) throws NumberFormatExce
@Data
public static final class LedgerBean {

public enum State {
OPEN,
IN_RECOVERY,
CLOSED,
UNKNOWN
}


private int clusterId;
private String clusterName;
private long id;
Expand All @@ -198,8 +207,7 @@ public static final class LedgerBean {
private String password;
private String digestType;
private long ctime;
private boolean closed;
private String state;
private State state;
private int metadataFormatVersion;
private Map<Long, List<String>> ensembles;

Expand Down
7 changes: 6 additions & 1 deletion web/src/main/java/org/bkvm/bookkeeper/BookkeeperManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ public void doRefreshMetadataCache() {
deletedLedgers.remove(ledgerId);
Ledger ledger = new Ledger(ledgerId, clusterId,
ledgerMetadata.getLength(),
ledgerMetadata.getState() == null ? null : ledgerMetadata.getState().name(),
new java.sql.Timestamp(ledgerMetadata.getCtime()),
new java.sql.Timestamp(System.currentTimeMillis()),
Base64.getEncoder().encodeToString(serDe.serialize(ledgerMetadata)));
Expand Down Expand Up @@ -438,11 +439,15 @@ public List<Map.Entry<Integer, Long>> searchLedgers(String term,
List<Long> ledgerIds,
Integer minLength,
Integer maxLength,
Integer minAge) throws BookkeeperManagerException {
Integer minAge,
String state) {
return metadataCache
.searchLedgers(term, bookieId, clusterId, ledgerIds)
.stream()
.filter(l -> {
if (state != null && !state.equalsIgnoreCase(l.getState())) {
return false;
}
if (minLength != null && l.getSize() < minLength) {
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion web/src/main/java/org/bkvm/cache/Ledger.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,23 @@ public class Ledger implements Serializable {
@Column(columnDefinition = "timestamp")
private java.sql.Timestamp scanTime;

@Column(columnDefinition = "string")
private String state;

@Column(columnDefinition = "string")
private String serializedMetadata;

public Ledger() {
}

public Ledger(long ledgerId, int clusterId, long size, Timestamp ctime, Timestamp scanTime, String serializedMetadata) {
public Ledger(long ledgerId, int clusterId, long size, String state, Timestamp ctime, Timestamp scanTime, String serializedMetadata) {
this.ledgerId = ledgerId;
this.clusterId = clusterId;
this.size = size;
this.ctime = ctime;
this.scanTime = scanTime;
this.serializedMetadata = serializedMetadata;
this.state = state;
}

public long getAge() {
Expand Down
6 changes: 3 additions & 3 deletions web/src/test/java/org/bkvm/cache/MetadataCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void test() {
datasource.setUrl("jdbc:herddb:local");
int clusterId = 1234;
try (MetadataCache metadataCache = new MetadataCache(datasource)) {
Ledger ledger = new Ledger(1, clusterId, 1024, new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
Ledger ledger = new Ledger(1, clusterId, 1024, "OPEN", new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
List<LedgerBookie> lb = new ArrayList<>();
lb.add(new LedgerBookie(1, "localhost:1234", clusterId));
lb.add(new LedgerBookie(1, "localhost:1235", clusterId));
Expand Down Expand Up @@ -86,7 +86,7 @@ public void test() {
assertEquals(1, ledgersByKeyAndValue4.size());

// UPDATE, just the size
Ledger ledger2 = new Ledger(1, clusterId, 2048, new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
Ledger ledger2 = new Ledger(1, clusterId, 2048, "OPEN", new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
metadataCache.updateLedger(ledger2, lb, entries);
List<Ledger> ledgers2 = metadataCache.listLedgers();
assertEquals(1, ledgers2.size());
Expand All @@ -101,7 +101,7 @@ public void test() {
assertEquals(0, metadataCache.getLedgersForBookie(clusterId, "localhost:1236").size());

// UPDATE, re-replication moved data to another bookie
Ledger ledger2rewritten = new Ledger(1, clusterId, 2048, new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
Ledger ledger2rewritten = new Ledger(1, clusterId, 2048, "OPEN", new java.sql.Timestamp(System.currentTimeMillis()), new java.sql.Timestamp(System.currentTimeMillis()), "");
List<LedgerBookie> lb2 = new ArrayList<>();
lb2.add(new LedgerBookie(1, "localhost:1234", clusterId));
lb2.add(new LedgerBookie(1, "localhost:1236", clusterId));
Expand Down
Loading