protected Collection<AgentMetadata> getAgentMetadataForPlugin(String pluginId) { LOGGER.debug("Listing agents for plugin {}", pluginId); List<ElasticAgentMetadata> elasticAgents = agentService.allElasticAgents().get(pluginId); Collection<AgentMetadata> metadata; if (elasticAgents == null) { metadata = new ArrayList<>(); } else { metadata = elasticAgents.stream().map(ElasticAgentPluginService::toAgentMetadata).collect(Collectors.toList()); } return metadata; }
@SuppressWarnings("rawtypes") public void receive(LinkedMultiValueMap<String, Object> multipartRequest){ logger.info("Successfully received multipart request: " + multipartRequest); for (String elementName : multipartRequest.keySet()) { if (elementName.equals("company")){ LinkedList value = (LinkedList)multipartRequest.get("company"); String[] multiValues = (String[]) value.get(0); for (String companyName : multiValues) { logger.info(elementName + " - " + companyName); } } else if (elementName.equals("company-logo")){ logger.info(elementName + " - as UploadedMultipartFile: " + ((UploadedMultipartFile) multipartRequest.getFirst("company-logo")).getOriginalFilename()); } } } }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>(); List<AnnotationAttributes> attributes = this.attributesMap.get(annotationName); if (attributes == null) { return null; } for (AnnotationAttributes raw : attributes) { for (Map.Entry<String, Object> entry : AnnotationReadingVisitorUtils.convertClassValues( "class '" + getClassName() + "'", this.classLoader, raw, classValuesAsString).entrySet()) { allAttributes.add(entry.getKey(), entry.getValue()); } } return allAttributes; }
@Test @SuppressWarnings("unchecked") public void getRequestGeneratesMapPayload() throws Exception { QueueChannel requestChannel = new QueueChannel(); HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false); gateway.setBeanFactory(mock(BeanFactory.class)); gateway.setRequestChannel(requestChannel); gateway.afterPropertiesSet(); gateway.start(); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.setParameter("foo", "bar"); MockHttpServletResponse response = new MockHttpServletResponse(); gateway.handleRequest(request, response); Message<?> message = requestChannel.receive(0); assertNotNull(message); assertEquals(LinkedMultiValueMap.class, message.getPayload().getClass()); LinkedMultiValueMap<String, String> map = (LinkedMultiValueMap<String, String>) message.getPayload(); assertEquals(1, map.get("foo").size()); assertEquals("bar", map.getFirst("foo")); }
public void updateAfterRemovedSubscription(String sessionId, String subsId) { synchronized (this.updateCache) { Set<String> destinationsToRemove = new HashSet<>(); this.updateCache.forEach((destination, sessionMap) -> { List<String> subscriptions = sessionMap.get(sessionId); if (subscriptions != null) { subscriptions.remove(subsId); if (subscriptions.isEmpty()) { sessionMap.remove(sessionId); } if (sessionMap.isEmpty()) { destinationsToRemove.add(destination); } else { this.accessCache.put(destination, sessionMap.deepCopy()); } } }); for (String destination : destinationsToRemove) { this.updateCache.remove(destination); this.accessCache.remove(destination); } } }
public void updateAfterNewSubscription(String destination, String sessionId, String subsId) { synchronized (this.updateCache) { this.updateCache.forEach((cachedDestination, subscriptions) -> { if (getPathMatcher().match(destination, cachedDestination)) { // Subscription id's may also be populated via getSubscriptions() List<String> subsForSession = subscriptions.get(sessionId); if (subsForSession == null || !subsForSession.contains(subsId)) { subscriptions.add(sessionId, subsId); this.accessCache.put(cachedDestination, subscriptions.deepCopy()); } } }); } }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (!this.attributesMap.containsKey(annotationName)) { return null; } MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>(); List<AnnotationAttributes> attributesList = this.attributesMap.get(annotationName); if (attributesList != null) { for (AnnotationAttributes annotationAttributes : attributesList) { AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues( "method '" + getMethodName() + "'", this.classLoader, annotationAttributes, classValuesAsString); convertedAttributes.forEach(allAttributes::add); } } return allAttributes; }
List<AnnotationAttributes> attributesList = attributesMap.get(annotationName); if (attributesList == null || attributesList.isEmpty()) { return null; List<AnnotationAttributes> currentAttributesList = attributesMap.get(currentAnnotationType); if (!ObjectUtils.isEmpty(currentAttributesList)) { Set<String> metaAnns = metaAnnotationMap.get(currentAnnotationType);
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>(); List<AnnotationAttributes> attributes = this.attributesMap.get(annotationName); if (attributes == null) { return null; } for (AnnotationAttributes raw : attributes) { for (Map.Entry<String, Object> entry : AnnotationReadingVisitorUtils.convertClassValues( "class '" + getClassName() + "'", this.classLoader, raw, classValuesAsString).entrySet()) { allAttributes.add(entry.getKey(), entry.getValue()); } } return allAttributes; }
@Override @Nullable public MultiValueMap<String, Object> getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (!this.attributesMap.containsKey(annotationName)) { return null; } MultiValueMap<String, Object> allAttributes = new LinkedMultiValueMap<>(); List<AnnotationAttributes> attributesList = this.attributesMap.get(annotationName); if (attributesList != null) { for (AnnotationAttributes annotationAttributes : attributesList) { AnnotationAttributes convertedAttributes = AnnotationReadingVisitorUtils.convertClassValues( "method '" + getMethodName() + "'", this.classLoader, annotationAttributes, classValuesAsString); convertedAttributes.forEach(allAttributes::add); } } return allAttributes; }
List<AnnotationAttributes> attributesList = attributesMap.get(annotationName); if (attributesList == null || attributesList.isEmpty()) { return null; List<AnnotationAttributes> currentAttributesList = attributesMap.get(currentAnnotationType); if (!ObjectUtils.isEmpty(currentAttributesList)) { Set<String> metaAnns = metaAnnotationMap.get(currentAnnotationType);
@Test public void addAll() throws Exception { map.add("key", "value1"); map.addAll("key", Arrays.asList("value2", "value3")); assertEquals(1, map.size()); List<String> expected = new ArrayList<>(2); expected.add("value1"); expected.add("value2"); expected.add("value3"); assertEquals(expected, map.get("key")); }
@Test public void add() { map.add("key", "value1"); map.add("key", "value2"); assertEquals(1, map.size()); List<String> expected = new ArrayList<>(2); expected.add("value1"); expected.add("value2"); assertEquals(expected, map.get("key")); }
public void heartbeat() { LinkedMultiValueMap<String, ElasticAgentMetadata> elasticAgentsOfMissingPlugins = agentService.allElasticAgents(); // pingMessage TTL is set lesser than elasticPluginHeartBeatInterval to ensure there aren't multiple ping request for the same plugin long pingMessageTimeToLive = elasticPluginHeartBeatInterval - 10000L; for (PluginDescriptor descriptor : elasticAgentPluginRegistry.getPlugins()) { serverPingQueue.post(new ServerPingMessage(descriptor.id()), pingMessageTimeToLive); elasticAgentsOfMissingPlugins.remove(descriptor.id()); serverHealthService.removeByScope(scope(descriptor.id())); } if (!elasticAgentsOfMissingPlugins.isEmpty()) { for (String pluginId : elasticAgentsOfMissingPlugins.keySet()) { Collection<String> uuids = elasticAgentsOfMissingPlugins.get(pluginId).stream().map(ElasticAgentMetadata::uuid).collect(Collectors.toList()); String description = String.format("Elastic agent plugin with identifier %s has gone missing, but left behind %s agent(s) with UUIDs %s.", pluginId, elasticAgentsOfMissingPlugins.get(pluginId).size(), uuids); serverHealthService.update(ServerHealthState.warning("Elastic agents with no matching plugins", description, HealthStateType.general(scope(pluginId)))); LOGGER.warn(description); } } }
@Test public void set() { map.set("key", "value1"); map.set("key", "value2"); assertEquals(1, map.size()); assertEquals(Collections.singletonList("value2"), map.get("key")); }
@SuppressWarnings("unchecked") @Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { LinkedMultiValueMap<Expression<?>, Predicate> predicates = new LinkedMultiValueMap<>(); List<JoinExpression> joins = metadata.getJoins(); for (int i = joins.size() - 1; i >= 0; i--) { JoinExpression join = joins.get(i); Path<?> source = (Path) ((Operation<?>) join.getTarget()).getArg(0); Path<?> target = (Path) ((Operation<?>) join.getTarget()).getArg(1); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<? extends Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { return ExpressionUtils.predicate(QuerydslMongoOps.NO_MATCH, source); } Path<?> path = ExpressionUtils.path(String.class, source, "$id"); predicates.add(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids)); } Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
public void updateAfterRemovedSubscription(String sessionId, String subsId) { synchronized (this.updateCache) { Set<String> destinationsToRemove = new HashSet<>(); this.updateCache.forEach((destination, sessionMap) -> { List<String> subscriptions = sessionMap.get(sessionId); if (subscriptions != null) { subscriptions.remove(subsId); if (subscriptions.isEmpty()) { sessionMap.remove(sessionId); } if (sessionMap.isEmpty()) { destinationsToRemove.add(destination); } else { this.accessCache.put(destination, sessionMap.deepCopy()); } } }); for (String destination : destinationsToRemove) { this.updateCache.remove(destination); this.accessCache.remove(destination); } } }
public void updateAfterNewSubscription(String destination, String sessionId, String subsId) { synchronized (this.updateCache) { this.updateCache.forEach((cachedDestination, subscriptions) -> { if (getPathMatcher().match(destination, cachedDestination)) { // Subscription id's may also be populated via getSubscriptions() List<String> subsForSession = subscriptions.get(sessionId); if (subsForSession == null || !subsForSession.contains(subsId)) { subscriptions.add(sessionId, subsId); this.accessCache.put(cachedDestination, subscriptions.deepCopy()); } } }); } }
@SuppressWarnings("unchecked") @Nullable protected Predicate createJoinFilter(QueryMetadata metadata) { LinkedMultiValueMap<Expression<?>, Predicate> predicates = new LinkedMultiValueMap<>(); List<JoinExpression> joins = metadata.getJoins(); for (int i = joins.size() - 1; i >= 0; i--) { JoinExpression join = joins.get(i); Path<?> source = (Path) ((Operation<?>) join.getTarget()).getArg(0); Path<?> target = (Path) ((Operation<?>) join.getTarget()).getArg(1); Collection<Predicate> extraFilters = predicates.get(target.getRoot()); Predicate filter = ExpressionUtils.allOf(join.getCondition(), allOf(extraFilters)); List<? extends Object> ids = getIds(target.getType(), filter); if (ids.isEmpty()) { return ExpressionUtils.predicate(QuerydslMongoOps.NO_MATCH, source); } Path<?> path = ExpressionUtils.path(String.class, source, "$id"); predicates.add(source.getRoot(), ExpressionUtils.in((Path<Object>) path, ids)); } Path<?> source = (Path) ((Operation) joins.get(0).getTarget()).getArg(0); return allOf(predicates.get(source.getRoot())); }
@Test public void multiValueParameterMap() throws Exception { QueueChannel channel = new QueueChannel(); HttpRequestHandlingMessagingGateway gateway = new HttpRequestHandlingMessagingGateway(false); gateway.setBeanFactory(mock(BeanFactory.class)); gateway.setRequestChannel(channel); gateway.afterPropertiesSet(); gateway.start(); MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test"); request.setParameter("foo", "123"); request.addParameter("bar", "456"); request.addParameter("bar", "789"); MockHttpServletResponse response = new MockHttpServletResponse(); gateway.handleRequest(request, response); Message<?> message = channel.receive(0); assertNotNull(message); assertNotNull(message.getPayload()); assertEquals(LinkedMultiValueMap.class, message.getPayload().getClass()); @SuppressWarnings("unchecked") LinkedMultiValueMap<String, String> map = (LinkedMultiValueMap<String, String>) message.getPayload(); List<String> fooValues = map.get("foo"); List<String> barValues = map.get("bar"); assertEquals(1, fooValues.size()); assertEquals("123", fooValues.get(0)); assertEquals(2, barValues.size()); assertEquals("456", barValues.get(0)); assertEquals("789", barValues.get(1)); }