Package org.rhq.core.domain.resource

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


        // First create an inventory report for a new platform with servers

        InventoryReport inventoryReport = new InventoryReport(agent);

        Resource platform = new Resource(prefix("platform"), prefix("platform"), platformType);
        platform.setUuid(String.valueOf(new Random().nextInt()));
        for (int i = 0; i < 17; i++) {
            String serverString = prefix("server " + String.valueOf(i));
            Resource server = new Resource(serverString, serverString, serverType);
            server.setUuid(String.valueOf(new Random().nextInt()));
            platform.addChildResource(server);
        }

        inventoryReport.addAddedRoot(platform);
View Full Code Here


        resourceTypeManager.setResourceTypeIgnoreFlagAndUninventoryResources(subjectManager.getOverlord(),
            serverType.getId(), true);

        // create an inventory report with a platform and a server - the server will be of the ignored type
        InventoryReport inventoryReport = new InventoryReport(agent);
        Resource platform = new Resource(prefix("platform"), prefix("platform"), platformType);
        platform.setUuid(String.valueOf(new Random().nextInt()));
        Resource server = new Resource(prefix("server0"), prefix("server0"), serverType);
        server.setUuid(String.valueOf(new Random().nextInt()));
        platform.addChildResource(server);
        inventoryReport.addAddedRoot(platform);

        // Merge this inventory report
        MergeInventoryReportResults mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
View Full Code Here

        resourceTypeManager.setResourceTypeIgnoreFlagAndUninventoryResources(subjectManager.getOverlord(),
            serviceType2.getId(), true);

        // create an inventory report with just a platform and a server
        InventoryReport inventoryReport = new InventoryReport(agent);
        Resource platform = new Resource(prefix("platform"), prefix("platform"), platformType);
        platform.setUuid(String.valueOf(new Random().nextInt()));
        Resource server = new Resource(prefix("server0"), prefix("server0"), serverType);
        server.setUuid(String.valueOf(new Random().nextInt()));
        platform.addChildResource(server);
        inventoryReport.addAddedRoot(platform);

        // Merge this inventory report
        MergeInventoryReportResults mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
View Full Code Here

                dynamicMeasuremenDef.setDataType(MEASUREMENT);
                dynamicMeasuremenDef.setMeasurementType(DYNAMIC);

                em.persist(dynamicMeasuremenDef);

                resource = new Resource(RESOURCE_KEY, RESOURCE_NAME, resourceType);
                resource.setUuid(RESOURCE_UUID);
                resource.setInventoryStatus(InventoryStatus.COMMITTED);
                resource.setAgent(agent);

                em.persist(resource);
