modules/enterprise/gui/rest-war/src/main/webapp/WEB-INF/web.xml
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AbstractRestBean.java
| 2
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
| 51 ++++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/ResourceWithType.java
| 20 ++
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
| 73 +++++++++-
modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
| 18 ++
6 files changed, 161 insertions(+), 5 deletions(-)
New commits:
commit 581a5b03422cb55dc88551b52231b048acb43f60
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Mon Jun 3 16:17:57 2013 +0200
BZ 966381 - allow to import servers and update resources.
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AbstractRestBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AbstractRestBean.java
index 224ab3f..62a85ca 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AbstractRestBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/AbstractRestBean.java
@@ -274,6 +274,8 @@ public class AbstractRestBean {
rwt.setTypeId(resourceType.getId());
rwt.setPluginName(resourceType.getPlugin());
rwt.setStatus(res.getInventoryStatus().name());
+ rwt.setLocation(res.getLocation());
+ rwt.setDescription(res.getDescription());
Resource parent = res.getParentResource();
if (parent != null) {
rwt.setParentId(parent.getId());
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
index 332dfbc..3ee8f19 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/ResourceHandlerBean.java
@@ -63,6 +63,7 @@ import javax.ws.rs.core.UriInfo;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiError;
+import com.wordnik.swagger.annotations.ApiErrors;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
@@ -96,6 +97,7 @@ import org.rhq.core.domain.util.PageOrdering;
import org.rhq.enterprise.server.RHQConstants;
import org.rhq.enterprise.server.alert.AlertManagerLocal;
import org.rhq.enterprise.server.core.AgentManagerLocal;
+import org.rhq.enterprise.server.discovery.DiscoveryBossLocal;
import org.rhq.enterprise.server.measurement.AvailabilityManagerLocal;
import org.rhq.enterprise.server.resource.ResourceAlreadyExistsException;
import org.rhq.enterprise.server.resource.ResourceFactoryManagerLocal;
@@ -136,6 +138,8 @@ public class ResourceHandlerBean extends AbstractRestBean {
AgentManagerLocal agentMgr;
@EJB
ResourceFactoryManagerLocal resourceFactory;
+ @EJB
+ DiscoveryBossLocal discoveryBoss;
@PersistenceContext(unitName = RHQConstants.PERSISTENCE_UNIT_NAME)
private EntityManager entityManager;
@@ -174,6 +178,50 @@ public class ResourceHandlerBean extends AbstractRestBean {
return builder.build();
}
+ @PUT
+ @Path("/{id:\\d+}")
+ @ApiOperation(value = "Update a single resource (name, description, location)
that is committed or import "+
+ "a resource that is new. To do the latter you need to PUT the resource
retrieved with a COMMITTED state",
+ responseClass = "ResourceWithType")
+ @ApiErrors({
+ @ApiError(code = 404, reason = NO_RESOURCE_FOR_ID),
+ @ApiError(code = 406, reason = "Tried to update a resource that is not
COMMITTED")
+ })
+ public Response updateResource(@ApiParam("Id of the resource to import")
@PathParam("id") int resourceId,
+ @ApiParam("Resource to update" )
ResourceWithType resourceWithType,
+ @Context UriInfo uriInfo) {
+
+ Resource res = fetchResource(resourceId);
+
+ if (res.getInventoryStatus()==InventoryStatus.NEW &&
res.getResourceType().getCategory()!=ResourceCategory.SERVICE &&
resourceWithType.getStatus().equalsIgnoreCase("COMMITTED")) {
+ // 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();
+
+ }
+
@GET @GZIP
@Path("/")
@ApiError(code = 406, reason = "The passed inventory status was invalid")
@@ -189,7 +237,6 @@ public class ResourceHandlerBean extends AbstractRestBean {
ResourceCriteria criteria = new ResourceCriteria();
criteria.addSortName(PageOrdering.ASC);
- criteria.addSortId(PageOrdering.ASC);
if (!status.toLowerCase().equals("all")) {
try {
criteria.addFilterInventoryStatus(InventoryStatus.valueOf(status.toUpperCase()));
@@ -270,7 +317,7 @@ public class ResourceHandlerBean extends AbstractRestBean {
} else {
if (mediaType.equals(wrappedCollectionJsonType)) {
- wrapForPaging(builder,uriInfo,resources,rwtList);
+ wrapForPaging(builder, uriInfo, resources, rwtList);
} else {
GenericEntity<List<ResourceWithType>> list = new
GenericEntity<List<ResourceWithType>>(rwtList) {
};
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/ResourceWithType.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/ResourceWithType.java
index 8273737..f802f35 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/ResourceWithType.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/rest/domain/ResourceWithType.java
@@ -47,6 +47,8 @@ public class ResourceWithType {
String status;
List<Link> links = new ArrayList<Link>();
private String ancestry;
+ private String location;
+ private String description;
public ResourceWithType() {
}
@@ -156,4 +158,22 @@ public class ResourceWithType {
", ancestry='" + ancestry + '\'' +
'}';
}
+
+ @ApiProperty("The location of the resource (e.g. data center / rack")
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ @ApiProperty("A description of the resource")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
}
diff --git
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
index 6b78fe7..852f802 100644
---
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
+++
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
@@ -456,7 +456,7 @@ public class ResourcesTest extends AbstractBase {
.expect()
.statusCode(201)
.log().everything()
- .body("resourceId",instanceOf(Number.class))
+ .body("resourceId", instanceOf(Number.class))
.when()
.post("/resource/platforms");
@@ -511,6 +511,60 @@ public class ResourcesTest extends AbstractBase {
}
@Test
+ public void testCreateUpdateRemovePlatform() throws Exception {
+
+ Resource resource = new Resource();
+ resource.setResourceName("dummy-test");
+ resource.setTypeName("Linux");
+
+ Response response =
+ given()
+ .header(acceptXml)
+ .contentType(ContentType.JSON)
+ .body(resource)
+ .expect()
+ .statusCode(201)
+ .log().ifError()
+ .when()
+ .post("/resource/platforms");
+
+ int platformId=0;
+ try {
+ XmlPath xmlPath = response.xmlPath();
+ Node resource1 = xmlPath.get("resource");
+ Node platformIdNode = resource1.get("resourceId");
+ platformId = Integer.parseInt(platformIdNode.value());
+
+ // Now update the description
+ resource.setDescription("li la lu");
+ resource.setLocation("Datacenter 1");
+ resource.setResourceName("DummY");
+
+ given()
+ .pathParam("id",platformId)
+ .body(resource)
+ .contentType(ContentType.JSON)
+ .header(acceptJson)
+ .expect()
+ .statusCode(200)
+ .log().ifError()
+ .body("location",is("Datacenter 1"))
+ .body("description",is("li la lu"))
+ .body("resourceName",is("DummY"))
+ .when()
+ .put("/resource/{id}");
+
+ } finally {
+ given()
+ .pathParam("id", platformId)
+ .expect()
+ .statusCode(HttpStatus.SC_NO_CONTENT)
+ .when()
+ .delete("/resource/{id}");
+ }
+ }
+
+ @Test
public void testCreatePlatformUpdateAvailabilityAndRemove() throws Exception {
Resource resource = new Resource();
diff --git
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
index f060101..5eb33d2 100644
---
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
+++
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/d/Resource.java
@@ -37,6 +37,8 @@ public class Resource {
int typeId;
List<Map> links;
String ancestry;
+ String location;
+ String description;
public Resource() {
}
@@ -112,4 +114,20 @@ public class Resource {
public void setStatus(String status) {
this.status = status;
}
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
}
commit bdd1e0055764d9c6127f8f02b004f940553c3b9f
Author: Heiko W. Rupp <hwr(a)redhat.com>
Date: Mon Jun 3 12:56:20 2013 +0200
Allow to use the .jsonw prefix to request the application/vnd.rhq.wrapped+json type
diff --git a/modules/enterprise/gui/rest-war/src/main/webapp/WEB-INF/web.xml
b/modules/enterprise/gui/rest-war/src/main/webapp/WEB-INF/web.xml
index f336c60..164707f 100644
--- a/modules/enterprise/gui/rest-war/src/main/webapp/WEB-INF/web.xml
+++ b/modules/enterprise/gui/rest-war/src/main/webapp/WEB-INF/web.xml
@@ -7,7 +7,7 @@
<context-param>
<param-name>resteasy.media.type.mappings</param-name>
<param-value>html : text/html, json : application/json, xml : application/xml,
csv : text/csv, txt: text/plain,
- yaml: application/yaml
+ yaml: application/yaml, jsonw: application/vnd.rhq.wrapped+json
</param-value>
</context-param>
diff --git
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
index 900ab10..6b78fe7 100644
---
a/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
+++
b/modules/integration-tests/rest-api/src/test/java/org/rhq/modules/integrationTests/restApi/ResourcesTest.java
@@ -33,7 +33,6 @@ import com.jayway.restassured.path.json.JsonPath;
import com.jayway.restassured.path.xml.XmlPath;
import com.jayway.restassured.path.xml.element.Node;
import com.jayway.restassured.response.Response;
-import com.jayway.restassured.response.ResponseBody;
import org.apache.http.HttpStatus;
import org.junit.Test;
@@ -344,6 +343,22 @@ public class ResourcesTest extends AbstractBase {
}
@Test
+ public void testGetResourcesWithPagingAndWrappingByExtension() throws Exception {
+
+ given()
+ .queryParam("page", 1)
+ .queryParam("ps", 2) // Unusually small to provoke having more
than 1 page
+ .queryParam("category", "service")
+ .expect()
+ .statusCode(200)
+ .log().everything()
+ .body("pageSize",is(2))
+ .body("currentPage",is(1))
+ .when()
+ .get("/resource.jsonw");
+ }
+
+ @Test
public void testGetPlatformsWithPaging() throws Exception {
given()