Package org.rhq.enterprise.server.rest.domain

Examples of org.rhq.enterprise.server.rest.domain.ResourceWithType


        ret.setAlertTime(al.getCtime());
        ret.setDescription(alertManager.prettyPrintAlertConditions(al,false));
        ret.setRecoveryTime(al.getRecoveryTime());

        Resource r = fetchResource(alertDefinition.getResource().getId());
        ResourceWithType rwt;
        if (slim) {
            rwt = new ResourceWithType(r.getName(),r.getId());
        } else {
            rwt = fillRWT(r,uriInfo);
        }
        ret.setResource(rwt);
View Full Code Here


        return true;
    }

    public ResourceWithType fillRWT(Resource res, UriInfo uriInfo) {
        ResourceType resourceType = res.getResourceType();
        ResourceWithType rwt = new ResourceWithType(res.getName(), res.getId());
        rwt.setTypeName(resourceType.getName());
        rwt.setTypeId(resourceType.getId());
        rwt.setPluginName(resourceType.getPlugin());
        rwt.setStatus(res.getInventoryStatus().name());
        rwt.setLocation(res.getLocation());
        rwt.setDescription(res.getDescription());
        rwt.setAvailability(res.getCurrentAvailability().getAvailabilityType().toString());
        Resource parent = res.getParentResource();
        if (parent != null) {
            rwt.setParentId(parent.getId());
        } else {
            rwt.setParentId(0);
        }

        rwt.setAncestry(res.getAncestry());

        UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/operation/definitions");
        uriBuilder.queryParam("resourceId", res.getId());
        URI uri = uriBuilder.build();
        Link link = new Link("operationDefinitions", uri.toString());
        rwt.addLink(link);

        link = getLinkToResource(res, uriInfo, "self");
        rwt.addLink(link);
        uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/resource/{id}/schedules");
        uri = uriBuilder.build(res.getId());
        link = new Link("schedules", uri.toString());
        rwt.addLink(link);
        uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/resource/{id}/availability");
        uri = uriBuilder.build(res.getId());
        link = new Link("availability", uri.toString());
        rwt.addLink(link);
        uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/resource/{id}/children");
        uri = uriBuilder.build(res.getId());
        link = new Link("children", uri.toString());
        rwt.addLink(link);
        uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/resource/{id}/alerts");
        uri = uriBuilder.build(res.getId());
        link = new Link("alerts", uri.toString());
        rwt.addLink(link);
        uriBuilder = uriInfo.getBaseUriBuilder();
        uriBuilder.path("/alert/definitions");
        uriBuilder.queryParam("resourceId",res.getId());
        uri = uriBuilder.build(res.getId());
        link = new Link("alertDefinitions", uri.toString());
        rwt.addLink(link);
        if (parent != null) {
            uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/{id}/");
            uri = uriBuilder.build(parent.getId());
            link = new Link("parent", uri.toString());
            rwt.addLink(link);
        }
        rwt.addLink(createUILink(uriInfo,UILinkTemplate.RESOURCE,res.getId()));

        return rwt;
    }
View Full Code Here

        MediaType mediaType = httpHeaders.getAcceptableMediaTypes().get(0);
        for (Integer id : favIds) {
            try {
                Resource res = resourceManager.getResource(caller, id);

                ResourceWithType rwt = fillRWT(res, uriInfo);
                ret.add(rwt);
            } catch (Exception e) {
                if (e instanceof ResourceNotFoundException) {
                    log.debug("Favorite resource with id " + id + " not found - not returning to the user");
                }
View Full Code Here

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

        ResourceWithType rwt = fillRWT(res, uriInfo);

        // What media type does the user request?
        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);

        if (mediaType.equals(MediaType.TEXT_HTML_TYPE)) {
View Full Code Here

            // Import
            discoveryBoss.importResources(caller,new int[] { resourceId});

            res = fetchResource(resourceId);

            ResourceWithType outWithType = fillRWT(res,uriInfo);

            return Response.ok(outWithType).build();
        }

        // Import was handled above, so we require committed state now
        if (res.getInventoryStatus()!=InventoryStatus.COMMITTED) {
            throw new BadArgumentException("Can only update resources in committed state");
        }

        // No import, so update some of the allowed items
        Resource in = new Resource(res.getId());
        in.setName(resourceWithType.getResourceName());
        in.setDescription(resourceWithType.getDescription());
        in.setLocation(resourceWithType.getLocation());
        Resource out = resMgr.updateResource(caller,in);

        ResourceWithType outWithType = fillRWT(out,uriInfo);

        return Response.ok(outWithType).build();

    }
