Search in sources :

Example 6 with IResource

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

the class ServerAdapterHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
    ISelection selection = UIUtils.getCurrentSelection(event);
    IResource selectedResource = UIUtils.getFirstElement(selection, IResource.class);
    final IServer openShiftServer = getOpenShiftServer(selectedResource);
    if (openShiftServer != null) {
        openServersView(openShiftServer, workbenchWindow);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IServer(org.eclipse.wst.server.core.IServer) ISelection(org.eclipse.jface.viewers.ISelection) IResource(com.openshift.restclient.model.IResource)

Example 7 with IResource

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

the class OpenShiftServiceRequirement method cleanUp.

@Override
public void cleanUp() {
    if (serviceSpec.cleanup()) {
        String projectName = TestUtils.getValueOrDefault(serviceSpec.project(), DatastoreOS3.TEST_PROJECT);
        final IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
        IProjectTemplateProcessing capability = project.getCapability(IProjectTemplateProcessing.class);
        ITemplate processed = capability.process(template);
        for (IResource resource : processed.getObjects()) {
            IResource res = connection.getResource(resource.getKind(), projectName, resource.getName());
            try {
                connection.deleteResource(res);
            } catch (OpenShiftException ex) {
                LOGGER.error("Unable to remove " + res.getKind() + " named " + res.getName());
                LOGGER.error(StackTraceUtils.stackTraceToString(ex));
            }
        }
        cleanResources(connection, ResourceKind.BUILD, project, template);
        cleanResources(connection, ResourceKind.REPLICATION_CONTROLLER, project, template);
        cleanResources(connection, ResourceKind.POD, project, template);
        new WaitWhile(new AbstractWaitCondition() {

            @Override
            public boolean test() {
                for (IResource resource : project.getResources(ResourceKind.POD)) {
                    if (resource.getName().startsWith(template.getName())) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String description() {
                return "at least one application pod is running";
            }
        }, TimePeriod.LONG);
        new OpenShiftExplorerView().getOpenShift3Connection(connection).refresh();
    }
}
Also used : IProjectTemplateProcessing(com.openshift.restclient.capability.resources.IProjectTemplateProcessing) WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) OpenShiftException(com.openshift.restclient.OpenShiftException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ITemplate(com.openshift.restclient.model.template.ITemplate) AbstractWaitCondition(org.eclipse.reddeer.common.condition.AbstractWaitCondition) OpenShiftExplorerView(org.jboss.tools.openshift.reddeer.view.OpenShiftExplorerView) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 8 with IResource

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

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

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

the class ServerResourceViewModelWithReplicationControllerTest 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)

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