Skip to content

Commit

Permalink
dcache-frontend: adjust REST API for Pool Info Resources
Browse files Browse the repository at this point in the history
Motivation:

Inconsistent use of POST for methods to kill  movers and change pool mode.

Modification:

Use DELETE with path to kill movers.  Use PATCH with path and json request
to change pool mode.

NOTE:  I have decided to let the bulk operations go for the moment.

Result:

REST API adheres to best practice.

Target: master
Request: 3.2
Require-notes: yes
Require-book: yes
Acked-by: Paul
  • Loading branch information
alrossi committed Oct 25, 2017
1 parent df6493a commit cdf6aaa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 143 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,10 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
public class PoolModeUpdate implements Serializable {
private static final long serialVersionUID = 4199793636351366103L;

private String pool;
private boolean strict;
private boolean rdonly;
private boolean resilience;

public String getPool() {
return pool;
}

public boolean isRdonly() {
return rdonly;
}
Expand All @@ -103,10 +98,6 @@ public int mode() {
return PoolV2Mode.ENABLED;
}

public void setPool(String pool) {
this.pool = pool;
}

public void setRdonly(boolean rdonly) {
this.rdonly = rdonly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*/
package org.dcache.restful.resources.pool;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONException;
import org.springframework.stereotype.Component;
Expand All @@ -70,19 +68,19 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.ForbiddenException;
import javax.ws.rs.GET;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.POST;
import javax.ws.rs.PATCH;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.io.IOException;

import diskCacheV111.pools.PoolV2Mode;
Expand All @@ -91,14 +89,11 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
import diskCacheV111.vehicles.Message;
import diskCacheV111.vehicles.PoolModifyModeMessage;
import diskCacheV111.vehicles.PoolMoverKillMessage;

import dmg.cells.nucleus.CellPath;
import dmg.cells.nucleus.NoRouteToCellException;

import org.dcache.cells.CellStub;
import org.dcache.restful.providers.pool.PoolGroupInfo;
import org.dcache.restful.providers.pool.PoolInfo;
import org.dcache.restful.providers.pool.PoolKillMover;
import org.dcache.restful.providers.pool.PoolModeUpdate;
import org.dcache.restful.services.pool.PoolInfoService;
import org.dcache.restful.util.HttpServletRequests;
Expand Down Expand Up @@ -344,35 +339,24 @@ public String[] getPools(@QueryParam("group") String group)

/**
* <p>Request to update the indicated pool to either enabled or disabled.</p>
*
* @param requestPayload containing the object with updated fields.
*/
@POST
@Path("movers")
@Consumes(MediaType.APPLICATION_JSON)
@DELETE
@Path("{pool : .*}/mover/{id : [0-9]*}")
@Produces(MediaType.APPLICATION_JSON)
public Response killMovers(String requestPayload) throws
CacheException {
public Response killMovers(@PathParam("pool") String pool,
@PathParam("id") int id ) {
if (!HttpServletRequests.isAdmin(request)) {
throw new ForbiddenException(
"Pool command only accessible to admin users.");
}

try {
PoolKillMover update = new ObjectMapper().readValue(requestPayload,
PoolKillMover.class);
String pool = update.getPool();
Message message;
Integer moverId = update.getMoverId();
if (moverId != null) {
message = new PoolMoverKillMessage(pool, moverId,
update.getReason());
poolStub.sendAndWait(new CellPath(pool), message);
}
} catch (JSONException | IllegalArgumentException | JsonParseException
| JsonMappingException e) {
poolStub.sendAndWait(new CellPath(pool),
new PoolMoverKillMessage(pool, id,
"Killed by user."));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e);
} catch (IOException | InterruptedException | NoRouteToCellException e) {
} catch (InterruptedException | NoRouteToCellException | CacheException e) {
throw new InternalServerErrorException(e);
}

Expand All @@ -382,14 +366,14 @@ public Response killMovers(String requestPayload) throws
/**
* <p>Request to update the indicated pool to either enabled or disabled.</p>
*
* @param requestPayload containing the object with updated fields.
* @param requestPayload containing the mode specification.
*/
@POST
@Path("mode")
@PATCH
@Path("{pool : .*}/mode")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateMode(String requestPayload) throws
CacheException {
public Response updateMode(@PathParam("pool") String pool,
String requestPayload) {
if (!HttpServletRequests.isAdmin(request)) {
throw new ForbiddenException(
"Pool command only accessible to admin users.");
Expand All @@ -399,15 +383,13 @@ public Response updateMode(String requestPayload) throws
PoolModeUpdate update
= new ObjectMapper().readValue(requestPayload,
PoolModeUpdate.class);
String pool = update.getPool();
PoolV2Mode mode = new PoolV2Mode(update.mode());
mode.setResilienceEnabled(update.isResilience());
Message message = new PoolModifyModeMessage(pool, mode);
poolStub.sendAndWait(new CellPath(pool), message);
} catch (JSONException | IllegalArgumentException | JsonParseException
| JsonMappingException e) {
} catch (JSONException | IllegalArgumentException | IOException e) {
throw new BadRequestException(e);
} catch (IOException | InterruptedException | NoRouteToCellException e) {
} catch (InterruptedException | NoRouteToCellException | CacheException e) {
throw new InternalServerErrorException(e);
}

Expand Down

0 comments on commit cdf6aaa

Please sign in to comment.