Examples of ResourceGroup


Examples of org.rhq.core.domain.resource.group.ResourceGroup

    // lifted from ResourceManagerBeanTest, with the addition of adding bundle config to the type
    private ResourceGroup createTestResourceGroup() throws Exception {
        getTransactionManager().begin();

        ResourceGroup resourceGroup = null;
        Resource resource;

        try {
            // Naming this with TEST_PREFIX allows cleanupDatabase to blow away these test resources along
            // with the bundle resource type
            ResourceType resourceType = new ResourceType(TEST_PREFIX + "-platform-" + System.currentTimeMillis(),
                "test", ResourceCategory.PLATFORM, null);

            // we need to make this test type bundle targetable
            ConfigurationDefinition pcDef = new ConfigurationDefinition(TEST_PREFIX + "-testdef", "bundle test");
            PropertyDefinitionSimple propDef = new PropertyDefinitionSimple(TEST_BUNDLE_DESTBASEDIR_PROP, "", true,
                PropertySimpleType.STRING);
            propDef.setDisplayName(TEST_BUNDLE_DESTBASEDIR_PROP);
            pcDef.put(propDef);
            em.persist(pcDef);

            ResourceTypeBundleConfiguration rtbc = new ResourceTypeBundleConfiguration(new Configuration());
            rtbc.addBundleDestinationBaseDirectory(TEST_DESTBASEDIR_NAME,
                ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory.Context.pluginConfiguration.name(),
                TEST_BUNDLE_DESTBASEDIR_PROP, null);
            resourceType.setResourceTypeBundleConfiguration(rtbc);
            resourceType.setPluginConfigurationDefinition(pcDef);

            em.persist(resourceType);

            // make sure the bundle config is ok
            rtbc = resourceType.getResourceTypeBundleConfiguration();
            assert rtbc != null;
            assert rtbc.getBundleDestinationBaseDirectories().size() == 1;
            BundleDestinationBaseDirectory bdbd = rtbc.getBundleDestinationBaseDirectories().iterator().next();
            assert bdbd.getName().equals(TEST_DESTBASEDIR_NAME);
            assert bdbd.getValueContext() == ResourceTypeBundleConfiguration.BundleDestinationBaseDirectory.Context.pluginConfiguration;
            assert bdbd.getValueName().equals(TEST_BUNDLE_DESTBASEDIR_PROP);

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

            Configuration rc = new Configuration();
            rc.put(new PropertySimple(TEST_BUNDLE_DESTBASEDIR_PROP, TEST_BUNDLE_DESTBASEDIR_PROP_VALUE));
            em.persist(rc);

            resource = new Resource("reskey" + System.currentTimeMillis(), TEST_PREFIX + "-resname", resourceType);
            resource.setUuid("" + System.currentTimeMillis());
            resource.setInventoryStatus(InventoryStatus.COMMITTED);
            resource.setAgent(agent);
            resource.setResourceConfiguration(rc);
            em.persist(resource);

            resourceGroup = new ResourceGroup(TEST_PREFIX + "-group-" + System.currentTimeMillis());
            resourceGroup.addExplicitResource(resource);
            resourceGroup.addImplicitResource(resource);
            resourceGroup.setResourceType(resourceType); // need to tell the group the type it is
            em.persist(resourceGroup);

            getTransactionManager().commit();
        } catch (Exception e) {
            try {
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

            resourcesServiceE2.get(0));
        // Intentionally greater than 200 to test an issue with Criteria fetch defaults
        List<Resource> resourcesServiceE4 = createResources(205, "RemoveTypesPlugin", "ServiceE4",
            resourcesServiceE3.get(0));

        ResourceGroup rgRecursive = createResourceGroup("ServerE Group", "ServerE", "RemoveTypesPlugin", true);
        addResourcesToGroup(rgRecursive, resourcesServerE);

        ResourceGroup rgFlat = createResourceGroup("ServiceE4 Group", "ServiceE4", "RemoveTypesPlugin", false);
        addResourcesToGroup(rgFlat, resourcesServiceE4);

        createPlugin("remove-types-plugin", "2.0", "remove_types_v2.xml");

        //Removal of this resource type exceeds default criteria page size.
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

        ResourceType resourceType = resourceTypeMgr.getResourceTypeByNameAndPlugin(resourceTypeName, pluginName);

        assertNotNull("Cannot create resource group. Unable to find resource type for [name: " + resourceTypeName
            + ", plugin: " + pluginName + "]", resourceType);

        ResourceGroup resourceGroup = new ResourceGroup(groupName, resourceType);
        resourceGroup.setRecursive(recursive);
        ResourceGroup result = resourceGroupMgr.createResourceGroup(subjectMgr.getOverlord(), resourceGroup);
        groupIds.add(result.getId());
        return result;
    }
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

    @ApiError(code = 404, reason = "Group with passed id not found")
    public Response getGroup(@ApiParam(value = "Id of the group") @PathParam("id") int id,
                             @Context HttpHeaders headers,
                             @Context UriInfo uriInfo) {

        ResourceGroup group = fetchGroup(id, false);

        GroupRest groupRest = fillGroup(group, uriInfo);

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

        if (group==null)
            throw new BadArgumentException("A group must be provided");
        if (group.getName()==null)
            throw new BadArgumentException("A group name is required");

        ResourceGroup newGroup = new ResourceGroup(group.getName());
        if (group.getResourceTypeId()!=null) {

            ResourceType resourceType = null;
            try {
                resourceType = resourceTypeManager.getResourceTypeById(caller,group.getResourceTypeId());
                newGroup.setResourceType(resourceType);
            } catch (ResourceTypeNotFoundException e) {
                throw new StuffNotFoundException("ResourceType with id " + group.getResourceTypeId());
            }
        }

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
        Response.ResponseBuilder builder;
        UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/group/{id}");

        try {
            newGroup = resourceGroupManager.createResourceGroup(caller, newGroup);
            URI uri = uriBuilder.build(newGroup.getId());

            builder=Response.created(uri);
        } catch (ResourceGroupAlreadyExistsException e) {

            ResourceGroupCriteria criteria = new ResourceGroupCriteria();
            criteria.setStrict(true);
            criteria.addFilterName(newGroup.getName());
            // TODO also case sensitive?
            List<ResourceGroup> groups = resourceGroupManager.findResourceGroupsByCriteria(caller,criteria);
            newGroup = groups.get(0);

            URI uri = uriBuilder.build(newGroup.getId());

            builder=Response.ok(uri);
        } catch (Exception e) {
            builder=Response.status(Response.Status.NOT_ACCEPTABLE);
            builder.type(mediaType);
            builder.entity(e.getCause());
        }

        builder.type(mediaType);
        builder.entity(fillGroup(newGroup,uriInfo));
        putToCache(newGroup.getId(),ResourceGroup.class,newGroup);

        return builder.build();
    }
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

    public Response updateGroup(@ApiParam(value = "Id of the group to update") @PathParam("id") int id,
                                @ApiParam(value = "New version of the group") GroupRest in,
                                @Context HttpHeaders headers,
                                @Context UriInfo uriInfo) {

        ResourceGroup resourceGroup = fetchGroup(id, false);
        resourceGroup.setName(in.getName());
        Response.ResponseBuilder builder;

        try {
            resourceGroup = resourceGroupManager.updateResourceGroup(caller,resourceGroup);
            builder=Response.ok(fillGroup(resourceGroup,uriInfo));
            putToCache(resourceGroup.getId(),ResourceGroup.class,resourceGroup);
        }
        catch (Exception e) {
            builder = Response.status(Response.Status.NOT_ACCEPTABLE);
        }
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

    @ApiError(code = 404, reason = "Group with passed id does not exist")
    public Response getResources(@ApiParam("Id of the group to retrieve the resources for") @PathParam("id") int id,
                                 @Context HttpHeaders headers,
                                 @Context UriInfo uriInfo) {

        ResourceGroup resourceGroup = fetchGroup(id, false);

        Set<Resource> resources = resourceGroup.getExplicitResources();
        List<ResourceWithType> rwtList = new ArrayList<ResourceWithType>(resources.size());
        for (Resource res: resources) {
            rwtList.add(fillRWT(res,uriInfo));
        }
        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

                                @ApiParam("Id of the resource to add") @PathParam("resourceId") int resourceId,
                                @Context HttpHeaders headers, @Context UriInfo uriInfo) {

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);

        ResourceGroup resourceGroup = fetchGroup(id, false);
        Resource res = resourceManager.getResource(caller,resourceId);
        if (res==null)
            throw new StuffNotFoundException("Resource with id " + resourceId);

        // A resource type is set for the group, so only allow to add resources with the same type.
        if (resourceGroup.getResourceType()!=null) {
            if (!res.getResourceType().equals(resourceGroup.getResourceType())) {
                Response.ResponseBuilder status = Response.status(Response.Status.CONFLICT);
                status.type(mediaType);
                return status.build();
            }
        }
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

    public Response removeResource(@ApiParam("Id of the existing group") @PathParam("id") int id,
                                   @ApiParam("Id of the resource to remove") @PathParam("resourceId") int resourceId,
                                   @ApiParam("Validate if the resource exists in the group") @QueryParam(
                                       "validate") @DefaultValue("false") boolean validate) {

        ResourceGroup resourceGroup = fetchGroup(id, false);
        Resource res = resourceManager.getResource(caller, resourceId);
        if (res==null)
            throw new StuffNotFoundException("Resource with id " + resourceId);

        boolean removed = resourceGroup.removeExplicitResource(res);
        if (!removed && validate) {
            throw new StuffNotFoundException("Resource " + resourceId + " in group " + id);
        }

        return Response.noContent().build();
View Full Code Here

Examples of org.rhq.core.domain.resource.group.ResourceGroup

    @ApiOperation(value = "Get the metric definitions for the compatible group with the passed id")
    @ApiError(code = 404, reason = "Group with the passed id does not exist")
    public Response getMetricDefinitionsForGroup(@ApiParam(value = "Id of the group") @PathParam("id") int id,
                                                 @Context HttpHeaders headers,
                                                 @Context UriInfo uriInfo) {
        ResourceGroup group = fetchGroup(id, true);

        Set<MeasurementDefinition> definitions = group.getResourceType().getMetricDefinitions();
        List<MetricSchedule> schedules = new ArrayList<MetricSchedule>(definitions.size());
        for (MeasurementDefinition def : definitions) {
            MetricSchedule schedule = new MetricSchedule(def.getId(),def.getName(),def.getDisplayName(),false,def.getDefaultInterval(),
                    def.getUnits().getName(),def.getDataType().toString());
            schedule.setDefinitionId(def.getId());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.