Eli Mesika has uploaded a new change for review.

Change subject: [WIP] API: Adding StepResource and StepsResource..
......................................................................

[WIP] API: Adding StepResource and StepsResource..

API: Adding StepResource and StepsResource interfaces

Change-Id: Id1b95a094dc586e6ebbdacd44e0a034e91605496
Signed-off-by: Eli Mesika <[email protected]>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=872719
---
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepResource.java
A 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepsResource.java
A 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStepsResource.java
3 files changed, 149 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/16163/1

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepResource.java
new file mode 100644
index 0000000..317a7cc
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepResource.java
@@ -0,0 +1,32 @@
+package org.ovirt.engine.api.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.providers.jaxb.Formatted;
+import org.ovirt.engine.api.model.Action;
+import org.ovirt.engine.api.model.Actionable;
+import org.ovirt.engine.api.model.Step;
+
+@Produces( { ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
+public interface StepResource {
+
+  @Path("{action: (end)}/{oid}")
+  public ActionResource getActionSubresource(@PathParam("action")String 
action, @PathParam("oid")String oid);
+
+  @POST
+  @Formatted
+  @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+  @Actionable
+  @Path("end")
+  public Response end(Action action);
+
+    @GET
+    @Formatted
+    public Step get();
+}
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepsResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepsResource.java
new file mode 100644
index 0000000..58c98d0
--- /dev/null
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/StepsResource.java
@@ -0,0 +1,35 @@
+package org.ovirt.engine.api.resource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
+
+import org.jboss.resteasy.annotations.providers.jaxb.Formatted;
+import org.ovirt.engine.api.model.Step;
+import org.ovirt.engine.api.model.Steps;
+
+@Produces( { ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML })
+public interface StepsResource {
+
+    @GET
+    @Formatted
+    public Steps list();
+
+    @POST
+    @Formatted
+    @Consumes({ApiMediaType.APPLICATION_XML, ApiMediaType.APPLICATION_JSON, 
ApiMediaType.APPLICATION_X_YAML})
+    public Response add(Step step);
+
+    /**
+     * Sub-resource locator method, returns individual EventResource on which 
the remainder of the URI is dispatched.
+     *
+     * @param id the Event ID
+     * @return matching sub-resource if found
+     */
+    @Path("{id}")
+    public StepResource getStepSubResource(@PathParam("id") String id);
+}
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStepsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStepsResource.java
new file mode 100644
index 0000000..d82302e
--- /dev/null
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendStepsResource.java
@@ -0,0 +1,82 @@
+package org.ovirt.engine.api.restapi.resource;
+
+import java.util.List;
+
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.lang.NotImplementedException;
+import org.ovirt.engine.api.model.Job;
+import org.ovirt.engine.api.model.Step;
+import org.ovirt.engine.api.model.Steps;
+import org.ovirt.engine.api.resource.StepResource;
+import org.ovirt.engine.api.resource.StepsResource;
+import org.ovirt.engine.api.restapi.types.StepMapper;
+import org.ovirt.engine.core.common.action.AddExternalStepParameters;
+import org.ovirt.engine.core.common.action.VdcActionType;
+import org.ovirt.engine.core.common.queries.GetStepsByJobIdQueryParameters;
+import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryType;
+import org.ovirt.engine.core.compat.Guid;
+
+public class BackendStepsResource extends 
AbstractBackendCollectionResource<org.ovirt.engine.api.model.Step, 
org.ovirt.engine.core.common.job.Step> implements StepsResource {
+
+    private Guid jobId;
+
+    public BackendStepsResource(Guid jobId) {
+        super(org.ovirt.engine.api.model.Step.class, 
org.ovirt.engine.core.common.job.Step.class);
+        this.jobId = jobId;
+    }
+
+    @Override
+    public Steps list() {
+        GetStepsByJobIdQueryParameters params = new 
GetStepsByJobIdQueryParameters(jobId);
+        List<org.ovirt.engine.core.common.job.Step> steps = 
getBackendCollection(VdcQueryType.GetStepsByJobId,params);
+        return mapCollection(steps);
+    }
+
+    @Override
+    public Response add(Step step) {
+        validateParameters(step, "job" , "stepType", "status" , "description");
+        String id;
+        if (step.isSetParentStep()) {
+            id = step.getParentStep().getId();
+        }
+        else {
+            id = step.getJob().getId();
+        }
+        return performCreate(VdcActionType.AddExternalStep,
+                new AddExternalStepParameters(Guid.createGuidFromString(id), 
step.getDescription(),StepMapper.map(step.getStepType()), 
StepMapper.map(step.getStatus())),
+                new QueryIdResolver<Guid>(VdcQueryType.GetStepByStepId, 
IdQueryParameters.class));
+    }
+
+    @Override
+    public StepResource getStepSubResource(@PathParam("id") String id) {
+        return inject(new BackendStepResource(id, this));
+    }
+
+    @Override
+    protected Response performRemove(String id) {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    protected Step doPopulate(Step model, 
org.ovirt.engine.core.common.job.Step entity) {
+        return model;
+    }
+
+    protected Steps mapCollection(List<org.ovirt.engine.core.common.job.Step> 
entities) {
+        Steps collection = new Steps();
+        for (org.ovirt.engine.core.common.job.Step entity : entities) {
+            collection.getSteps().add(addLinks(map(entity)));
+        }
+        return collection;
+    }
+
+    @Override
+    protected Step addParents(Step model) {
+        model.setJob(new Job());
+        model.getJob().setId(jobId.toString());
+        return model;
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/16163
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id1b95a094dc586e6ebbdacd44e0a034e91605496
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Eli Mesika <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to