Search in sources :

Example 1 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PulseControllerJUnitTest method setup.

@Before
public void setup() throws Exception {
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    cluster = Mockito.spy(Cluster.class);
    Cluster.Region region = new Cluster.Region();
    region.setName(REGION_NAME);
    region.setFullPath(REGION_PATH);
    region.setRegionType(REGION_TYPE);
    region.setMemberCount(1);
    region.setMemberName(new ArrayList<String>() {

        {
            add(MEMBER_NAME);
        }
    });
    region.setPutsRate(12.31D);
    region.setGetsRate(27.99D);
    Cluster.RegionOnMember regionOnMember = new Cluster.RegionOnMember();
    regionOnMember.setRegionFullPath(REGION_PATH);
    regionOnMember.setMemberName(MEMBER_NAME);
    region.setRegionOnMembers(new ArrayList<Cluster.RegionOnMember>() {

        {
            add(regionOnMember);
        }
    });
    cluster.addClusterRegion(REGION_PATH, region);
    Cluster.Member member = new Cluster.Member();
    member.setId(MEMBER_ID);
    member.setName(MEMBER_NAME);
    member.setUptime(1L);
    member.setHost(PHYSICAL_HOST_NAME);
    member.setGemfireVersion(GEMFIRE_VERSION);
    member.setCpuUsage(55.77123D);
    member.setMemberRegions(new HashMap<String, Cluster.Region>() {

        {
            put(REGION_NAME, region);
        }
    });
    Cluster.AsyncEventQueue aeq = new Cluster.AsyncEventQueue();
    aeq.setAsyncEventListener(AEQ_LISTENER);
    member.setAsyncEventQueueList(new ArrayList() {

        {
            add(aeq);
        }
    });
    Cluster.Client client = new Cluster.Client();
    client.setId("100");
    client.setName(CLIENT_NAME);
    client.setUptime(1L);
    member.setMemberClientsHMap(new HashMap<String, Cluster.Client>() {

        {
            put(CLIENT_NAME, client);
        }
    });
    cluster.setMembersHMap(new HashMap() {

        {
            put(MEMBER_NAME, member);
        }
    });
    cluster.setPhysicalToMember(new HashMap() {

        {
            put(PHYSICAL_HOST_NAME, new ArrayList() {

                {
                    add(member);
                }
            });
        }
    });
    cluster.setServerName(CLUSTER_NAME);
    cluster.setMemoryUsageTrend(new CircularFifoBuffer() {

        {
            add(1);
            add(2);
            add(3);
        }
    });
    cluster.setWritePerSecTrend(new CircularFifoBuffer() {

        {
            add(1.29);
            add(2.3);
            add(3.0);
        }
    });
    cluster.setThroughoutReadsTrend(new CircularFifoBuffer() {

        {
            add(1);
            add(2);
            add(3);
        }
    });
    cluster.setThroughoutWritesTrend(new CircularFifoBuffer() {

        {
            add(4);
            add(5);
            add(6);
        }
    });
    Repository repo = Mockito.spy(Repository.class);
    // Set up a partial mock for some static methods
    spy(Repository.class);
    when(Repository.class, "get").thenReturn(repo);
    doReturn(cluster).when(repo).getCluster();
    PulseConfig config = new PulseConfig();
    File tempQueryLog = tempFolder.newFile("query_history.log");
    config.setQueryHistoryFileName(tempQueryLog.toString());
    doReturn(config).when(repo).getPulseConfig();
    PulseController.pulseVersion.setPulseVersion("not empty");
    PulseController.pulseVersion.setPulseBuildId("not empty");
    PulseController.pulseVersion.setPulseBuildDate("not empty");
    PulseController.pulseVersion.setPulseSourceDate("not empty");
    PulseController.pulseVersion.setPulseSourceRevision("not empty");
    PulseController.pulseVersion.setPulseSourceRepository("not empty");
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) Matchers.anyString(org.mockito.Matchers.anyString) CircularFifoBuffer(org.apache.commons.collections.buffer.CircularFifoBuffer) Repository(org.apache.geode.tools.pulse.internal.data.Repository) PulseConfig(org.apache.geode.tools.pulse.internal.data.PulseConfig) File(java.io.File) Before(org.junit.Before)

