public static IndexDefinition map(IndexEntry entry) { return new IndexDefinition(entry.getName(), entry.getKeyHeader(), entry.getValueHeader(), entry.getIndexType()); } }
private RestEntity requestById(StorageService storageService, String requestedId, RequestContext context) throws JasDBStorageException { Entity entity = storageService.getEntityById(context, requestedId); if(entity != null) { return new StreamedEntity(entity); } else { return new ErrorEntity(404, "No entity was found with id: " + requestedId); } }
public RestUserList(List<String> userList) { users = new ArrayList<>(userList.size()); for(String user: userList) { users.add(new RestUser(user, null, null)); } }
public static Node mapTo(NodeInformation nodeInformation) { if(nodeInformation != null) { Node mappedNode = new Node(); mappedNode.setGridId(nodeInformation.getGridId()); mappedNode.setInstanceId(nodeInformation.getInstanceId()); List<NodeServiceInformation> nodeServices = new ArrayList<>(); for(ServiceInformation serviceInformation : nodeInformation.getServiceInformationList()) { NodeServiceInformation nodeService = new NodeServiceInformation(); nodeService.setProperties(serviceInformation.getNodeProperties()); nodeService.setServiceType(serviceInformation.getServiceType()); nodeServices.add(nodeService); } mappedNode.setServices(nodeServices); return mappedNode; } else { return null; } }
@Override public List<String> getUsers(RemotingContext context) throws RemoteException { ClientResponse clientResponse = doRequest(context, "Users"); try { RestUserList userList = new JsonRestResponseHandler().deserialize(RestUserList.class, clientResponse.getEntityInputStream()); List<String> userNames = new ArrayList<>(); for(RestUser restUser : userList.getUsers()) { userNames.add(restUser.getUsername()); } return userNames; } catch(RestException e) { throw new RemoteException("Unable to retrieve remote user list", e); } }
public static RestGrant map(String objectName, Grant grant) { return new RestGrant(grant.getGrantedUsername(), objectName, grant.getAccessMode()); } }
private ResponseEntity<RestEntity> doSearch(String instanceId, String bagName) throws JasDBException { DBInstance instance = getInstance(instanceFactory, instanceId); LOG.debug("Searching for a bag on instance: {} with name: {}", instanceId, bagName); try { StorageService storageService = storageServiceFactory.getStorageService(instance.getInstanceId(), bagName); if(storageService != null) { LOG.debug("Found a bag with name: {}", bagName); return ok(new RestBag(instance.getInstanceId(), bagName, storageService.getSize(), storageService.getDiskSize())); } else { return notFound(new ErrorEntity(404, "No bag was found with name: " + bagName)); } } catch(JasDBStorageException e) { throw new RestException("Unable to load bag metadata", e); } }
@RequestMapping(value = "/Caches", method = RequestMethod.GET, produces = "application/json") public RestEntity loadModel() throws RestException { GlobalCachingMemoryManager cachingMemoryManager = GlobalCachingMemoryManager.getGlobalInstance(); List<CacheBucket> buckets = new ArrayList<>(); for(CacheRegion region : cachingMemoryManager.getRegions()) { buckets.add(new CacheBucket(region.name(), region.size(), region.memorySize())); } return new CacheBucketCollection(buckets); } }
@RequestMapping(value = "/stats", method = RequestMethod.GET, produces = "application/json") public RestEntity loadModel() throws RestException { List<AggregationResult> stats = StatisticsMonitor.getAggregationResults(); List<Statistic> mappedStats = new LinkedList<>(); for(AggregationResult stat : stats) { mappedStats.add(new Statistic(stat.getName(), stat.getAverage(), stat.getCalls(), stat.getTotalTime(), stat.getLowest(), stat.getHighest())); } return new StatisticCollection(mappedStats); }
public static IndexEntry map(IndexDefinition definition, boolean isUnique) { return new IndexEntry(definition.getIndexName(), definition.getHeaderDescriptor(), definition.getValueDescriptor(), isUnique, definition.getIndexType()); }
private InstanceRest loadInstance(String instanceId) throws RestException { try { DBInstance dbInstance = instanceFactory.getInstance(instanceId); return new InstanceRest(dbInstance.getPath(), "OK", engineManager.getEngineVersion(), dbInstance.getInstanceId()); } catch(ConfigurationException e) { throw new RestException("Unable to retrieve the instance", e); } }
public static void handleError(String message, HttpServletResponse response) { handleError(new ErrorEntity(HttpStatus.BAD_REQUEST.value(), message), response); }
private static void handleError(ErrorEntity errorEntity, HttpServletResponse response) { sendResponse(errorEntity, errorEntity.getStatusCode(), response); }
@RequestMapping(value = "/Instances", produces = "application/json", method = GET) public RestEntity getInstances() throws RestException { return new InstanceCollection(loadInstances()); }
@RequestMapping(value = "/stats/reset") public RestEntity doOperation() throws RestException { StatisticsMonitor.clearStats(); return new StatisticCollection(new LinkedList<>()); } }
private RestEntity loadUserList(RequestContext context) throws RestException { try { List<String> userList = userManager.getUsers(context.getUserSession()); return new RestUserList(userList); } catch(JasDBStorageException e) { throw new RestException("Unable to load user list", e); } }
@Override public void addUser(RemotingContext context, String username, String host, String password) throws RemoteException { try { byte[] serializedUser = toBytes(new RestUser(username, host, password)); doInternalRequest(context, "Users", new HashMap<>(), serializedUser, REQUEST_MODE.POST); } catch(RestException e) { throw new RemoteException("Unable to add user", e); } }
@Override public void revoke(RemotingContext context, String object, String user) throws RemoteException { try { byte[] serializedGrant = toBytes(new RestGrant(user, object, AccessMode.NONE)); doInternalRequest(context, "Grants", new HashMap<>(), serializedGrant, REQUEST_MODE.DELETE); } catch(RestException e) { throw new RemoteException("Unable to grant", e); } } }
public static void createResponse(final RestEntity entity, HttpServletResponse response) { if(entity != null) { if(entity instanceof ErrorEntity) { handleError((ErrorEntity)entity, response); } else { sendResponse(entity, HttpStatus.OK.value(), response); } } else { handleError(new ErrorEntity(HttpStatus.NOT_FOUND.value(), "Resource could not be found"), response); } }
@Override public void grant(RemotingContext context, String object, String user, AccessMode mode) throws RemoteException { try { byte[] serializedGrant = toBytes(new RestGrant(user, object, mode)); doInternalRequest(context, "Grants", new HashMap<>(), serializedGrant, REQUEST_MODE.POST); } catch(RestException e) { throw new RemoteException("Unable to grant", e); } }