Package org.rhq.core.domain.resource

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


                em.remove(sched);

                Resource attachedPlatform = em.find(Resource.class, testData.fakePlatform.getId());
                ResourceTreeHelper.deleteResource(em, attachedPlatform);

                ResourceType attachedType = em.find(ResourceType.class, testData.fakeType.getId());
                em.remove(attachedType);

                em.flush();

                getTransactionManager().commit();
View Full Code Here


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

                resourceType = new ResourceType(RESOURCE_TYPE, PLUGIN, SERVER, null);
                em.persist(resourceType);

                server = ServerFactory.newInstance();
                server.setName(RHQ_SERVER_NAME_PROPERTY_VALUE);
                server.setAddress("localhost");
View Full Code Here

            agentServiceContainer.discoveryService.manuallyAddResource(any(ResourceType.class), anyInt(),
                any(Configuration.class), anyInt())).thenAnswer(new Answer<MergeResourceResponse>() {
            public MergeResourceResponse answer(InvocationOnMock invocation) throws Throwable {
                Resource resource = new Resource(1000000);
                resource.setUuid(UUID.randomUUID().toString());
                ResourceType resourceType = (ResourceType) invocation.getArguments()[0];
                resource.setResourceType(resourceType);
                long randomLong = UUID.randomUUID().getLeastSignificantBits();
                resource.setResourceKey(prefix("key-" + randomLong));
                resource.setName(prefix("name-" + randomLong));
                int parentResourceId = (Integer) invocation.getArguments()[1];
View Full Code Here

        @PathParam("id") int resourceTypeId,
        @Context HttpHeaders headers,
        @Context UriInfo uriInfo) {


        ResourceType type;
        try {
            type = typeManager.getResourceTypeById(caller,resourceTypeId);
        } catch (ResourceTypeNotFoundException e) {
            throw new StuffNotFoundException("Resource type with id " + resourceTypeId);
        }
View Full Code Here

        getTransactionManager().begin();
        try {
            String prefix = MeasurementViewManagerTest.class.getSimpleName();

            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);
View Full Code Here

    @Test(enabled = ENABLED)
    public void testOperationAndArtifactUpdates() throws Exception {
        System.out.println("= testOperationAndArtifactUpdates");
        try {
            registerPlugin("update3-v1_0.xml");
            ResourceType platform1 = getResourceType("myPlatform3");
            getTransactionManager().begin();

            platform1 = em.find(ResourceType.class, platform1.getId());

            Set<PackageType> packageTypes = platform1.getPackageTypes();
            assert packageTypes.size() == 3 : "Did not find the three expected package types in v1";
            Set<OperationDefinition> ops = platform1.getOperationDefinitions();
            assert ops.size() == 3 : "Did not find three expected operations in v1";
            getTransactionManager().rollback();

            /*
             * Now deploy the changed version of the plugin
             */
            registerPlugin("update3-v2_0.xml");
            ResourceType platform2 = getResourceType("myPlatform3");
            getTransactionManager().begin();

            platform2 = em.find(ResourceType.class, platform2.getId());

            Set<PackageType> packageTypes2 = platform2.getPackageTypes();
            assert packageTypes2.size() == 3 : "Did not find the expected three package types in v2";
            Set<OperationDefinition> opDefs = platform2.getOperationDefinitions();
            assert opDefs.size() == 3 : "Did not find the three expected operations in v2";
            // now that the basics are tested, go for the details...

            boolean ubuFound = false;
            for (PackageType pt : packageTypes2) {
                //            System.out.println(at.getName());
                assert !(pt.getName().equals("rpm")) : "RPM should be gone in v2";
                if (pt.getName().equals("ubu")) {
                    ubuFound = true;
                }
            }

            assert ubuFound == true : "Ubu should be in v2";

            boolean startFound = false;
            for (OperationDefinition opDef : opDefs) {
                //            System.out.println(opDef.getName());
                assert !(opDef.getName().equals("restart")) : "Restart should be gone in v2";
                if (opDef.getName().equals("start")) {
                    startFound = true;
                }

                if (opDef.getName().equals("status")) {
                    assert opDef.getDescription().equals("Yadda!") : "Description for 'start' should be 'Yadda!', but was "
                        + opDef.getDescription();
                }
            }

            assert startFound == true : "Start should be in v2";
            getTransactionManager().rollback();

            /*
             * Now try the other way round
             */

            registerPlugin("update3-v1_0.xml", "3.0");
            ResourceType platform3 = getResourceType("myPlatform3");
            getTransactionManager().begin();

            platform3 = em.find(ResourceType.class, platform3.getId());

            Set<PackageType> packageTypes3 = platform3.getPackageTypes();
            assert packageTypes3.size() == 3 : "Did not find the three package types in v3";
            Set<OperationDefinition> ops3 = platform3.getOperationDefinitions();
            assert ops3.size() == 3 : "Did not find three expected operations in v3";

            // we should have rpm, deb, mpkg. ubu from v2 should be gone again.
            boolean rpmFound = false;
            for (PackageType pt : packageTypes3) {
View Full Code Here

    @Test(enabled = ENABLED)
    public void testAddRemoveOperationWithParams() throws Exception {
        System.out.println("= testAddRemoveOperationWithParams");
        try {
            registerPlugin("operation1-1.xml");
            ResourceType platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();

            platform = em.find(ResourceType.class, platform.getId());

            Set<OperationDefinition> opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 1;
            OperationDefinition def = opDefs.iterator().next();
            assert def.getName().equals("sleep");
            assert def.getParametersConfigurationDefinition() == null;
            getTransactionManager().rollback();

            System.out.println("==> Done with v1");

            registerPlugin("operation1-2.xml");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();

            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 2;

            for (OperationDefinition odef : opDefs) {
                if (odef.getName().equals("invokeSql")) {
                    assert odef.getDescription().startsWith("Execute");
                    ConfigurationDefinition conf = odef.getParametersConfigurationDefinition();
                    assert conf != null;
                    Map<String, PropertyDefinition> props = conf.getPropertyDefinitions();
                    assert props.size() == 2;
                    for (PropertyDefinition pd : props.values()) {
                        PropertyDefinitionSimple pds = (PropertyDefinitionSimple) pd;
                        if (pds.getName().equals("sleep")) {
                            assert pds.getDescription() == null;
                        }
                        if (pds.getName().equals("invokeSql")) {
                            List<PropertyDefinitionEnumeration> pde = pds.getEnumeratedValues();
                            assert pde.size() == 2;
                        }
                    }

                    conf = odef.getResultsConfigurationDefinition();
                    assert conf != null;
                }
            }
            getTransactionManager().rollback();

            System.out.println("==> Done with v2");

            registerPlugin("operation1-1.xml", "3.0");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 1;

        } finally {
            if (Status.STATUS_NO_TRANSACTION != getTransactionManager().getStatus()) {
View Full Code Here

    @Test(enabled = ENABLED)
    public void testAddRemoveOperationWithParams2() throws Exception {
        System.out.println("= testAddRemoveOperationWithParams2");
        try {
            registerPlugin("operation2-1.xml");
            ResourceType platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            Set<OperationDefinition> opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 3 : "Did not find the expected 3 defs, but " + opDefs.size();

            int found = 0;
            for (OperationDefinition def : opDefs) {
                if (containedIn(def.getName(), new String[] { "sleep", "wakeup", "getup" }))
                    found++;
            }
            assert found == 3 : "Did not find all 3 expected operations";
            getTransactionManager().rollback();

            System.out.println("==> Done with v1");

            registerPlugin("operation2-1.xml");
            System.out.println("==> Done with v1 (2)");

            registerPlugin("operation2-2.xml");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 4 : "Did not find the expected 4 defs, but " + opDefs.size();
            found = 0;
            for (OperationDefinition def : opDefs) {
                if (containedIn(def.getName(), new String[] { "wakeup", "getup", "eat", "goToWork" }))
                    found++;
            }
            assert found == 4 : "Did not find all 4 expected operations";
            getTransactionManager().rollback();

            System.out.println("==> Done with v2");

            registerPlugin("operation2-1.xml", "3.0");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 3 : "Did not find the expected 3 defs, but " + opDefs.size();

        } finally {
            if (Status.STATUS_NO_TRANSACTION != getTransactionManager().getStatus()) {
View Full Code Here

    @Test(enabled = ENABLED)
    public void testAddRemoveOperationWithGrouping() throws Exception {
        System.out.println("= testAddRemoveOperationWithGrouping");
        try {
            registerPlugin("operation3-1.xml");
            ResourceType platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            Set<OperationDefinition> opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 3 : "Did not find the expected 3 defs, but " + opDefs.size();

            int found = 0;
            for (OperationDefinition def : opDefs) {
                if (containedIn(def.getName(), new String[] { "sleep", "wakeup", "getup" }))
                    found++;
            }
            assert found == 3 : "Did not find all 3 expected operations";
            getTransactionManager().rollback();

            System.out.println("==> Done with v1");

            registerPlugin("operation3-1.xml");
            System.out.println("==> Done with v1 (2)");

            registerPlugin("operation3-2.xml");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;

            assert opDefs.size() == 4 : "Did not find the expected 4 defs, but " + opDefs.size();
            found = 0;
            for (OperationDefinition def : opDefs) {
                if (containedIn(def.getName(), new String[] { "wakeup", "getup", "eat", "goToWork" }))
                    found++;
            }
            assert found == 4 : "Did not find all 4 expected operations";
            getTransactionManager().rollback();

            System.out.println("==> Done with v2");

            registerPlugin("operation3-1.xml", "3.0");
            platform = getResourceType("ops");
            assert platform != null;
            getTransactionManager().begin();
            platform = em.find(ResourceType.class, platform.getId());

            opDefs = platform.getOperationDefinitions();
            assert opDefs != null;
            assert opDefs.size() == 3 : "Did not find the expected 3 defs, but " + opDefs.size();

        } finally {
            if (Status.STATUS_NO_TRANSACTION != getTransactionManager().getStatus()) {
View Full Code Here

    public void testRemovalOfObsoleteBundleAndDriftConfig() throws Exception {
        // create the initial type that has bundle and drift definitions
        createPlugin("test-plugin.jar", "1.0", "remove_bundle_drift_config_v1.xml");

        // make sure the drift definition was persisted, and remember the type
        ResourceType type1 = assertResourceTypeAssociationEquals("ServerWithBundleAndDriftConfig", PLUGIN_NAME,
            "driftDefinitionTemplates", asList("drift1"));

        // sanity check, make sure our queries work and that we did persist these things
        Query qTemplate;
        Query qConfig;
        //String qTemplateString = "select ct from ConfigurationTemplate ct where ct.id = :id";
        String qTemplateString = "from DriftDefinitionTemplate where id = :id";
        String qConfigString = "from Configuration c where id = :id";
        DriftDefinitionTemplate driftTemplate = type1.getDriftDefinitionTemplates().iterator().next();
        Configuration bundleConfig = type1.getResourceTypeBundleConfiguration().getBundleConfiguration();
        Configuration driftDefConfig = driftTemplate.getConfiguration();

        getTransactionManager().begin();
        try {
            qTemplate = getEntityManager().createQuery(qTemplateString).setParameter("id", driftTemplate.getId());
            qConfig = getEntityManager().createQuery(qConfigString).setParameter("id", driftDefConfig.getId());
            assertEquals("drift template didn't get persisted", 1, qTemplate.getResultList().size());
            assertEquals("drift template config didn't get persisted", 1, qConfig.getResultList().size());

            qConfig.setParameter("id", bundleConfig.getId());
            assertEquals("bundle config didn't get persisted", 1, qConfig.getResultList().size());
        } finally {
            getTransactionManager().commit();
        }

        assertNotNull(type1.getResourceTypeBundleConfiguration());
        assertEquals("destdir1", type1.getResourceTypeBundleConfiguration().getBundleDestinationBaseDirectories()
            .iterator().next().getName());

        // upgrade the type which removes the bundle config and drift definition
        createPlugin("test-plugin.jar", "2.0", "remove_bundle_drift_config_v2.xml");
View Full Code Here

TOP

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

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.