Example 2 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class PropMockDataUpdater method updateData.

/**
   * function used for updating Cluster data for Mock
   */
@Override
public boolean updateData() {
    cluster.setConnectedFlag(true);
    Random r = new Random(System.currentTimeMillis());
    long totalHeapSize = Math.abs(r.nextInt(3200 - 2048) + 2048);
    cluster.setTotalHeapSize(totalHeapSize);
    long usedHeapSize = Math.abs(r.nextInt(2048));
    cluster.setUsedHeapSize(usedHeapSize);
    double writePerSec = Math.abs(r.nextInt(100));
    cluster.setWritePerSec(writePerSec);
    // propfile
    cluster.setSubscriptionCount(testbed.getRootDs().getClients().size());
    cluster.setRegisteredCQCount((long) testbed.getRootDs().getCQs().size());
    cluster.setRunningFunctionCount(testbed.getRootDs().getFunction().size());
    cluster.setClusterId(Math.abs(r.nextInt(100)));
    cluster.getWritePerSecTrend().add(writePerSec);
    cluster.setDiskWritesRate(writePerSec);
    long garbageCollectionCount = Math.abs(r.nextInt(100));
    cluster.setGarbageCollectionCount(garbageCollectionCount);
    cluster.getGarbageCollectionTrend().add(garbageCollectionCount);
    long readPerSec = Math.abs(r.nextInt(100));
    cluster.setReadPerSec(readPerSec);
    cluster.getReadPerSecTrend().add(readPerSec);
    long diskReadsRate = readPerSec;
    cluster.setDiskReadsRate(diskReadsRate);
    cluster.setDiskReadsRate(readPerSec);
    long queriesPerSec = Math.abs(r.nextInt(100));
    cluster.setQueriesPerSec(queriesPerSec);
    cluster.getQueriesPerSecTrend().add(queriesPerSec);
    long loadPerSec = Math.abs(r.nextInt(100));
    cluster.setLoadPerSec(loadPerSec);
    cluster.setTotalHeapSize(totalHeapSize);
    long totalBytesOnDisk = totalHeapSize;
    cluster.setTotalBytesOnDisk(totalBytesOnDisk);
    cluster.getTotalBytesOnDiskTrend().add(totalBytesOnDisk);
    cluster.getMemoryUsageTrend().add(usedHeapSize);
    cluster.getThroughoutWritesTrend().add(writePerSec);
    cluster.setMemberCount(0);
    Map<String, Cluster.Member> membersHMap = cluster.getMembersHMap();
    List<Cluster.Region> regionsList = (List<Cluster.Region>) cluster.getClusterRegions().values();
    Map<String, Boolean> wanInformation = cluster.getWanInformation();
    // Create 3 members first time around
    int locatorCount = 0;
    if (membersHMap.size() == 0) {
        for (Locator locator : testbed.getRootDs().getLocators()) {
            String id = "(Launcher_Locator-1099-13-40-24-5368)-" + locatorCount++;
            String name = locator.getName();
            membersHMap.put(id + name, initializeMember(id, name, true, true, true, false, locator.getHost()));
        }
        cluster.setLocatorCount(testbed.getRootDs().getLocators().size());
        int serverCount = 0;
        for (Server server : testbed.getRootDs().getServers()) {
            String id = "(Launcher_Server-1099-13-40-24-5368)-" + serverCount++;
            String name = server.getName();
            membersHMap.put(id + name, initializeMember(id, name, false, true, false, true, server.getHost()));
        }
        cluster.setServerCount(testbed.getRootDs().getServers().size());
        int peerCount = 0;
        for (Peer peer : testbed.getRootDs().getPeers()) {
            String id = "(Launcher_Peer-1099-13-40-24-5368)-" + peerCount++;
            String name = peer.getName();
            membersHMap.put(id + name, initializeMember(id, name, false, true, false, false, peer.getHost()));
        }
        for (Entry<String, Member> memberSet : membersHMap.entrySet()) {
            HashMap<String, Cluster.Region> memberRegions = new HashMap<>();
            HashMap<String, Cluster.Client> memberClientsHM = new HashMap<>();
            Random randomGenerator = new Random();
            // Read from property file
            int randomInt = (randomGenerator.nextInt(5)) + 1;
            List<org.apache.geode.tools.pulse.testbed.GemFireDistributedSystem.Region> thisMemberRegions = testbed.getRootDs().getRegions(memberSet.getValue().getName());
            int regionExists = 0;
            int index = 0;
            for (org.apache.geode.tools.pulse.testbed.GemFireDistributedSystem.Region thisMemberRegion : thisMemberRegions) {
                Region region = initMemberRegion(index++, thisMemberRegion.getName(), memberSet.getValue().getName(), thisMemberRegion.getEntryCount(), thisMemberRegion.getType(), // read from
                thisMemberRegion.getMembers().size());
                // property file
                if (regionsList.size() > 0) {
                    for (Region clusterRegion : regionsList) {
                        if ((region.getName()).equals(clusterRegion.getName())) {
                            clusterRegion.getMemberName().add(memberSet.getValue().getName());
                            // clusterRegion.memberCount = clusterRegion.memberCount + 1;
                            // int mcount = clusterRegion.getMemberCount() + 1;
                            // clusterRegion.setMemberCount(mcount);
                            regionExists = 1;
                            break;
                        }
                    }
                    if (regionExists == 0) {
                        regionsList.add(region);
                    }
                } else {
                    regionsList.add(region);
                }
                memberRegions.put(region.getFullPath(), region);
                // totalRegionCount = regionsList.size();
                cluster.setTotalRegionCount(regionsList.size());
            }
            membersHMap.get(memberSet.getKey()).setMemberRegions(memberRegions);
            if (memberSet.getValue().isCache()) {
                // read from prop
                Client client = initMemberClient(0, memberSet.getValue().getHost());
                // File
                memberClientsHM.put(client.getId(), client);
                randomInt = randomGenerator.nextInt(10);
                for (int y = 1; y < randomInt; y++) {
                    Client newClient = initMemberClient(y, memberSet.getValue().getHost());
                    memberClientsHM.put(newClient.getId(), newClient);
                }
                membersHMap.get(memberSet.getKey()).updateMemberClientsHMap(memberClientsHM);
                /*
           * clientConnectionCount = clientConnectionCount +
           * membersHMap.get(memberSet.getKey()).getMemberClientsHMap().size();
           */
                long clientConnectionCount = cluster.getClientConnectionCount() + membersHMap.get(memberSet.getKey()).getMemberClientsHMap().size();
                cluster.setClientConnectionCount(clientConnectionCount);
            }
        }
    }
    // read from property file
    wanInformation.clear();
    int wanInfoSize = Math.abs(r.nextInt(10));
    wanInfoSize++;
    for (int i = 0; i < wanInfoSize; i++) {
        String name = "Mock Cluster" + i;
        Boolean value = false;
        if (i % 2 == 0) {
            value = true;
        }
        wanInformation.put(name, value);
    }
    // memberCount = membersHMap.size();
    cluster.setMemberCount(membersHMap.size());
    totalHeapSize = 0;
    for (Entry<String, Member> memberSet : membersHMap.entrySet()) {
        refresh(membersHMap.get(memberSet.getKey()));
        Member member = membersHMap.get(memberSet.getKey());
        totalHeapSize += member.getCurrentHeapSize();
    }
    for (Region region : regionsList) {
        region.setGetsRate((Math.abs(r.nextInt(100))) + 1);
        region.setPutsRate((Math.abs(r.nextInt(100))) + 1);
        region.getGetsPerSecTrend().add(region.getGetsRate());
        region.getPutsPerSecTrend().add(region.getPutsRate());
    }
    return true;
}
Also used : Server(org.apache.geode.tools.pulse.testbed.GemFireDistributedSystem.Server) HashMap(java.util.HashMap) Locator(org.apache.geode.tools.pulse.testbed.GemFireDistributedSystem.Locator) Random(java.util.Random) ArrayList(java.util.ArrayList) List(java.util.List) Client(org.apache.geode.tools.pulse.internal.data.Cluster.Client) Member(org.apache.geode.tools.pulse.internal.data.Cluster.Member) Peer(org.apache.geode.tools.pulse.testbed.GemFireDistributedSystem.Peer) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) Region(org.apache.geode.tools.pulse.internal.data.Cluster.Region)

