Skip to content

Commit

Permalink
Log Payload also impacts C8YAgent
Browse files Browse the repository at this point in the history
  • Loading branch information
switschel committed Oct 23, 2024
1 parent 6fb465a commit 5eb1318
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import com.cumulocity.sdk.client.measurement.MeasurementApi;
import com.fasterxml.jackson.core.JsonProcessingException;
import dynamic.mapping.App;
import dynamic.mapping.configuration.ServiceConfiguration;
import dynamic.mapping.configuration.TrustedCertificateCollectionRepresentation;
import dynamic.mapping.configuration.TrustedCertificateRepresentation;
import dynamic.mapping.connector.core.client.AConnectorClient;
Expand Down Expand Up @@ -392,6 +393,7 @@ public AbstractExtensibleRepresentation createMEAO(ProcessingContext<?> context)
StringBuffer error = new StringBuffer("");
C8YRequest currentRequest = context.getCurrentRequest();
String payload = currentRequest.getRequest();
ServiceConfiguration serviceConfiguration = configurationRegistry.getServiceConfigurations().get(tenant);
API targetAPI = context.getMapping().getTargetAPI();
AbstractExtensibleRepresentation result = subscriptionsService.callForTenant(tenant, () -> {
MicroserviceCredentials contextCredentials = removeAppKeyHeaderFromContext(contextService.getContext());
Expand All @@ -403,18 +405,27 @@ public AbstractExtensibleRepresentation createMEAO(ProcessingContext<?> context)
payload,
EventRepresentation.class);
rt = eventApi.create(eventRepresentation);
log.info("Tenant {} - New event posted: {}", tenant, rt);
if(serviceConfiguration.logPayload )
log.info("Tenant {} - New event posted: {}", tenant, rt);
else
log.info("Tenant {} - New event posted with Id {}", tenant, ((EventRepresentation)rt).getId().getValue());
} else if (targetAPI.equals(API.ALARM)) {
AlarmRepresentation alarmRepresentation = configurationRegistry.getObjectMapper().readValue(
payload,
AlarmRepresentation.class);
rt = alarmApi.create(alarmRepresentation);
log.info("Tenant {} - New alarm posted: {}", tenant, rt);
if(serviceConfiguration.logPayload )
log.info("Tenant {} - New alarm posted: {}", tenant, rt);
else
log.info("Tenant {} - New alarm posted with Id {}", tenant, ((AlarmRepresentation)rt).getId().getValue());
} else if (targetAPI.equals(API.MEASUREMENT)) {
MeasurementRepresentation measurementRepresentation = jsonParser
.parse(MeasurementRepresentation.class, payload);
rt = measurementApi.create(measurementRepresentation);
log.info("Tenant {} - New measurement posted: {}", tenant, rt);
if(serviceConfiguration.logPayload )
log.info("Tenant {} - New measurement posted: {}", tenant, rt);
else
log.info("Tenant {} - New measurement posted with Id {}", tenant, ((MeasurementRepresentation) rt).getId().getValue());
} else if (targetAPI.equals(API.OPERATION)) {
OperationRepresentation operationRepresentation = jsonParser
.parse(OperationRepresentation.class, payload);
Expand Down Expand Up @@ -443,6 +454,7 @@ public ManagedObjectRepresentation upsertDevice(String tenant, ID identity, Proc
throws ProcessingException {
StringBuffer error = new StringBuffer("");
C8YRequest currentRequest = context.getCurrentRequest();
ServiceConfiguration serviceConfiguration = configurationRegistry.getServiceConfigurations().get(tenant);
ManagedObjectRepresentation device = subscriptionsService.callForTenant(tenant, () -> {
MicroserviceCredentials contextCredentials = removeAppKeyHeaderFromContext(contextService.getContext());
return contextService.callWithinContext(contextCredentials, () -> {
Expand Down Expand Up @@ -471,14 +483,19 @@ public ManagedObjectRepresentation upsertDevice(String tenant, ID identity, Proc

mor = inventoryApi.create(mor, context);
//TODO Add/Update new managed object to IdentityCache
log.info("Tenant {} - New device created: {}", tenant, mor);
if(serviceConfiguration.logPayload)
log.info("Tenant {} - New device created: {}", tenant, mor);
else
log.info("Tenant {} - New device created with Id {}", tenant, mor.getId().getValue());
identityApi.create(mor, identity, context);
} else {
// Device exists - update needed
mor.setId(extId.getManagedObject().getId());
mor = inventoryApi.update(mor, context);

log.info("Tenant {} - Device updated: {}", tenant, mor);
if(serviceConfiguration.logPayload)
log.info("Tenant {} - Device updated: {}", tenant, mor);
else
log.info("Tenant {} - Device {} updated.", tenant, mor.getId().getValue());
}
} catch (SDKException s) {
log.error("Tenant {} - Could not sent payload to c8y: {}: ", tenant, currentRequest.getRequest(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public ProcessingContext<T> substituteInTargetAndSend(ProcessingContext<T> conte
log.error("Tenant {} - Error waiting for result of Processing context", tenant, e);
}
}
log.info("Tenant {} - Context is completed, {} parallel requests processed!", tenant, j);
log.debug("Tenant {} - Context is completed, {} parallel requests processed!", tenant, j);
return context;
}

Expand Down

0 comments on commit 5eb1318

Please sign in to comment.