Java Code Examples for org.restlet.resource.Get

The following examples show how to use org.restlet.resource.Get. These examples are extracted from open source projects. 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
/**
 * 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 Project: vicinity-gateway-api   Source File: Objects.java    License: 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 3
/**
 * 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 4
/**
 * 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 5
/**
 * 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 6
Source Project: ipst   Source File: ITeslaStatsResource.java    License: 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 7
Source Project: ontopia   Source File: TopicNamesResource.java    License: 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 8
Source Project: uReplicator   Source File: AdminRestletResource.java    License: 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 9
@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 10
@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 11
@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 12
@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 13
@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 14
@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 15
Source Project: ontopia   Source File: ScopeUseResource.java    License: 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 16
Source Project: ontopia   Source File: RolesResource.java    License: 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 17
Source Project: ontopia   Source File: APIInfoResource.java    License: 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 18
Source Project: ontopia   Source File: AssociationsResource.java    License: 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 19
/**
 * Logs the object that is calling this method out from the network.
 * 
 * @return {@link StatusMessage StatusMessage} with a success message.
 */
@Get
public Representation represent() {
	
	logoutObject();
	
	// the status message has to be created a new - there is no easy way how to propagate it from the REST
	// authentication verifier.
	StatusMessage statusMessage = new StatusMessage(false, CodesAndReasons.CODE_200_OK, 
			CodesAndReasons.REASON_200_OK + "Logout successfull.", StatusMessage.CONTENTTYPE_APPLICATIONJSON);
	
	return new JsonRepresentation(statusMessage.buildMessage().toString());
}
 
Example 20
Source Project: ipst   Source File: ITeslaRules.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Get("json")
public Object getRepresentation() throws Exception{

    Form queryForm = getRequest().getOriginalRef().getQueryAsForm();
    String workflowId = queryForm.getFirstValue("workflowId", true, null);
    String startStr = queryForm.getFirstValue("start", "0");
    String countStr = queryForm.getFirstValue("count", "50");

    Map<String, Object> query = new HashMap();
    if (algoType != null) query.put("algoType", algoType);
    if (contingencyId != null) query.put("contingencyId", contingencyId);
    if (indexType != null) query.put("indexType", indexType);
    if (workflowId != null) query.put("workflowId", workflowId);

    Dataset set = datasource.getData(query,
            Integer.parseInt(startStr),
            Integer.parseInt(countStr),
            ColumnDescriptor.getDescriptorsForNames("algoType", "contingencyId", "indexType", "workflowId", "quality", "treeSize", "criticality", "tree"));
    Iterator<Collection> it = set.getRowIterator();

    JSONArray result = new JSONArray();

    while (it.hasNext()) {
        Object[] values = it.next().toArray();
        JSONObject ruleObj = new JSONObject();
        ruleObj.put("algoType", values[0]);
        ruleObj.put("contingencyId", values[1]);
        ruleObj.put("indexType", values[2]);
        ruleObj.put("workflowId", values[3]);
        ruleObj.put("quality", values[4]);
        ruleObj.put("treeSize", values[5]);
        ruleObj.put("criticality", values[6]);
        ruleObj.put("tree", new JSONObject((String)values[7]));
        result.put(ruleObj);
    }

    return result;
}
 
Example 21
Source Project: ipst   Source File: ITeslaRules.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Get("cond")
public String getTreeConditions() throws Exception{

    Form queryForm = getRequest().getOriginalRef().getQueryAsForm();
    String workflowId = queryForm.getFirstValue("workflowId", true, null);

    Map<String, Object> query = new HashMap();
    if (algoType != null) query.put("algoType", algoType);
    if (contingencyId != null) query.put("contingencyId", contingencyId);
    if (indexType != null) query.put("indexType", indexType);
    if (workflowId != null) query.put("workflowId", workflowId);

    Dataset set = datasource.getData(query,
            0,
            -1,
            ColumnDescriptor.getDescriptorsForNames("tree"));
    Iterator<Collection> it = set.getRowIterator();

    StringBuffer conditions = new StringBuffer();

    while (it.hasNext()) {
        Object[] values = it.next().toArray();
        JSONObject jsonTreeDescr = new JSONObject((String)values[0]);

        processJsonTree(jsonTreeDescr, conditions);
    }

    return conditions.toString();
}
 
