Search in sources :

Example 11 with IReplicationController

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

the class ResourceUtilsTest method shouldSelectLatestReplicationControllerGiven4Versions.

@Test
public void shouldSelectLatestReplicationControllerGiven4Versions() {
    // given
    List<IReplicationController> noRcs = Arrays.asList(ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, rc -> {
        doReturn("4").when(rc).getAnnotation(OpenShiftAPIAnnotations.DEPLOYMENT_CONFIG_LATEST_VERSION);
        doReturn("4").when(rc).getName();
    }), ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, rc -> {
        doReturn("-1").when(rc).getAnnotation(OpenShiftAPIAnnotations.DEPLOYMENT_CONFIG_LATEST_VERSION);
        doReturn("-1").when(rc).getName();
    }), ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, rc -> {
        doReturn("4").when(rc).getAnnotation(OpenShiftAPIAnnotations.DEPLOYMENT_CONFIG_LATEST_VERSION);
        doReturn("4").when(rc).getName();
    }), ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER, rc -> {
        doReturn("6").when(rc).getAnnotation(OpenShiftAPIAnnotations.DEPLOYMENT_CONFIG_LATEST_VERSION);
        doReturn("6").when(rc).getName();
    }));
    // when
    IReplicationController rc = ResourceUtils.getLatestDeploymentConfigVersion(noRcs);
    // then
    assertThat(rc).isNotNull();
    assertThat(rc.getName()).isEqualTo("6");
}
Also used : ResourceUtils.getBuildConfigFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getBuildConfigFor) ResourceUtils.containsAll(org.jboss.tools.openshift.internal.core.util.ResourceUtils.containsAll) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ResourceUtils(org.jboss.tools.openshift.internal.core.util.ResourceUtils) ResourceUtils.imageRef(org.jboss.tools.openshift.internal.core.util.ResourceUtils.imageRef) CoreException(org.eclipse.core.runtime.CoreException) IDeploymentImageChangeTrigger(com.openshift.restclient.model.deploy.IDeploymentImageChangeTrigger) ResourceUtils.getBuildConfigsFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getBuildConfigsFor) Matchers.anyBoolean(org.mockito.Matchers.anyBoolean) ResourceUtils.areRelated(org.jboss.tools.openshift.internal.core.util.ResourceUtils.areRelated) ResourceUtils.getServicesFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getServicesFor) Map(java.util.Map) Mockito.doReturn(org.mockito.Mockito.doReturn) ResourceUtils.getRouteFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getRouteFor) IService(com.openshift.restclient.model.IService) ResourceKind(com.openshift.restclient.ResourceKind) Collection(java.util.Collection) IBuild(com.openshift.restclient.model.IBuild) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) Matchers.any(org.mockito.Matchers.any) List(java.util.List) OpenShiftAPIAnnotations(org.jboss.tools.openshift.core.OpenShiftAPIAnnotations) Assert.assertFalse(org.junit.Assert.assertFalse) IRoute(com.openshift.restclient.model.route.IRoute) Mockito.mock(org.mockito.Mockito.mock) IReplicationController(com.openshift.restclient.model.IReplicationController) IBuildConfig(com.openshift.restclient.model.IBuildConfig) Mock(org.mockito.Mock) ResourceUtils.getImageRefs(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getImageRefs) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IPod(com.openshift.restclient.model.IPod) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ITags(com.openshift.restclient.capability.resources.ITags) Before(org.junit.Before) DockerImageURI(com.openshift.restclient.images.DockerImageURI) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) IObjectReference(com.openshift.restclient.model.IObjectReference) Connection(org.jboss.tools.openshift.core.connection.Connection) ResourceUtils.isMatchingNameOrTag(org.jboss.tools.openshift.internal.core.util.ResourceUtils.isMatchingNameOrTag) ResourceMocks(org.jboss.tools.openshift.test.util.ResourceMocks) ResourceUtils.getDeploymentConfigNameFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getDeploymentConfigNameFor) Assert.assertNull(org.junit.Assert.assertNull) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) CapabilityVisitor(com.openshift.restclient.capability.CapabilityVisitor) ResourceUtils.getRoutesFor(org.jboss.tools.openshift.internal.core.util.ResourceUtils.getRoutesFor) ResourceUtils.isBuildPod(org.jboss.tools.openshift.internal.core.util.ResourceUtils.isBuildPod) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 12 with IReplicationController

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

