Search in sources :

Example 76 with IResource

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

the class ServerResourceViewModelWithServiceTest method shouldReturnNullServiceIfNoConnectionIsSet.

@Test
public void shouldReturnNullServiceIfNoConnectionIsSet() {
    // given
    ServerResourceViewModel model = new ServerResourceViewModel(null);
    model.loadResources();
    // when
    IResource resource = model.getResource();
    // then
    assertThat(resource).isNull();
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 77 with IResource

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

the class ServerResourceViewModelWithDeploymentConfigTest method shouldReturnNullResourceIfResourcesNotLoaded.

@Test
public void shouldReturnNullResourceIfResourcesNotLoaded() {
    // given
    ServerResourceViewModel model = new ServerResourceViewModel(null);
    // when
    IResource resource = model.getResource();
    // then
    assertThat(resource).isNull();
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 78 with IResource

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

the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnResourceIfResourcesAreLoaded.

@Test
public void shouldReturnResourceIfResourcesAreLoaded() {
    // given
    model.loadResources();
    // when
    IResource resource = model.getResource();
    // then
    assertThat(resource).isEqualTo(selectedReplicationController);
}
Also used : IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

Example 79 with IResource

use of com.openshift.restclient.model.IResource 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 80 with IResource

use of com.openshift.restclient.model.IResource 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

IResource (com.openshift.restclient.model.IResource)101 Test (org.junit.Test)32 Connection (org.jboss.tools.openshift.core.connection.Connection)27 IProject (com.openshift.restclient.model.IProject)14 IStatus (org.eclipse.core.runtime.IStatus)12 Collection (java.util.Collection)10 ServerResourceViewModel (org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel)9 IReplicationController (com.openshift.restclient.model.IReplicationController)8 IService (com.openshift.restclient.model.IService)8 ArrayList (java.util.ArrayList)8 CoreException (org.eclipse.core.runtime.CoreException)8 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)7 Status (org.eclipse.core.runtime.Status)7 ISelection (org.eclipse.jface.viewers.ISelection)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IPod (com.openshift.restclient.model.IPod)6 List (java.util.List)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IBuildConfig (com.openshift.restclient.model.IBuildConfig)5