View Full Code Here

    @Test(groups = "integration.ejb3")
    public void testIgnoreResourceTypeAndUninventoryResources() throws Exception {

        // First create an inventory report for a new platform with servers - nothing is ignored yet
        InventoryReport inventoryReport = new InventoryReport(agent);
        Resource platform = new Resource(prefix("platform"), prefix("platform"), platformType);
        platform.setUuid(String.valueOf(new Random().nextInt()));
        for (int i = 0; i < 17; i++) {
            String serverString = prefix("server " + String.valueOf(i));
            Resource server = new Resource(serverString, serverString, serverType);
            server.setUuid(String.valueOf(new Random().nextInt()));
            platform.addChildResource(server);
        }
        inventoryReport.addAddedRoot(platform);

        // Merge this inventory report to get platform and servers in NEW state
View Full Code Here

        if (assumeResourceExists && !r.isEmpty()) {
            assertTrue("Should be only 1 resource", r.size() == 1);
        }

        if (!r.isEmpty()) {
            Resource doomedResource = r.get(0);
            deleteAlertDefinitions(doomedResource.getAlertDefinitions());
        }

        executeInTransaction(false, new TransactionCallback() {
            @Override
            public void execute() throws Exception {

                if (!r.isEmpty()) {
                    //load the resource entity again within this transaction so that we
                    //have an attached copy of it.
                    Resource delete = em.find(Resource.class, r.get(0).getId());


                    // Note that the order of deletes is important due to FK
                    // constraints.
                    deleteMeasurementSchedules(delete);
View Full Code Here

    public void testAutoImportStorageNode() throws Exception {

        // create an inventory report for a storage node
        InventoryReport inventoryReport = new InventoryReport(agent);

        Resource storagePlatform = new Resource(prefix("storagePlatform"), prefix("storagePlatform"),
            storagePlatformType);
        storagePlatform.setUuid(String.valueOf(new Random().nextInt()));

        Resource storageNode = new Resource(prefix("storageNode"), prefix("storageNode"), storageServerType);
        storageNode.setUuid(String.valueOf(new Random().nextInt()));
        storagePlatform.addChildResource(storageNode);

        storageNode.setPluginConfiguration(Configuration.builder().addSimple("nativeTransportPort", 9142)
            .addSimple("storagePort", 7100).addSimple("host", "localhost").build());

        inventoryReport.addAddedRoot(storagePlatform);

        // Merge this inventory report
        MergeInventoryReportResults mergeResults = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
        assert mergeResults != null;
        assert checkIgnoredTypes(mergeResults) : "nothing should have been ignored: "
            + mergeResults.getIgnoredResourceTypes();
        PlatformSyncInfo platformSyncInfo = mergeResults.getPlatformSyncInfo();
        assert platformSyncInfo != null;

        // Check merge result
        assertEquals(InventoryStatus.COMMITTED, platformSyncInfo.getPlatform().getInventoryStatus());
        assertEquals(storagePlatform.getChildResources().size(), platformSyncInfo.getTopLevelServerIds().size());

        storageNode = resourceManager.getResourceById(subjectManager.getOverlord(), platformSyncInfo
            .getTopLevelServerIds().iterator().next());
        assertNotNull(storageNode);
        assertEquals(InventoryStatus.COMMITTED, storageNode.getInventoryStatus());
    }
View Full Code Here

    public void testPersistUserSuppliedResourceNameOnCreatedResource() throws Exception {

        // First inventory the platform and the server
        InventoryReport inventoryReport = new InventoryReport(agent);

        Resource platform = new Resource(prefix("userPlatform"), prefix("platform"), platformType);
        platform.setUuid(String.valueOf(new Random().nextInt()));
        Resource server = new Resource(prefix("userServer"), prefix("server"), serverType);
        server.setUuid(String.valueOf(new Random().nextInt()));
        platform.addChildResource(server);

        inventoryReport.addAddedRoot(platform);

        MergeInventoryReportResults results = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
        assertNotNull(results);
        assert checkIgnoredTypes(results) : "nothing should have been ignored in this test "
            + results.getIgnoredResourceTypes();
        final PlatformSyncInfo firstDiscoverySyncInfo = results.getPlatformSyncInfo();
        assertNotNull(firstDiscoverySyncInfo);

        // Then simulate a create resource request
        final String userSuppliedResourceName = prefix("User Supplied Resource Name");
        final String newResourceKey = prefix("Created Resource Key");
        final int serverResourceId = firstDiscoverySyncInfo.getTopLevelServerIds().iterator().next();

        executeInTransaction(false, new TransactionCallback() {
            @Override
            public void execute() throws Exception {
                Resource serverResource = getEntityManager().find(Resource.class, serverResourceId);
                CreateResourceHistory createResourceHistory = new CreateResourceHistory(serverResource, serviceType1,
                    subjectManager.getOverlord().getName(), new Configuration());
                createResourceHistory.setCreatedResourceName(userSuppliedResourceName);
                createResourceHistory.setNewResourceKey(newResourceKey);
                createResourceHistory.setStatus(SUCCESS);
                getEntityManager().persist(createResourceHistory);
                serverResource.addCreateChildResourceHistory(createResourceHistory);
                getEntityManager().flush();
            }
        });

        // Eventually inventory the newly discovered service

        inventoryReport = new InventoryReport(agent);
        Resource service1 = new Resource(newResourceKey, prefix("Plugin Computed Resource Name"), serviceType1);
        service1.setUuid(String.valueOf(new Random().nextInt()));
        server.setId(serverResourceId);
        server.addChildResource(service1);
        inventoryReport.addAddedRoot(server);

        results = discoveryBoss.mergeInventoryReport(serialize(inventoryReport));
        assertNotNull(results);
        assert checkIgnoredTypes(results) : "nothing should have been ignored in this test "
            + results.getIgnoredResourceTypes();
        PlatformSyncInfo secondDiscoverySyncInfo = results.getPlatformSyncInfo();
        assertNotNull(secondDiscoverySyncInfo);

        // Check that the resource ends with the user supplied name in inventory

        Integer toplevelServerId = secondDiscoverySyncInfo.getTopLevelServerIds().iterator().next();
        Collection<ResourceSyncInfo> topLevelServerSyncInfo = discoveryBoss.getResourceSyncInfo(toplevelServerId);
        assert topLevelServerSyncInfo.size() == 2;
        Iterator<ResourceSyncInfo> iter = topLevelServerSyncInfo.iterator();
        Integer childId = iter.next().getId();
        childId = childId.equals(toplevelServerId) ? iter.next().getId() : childId;
        Resource service1Resource = getEntityManager().find(Resource.class, childId);
        assertEquals(userSuppliedResourceName, service1Resource.getName());
    }
View Full Code Here

                + "    WHERE r.resourceType.name LIKE '" + getPrefix() + "%'" //
                + "       OR r.resourceType.name = 'RHQ Storage Node'" //
                + " ORDER BY r.id DESC");
            doomed = q.getResultList();
            for (Object removeMe : doomed) {
                Resource res = em.getReference(Resource.class, ((Resource) removeMe).getId());
                StorageNode storageNode = findStorageNode(res);
                if (storageNode != null) {
                    storageNode.setResource(null);
                }
                for (Iterator<CreateResourceHistory> historyIterator = res.getCreateChildResourceRequests().iterator(); historyIterator
                    .hasNext();) {
                    CreateResourceHistory history = historyIterator.next();
                    historyIterator.remove();
                    em.remove(history);
                }
View Full Code Here

            type = new ResourceType(prefix + "type", prefix + "plugin", ResourceCategory.PLATFORM, null);
            em.persist(type);

            resources = new ArrayList<Resource>();
            for (int i = 0; i < SIZE; i++) {
                Resource resource = new Resource(prefix + "key " + i, prefix + "key " + i, type);
                resource.setUuid(resource.getResourceKey());
                resources.add(resource);
                em.persist(resource);
            }

            definitions = new ArrayList<MeasurementDefinition>();
            for (int i = 0; i < SIZE; i++) {
                MeasurementDefinition definition = new MeasurementDefinition(type, prefix + "definition " + i);
                definitions.add(definition);
                type.addMetricDefinition(definition);
                em.persist(definition);
            }
            type = em.merge(type);

            schedules = new ArrayList<MeasurementSchedule>();
            for (int i = 0; i < SIZE; i++) {
                for (int j = 0; j < SIZE; j++) {
                    MeasurementDefinition definition = definitions.get(i);
                    Resource resource = resources.get(j);
                    MeasurementSchedule schedule = new MeasurementSchedule(definition, resource);
                    schedules.add(schedule);
                    definition.addSchedule(schedule);
                    resource.addSchedule(schedule);
                    em.persist(schedule);
                }
            }
            for (int i = 0; i < SIZE; i++) {
                MeasurementDefinition definition = definitions.get(i);
                definitions.set(i, em.merge(definition));
            }
            for (int j = 0; j < SIZE; j++) {
                Resource resource = resources.get(j);
                resources.set(j, em.merge(resource));
            }
        } finally {
            getTransactionManager().commit();
        }
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.