All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pivotal.services.plugin.tasks.helper.CfAutoPilotDelegate Maven / Gradle / Ivy

There is a newer version: 2.3.0-rc.6
Show newest version
package io.pivotal.services.plugin.tasks.helper;

import io.pivotal.services.plugin.CfProperties;
import io.pivotal.services.plugin.ImmutableCfProperties;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.cloudfoundry.operations.applications.ApplicationDetail;
import org.gradle.api.Project;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import reactor.core.publisher.Mono;

import java.util.Optional;

/**
 * Responsible for handling Autopilot flow.
 */
public class CfAutoPilotDelegate {
    private CfPushDelegate pushDelegate = new CfPushDelegate();
    private CfRenameAppDelegate renameAppDelegate = new CfRenameAppDelegate();
    private CfDeleteAppDelegate deleteDelegate = new CfDeleteAppDelegate();
    private CfAppDetailsDelegate detailsDelegate = new CfAppDetailsDelegate();

    private static final Logger LOGGER = Logging.getLogger(CfAutoPilotDelegate.class);

    public Mono runAutopilot(Project project, CloudFoundryOperations cfOperations,
                                   CfProperties cfProperties) {
        LOGGER.lifecycle("Running Autopilot on App: {}", cfProperties.name());
        CfProperties withNameChanged = ImmutableCfProperties.copyOf(cfProperties)
            .withName(cfProperties.name() + "-venerable");

        Mono> appDetailMono = detailsDelegate
            .getAppDetails(cfOperations, cfProperties);

        Mono autopilotResult = appDetailMono.flatMap(appDetailOpt -> {
            if (appDetailOpt.isPresent()) {
                ApplicationDetail appDetail = appDetailOpt.get();
                CfProperties withExistingDetails = ImmutableCfProperties
                    .copyOf(cfProperties).withInstances(appDetail.getInstances())
                    .withMemory(appDetail.getMemoryLimit())
                    .withDiskQuota(appDetail.getDiskQuota());
                Mono renameResult = renameAppDelegate
                    .renameApp(cfOperations, cfProperties, withNameChanged);
                return renameResult
                    .then(pushDelegate.push(cfOperations, withExistingDetails))
                    .then(deleteDelegate.deleteApp(cfOperations, withNameChanged));
            } else {
                return pushDelegate.push(cfOperations, cfProperties);
            }
        });

        return autopilotResult;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy