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");
}
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();
}
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();
}
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);
}
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;
}
Aggregations