|
@@ -55,28 +55,16 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
|
|
|
protected static class ObservationInfo { Float value; OffsetDateTime time; }
|
|
protected static class ObservationInfo { Float value; OffsetDateTime time; }
|
|
|
|
|
|
|
|
private synchronized HttpCookie getAuthCookie() {
|
|
private synchronized HttpCookie getAuthCookie() {
|
|
|
- /*
|
|
|
|
|
- if (authCookie.getItem1()) {
|
|
|
|
|
- return authCookie.getItem2();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (config.getAuth() == null) {
|
|
|
|
|
- authCookie = Tuple.of(true, null);
|
|
|
|
|
- return authCookie.getItem2();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
HttpRequest request = HttpRequest.newBuilder().GET()
|
|
HttpRequest request = HttpRequest.newBuilder().GET()
|
|
|
.url(URLBuilder.newBuilder(config.getBaseUrl(), "/ControllerServlet")
|
|
.url(URLBuilder.newBuilder(config.getBaseUrl(), "/ControllerServlet")
|
|
|
.addParam("username", config.getAuth().getUsername())
|
|
.addParam("username", config.getAuth().getUsername())
|
|
|
.addParam("password", config.getAuth().getPassword())
|
|
.addParam("password", config.getAuth().getPassword())
|
|
|
.build()
|
|
.build()
|
|
|
).build();
|
|
).build();
|
|
|
- logger.info("Getting new auth cookie from the server: {}.", config.getBaseUrl());
|
|
|
|
|
|
|
+ logger.debug("Getting new auth cookie from the server: {}.", config.getBaseUrl());
|
|
|
|
|
|
|
|
HttpResponse response = httpClient.send(request);
|
|
HttpResponse response = httpClient.send(request);
|
|
|
- logger.info("Received new auth token with the status '{}' from the server {}.", response.getStatus(), config.getBaseUrl());
|
|
|
|
|
|
|
+ logger.info("Refreshed auth token with status: '{}'", response.getStatus());
|
|
|
|
|
|
|
|
if (response.isError()) {
|
|
if (response.isError()) {
|
|
|
logger.warn("Authorization failed. Error code {} with the reason '{}'.", response.getStatus(), response.getBody());
|
|
logger.warn("Authorization failed. Error code {} with the reason '{}'.", response.getStatus(), response.getBody());
|
|
@@ -111,10 +99,10 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
HttpRequest request = reqBuilder.addCookie(authCookie).build();
|
|
HttpRequest request = reqBuilder.addCookie(authCookie).build();
|
|
|
- logger.info("Getting new data from the server: {}.", request.getUrl());
|
|
|
|
|
|
|
+ logger.debug("Getting new data from the server: {}.", request.getUrl());
|
|
|
|
|
|
|
|
HttpResponse response = httpClient.send(request);
|
|
HttpResponse response = httpClient.send(request);
|
|
|
- logger.info("Received new data with the status '{}' from the server {}.", response.getStatus(), request.getUrl());
|
|
|
|
|
|
|
+ logger.debug("Received new data with the status '{}' from the server {}.", response.getStatus(), request.getUrl());
|
|
|
|
|
|
|
|
if (response.getStatus() == HttpCode.UNAUTHORIZED && authErrors.get() <= MAX_AUTH_ERRORS) {
|
|
if (response.getStatus() == HttpCode.UNAUTHORIZED && authErrors.get() <= MAX_AUTH_ERRORS) {
|
|
|
this.authCookie = Tuple.of(false, null);
|
|
this.authCookie = Tuple.of(false, null);
|
|
@@ -184,7 +172,9 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
|
|
|
public SenslogV1Model fetch(Optional<SensLogSession> persistenceSession) {
|
|
public SenslogV1Model fetch(Optional<SensLogSession> persistenceSession) {
|
|
|
HttpCookie authCookie = getAuthCookie();
|
|
HttpCookie authCookie = getAuthCookie();
|
|
|
|
|
|
|
|
|
|
+ // get 'now' time at the configured time zone (i.e., the 'timeZone' parameter in the config)
|
|
|
OffsetDateTime now = ZonedDateTime.ofInstant(Instant.now(), config.getTimeZone().toZoneId()).toOffsetDateTime();
|
|
OffsetDateTime now = ZonedDateTime.ofInstant(Instant.now(), config.getTimeZone().toZoneId()).toOffsetDateTime();
|
|
|
|
|
+ // get the 'startDate' at the configured time zone
|
|
|
OffsetDateTime startDate = ZonedDateTime.of(config.getStartDate(), config.getTimeZone().toZoneId()).toOffsetDateTime();
|
|
OffsetDateTime startDate = ZonedDateTime.of(config.getStartDate(), config.getTimeZone().toZoneId()).toOffsetDateTime();
|
|
|
|
|
|
|
|
SensLogSession session = persistenceSession.filter(ProxySessionModel::isActive).orElse(localSession);
|
|
SensLogSession session = persistenceSession.filter(ProxySessionModel::isActive).orElse(localSession);
|
|
@@ -204,7 +194,7 @@ public class SenslogFetcher implements ConnectorFetcher<SensLogSession, SenslogV
|
|
|
toDate = now;
|
|
toDate = now;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- logger.info("Getting new observations for the unit {} and the sensor {} from {} to {}.", unit.getUnitId(), sensor.getSensorId(), fromDate, toDate);
|
|
|
|
|
|
|
+ logger.info("Data request: unit <{}> | sensor <{}> | interval {} - {}.", unit.getUnitId(), sensor.getSensorId(), fromDate, toDate);
|
|
|
|
|
|
|
|
final DateTimeFormatter pattern = ofPattern("yyyy-MM-dd HH:mm:ssZ");
|
|
final DateTimeFormatter pattern = ofPattern("yyyy-MM-dd HH:mm:ssZ");
|
|
|
HttpRequest observationRequest = HttpRequest.newBuilder().GET()
|
|
HttpRequest observationRequest = HttpRequest.newBuilder().GET()
|