Example 22
Source Project: ontopia   Source File: TopicUseResource.java    License: Apache License 2.0 5 votes vote down vote up
@Get
public Map<String, Object> getTopicUse() {
	TopicIF topic = resolve();
	
	ClassInstanceIndexIF index = getIndex(ClassInstanceIndexIF.class);
	
	boolean usedAsAssociationRoleType = index.usedAsAssociationRoleType(topic);
	boolean usedAsAssociationType = index.usedAsAssociationType(topic);
	boolean usedAsOccurrenceType = index.usedAsOccurrenceType(topic);
	boolean usedAsTopicNameType = index.usedAsTopicNameType(topic);
	boolean usedAsTopicType = index.usedAsTopicType(topic);

	Map<String, Object> result = new HashMap<>();
	result.put("usedAsType", index.usedAsType(topic));
	result.put("usedAsAssociationRoleType", usedAsAssociationRoleType);
	result.put("usedAsAssociationType", usedAsAssociationType);
	result.put("usedAsOccurrenceType", usedAsOccurrenceType);
	result.put("usedAsTopicNameType", usedAsTopicNameType);
	result.put("usedAsTopicType", usedAsTopicType);
	result.put("usedAsType", 
			usedAsAssociationRoleType ||
			usedAsAssociationType ||
			usedAsOccurrenceType ||
			usedAsTopicNameType ||
			usedAsTopicType	
	);
	
	return result;
}
 
Example 23
@Override
@Get
public Representation get() {
  final String topicName = (String) getRequest().getAttributes().get("topicName");
  if (topicName == null) {
    List<String> topicLists = _helixMirrorMakerManager.getTopicLists();
    if (topicLists == null || topicLists.isEmpty()) {
      return new StringRepresentation("No topic is added in MirrorMaker Controller!");
    } else {
      return new StringRepresentation(String
          .format("Current serving topics: %s", Arrays.toString(topicLists.toArray())));
    }
  }
  try {
    if (_helixMirrorMakerManager.isTopicExisted(topicName)) {
      IdealState idealStateForTopic =
          _helixMirrorMakerManager.getIdealStateForTopic(topicName);
      ExternalView externalViewForTopic =
          _helixMirrorMakerManager.getExternalViewForTopic(topicName);
      JSONObject responseJson = TopicAssignmentViewBuilder.build(
          topicName, idealStateForTopic, externalViewForTopic);
      return new StringRepresentation(responseJson.toJSONString());
    } else {
      getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
      return new StringRepresentation(String
          .format("Failed to get ExternalView for topic: %s, it is not existed!", topicName));
    }
  } catch (Exception e) {
    LOGGER.error("Got error during processing Get request", e);
    getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
    return new StringRepresentation(String
        .format("Failed to get ExternalView for topic: %s, with exception: %s", topicName, e));
  }
}
 
Example 24
Source Project: uReplicator   Source File: AdminRestletResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Get
public Representation get() {
  JSONObject responseJson = new JSONObject();
  final String opt = (String) getRequest().getAttributes().get("opt");
  if ("autobalancing_status".equalsIgnoreCase(opt)) {
    responseJson.put("auto_balancing", _helixMirrorMakerManager.isAutoBalancingEnabled());
  } else if ("workloadinfo".equalsIgnoreCase(opt)) {
    return new StringRepresentation(JSONObject.toJSONString(calculateWorkloadInfo()));
  } else {
    LOGGER.info("No valid input!");
    responseJson.put("opt", "No valid input!");
  }
  return new StringRepresentation(responseJson.toJSONString());
}
 
