Search in sources :

Example 1 with IReplicationController

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

the class ManageEnvironmentVariablesWizard method findReplicationController.

/**
 * If a replication controller is selected, method returns it.
 * If a deployment config is selected, method returns it.
 * If a deployment is selected, method finds a deployment config and returns it.
 * @param event
 * @return
 */
IReplicationController findReplicationController(ExecutionEvent event) {
    ISelection selection = UIUtils.getCurrentSelection(event);
    IDeploymentConfig dc = UIUtils.getFirstElement(selection, IDeploymentConfig.class);
    if (dc != null) {
        return dc;
    }
    IReplicationController rc = UIUtils.getFirstElement(selection, IReplicationController.class);
    if (rc != null) {
        return rc;
    }
    IServiceWrapper deployment = UIUtils.getFirstElement(selection, IServiceWrapper.class);
    Collection<IResourceWrapper<?, ?>> dcs = deployment.getResourcesOfKind(ResourceKind.DEPLOYMENT_CONFIG);
    if (!dcs.isEmpty()) {
        dc = (IDeploymentConfig) dcs.iterator().next().getWrapped();
        if (dc != null) {
            return dc;
        }
    }
    return null;
}
Also used : IResourceWrapper(org.jboss.tools.openshift.internal.ui.models.IResourceWrapper) IServiceWrapper(org.jboss.tools.openshift.internal.ui.models.IServiceWrapper) ISelection(org.eclipse.jface.viewers.ISelection) IDeploymentConfig(com.openshift.restclient.model.IDeploymentConfig) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 2 with IReplicationController

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

the class OpenShiftServiceRequirement method waitForResources.

private void waitForResources(final String serviceName, final String projectName, final IService service) {
    new WaitUntil(new ServicePodsExist(serviceName, projectName, connection), TimePeriod.VERY_LONG);
    new WaitUntil(new ResourceExists(ResourceKind.REPLICATION_CONTROLLER, new BaseMatcher<List<IResource>>() {

        @Override
        public boolean matches(Object item) {
            if (!(item instanceof List)) {
                return false;
            }
            @SuppressWarnings("unchecked") List<IReplicationController> resources = (List<IReplicationController>) item;
            if (resources.isEmpty()) {
                return false;
            }
            return ResourceUtils.getReplicationControllerFor(service, resources) != null;
        }

        @Override
        public void describeTo(Description description) {
        }
    }, projectName, connection), TIMEPERIOD_WAIT_FOR_BUILD);
}
Also used : Description(org.hamcrest.Description) BaseMatcher(org.hamcrest.BaseMatcher) ServicePodsExist(org.jboss.tools.openshift.reddeer.condition.core.ServicePodsExist) List(java.util.List) OpenShiftResourceExists(org.jboss.tools.openshift.reddeer.condition.OpenShiftResourceExists) ResourceExists(org.jboss.tools.openshift.reddeer.condition.core.ResourceExists) WaitUntil(org.eclipse.reddeer.common.wait.WaitUntil) IResource(com.openshift.restclient.model.IResource) IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 3 with IReplicationController

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

the class OpenShiftServiceRequirement method getReplicationController.

public IReplicationController getReplicationController() {
    if (service == null || connection == null) {
        return null;
    }
    List<IReplicationController> rcs = connection.getResources(ResourceKind.REPLICATION_CONTROLLER, service.getNamespaceName());
    IReplicationController rc = ResourceUtils.getReplicationControllerFor(service, rcs);
    return rc;
}
Also used : IReplicationController(com.openshift.restclient.model.IReplicationController)

Example 4 with IReplicationController

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

the class ServerResourceViewModelWithReplicationControllerTest method shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewSelectedDeploymentConfigIfLoadResourcesWithConnection() {
    // given
    IResource selectedDeploymentConfig = model.getResource();
    Connection connection = ResourceMocks.createConnection("https://localhost:8181", "ops@42.org");
    ConnectionsRegistrySingleton.getInstance().add(connection);
    try {
        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
        IResource newSelectedDeploymentConfig = model.getResource();
        assertThat(selectedDeploymentConfig).isNotEqualTo(newSelectedDeploymentConfig);
    } finally {
        ConnectionsRegistrySingleton.getInstance().remove(connection);
    }
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IReplicationController(com.openshift.restclient.model.IReplicationController) Test(org.junit.Test)

Example 5 with IReplicationController

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

the class ServerResourceViewModelWithReplicationControllerTest method shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllReplicationControllers.

@Test
public void shouldReturn1stServiceInListIfInitializedServiceIsNotInListOfAllReplicationControllers() {
    // given
    IReplicationController otherReplicationController = ResourceMocks.createResource(IReplicationController.class, ResourceKind.REPLICATION_CONTROLLER);
    ServerResourceViewModel model = new ServerResourceViewModel(otherReplicationController, connection);
    model.loadResources();
    // when
    IResource service = model.getResource();
    // then
    assertThat(service).isEqualTo(ResourceMocks.PROJECT2_SERVICES[0]);
}
Also used : ServerResourceViewModel(org.jboss.tools.openshift.internal.ui.server.ServerResourceViewModel) IReplicationController(com.openshift.restclient.model.IReplicationController) IResource(com.openshift.restclient.model.IResource) Test(org.junit.Test)

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