View Full Code Here

    private Response.ResponseBuilder getResponseBuilderForResourceList(HttpHeaders headers, UriInfo uriInfo,
                                                                       PageList<Resource> resources) {
        List<ResourceWithType> rwtList = new ArrayList<ResourceWithType>(resources.size());
        for (Resource r : resources) {
            putToCache(r.getId(), Resource.class, r);
            ResourceWithType rwt = fillRWT(r, uriInfo);
            rwtList.add(rwt);
        }
        // What media type does the user request?
        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
        Response.ResponseBuilder builder = Response.ok();
View Full Code Here

        parent = fetchResource(id);
        List<Resource> ret = resMgr.findResourceByParentAndInventoryStatus(caller, parent, InventoryStatus.COMMITTED,
            pc);
        List<ResourceWithType> rwtList = new ArrayList<ResourceWithType>(ret.size());
        for (Resource r : ret) {
            ResourceWithType rwt = fillRWT(r, uriInfo);
            rwtList.add(rwt);
        }

        // What media type does the user request?
        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
View Full Code Here

        String resourceKey = "p:" + name;
        Resource r = resMgr.getResourceByParentAndKey(caller,null,resourceKey,"Platforms",typeName);
        if (r!=null) {
            // platform exists - return it
            ResourceWithType rwt = fillRWT(r,uriInfo);

            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/{id}");
            URI uri = uriBuilder.build(r.getId());


            Response.ResponseBuilder builder = Response.created(uri);
            builder.entity(rwt);
            return builder.build();

        }

        // Create a dummy agent per platform - otherwise we can't delete the platform later
        // See also https://docs.jboss.org/author/display/RHQ/Virtual+platforms+and+synthetic+agents
        Agent agent ;
        agent = new Agent(DUMMY_AGENT_NAME_PREFIX + name, "-dummy-p:" + name, 12345, "http://foo.com/p:name/" + name,
            DUMMY_AGENT_TOKEN_PREFIX + name);
        agentMgr.createAgent(agent);

        Resource platform = new Resource(resourceKey,name,type);
        platform.setUuid(UUID.randomUUID().toString());
        platform.setAgent(agent);
        platform.setInventoryStatus(InventoryStatus.COMMITTED);
        platform.setModifiedBy(caller.getName());
        platform.setDescription(type.getDescription() + ". Created via REST-api");
        platform.setItime(System.currentTimeMillis());

        try {
            resMgr.createResource(caller,platform,-1);

            createSchedules(platform);

            ResourceWithType rwt = fillRWT(platform,uriInfo);
            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/{id}");
            URI uri = uriBuilder.build(platform.getId());

            Response.ResponseBuilder builder = Response.created(uri);
View Full Code Here

        Response.ResponseBuilder builder;

        if ( status == CreateResourceStatus.SUCCESS) {

            ResourceWithType rwt = findCreatedResource(history.getParentResource().getId(),history.getCreatedResourceName(),uriInfo);
            if (rwt!=null) {
                builder = Response.ok();
                builder.entity(rwt);
            } else {
                // History says we had success but due to internal timing
View Full Code Here

        String resourceKey = "res:" + name + ":" + parentId;

        Resource r = resMgr.getResourceByParentAndKey(caller,parent,resourceKey,plugin,typeName);
        if (r!=null) {
            // resource exists - return it
            ResourceWithType rwt = fillRWT(r,uriInfo);

            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/{id}");
            URI uri = uriBuilder.build(r.getId());

            Response.ResponseBuilder builder = Response.created(uri);
            builder.entity(rwt);
            return builder.build();
        }

        Resource res = new Resource(resourceKey,name,resType);
        res.setUuid(UUID.randomUUID().toString());
        res.setAgent(parent.getAgent());
        res.setParentResource(parent);
        res.setInventoryStatus(InventoryStatus.COMMITTED);
        res.setDescription(resType.getDescription() + ". Created via REST-api");

        try {
            resMgr.createResource(caller,res,parent.getId());

            createSchedules(res);

            ResourceWithType rwt = fillRWT(res,uriInfo);

            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/{id}");
            URI uri = uriBuilder.build(res.getId());
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.server.rest.domain.ResourceWithType

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.