Search in sources :

Example 16 with IReplicationController

use of com.openshift.restclient.model.IReplicationController in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
    // given
    List<ObservableTreeItem> resourceItems = new ArrayList<>(model.getResourceItems());
    Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
    IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
    when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
    IReplicationController replicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
    when(project.getResources(ResourceKind.REPLICATION_CONTROLLER)).thenReturn(Collections.singletonList(replicationController));
    // when
    model.loadResources(connection);
    // then
    List<ObservableTreeItem> newResourceItems = model.getResourceItems();
    assertThat(newResourceItems).isNotEqualTo(resourceItems);
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 17 with IReplicationController

use of com.openshift.restclient.model.IReplicationController in project jbosstools-openshift by jbosstools.

the class NewPodDetectorJob method getOldPods.

private Collection<String> getOldPods(IReplicationController rc) {
    Connection connection = ConnectionsRegistryUtil.getConnectionFor(rc);
    List<IPod> allPods = connection.getResources(ResourceKind.POD, rc.getNamespaceName());
    return ResourceUtils.getPodsFor(rc, allPods).stream().filter(pod -> ResourceUtils.isRuntimePod(pod)).map(p -> p.getName()).collect(Collectors.toList());
}
Also used : ResourceKind(com.openshift.restclient.ResourceKind) Job(org.eclipse.core.runtime.jobs.Job) Collection(java.util.Collection) Status(org.eclipse.core.runtime.Status) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Collectors(java.util.stream.Collectors) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IPod(com.openshift.restclient.model.IPod) List(java.util.List) IStatus(org.eclipse.core.runtime.IStatus) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ConnectionsRegistryAdapter(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter) ConnectionsRegistrySingleton(org.jboss.tools.openshift.common.core.connection.ConnectionsRegistrySingleton) IConnectionsRegistryListener(org.jboss.tools.openshift.common.core.connection.IConnectionsRegistryListener) Collections(java.util.Collections) IReplicationController(com.openshift.restclient.model.IReplicationController) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IPod(com.openshift.restclient.model.IPod)

Example 18 with IReplicationController

use of com.openshift.restclient.model.IReplicationController in project jbosstools-openshift by jbosstools.

the class ServerAdapterHandler method getOpenShiftServer.

/**
 * Finds the OpenShift server corresponding to the selection or prompts the
 * user to create one.
 *
 * @param resource
 *            the selected OpenShift {@link IResource}
 *
 * @return the matching OpenShift {@link IServer} or <code>null</code> if
 *         none was found or user cancelled the creation operation.
 */
private IServer getOpenShiftServer(final IResource resource) {
    if (resource == null) {
        return null;
    }
    IResource source = null;
    IRoute route = null;
    if (resource instanceof IService) {
        source = (IService) resource;
    } else if (resource instanceof IRoute) {
        route = (IRoute) resource;
        final IRoute localRoute = route;
        source = (IService) route.getProject().getResources(ResourceKind.SERVICE).stream().filter(s -> ResourceUtils.areRelated(localRoute, (IService) s)).findFirst().orElseGet(() -> null);
    } else if (resource instanceof IReplicationController) {
        source = resource;
    } else if (resource instanceof IPod) {
        final Collection<IService> services = ResourceUtils.getServicesFor((IPod) resource, resource.getProject().getResources(ResourceKind.SERVICE));
        if (!services.isEmpty()) {
            source = services.iterator().next();
        } else {
            source = ResourceUtils.getDeploymentConfigOrReplicationControllerFor((IPod) resource);
        }
    }
    if (source != null) {
        final Connection connection = ConnectionsRegistryUtil.safeGetConnectionFor(source);
        return openOrCreateServerAdapter(source, route, connection);
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ServerSettingsWizard(org.jboss.tools.openshift.internal.ui.server.ServerSettingsWizard) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) OpenShiftResourceUniqueId(org.jboss.tools.openshift.core.util.OpenShiftResourceUniqueId) CoreException(org.eclipse.core.runtime.CoreException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) IPod(com.openshift.restclient.model.IPod) UIUtils(org.jboss.tools.openshift.internal.common.ui.utils.UIUtils) PartInitException(org.eclipse.ui.PartInitException) CommonNavigator(org.eclipse.ui.navigator.CommonNavigator) OpenShiftUIActivator(org.jboss.tools.openshift.internal.ui.OpenShiftUIActivator) IService(com.openshift.restclient.model.IService) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) Collection(java.util.Collection) IServer(org.eclipse.wst.server.core.IServer) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) ExecutionException(org.eclipse.core.commands.ExecutionException) Display(org.eclipse.swt.widgets.Display) Connection(org.jboss.tools.openshift.core.connection.Connection) WizardUtils(org.jboss.tools.common.ui.WizardUtils) IRoute(com.openshift.restclient.model.route.IRoute) ConnectionsRegistryUtil(org.jboss.tools.openshift.core.connection.ConnectionsRegistryUtil) ISelection(org.eclipse.jface.viewers.ISelection) AbstractHandler(org.eclipse.core.commands.AbstractHandler) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IReplicationController(com.openshift.restclient.model.IReplicationController) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) Collection(java.util.Collection) IResource(com.openshift.restclient.model.IResource) IService(com.openshift.restclient.model.IService) IReplicationController(com.openshift.restclient.model.IReplicationController) IPod(com.openshift.restclient.model.IPod)

