Skip to content

Commit

Permalink
feat(imp):[#214] Move logging to business classes and remove some deb…
Browse files Browse the repository at this point in the history
…ug infos

Moved logging from helper class to business class because this way the log entry shows the business class and not the helper class.
  • Loading branch information
dsmf committed Feb 1, 2024
1 parent 5a02803 commit 806dedb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 81 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import lombok.extern.slf4j.Slf4j;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.tractusx.irs.common.util.concurrent.ResultFinder;
import org.eclipse.tractusx.irs.common.util.concurrent.StopwatchUtils;
import org.eclipse.tractusx.irs.component.assetadministrationshell.AssetAdministrationShellDescriptor;
import org.eclipse.tractusx.irs.component.assetadministrationshell.IdentifierKeyValuePair;
import org.eclipse.tractusx.irs.registryclient.DigitalTwinRegistryKey;
Expand Down Expand Up @@ -85,8 +84,9 @@ public Collection<AssetAdministrationShellDescriptor> fetchShells(final Collecti
throws RegistryServiceException {

final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch,
LOGPREFIX_TO_BE_REMOVED_LATER + "Fetching shell(s) for %s key(s)".formatted(keys.size()));
final String msg = LOGPREFIX_TO_BE_REMOVED_LATER + "Fetching shell(s) for %s key(s)".formatted(keys.size());
watch.start(msg);
log.info(msg);

try {
final var calledEndpoints = new HashSet<String>();
Expand Down Expand Up @@ -114,7 +114,8 @@ public Collection<AssetAdministrationShellDescriptor> fetchShells(final Collecti
}

} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand All @@ -141,8 +142,10 @@ private CompletableFuture<List<AssetAdministrationShellDescriptor>> fetchShellDe
final Set<String> calledEndpoints, final String bpn, final List<DigitalTwinRegistryKey> keys) {

final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch,
LOGPREFIX_TO_BE_REMOVED_LATER + "Fetching %s shells for bpn '%s'".formatted(keys.size(), bpn));
final String msg =
LOGPREFIX_TO_BE_REMOVED_LATER + "Fetching %s shells for bpn '%s'".formatted(keys.size(), bpn);
watch.start(msg);
log.info(msg);

try {
final var connectorEndpoints = connectorEndpointsService.fetchConnectorEndpoints(bpn);
Expand All @@ -154,7 +157,8 @@ private CompletableFuture<List<AssetAdministrationShellDescriptor>> fetchShellDe
return fetchShellDescriptorsForConnectorEndpoints(keys, connectorEndpoints);

} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand All @@ -181,13 +185,15 @@ private List<AssetAdministrationShellDescriptor> fetchShellDescriptorsForKey(
final var logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + " fetchShellDescriptorsForKey - ";

final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch,
logPrefix + "Fetching shell descriptors for keys %s from endpoint '%s'".formatted(keys,
endpointDataReference.getEndpoint()));
final String msg = logPrefix + "Fetching shell descriptors for keys %s from endpoint '%s'".formatted(keys,
endpointDataReference.getEndpoint());
watch.start(msg);
log.info(msg);
try {
return keys.stream().map(key -> fetchShellDescriptor(endpointDataReference, key)).toList();
} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand All @@ -197,14 +203,16 @@ private AssetAdministrationShellDescriptor fetchShellDescriptor(final EndpointDa
final var logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + " fetchShellDescriptor - ";

final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch,
logPrefix + "Retrieving AAS identification for DigitalTwinRegistryKey: '%s'".formatted(key));
final String msg = logPrefix + "Retrieving AAS identification for DigitalTwinRegistryKey: '%s'".formatted(key);
watch.start(msg);
log.info(msg);
try {
final String aaShellIdentification = mapToShellId(endpointDataReference, key.shellId());
return decentralDigitalTwinRegistryClient.getAssetAdministrationShellDescriptor(endpointDataReference,
aaShellIdentification);
} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand All @@ -223,8 +231,10 @@ private String mapToShellId(final EndpointDataReference endpointDataReference, f
final var logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + "mapToShellId - ";

final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch, logPrefix + "Mapping '%s' to shell ID for endpoint '%s'".formatted(key,
endpointDataReference.getEndpoint()));
final String msg = logPrefix + "Mapping '%s' to shell ID for endpoint '%s'".formatted(key,
endpointDataReference.getEndpoint());
watch.start(msg);
log.info(msg);

try {

Expand All @@ -248,7 +258,8 @@ private String mapToShellId(final EndpointDataReference endpointDataReference, f
return aaShellIdentification;

} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand Down Expand Up @@ -313,16 +324,19 @@ private Collection<String> lookupShellIds(final String bpn, final EndpointDataRe

final String logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + "lookupShellIds - ";
final var watch = new StopWatch();
StopwatchUtils.startWatch(log, watch,
final String msg =
logPrefix + "Looking up shell IDs for bpn '%s' with endpointDataReference '%s'".formatted(bpn,
endpointDataReference));
endpointDataReference);
watch.start(msg);
log.info(msg);

try {
return decentralDigitalTwinRegistryClient.getAllAssetAdministrationShellIdsByAssetLink(
endpointDataReference,
List.of(IdentifierKeyValuePair.builder().name("manufacturerId").value(bpn).build())).getResult();
} finally {
StopwatchUtils.stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import static java.util.concurrent.CompletableFuture.supplyAsync;
import static org.eclipse.tractusx.irs.common.util.concurrent.ResultFinder.LOGPREFIX_TO_BE_REMOVED_LATER;
import static org.eclipse.tractusx.irs.common.util.concurrent.StopwatchUtils.startWatch;
import static org.eclipse.tractusx.irs.common.util.concurrent.StopwatchUtils.stopWatch;

import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -54,19 +52,23 @@ public class EndpointDataForConnectorsService {
public List<CompletableFuture<EndpointDataReference>> createFindEndpointDataForConnectorsFutures(
final List<String> connectorEndpoints) {

final String logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + "createFindEndpointDataForConnectorsFutures - ";
final var watch = new StopWatch();
final String msg = "Creating futures to get EndpointDataReferences for endpoints: %s".formatted(
connectorEndpoints);
watch.start(msg);
log.info(msg);

List<CompletableFuture<EndpointDataReference>> futures = Collections.emptyList();
try {
log.info(logPrefix + "Creating futures to get EndpointDataReferences for endpoints: {}",
connectorEndpoints);
futures = connectorEndpoints.stream()
.map(connectorEndpoint -> supplyAsync(
() -> getEndpointReferenceForAsset(connectorEndpoint)))
.toList();
return futures;
} finally {
log.info(logPrefix + "Created {} futures", futures.size());
log.info("Created {} futures", futures.size());
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}
}

Expand All @@ -75,8 +77,10 @@ private EndpointDataReference getEndpointReferenceForAsset(final String connecto
final String logPrefix = LOGPREFIX_TO_BE_REMOVED_LATER + "getEndpointReferenceForAsset - ";

final var watch = new StopWatch();
startWatch(log, watch,
logPrefix + "Trying to retrieve EndpointDataReference for connector '%s'".formatted(connector));
final String msg =
logPrefix + "Trying to retrieve EndpointDataReference for connector '%s'".formatted(connector);
watch.start(msg);
log.info(msg);

try {
return edcSubmodelFacade.getEndpointReferenceForAsset(connector, DT_REGISTRY_ASSET_TYPE,
Expand All @@ -86,7 +90,8 @@ private EndpointDataReference getEndpointReferenceForAsset(final String connecto
connector, e);
throw new CompletionException(e.getMessage(), e);
} finally {
stopWatch(log, watch);
watch.stop();
log.info("{} took {} ms", watch.getLastTaskName(), watch.getLastTaskTimeMillis());
}

}
Expand Down

0 comments on commit 806dedb

Please sign in to comment.