Package org.rhq.core.domain.resource.group

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


        }
    }

    public GroupDefinition createGroupDefinition(GroupDefinition groupDefinition) throws RuntimeException {
        try {
            GroupDefinition results = definitionManager.createGroupDefinition(getSessionSubject(), groupDefinition);

            return SerialUtility.prepare(results, "ResourceGroupService.createGroupDefinition");
        } catch (Throwable t) {
            throw getExceptionToThrowToClient(t);
        }
View Full Code Here


    public Response getGroupDefinition(
            @ApiParam("The id of the definition to retrieve") @PathParam("id") int definitionId,
            @Context HttpHeaders headers, @Context UriInfo uriInfo) {

        try {
            GroupDefinition def = definitionManager.getById(definitionId);
            GroupDefinitionRest gdr = buildGDRestFromDefinition(def);

            createLinksForGDRest(uriInfo,gdr);

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

        @ApiParam("Validate if the definition exists") @QueryParam("validate") @DefaultValue("false") boolean validate,
        @Context HttpHeaders headers) {

        Response.ResponseBuilder builder;
        try {
            GroupDefinition def = definitionManager.getById(definitionId);
            definitionManager.removeGroupDefinition(caller,definitionId);
            builder = Response.noContent();
        } catch (GroupDefinitionNotFoundException e) {
            if (validate) {
                builder = Response.status(Response.Status.NOT_FOUND);
View Full Code Here

        }
        if (builder!=null)
            return builder.build();


        GroupDefinition gd = new GroupDefinition(definition.getName());
        gd.setDescription(definition.getDescription());
        addGroupDefinitionExpression(definition, gd);
        if (definition.getRecalcInterval() < 0 ) {
            throw new BadArgumentException("Recalculation interval must be >= 0");
        }
        gd.setRecalculationInterval(definition.getRecalcInterval());
        gd.setRecursive(definition.isRecursive());

        try {
            GroupDefinition res = definitionManager.createGroupDefinition(caller,gd);
            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/group/definition/{id}");
            URI location = uriBuilder.build(res.getId());

            Link link = new Link("edit",location.toString());
            builder= Response.created(location);
            GroupDefinitionRest gdr = buildGDRestFromDefinition(res);
            createLinksForGDRest(uriInfo,gdr);
View Full Code Here

                                          @DefaultValue("false") boolean recalculate,
                                          GroupDefinitionRest definition, // TODO mark as optional?
                                          @Context HttpHeaders headers,
                                          @Context UriInfo uriInfo) {

        GroupDefinition gd;
        try {
            gd = definitionManager.getById(definitionId);
        } catch (GroupDefinitionNotFoundException e) {
            throw new StuffNotFoundException("Group Definition with id " + definitionId);
        }

        Response.ResponseBuilder builder = null;

        if (recalculate) {
            try {
                definitionManager.calculateGroupMembership(caller,gd.getId());
                builder = Response.noContent();
            } catch (Exception e) {
                builder = Response.status(Response.Status.NOT_ACCEPTABLE);
                builder.entity(e.getLocalizedMessage());
            }
            return builder.build();
        }

        // Not recalculation, but an update

        if (!definition.getName().isEmpty()) {
            gd.setName(definition.getName());
        }
        gd.setDescription(definition.getDescription());
        addGroupDefinitionExpression(definition,gd);
        if (definition.getRecalcInterval() < 0 ) {
            throw new BadArgumentException("Recalculation interval must be >= 0");
        }
        gd.setRecalculationInterval(definition.getRecalcInterval());
        gd.setRecursive(definition.isRecursive());

        try {
            definitionManager.updateGroupDefinition(caller,gd);
        } catch (Exception e) {
            builder = Response.status(Response.Status.NOT_ACCEPTABLE);
            builder.entity(e.getLocalizedMessage());
            return builder.build();
        }


        try {
            // Re-fetch, as groups may have changed
            gd = definitionManager.getById(gd.getId());
            GroupDefinitionRest gdr = buildGDRestFromDefinition(gd);
            createLinksForGDRest(uriInfo, gdr);

            builder = Response.ok(gdr);
        } catch (GroupDefinitionNotFoundException e) {
            builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
            builder.entity("Group Definition with id " + gd.getId());
        }

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
        builder.type(mediaType);
        return builder.build();
View Full Code Here

                log.error("Error recalculating DynaGroups for GroupDefinition[id=" + groupDefinitionId + "]", t);
            }
            long singleEnd = System.currentTimeMillis();

            try {
                GroupDefinition groupDefinition = getById(groupDefinitionId);
                int size = getManagedResourceGroupSizeForGroupDefinition(groupDefinitionId);
                monitor.updateStatistic(groupDefinition.getName(), size, success, singleEnd - singleStart);
            } catch (Throwable t) {
                log.error("Error updating DynaGroup statistics GroupDefinition[id=" + groupDefinitionId + "]", t);
                // ignore error during statistic update
            }
        }
View Full Code Here

        long totalEnd = System.currentTimeMillis();
        monitor.updateAutoRecalculationThreadTime(totalEnd - totalStart);
    }

    public GroupDefinition getById(int groupDefinitionId) throws GroupDefinitionNotFoundException {
        GroupDefinition groupDefinition = entityManager.find(GroupDefinition.class, groupDefinitionId);
        if (groupDefinition == null) {
            throw new GroupDefinitionNotFoundException("Group definition with specified id does not exist");
        }

        return groupDefinition;
View Full Code Here

        } catch (GroupDefinitionException gde) {
            throw new GroupDefinitionUpdateException(gde.getMessage());
        }

        RecursivityChangeType changeType = RecursivityChangeType.None;
        GroupDefinition attachedGroupDefinition = null;
        try {
            attachedGroupDefinition = getById(groupDefinition.getId());
        } catch (GroupDefinitionNotFoundException gdnfe) {
            throw new GroupDefinitionUpdateException(gdnfe.getMessage());
        }
        if (groupDefinition.isRecursive() == true && attachedGroupDefinition.isRecursive() == false) {
            // making a recursive group into a "normal" group
            changeType = RecursivityChangeType.AddedRecursion;
        } else if (groupDefinition.isRecursive() == false && attachedGroupDefinition.isRecursive() == true) {
            // making a "normal" group into a recursive group
            changeType = RecursivityChangeType.RemovedRecursion;
        } else {
            // recursive bit didn't change
        }

        if (nameChanged || changeType != RecursivityChangeType.None) {
            String oldGroupDefinitionName = attachedGroupDefinition.getName();
            Subject overlord = subjectManager.getOverlord();
            for (ResourceGroup dynaGroup : attachedGroupDefinition.getManagedResourceGroups()) {
                String dynaGroupName = dynaGroup.getName();
                String newDynaGroupName = updateDynaGroupName(oldGroupDefinitionName, groupDefinition.getName(),
                    dynaGroupName);
                dynaGroup.setName(newDynaGroupName);
                // do not set recursive bit here
                // the update method will figure out whether to flip it by inspecting its managing GroupDefinition
                //dynaGroup.setRecursive(groupDefinition.isRecursive());
                resourceGroupManager.updateResourceGroup(overlord, dynaGroup, changeType);
            }
        }

        // do not call entityManager.merge, it could overwrite managed fields
        // merge fields explicitly to control precisely which fields get updated
        attachedGroupDefinition.setName(groupDefinition.getName());
        attachedGroupDefinition.setDescription(groupDefinition.getDescription());
        attachedGroupDefinition.setRecursive(groupDefinition.isRecursive());
        attachedGroupDefinition.setExpression(groupDefinition.getExpression());
        attachedGroupDefinition.setRecalculationInterval(groupDefinition.getRecalculationInterval());
        if (detachFromCannedExpression) {
            attachedGroupDefinition.setCannedExpression(null);
        }
        return attachedGroupDefinition;
    }
View Full Code Here

        Query query = entityManager.createNamedQuery(GroupDefinition.QUERY_FIND_BY_NAME);
        query.setParameter("name", name);

        try {
            GroupDefinition found = (GroupDefinition) query.getSingleResult();
            if ((id == null) // null == id means creating new def - so if query has results, it's a dup
                || (found.getId() != id)) // found != id means updating def - so if query has result, only dup if ids don't match
            {
                throw new GroupDefinitionAlreadyExistsException("GroupDefinition with name " + name + " already exists");
            }
        } catch (NoResultException e) {
            // user is changing the name of the group, this is OK
View Full Code Here

         * correct the expression set before attempting to calculate the effective group again.
         */

        long startTime = System.currentTimeMillis();

        GroupDefinition groupDefinition = getById(groupDefinitionId);
        groupDefinition.setLastCalculationTime(System.currentTimeMillis()); // we're calculating now

        ExpressionEvaluator evaluator = new ExpressionEvaluator();
        for (String expression : groupDefinition.getExpressionAsList()) {
            evaluator.addExpression(expression);
        }

        Collection<Integer> doomedResourceGroupIds = new ArrayList<Integer>();
        for (Integer managedGroupId : getManagedResourceGroupIdsForGroupDefinition(groupDefinitionId)) {
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.resource.group.GroupDefinition

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.