Example 3 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class ClusterMembersRGraphService method execute.

public ObjectNode execute(final HttpServletRequest request) throws Exception {
    // Reference to repository
    Repository repository = Repository.get();
    // get cluster object
    Cluster cluster = repository.getCluster();
    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();
    // cluster's Members
    responseJSON.put(this.CLUSTER, getPhysicalServerJson(cluster, repository.getHost(), repository.getPort()));
    responseJSON.put(this.MEMBER_COUNT, cluster.getMemberCount());
    // Send json response
    return responseJSON;
}
Also used : Repository(org.apache.geode.tools.pulse.internal.data.Repository) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster)

Example 4 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class ClusterMemoryUsageService method execute.

public ObjectNode execute(final HttpServletRequest request) throws Exception {
    // get cluster object
    Cluster cluster = Repository.get().getCluster();
    // json object to be sent as response
    ObjectNode responseJSON = mapper.createObjectNode();
    // cluster's Memory Usage trend added to json response object
    responseJSON.put("currentMemoryUsage", cluster.getUsedHeapSize());
    responseJSON.put("memoryUsageTrend", mapper.valueToTree(cluster.getStatisticTrend(Cluster.CLUSTER_STAT_MEMORY_USAGE)));
    // Send json response
    return responseJSON;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster)

