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

io.pivotal.services.plugin.tasks.CfRenameAppTask Maven / Gradle / Ivy

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

import io.pivotal.services.plugin.CfProperties;
import io.pivotal.services.plugin.ImmutableCfProperties;
import io.pivotal.services.plugin.tasks.helper.CfRenameAppDelegate;
import org.cloudfoundry.operations.CloudFoundryOperations;
import org.gradle.api.tasks.TaskAction;
import reactor.core.publisher.Mono;

import java.time.Duration;

/**
 * Responsible for handling renaming an app.
 *
 * @author Biju Kunjummen
 */
public class CfRenameAppTask extends AbstractCfTask {

    private CfRenameAppDelegate renameDelegate = new CfRenameAppDelegate();

    @TaskAction
    public void renameApp() {
        CloudFoundryOperations cfOperations = getCfOperations();
        CfProperties cfAppProperties = getCfProperties();

        if (getNewName() == null) {
            throw new RuntimeException("New name not provided");
        }

        CfProperties oldCfProperties = cfAppProperties;

        CfProperties newCfProperties = ImmutableCfProperties.copyOf(oldCfProperties).withName(getNewName());

        Mono resp = renameDelegate.renameApp(cfOperations, oldCfProperties, newCfProperties);

        resp.block(Duration.ofMillis(defaultWaitTimeout));
    }

    private String getNewName() {
        return this.cfPropertiesMapper.getNewName();
    }


    @Override
    public String getDescription() {
        return "Rename an Application";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy