public ExitCode run()

in genie-agent/src/main/java/com/netflix/genie/agent/cli/InfoCommand.java [65:213]


    public ExitCode run() {
        final StringBuilder messageBuilder = new StringBuilder();

        messageBuilder
            .append("Agent info:")
            .append(NEWLINE)
            .append("  version: ")
            .append(agentMetadata.getAgentVersion())
            .append(NEWLINE)
            .append("  host: ")
            .append(agentMetadata.getAgentHostName())
            .append(NEWLINE)
            .append("  pid: ")
            .append(agentMetadata.getAgentPid())
            .append(NEWLINE);

        messageBuilder
            .append("Active profiles:")
            .append(NEWLINE);

        for (String profileName : applicationContext.getEnvironment().getActiveProfiles()) {
            messageBuilder
                .append("  - ")
                .append(profileName)
                .append(NEWLINE);
        }

        messageBuilder
            .append("Default profiles:")
            .append(NEWLINE);

        for (String profileName : applicationContext.getEnvironment().getDefaultProfiles()) {
            messageBuilder
                .append("  - ")
                .append(profileName)
                .append(NEWLINE);
        }

        if (infoCommandArguments.getIncludeBeans()) {
            messageBuilder
                .append("Beans in context: ")
                .append(applicationContext.getBeanDefinitionCount())
                .append(NEWLINE);

            final String[] beanNames = applicationContext.getBeanDefinitionNames();
            for (String beanName : beanNames) {

                final BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(beanName);
                final String beanClass = beanDefinition.getBeanClassName();

                final String description = new StringBuilder()
                    .append(beanDefinition.isLazyInit() ? "lazy" : "eager")
                    .append(beanDefinition.isPrototype() ? ", prototype" : "")
                    .append(beanDefinition.isSingleton() ? ", singleton" : "")
                    .toString();

                messageBuilder
                    .append(
                        String.format(
                            "  - %s (%s) [%s]",
                            beanName,
                            beanClass == null ? "?" : beanClass,
                            description
                        )
                    )
                    .append(NEWLINE);
            }
        }

        if (infoCommandArguments.getIncludeEnvironment()) {

            final Set<Map.Entry<String, Object>> envEntries =
                applicationContext.getEnvironment().getSystemEnvironment().entrySet();

            messageBuilder
                .append("Environment variables: ")
                .append(envEntries.size())
                .append(NEWLINE);

            for (Map.Entry<String, Object> envEntry : envEntries) {
                messageBuilder
                    .append(
                        String.format(
                            "  - %s=%s",
                            envEntry.getKey(),
                            envEntry.getValue()
                        )
                    )
                    .append(NEWLINE);
            }
        }

        if (infoCommandArguments.getIncludeProperties()) {

            final Set<Map.Entry<String, Object>> properties =
                applicationContext.getEnvironment().getSystemProperties().entrySet();

            messageBuilder
                .append("Properties: ")
                .append(properties.size())
                .append(NEWLINE);
            for (Map.Entry<String, Object> property : properties) {
                messageBuilder
                    .append(
                        String.format(
                            "  - %s=%s",
                            property.getKey(),
                            property.getValue()
                        )
                    )
                    .append(NEWLINE);
            }

            final PropertySources propertySources = applicationContext.getEnvironment().getPropertySources();
            messageBuilder
                .append("Property sources: ")
                .append(NEWLINE);
            for (PropertySource<?> propertySource : propertySources) {
                messageBuilder
                    .append(
                        String.format(
                            "  - %s (%s)",
                            propertySource.getName(),
                            propertySource.getClass().getSimpleName()
                        )
                    )
                    .append(NEWLINE);
            }
        }

        if (infoCommandArguments.getIncludeStateMachine()) {
            messageBuilder
                .append("Job execution state machine: ")
                .append(NEWLINE)
                .append("// ------------------------------------------------------------------------")
                .append(NEWLINE);

            final JobExecutionStateMachine jobExecutionStateMachine
                = applicationContext.getBean(JobExecutionStateMachine.class);

            final List<ExecutionStage> stages = jobExecutionStateMachine.getExecutionStages();

            createStateMachineDotGraph(stages, messageBuilder);
        }

        System.out.println(messageBuilder);

        return ExitCode.SUCCESS;
    }