Skip to content
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 @@ -423,6 +423,14 @@ public long getJNStartedTimeInMillis() {
return this.startTime;
}

@Override
// JournalNodeMXBean
public List<String> getStorageInfos() {
return journalsById.values().stream()
.map(journal -> journal.getStorage().toMapString())
.collect(Collectors.toList());
}

/**
* Register JournalNodeMXBean
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,13 @@ public interface JournalNodeMXBean {
* @return the start time of the JournalNode.
*/
long getJNStartedTimeInMillis();

/**
* Get the list of the storage infos of JournalNode's journals. Storage infos
* include layout version, namespace id, cluster id and creation time of the
* File system state.
*
* @return the list of storage infos associated with journals.
*/
List<String> getStorageInfos();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.SortedSet;
Expand Down Expand Up @@ -112,6 +113,20 @@ public String toString() {
.append(";nsid=").append(namespaceID).append(";c=").append(cTime);
return sb.toString();
}

/**
* Returns string representation of Storage info attributes stored in Map.
*
* @return string representation of storage info attributes.
*/
public String toMapString() {
Map<String, Object> storageInfo = new HashMap<>();
storageInfo.put("LayoutVersion", layoutVersion);
storageInfo.put("ClusterId", clusterID);
storageInfo.put("NamespaceId", namespaceID);
storageInfo.put("CreationTime", cTime);
return storageInfo.toString();
}

public String toColonSeparatedString() {
return Joiner.on(":").join(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class TestJournalNodeMXBean {

private static final String NAMESERVICE = "ns1";
private static final int NUM_JN = 1;
private static final int NS_ID = 12345;

private MiniJournalCluster jCluster;
private JournalNode jn;
Expand Down Expand Up @@ -80,9 +81,8 @@ public void testJournalNodeMXBean() throws Exception {
assertFalse(journalStatus.contains(NAMESERVICE));

// format the journal ns1
final NamespaceInfo FAKE_NSINFO = new NamespaceInfo(12345, "mycluster",
"my-bp", 0L);
jn.getOrCreateJournal(NAMESERVICE).format(FAKE_NSINFO, false);
final NamespaceInfo fakeNsInfo = new NamespaceInfo(NS_ID, "mycluster", "my-bp", 0L);
jn.getOrCreateJournal(NAMESERVICE).format(fakeNsInfo, false);

// check again after format
// getJournalsStatus
Expand All @@ -109,6 +109,11 @@ public void testJournalNodeMXBean() throws Exception {
assertEquals(jn.getJNStartedTimeInMillis(), startTime);
String version = (String) mbs.getAttribute(mxbeanName, "Version");
assertEquals(jn.getVersion(), version);
String[] journalStorageInfos = (String[]) mbs.getAttribute(mxbeanName, "StorageInfos");
assertEquals(jn.getStorageInfos().size(), journalStorageInfos.length);
assertTrue(journalStorageInfos[1].contains("ClusterId=mycluster"));
assertTrue(journalStorageInfos[1].contains("CreationTime=0"));
assertTrue(journalStorageInfos[1].contains("NamespaceId=" + NS_ID));

// restart journal node without formatting
jCluster = new MiniJournalCluster.Builder(new Configuration()).format(false)
Expand Down