Search in sources :

Example 86 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithReplicationControllerTest method shouldLoadResourcesWhenToldTo.

@Test
public void shouldLoadResourcesWhenToldTo() {
    // given
    Connection connection = ResourceMocks.createConnection("http://10.1.2.2:8443", "dev@paas.redhat.com");
    ServerResourceViewModel model = new ServerResourceViewModel(connection);
    model.loadResources();
    // when
    // then
    verify(connection, atLeastOnce()).getResources(any());
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 87 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class ServerResourceViewModelWithServiceTest method shouldNotLoadResourcesBeforeBeingToldTo.

@Test
public void shouldNotLoadResourcesBeforeBeingToldTo() {
    // given
    Connection connection = ResourceMocks.createConnection("http://10.1.2.2:8443", "dev@paas.redhat.com");
    new ServerResourceViewModel(connection);
    // when
    // then
    verify(connection, never()).getResources(any());
    verify(connection, never()).getResources(any(), any());
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Example 88 with Connection

use of org.jboss.tools.openshift.core.connection.Connection 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 89 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class OpenShiftDebugMode method execute.

/**
 * Sends the changes to the deployment config if required. Nothing is done if
 * the deployment config already is in the state that the context is in. If the
 * changes are sent the existing pods are killed and it waits until the new pods
 * are running.
 *
 * @param context
 * @param monitor
 * @throws CoreException
 */
public OpenShiftDebugMode execute(IProgressMonitor monitor) throws CoreException {
    Connection connection = OpenShiftServerUtils.getConnection(context.getServer());
    IResource resource = OpenShiftServerUtils.getResource(context.getServer(), monitor);
    IDeploymentConfig dc = getDeploymentConfig(resource, connection, monitor);
    if (dc == null) {
        throw new CoreException(OpenShiftCoreActivator.statusFactory().errorStatus(NLS.bind("Could not find deployment config for resource {0}. " + "Your build might be still running and pods not created yet or " + "there might be no labels on your pods pointing to the wanted deployment config.", resource != null ? resource.getName() : "")));
    }
    boolean dcUpdated = updateDc(dc, connection, monitor);
    IPod pod = getPod(dcUpdated, dc, connection, monitor);
    context.setPod(pod);
    toggleRouteTimeout(resource, connection, context, monitor);
    toggleDebugger(context, monitor);
    return this;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) Connection(org.jboss.tools.openshift.core.connection.Connection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IResource(com.openshift.restclient.model.IResource) IPod(com.openshift.restclient.model.IPod)

Example 90 with Connection

use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.

the class RouteTimeout method getRoute.

private IRoute getRoute(IResource resource, Connection connection, IProgressMonitor monitor) {
    SubMonitor routeMonitor = SubMonitor.convert(monitor);
    routeMonitor.beginTask("Determine route to set the haproxy timeout for...", 2);
    if (routeMonitor.isCanceled()) {
        return null;
    }
    List<IService> services = connection.getResources(ResourceKind.SERVICE, resource.getNamespaceName());
    Collection<IService> matchingServices = ResourceUtils.getServicesFor(resource, services);
    routeMonitor.worked(1);
    if (routeMonitor.isCanceled()) {
        return null;
    }
    List<IRoute> routes = connection.getResources(ResourceKind.ROUTE, resource.getNamespaceName());
    // TODO: support multiple matching routes, for now only get first
    Optional<IRoute> matchingRoute = matchingServices.stream().flatMap(service -> ResourceUtils.getRoutesFor(service, routes).stream()).findFirst();
    routeMonitor.worked(1);
    routeMonitor.done();
    return matchingRoute.orElse(null);
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) IResource(com.openshift.restclient.model.IResource) ResourceKind(com.openshift.restclient.ResourceKind) NLS(org.eclipse.osgi.util.NLS) SubMonitor(org.eclipse.core.runtime.SubMonitor) Collection(java.util.Collection) OpenShiftServerUtils(org.jboss.tools.openshift.core.server.OpenShiftServerUtils) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) CoreException(org.eclipse.core.runtime.CoreException) OpenShiftCoreActivator(org.jboss.tools.openshift.internal.core.OpenShiftCoreActivator) Connection(org.jboss.tools.openshift.core.connection.Connection) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) IRoute(com.openshift.restclient.model.route.IRoute) Optional(java.util.Optional) IService(com.openshift.restclient.model.IService) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRoute(com.openshift.restclient.model.route.IRoute) IService(com.openshift.restclient.model.IService)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6