Java Code Examples for org.restlet.data.Status

The following are top voted examples for showing how to use org.restlet.data.Status. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: FFS-Api   File: EventRoundUserScoreResource.java   View source code 6 votes vote down vote up
@Put
public Status updateScore(UpdateScoreEntity entity) throws SQLException {
	if (entity == null) throw new BadEntityException("ENTITY_NOT_FOUND");

	if (mEvents.getEvent(mEventId) == null) throw new NotFoundException("EVENT_NOT_FOUND");
	if (!mEvents.roundExists(mEventId, mRoundId)) throw new NotFoundException("ROUND_NOT_FOUND");
	if (mEvents.getRegistered(mEventId, mUserId) == null) throw new NotFoundException("USER_NOT_REGISTERED");
	
	if (mEvents.getScore(mRoundId, mUserId) != null) mEvents.updateScore(mRoundId, mUserId, entity.score);
	else mEvents.addScore(mRoundId, mUserId, entity.score);
	
	try {
		mRabbitMQManager.basicPublish("Pub", "", null, new TopicPacket("event-score-v1." + mEventId, new UpdateScoreMessage(mEventId, mRoundId, mUserId, entity.score)));
	} catch (IOException e) {
		Server.LOGGER.log(Level.SEVERE, "Cannot send publish to RabbitMQ", e);
	}

	return Status.SUCCESS_OK;
}
 
Example 2
Project: FFS-Api   File: EventResource.java   View source code 6 votes vote down vote up
@Put
public Status updateEvent(UpdateEventEntity entity) throws SQLException {
	ValidationUtils.verifyGroup(getRequest(), ApiV1.ADMIN);
	ValidationErrors err = new ValidationErrors();
	
	if (entity == null) throw new BadEntityException("ENTITY_NOT_FOUND");
	
	err.verifyFieldEmptyness("name", entity.name, 3, 200);
	err.verifyFieldEmptyness("description", entity.description, 3, 2048);
	
	err.checkErrors("EVENT_UPDATE_ERROR");
	
	EventBean bean = mEvents.getEvent(mEventId);
	if (bean == null) throw new NotFoundException("EVENT_NOT_FOUND");
	bean.setCurrent(entity.current);
	bean.setDescription(entity.description);
	bean.setName(entity.name);
	bean.setReservedToAffiliates(entity.reserved_to_affiliates);
	bean.setReservedToPartners(entity.reserved_to_partners);
	bean.setStatus(entity.status);
	bean.setMinimumViews(entity.minimum_views);
	bean.setMinimumFollowers(entity.minimum_followers);
	mEvents.update(bean);
	return Status.SUCCESS_OK;
}
 
Example 3
Project: FFS-Api   File: EventRegisterResource.java   View source code 6 votes vote down vote up
@Put
public Status updatePariticipationStatus(EmailValidationBean bean) throws SQLException {
	if (bean == null) throw new BadEntityException("EVENT_NOT_FOUND");
	ValidationErrors err = new ValidationErrors();
	
	err.verifyFieldEmptyness("key", bean.key, 5, 36);
	
	err.checkErrors("INVALID_KEY");

	AccountBean acc = (AccountBean) getRequest().getAttributes().get("account");
	UserStatus status = mEvents.getUserStatusFromEmailKey(mEventId, acc.getTwitchId(), bean.key);
	if (status == null) throw new NotFoundException("UNKNOWN_KEY");
	if (status != UserStatus.AWAITING_FOR_EMAIL_VALIDATION) throw new ConflictException("BAD_STATUS");
	
	mEvents.updateUser(mEventId, acc.getTwitchId(), UserStatus.VALIDATED);
	try {
		EventBean event = mEvents.getEvent(mEventId);
		MimeMessage message = mEmailsService.generateMime("Validez votre compte!",
				mValidatedEmail.replaceAll("\\{EVENT_NAME\\}", event.getName())
				.replaceAll("\\{EVENT_ID\\}", event.getId() + ""), "text/html", acc.getEmail());
		mEmailsService.sendEmail(message);
	} catch (MessagingException e) {
		Main.LOGGER.log(Level.SEVERE, "Cannot send email.", e);
	}
	return Status.SUCCESS_OK;
}
 
