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

org.cloudfoundry.multiapps.controller.process.steps.PollServiceBindingUnbindingOperationBaseExecution Maven / Gradle / Ivy

There is a newer version: 1.183.0
Show newest version
package org.cloudfoundry.multiapps.controller.process.steps;

import java.util.List;
import java.util.function.Consumer;

import org.cloudfoundry.multiapps.controller.client.lib.domain.CloudServiceInstanceExtended;
import org.cloudfoundry.multiapps.controller.process.Messages;
import org.cloudfoundry.multiapps.controller.process.variables.Variables;

import com.sap.cloudfoundry.client.facade.domain.CloudApplication;
import com.sap.cloudfoundry.client.facade.domain.CloudAsyncJob;

public abstract class PollServiceBindingUnbindingOperationBaseExecution extends PollOperationBaseExecution {

    @Override
    protected boolean isOptional(ProcessContext context) {
        List servicesToBind = context.getVariable(Variables.SERVICES_TO_BIND);
        String serviceInstanceName = context.getVariable(Variables.SERVICE_TO_UNBIND_BIND);
        return StepsUtil.isServiceOptional(servicesToBind, serviceInstanceName);
    }

    @Override
    protected Consumer getInProgressHandler(ProcessContext context) {
        return serviceBindingJob -> context.getStepLogger()
                                           .debug(Messages.ASYNC_OPERATION_SERVICE_BINDING_IN_STATE_WITH_WARNINGS,
                                                  serviceBindingJob.getState(), serviceBindingJob.getWarnings());
    }

    @Override
    protected Consumer getOnCompleteHandler(ProcessContext context) {
        return serviceBindingJob -> context.getStepLogger()
                                           .debug(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FINISHED, serviceBindingJob.getGuid());
    }

    @Override
    protected Consumer getOnErrorHandler(ProcessContext context) {
        CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS);
        String serviceInstanceName = context.getVariable(Variables.SERVICE_TO_UNBIND_BIND);
        return serviceBindingJob -> context.getStepLogger()
                                           .error(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FAILED_WITH, app.getName(),
                                                  serviceInstanceName, serviceBindingJob.getErrors());
    }

    @Override
    protected Consumer getOnErrorHandlerForOptionalResource(ProcessContext context) {
        CloudApplication app = context.getVariable(Variables.APP_TO_PROCESS);
        String serviceInstanceName = context.getVariable(Variables.SERVICE_TO_UNBIND_BIND);
        return serviceBindingJob -> context.getStepLogger()
                                           .warnWithoutProgressMessage(Messages.ASYNC_OPERATION_FOR_SERVICE_BINDING_FOR_OPTIONAL_SERVICE_FAILED_WITH,
                                                                        app.getName(), serviceInstanceName, serviceBindingJob.getErrors());
    }

    @Override
    public String getPollingErrorMessage(ProcessContext context) {
        return Messages.ERROR_POLLING_ASYNC_SERVICE_BINDING;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy