private void instanceToRow()

in athena-aws-cmdb/src/main/java/com/amazonaws/athena/connectors/aws/cmdb/tables/ec2/Ec2TableProvider.java [135:231]


    private void instanceToRow(Instance instance,
            BlockSpiller spiller)
    {
        spiller.writeRows((Block block, int row) -> {
            boolean matched = true;

            matched &= block.offerValue("instance_id", row, instance.getInstanceId());
            matched &= block.offerValue("image_id", row, instance.getImageId());
            matched &= block.offerValue("instance_type", row, instance.getInstanceType());
            matched &= block.offerValue("platform", row, instance.getPlatform());
            matched &= block.offerValue("private_dns_name", row, instance.getPrivateDnsName());
            matched &= block.offerValue("private_ip_address", row, instance.getPrivateIpAddress());
            matched &= block.offerValue("public_dns_name", row, instance.getPublicDnsName());
            matched &= block.offerValue("public_ip_address", row, instance.getPublicIpAddress());
            matched &= block.offerValue("subnet_id", row, instance.getSubnetId());
            matched &= block.offerValue("vpc_id", row, instance.getVpcId());
            matched &= block.offerValue("architecture", row, instance.getArchitecture());
            matched &= block.offerValue("instance_lifecycle", row, instance.getInstanceLifecycle());
            matched &= block.offerValue("root_device_name", row, instance.getRootDeviceName());
            matched &= block.offerValue("root_device_type", row, instance.getRootDeviceType());
            matched &= block.offerValue("spot_instance_request_id", row, instance.getSpotInstanceRequestId());
            matched &= block.offerValue("virtualization_type", row, instance.getVirtualizationType());
            matched &= block.offerValue("key_name", row, instance.getKeyName());
            matched &= block.offerValue("kernel_id", row, instance.getKernelId());
            matched &= block.offerValue("capacity_reservation_id", row, instance.getCapacityReservationId());
            matched &= block.offerValue("launch_time", row, instance.getLaunchTime());

            matched &= block.offerComplexValue("state",
                    row,
                    (Field field, Object val) -> {
                        if (field.getName().equals("name")) {
                            return ((InstanceState) val).getName();
                        }
                        else if (field.getName().equals("code")) {
                            return ((InstanceState) val).getCode();
                        }
                        throw new RuntimeException("Unknown field " + field.getName());
                    }, instance.getState());

            matched &= block.offerComplexValue("network_interfaces",
                    row,
                    (Field field, Object val) -> {
                        if (field.getName().equals("status")) {
                            return ((InstanceNetworkInterface) val).getStatus();
                        }
                        else if (field.getName().equals("subnet")) {
                            return ((InstanceNetworkInterface) val).getSubnetId();
                        }
                        else if (field.getName().equals("vpc")) {
                            return ((InstanceNetworkInterface) val).getVpcId();
                        }
                        else if (field.getName().equals("mac")) {
                            return ((InstanceNetworkInterface) val).getMacAddress();
                        }
                        else if (field.getName().equals("private_dns")) {
                            return ((InstanceNetworkInterface) val).getPrivateDnsName();
                        }
                        else if (field.getName().equals("private_ip")) {
                            return ((InstanceNetworkInterface) val).getPrivateIpAddress();
                        }
                        else if (field.getName().equals("security_groups")) {
                            return ((InstanceNetworkInterface) val).getGroups().stream().map(next -> next.getGroupName() + ":" + next.getGroupId()).collect(Collectors.toList());
                        }
                        else if (field.getName().equals("interface_id")) {
                            return ((InstanceNetworkInterface) val).getNetworkInterfaceId();
                        }

                        throw new RuntimeException("Unknown field " + field.getName());
                    }, instance.getNetworkInterfaces());

            matched &= block.offerComplexValue("state_reason", row, (Field field, Object val) -> {
                if (field.getName().equals("message")) {
                    return ((StateReason) val).getMessage();
                }
                else if (field.getName().equals("code")) {
                    return ((StateReason) val).getCode();
                }
                throw new RuntimeException("Unknown field " + field.getName());
            }, instance.getStateReason());

            matched &= block.offerValue("ebs_optimized", row, instance.getEbsOptimized());

            List<String> securityGroups = instance.getSecurityGroups().stream()
                    .map(next -> next.getGroupId()).collect(Collectors.toList());
            matched &= block.offerComplexValue("security_groups", row, FieldResolver.DEFAULT, securityGroups);

            List<String> securityGroupNames = instance.getSecurityGroups().stream()
                    .map(next -> next.getGroupName()).collect(Collectors.toList());
            matched &= block.offerComplexValue("security_group_names", row, FieldResolver.DEFAULT, securityGroupNames);

            List<String> ebsVolumes = instance.getBlockDeviceMappings().stream()
                    .map(next -> next.getEbs().getVolumeId()).collect(Collectors.toList());
            matched &= block.offerComplexValue("ebs_volumes", row, FieldResolver.DEFAULT, ebsVolumes);

            return matched ? 1 : 0;
        });
    }