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

示例1
private static CloudApplication buildApplication(Staging staging) {
    return ImmutableCloudApplication.builder()
                                    .metadata(RawCloudEntityTest.EXPECTED_METADATA)
                                    .name(RawCloudEntityTest.NAME)
                                    .uris(EXPECTED_URIS)
                                    .memory(MEMORY)
                                    .diskQuota(DISK_QUOTA)
                                    .instances(INSTANCES)
                                    .runningInstances(RUNNING_INSTANCES)
                                    .state(EXPECTED_STATE)
                                    .packageState(EXPECTED_PACKAGE_STATE)
                                    .stagingError(STAGING_ERROR)
                                    .staging(staging)
                                    .services(EXPECTED_SERVICES)
                                    .env(EXPECTED_ENVIRONMENT)
                                    .space(SPACE)
                                    .build();
}
 
示例2
private boolean hasStagingChanged(Staging staging, Staging existingStaging) {
    List<String> buildpacks = staging.getBuildpacks();
    String command = staging.getCommand();
    String stack = staging.getStack();
    Integer healthCheckTimeout = staging.getHealthCheckTimeout();
    String healthCheckType = staging.getHealthCheckType();
    String healthCheckHttpEndpoint = staging.getHealthCheckHttpEndpoint();
    Boolean sshEnabled = staging.isSshEnabled();
    return (buildpacks != null && !buildpacks.equals(existingStaging.getBuildpacks()))
        || (command != null && !command.equals(existingStaging.getCommand()))
        || (stack != null && !stack.equals(existingStaging.getStack()))
        || (healthCheckTimeout != null && !healthCheckTimeout.equals(existingStaging.getHealthCheckTimeout()))
        || (healthCheckType != null && !healthCheckType.equals(existingStaging.getHealthCheckType()))
        || (healthCheckHttpEndpoint != null && !healthCheckHttpEndpoint.equals(existingStaging.getHealthCheckHttpEndpoint()))
        || (sshEnabled != null && !sshEnabled.equals(existingStaging.isSshEnabled())
            || isDockerInfoModified(existingStaging.getDockerInfo(), staging.getDockerInfo()));
}
 
示例3
@Override
public Staging parse(List<Map<String, Object>> parametersList) {
    String command = (String) getPropertyValue(parametersList, SupportedParameters.COMMAND, null);
    List<String> buildpacks = getPluralOrSingular(parametersList, SupportedParameters.BUILDPACKS, SupportedParameters.BUILDPACK);
    String stack = (String) getPropertyValue(parametersList, SupportedParameters.STACK, null);
    Integer healthCheckTimeout = (Integer) getPropertyValue(parametersList, SupportedParameters.HEALTH_CHECK_TIMEOUT, null);
    String healthCheckType = (String) getPropertyValue(parametersList, SupportedParameters.HEALTH_CHECK_TYPE, null);
    String healthCheckHttpEndpoint = (String) getPropertyValue(parametersList, SupportedParameters.HEALTH_CHECK_HTTP_ENDPOINT,
                                                               getDefaultHealthCheckHttpEndpoint(healthCheckType));
    Boolean isSshEnabled = (Boolean) getPropertyValue(parametersList, SupportedParameters.ENABLE_SSH, null);
    DockerInfo dockerInfo = new DockerInfoParser().parse(parametersList);
    return ImmutableStaging.builder()
                           .command(command)
                           .buildpacks(buildpacks)
                           .stack(stack)
                           .healthCheckTimeout(healthCheckTimeout)
                           .healthCheckType(healthCheckType)
                           .healthCheckHttpEndpoint(healthCheckHttpEndpoint)
                           .isSshEnabled(isSshEnabled)
                           .dockerInfo(dockerInfo)
                           .build();
}
 
示例4
private static Staging parseStaging(SummaryApplicationResponse summary, Derivable<CloudStack> stack) {
    return ImmutableStaging.builder()
                           .addBuildpack(summary.getBuildpack())
                           .command(summary.getCommand())
                           .detectedBuildpack(summary.getDetectedBuildpack())
                           .healthCheckHttpEndpoint(summary.getHealthCheckHttpEndpoint())
                           .healthCheckTimeout(summary.getHealthCheckTimeout())
                           .healthCheckType(summary.getHealthCheckType())
                           .isSshEnabled(summary.getEnableSsh())
                           .dockerInfo(parseDockerInfo(summary))
                           .stack(parseStackName(stack))
                           .build();
}
 