Example 25
/**
 * Gets topic partition in blacklist
 *
 * @return topic partition in blacklist
 */
@Override
@Get
public Representation get() {
  Set<TopicPartition> blacklist = _helixMirrorMakerManager.getTopicPartitionBlacklist();
  JSONObject result = new JSONObject();
  result.put("blacklist", blacklist);
  return new StringRepresentation(result.toJSONString());
}
 
Example 26
Source Project: uReplicator   Source File: HealthCheckRestletResource.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Get
public Representation get() {
  if (_helixMirrorMakerManager.isHealthy()) {
    return new StringRepresentation("OK\n");
  } else {
    getResponse().setStatus(Status.SERVER_ERROR_SERVICE_UNAVAILABLE);
    return new StringRepresentation("Unhealthy\n");
  }
}
 
Example 27
@Override
@Get
public Representation get() {
  JSONObject responseJson = new JSONObject();
  List<TopicAndPartition> noProgressTopicPartition = _helixMirrorMakerManager.getOffsetMonitor().getNoProgessTopicPartitions();
  if (noProgressTopicPartition == null || noProgressTopicPartition.size() == 0) {
    return new StringRepresentation(responseJson.toJSONString());
  }
  JSONArray jsonArray = new JSONArray();
  for (TopicAndPartition info : noProgressTopicPartition) {

    JSONObject node = new JSONObject();
    node.put("topic", info.topic());
    node.put("partition", info.partition());

    IdealState idealStateForTopic =
        _helixMirrorMakerManager.getIdealStateForTopic(info.topic());
    Map<String, String> idealStateMap = idealStateForTopic.getInstanceStateMap(String.valueOf(info.partition()));
    ExternalView externalViewForTopic =
        _helixMirrorMakerManager.getExternalViewForTopic(info.topic());
    Map<String, String> stateMap = externalViewForTopic.getStateMap(String.valueOf(info.partition()));
    if (idealStateMap != null && idealStateMap.keySet().size() != 0) {
      node.put("idealWorker", idealStateMap.keySet().iterator().next());
    }
    if (stateMap != null && stateMap.keySet().size() != 0) {
      node.put("actualWorker", stateMap.keySet().iterator().next());
    }
    jsonArray.add(node);

  }
  responseJson.put("topics", jsonArray);

  return new StringRepresentation(responseJson.toJSONString());
}
 
Example 28
Source Project: floodlight_with_topoguard   Source File: NetworkResource.java    License: Apache License 2.0 5 votes vote down vote up
@Get("json")
public Collection <VirtualNetwork> retrieve() {
    IVirtualNetworkService vns =
            (IVirtualNetworkService)getContext().getAttributes().
                get(IVirtualNetworkService.class.getCanonicalName());
    
    return vns.listNetworks();               
}
 
Example 29
Source Project: floodlight_with_topoguard   Source File: NoOp.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Does nothing and returns 200 OK with a status message
 * 
 * @return status: ok
 */
@Get
@Put
@Post
@Delete
public String noOp(String postdata) {
    setStatus(Status.SUCCESS_OK);
    return "{\"status\":\"ok\"}";
}
 
Example 30
Source Project: ontopia   Source File: ScopedResource.java    License: Apache License 2.0 5 votes vote down vote up
@Get
public Collection<? extends TMObjectIF> getScoped() {
	TopicIF topic = resolve();
	ScopeIndexIF index = getIndex(ScopeIndexIF.class);

	switch (getAttribute("type").toUpperCase()) {
		case "ASSOCIATIONS": return index.getAssociations(topic);
		case "OCCURRENCES": return index.getOccurrences(topic);
		case "NAMES": return index.getTopicNames(topic);
		case "VARIANTS": return index.getVariants(topic);
		default:
			setStatus(Status.CLIENT_ERROR_NOT_FOUND, "Expected type one of associations, occurrences, names, variants");
			return null;
	}
}