Package org.rhq.core.domain.resource

Examples of org.rhq.core.domain.resource.Resource


        if (resourceId == null) {
            throw new ParameterMissingException("resourceId");
        }

        Resource res;
        try {
            res = resourceManager.getResource(caller,resourceId);
        }
        catch (ResourceNotFoundException rnfe) {
            throw new StuffNotFoundException("resource with id " + resourceId);
        }

        ResourceType resourceType = res.getResourceType();

        EntityTag eTag = new EntityTag(Integer.toHexString(resourceType.hashCode()));
        Response.ResponseBuilder builder = request.evaluatePreconditions(eTag);
        if (builder==null) {
View Full Code Here


        assert current.getConfiguration().getId() == newConfigUpdate.getConfiguration().getId();
    }

    @Test(enabled = ENABLE_TESTS)
    public void testPurgeConfigurationHistorySame() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        // create a couple configs in history
        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("myboolean", "true"));

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("myboolean", "true"));

        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
        Thread.sleep(6000); // wait for the test agent to complete the request
        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
        Thread.sleep(6000); // wait for the test agent to complete the request

        // at this point in time, the round trip messaging is done and we have the agent response
        List<ResourceConfigurationUpdate> requests;

        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests != null;
        assert requests.size() == 1 : "Got " + requests.size() + " config update requests - expected 1.";
    }
View Full Code Here

        definitionCt1 = new MeasurementDefinition("CT-Def1", MeasurementCategory.PERFORMANCE,
            MeasurementUnits.MILLISECONDS, DataType.MEASUREMENT, true, 120000L, DisplayType.SUMMARY);
        definitionCt1.setResourceType(theResourceType);
        em.persist(definitionCt1);

        resource1 = new Resource("test-platform-key1", "test-platform-name", theResourceType);
        resource1.setUuid("" + new Random().nextInt());
        resource1.setAgent(theAgent);
        resource1.setInventoryStatus(InventoryStatus.COMMITTED);
        em.persist(resource1);
    }
View Full Code Here

        assert requests.size() == 1 : "Got " + requests.size() + " config update requests - expected 1.";
    }

    @Test(enabled = true)
    public void testPurgeConfigurationHistoryDifferent() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        // create a couple configs in history
        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("myboolean", "true"));

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("myboolean", "false"));

        ResourceConfigurationUpdate up;
        up = configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
        Thread.sleep(2000); // wait for the test agent to complete the request
        assert configuration1.equals(configurationManager.getResourceConfiguration(resource.getId()));
        up = configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
        Thread.sleep(2000); // wait for the test agent to complete the request
        assert configuration2.equals(configurationManager.getResourceConfiguration(resource.getId()));

        // at this point in time, the round trip messaging is done and we have the agent response
        List<ResourceConfigurationUpdate> requests;

        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests != null;
        assert requests.size() == 2 : "Got " + requests.size() + " config update requests - expected 2.";

        // delete the first one
        ResourceConfigurationUpdate doomedRequest = requests.get(0);
        ResourceConfigurationUpdate savedRequest = requests.get(1);

        configurationManager.purgeResourceConfigurationUpdates(overlord, new int[] { doomedRequest.getId() }, false);

        // now get the current configs/requests and
        // make sure we deleted just the one configuration, leaving one left
        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests.size() == 1;
        assert requests.get(0).getId() == savedRequest.getId();
    }
View Full Code Here

                driftDef.setName("drift-def-name");
                resource.addDriftDefinition(driftDef);
            }
        };

        Resource resource = createNewResource(rtCreator, rCreator);

        int templateId = resource.getResourceType().getDriftDefinitionTemplates().iterator().next().getId();
        int driftDefId = resource.getDriftDefinitions().iterator().next().getId();

        // sanity check, make sure things are in the DB now
        Query qTemplate;
        Query qDef;
        String qTemplateString = "select t from DriftDefinitionTemplate t where t.id = :id";
View Full Code Here

        assert requests.get(0).getId() == savedRequest.getId();
    }

    @Test(enabled = ENABLE_TESTS)
    public void testPurgeConfigurationHistoryWithFailedUpdateRequest() throws Exception {
        Resource resource = newResource1;

        Subject overlord = LookupUtil.getSubjectManager().getOverlord();

        // create a couple update/requests in history - one request will fail, so only a single config in history will be there
        Configuration configuration1 = new Configuration();
        configuration1.put(new PropertySimple("myboolean", "invalid-boolean"));

        Configuration configuration2 = new Configuration();
        configuration2.put(new PropertySimple("myboolean", "true"));

        Configuration activeConfigurationBefore = configurationManager.getResourceConfiguration(resource.getId());

        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration1);
        Thread.sleep(2000); // wait for the test agent to complete the request

        Configuration activeConfigurationAfter = configurationManager.getResourceConfiguration(resource.getId());
        assert activeConfigurationBefore.equals(activeConfigurationAfter) : "ActiveResourceConfiguration was not supposed to change for a failed update -- old was: "
            + activeConfigurationBefore + ", new was: " + activeConfigurationAfter;

        configurationManager.updateResourceConfiguration(overlord, resource.getId(), configuration2);
        Thread.sleep(2000); // wait for the test agent to complete the request

        Configuration activeConfiguration = configurationManager.getResourceConfiguration(resource.getId());
        assert activeConfiguration != null : "ActiveResourceConfiguration was not updated with configuration2";
        Map<String, PropertySimple> activeProperties = activeConfiguration.getSimpleProperties();
        assert activeProperties.size() == 1;
        assert activeProperties.containsKey("myboolean");
        PropertySimple activeProperty = activeProperties.get("myboolean");
        assert activeProperty.getName().equals("myboolean");
        assert "true".equals(activeProperty.getStringValue());

        // at this point in time, the round trip messaging is done and we have the agent response
        List<ResourceConfigurationUpdate> requests;

        requests = configurationManager.findResourceConfigurationUpdates(overlord, resource.getId(), null, null, false,
            configUpdatesPageControl);

        assert requests != null;
        assert requests.size() == 2; // one succeeded and one failed

        assert requests.get(0).getStatus() == ConfigurationUpdateStatus.FAILURE : "actual: "
            + requests.get(0).getStatus();
        assert requests.get(1).getStatus() == ConfigurationUpdateStatus.SUCCESS : "actual: "
            + requests.get(1).getStatus();

        ResourceConfigurationUpdate savedRequest = requests.get(0); // this is the one that failed
        ResourceConfigurationUpdate doomedRequest = requests.get(1); // this is the one that succeeded

        configurationManager.purgeResourceConfigurationUpdate(overlord, doomedRequest.getId(), false);

        // now get the current configs/requests and
        // make sure we deleted the only one configuration that succeeded, leaving one update record
        ResourceConfigurationUpdateCriteria criteria = new ResourceConfigurationUpdateCriteria();
        criteria.addFilterResourceIds(resource.getId());
        criteria.fetchConfiguration(true);
        criteria.addSortCreatedTime(PageOrdering.ASC);

        requests = configurationManager.findResourceConfigurationUpdatesByCriteria(overlord, criteria);