示例5
@Override
public void updateApplicationStaging(String applicationName, Staging staging) {
    UUID applicationGuid = getRequiredApplicationGuid(applicationName);
    UpdateApplicationRequest.Builder requestBuilder = UpdateApplicationRequest.builder();
    requestBuilder.applicationId(applicationGuid.toString());
    if (staging != null) {
        requestBuilder.buildpack(staging.getBuildpack())
                      .command(staging.getCommand())
                      .healthCheckHttpEndpoint(staging.getHealthCheckHttpEndpoint())
                      .healthCheckTimeout(staging.getHealthCheckTimeout())
                      .healthCheckType(staging.getHealthCheckType())
                      .enableSsh(staging.isSshEnabled());
        String stackName = staging.getStack();
        if (stackName != null) {
            UUID stackGuid = getStack(stackName).getMetadata()
                                                .getGuid();
            requestBuilder.stackId(stackGuid.toString());
        }
        if (staging.getDockerInfo() != null) {
            requestBuilder.dockerImage(staging.getDockerInfo()
                                              .getImage());
            DockerCredentials dockerCredentials = staging.getDockerInfo()
                                                         .getCredentials();
            if (dockerCredentials != null) {
                requestBuilder.dockerCredentials(org.cloudfoundry.client.v2.applications.DockerCredentials.builder()
                                                                                                          .username(dockerCredentials.getUsername())
                                                                                                          .password(dockerCredentials.getPassword())
                                                                                                          .build());
            }
        }
    }
    delegate.applicationsV2()
            .update(requestBuilder.build())
            .block();

    if (shouldUpdateWithV3Buildpacks(staging)) {
        updateBuildpacks(applicationGuid, staging.getBuildpacks());
    }
}
 
示例6
private static Staging buildStaging() {
    return ImmutableStaging.builder()
                           .buildpacks(Arrays.asList(BUILDPACK))
                           .command(COMMAND)
                           .detectedBuildpack(DETECTED_BUILDPACK)
                           .dockerInfo(DOCKER_INFO)
                           .healthCheckHttpEndpoint(HEALTH_CHECK_HTTP_ENDPOINT)
                           .healthCheckTimeout(HEALTH_CHECK_TIMEOUT)
                           .healthCheckType(HEALTH_CHECK_TYPE)
                           .isSshEnabled(SSH_ENABLED)
                           .stack(STACK_NAME)
                           .build();
}
 
示例7
@Override
public void createApplication(String applicationName, Staging staging, Integer disk, Integer memory, List<String> uris,
                              DockerInfo dockerInfo) {
    logger.debug(Messages.CREATING_APPLICATION_0_WITH_DISK_QUOTA_1_MEMORY_2_URIS_3_AND_STAGING_4, applicationName, disk, memory, uris,
                 SecureSerialization.toJson(staging));
    delegate.createApplication(applicationName, staging, disk, memory, uris, dockerInfo);
}
 
示例8
@Override
public void createApplication(String name, Staging staging, Integer memory, List<String> uris) {
    createApplication(name, staging, null, memory, uris, null);
}
 
示例9
@Override
public void createApplication(String name, Staging staging, Integer diskQuota, Integer memory, List<String> uris,
                              DockerInfo dockerInfo) {
    CreateApplicationRequest.Builder requestBuilder = CreateApplicationRequest.builder()
                                                                              .spaceId(getTargetSpaceGuid().toString())
                                                                              .name(name)
                                                                              .memory(memory)
                                                                              .diskQuota(diskQuota)
                                                                              .instances(1)
                                                                              .state(CloudApplication.State.STOPPED.toString());
    if (dockerInfo != null) {
        requestBuilder.dockerImage(dockerInfo.getImage());
        DockerCredentials dockerCredentials = dockerInfo.getCredentials();
        if (dockerCredentials != null) {
            requestBuilder.dockerCredentials(org.cloudfoundry.client.v2.applications.DockerCredentials.builder()
                                                                                                      .username(dockerCredentials.getUsername())
                                                                                                      .password(dockerCredentials.getPassword())
                                                                                                      .build());
        }
    }
    if (staging != null) {
        requestBuilder.buildpack(staging.getBuildpack())
                      .command(staging.getCommand())
                      .healthCheckHttpEndpoint(staging.getHealthCheckHttpEndpoint())
                      .healthCheckTimeout(staging.getHealthCheckTimeout())
                      .healthCheckType(staging.getHealthCheckType())
                      .enableSsh(staging.isSshEnabled());
        String stackName = staging.getStack();
        if (stackName != null) {
            CloudStack stack = getStack(stackName);
            UUID stackGuid = stack.getMetadata()
                                  .getGuid();
            requestBuilder.stackId(stackGuid.toString());
        }
    }

    CreateApplicationResponse response = delegate.applicationsV2()
                                                 .create(requestBuilder.build())
                                                 .block();
    UUID newAppGuid = UUID.fromString(response.getMetadata()
                                              .getId());

    if (shouldUpdateWithV3Buildpacks(staging)) {
        updateBuildpacks(newAppGuid, staging.getBuildpacks());
    }

    if (!CollectionUtils.isEmpty(uris)) {
        addUris(uris, newAppGuid);
    }
}
 
