Search in sources :

Example 1 with ControlPanelTypes

use of com.netflix.exhibitor.core.controlpanel.ControlPanelTypes 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 ControlPanelTypes

use of com.netflix.exhibitor.core.controlpanel.ControlPanelTypes in project exhibitor by soabase.

the class ClusterResource method getStatus.

@Path("state")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String getStatus() throws Exception {
    ObjectNode mainNode = JsonNodeFactory.instance.objectNode();
    ObjectNode switchesNode = JsonNodeFactory.instance.objectNode();
    for (ControlPanelTypes type : ControlPanelTypes.values()) {
        switchesNode.put(UIResource.fixName(type), context.getExhibitor().getControlPanelValues().isSet(type));
    }
    mainNode.put("switches", switchesNode);
    MonitorRunningInstance monitorRunningInstance = context.getExhibitor().getMonitorRunningInstance();
    InstanceStateTypes state = monitorRunningInstance.getCurrentInstanceState();
    mainNode.put("state", state.getCode());
    mainNode.put("description", state.getDescription());
    mainNode.put("isLeader", monitorRunningInstance.isCurrentlyLeader());
    return JsonUtil.writeValueAsString(mainNode);
}
Also used : ControlPanelTypes(com.netflix.exhibitor.core.controlpanel.ControlPanelTypes) MonitorRunningInstance(com.netflix.exhibitor.core.state.MonitorRunningInstance) ObjectNode(org.codehaus.jackson.node.ObjectNode) InstanceStateTypes(com.netflix.exhibitor.core.state.InstanceStateTypes) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ControlPanelTypes

use of com.netflix.exhibitor.core.controlpanel.ControlPanelTypes in project exhibitor by soabase.

the class TestMonitorRunningInstance method makeMockExhibitor.

private Exhibitor makeMockExhibitor(InstanceConfig config, String us) {
    Preferences preferences = Mockito.mock(Preferences.class);
    ControlPanelValues controlPanelValues = new ControlPanelValues(preferences) {

        @Override
        public boolean isSet(ControlPanelTypes type) throws Exception {
            return true;
        }
    };
    ConfigManager configManager = Mockito.mock(ConfigManager.class);
    Mockito.when(configManager.getConfig()).thenReturn(config);
    Exhibitor mockExhibitor = Mockito.mock(Exhibitor.class, Mockito.RETURNS_MOCKS);
    Mockito.when(mockExhibitor.getConfigManager()).thenReturn(configManager);
    Mockito.when(mockExhibitor.getThisJVMHostname()).thenReturn(us);
    Mockito.when(mockExhibitor.getControlPanelValues()).thenReturn(controlPanelValues);
    return mockExhibitor;
}
Also used : ControlPanelValues(com.netflix.exhibitor.core.controlpanel.ControlPanelValues) ControlPanelTypes(com.netflix.exhibitor.core.controlpanel.ControlPanelTypes) Exhibitor(com.netflix.exhibitor.core.Exhibitor) Preferences(java.util.prefs.Preferences) ConfigManager(com.netflix.exhibitor.core.config.ConfigManager)

Aggregations

ControlPanelTypes (com.netflix.exhibitor.core.controlpanel.ControlPanelTypes)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Exhibitor (com.netflix.exhibitor.core.Exhibitor)1 ConfigManager (com.netflix.exhibitor.core.config.ConfigManager)1 ControlPanelValues (com.netflix.exhibitor.core.controlpanel.ControlPanelValues)1 Result (com.netflix.exhibitor.core.entities.Result)1 InstanceStateTypes (com.netflix.exhibitor.core.state.InstanceStateTypes)1 MonitorRunningInstance (com.netflix.exhibitor.core.state.MonitorRunningInstance)1 Preferences (java.util.prefs.Preferences)1 ObjectNode (org.codehaus.jackson.node.ObjectNode)1