Package org.rhq.enterprise.server.auth

Examples of org.rhq.enterprise.server.auth.SubjectManagerLocal


    }

    @Test
    public void testLinkAgentWithAgentInstall() throws Exception {
        AgentManagerLocal agentManager = LookupUtil.getAgentManager();
        SubjectManagerLocal sm = LookupUtil.getSubjectManager();

        AgentInstall persistedAgentInstall = agentManager.getAgentInstallByAgentName(sm.getOverlord(),
            "should-not-exist");
        assert persistedAgentInstall == null;

        AgentInstall agentInstall = new AgentInstall();
        agentInstall.setSshHost("CoreServerServiceImpl-SshHost");
        agentInstall.setSshPort(44);
        agentInstall.setSshUsername("CoreServerServiceImpl-SshUsername");
        agentInstall.setSshPassword("CoreServerServiceImpl-SshPassword");
        agentInstall = agentManager.updateAgentInstall(sm.getOverlord(), agentInstall);
        assert agentInstall.getId() > 0 : "didn't persist properly - ID should be non-zero";
        assert agentInstall.getAgentName() == null : "there should be no agent name yet";
        assert agentInstall.getInstallLocation() == null : "there should be no install location yet";

        CoreServerServiceImpl service = new CoreServerServiceImpl();
        AgentRegistrationRequest aReq = createRequest(prefixName(".AgentInstall"), A_HOST, A_PORT, null,
            String.valueOf(agentInstall.getId()), "/tmp/CoreServerServiceImplTest/rhq-agent");
        AgentRegistrationResults aResults = service.registerAgent(aReq);
        assert aResults != null : "got null results";

        persistedAgentInstall = agentManager.getAgentInstallByAgentName(sm.getOverlord(), aReq.getName());
        assert persistedAgentInstall != null : "the new agent info is missing";
        assert persistedAgentInstall.getAgentName().equals(aReq.getName());
        assert persistedAgentInstall.getInstallLocation().equals("/tmp/CoreServerServiceImplTest/rhq-agent");
        assert persistedAgentInstall.getSshHost().equals("CoreServerServiceImpl-SshHost");
        assert persistedAgentInstall.getSshPort().equals(44);
        assert persistedAgentInstall.getSshUsername().equals("CoreServerServiceImpl-SshUsername");
        assert persistedAgentInstall.getSshPassword().equals("CoreServerServiceImpl-SshPassword");

        Agent doomed = agentManager.getAgentByName(aReq.getName());
        agentManager.deleteAgent(doomed);
        persistedAgentInstall = agentManager.getAgentInstallByAgentName(sm.getOverlord(), aReq.getName());
        assert persistedAgentInstall == null : "the agent info should have been deleted";
    }
View Full Code Here


    private AlertDefinition injectAlertDef(InjectedTemplate injectedAlertDef, boolean replaceIfExists) {

        AlertDefinition result = null;
        ResourceTypeManagerLocal typeManager = LookupUtil.getResourceTypeManager();
        AlertDefinitionManagerLocal alertDefManager = LookupUtil.getAlertDefinitionManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        ResourceTypeCriteria rtc = new ResourceTypeCriteria();
        rtc.addFilterPluginName(injectedAlertDef.getPluginName());
        rtc.addFilterName(injectedAlertDef.getResourceTypeName());
        rtc.fetchMetricDefinitions(true);
        List<ResourceType> resourceTypes = typeManager.findResourceTypesByCriteria(subjectManager.getOverlord(), rtc);

        if (resourceTypes.isEmpty()) {
            return result;
        }

        assert 1 == resourceTypes.size() : "Found more than 1 resource type!";
        ResourceType resourceType = resourceTypes.get(0);

        AlertDefinitionCriteria adc = new AlertDefinitionCriteria();
        adc.addFilterName(injectedAlertDef.getName());
        adc.addFilterAlertTemplateResourceTypeId(resourceType.getId());
        List<AlertDefinition> alertDefs = alertDefManager.findAlertDefinitionsByCriteria(subjectManager.getOverlord(),
            adc);

        if (!alertDefs.isEmpty()) {
            assert 1 == alertDefs.size() : "Found more than 1 existing alert def!";

            if (!replaceIfExists) {
                return result;
            }

            int[] alertDefIdArray = new int[1];
            alertDefIdArray[0] = alertDefs.get(0).getId();
            alertDefManager.removeAlertDefinitions(subjectManager.getOverlord(), alertDefIdArray);
        }

        int newAlertDefId = 0;

        if (storageNodeHighHeapTemplate.equals(injectedAlertDef)) {
            newAlertDefId = injectStorageNodeHighHeapTemplate(resourceType);
        } else if (storageNodeHighDiskUsageTemplate.equals(injectedAlertDef)) {
            newAlertDefId = injectStorageNodeHighDiskUsageTemplate(resourceType);
        } else if (storageNodeSnapshotFailureTemplate.equals(injectedAlertDef)) {
            newAlertDefId = injectStorageNodeSnapshotFailureTemplate(resourceType);
        } else if (storageNodeMaintenanceOperationsFailureTemplate.equals(injectedAlertDef)) {
            newAlertDefId = injectStorageNodeMaintenanceOperationsFailureTemplate(resourceType);
        }

        adc.addFilterId(newAlertDefId);
        alertDefs = alertDefManager.findAlertDefinitionsByCriteria(subjectManager.getOverlord(), adc);
        assert 1 == alertDefs.size() : "Found more than 1 new alert def!";
        result = alertDefs.get(0);

        return result;
    }
View Full Code Here

        return result;
    }

    private int injectStorageNodeHighHeapTemplate(ResourceType resourceType) {
        AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        AlertDefinition newTemplate = new AlertDefinition();
        newTemplate.setName(storageNodeHighHeapTemplate.getName());
        newTemplate.setResourceType(resourceType);
        newTemplate.setPriority(AlertPriority.MEDIUM);
        newTemplate.setConditionExpression(BooleanExpression.ANY);
        newTemplate.setDescription(storageNodeHighHeapTemplate.getDescription());
        newTemplate.setRecoveryId(0);
        newTemplate.setEnabled(true);

        AlertCondition ac = new AlertCondition();
        ac.setCategory(AlertConditionCategory.THRESHOLD);
        ac.setComparator(">");
        ac.setThreshold(0.75D);

        List<Integer> measurementDefinitionIds = new ArrayList<Integer>(2);
        for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
            if ("Calculated.HeapUsagePercentage".equals(d.getName())) {
                measurementDefinitionIds.add(d.getId());
                ac.setMeasurementDefinition(d);
                ac.setName(d.getDisplayName());
            } else if ("{HeapMemoryUsage.used}".equals(d.getName())) {
                measurementDefinitionIds.add(d.getId());
            }
        }
        assert null != ac.getMeasurementDefinition() : "Did not find expected measurement definition [Calculated.HeapUsagePercentage] for "
            + resourceType;
        newTemplate.addCondition(ac);

        AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
        dampener.setPeriod(15);
        dampener.setPeriodUnits(TimeUnits.MINUTES);
        dampener.setValue(10);
        newTemplate.setAlertDampening(dampener);

        int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
            resourceType.getId());

        // additionally, we want to ensure that the metric is enabled and collecting at a more frequent interval than
        // is set by default.
        MeasurementScheduleManagerLocal measurementManager = LookupUtil.getMeasurementScheduleManager();
        measurementManager.updateDefaultCollectionIntervalAndEnablementForMeasurementDefinitions(
            subjectManager.getOverlord(), ArrayUtils.toPrimitive(measurementDefinitionIds.toArray(new Integer[2])),
            60000L, true, true);

        return newTemplateId;
    }
