Java源码示例:org.cloudfoundry.client.lib.domain.InstanceInfo

示例1
@Override
public AsyncExecutionState execute(ProcessContext context) {
    String appToPoll = getAppToPoll(context).getName();
    CloudControllerClient client = context.getControllerClient();

    context.getStepLogger()
           .debug(Messages.CHECKING_APP_STATUS, appToPoll);

    // We're using the app object returned by the controller, because it includes the router port in its URIs, while the app model
    // we've built doesn't.
    CloudApplication app = client.getApplication(appToPoll);
    List<InstanceInfo> appInstances = getApplicationInstances(client, app);
    StartupStatus status = getStartupStatus(context, app, appInstances);
    ProcessLoggerProvider processLoggerProvider = context.getStepLogger()
                                                         .getProcessLoggerProvider();
    StepsUtil.saveAppLogs(context.getExecution(), client, recentLogsRetriever, app, LOGGER, processLoggerProvider);
    return checkStartupStatus(context, app, status);
}
 
示例2
private StartupStatus getStartupStatus(ProcessContext context, CloudApplication app, List<InstanceInfo> appInstances) {
    boolean failOnCrashed = context.getVariable(Variables.FAIL_ON_CRASHED);

    if (appInstances != null) {
        int expectedInstances = app.getInstances();
        long runningInstances = getInstanceCount(appInstances, InstanceState.RUNNING);
        long flappingInstances = getInstanceCount(appInstances, InstanceState.FLAPPING);
        long crashedInstances = getInstanceCount(appInstances, InstanceState.CRASHED);
        long startingInstances = getInstanceCount(appInstances, InstanceState.STARTING);

        String states = composeStatesMessage(appInstances);

        context.getStepLogger()
               .debug(Messages.APPLICATION_0_X_OF_Y_INSTANCES_RUNNING, app.getName(), runningInstances, expectedInstances, states);

        if (runningInstances == expectedInstances) {
            return StartupStatus.STARTED;
        }
        if (startingInstances > 0) {
            return StartupStatus.STARTING;
        }
        if (flappingInstances > 0) {
            return StartupStatus.FLAPPING;
        }
        if (crashedInstances > 0 && failOnCrashed) {
            return StartupStatus.CRASHED;
        }
    }

    return StartupStatus.STARTING;
}
 
示例3
private String composeStatesMessage(List<InstanceInfo> instances) {
    Map<String, Long> stateCounts;
    if (instances.isEmpty()) {
        stateCounts = MapUtil.asMap(InstanceState.STARTING.toString(), 0L);
    } else {
        stateCounts = instances.stream()
                               .collect(Collectors.groupingBy(instance -> instance.getState()
                                                                                  .toString(), Collectors.counting()));
    }
    return stateCounts.entrySet()
                      .stream()
                      .map(this::formatStateString)
                      .collect(Collectors.joining(","));
}
 
示例4
private InstancesInfo buildInstancesInfo(List<InstanceState> instancesStates) {
    List<InstanceInfo> instances = instancesStates.stream()
                                                  .map(this::buildInstanceInfo)
                                                  .collect(Collectors.toList());
    return ImmutableInstancesInfo.builder()
                                 .instances(instances)
                                 .build();
}
 
示例5
public static boolean isApplicationRunning(CloudFoundryClient client, String appName) {
    InstancesInfo infos = client.getApplicationInstances(appName);
    if (infos != null) {
        for (InstanceInfo info :infos.getInstances()) {
            if (info.getState() != InstanceState.RUNNING) {
                return false;
            }
        }
        // All instances are running
        return true;
    }         
    
    // No instance info - app not running
    return false;
}
 
示例6
private static List<InstanceInfo> parseInstancesMap(Map<String, ApplicationInstanceInfo> instances) {
    return instances.entrySet()
                    .stream()
                    .map(RawInstancesInfo::parseInstance)
                    .collect(Collectors.toList());
}
 
示例7
private static InstanceInfo parseInstance(Map.Entry<String, ApplicationInstanceInfo> instance) {
    return ImmutableInstanceInfo.builder()
                                .index(parseIndex(instance))
                                .state(parseState(instance))
                                .build();
}
 
示例8
private List<InstanceInfo> getApplicationInstances(CloudControllerClient client, CloudApplication app) {
    InstancesInfo instancesInfo = client.getApplicationInstances(app);
    return (instancesInfo != null) ? instancesInfo.getInstances() : null;
}
 
示例9
private long getInstanceCount(List<InstanceInfo> instances, InstanceState state) {
    return instances.stream()
                    .filter(instance -> instance.getState()
                                                .equals(state))
                    .count();
}
 
示例10
private InstanceInfo buildInstanceInfo(InstanceState state) {
    return ImmutableInstanceInfo.builder()
                                .index(0)
                                .state(state)
                                .build();
}