Search in sources :

Example 1 with IProject

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

the class ImportApplicationHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = UIUtils.getCurrentSelection(event);
    IBuildConfig buildConfig = UIUtils.getFirstElement(currentSelection, IBuildConfig.class);
    Map<IProject, Collection<IBuildConfig>> projectsAndBuildConfigs = null;
    IProject project = null;
    Collection<IBuildConfig> buildConfigs = null;
    if (buildConfig == null) {
        IResource resource = UIUtils.getFirstElement(currentSelection, IResource.class);
        if (resource != null) {
            project = resource.getProject();
        }
        if (project != null) {
            buildConfigs = project.getResources(ResourceKind.BUILD_CONFIG);
        }
    } else {
        project = buildConfig.getProject();
        buildConfigs = Collections.singleton(buildConfig);
    }
    if (project != null) {
        if (buildConfigs == null || buildConfigs.isEmpty()) {
            MessageDialog.openWarning(HandlerUtil.getActiveShell(event), NO_BUILD_CONFIG_MSG, NO_BUILD_CONFIG_MSG);
            return OpenShiftUIActivator.statusFactory().cancelStatus(NO_BUILD_CONFIG_MSG);
        }
        projectsAndBuildConfigs = Collections.singletonMap(project, buildConfigs);
    }
    if (projectsAndBuildConfigs == null) {
        ImportApplicationWizard wizard = new ImportApplicationWizard();
        Connection connection = UIUtils.getFirstElement(currentSelection, Connection.class);
        wizard.setConnection(connection);
        WizardUtils.openWizardDialog(wizard, HandlerUtil.getActiveShell(event));
    } else {
        WizardUtils.openWizardDialog(new ImportApplicationWizard(projectsAndBuildConfigs), HandlerUtil.getActiveShell(event));
    }
    return Status.OK_STATUS;
}
Also used : IBuildConfig(com.openshift.restclient.model.IBuildConfig) ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) Collection(java.util.Collection) ImportApplicationWizard(org.jboss.tools.openshift.internal.ui.wizard.importapp.ImportApplicationWizard) IProject(com.openshift.restclient.model.IProject) IResource(com.openshift.restclient.model.IResource)

Example 2 with IProject

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

the class NewProjectHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    Connection connection = UIUtils.getFirstElement(selection, Connection.class);
    if (connection == null) {
        IProject project = UIUtils.getFirstElement(selection, IProject.class);
        if (project != null) {
            connection = ConnectionsRegistryUtil.getConnectionFor(project);
        }
    }
    if (connection == null) {
        // $NON-NLS-1$
        return OpenShiftUIActivator.statusFactory().cancelStatus("No connection selected");
    }
    openNewProjectDialog(connection, HandlerUtil.getActiveShell(event));
    return null;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) Connection(org.jboss.tools.openshift.core.connection.Connection) IProject(com.openshift.restclient.model.IProject)

Example 3 with IProject

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

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

the class ServerResourceViewModelWithServiceTest method shouldReturnNewServiceItemsIfLoadResourcesWithConnection.

@Test
public void shouldReturnNewServiceItemsIfLoadResourcesWithConnection() {
    // given
    List<ObservableTreeItem> serviceItems = new ArrayList<>(model.getResourceItems());
    Connection connection = ResourceMocks.createConnection("http://localhost:8080", "dev@42.org");
    IProject project = ResourceMocks.createResource(IProject.class, ResourceKind.PROJECT);
    when(connection.getResources(ResourceKind.PROJECT)).thenReturn(Collections.singletonList(project));
    IService service = ResourceMocks.createResource(IService.class, ResourceKind.SERVICE);
    when(project.getResources(ResourceKind.SERVICE)).thenReturn(Collections.singletonList(service));
    // when
    model.loadResources(connection);
    // then
    List<ObservableTreeItem> newServiceItems = model.getResourceItems();
    assertThat(newServiceItems).isNotEqualTo(serviceItems);
}
Also used : ArrayList(java.util.ArrayList) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) ObservableTreeItem(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService) Test(org.junit.Test)

Example 5 with IProject

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

Aggregations

IProject (com.openshift.restclient.model.IProject)49 Test (org.junit.Test)18 Connection (org.jboss.tools.openshift.core.connection.Connection)16 IResource (com.openshift.restclient.model.IResource)13 ArrayList (java.util.ArrayList)8 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)7 ResourceKind (com.openshift.restclient.ResourceKind)6 IStatus (org.eclipse.core.runtime.IStatus)6 ObservableTreeItem (org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem)6 List (java.util.List)5 ISelection (org.eclipse.jface.viewers.ISelection)5 IService (com.openshift.restclient.model.IService)4 IRoute (com.openshift.restclient.model.route.IRoute)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4 OpenShiftException (com.openshift.restclient.OpenShiftException)3 IBuildConfig (com.openshift.restclient.model.IBuildConfig)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3