Example 19 with IReplicationController

use of com.openshift.restclient.model.IReplicationController in project jbosstools-openshift by jbosstools.

the class EditResourceLimitsHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IResource resource = UIUtils.getFirstElement(UIUtils.getCurrentSelection(event), IResource.class);
    RetrieveDCOrRCJob job = new RetrieveDCOrRCJob(resource);
    new JobChainBuilder(job).runWhenSuccessfullyDone(new UIJob("Launching Edit Resource Limits Wizard...") {

        @Override
        public IStatus runInUIThread(IProgressMonitor monitor) {
            IReplicationController dcOrRc = job.getDeplConfigOrReplController();
            if (dcOrRc == null) {
                return Status.CANCEL_STATUS;
            }
            editResources(HandlerUtil.getActiveShell(event), dcOrRc, dcOrRc.getName());
            return Status.OK_STATUS;
        }
    }).schedule();
    return null;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) UIJob(org.eclipse.ui.progress.UIJob) IResource(com.openshift.restclient.model.IResource) JobChainBuilder(org.jboss.tools.openshift.internal.common.core.job.JobChainBuilder) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 20 with IReplicationController

use of com.openshift.restclient.model.IReplicationController in project jbosstools-openshift by jbosstools.

the class ManageEnvironmentVariablesWizard method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IReplicationController rc = findReplicationController(event);
    if (rc != null) {
        ManageEnvironmentVariablesWizard wizard = new ManageEnvironmentVariablesWizard(rc);
        WizardUtils.openWizardDialog(wizard, HandlerUtil.getActiveShell(event));
    }
    return null;
}
Also used : IReplicationController(com.openshift.restclient.model.IReplicationController)

Aggregations

IReplicationController (com.openshift.restclient.model.IReplicationController)21 IResource (com.openshift.restclient.model.IResource)9 Connection (org.jboss.tools.openshift.core.connection.Connection)7 Test (org.junit.Test)7 IPod (com.openshift.restclient.model.IPod)6 ResourceKind (com.openshift.restclient.ResourceKind)5 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)5 IService (com.openshift.restclient.model.IService)5 List (java.util.List)5 Collection (java.util.Collection)4 HashMap (java.util.HashMap)4 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)4 IProject (com.openshift.restclient.model.IProject)3 IRoute (com.openshift.restclient.model.route.IRoute)3 Collections (java.util.Collections)3 Map (java.util.Map)3 CoreException (org.eclipse.core.runtime.CoreException)3 CapabilityVisitor (com.openshift.restclient.capability.CapabilityVisitor)2 ITags (com.openshift.restclient.capability.resources.ITags)2 IBuild (com.openshift.restclient.model.IBuild)2