org.restlet.resource.Get Java Examples

The following examples show how to use org.restlet.resource.Get. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AgentsAgidObjects.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the list of IoT objects registered under given Agent.
 * 
 * @return All VICINITY identifiers of objects registered under specified agent.
 */
@Get
public Representation represent() {
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	XMLConfiguration config = (XMLConfiguration) getContext().getAttributes().get(Api.CONTEXT_CONFIG);
	
	
	String attrAgid = getAttribute(ATTR_AGID);
	
	if (attrAgid == null){
		logger.info("AGID: " + attrAgid + " Invalid Agent ID.");
		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
				"Invalid Agent ID.");
	}
	
	return getAgentObjects(attrAgid, logger, config);
}
 
Example #2
Source File: APIInfoResource.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Get
public Representation getAPIInfo() throws IOException {
	TemplateRepresentation r = new TemplateRepresentation("net/ontopia/topicmaps/rest/resources/info.html", MediaType.TEXT_HTML);
	r.getEngine().addProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
	r.getEngine().addProperty("classpath." + VelocityEngine.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName());
	
	Map<Restlet, String> allRoutes = new HashMap<>();
	list(allRoutes, getApplication().getInboundRoot(), "");
	Map<String, Object> data = new HashMap<>();
	data.put("util", this);
	data.put("root", getApplication().getInboundRoot());
	data.put("routes", allRoutes);
	data.put("cutil", ClassUtils.class);
	
	r.setDataModel(data);

	return r;
}
 
Example #3
Source File: AssociationsResource.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Get
public Collection<AssociationIF> getAssociations() {
	TopicIF topic = Parameters.ID.withExpected(TopicIF.class).optional(this);
	TopicIF type = Parameters.TYPE.optional(this);
	
	if (topic == null) {
		if (type != null) {
			return getIndex(ClassInstanceIndexIF.class).getAssociations(type);
		} else {
			return getTopicMap().getAssociations();
		}
	} else {
		if (type == null) {
			return topic.getAssociations();
		} else {
			return topic.getAssociationsByType(type);
		}
	}
}
 
Example #4
Source File: ObjectsOidPropertiesPid.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the property value of an available IoT object.
 * 
 * @return Latest property value.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrPid = getAttribute(ATTR_PID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrPid == null){
		logger.info("OID: " + attrOid + " PID: " + attrPid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	return getObjectProperty(callerOid, attrOid, attrPid, body, queryParams);
	
}
 
Example #5
Source File: ObjectsOidActionsAidTasksTid.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a specific task status to perform an action of an available IoT object.
 * 
 * @return Task status.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrAid = getAttribute(ATTR_AID);
	String attrTid = getAttribute(ATTR_TID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrAid == null || attrTid == null){
		logger.info("OID: " + attrOid + " AID: " + attrAid + " TID: " + attrTid 
				+ " Given identifier does not exist.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Given identifier does not exist.");
	}
	
	String body = getRequestBody(entity, logger);
	
	return getActionTaskStatus(callerOid, attrOid, attrAid, attrTid, queryParams, body);
}
 
Example #6
Source File: RolesResource.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Get
public Collection<AssociationRoleIF> getRolesByType() {
	TMObjectIF object = Parameters.ID.withExpected(TMObjectIF.class).optional(this);
	TopicIF roleType = Parameters.ROLETYPE.optional(this);
	TopicIF associationType = Parameters.ASSOCIATIONTYPE.optional(this);
	
	if (object == null) {
		return getIndex(ClassInstanceIndexIF.class).getAssociationRoles(roleType);
	} else if (object instanceof AssociationIF) {
		return getAssociationRoles((AssociationIF) object, roleType);
	} else if (object instanceof TopicIF) {
		return getTopicRoles((TopicIF) object, roleType, associationType);
	} else {
		throw OntopiaRestErrors.MANDATORY_ATTRIBUTE_IS_WRONG_TYPE.build(Parameters.ID, "TopicIF or AssociationIF", object.getClass().getSimpleName());
	}
}
 
Example #7
Source File: ObjectsOidEventsEid.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves status of a remote event channel.
 * 
 * @return Latest property value.
 */