the class ResourceUtilsTest method shouldReturnNullIfSelectReplicationControllerByDeploymentConfigOnEmptyList.

@Test
public void shouldReturnNullIfSelectReplicationControllerByDeploymentConfigOnEmptyList() {
    // given
    List<IReplicationController> noRcs = Collections.<IReplicationController>emptyList();
    // when
    IReplicationController rc = ResourceUtils.getLatestDeploymentConfigVersion(noRcs);
    // then
    assertThat(rc).isNull();
}
Also used : IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 13 with IReplicationController

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

the class ResourceUtilsTest method shouldReturnNullIfSelectReplicationControllerByDeploymentConfigOnNullList.

@Test
public void shouldReturnNullIfSelectReplicationControllerByDeploymentConfigOnNullList() {
    // given
    List<IReplicationController> nullRcs = null;
    // when
    IReplicationController rc = ResourceUtils.getLatestDeploymentConfigVersion(nullRcs);
    // then
    assertThat(rc).isNull();
}
Also used : IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 14 with IReplicationController

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

the class OpenShiftServiceRequirement method waitForUI.

/**
 * Waits for the service and replication controller to appear in the UI,
 * possibly refreshes the project. This shouldnt be required but turns out
 * that the UI takes extensive amount of time to notice the new resources.
 * We therefore make sure they are present in UI before considering this
 * requirement as fullfilled and possibly refresh the project (in ui) to
 * force it to appear. This shouldnt be necessary, I consider this as workaround.
 *
 * @param projectName
 * @param serviceName
 */
private void waitForUI(final String serviceName, final String projectName) {
    // wait for service to appear in UI
    new WaitUntil(new AbstractWaitCondition() {

        @Override
        public boolean test() {
            OpenShiftExplorerView explorer = new OpenShiftExplorerView();
            explorer.open();
            OpenShift3Connection os3Connection = explorer.getOpenShift3Connection(connection);
            assertThat(os3Connection, not(nullValue()));
            OpenShiftProject os3Project = os3Connection.getProject(projectName);
            assertThat(os3Project, not(nullValue()));
            boolean serviceExists = false;
            try {
                serviceExists = os3Project.getService(serviceName) != null;
            } catch (RedDeerException e) {
                // catched intentionnally
                System.err.println(e);
            }
            /*
						 * WORKAROUND: UI takes extensive amount of time to notice resource changes
						 * -> refresh tree to force it to see changes
						 */
            if (!serviceExists) {
                os3Project.refresh();
            }
            return serviceExists;
        }
    }, TimePeriod.VERY_LONG);
    // wait for replication controller to appear in UI
    List<IReplicationController> rcs = connection.getResources(ResourceKind.REPLICATION_CONTROLLER, service.getNamespaceName());
    IReplicationController serviceRc = ResourceUtils.getReplicationControllerFor(service, rcs);
    assertThat(serviceRc, not(nullValue()));
    new WaitUntil(new OpenShiftResourceExists(Resource.DEPLOYMENT, containsString(serviceRc.getName()), ResourceState.UNSPECIFIED, projectName, connection), TimePeriod.VERY_LONG);
}
Also used : RedDeerException(org.eclipse.reddeer.common.exception.RedDeerException) OpenShiftProject(org.jboss.tools.openshift.reddeer.view.resources.OpenShiftProject) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) AbstractWaitCondition(org.eclipse.reddeer.common.condition.AbstractWaitCondition) OpenShiftExplorerView(org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView) IReplicationController(com.openshift.restclient.model.IReplicationController) OpenShiftResourceExists(org.jboss.tools.openshift.reddeer.condition.OpenShiftResourceExists) OpenShift3Connection(org.jboss.tools.openshift.reddeer.view.resources.OpenShift3Connection)

Example 15 with IReplicationController

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

the class ServicePodsExist method hasDesiredReplicas.

private boolean hasDesiredReplicas(IService service) {
    List<IReplicationController> allReplicationControllers = connection.getResources(ResourceKind.REPLICATION_CONTROLLER, service.getNamespaceName());
    IReplicationController rc = ResourceUtils.getReplicationControllerFor(service, allReplicationControllers);
    return rc != null && rc.getDesiredReplicaCount() > 0;
}
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