Package org.qzerver.model.domain.entities.cluster

Examples of org.qzerver.model.domain.entities.cluster.ClusterGroup


            ClusterGroup.class, clusterGroup);
    }

    @Test
    public void testClusterNodeDao() throws Exception {
        ClusterGroup clusterGroup = new ClusterGroup();
        clusterGroup.setName("dgfsrgw");
        clusterGroup.setRollingIndex(2);
        businessEntityDao.save(clusterGroup);

        ClusterNode clusterNode = new ClusterNode();
        clusterNode.setAddress("www.example.org");
        clusterNode.setEnabled(false);
        clusterNode.setDescription("rwgwrgwr");

        clusterNode.setGroup(clusterGroup);
        clusterGroup.getNodes().add(clusterNode);

        BusinessEntityJpaDaoChecker.checkBusinessEntityDao(entityManager, businessEntityDao,
                ClusterNode.class, clusterNode);
    }
View Full Code Here


    @Test
    public void testRollIndex() throws Exception {
        // Create group and nodes

        ClusterGroup clusterGroup = clusterManagementService.createGroup("Test group");
        Assert.assertNotNull(clusterGroup);
        Assert.assertEquals(0, clusterGroup.getRollingIndex());

        ClusterNode clusterNode1 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.1", "Node 1", true);
        Assert.assertNotNull(clusterNode1);

        ClusterNode clusterNode2 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.2", "Node 2", true);
        Assert.assertNotNull(clusterNode2);

        ClusterNode clusterNode3 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.3", "Node 3", false);
        Assert.assertNotNull(clusterNode3);

        ClusterNode clusterNode4 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.4", "Node 4", true);
        Assert.assertNotNull(clusterNode4);

        ClusterNode clusterNode5 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.5", "Node 5", false);
        Assert.assertNotNull(clusterNode5);

        // Roll index

        int index;

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(1, index);

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(3, index);

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(0, index);

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(1, index);

        // Toggle nodes and roll

        clusterManagementService.modifyNode(clusterNode3.getId(), "10.2.0.3", "Node 3", true);
        clusterManagementService.modifyNode(clusterNode4.getId(), "10.2.0.4", "Node 4", false);

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(2, index);

        index = clusterManagementService.rollGroupIndex(clusterGroup.getId());
        Assert.assertEquals(0, index);
    }
View Full Code Here

    @Test
    public void testDeleteAssignedGroup() throws Exception {
        // Create cluster group and nodes

        ClusterGroup clusterGroup = clusterManagementService.createGroup("Test group");
        Assert.assertNotNull(clusterGroup);
        Assert.assertEquals(0, clusterGroup.getRollingIndex());

        ClusterNode clusterNode1 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.1", "Node 1", true);
        Assert.assertNotNull(clusterNode1);

        ClusterNode clusterNode2 = clusterManagementService.createNode(clusterGroup.getId(),
            "10.2.0.2", "Node 2", true);
        Assert.assertNotNull(clusterNode2);

        // Create scheduled job

        ScheduleGroup scheduleGroup = scheduleJobManagementService.createGroup("Test group");
        Assert.assertNotNull(scheduleGroup);

        ScheduleJobCreateParameters jobParameters = new ScheduleJobCreateParameters();
        jobParameters.setName("Test Job");
        jobParameters.setDescription("Nothing to do");
        jobParameters.setTimezone("UTC");
        jobParameters.setCron("0 0 0 * * ?");
        jobParameters.setEnabled(true);
        jobParameters.setClusterGroupId(clusterGroup.getId());
        jobParameters.setScheduleGroupId(scheduleGroup.getId());
        jobParameters.setStrategy(ScheduleExecutionStrategy.CIRCULAR);
        jobParameters.setActionIdentifier("action.type");
        jobParameters.setActionDefinition("action.data".getBytes());

        ScheduleJob scheduleJob = scheduleJobManagementService.createJob(jobParameters);
        Assert.assertNotNull(scheduleJob);

        // Try to delete assigned jobs

        entityManager.flush();
        entityManager.clear();

        try {
            clusterManagementService.deleteGroup(clusterGroup.getId());
            Assert.fail("Exception is expected");
        } catch (ClusterGroupUsed e) {
            // do nothing
        }
    }