Example 4
Project: open-rmbt   File: StatusResource.java   View source code 6 votes vote down vote up
@Get
public String request() throws JSONException {
	JSONObject json = new JSONObject();
	
	json.put("starttime", TestServer.serverPreferences.getStartTimestamp());
	json.put("version", TestServer.TEST_SERVER_VERSION_MAJOR + "." + TestServer.TEST_SERVER_VERSION_MINOR + "." + TestServer.TEST_SERVER_VERSION_PATCH);
	
	if (TestServerConsole.errorReportMap.size() > 0) {
		setStatus(Status.SERVER_ERROR_INTERNAL);
		
		JSONArray errors = new JSONArray();
		for (ErrorReport er : TestServerConsole.errorReportMap.values()) {
			errors.put(er.toJson());
		}
		
		json.put("errors", errors);
	}
	
	return json.toString();
}
 
Example 5
Project: fresco_floodlight   File: PerfMonDataResource.java   View source code 6 votes vote down vote up
@Get("json")
public CumulativeTimeBucket handleApiQuery() {        
    IPktInProcessingTimeService pktinProcTime = 
        (IPktInProcessingTimeService)getContext().getAttributes().
            get(IPktInProcessingTimeService.class.getCanonicalName());
    
    setStatus(Status.SUCCESS_OK, "OK");
    // If the user is requesting this they must think that it is enabled, 
    // so lets enable it to prevent from erroring out
    if (!pktinProcTime.isEnabled()){
    	pktinProcTime.setEnabled(true);
    	logger.warn("Requesting performance monitor data when performance monitor is disabled. Turning it on");
    }
    // Allocate output object
    if (pktinProcTime.isEnabled()) {
        CumulativeTimeBucket ctb = pktinProcTime.getCtb();
        ctb.computeAverages();
        return ctb;
    }
    
    return null;
}
 
Example 6
Project: fresco_floodlight   File: PerfMonToggleResource.java   View source code 6 votes vote down vote up
@Get("json")
public String retrieve() {
    IPktInProcessingTimeService pktinProcTime = 
            (IPktInProcessingTimeService)getContext().getAttributes().
                get(IPktInProcessingTimeService.class.getCanonicalName());
    
    String param = ((String)getRequestAttributes().get("perfmonstate")).toLowerCase();
    if (param.equals("reset")) {
    	// We cannot reset something that is disabled, so enable it first.
    	if(!pktinProcTime.isEnabled()){
    		pktinProcTime.setEnabled(true);
    	}
        pktinProcTime.getCtb().reset();
    } else {
        if (param.equals("enable") || param.equals("true")) {
            pktinProcTime.setEnabled(true);
        } else if (param.equals("disable") || param.equals("false")) {
            pktinProcTime.setEnabled(false);
        }
    }
    setStatus(Status.SUCCESS_OK, "OK");
    return "{ \"enabled\" : " + pktinProcTime.isEnabled() + " }";
}
 
Example 7
Project: fresco_floodlight   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MacAddress.of(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 8
Project: fresco_floodlight   File: ListStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public OFFlowModMap ListStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Listing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        return new OFFlowModMap(sfpService.getFlows());
    } else {
        try {
            Map<String, Map<String, OFFlowMod>> retMap = new HashMap<String, Map<String, OFFlowMod>>();
            retMap.put(param, sfpService.getFlows(DatapathId.of(param)));
            return new OFFlowModMap(retMap);
            
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ControllerSwitchesResource.DPID_ERROR);
        }
    }
    return null;
}
 
Example 9
Project: fresco_floodlight   File: ClearStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public String ClearStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Clearing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        sfpService.deleteAllFlows();
        return "{\"status\":\"Deleted all flows.\"}";
    } else {
        try {
            sfpService.deleteFlowsForSwitch(DatapathId.of(param));
            return "{\"status\":\"Deleted all flows for switch " + param + ".\"}";
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, 
                      ControllerSwitchesResource.DPID_ERROR);
            return "'{\"status\":\"Could not delete flows requested! See controller log for details.\"}'";
        }
    }
}
 
Example 10
Project: fresco_floodlight   File: FirewallSubnetMaskResource.java   View source code 6 votes vote down vote up
@Post
public String handlePost(String fmJson) {
	IFirewallService firewall = getFirewallService();

	String newMask;
	try {
		newMask = jsonExtractSubnetMask(fmJson);
	} catch (IOException e) {
		log.error("Error parsing new subnet mask: " + fmJson, e);
		setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
	}

	firewall.setSubnetMask(newMask);

	setStatus(Status.SUCCESS_OK);
	return ("{\"status\" : \"subnet mask set\"}");
}
 
Example 11
Project: iTAP-controller   File: PerfMonDataResource.java   View source code 6 votes vote down vote up
@Get("json")
public CumulativeTimeBucket handleApiQuery() {        
    IPktInProcessingTimeService pktinProcTime = 
        (IPktInProcessingTimeService)getContext().getAttributes().
            get(IPktInProcessingTimeService.class.getCanonicalName());
    
    setStatus(Status.SUCCESS_OK, "OK");
    // If the user is requesting this they must think that it is enabled, 
    // so lets enable it to prevent from erroring out
    if (!pktinProcTime.isEnabled()){
    	pktinProcTime.setEnabled(true);
    	logger.warn("Requesting performance monitor data when performance monitor is disabled. Turning it on");
    }
    // Allocate output object
    if (pktinProcTime.isEnabled()) {
        CumulativeTimeBucket ctb = pktinProcTime.getCtb();
        ctb.computeAverages();
        return ctb;
    }
    
    return null;
}
 
Example 12
Project: iTAP-controller   File: PerfMonToggleResource.java   View source code 6 votes vote down vote up
@Get("json")
public String retrieve() {
    IPktInProcessingTimeService pktinProcTime = 
            (IPktInProcessingTimeService)getContext().getAttributes().
                get(IPktInProcessingTimeService.class.getCanonicalName());
    
    String param = ((String)getRequestAttributes().get("perfmonstate")).toLowerCase();
    if (param.equals("reset")) {
    	// We cannot reset something that is disabled, so enable it first.
    	if(!pktinProcTime.isEnabled()){
    		pktinProcTime.setEnabled(true);
    	}
        pktinProcTime.getCtb().reset();
    } else {
        if (param.equals("enable") || param.equals("true")) {
            pktinProcTime.setEnabled(true);
        } else if (param.equals("disable") || param.equals("false")) {
            pktinProcTime.setEnabled(false);
        }
    }
    setStatus(Status.SUCCESS_OK, "OK");
    return "{ \"enabled\" : " + pktinProcTime.isEnabled() + " }";
}
 
Example 13
Project: iTAP-controller   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MacAddress.of(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 14
Project: iTAP-controller   File: ListStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public OFFlowModMap ListStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Listing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        return new OFFlowModMap(sfpService.getFlows());
    } else {
        try {
            Map<String, Map<String, OFFlowMod>> retMap = new HashMap<String, Map<String, OFFlowMod>>();
            retMap.put(param, sfpService.getFlows(DatapathId.of(param)));
            return new OFFlowModMap(retMap);
            
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ControllerSwitchesResource.DPID_ERROR);
        }
    }
    return null;
}
 
Example 15
Project: iTAP-controller   File: ClearStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public String ClearStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Clearing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        sfpService.deleteAllFlows();
        return "{\"status\":\"Deleted all flows.\"}";
    } else {
        try {
            sfpService.deleteFlowsForSwitch(DatapathId.of(param));
            return "{\"status\":\"Deleted all flows for switch " + param + ".\"}";
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, 
                      ControllerSwitchesResource.DPID_ERROR);
            return "'{\"status\":\"Could not delete flows requested! See controller log for details.\"}'";
        }
    }
}
 
Example 16
Project: iTAP-controller   File: FirewallSubnetMaskResource.java   View source code 6 votes vote down vote up
@Post
public String handlePost(String fmJson) {
	IFirewallService firewall = getFirewallService();

	String newMask;
	try {
		newMask = jsonExtractSubnetMask(fmJson);
	} catch (IOException e) {
		log.error("Error parsing new subnet mask: " + fmJson, e);
		setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
	}

	firewall.setSubnetMask(newMask);

	setStatus(Status.SUCCESS_OK);
	return ("{\"status\" : \"subnet mask set\"}");
}
 
Example 17
Project: SDN-Multicast   File: PerfMonDataResource.java   View source code 6 votes vote down vote up
@Get("json")
public CumulativeTimeBucket handleApiQuery() {        
    IPktInProcessingTimeService pktinProcTime = 
        (IPktInProcessingTimeService)getContext().getAttributes().
            get(IPktInProcessingTimeService.class.getCanonicalName());
    
    setStatus(Status.SUCCESS_OK, "OK");
    // If the user is requesting this they must think that it is enabled, 
    // so lets enable it to prevent from erroring out
    if (!pktinProcTime.isEnabled()){
    	pktinProcTime.setEnabled(true);
    	logger.warn("Requesting performance monitor data when performance monitor is disabled. Turning it on");
    }
    // Allocate output object
    if (pktinProcTime.isEnabled()) {
        CumulativeTimeBucket ctb = pktinProcTime.getCtb();
        ctb.computeAverages();
        return ctb;
    }
    
    return null;
}
 
Example 18
Project: SDN-Multicast   File: PerfMonToggleResource.java   View source code 6 votes vote down vote up
@Get("json")
public String retrieve() {
    IPktInProcessingTimeService pktinProcTime = 
            (IPktInProcessingTimeService)getContext().getAttributes().
                get(IPktInProcessingTimeService.class.getCanonicalName());
    
    String param = ((String)getRequestAttributes().get("perfmonstate")).toLowerCase();
    if (param.equals("reset")) {
    	// We cannot reset something that is disabled, so enable it first.
    	if(!pktinProcTime.isEnabled()){
    		pktinProcTime.setEnabled(true);
    	}
        pktinProcTime.getCtb().reset();
    } else {
        if (param.equals("enable") || param.equals("true")) {
            pktinProcTime.setEnabled(true);
        } else if (param.equals("disable") || param.equals("false")) {
            pktinProcTime.setEnabled(false);
        }
    }
    setStatus(Status.SUCCESS_OK, "OK");
    return "{ \"enabled\" : " + pktinProcTime.isEnabled() + " }";
}
 
Example 19
Project: SDN-Multicast   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MacAddress.of(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 20
Project: SDN-Multicast   File: ListStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public OFFlowModMap ListStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Listing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        return new OFFlowModMap(sfpService.getFlows());
    } else {
        try {
            Map<String, Map<String, OFFlowMod>> retMap = new HashMap<String, Map<String, OFFlowMod>>();
            retMap.put(param, sfpService.getFlows(DatapathId.of(param)));
            return new OFFlowModMap(retMap);
            
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ControllerSwitchesResource.DPID_ERROR);
        }
    }
    return null;
}
 
Example 21
Project: SDN-Multicast   File: ClearStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public String ClearStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Clearing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        sfpService.deleteAllFlows();
        return "{\"status\":\"Deleted all flows.\"}";
    } else {
        try {
            sfpService.deleteFlowsForSwitch(DatapathId.of(param));
            return "{\"status\":\"Deleted all flows for switch " + param + ".\"}";
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, 
                      ControllerSwitchesResource.DPID_ERROR);
            return "'{\"status\":\"Could not delete flows requested! See controller log for details.\"}'";
        }
    }
}
 
Example 22
Project: SDN-Multicast   File: FirewallSubnetMaskResource.java   View source code 6 votes vote down vote up
@Post
public String handlePost(String fmJson) {
	IFirewallService firewall = getFirewallService();

	String newMask;
	try {
		newMask = jsonExtractSubnetMask(fmJson);
	} catch (IOException e) {
		log.error("Error parsing new subnet mask: " + fmJson, e);
		setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
	}

	firewall.setSubnetMask(newMask);

	setStatus(Status.SUCCESS_OK);
	return ("{\"status\" : \"subnet mask set\"}");
}
 
Example 23
Project: ACAMPController   File: FirewallSubnetMaskResource.java   View source code 6 votes vote down vote up
@Post
public String handlePost(String fmJson) {
	IFirewallService firewall = getFirewallService();

	String newMask;
	try {
		newMask = jsonExtractSubnetMask(fmJson);
	} catch (IOException e) {
		log.error("Error parsing new subnet mask: " + fmJson, e);
		setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
	}

	firewall.setSubnetMask(newMask);

	setStatus(Status.SUCCESS_OK);
	return ("{\"status\" : \"subnet mask set\"}");
}
 
Example 24
Project: ipst   File: ITeslaStatsResource.java   View source code 6 votes vote down vote up
@Get("csv")
public Object getRepresentation() {

    if (ds == null) {
        getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        return null;
    }

    if (!ds.getStatus().isInitialized()) {
        getResponse().setStatus(Status.SUCCESS_ACCEPTED);
        return "Initializing...";
    }

    Form queryForm = getRequest().getOriginalRef().getQueryAsForm();
    char delimiter = queryForm.getFirstValue("delimiter", ",").charAt(0);

    return new CsvRepresentation(getStats(), true, delimiter);
}
 
Example 25
Project: arscheduler   File: PerfMonDataResource.java   View source code 6 votes vote down vote up
@Get("json")
public CumulativeTimeBucket handleApiQuery() {        
    IPktInProcessingTimeService pktinProcTime = 
        (IPktInProcessingTimeService)getContext().getAttributes().
            get(IPktInProcessingTimeService.class.getCanonicalName());
    
    setStatus(Status.SUCCESS_OK, "OK");
    // If the user is requesting this they must think that it is enabled, 
    // so lets enable it to prevent from erroring out
    if (!pktinProcTime.isEnabled()){
    	pktinProcTime.setEnabled(true);
    	logger.warn("Requesting performance monitor data when performance monitor is disabled. Turning it on");
    }
    // Allocate output object
    if (pktinProcTime.isEnabled()) {
        CumulativeTimeBucket ctb = pktinProcTime.getCtb();
        ctb.computeAverages();
        return ctb;
    }
    
    return null;
}
 
Example 26
Project: arscheduler   File: PerfMonToggleResource.java   View source code 6 votes vote down vote up
@Get("json")
public String retrieve() {
    IPktInProcessingTimeService pktinProcTime = 
            (IPktInProcessingTimeService)getContext().getAttributes().
                get(IPktInProcessingTimeService.class.getCanonicalName());
    
    String param = ((String)getRequestAttributes().get("perfmonstate")).toLowerCase();
    if (param.equals("reset")) {
    	// We cannot reset something that is disabled, so enable it first.
    	if(!pktinProcTime.isEnabled()){
    		pktinProcTime.setEnabled(true);
    	}
        pktinProcTime.getCtb().reset();
    } else {
        if (param.equals("enable") || param.equals("true")) {
            pktinProcTime.setEnabled(true);
        } else if (param.equals("disable") || param.equals("false")) {
            pktinProcTime.setEnabled(false);
        }
    }
    setStatus(Status.SUCCESS_OK, "OK");
    return "{ \"enabled\" : " + pktinProcTime.isEnabled() + " }";
}
 
Example 27
Project: arscheduler   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MacAddress.of(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 28
Project: ACAMPController   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MacAddress.of(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 29
Project: arscheduler   File: FirewallSubnetMaskResource.java   View source code 6 votes vote down vote up
@Post
public String handlePost(String fmJson) {
	IFirewallService firewall = getFirewallService();

	String newMask;
	try {
		newMask = jsonExtractSubnetMask(fmJson);
	} catch (IOException e) {
		log.error("Error parsing new subnet mask: " + fmJson, e);
		setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
		return "{\"status\" : \"Error! Could not parse new subnet mask, see log for details.\"}";
	}

	firewall.setSubnetMask(newMask);

	setStatus(Status.SUCCESS_OK);
	return ("{\"status\" : \"subnet mask set\"}");
}
 
Example 30
Project: chaperone   File: TopicManagementRestletResource.java   View source code 6 votes vote down vote up
@Override
@Put("json")
public Representation put(Representation entity) {
  try {
    String jsonRequest = entity.getText();
    TopicPartition topicPartitionInfo = TopicPartition.init(jsonRequest);
    if (_autoTopicWhitelistingManager != null) {
      _autoTopicWhitelistingManager.removeFromBlacklist(topicPartitionInfo.getTopic());
    }
    if (_helixMirrorMakerManager.isTopicExisted(topicPartitionInfo.getTopic())) {
      _helixMirrorMakerManager.expandTopicInMirrorMaker(topicPartitionInfo);
      return new StringRepresentation(
          String.format("Successfully expand topic: %s", topicPartitionInfo));
    } else {
      getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      return new StringRepresentation(String.format(
          "Failed to expand topic, topic: %s is not existed!", topicPartitionInfo.getTopic()));
    }
  } catch (IOException e) {
    LOGGER.error("Got error during processing Put request", e);
    getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
    return new StringRepresentation(
        String.format("Failed to expand topic, with exception: %s", e));
  }
}
 
Example 31
Project: hub-email-extension   File: EmailTestServerResource.java   View source code 6 votes vote down vote up
@Post
public void postFormData(final Representation entity) {
    ExtensionTokenManager tokenManager = getTokenManager();
    if (tokenManager.authenticationRequired()) {
        getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
    } else {
        Form form = new Form(entity);
        final String emailAddress = form.getFirstValue(FORM_INPUT_EMAIL_ADDRESS);
        if (StringUtils.isNotBlank(emailAddress)) {
            TestEmailNotifier testNotifier = (TestEmailNotifier) getContext().getAttributes()
                    .get(EmailExtensionConstants.CONTEXT_ATTRIBUTE_KEY_TEST_NOTIFIER);
            testNotifier.setEmailAddress(emailAddress);
            testNotifier.run();
            testNotifier.setEmailAddress("");
        }
    }
}
 
Example 32
Project: hub-email-extension   File: EmailTestServerResource.java   View source code 6 votes vote down vote up
@Get
public FileRepresentation getTestForm() {
    ExtensionTokenManager tokenManager = this.getTokenManager();
    if (tokenManager.authenticationRequired()) {
        getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
        return null;
    } else {
        try {
            File webDir = getWebDirectory();
            File file = new File(webDir, TEST_FORM_HTML);
            FileRepresentation htmlForm = new FileRepresentation(file, MediaType.TEXT_HTML);
            return htmlForm;
        } catch (Exception ex) {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return null;
        }
    }
}
 
Example 33
Project: hub-email-extension   File: TokenAuthenticationResource.java   View source code 6 votes vote down vote up
@Get
public void authenticate() {
    // Use state if provided
    final String next = getRequest().getResourceRef().getQueryAsForm(true).getFirstValue("next");
    final StateUrlProcessor state = new StateUrlProcessor(getQueryValue("state"));

    if (state.getReturnUrl().isPresent() && next != null) {
        state.setReturnUrl(next);
    } else if (getRequest().getReferrerRef() != null) {
        state.setReturnUrl(getRequest().getReferrerRef().toString());
    }
    final ExtensionTokenManager tokenManager = getTokenManager();
    if (tokenManager != null) {
        logger.info("Authenticate method called to obtain authorization url");
        final Reference authUrl = new Reference(tokenManager.getOAuthAuthorizationUrl(Optional.of(state)));
        getResponse().redirectSeeOther(authUrl);
    } else {
        getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
    }
}
 
Example 34
Project: ACAMPController   File: ListStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get("json")
public OFFlowModMap ListStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Listing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        return new OFFlowModMap(sfpService.getFlows());
    } else {
        try {
            Map<String, Map<String, OFFlowMod>> retMap = new HashMap<String, Map<String, OFFlowMod>>();
            retMap.put(param, sfpService.getFlows(DatapathId.of(param)));
            return new OFFlowModMap(retMap);
            
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, ControllerSwitchesResource.DPID_ERROR);
        }
    }
    return null;
}
 
Example 35
Project: QoS-floodlight   File: PerfMonDataResource.java   View source code 6 votes vote down vote up
@Get("json")
public CumulativeTimeBucket handleApiQuery() {        
    IPktInProcessingTimeService pktinProcTime = 
        (IPktInProcessingTimeService)getContext().getAttributes().
            get(IPktInProcessingTimeService.class.getCanonicalName());
    
    setStatus(Status.SUCCESS_OK, "OK");
    // If the user is requesting this they must think that it is enabled, 
    // so lets enable it to prevent from erroring out
    if (!pktinProcTime.isEnabled()){
    	pktinProcTime.setEnabled(true);
    	logger.warn("Requesting performance monitor data when performance monitor is disabled. Turning it on");
    }
    // Allocate output object
    if (pktinProcTime.isEnabled()) {
        CumulativeTimeBucket ctb = pktinProcTime.getCtb();
        ctb.computeAverages();
        return ctb;
    }
    
    return null;
}
 