@Get
public Representation represent(Representation entity) {
	String attrOid = getAttribute(ATTR_OID);
	String attrEid = getAttribute(ATTR_EID);
	String callerOid = getRequest().getChallengeResponse().getIdentifier();
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	Logger logger = (Logger) getContext().getAttributes().get(Api.CONTEXT_LOGGER);
	
	if (attrOid == null || attrEid == null){
		logger.info("OID: " + attrOid + " EID: " + attrEid + " Invalid identifier.");
		throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
				"Invalid identifier.");
	}
	
	String body = getRequestBody(entity, logger);
	
	CommunicationManager communicationManager 
			= (CommunicationManager) getContext().getAttributes().get(Api.CONTEXT_COMMMANAGER);
	
	
	return new JsonRepresentation(communicationManager.getEventChannelStatus(callerOid, attrOid, attrEid, 
			queryParams, body).buildMessage().toString()); 
	
}
 
Example #8
Source File: ScopeUseResource.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Get
public Map<String, Object> getScopeUse() {
	TopicIF topic = resolve();
	
	ScopeIndexIF index = getIndex(ScopeIndexIF.class);
	
	boolean usedAsAssociationTheme = index.usedAsAssociationTheme(topic);
	boolean usedAsOccurrenceTheme = index.usedAsOccurrenceTheme(topic);
	boolean usedAsTopicNameTheme = index.usedAsTopicNameTheme(topic);
	boolean usedAsVariantTheme = index.usedAsVariantTheme(topic);

	Map<String, Object> result = new HashMap<>();
	result.put("usedAsAssociationTheme", usedAsAssociationTheme);
	result.put("usedAsOccurrenceTheme", usedAsOccurrenceTheme);
	result.put("usedAsTopicNameTheme", usedAsTopicNameTheme);
	result.put("usedAsVariantTheme", usedAsVariantTheme);
	result.put("usedAsTheme", 
			usedAsAssociationTheme ||
			usedAsOccurrenceTheme ||
			usedAsTopicNameTheme ||
			usedAsVariantTheme
	);
	
	return result;
}
 
Example #9
Source File: Objects.java    From vicinity-gateway-api with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns all available (both exposed and discovered and all adapters) IoT objects that can be seen by that 
 * particular object - this does not count objects that are offline.
 * 
 * 
 * @return All VICINITY Identifiers of IoT objects fulfil the type and maximum constraint and own parameter OR 
 * Object description if the OID is specified.
 * 
 */
@Get
public Representation represent() {
	
	Map<String, String> queryParams = getQuery().getValuesMap();
	
	boolean attrObjectsWithTDs = false;
	
	if (queryParams.get(ATTR_TDS) != null) {
		attrObjectsWithTDs = Boolean.parseBoolean(queryParams.get(ATTR_TDS));
	}
	
	int attrPage = 0;
	
	if (queryParams.get(ATTR_PAGE) != null) {
		attrPage = Integer.parseInt(queryParams.get(ATTR_PAGE));
	}
	
	if (attrObjectsWithTDs) {
		return getObjectsTDs(attrPage);
	} else {
		return getObjects();	
	}
	
	
}
 
Example #10
Source File: ITeslaStatsResource.java    From ipst with Mozilla Public License 2.0 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 #11
Source File: TopicNamesResource.java    From ontopia with Apache License 2.0 6 votes vote down vote up
@Get
public Collection<TopicNameIF> getTopicNames() {
	TopicIF topic = Parameters.ID.withExpected(TopicIF.class).optional(this);
	TopicIF type = Parameters.TYPE.optional(this);
	
	if (topic != null) {
		addMixInAnnotations(TopicNameIF.class, MTopicNameWithoutTopic.class);
		
		if (type == null) {
			return topic.getTopicNames();
		} else {
			return topic.getTopicNamesByType(type);
		}
	} else {
		return getIndex(ClassInstanceIndexIF.class).getTopicNames(type);
	}
}
 
Example #12
Source File: PerfMonDataResource.java    From floodlight_with_topoguard with Apache License 2.0 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 #13
Source File: PerfMonToggleResource.java    From floodlight_with_topoguard with Apache License 2.0 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 #14
Source File: DeviceEntityResource.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Get("json")
public Iterator<Entity[]> getDeviceEntities() {
    final Iterator<? extends IDevice> devices = super.getDevices();
    return new Iterator<Entity[]>() {

        @Override
        public boolean hasNext() {
            return devices.hasNext();
        }

        @Override
        public Entity[] next() {
            Device d = (Device)devices.next();
            return d.getEntities();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
 
Example #15
Source File: SwitchCounterCategoriesResource.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Get("json")
public Map<String, Object> retrieve() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    HashMap<String,Object> model = new HashMap<String,Object>();

    String switchID = (String) getRequestAttributes().get("switchId");
    String counterName = (String) getRequestAttributes().get("counterName");
    String layer = (String) getRequestAttributes().get("layer");

    if (switchID.equalsIgnoreCase("all")) {
        for (Long dpid : floodlightProvider.getAllSwitchDpids()) {
            switchID = HexString.toHexString(dpid);

            getOneSwitchCounterCategoriesJson(model, switchID, counterName, layer);
        }
    } else {
        getOneSwitchCounterCategoriesJson(model, switchID, counterName, layer);
    }

    return model;
}
 
Example #16
Source File: ClearStaticFlowEntriesResource.java    From floodlight_with_topoguard with Apache License 2.0 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 #17
Source File: DirectedLinksResource.java    From floodlight_with_topoguard with Apache License 2.0 6 votes vote down vote up
@Get("json")
public Set<LinkWithType> retrieve() {
    ILinkDiscoveryService ld = (ILinkDiscoveryService)getContext().getAttributes().
            get(ILinkDiscoveryService.class.getCanonicalName());
    Map<Link, LinkInfo> links = new HashMap<Link, LinkInfo>();
    Set<LinkWithType> returnLinkSet = new HashSet<LinkWithType>();

    if (ld != null) {
        links.putAll(ld.getLinks());
        for (Link link: links.keySet()) {
            LinkInfo info = links.get(link);
            LinkType type = ld.getLinkType(link, info);
            if (type == LinkType.DIRECT_LINK || type == LinkType.TUNNEL) {
                LinkWithType lwt = new LinkWithType(link,
                        type,LinkDirection.UNIDIRECTIONAL);
                returnLinkSet.add(lwt);
            }
        }
    }
    return returnLinkSet;
}
 
Example #18
Source File: AdminRestletResource.java    From uReplicator with Apache License 2.0 6 votes vote down vote up
@Override
@Get
public Representation get() {
  final String opt = (String) getRequest().getAttributes().get("opt");
  JSONObject responseJson = new JSONObject();
  if ("autoscaling_status".equalsIgnoreCase(opt)) {
    responseJson.put(opt, _helixMirrorMakerManager.isAutoScalingEnabled());
  } else if ("autobalancing_status".equalsIgnoreCase(opt)) {
    responseJson.put(opt, _helixMirrorMakerManager.isAutoBalancingEnabled());
  } else if ("controller_autobalancing".equalsIgnoreCase(opt)) {
    AdminHelper helper = new AdminHelper(_helixMirrorMakerManager);
    return new StringRepresentation(helper.getControllerAutobalancingStatus(null, null)
        .toJSONString());
  } else if ("worker_number_override".equalsIgnoreCase(opt)) {
    responseJson.put("worker_number_override", _helixMirrorMakerManager.getRouteWorkerOverride());
  } else {
    LOGGER.info("No valid input!");
    responseJson.put("opt", "No valid input!");
  }
  return new StringRepresentation(responseJson.toJSONString());
}
 
Example #19
Source File: SwitchClustersResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Map<String, List<String>> retrieve() {
    IFloodlightProviderService floodlightProvider =
            (IFloodlightProviderService)getContext().getAttributes().
                get(IFloodlightProviderService.class.getCanonicalName());
    ITopologyService topology =
            (ITopologyService)getContext().getAttributes().
                get(ITopologyService.class.getCanonicalName());

    Form form = getQuery();
    String queryType = form.getFirstValue("type", true);
    boolean openflowDomain = true;
    if (queryType != null && "l2".equals(queryType)) {
        openflowDomain = false;
    }

    Map<String, List<String>> switchClusterMap = new HashMap<String, List<String>>();
    for (Long dpid: floodlightProvider.getAllSwitchDpids()) {
        Long clusterDpid =
                (openflowDomain
                 ? topology.getOpenflowDomainId(dpid)
                 :topology.getL2DomainId(dpid));
        List<String> switchesInCluster = switchClusterMap.get(HexString.toHexString(clusterDpid));
        if (switchesInCluster != null) {
            switchesInCluster.add(HexString.toHexString(dpid));
        } else {
            List<String> l = new ArrayList<String>();
            l.add(HexString.toHexString(dpid));
            switchClusterMap.put(HexString.toHexString(clusterDpid), l);
        }
    }
    return switchClusterMap;
}
 
Example #20
Source File: RoleTypesResource.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Get
public Collection<TopicIF> getRoleTypes() {
	AssociationIF association = Parameters.ID.withExpected(AssociationIF.class).optional(this);
	
	if (association == null) {
		return getIndex(ClassInstanceIndexIF.class).getAssociationRoleTypes();
	} else {
		return association.getRoleTypes();
	}
}
 
Example #21
Source File: SystemUptimeResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public UptimeRest retrieve() {
    IFloodlightProviderService floodlightProvider =
        (IFloodlightProviderService)getContext().getAttributes().
        get(IFloodlightProviderService.class.getCanonicalName());

    UptimeRest uptime = new UptimeRest();
    uptime.systemUptimeMsec = floodlightProvider.getUptime();

    return (uptime);
}
 
Example #22
Source File: ControllerMemoryResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Map<String, Object> retrieve() {
    HashMap<String, Object> model = new HashMap<String, Object>();
    Runtime runtime = Runtime.getRuntime();
    model.put("total", new Long(runtime.totalMemory()));
    model.put("free", new Long(runtime.freeMemory()));
    return model;
}
 
Example #23
Source File: BroadcastDomainPortsResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Set<NodePortTuple> retrieve() {
    ITopologyService topology = 
            (ITopologyService)getContext().getAttributes().
                get(ITopologyService.class.getCanonicalName());
    
    return topology.getBroadcastDomainPorts();
}
 
Example #24
Source File: BlockedPortsResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Set<NodePortTuple> retrieve() {
    ITopologyService topology = 
            (ITopologyService)getContext().getAttributes().
                get(ITopologyService.class.getCanonicalName());
    
    return topology.getBlockedPorts();
}
 
Example #25
Source File: TunnelLinksResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Set<NodePortTuple> retrieve() {
    ITopologyService topology = 
            (ITopologyService)getContext().getAttributes().
                get(ITopologyService.class.getCanonicalName());
    
    return topology.getTunnelPorts();
}
 
Example #26
Source File: RouteResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public List<NodePortTuple> retrieve() {
    IRoutingService routing = 
            (IRoutingService)getContext().getAttributes().
                get(IRoutingService.class.getCanonicalName());
    
    String srcDpid = (String) getRequestAttributes().get("src-dpid");
    String srcPort = (String) getRequestAttributes().get("src-port");
    String dstDpid = (String) getRequestAttributes().get("dst-dpid");
    String dstPort = (String) getRequestAttributes().get("dst-port");

    log.debug( srcDpid + "--" + srcPort + "--" + dstDpid + "--" + dstPort);

    long longSrcDpid = HexString.toLong(srcDpid);
    short shortSrcPort = Short.parseShort(srcPort);
    long longDstDpid = HexString.toLong(dstDpid);
    short shortDstPort = Short.parseShort(dstPort);
    
    Route result = routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort, 0);
    
    if (result!=null) {
        return routing.getRoute(longSrcDpid, shortSrcPort, longDstDpid, shortDstPort, 0).getPath();
    }
    else {
        log.debug("ERROR! no route found");
        return null;
    }
}
 
Example #27
Source File: MembersResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Collection <LBMember> retrieve() {
    ILoadBalancerService lbs =
            (ILoadBalancerService)getContext().getAttributes().
                get(ILoadBalancerService.class.getCanonicalName());
    
    String memberId = (String) getRequestAttributes().get("member");
    if (memberId!=null)
        return lbs.listMember(memberId);
    else        
        return lbs.listMembers();               
}
 
Example #28
Source File: PoolsResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Collection <LBPool> retrieve() {
    ILoadBalancerService lbs =
            (ILoadBalancerService)getContext().getAttributes().
                get(ILoadBalancerService.class.getCanonicalName());
    
    String poolId = (String) getRequestAttributes().get("pool");
    if (poolId!=null)
        return lbs.listPool(poolId);
    else        
        return lbs.listPools();               
}
 
Example #29
Source File: VipsResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public Collection <LBVip> retrieve() {
    ILoadBalancerService lbs =
            (ILoadBalancerService)getContext().getAttributes().
                get(ILoadBalancerService.class.getCanonicalName());
    
    String vipId = (String) getRequestAttributes().get("vip");
    if (vipId!=null)
        return lbs.listVip(vipId);
    else
        return lbs.listVips();
}
 
Example #30
Source File: FirewallRulesResource.java    From floodlight_with_topoguard with Apache License 2.0 5 votes vote down vote up
@Get("json")
public List<FirewallRule> retrieve() {
    IFirewallService firewall =
            (IFirewallService)getContext().getAttributes().
            get(IFirewallService.class.getCanonicalName());

    return firewall.getRules();
}