View Full Code Here

        return newTemplateId;
    }

    private int injectStorageNodeHighDiskUsageTemplate(ResourceType resourceType) {
        AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        AlertDefinition newTemplate = new AlertDefinition();
        newTemplate.setName(storageNodeHighDiskUsageTemplate.getName());
        newTemplate.setResourceType(resourceType);
        newTemplate.setPriority(AlertPriority.MEDIUM);
        newTemplate.setConditionExpression(BooleanExpression.ANY);
        newTemplate.setDescription(storageNodeHighDiskUsageTemplate.getDescription());
        newTemplate.setRecoveryId(0);
        newTemplate.setEnabled(true);


        AlertCondition dataDiskUsedAlertCondition = new AlertCondition();
        dataDiskUsedAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
        dataDiskUsedAlertCondition.setComparator(">");
        dataDiskUsedAlertCondition.setThreshold(0.5D);

        AlertCondition totalDiskUsedAlertCondition = new AlertCondition();
        totalDiskUsedAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
        totalDiskUsedAlertCondition.setComparator(">");
        totalDiskUsedAlertCondition.setThreshold(0.75D);

        AlertCondition freeSpaveDataRatioAlertCondition = new AlertCondition();
        freeSpaveDataRatioAlertCondition.setCategory(AlertConditionCategory.THRESHOLD);
        freeSpaveDataRatioAlertCondition.setComparator("<");
        freeSpaveDataRatioAlertCondition.setThreshold(1.5D);

        List<Integer> measurementDefinitionIds = new ArrayList<Integer>(1);
        for (MeasurementDefinition d : resourceType.getMetricDefinitions()) {
            if (DATA_DISK_USED_PERCENTAGE_METRIC_NAME.equals(d.getName())) {
                measurementDefinitionIds.add(d.getId());
                dataDiskUsedAlertCondition.setMeasurementDefinition(d);
                dataDiskUsedAlertCondition.setName(d.getDisplayName());
            } else if (TOTAL_DISK_USED_PERCENTAGE_METRIC_NAME.equals(d.getName())) {
                measurementDefinitionIds.add(d.getId());
                totalDiskUsedAlertCondition.setMeasurementDefinition(d);
                totalDiskUsedAlertCondition.setName(d.getDisplayName());
            } else if (FREE_DISK_TO_DATA_SIZE_RATIO_METRIC_NAME.equals(d.getName())) {
                measurementDefinitionIds.add(d.getId());
                freeSpaveDataRatioAlertCondition.setMeasurementDefinition(d);
                freeSpaveDataRatioAlertCondition.setName(d.getDisplayName());
            }
        }

        newTemplate.addCondition(dataDiskUsedAlertCondition);
        newTemplate.addCondition(totalDiskUsedAlertCondition);
        newTemplate.addCondition(freeSpaveDataRatioAlertCondition);

        AlertDampening dampener = new AlertDampening(AlertDampening.Category.PARTIAL_COUNT);
        dampener.setPeriod(15);
        dampener.setPeriodUnits(TimeUnits.MINUTES);
        dampener.setValue(10);
        newTemplate.setAlertDampening(dampener);

        int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
            resourceType.getId());

        // additionally, we want to ensure that the metric is enabled and collecting at a more frequent interval than
        // is set by default.
        MeasurementScheduleManagerLocal measurementManager = LookupUtil.getMeasurementScheduleManager();
        measurementManager.updateDefaultCollectionIntervalAndEnablementForMeasurementDefinitions(
            subjectManager.getOverlord(),
            ArrayUtils.toPrimitive(measurementDefinitionIds.toArray(new Integer[measurementDefinitionIds.size()])),
            60000L, true, true);

        return newTemplateId;
    }
View Full Code Here

        return newTemplateId;
    }

    private int injectStorageNodeSnapshotFailureTemplate(ResourceType resourceType) {
        AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        AlertDefinition newTemplate = new AlertDefinition();
        newTemplate.setName(storageNodeSnapshotFailureTemplate.getName());
        newTemplate.setResourceType(resourceType);
        newTemplate.setPriority(AlertPriority.MEDIUM);
        newTemplate.setConditionExpression(BooleanExpression.ANY);
        newTemplate.setDescription(storageNodeSnapshotFailureTemplate.getDescription());
        newTemplate.setRecoveryId(0);
        newTemplate.setEnabled(true);

        AlertCondition snapshotFailureCondition = new AlertCondition();
        snapshotFailureCondition.setCategory(AlertConditionCategory.CONTROL);
        snapshotFailureCondition.setName(TAKE_SNAPSHOT_OPERATION_NAME);
        snapshotFailureCondition.setOption(OperationRequestStatus.FAILURE.name());
        newTemplate.addCondition(snapshotFailureCondition);

        AlertDampening dampener = new AlertDampening(AlertDampening.Category.NONE);
        newTemplate.setAlertDampening(dampener);

        int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
            resourceType.getId());

        return newTemplateId;
    }