Example 36
Project: QoS-floodlight   File: PerfMonToggleResource.java   View source code 6 votes vote down vote up
@Get("json")
public String retrieve() {
    IPktInProcessingTimeService pktinProcTime = 
            (IPktInProcessingTimeService)getContext().getAttributes().
                get(IPktInProcessingTimeService.class.getCanonicalName());
    
    String param = ((String)getRequestAttributes().get("perfmonstate")).toLowerCase();
    if (param.equals("reset")) {
    	// We cannot reset something that is disabled, so enable it first.
    	if(!pktinProcTime.isEnabled()){
    		pktinProcTime.setEnabled(true);
    	}
        pktinProcTime.getCtb().reset();
    } else {
        if (param.equals("enable") || param.equals("true")) {
            pktinProcTime.setEnabled(true);
        } else if (param.equals("disable") || param.equals("false")) {
            pktinProcTime.setEnabled(false);
        }
    }
    setStatus(Status.SUCCESS_OK, "OK");
    return "{ \"enabled\" : " + pktinProcTime.isEnabled() + " }";
}
 
Example 37
Project: QoS-floodlight   File: HostResource.java   View source code 6 votes vote down vote up
@Put
public String addHost(String postData) {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    HostDefinition host = new HostDefinition();
    host.port = (String) getRequestAttributes().get("port");
    host.guid = (String) getRequestAttributes().get("network");
    try {
        jsonToHostDefinition(postData, host);
    } catch (IOException e) {
        log.error("Could not parse JSON {}", e.getMessage());
    }
    vns.addHost(MACAddress.valueOf(host.mac), host.guid, host.port);
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 38
Project: QoS-floodlight   File: ListStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get
public Map<String, Map<String, OFFlowMod>> ListStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Listing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        return sfpService.getFlows();
    } else {
        try {
            Map<String, Map<String, OFFlowMod>> retMap = 
                    new HashMap<String, Map<String, OFFlowMod>>();
            retMap.put(param, sfpService.getFlows(param));
            return retMap;
            
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, 
                      ControllerSwitchesResource.DPID_ERROR);
        }
    }
    return null;
}
 
Example 39
Project: QoS-floodlight   File: ClearStaticFlowEntriesResource.java   View source code 6 votes vote down vote up
@Get
public void ClearStaticFlowEntries() {
    IStaticFlowEntryPusherService sfpService =
            (IStaticFlowEntryPusherService)getContext().getAttributes().
                get(IStaticFlowEntryPusherService.class.getCanonicalName());
    
    String param = (String) getRequestAttributes().get("switch");
    if (log.isDebugEnabled())
        log.debug("Clearing all static flow entires for switch: " + param);
    
    if (param.toLowerCase().equals("all")) {
        sfpService.deleteAllFlows();
    } else {
        try {
            sfpService.deleteFlowsForSwitch(HexString.toLong(param));
        } catch (NumberFormatException e){
            setStatus(Status.CLIENT_ERROR_BAD_REQUEST, 
                      ControllerSwitchesResource.DPID_ERROR);
            return;
        }
    }
}
 
Example 40
Project: sync-android-p2p   File: HttpListener.java   View source code 6 votes vote down vote up
@Post("json")
public Representation handlePost(Representation entity) {

    String path = getReference().getPath();

    String dbname = getDatabaseName(path);
    
    if (!dbNameExists(dbname)) {
        return databaseNotFound();
    }
    else if (path.endsWith("/_revs_diff")) {
        return handleRevsDiff(dbname);
    }
    else if (path.endsWith("/_ensure_full_commit")) {
        return handleEnsureFullCommitPost(dbname);
    }
    else if (path.endsWith("/_bulk_docs")) {
        return handleBulkDocsPost(dbname);
    }
    else {
    	getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
    	return new StringRepresentation("{\"message\": \"Server error for request: " + getMethod() + " " + path + "\"}", MediaType.TEXT_PLAIN);
    }
}