Search in sources :

Example 1 with IScalable

use of com.openshift.restclient.api.capabilities.IScalable in project jbosstools-openshift by jbosstools.

the class ScaleDeploymentHandler method scaleDeployment.

protected void scaleDeployment(ExecutionEvent event, String name, IReplicationController rc, int replicas) {
    if (replicas >= 0) {
        new Job(NLS.bind("Scaling {0} deployment to {1}...", name, replicas)) {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                try {
                    return rc.accept(new CapabilityVisitor<IScalable, IStatus>() {

                        @Override
                        public IStatus visit(IScalable capability) {
                            capability.scaleTo(replicas);
                            return Status.OK_STATUS;
                        }
                    }, new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, "Scaling is not supported for this resource"));
                } catch (Exception e) {
                    String message = NLS.bind("Unable to scale {0}", name);
                    OpenShiftUIActivator.getDefault().getLogger().logError(message, e);
                    return new Status(Status.ERROR, OpenShiftUIActivator.PLUGIN_ID, message, e);
                }
            }
        }.schedule();
    }
}
Also used : ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) Job(org.eclipse.core.runtime.jobs.Job) IScalable(com.openshift.restclient.api.capabilities.IScalable) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

IScalable (com.openshift.restclient.api.capabilities.IScalable)1 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 Job (org.eclipse.core.runtime.jobs.Job)1