Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public InstanceIdGenerator instanceIdGenerator() {
@Bean
@ConditionalOnMissingBean
public StatusUpdater statusUpdater(InstanceRepository instanceRepository,
InstanceWebClient.Builder instanceWebClientBulder) {
return new StatusUpdater(instanceRepository, instanceWebClientBulder.build(), new ApiMediaTypeHandler());
InstanceWebClient.Builder instanceWebClientBuilder) {
return new StatusUpdater(instanceRepository, instanceWebClientBuilder.build(), new ApiMediaTypeHandler());
}

@Bean(initMethod = "start", destroyMethod = "stop")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,12 @@ private List<InstanceEvent> appendToEvents(InstanceEvent event, boolean isNewEve

@Nullable
@SafeVarargs
private final BuildVersion updateBuildVersion(Map<String, ?>... sources) {
private BuildVersion updateBuildVersion(Map<String, ?>... sources) {
return Arrays.stream(sources).map(BuildVersion::from).filter(Objects::nonNull).findFirst().orElse(null);
}

@SafeVarargs
private final Tags updateTags(Map<String, ?>... sources) {
private Tags updateTags(Map<String, ?>... sources) {
return Arrays.stream(sources).map((source) -> Tags.from(source, "tags")).reduce(Tags.empty(), Tags::append);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class SnapshottingInstanceRepository extends EventsourcingInstanceReposit

private final ConcurrentMap<InstanceId, Instance> snapshots = new ConcurrentHashMap<>();

private final Set<InstanceId> oudatedSnapshots = ConcurrentHashMap.newKeySet();
private final Set<InstanceId> outdatedSnapshots = ConcurrentHashMap.newKeySet();

private final InstanceEventStore eventStore;

Expand All @@ -64,19 +64,19 @@ public Flux<Instance> findAll() {
@Override
public Mono<Instance> find(InstanceId id) {
return Mono.defer(() -> {
if (!this.oudatedSnapshots.contains(id)) {
if (!this.outdatedSnapshots.contains(id)) {
return Mono.justOrEmpty(this.snapshots.get(id));
}
else {
return rehydrateSnapshot(id).doOnSuccess((v) -> this.oudatedSnapshots.remove(v.getId()));
return rehydrateSnapshot(id).doOnSuccess((v) -> this.outdatedSnapshots.remove(v.getId()));
}
});
}

@Override
public Mono<Instance> save(Instance instance) {
return super.save(instance).doOnError(OptimisticLockingException.class,
(e) -> this.oudatedSnapshots.add(instance.getId()));
(e) -> this.outdatedSnapshots.add(instance.getId()));
}

public void start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
Expand All @@ -32,6 +33,7 @@ public class InstanceDeregisteredEvent extends InstanceEvent {

public static final String TYPE = "DEREGISTERED";

@Serial
private static final long serialVersionUID = 1L;

public InstanceDeregisteredEvent(InstanceId instance, long version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.Endpoints;
Expand All @@ -33,6 +34,7 @@ public class InstanceEndpointsDetectedEvent extends InstanceEvent {

public static final String TYPE = "ENDPOINTS_DETECTED";

@Serial
private static final long serialVersionUID = 1L;

private final Endpoints endpoints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;

Expand All @@ -31,6 +32,7 @@
@lombok.Data
public abstract class InstanceEvent implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private final InstanceId instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.Info;
Expand All @@ -33,6 +34,7 @@ public class InstanceInfoChangedEvent extends InstanceEvent {

public static final String TYPE = "INFO_CHANGED";

@Serial
private static final long serialVersionUID = 1L;

private final Info info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
Expand All @@ -33,6 +34,7 @@ public class InstanceRegisteredEvent extends InstanceEvent {

public static final String TYPE = "REGISTERED";

@Serial
private static final long serialVersionUID = 1L;

private final Registration registration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
Expand All @@ -33,6 +34,7 @@ public class InstanceRegistrationUpdatedEvent extends InstanceEvent {

public static final String TYPE = "REGISTRATION_UPDATED";

@Serial
private static final long serialVersionUID = 1L;

private final Registration registration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package de.codecentric.boot.admin.server.domain.events;

import java.io.Serial;
import java.time.Instant;

import de.codecentric.boot.admin.server.domain.values.InstanceId;
Expand All @@ -33,6 +34,7 @@ public class InstanceStatusChangedEvent extends InstanceEvent {

public static final String TYPE = "STATUS_CHANGED";

@Serial
private static final long serialVersionUID = 1L;

private final StatusInfo statusInfo;
Expand All @@ -46,8 +48,4 @@ public InstanceStatusChangedEvent(InstanceId instance, long version, Instant tim
this.statusInfo = statusInfo;
}

public StatusInfo getStatusInfo() {
return statusInfo;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package de.codecentric.boot.admin.server.eventstore;

import java.util.List;
import java.util.stream.Collectors;

import com.hazelcast.core.EntryAdapter;
import com.hazelcast.core.EntryEvent;
Expand Down Expand Up @@ -52,7 +51,7 @@ public void entryUpdated(EntryEvent<InstanceId, List<InstanceEvent>> event) {
List<InstanceEvent> newEvents = event.getValue()
.stream()
.filter((e) -> e.getVersion() > lastKnownVersion)
.collect(Collectors.toList());
.toList();
HazelcastEventStore.this.publish(newEvents);
}
}, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import lombok.extern.slf4j.Slf4j;
import org.apache.hc.client5.http.utils.Base64;
import org.springframework.context.expression.MapAccessor;
import org.springframework.expression.Expression;
Expand All @@ -47,6 +48,7 @@
*
* @author Mask
*/
@Slf4j
public class DingTalkNotifier extends AbstractStatusChangeNotifier {

private static final String DEFAULT_MESSAGE = "#{instance.registration.name} #{instance.id} is #{event.statusInfo.status}";
Expand Down Expand Up @@ -116,10 +118,10 @@ private String getSign(Long timestamp) {
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
return URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
return URLEncoder.encode(new String(Base64.encodeBase64(signData)), StandardCharsets.UTF_8);
}
catch (Exception ex) {
ex.printStackTrace();
log.warn("Failed to sign message", ex);
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import javax.crypto.spec.SecretKeySpec;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.expression.MapAccessor;
import org.springframework.expression.Expression;
import org.springframework.expression.ParserContext;
Expand All @@ -58,12 +57,11 @@
* "https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN">https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN</a>
*
*/
@Slf4j
public class FeiShuNotifier extends AbstractStatusChangeNotifier {

private static final String DEFAULT_MESSAGE = "ServiceName: #{instance.registration.name}(#{instance.id}) \nServiceUrl: #{instance.registration.serviceUrl} \nStatus: changed status from [#{lastStatus}] to [#{event.statusInfo.status}]";

private final Logger log = LoggerFactory.getLogger(this.getClass());

private final SpelExpressionParser parser = new SpelExpressionParser();

private RestTemplate restTemplate;
Expand Down Expand Up @@ -143,9 +141,6 @@ protected HttpEntity<Map<String, Object>> createNotification(InstanceEvent event
body.put("card", this.createCardContent(event, instance));
break;
case text:
body.put("content", this.createTextContent(event, instance));
break;

default:
body.put("content", this.createTextContent(event, instance));
}
Expand Down Expand Up @@ -177,13 +172,12 @@ private String createTextContent(InstanceEvent event, Instance instance) {

private String createCardContent(InstanceEvent event, Instance instance) {
String content = this.createContent(event, instance);
Card card = this.card;

Map<String, Object> header = new HashMap<>();
header.put("template", StringUtils.hasText(card.getThemeColor()) ? "red" : card.getThemeColor());
header.put("template", StringUtils.hasText(this.card.getThemeColor()) ? "red" : this.card.getThemeColor());
Map<String, String> titleContent = new HashMap<>();
titleContent.put("tag", "plain_text");
titleContent.put("content", card.getTitle());
titleContent.put("content", this.card.getTitle());
header.put("title", titleContent);

List<Map<String, Object>> elements = new ArrayList<>();
Expand Down Expand Up @@ -217,7 +211,7 @@ private String toJsonString(Object o) {
return objectMapper.writeValueAsString(o);
}
catch (Exception ex) {
ex.printStackTrace();
log.warn("Failed to serialize JSON object", ex);
}
return null;
}
Expand Down Expand Up @@ -280,7 +274,7 @@ public enum MessageType {

}

public class Card {
public static class Card {

/**
* This is header title.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public LetsChatNotifier(InstanceRepository repository, RestTemplate restTemplate
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// Let's Chat requiers the token as basic username, the password can be an
// Let's Chat requires the token as basic username, the password can be an
// arbitrary string.
String auth = Base64.getEncoder()
.encodeToString(String.format("%s:%s", token, username).getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import static java.util.Collections.singleton;

/**
* Notifier sending emails using thymleaf templates.
* Notifier sending emails using Thymeleaf templates.
*
* @author Johannes Edmeier
*/
Expand Down Expand Up @@ -74,7 +74,7 @@ public class MailNotifier extends AbstractStatusChangeNotifier {
private String baseUrl;

/**
* Thymleaf template for mail
* Thymeleaf template for mail
*/
private String template = "META-INF/spring-boot-admin-server/mail/status-changed.html";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TelegramNotifier extends AbstractStatusChangeNotifier {
private String chatId;

/**
* The token identifiying und authorizing your Telegram bot (e.g.
* The token identifying und authorizing your Telegram bot (e.g.
* `123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11`)
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

import static de.codecentric.boot.admin.server.domain.values.StatusInfo.STATUS_UNKNOWN;
import static java.util.Comparator.naturalOrder;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;

/**
Expand Down Expand Up @@ -114,7 +113,7 @@ protected BuildVersion getBuildVersion(List<Instance> instances) {
.filter(Objects::nonNull)
.distinct()
.sorted()
.collect(toList());
.toList();
if (versions.isEmpty()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class InfoUpdater {

private static final Logger log = LoggerFactory.getLogger(InfoUpdater.class);

private static final ParameterizedTypeReference<Map<String, Object>> RESPONSE_TYPE = new ParameterizedTypeReference<Map<String, Object>>() {
private static final ParameterizedTypeReference<Map<String, Object>> RESPONSE_TYPE = new ParameterizedTypeReference<>() {
};

private final InstanceRepository repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected Mono<Instance> doUpdateStatus(Instance instance) {

/*
* return a timeout less than the given one to prevent backdrops in concurrent get
* request. This prevents flakyness of health checks.
* request. This prevents flakiness of health checks.
*/
private Duration getTimeoutWithMargin() {
return this.timeout.minusSeconds(1).abs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.Data;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,7 +51,7 @@ public class ProbeEndpointsStrategy implements EndpointDetectionStrategy {
public ProbeEndpointsStrategy(InstanceWebClient instanceWebClient, String[] endpoints) {
Assert.notNull(endpoints, "'endpoints' must not be null.");
Assert.noNullElements(endpoints, "'endpoints' must not contain null.");
this.endpoints = Arrays.stream(endpoints).map(EndpointDefinition::create).collect(Collectors.toList());
this.endpoints = Arrays.stream(endpoints).map(EndpointDefinition::create).toList();
this.instanceWebClient = instanceWebClient;
}

Expand Down Expand Up @@ -117,7 +116,7 @@ protected Mono<Endpoints> convert(List<DetectedEndpoint> endpoints) {
endpointList.get(0).getDefinition().getId(), endpointList.subList(1, endpointList.size()));
}
return endpointList.get(0).getEndpoint();
}).collect(Collectors.toList());
}).toList();
return Mono.just(Endpoints.of(result));
}

Expand Down
Loading
Loading