Search in sources :

Example 1 with Result

use of com.netflix.exhibitor.core.entities.Result in project exhibitor by soabase.

the class ClusterResource method setControlPanelSetting.

@Path("set/{type}/{value}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String setControlPanelSetting(@PathParam("type") String typeStr, @PathParam("value") boolean newValue) throws Exception {
    ControlPanelTypes type = null;
    try {
        type = ControlPanelTypes.fuzzyFind(typeStr);
    } catch (IllegalArgumentException ignore) {
    // ignore
    }
    Result result;
    if (type != null) {
        try {
            context.getExhibitor().getControlPanelValues().set(type, newValue);
            result = new Result("OK", true);
        } catch (Exception e) {
            result = new Result(e);
        }
    } else {
        result = new Result("Not found", false);
    }
    return JsonUtil.writeValueAsString(result);
}
Also used : ControlPanelTypes(com.netflix.exhibitor.core.controlpanel.ControlPanelTypes) Result(com.netflix.exhibitor.core.entities.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Result

use of com.netflix.exhibitor.core.entities.Result in project exhibitor by soabase.

the class ClusterResource method stopZooKeeper.

@Path("stop")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String stopZooKeeper() throws Exception {
    context.getExhibitor().getActivityQueue().add(QueueGroups.MAIN, new KillRunningInstance(context.getExhibitor(), false));
    Result result = new Result("OK", true);
    return JsonUtil.writeValueAsString(result);
}
Also used : KillRunningInstance(com.netflix.exhibitor.core.state.KillRunningInstance) Result(com.netflix.exhibitor.core.entities.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with Result

use of com.netflix.exhibitor.core.entities.Result in project exhibitor by soabase.

the class ClusterResource method stopStartZooKeeper.

@Path("restart")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String stopStartZooKeeper() throws Exception {
    context.getExhibitor().getActivityQueue().add(QueueGroups.MAIN, new KillRunningInstance(context.getExhibitor(), true));
    Result result = new Result("OK", true);
    return JsonUtil.writeValueAsString(result);
}
Also used : KillRunningInstance(com.netflix.exhibitor.core.state.KillRunningInstance) Result(com.netflix.exhibitor.core.entities.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with Result

use of com.netflix.exhibitor.core.entities.Result in project exhibitor by soabase.

the class ClusterResource method startZooKeeper.

@Path("start")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String startZooKeeper() throws Exception {
    context.getExhibitor().getActivityQueue().add(QueueGroups.MAIN, new StartInstance(context.getExhibitor()));
    Result result = new Result("OK", true);
    return JsonUtil.writeValueAsString(result);
}
Also used : StartInstance(com.netflix.exhibitor.core.state.StartInstance) Result(com.netflix.exhibitor.core.entities.Result) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with Result

use of com.netflix.exhibitor.core.entities.Result in project exhibitor by soabase.

the class ExplorerResource method createNode.

@PUT
@Path("znode/{path:.*}")
@Produces("application/json")
@Consumes("application/json")
public Response createNode(@PathParam("path") String path, @HeaderParam("netflix-user-name") String trackingUserName, @HeaderParam("netflix-ticket-number") String trackingTicketNumber, @HeaderParam("netflix-reason") String trackingReason, String binaryDataStr) {
    Response response;
    do {
        path = "/" + path;
        context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("Create/update node request received. Path [%s], Username [%s], Ticket Number [%s], Reason [%s]", path, trackingUserName, trackingTicketNumber, trackingReason));
        if (!context.getExhibitor().nodeMutationsAllowed()) {
            response = Response.status(Response.Status.FORBIDDEN).build();
            break;
        }
        try {
            binaryDataStr = binaryDataStr.replace(" ", "");
            byte[] data = new byte[binaryDataStr.length() / 2];
            for (int i = 0; i < data.length; ++i) {
                String hex = binaryDataStr.substring(i * 2, (i * 2) + 2);
                int val = Integer.parseInt(hex, 16);
                data[i] = (byte) (val & 0xff);
            }
            try {
                context.getExhibitor().getLocalConnection().setData().forPath(path, data);
                context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() updated node [%s] to data [%s]", path, binaryDataStr));
            } catch (KeeperException.NoNodeException dummy) {
                context.getExhibitor().getLocalConnection().create().creatingParentsIfNeeded().forPath(path, data);
                context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("createNode() created node [%s] with data [%s]", path, binaryDataStr));
            }
        } catch (Exception e) {
            response = Response.ok(new Result(e)).build();
            break;
        }
        response = Response.ok(new Result("OK", true)).build();
    } while (false);
    return response;
}
Also used : Response(javax.ws.rs.core.Response) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException) Result(com.netflix.exhibitor.core.entities.Result)

Aggregations

Result (com.netflix.exhibitor.core.entities.Result)9 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 GET (javax.ws.rs.GET)4 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)2 PseudoLock (com.netflix.exhibitor.core.config.PseudoLock)2 KillRunningInstance (com.netflix.exhibitor.core.state.KillRunningInstance)2 IOException (java.io.IOException)2 POST (javax.ws.rs.POST)2 Response (javax.ws.rs.core.Response)2 KeeperException (org.apache.zookeeper.KeeperException)2 ControlPanelTypes (com.netflix.exhibitor.core.controlpanel.ControlPanelTypes)1 SearchResult (com.netflix.exhibitor.core.entities.SearchResult)1 StartInstance (com.netflix.exhibitor.core.state.StartInstance)1 File (java.io.File)1 DELETE (javax.ws.rs.DELETE)1