Search in sources :

Example 6 with Result

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

the class IndexResource method deleteIndex.

@Path("{index-name}")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public Response deleteIndex(@PathParam("index-name") String indexName) {
    File indexFile = getLogFile(indexName);
    context.getExhibitor().getIndexCache().markForDeletion(indexFile);
    return Response.ok(new Result("OK", true)).build();
}
Also used : File(java.io.File) Result(com.netflix.exhibitor.core.entities.Result) SearchResult(com.netflix.exhibitor.core.entities.SearchResult) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 7 with Result

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

the class ConfigResource method setConfigRolling.

@Path("set-rolling")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response setConfigRolling(String newConfigJson) throws Exception {
    InstanceConfig wrapped = parseToConfig(newConfigJson);
    Result result = null;
    try {
        PseudoLock lock = context.getExhibitor().getConfigManager().newConfigBasedLock();
        try {
            if (// TODO consider making configurable in the future
            lock.lock(context.getExhibitor().getLog(), 10, TimeUnit.SECONDS)) {
                if (context.getExhibitor().getConfigManager().startRollingConfig(wrapped, null)) {
                    result = new Result("OK", true);
                }
            }
        } finally {
            lock.unlock();
        }
        if (result == null) {
            result = new Result("Another process has updated the config.", false);
        }
        context.getExhibitor().resetLocalConnection();
    } catch (Exception e) {
        result = new Result(e);
    }
    return Response.ok(result).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) IOException(java.io.IOException) Result(com.netflix.exhibitor.core.entities.Result) PseudoLock(com.netflix.exhibitor.core.config.PseudoLock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 8 with Result

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

the class ConfigResource method setConfig.

@Path("set")
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response setConfig(String newConfigJson) throws Exception {
    InstanceConfig wrapped = parseToConfig(newConfigJson);
    Result result = null;
    try {
        PseudoLock lock = context.getExhibitor().getConfigManager().newConfigBasedLock();
        try {
            if (// TODO consider making configurable in the future
            lock.lock(context.getExhibitor().getLog(), 10, TimeUnit.SECONDS)) {
                if (context.getExhibitor().getConfigManager().updateConfig(wrapped)) {
                    result = new Result("OK", true);
                }
            }
        } finally {
            lock.unlock();
        }
        if (result == null) {
            result = new Result(CANT_UPDATE_CONFIG_MESSAGE, false);
        }
        context.getExhibitor().resetLocalConnection();
    } catch (Exception e) {
        result = new Result(e);
    }
    return Response.ok(result).build();
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) IOException(java.io.IOException) Result(com.netflix.exhibitor.core.entities.Result) PseudoLock(com.netflix.exhibitor.core.config.PseudoLock) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 9 with Result

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

the class ExplorerResource method deleteNode.

@DELETE
@Path("znode/{path:.*}")
@Produces("application/json")
public Response deleteNode(@PathParam("path") String path, @HeaderParam("netflix-user-name") String trackingUserName, @HeaderParam("netflix-ticket-number") String trackingTicketNumber, @HeaderParam("netflix-reason") String trackingReason) {
    Response response;
    do {
        path = "/" + path;
        context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("Delete 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 {
            recursivelyDelete(path);
        } 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) 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