示例10
private boolean shouldUpdateWithV3Buildpacks(Staging staging) {
    return staging.getBuildpacks()
                  .size() > 1;
}
 
示例11
@Override
public void createApplication(String applicationName, Staging staging, Integer memory, List<String> uris) {
    handleExceptions(() -> delegate.createApplication(applicationName, staging, memory, uris));
}
 
示例12
@Override
public void createApplication(String applicationName, Staging staging, Integer disk, Integer memory, List<String> uris,
                              DockerInfo dockerInfo) {
    handleExceptions(() -> delegate.createApplication(applicationName, staging, disk, memory, uris, dockerInfo));
}
 
示例13
@Override
public void updateApplicationStaging(String applicationName, Staging staging) {
    handleExceptions(() -> delegate.updateApplicationStaging(applicationName, staging));
}
 
示例14
private static CloudApplication buildApplicationWithoutDockerInfo() {
    Staging staging = buildStaging();
    Staging stagingWithoutDockerInfo = ImmutableStaging.copyOf(staging)
                                                       .withDockerInfo(null);
    return buildApplication(stagingWithoutDockerInfo);
}
 
示例15
private static CloudApplication buildApplicationWithoutDockerCredentials() {
    Staging staging = buildStaging();
    Staging stagingWithoutDockerCredentials = ImmutableStaging.copyOf(staging)
                                                              .withDockerInfo(DOCKER_INFO_WITHOUT_CREDENTIALS);
    return buildApplication(stagingWithoutDockerCredentials);
}
 
示例16
@Override
public void createApplication(String applicationName, Staging staging, Integer memory, List<String> uris) {
    logger.debug(Messages.CREATING_APPLICATION_0_WITH_MEMORY_1_URIS_2_AND_STAGING_3, applicationName, memory, uris,
                 SecureSerialization.toJson(staging));
    delegate.createApplication(applicationName, staging, memory, uris);
}
 
示例17
@Override
public void updateApplicationStaging(String applicationName, Staging staging) {
    logger.debug(Messages.UPDATING_STAGING_OF_APPLICATION_0_TO_1, applicationName, SecureSerialization.toJson(staging));
    delegate.updateApplicationStaging(applicationName, staging);
}
 
示例18
@Override
protected boolean shouldUpdateAttribute(CloudApplication existingApplication, CloudApplication application) {
    Staging staging = application.getStaging();
    Staging existingStaging = existingApplication.getStaging();
    return hasStagingChanged(staging, existingStaging);
}
 
示例19
@Override
public void createApplication(String applicationName, Staging staging, Integer disk, Integer memory, List<String> uris,
                              DockerInfo dockerInfo) {
    executeWithRetry(() -> delegate.createApplication(applicationName, staging, disk, memory, uris, dockerInfo));
}
 
示例20
@Override
public void updateApplicationStaging(String applicationName, Staging staging) {
    executeWithRetry(() -> delegate.updateApplicationStaging(applicationName, staging));
}
 
示例21
@Override
public void createApplication(String applicationName, Staging staging, Integer memory, List<String> uris) {
    executeWithRetry(() -> delegate.createApplication(applicationName, staging, memory, uris));
}
 
示例22
/**
 * Create application.
 *
 * @param applicationName application name
 * @param staging staging info
 * @param memory memory to use in MB
 * @param uris list of URIs for the app
 * @param serviceInstanceNames list of service instance names to bind to app
 */
void createApplication(String applicationName, Staging staging, Integer memory, List<String> uris);
 
示例23
/**
 * Create application.
 *
 * @param applicationName application name
 * @param staging staging info
 * @param disk disk quota to use in MB
 * @param memory memory to use in MB
 * @param uris list of URIs for the app
 * @param serviceInstanceNames list of service instance names to bind to app
 * @param dockerInfo docker params(image, username, password)
 */
void createApplication(String applicationName, Staging staging, Integer disk, Integer memory, List<String> uris, DockerInfo dockerInfo);
 
示例24
/**
 * Update application staging information.
 *
 * @param applicationName name of appplication
 * @param staging staging information for the app
 */
void updateApplicationStaging(String applicationName, Staging staging);
 
示例25
void createApplication(String applicationName, Staging staging, Integer memory, List<String> uris); 
示例26
void createApplication(String applicationName, Staging staging, Integer disk, Integer memory, List<String> uris, DockerInfo dockerInfo); 
示例27
void updateApplicationStaging(String applicationName, Staging staging);