View Full Code Here

        return newTemplateId;
    }

    private int injectStorageNodeMaintenanceOperationsFailureTemplate(ResourceType resourceType) {
        AlertTemplateManagerLocal alertTemplateManager = LookupUtil.getAlertTemplateManager();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();

        AlertDefinition newTemplate = new AlertDefinition();
        newTemplate.setName(storageNodeMaintenanceOperationsFailureTemplate.getName());
        newTemplate.setResourceType(resourceType);
        newTemplate.setPriority(AlertPriority.MEDIUM);
        newTemplate.setConditionExpression(BooleanExpression.ANY);
        newTemplate.setDescription(storageNodeMaintenanceOperationsFailureTemplate.getDescription());
        newTemplate.setRecoveryId(0);
        newTemplate.setEnabled(true);

        for (String operation : MAINTENANCE_OPERATIONS) {
            AlertCondition snapshotFailureCondition = new AlertCondition();
            snapshotFailureCondition.setCategory(AlertConditionCategory.CONTROL);
            snapshotFailureCondition.setName(operation);
            snapshotFailureCondition.setOption(OperationRequestStatus.FAILURE.name());
            newTemplate.addCondition(snapshotFailureCondition);
        }

        AlertDampening dampener = new AlertDampening(AlertDampening.Category.NONE);
        newTemplate.setAlertDampening(dampener);

        int newTemplateId = alertTemplateManager.createAlertTemplate(subjectManager.getOverlord(), newTemplate,
            resourceType.getId());

        return newTemplateId;
    }
View Full Code Here

        DbSetupUtility.dbreset();
        DbSetupUtility.dbsetup();
    }

    public void testRoles() throws Exception {
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Subject overlord = subjectManager.getOverlord();

        Role superuserRole = roleManager.getRole(overlord, 1);
        Set<Permission> superuserRoleOriginalPermissions = superuserRole.getPermissions();
        assertTrue("[Superuser] role does not have all global permissions.",
            superuserRoleOriginalPermissions.containsAll(Permission.GLOBAL_ALL));
View Full Code Here

        // Upgrade to the latest schema version so the DB is left in a state usable by other tests.
        DbSetupUtility.dbupgrade("LATEST");
    }

    public void testUpgradeToV2_119() throws Exception {
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        RoleManagerLocal roleManager = LookupUtil.getRoleManager();
        Subject overlord = subjectManager.getOverlord();

        Role customRole = new Role("role" + UUID.randomUUID());
        customRole.addPermission(Permission.MANAGE_REPOSITORIES);
        customRole.addPermission(Permission.MANAGE_MEASUREMENTS);
        customRole = roleManager.createRole(overlord, customRole);
View Full Code Here

        tx.begin();
        EntityManager entityManager = getEntityManager();

        ContentSourceManagerLocal contentManager = LookupUtil.getContentSourceManager();
        RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        Subject overlord = subjectManager.getOverlord();

        // Create a sample content source type that will be used in this test
        testSourceType = new ContentSourceType("testType");
        entityManager.persist(testSourceType);
        entityManager.flush();
View Full Code Here

            TransactionManager tx = getTransactionManager();
            tx.begin();
            EntityManager entityManager = getEntityManager();

            RepoManagerLocal repoManager = LookupUtil.getRepoManagerLocal();
            SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
            Subject overlord = subjectManager.getOverlord();

            // Delete the repo relationships
            entityManager.createNamedQuery(RepoRepoRelationship.DELETE_BY_REPO_ID).setParameter("repoId", repoId)
                .executeUpdate();
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.auth.SubjectManagerLocal

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.