Search in sources :

Example 46 with IProject

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

the class OpenShift3NativeProjectUtils method getOrCreateProject.

public static IProject getOrCreateProject(String name, String displayName, String description, Connection connection) {
    IProject project = OpenShift3NativeResourceUtils.getProject(name, connection);
    if (project == null) {
        LOGGER.debug(NLS.bind("Project {0} doesnt exist yet in {1}, creating it.", name, connection.getHost()));
        project = createProject(name, displayName, description, connection);
    }
    return project;
}
Also used : IProject(com.openshift.restclient.model.IProject)

Example 47 with IProject

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

the class DeleteResourceHandlerTest method testStopWatchProject.

@Test
public void testStopWatchProject() throws Exception {
    IProject project = mock(IProject.class);
    when(project.getName()).thenReturn("ProjectName");
    when(project.getKind()).thenReturn(ResourceKind.PROJECT);
    IProjectWrapper projectWrapper = mock(IProjectWrapper.class);
    when(projectWrapper.getWrapped()).thenReturn(project);
    Connection connection = mock(Connection.class);
    ConnectionsRegistrySingleton.getInstance().add(connection);
    when(connection.ownsResource(project)).thenReturn(true);
    WatchManager.getInstance().startWatch(project, connection);
    assertEquals(WatchManager.KINDS.length, WatchManager.getInstance()._getWatches().size());
    DeleteResourceHandlerTestExtension handler = new DeleteResourceHandlerTestExtension();
    JobGroup deleteResourcesJobGroup = handler.deleteResources(new IResourceWrapper<?, ?>[] { projectWrapper });
    deleteResourcesJobGroup.join(500, null);
    assertEquals(0, WatchManager.getInstance()._getWatches().size());
}
Also used : JobGroup(org.eclipse.core.runtime.jobs.JobGroup) Connection(org.jboss.tools.openshift.core.connection.Connection) IProject(com.openshift.restclient.model.IProject) IProjectWrapper(org.jboss.tools.openshift.internal.ui.models.IProjectWrapper) Test(org.junit.Test)

Example 48 with IProject

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

the class DeployImageWizardModelTest method loadResources_should_load_projects.

@Test
public void loadResources_should_load_projects() {
    // given
    IProject project1 = mock(IProject.class);
    IProject project2 = mock(IProject.class);
    createModelProjects(this.connection, project1, project2);
    model.setResourcesLoaded(false);
    // when
    model.loadResources();
    // then
    assertThat(model.getProjects()).isEqualTo(Arrays.asList(project1, project2));
}
Also used : IProject(com.openshift.restclient.model.IProject) Test(org.junit.Test)

Example 49 with IProject

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

the class NamespaceService method start.

@Override
public void start(StartContext context) throws StartException {
    this.client = this.clientInjector.getValue();
    this.namespace = System.getenv("KUBERNETES_NAMESPACE");
    if (this.namespace == null) {
        Path namespaceFile = Paths.get("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
        if (Files.exists(namespaceFile)) {
            try {
                this.namespace = new String(Files.readAllBytes(namespaceFile));
            } catch (IOException ignored) {
            // shouldn't happen, this file is on tmpfs
            // but if it happened anyway, we'll try the following options
            }
        }
    }
    if (this.namespace == null) {
        this.namespace = System.getenv("OPENSHIFT_BUILD_NAMESPACE");
    }
    if (this.namespace == null) {
        List<IProject> projects = this.client.list(ResourceKind.PROJECT);
        if (projects.size() != 1) {
            throw new StartException("Unable to automatically detect the " + "Kubernetes namespace to use. Set the environment " + "variable KUBERNETES_NAMESPACE and try again.");
        }
        this.namespace = projects.get(0).getNamespace();
    }
}
Also used : Path(java.nio.file.Path) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException) IProject(com.openshift.restclient.model.IProject)

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