View Full Code Here

    @Override
    public ScheduleJob createJob(ScheduleJobCreateParameters parameters) {
        BeanValidationUtils.checkValidity(parameters, beanValidator);

        ClusterGroup clusterGroup = null;
        if (parameters.getClusterGroupId() != null) {
            clusterGroup = businessEntityDao.findById(ClusterGroup.class, parameters.getClusterGroupId());
            if (clusterGroup == null) {
                throw new MissingEntityException(ClusterGroup.class, parameters.getClusterGroupId());
            }
View Full Code Here

    @Override
    public ClusterGroup createGroup(String name) {
        Preconditions.checkNotNull(name);

        ClusterGroup clusterGroup = new ClusterGroup();
        clusterGroup.setName(name);
        clusterGroup.setRollingIndex(0);

        businessEntityDao.save(clusterGroup);

        return clusterGroup;
    }
View Full Code Here

    @Override
    public ClusterGroup modifyGroup(long clusterGroupId, String name) {
        Preconditions.checkNotNull(name);

        ClusterGroup clusterGroup = businessEntityDao.lockById(ClusterGroup.class, clusterGroupId);
        if (clusterGroup == null) {
            throw new MissingEntityException(ClusterGroup.class, clusterGroupId);
        }

        clusterGroup.setName(name);

        return clusterGroup;
    }
View Full Code Here

    }

    @Override
    @Transactional(readOnly = true)
    public ClusterGroup findGroup(long clusterGroupId) {
        ClusterGroup clusterGroup = businessEntityDao.findById(ClusterGroup.class, clusterGroupId);
        if (clusterGroup != null) {
            Hibernate.initialize(clusterGroup.getNodes());
        }
        return clusterGroup;
    }
View Full Code Here

        return clusterGroup;
    }

    @Override
    public int rollGroupIndex(long clusterGroupId) {
        ClusterGroup clusterGroup = businessEntityDao.lockById(ClusterGroup.class, clusterGroupId);
        if (clusterGroup == null) {
            throw new MissingEntityException(ClusterGroup.class, clusterGroupId);
        }

        int currentIndex = clusterGroup.getRollingIndex();

        for (int i = currentIndex + 1, size = clusterGroup.getNodes().size(); i < size; i++) {
            ClusterNode clusterNode = clusterGroup.getNodes().get(i);
            if (clusterNode.isEnabled()) {
                clusterGroup.setRollingIndex(i);
                return i;
            }
        }

        for (int i = 0; i < currentIndex; i++) {
            ClusterNode clusterNode = clusterGroup.getNodes().get(i);
            if (clusterNode.isEnabled()) {
                clusterGroup.setRollingIndex(i);
                return i;
            }
        }

        return currentIndex;
View Full Code Here

            }
            return result;
        }

        // If cluster is set then choose some nodes to work on
        ClusterGroup clusterGroup = scheduleJob.getCluster();
        if (clusterGroup != null) {
            List<ClusterNode> selectedNodes = selectClusterNodes(scheduleJob);
            List<ScheduleExecutionNode> result = new ArrayList<ScheduleExecutionNode>(selectedNodes.size());
            for (int i = 0, size = selectedNodes.size(); i < size; i++) {
                ClusterNode clusterNode = selectedNodes.get(i);
View Full Code Here

        executionNode.setAddress("localhost");
        return Collections.singletonList(executionNode);
    }

    private List<ClusterNode> selectClusterNodes(ScheduleJob scheduleJob) {
        ClusterGroup clusterGroup = scheduleJob.getCluster();

        List<ClusterNode> selectedNodes;

        // Choose nodes depending on the selection strategy
        switch (scheduleJob.getStrategy()) {
View Full Code Here

TOP

Related Classes of org.qzerver.model.domain.entities.cluster.ClusterGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.