class UsageLoggingUtil {

    public void logClusterRequestedUsageEvent(@Nullable Cluster cluster) {
        if (cluster == null || cluster.getId() == null) {
            return;
        }
        Stack stack = cluster.getStack();
        if (stack == null) {
            return;
        }
        long timestamp = System.currentTimeMillis();
        // Datahub clusters will have datalake resource id set.
        User creator = stack.getCreator();
        String cloudPlatform = stack.getCloudPlatform();
        UsageProto.CDPEnvironmentsEnvironmentType.Value cloudPlatformEnum =
                UsageProto.CDPEnvironmentsEnvironmentType.Value.UNSET;
        if (cloudPlatform != null) {
            try {
                cloudPlatformEnum = UsageProto.CDPEnvironmentsEnvironmentType.Value.valueOf(cloudPlatform.toUpperCase());
            } catch (IllegalArgumentException e) {
                // Do not set the cloud platform.
            }
        }
        if (stack.getDatalakeResourceId() != null) {
            UsageProto.CDPDatahubClusterRequested.Builder protoBuilder =
                    UsageProto.CDPDatahubClusterRequested.newBuilder();
            protoBuilder.setClusterId(cluster.getId().toString());
            protoBuilder.setDatalakeCrn(stack.getDatalakeResourceId().toString());
            buildDatahubRequestedProto(cluster, stack, creator, cloudPlatformEnum, protoBuilder);
            usageReporter.cdpDatahubClusterRequested(timestamp, protoBuilder.build());
        } else {
            UsageProto.CDPDatalakeClusterRequested.Builder protoBuilder =
                    UsageProto.CDPDatalakeClusterRequested.newBuilder();
            protoBuilder.setDatalakeId(cluster.getId().toString());
            buildDatalakeRequestedProto(cluster, stack, creator, cloudPlatformEnum, protoBuilder);
            usageReporter.cdpDatalakeClusterRequested(timestamp, protoBuilder.build());
        }
    }

}