View Full Code Here

    }

    private Resource createNewResource(ResourceTypeCreator rtCreator, ResourceCreator rCreator) throws Exception {
        getTransactionManager().begin();

        Resource resource;

        try {
            ResourceType resourceType = new ResourceType("plat" + System.currentTimeMillis(), "test",
                ResourceCategory.PLATFORM, null);

            if (rtCreator != null) {
                rtCreator.modifyResourceTypeToPersist(resourceType);
            }

            em.persist(resourceType);

            Agent agent = new Agent("testagent", "testaddress", 1, "", "testtoken");
            em.persist(agent);
            em.flush();

            resource = new Resource("reskey" + System.currentTimeMillis(), "resname", resourceType);
            resource.setUuid("" + new Random().nextInt());
            resource.setAgent(agent);
            resource.setInventoryStatus(InventoryStatus.COMMITTED);
            if (rCreator != null) {
                rCreator.modifyResourceToPersist(resource);
            }
            em.persist(resource);
View Full Code Here

        // disambiguate as the results could be cross-resource
        default:
            Set<Integer> typesSet = new HashSet<Integer>();
            Set<String> ancestries = new HashSet<String>();
            for (Alert alert : result) {
                Resource resource = alert.getAlertDefinition().getResource();
                typesSet.add(resource.getResourceType().getId());
                ancestries.add(resource.getAncestry());
            }

            // In addition to the types of the result resources, get the types of their ancestry
            typesSet.addAll(AncestryUtil.getAncestryTypeIds(ancestries));
View Full Code Here

        }

        AlertDefinition alertDefinition = from.getAlertDefinition();

        record.setAttribute("definitionId", alertDefinition.getId());
        Resource resource = alertDefinition.getResource();
        record.setAttribute("name", alertDefinition.getName());
        record.setAttribute("description", alertDefinition.getDescription());
        record.setAttribute("priority", ImageManager.getAlertIcon(alertDefinition.getPriority()));

        // for ancestry handling
        record.setAttribute(AncestryUtil.RESOURCE_ID, resource.getId());
        record.setAttribute(AncestryUtil.RESOURCE_NAME, resource.getName());
        record.setAttribute(AncestryUtil.RESOURCE_ANCESTRY, resource.getAncestry());
        record.setAttribute(AncestryUtil.RESOURCE_TYPE_ID, resource.getResourceType().getId());

        AlertDefinition groupAlertDefinition = alertDefinition.getGroupAlertDefinition();
        Integer parentId = alertDefinition.getParentId();
        if (groupAlertDefinition != null && groupAlertDefinition.getGroup() != null) {
            boolean isAutogroup = groupAlertDefinition.getGroup().getAutoGroupParentResource() != null;
            record.setAttribute(FIELD_PARENT, (isAutogroup ? "#Resource/AutoGroup/" : "#ResourceGroup/")
                + groupAlertDefinition.getGroup().getId() + "/Alerts/Definitions/" + groupAlertDefinition.getId());
            record.setLinkText(MSG.view_alert_definition_for_group());
        } else if (parentId != null && parentId.intValue() != 0) {
            record.setAttribute(
                FIELD_PARENT,
                LinkManager.getAdminTemplatesEditLink(AlertDefinitionTemplateTypeView.VIEW_ID.getName(), resource
                    .getResourceType().getId())
                    + "/" + parentId);
            record.setLinkText(MSG.view_alert_definition_for_type());
        }
View Full Code Here

        // R2:  UNKNOWN   DOWN      UP     
        // R3:  UNKNOWN   DOWN               UP       DISABLED 
        // ----------------------------------------------------------
        // AV:  WARN      DOWN      WARN     UP       DISABLED

        final Resource r1 = theResource;
        final Resource r2 = additionalResources.get(0);
        final Resource r3 = additionalResources.get(1);

        AvailabilityReport report = new AvailabilityReport(false, theAgent.getName());

        report.addAvailability(new Availability(r1, 10000L, DOWN));
        report.addAvailability(new Availability(r2, 10000L, DOWN));
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.resource.Resource

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.