Example 5 with Cluster

use of org.apache.geode.tools.pulse.internal.data.Cluster in project geode by apache.

the class ClusterRegionService method getRegionJson.

/**
   * This method is used to get various regions associated with the given cluster and create json
   * for each region fields and returns Array List for all the regions associated with given cluster
   *
   * @param cluster
   * @return ArrayNode Array List
   */
private ArrayNode getRegionJson(Cluster cluster) {
    Long totalHeapSize = cluster.getTotalHeapSize();
    Long totalDiskUsage = cluster.getTotalBytesOnDisk();
    Map<String, Cluster.Region> clusterRegions = cluster.getClusterRegions();
    List<Cluster.Region> clusterRegionsList = new ArrayList<Cluster.Region>();
    clusterRegionsList.addAll(clusterRegions.values());
    Collections.sort(clusterRegionsList, regionEntryCountComparator);
    ArrayNode regionListJson = mapper.createArrayNode();
    for (int count = 0; count < clusterRegionsList.size(); count++) {
        Cluster.Region reg = clusterRegionsList.get(count);
        ObjectNode regionJSON = mapper.createObjectNode();
        regionJSON.put("name", reg.getName());
        regionJSON.put("totalMemory", totalHeapSize);
        regionJSON.put("systemRegionEntryCount", reg.getSystemRegionEntryCount());
        regionJSON.put("memberCount", reg.getMemberCount());
        final String regionType = reg.getRegionType();
        regionJSON.put("type", regionType);
        regionJSON.put("getsRate", reg.getGetsRate());
        regionJSON.put("putsRate", reg.getPutsRate());
        Cluster.Member[] clusterMembersList = cluster.getMembers();
        ArrayNode memberNameArray = mapper.createArrayNode();
        for (String memberName : reg.getMemberName()) {
            for (Cluster.Member member : clusterMembersList) {
                String name = member.getName();
                name = name.replace(":", "-");
                String id = member.getId();
                id = id.replace(":", "-");
                if ((memberName.equals(id)) || (memberName.equals(name))) {
                    ObjectNode regionMember = mapper.createObjectNode();
                    regionMember.put("id", member.getId());
                    regionMember.put("name", member.getName());
                    memberNameArray.add(regionMember);
                    break;
                }
            }
        }
        regionJSON.put("memberNames", memberNameArray);
        regionJSON.put("entryCount", reg.getSystemRegionEntryCount());
        Boolean persistent = reg.getPersistentEnabled();
        if (persistent) {
            regionJSON.put("persistence", VALUE_ON);
        } else {
            regionJSON.put("persistence", VALUE_OFF);
        }
        Boolean isEnableOffHeapMemory = reg.isEnableOffHeapMemory();
        if (isEnableOffHeapMemory) {
            regionJSON.put("isEnableOffHeapMemory", VALUE_ON);
        } else {
            regionJSON.put("isEnableOffHeapMemory", VALUE_OFF);
        }
        String regCompCodec = reg.getCompressionCodec();
        if (StringUtils.isNotBlank(regCompCodec)) {
            regionJSON.put("compressionCodec", reg.getCompressionCodec());
        } else {
            regionJSON.put("compressionCodec", VALUE_NA);
        }
        regionJSON.put("regionPath", reg.getFullPath());
        regionJSON.put("memoryReadsTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_GETS_PER_SEC_TREND)));
        regionJSON.put("memoryWritesTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_PUTS_PER_SEC_TREND)));
        regionJSON.put("diskReadsTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_READS_PER_SEC_TREND)));
        regionJSON.put("diskWritesTrend", mapper.valueToTree(reg.getRegionStatisticTrend(Cluster.Region.REGION_STAT_DISK_WRITES_PER_SEC_TREND)));
        regionJSON.put("emptyNodes", reg.getEmptyNode());
        Long entrySize = reg.getEntrySize();
        DecimalFormat form = new DecimalFormat(PulseConstants.DECIMAL_FORMAT_PATTERN_2);
        String entrySizeInMB = form.format(entrySize / (1024f * 1024f));
        if (entrySize < 0) {
            regionJSON.put(this.ENTRY_SIZE, VALUE_NA);
        } else {
            regionJSON.put(this.ENTRY_SIZE, entrySizeInMB);
        }
        regionJSON.put("dataUsage", reg.getDiskUsage());
        regionJSON.put("wanEnabled", reg.getWanEnabled());
        regionJSON.put("totalDataUsage", totalDiskUsage);
        regionJSON.put("memoryUsage", entrySizeInMB);
        regionListJson.add(regionJSON);
    }
    return regionListJson;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Cluster(org.apache.geode.tools.pulse.internal.data.Cluster) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

Cluster (org.apache.geode.tools.pulse.internal.data.Cluster)43 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)39 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)18 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 IOException (java.io.IOException)7 DecimalFormat (java.text.DecimalFormat)7 ArrayList (java.util.ArrayList)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Repository (org.apache.geode.tools.pulse.internal.data.Repository)2 File (java.io.File)1 Random (java.util.Random)1 CircularFifoBuffer (org.apache.commons.collections.buffer.CircularFifoBuffer)1 Client (org.apache.geode.tools.pulse.internal.data.Cluster.Client)1 Member (org.apache.geode.tools.pulse.internal.data.Cluster.Member)1 Region (org.apache.geode.tools.pulse.internal.data.Cluster.Region)1